var BABYLON;!function(e){var t=function(){function e(e,t,r){void 0===e&&(e=0),void 0===t&&(t=0),void 0===r&&(r=0),this.r=e,this.g=t,this.b=r}return e.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+"}"},e.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,this},e.prototype.toColor4=function(e){return void 0===e&&(e=1),new r(this.r,this.g,this.b,e)},e.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},e.prototype.toLuminance=function(){return.3*this.r+.59*this.g+.11*this.b},e.prototype.multiply=function(t){return new e(this.r*t.r,this.g*t.g,this.b*t.b)},e.prototype.multiplyToRef=function(e,t){return t.r=this.r*e.r,t.g=this.g*e.g,t.b=this.b*e.b,this},e.prototype.equals=function(e){return e&&this.r===e.r&&this.g===e.g&&this.b===e.b},e.prototype.scale=function(t){return new e(this.r*t,this.g*t,this.b*t)},e.prototype.scaleToRef=function(e,t){return t.r=this.r*e,t.g=this.g*e,t.b=this.b*e,this},e.prototype.add=function(t){return new e(this.r+t.r,this.g+t.g,this.b+t.b)},e.prototype.addToRef=function(e,t){return t.r=this.r+e.r,t.g=this.g+e.g,t.b=this.b+e.b,this},e.prototype.subtract=function(t){return new e(this.r-t.r,this.g-t.g,this.b-t.b)},e.prototype.subtractToRef=function(e,t){return t.r=this.r-e.r,t.g=this.g-e.g,t.b=this.b-e.b,this},e.prototype.clone=function(){return new e(this.r,this.g,this.b)},e.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this},e.prototype.copyFromFloats=function(e,t,r){return this.r=e,this.g=t,this.b=r,this},e.FromArray=function(t,r){return void 0===r&&(r=0),new e(t[r],t[r+1],t[r+2])},e.FromInts=function(t,r,i){return new e(t/255,r/255,i/255)},e.Lerp=function(t,r,i){var n=t.r+(r.r-t.r)*i,o=t.g+(r.g-t.g)*i,s=t.b+(r.b-t.b)*i;return new e(n,o,s)},e.Red=function(){return new e(1,0,0)},e.Green=function(){return new e(0,1,0)},e.Blue=function(){return new e(0,0,1)},e.Black=function(){return new e(0,0,0)},e.White=function(){return new e(1,1,1)},e.Purple=function(){return new e(.5,0,.5)},e.Magenta=function(){return new e(1,0,1)},e.Yellow=function(){return new e(1,1,0)},e.Gray=function(){return new e(.5,.5,.5)},e}();e.Color3=t;var r=function(){function e(e,t,r,i){this.r=e,this.g=t,this.b=r,this.a=i}return e.prototype.addInPlace=function(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this.a+=e.a,this},e.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},e.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e[t+3]=this.a,this},e.prototype.add=function(t){return new e(this.r+t.r,this.g+t.g,this.b+t.b,this.a+t.a)},e.prototype.subtract=function(t){return new e(this.r-t.r,this.g-t.g,this.b-t.b,this.a-t.a)},e.prototype.subtractToRef=function(e,t){return t.r=this.r-e.r,t.g=this.g-e.g,t.b=this.b-e.b,t.a=this.a-e.a,this},e.prototype.scale=function(t){return new e(this.r*t,this.g*t,this.b*t,this.a*t)},e.prototype.scaleToRef=function(e,t){return t.r=this.r*e,t.g=this.g*e,t.b=this.b*e,t.a=this.a*e,this},e.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+" A:"+this.a+"}"},e.prototype.clone=function(){return new e(this.r,this.g,this.b,this.a)},e.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this},e.Lerp=function(t,r,i){var n=new e(0,0,0,0);return e.LerpToRef(t,r,i,n),n},e.LerpToRef=function(e,t,r,i){i.r=e.r+(t.r-e.r)*r,i.g=e.g+(t.g-e.g)*r,i.b=e.b+(t.b-e.b)*r,i.a=e.a+(t.a-e.a)*r},e.FromArray=function(t,r){return void 0===r&&(r=0),new e(t[r],t[r+1],t[r+2],t[r+3])},e.FromInts=function(t,r,i,n){return new e(t/255,r/255,i/255,n/255)},e}();e.Color4=r;var i=function(){function t(e,t){this.x=e,this.y=t}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}"},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,this},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this},t.prototype.copyFromFloats=function(e,t){return this.x=e,this.y=t,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.addVector3=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y)},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,this},t.prototype.multiplyByFloats=function(e,r){return new t(this.x*e,this.y*r)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,this},t.prototype.negate=function(){return new t(-this.x,-this.y)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e)},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y},t.prototype.equalsWithEpsilon=function(t){return t&&e.Tools.WithinEpsilon(this.x,t.x)&&e.Tools.WithinEpsilon(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 e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this},t.prototype.clone=function(){return new t(this.x,this.y)},t.Zero=function(){return new t(0,0)},t.FromArray=function(e,r){return void 0===r&&(r=0),new t(e[r],e[r+1])},t.FromArrayToRef=function(e,t,r){r.x=e[t],r.y=e[t+1]},t.CatmullRom=function(e,r,i,n,o){var s=o*o,a=o*s,h=.5*(2*r.x+(-e.x+i.x)*o+(2*e.x-5*r.x+4*i.x-n.x)*s+(-e.x+3*r.x-3*i.x+n.x)*a),c=.5*(2*r.y+(-e.y+i.y)*o+(2*e.y-5*r.y+4*i.y-n.y)*s+(-e.y+3*r.y-3*i.y+n.y)*a);return new t(h,c)},t.Clamp=function(e,r,i){var n=e.x;n=n>i.x?i.x:n,n=ni.y?i.y:o,o=or.x?e.x:r.x,n=e.y>r.y?e.y:r.y;return new t(i,n)},t.Transform=function(e,r){var i=e.x*r.m[0]+e.y*r.m[4],n=e.x*r.m[1]+e.y*r.m[5];return new t(i,n)},t.Distance=function(e,r){return Math.sqrt(t.DistanceSquared(e,r))},t.DistanceSquared=function(e,t){var r=e.x-t.x,i=e.y-t.y;return r*r+i*i},t}();e.Vector2=i;var n=function(){function t(e,t,r){this.x=e,this.y=t,this.z=r}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,this},t.prototype.toQuaternion=function(){var e=new s(0,0,0,1),t=Math.cos(.5*(this.x+this.z)),r=Math.sin(.5*(this.x+this.z)),i=Math.cos(.5*(this.z-this.x)),n=Math.sin(.5*(this.z-this.x)),o=Math.cos(.5*this.y),a=Math.sin(.5*this.y);return e.x=i*a,e.y=-n*a,e.z=r*o,e.w=t*o,e},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,this},t.prototype.subtractFromFloats=function(e,r,i){return new t(this.x-e,this.y-r,this.z-i)},t.prototype.subtractFromFloatsToRef=function(e,t,r,i){return i.x=this.x-e,i.y=this.y-t,i.z=this.z-r,this},t.prototype.negate=function(){return new t(-this.x,-this.y,-this.z)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e)},t.prototype.scaleToRef=function(e,t){t.x=this.x*e,t.y=this.y*e,t.z=this.z*e},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z},t.prototype.equalsWithEpsilon=function(t){return t&&e.Tools.WithinEpsilon(this.x,t.x)&&e.Tools.WithinEpsilon(this.y,t.y)&&e.Tools.WithinEpsilon(this.z,t.z)},t.prototype.equalsToFloats=function(e,t,r){return this.x===e&&this.y===t&&this.z===r},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y,this.z*e.z)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,t.z=this.z*e.z,this},t.prototype.multiplyByFloats=function(e,r,i){return new t(this.x*e,this.y*r,this.z*i)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y,this.z/e.z)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,t.z=this.z/e.z,this},t.prototype.MinimizeInPlace=function(e){return e.xthis.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},t.prototype.normalize=function(){var e=this.length();if(0===e||1===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.clone=function(){return new t(this.x,this.y,this.z)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},t.prototype.copyFromFloats=function(e,t,r){return this.x=e,this.y=t,this.z=r,this},t.GetClipFactor=function(e,r,i,n){var o=t.Dot(e,i)-n,s=t.Dot(r,i)-n,a=o/(o-s);return a},t.FromArray=function(e,r){return r||(r=0),new t(e[r],e[r+1],e[r+2])},t.FromArrayToRef=function(e,t,r){r.x=e[t],r.y=e[t+1],r.z=e[t+2]},t.FromFloatArrayToRef=function(e,t,r){r.x=e[t],r.y=e[t+1],r.z=e[t+2]},t.FromFloatsToRef=function(e,t,r,i){i.x=e,i.y=t,i.z=r},t.Zero=function(){return new t(0,0,0)},t.Up=function(){return new t(0,1,0)},t.TransformCoordinates=function(e,r){var i=t.Zero();return t.TransformCoordinatesToRef(e,r,i),i},t.TransformCoordinatesToRef=function(e,t,r){var i=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8]+t.m[12],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9]+t.m[13],o=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10]+t.m[14],s=e.x*t.m[3]+e.y*t.m[7]+e.z*t.m[11]+t.m[15];r.x=i/s,r.y=n/s,r.z=o/s},t.TransformCoordinatesFromFloatsToRef=function(e,t,r,i,n){var o=e*i.m[0]+t*i.m[4]+r*i.m[8]+i.m[12],s=e*i.m[1]+t*i.m[5]+r*i.m[9]+i.m[13],a=e*i.m[2]+t*i.m[6]+r*i.m[10]+i.m[14],h=e*i.m[3]+t*i.m[7]+r*i.m[11]+i.m[15];n.x=o/h,n.y=s/h,n.z=a/h},t.TransformCoordinatesToRefSIMD=function(e,t,r){var i=SIMD.float32x4.loadXYZ(e._data,0),n=SIMD.float32x4.load(t.m,0),o=SIMD.float32x4.load(t.m,4),s=SIMD.float32x4.load(t.m,8),a=SIMD.float32x4.load(t.m,12),h=SIMD.float32x4.add(SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(i,0,0,0,0),n),SIMD.float32x4.mul(SIMD.float32x4.swizzle(i,1,1,1,1),o)),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(i,2,2,2,2),s),a));h=SIMD.float32x4.div(h,SIMD.float32x4.swizzle(h,3,3,3,3)),SIMD.float32x4.storeXYZ(r._data,0,h)},t.TransformCoordinatesFromFloatsToRefSIMD=function(e,t,r,i,n){var o=SIMD.float32x4.splat(e),s=SIMD.float32x4.splat(t),a=SIMD.float32x4.splat(r),h=SIMD.float32x4.load(i.m,0),c=SIMD.float32x4.load(i.m,4),l=SIMD.float32x4.load(i.m,8),u=SIMD.float32x4.load(i.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)},t.TransformNormal=function(e,r){var i=t.Zero();return t.TransformNormalToRef(e,r,i),i},t.TransformNormalToRef=function(e,t,r){r.x=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8],r.y=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9],r.z=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10]},t.TransformNormalFromFloatsToRef=function(e,t,r,i,n){n.x=e*i.m[0]+t*i.m[4]+r*i.m[8],n.y=e*i.m[1]+t*i.m[5]+r*i.m[9],n.z=e*i.m[2]+t*i.m[6]+r*i.m[10]},t.CatmullRom=function(e,r,i,n,o){var s=o*o,a=o*s,h=.5*(2*r.x+(-e.x+i.x)*o+(2*e.x-5*r.x+4*i.x-n.x)*s+(-e.x+3*r.x-3*i.x+n.x)*a),c=.5*(2*r.y+(-e.y+i.y)*o+(2*e.y-5*r.y+4*i.y-n.y)*s+(-e.y+3*r.y-3*i.y+n.y)*a),l=.5*(2*r.z+(-e.z+i.z)*o+(2*e.z-5*r.z+4*i.z-n.z)*s+(-e.z+3*r.z-3*i.z+n.z)*a);return new t(h,c,l)},t.Clamp=function(e,r,i){var n=e.x;n=n>i.x?i.x:n,n=ni.y?i.y:o,o=oi.z?i.z:s,s=sA&&2>b&&(d=Math.PI+d),new e.Vector3(p,d,m)},t}();e.Vector3=n;var o=function(){function t(e,t,r,i){this.x=e,this.y=t,this.z=r,this.w=i}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"W:"+this.w+"}"},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,this},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,t.w=this.w+e.w,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,t.w=this.w-e.w,this},t.prototype.subtractFromFloats=function(e,r,i,n){return new t(this.x-e,this.y-r,this.z-i,this.w-n)},t.prototype.subtractFromFloatsToRef=function(e,t,r,i,n){return n.x=this.x-e,n.y=this.y-t,n.z=this.z-r,n.w=this.w-i,this},t.prototype.negate=function(){return new t(-this.x,-this.y,-this.z,-this.w)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e,this.w*e)},t.prototype.scaleToRef=function(e,t){t.x=this.x*e,t.y=this.y*e,t.z=this.z*e,t.w=this.w*e},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},t.prototype.equalsWithEpsilon=function(t){return Math.abs(this.x-t.x)this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),e.w>this.w&&(this.w=e.w),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},t.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},t.prototype.copyFromFloats=function(e,t,r,i){return this.x=e,this.y=t,this.z=r,this.w=i,this},t.FromArray=function(e,r){return r||(r=0),new t(e[r],e[r+1],e[r+2],e[r+3])},t.FromArrayToRef=function(e,t,r){r.x=e[t],r.y=e[t+1],r.z=e[t+2],r.w=e[t+3]},t.FromFloatArrayToRef=function(e,t,r){r.x=e[t],r.y=e[t+1],r.z=e[t+2],r.w=e[t+3]},t.FromFloatsToRef=function(e,t,r,i,n){n.x=e,n.y=t,n.z=r,n.w=i},t.Zero=function(){return new t(0,0,0,0)},t.Normalize=function(e){var r=t.Zero();return t.NormalizeToRef(e,r),r},t.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},t.Minimize=function(e,t){var r=e.clone();return r.MinimizeInPlace(t),r},t.Maximize=function(e,t){var r=e.clone();return r.MaximizeInPlace(t),r},t.Distance=function(e,r){return Math.sqrt(t.DistanceSquared(e,r))},t.DistanceSquared=function(e,t){var r=e.x-t.x,i=e.y-t.y,n=e.z-t.z,o=e.w-t.w;return r*r+i*i+n*n+o*o},t.Center=function(e,t){var r=e.add(t);return r.scaleInPlace(.5),r},t}();e.Vector4=o;var s=function(){function e(e,t,r,i){void 0===e&&(e=0),void 0===t&&(t=0),void 0===r&&(r=0),void 0===i&&(i=1),this.x=e,this.y=t,this.z=r,this.w=i}return e.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},e.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},e.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},e.prototype.clone=function(){return new e(this.x,this.y,this.z,this.w)},e.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},e.prototype.copyFromFloats=function(e,t,r,i){return this.x=e,this.y=t,this.z=r,this.w=i,this},e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y,this.z+t.z,this.w+t.w)},e.prototype.subtract=function(t){return new e(this.x-t.x,this.y-t.y,this.z-t.z,this.w-t.w)},e.prototype.scale=function(t){return new e(this.x*t,this.y*t,this.z*t,this.w*t)},e.prototype.multiply=function(t){var r=new e(0,0,0,1);return this.multiplyToRef(t,r),r},e.prototype.multiplyToRef=function(e,t){var r=this.x*e.w+this.y*e.z-this.z*e.y+this.w*e.x,i=-this.x*e.z+this.y*e.w+this.z*e.x+this.w*e.y,n=this.x*e.y-this.y*e.x+this.z*e.w+this.w*e.z,o=-this.x*e.x-this.y*e.y-this.z*e.z+this.w*e.w;return t.copyFromFloats(r,i,n,o),this},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},e.prototype.normalize=function(){var e=1/this.length();return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},e.prototype.toEulerAngles=function(){var e=n.Zero();return this.toEulerAnglesToRef(e),e},e.prototype.toEulerAnglesToRef=function(e){var t=this.x,r=this.y,i=this.z,n=this.w,o=t*r,s=t*i,a=n*r,h=n*i,c=n*t,l=r*i,u=t*t,f=r*r,d=u+f;return 0!==d&&1!==d?(e.x=Math.atan2(s+a,c-l),e.y=Math.acos(1-2*d),e.z=Math.atan2(s-a,c+l)):0===d?(e.x=0,e.y=0,e.z=Math.atan2(o-h,.5-f-i*i)):(e.x=Math.atan2(o-h,.5-f-i*i),e.y=Math.PI,e.z=0),this},e.prototype.toRotationMatrix=function(e){var t=this.x*this.x,r=this.y*this.y,i=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 e.m[0]=1-2*(r+i),e.m[1]=2*(n+o),e.m[2]=2*(s-a),e.m[3]=0,e.m[4]=2*(n-o),e.m[5]=1-2*(i+t),e.m[6]=2*(h+c),e.m[7]=0,e.m[8]=2*(s+a),e.m[9]=2*(h-c),e.m[10]=1-2*(r+t),e.m[11]=0,e.m[12]=0,e.m[13]=0,e.m[14]=0,e.m[15]=1,this},e.prototype.fromRotationMatrix=function(t){return e.FromRotationMatrixToRef(t,this),this},e.FromRotationMatrix=function(t){var r=new e;return e.FromRotationMatrixToRef(t,r),r},e.FromRotationMatrixToRef=function(e,t){var r,i=e.m,n=i[0],o=i[4],s=i[8],a=i[1],h=i[5],c=i[9],l=i[2],u=i[6],f=i[10],d=n+h+f;d>0?(r=.5/Math.sqrt(d+1),t.w=.25/r,t.x=(u-c)*r,t.y=(s-l)*r,t.z=(a-o)*r):n>h&&n>f?(r=2*Math.sqrt(1+n-h-f),t.w=(u-c)/r,t.x=.25*r,t.y=(o+a)/r,t.z=(s+l)/r):h>f?(r=2*Math.sqrt(1+h-n-f),t.w=(s-l)/r,t.x=(o+a)/r,t.y=.25*r,t.z=(c+u)/r):(r=2*Math.sqrt(1+f-n-h),t.w=(a-o)/r,t.x=(s+l)/r,t.y=(c+u)/r,t.z=.25*r)},e.Inverse=function(t){return new e(-t.x,-t.y,-t.z,t.w)},e.Identity=function(){return new e(0,0,0,1)},e.RotationAxis=function(t,r){var i=new e,n=Math.sin(r/2);return i.w=Math.cos(r/2),i.x=t.x*n,i.y=t.y*n,i.z=t.z*n,i},e.FromArray=function(t,r){return r||(r=0),new e(t[r],t[r+1],t[r+2],t[r+3])},e.RotationYawPitchRoll=function(t,r,i){var n=new e;return e.RotationYawPitchRollToRef(t,r,i,n),n},e.RotationYawPitchRollToRef=function(e,t,r,i){var n=.5*r,o=.5*t,s=.5*e,a=Math.sin(n),h=Math.cos(n),c=Math.sin(o),l=Math.cos(o),u=Math.sin(s),f=Math.cos(s);i.x=f*c*h+u*l*a,i.y=u*l*h-f*c*a,i.z=f*l*a-u*c*h,i.w=f*l*h+u*c*a},e.RotationAlphaBetaGamma=function(t,r,i){var n=new e;return e.RotationAlphaBetaGammaToRef(t,r,i,n),n},e.RotationAlphaBetaGammaToRef=function(e,t,r,i){var n=.5*(r+e),o=.5*(r-e),s=.5*t;i.x=Math.cos(o)*Math.sin(s),i.y=Math.sin(o)*Math.sin(s),i.z=Math.sin(n)*Math.cos(s),i.w=Math.cos(n)*Math.cos(s)},e.Slerp=function(t,r,i){var n,o,s=i,a=t.x*r.x+t.y*r.y+t.z*r.z+t.w*r.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 e(o*t.x+n*r.x,o*t.y+n*r.y,o*t.z+n*r.z,o*t.w+n*r.w)},e}();e.Quaternion=s;var a=function(){function t(){this.m=new Float32Array(16)}return t.prototype.isIdentity=function(){return 1!==this.m[0]||1!==this.m[5]||1!==this.m[10]||1!==this.m[15]?!1:0!==this.m[1]||0!==this.m[2]||0!==this.m[3]||0!==this.m[4]||0!==this.m[6]||0!==this.m[7]||0!==this.m[8]||0!==this.m[9]||0!==this.m[11]||0!==this.m[12]||0!==this.m[13]||0!==this.m[14]?!1:!0},t.prototype.determinant=function(){var e=this.m[10]*this.m[15]-this.m[11]*this.m[14],t=this.m[9]*this.m[15]-this.m[11]*this.m[13],r=this.m[9]*this.m[14]-this.m[10]*this.m[13],i=this.m[8]*this.m[15]-this.m[11]*this.m[12],n=this.m[8]*this.m[14]-this.m[10]*this.m[12],o=this.m[8]*this.m[13]-this.m[9]*this.m[12];return this.m[0]*(this.m[5]*e-this.m[6]*t+this.m[7]*r)-this.m[1]*(this.m[4]*e-this.m[6]*i+this.m[7]*n)+this.m[2]*(this.m[4]*t-this.m[5]*i+this.m[7]*o)-this.m[3]*(this.m[4]*r-this.m[5]*n+this.m[6]*o)},t.prototype.toArray=function(){return this.m},t.prototype.asArray=function(){return this.toArray()},t.prototype.invert=function(){return this.invertToRef(this),this},t.prototype.invertToRef=function(e){var t=this.m[0],r=this.m[1],i=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,A=c*p-l*d,M=s*g-a*v+h*y,T=-(o*g-a*x+h*b),S=o*v-s*x+h*A,E=-(o*y-s*b+a*A),C=1/(t*M+r*T+i*S+n*E),P=a*_-h*m,D=s*_-h*p,w=s*m-a*p,I=o*_-h*d,L=o*m-a*d,O=o*p-s*d,B=a*f-h*u,R=s*f-h*l,F=s*u-a*l,V=o*f-h*c,N=o*u-a*c,k=o*l-s*c;return e.m[0]=M*C,e.m[4]=T*C,e.m[8]=S*C,e.m[12]=E*C,e.m[1]=-(r*g-i*v+n*y)*C,e.m[5]=(t*g-i*x+n*b)*C,e.m[9]=-(t*v-r*x+n*A)*C,e.m[13]=(t*y-r*b+i*A)*C,e.m[2]=(r*P-i*D+n*w)*C,e.m[6]=-(t*P-i*I+n*L)*C,e.m[10]=(t*D-r*I+n*O)*C,e.m[14]=-(t*w-r*L+i*O)*C,e.m[3]=-(r*B-i*R+n*F)*C,e.m[7]=(t*B-i*V+n*N)*C,e.m[11]=-(t*R-r*V+n*k)*C,e.m[15]=(t*F-r*N+i*k)*C,this},t.prototype.invertToRefSIMD=function(e){var t,r,i,n,o,s,a,h,c,l,u=this.m,f=e.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),r=SIMD.float32x4.shuffle(m,_,0,1,4,5),t=SIMD.float32x4.shuffle(o,r,0,2,4,6),r=SIMD.float32x4.shuffle(r,o,1,3,5,7),o=SIMD.float32x4.shuffle(d,p,2,3,6,7),n=SIMD.float32x4.shuffle(m,_,2,3,6,7),i=SIMD.float32x4.shuffle(o,n,0,2,4,6),n=SIMD.float32x4.shuffle(n,o,1,3,5,7),o=SIMD.float32x4.mul(i,n),o=SIMD.float32x4.swizzle(o,1,0,3,2),s=SIMD.float32x4.mul(r,o),a=SIMD.float32x4.mul(t,o),o=SIMD.float32x4.swizzle(o,2,3,0,1),s=SIMD.float32x4.sub(SIMD.float32x4.mul(r,o),s),a=SIMD.float32x4.sub(SIMD.float32x4.mul(t,o),a),a=SIMD.float32x4.swizzle(a,2,3,0,1),o=SIMD.float32x4.mul(r,i),o=SIMD.float32x4.swizzle(o,1,0,3,2),s=SIMD.float32x4.add(SIMD.float32x4.mul(n,o),s),c=SIMD.float32x4.mul(t,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(t,o),c),c=SIMD.float32x4.swizzle(c,2,3,0,1),o=SIMD.float32x4.mul(SIMD.float32x4.swizzle(r,2,3,0,1),n),o=SIMD.float32x4.swizzle(o,1,0,3,2),i=SIMD.float32x4.swizzle(i,2,3,0,1),s=SIMD.float32x4.add(SIMD.float32x4.mul(i,o),s),h=SIMD.float32x4.mul(t,o),o=SIMD.float32x4.swizzle(o,2,3,0,1),s=SIMD.float32x4.sub(s,SIMD.float32x4.mul(i,o)),h=SIMD.float32x4.sub(SIMD.float32x4.mul(t,o),h),h=SIMD.float32x4.swizzle(h,2,3,0,1),o=SIMD.float32x4.mul(t,r),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(i,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(i,o)),o=SIMD.float32x4.mul(t,n),o=SIMD.float32x4.swizzle(o,1,0,3,2),a=SIMD.float32x4.sub(a,SIMD.float32x4.mul(i,o)),h=SIMD.float32x4.add(SIMD.float32x4.mul(r,o),h),o=SIMD.float32x4.swizzle(o,2,3,0,1),a=SIMD.float32x4.add(SIMD.float32x4.mul(i,o),a),h=SIMD.float32x4.sub(h,SIMD.float32x4.mul(r,o)),o=SIMD.float32x4.mul(t,i),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(r,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(r,o),c),l=SIMD.float32x4.mul(t,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},t.prototype.setTranslation=function(e){return this.m[12]=e.x,this.m[13]=e.y,this.m[14]=e.z,this},t.prototype.multiply=function(e){var r=new t;return this.multiplyToRef(e,r),r},t.prototype.copyFrom=function(e){for(var t=0;16>t;t++)this.m[t]=e.m[t];return this},t.prototype.copyToArray=function(e,t){void 0===t&&(t=0);for(var r=0;16>r;r++)e[t+r]=this.m[r];return this},t.prototype.multiplyToRef=function(e,t){return this.multiplyToArray(e,t.m,0),this},t.prototype.multiplyToArray=function(e,t,r){var i=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=e.m[0],x=e.m[1],b=e.m[2],A=e.m[3],M=e.m[4],T=e.m[5],S=e.m[6],E=e.m[7],C=e.m[8],P=e.m[9],D=e.m[10],w=e.m[11],I=e.m[12],L=e.m[13],O=e.m[14],B=e.m[15];return t[r]=i*y+n*M+o*C+s*I,t[r+1]=i*x+n*T+o*P+s*L,t[r+2]=i*b+n*S+o*D+s*O,t[r+3]=i*A+n*E+o*w+s*B,t[r+4]=a*y+h*M+c*C+l*I,t[r+5]=a*x+h*T+c*P+l*L,t[r+6]=a*b+h*S+c*D+l*O,t[r+7]=a*A+h*E+c*w+l*B,t[r+8]=u*y+f*M+d*C+p*I,t[r+9]=u*x+f*T+d*P+p*L,t[r+10]=u*b+f*S+d*D+p*O,t[r+11]=u*A+f*E+d*w+p*B,t[r+12]=m*y+_*M+g*C+v*I,t[r+13]=m*x+_*T+g*P+v*L,t[r+14]=m*b+_*S+g*D+v*O,t[r+15]=m*A+_*E+g*w+v*B,this},t.prototype.multiplyToArraySIMD=function(e,t,r){void 0===r&&(r=0);var i=this.m,n=e.m,o=SIMD.float32x4.load(n,0),s=SIMD.float32x4.load(n,4),a=SIMD.float32x4.load(n,8),h=SIMD.float32x4.load(n,12),c=SIMD.float32x4.load(i,0);SIMD.float32x4.store(t,r+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(i,4);SIMD.float32x4.store(t,r+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(i,8);SIMD.float32x4.store(t,r+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(i,12);SIMD.float32x4.store(t,r+12,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,0,0,0,0),o),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,1,1,1,1),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,3,3,3,3),h)))))},t.prototype.equals=function(e){return e&&this.m[0]===e.m[0]&&this.m[1]===e.m[1]&&this.m[2]===e.m[2]&&this.m[3]===e.m[3]&&this.m[4]===e.m[4]&&this.m[5]===e.m[5]&&this.m[6]===e.m[6]&&this.m[7]===e.m[7]&&this.m[8]===e.m[8]&&this.m[9]===e.m[9]&&this.m[10]===e.m[10]&&this.m[11]===e.m[11]&&this.m[12]===e.m[12]&&this.m[13]===e.m[13]&&this.m[14]===e.m[14]&&this.m[15]===e.m[15]},t.prototype.clone=function(){return t.FromValues(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5],this.m[6],this.m[7],this.m[8],this.m[9],this.m[10],this.m[11],this.m[12],this.m[13],this.m[14],this.m[15]); },t.prototype.decompose=function(r,i,n){n.x=this.m[12],n.y=this.m[13],n.z=this.m[14];var o=e.Tools.Sign(this.m[0]*this.m[1]*this.m[2]*this.m[3])<0?-1:1,a=e.Tools.Sign(this.m[4]*this.m[5]*this.m[6]*this.m[7])<0?-1:1,h=e.Tools.Sign(this.m[8]*this.m[9]*this.m[10]*this.m[11])<0?-1:1;if(r.x=o*Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]+this.m[2]*this.m[2]),r.y=a*Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]+this.m[6]*this.m[6]),r.z=h*Math.sqrt(this.m[8]*this.m[8]+this.m[9]*this.m[9]+this.m[10]*this.m[10]),0===r.x||0===r.y||0===r.z)return i.x=0,i.y=0,i.z=0,i.w=1,!1;var c=t.FromValues(this.m[0]/r.x,this.m[1]/r.x,this.m[2]/r.x,0,this.m[4]/r.y,this.m[5]/r.y,this.m[6]/r.y,0,this.m[8]/r.z,this.m[9]/r.z,this.m[10]/r.z,0,0,0,0,1);return s.FromRotationMatrixToRef(c,i),!0},t.FromArray=function(e,r){var i=new t;return r||(r=0),t.FromArrayToRef(e,r,i),i},t.FromArrayToRef=function(e,t,r){for(var i=0;16>i;i++)r.m[i]=e[i+t]},t.FromValuesToRef=function(e,t,r,i,n,o,s,a,h,c,l,u,f,d,p,m,_){_.m[0]=e,_.m[1]=t,_.m[2]=r,_.m[3]=i,_.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},t.FromValues=function(e,r,i,n,o,s,a,h,c,l,u,f,d,p,m,_){var g=new t;return g.m[0]=e,g.m[1]=r,g.m[2]=i,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},t.Compose=function(e,r,i){var n=t.FromValues(e.x,0,0,0,0,e.y,0,0,0,0,e.z,0,0,0,0,1),o=t.Identity();return r.toRotationMatrix(o),n=n.multiply(o),n.setTranslation(i),n},t.Identity=function(){return t.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},t.IdentityToRef=function(e){t.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,e)},t.Zero=function(){return t.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},t.RotationX=function(e){var r=new t;return t.RotationXToRef(e,r),r},t.Invert=function(e){var r=new t;return e.invertToRef(r),r},t.RotationXToRef=function(e,t){var r=Math.sin(e),i=Math.cos(e);t.m[0]=1,t.m[15]=1,t.m[5]=i,t.m[10]=i,t.m[9]=-r,t.m[6]=r,t.m[1]=0,t.m[2]=0,t.m[3]=0,t.m[4]=0,t.m[7]=0,t.m[8]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},t.RotationY=function(e){var r=new t;return t.RotationYToRef(e,r),r},t.RotationYToRef=function(e,t){var r=Math.sin(e),i=Math.cos(e);t.m[5]=1,t.m[15]=1,t.m[0]=i,t.m[2]=-r,t.m[8]=r,t.m[10]=i,t.m[1]=0,t.m[3]=0,t.m[4]=0,t.m[6]=0,t.m[7]=0,t.m[9]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},t.RotationZ=function(e){var r=new t;return t.RotationZToRef(e,r),r},t.RotationZToRef=function(e,t){var r=Math.sin(e),i=Math.cos(e);t.m[10]=1,t.m[15]=1,t.m[0]=i,t.m[1]=r,t.m[4]=-r,t.m[5]=i,t.m[2]=0,t.m[3]=0,t.m[6]=0,t.m[7]=0,t.m[8]=0,t.m[9]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},t.RotationAxis=function(e,r){var i=Math.sin(-r),n=Math.cos(-r),o=1-n;e.normalize();var s=t.Zero();return s.m[0]=e.x*e.x*o+n,s.m[1]=e.x*e.y*o-e.z*i,s.m[2]=e.x*e.z*o+e.y*i,s.m[3]=0,s.m[4]=e.y*e.x*o+e.z*i,s.m[5]=e.y*e.y*o+n,s.m[6]=e.y*e.z*o-e.x*i,s.m[7]=0,s.m[8]=e.z*e.x*o-e.y*i,s.m[9]=e.z*e.y*o+e.x*i,s.m[10]=e.z*e.z*o+n,s.m[11]=0,s.m[15]=1,s},t.RotationYawPitchRoll=function(e,r,i){var n=new t;return t.RotationYawPitchRollToRef(e,r,i,n),n},t.RotationYawPitchRollToRef=function(e,t,r,i){s.RotationYawPitchRollToRef(e,t,r,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(i)},t.Scaling=function(e,r,i){var n=t.Zero();return t.ScalingToRef(e,r,i,n),n},t.ScalingToRef=function(e,t,r,i){i.m[0]=e,i.m[1]=0,i.m[2]=0,i.m[3]=0,i.m[4]=0,i.m[5]=t,i.m[6]=0,i.m[7]=0,i.m[8]=0,i.m[9]=0,i.m[10]=r,i.m[11]=0,i.m[12]=0,i.m[13]=0,i.m[14]=0,i.m[15]=1},t.Translation=function(e,r,i){var n=t.Identity();return t.TranslationToRef(e,r,i,n),n},t.TranslationToRef=function(e,r,i,n){t.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,e,r,i,1,n)},t.LookAtLH=function(e,r,i){var n=t.Zero();return t.LookAtLHToRef(e,r,i,n),n},t.LookAtLHToRef=function(e,r,i,o){r.subtractToRef(e,this._zAxis),this._zAxis.normalize(),n.CrossToRef(i,this._zAxis,this._xAxis),this._xAxis.normalize(),n.CrossToRef(this._zAxis,this._xAxis,this._yAxis),this._yAxis.normalize();var s=-n.Dot(this._xAxis,e),a=-n.Dot(this._yAxis,e),h=-n.Dot(this._zAxis,e);return t.FromValuesToRef(this._xAxis.x,this._yAxis.x,this._zAxis.x,0,this._xAxis.y,this._yAxis.y,this._zAxis.y,0,this._xAxis.z,this._yAxis.z,this._zAxis.z,0,s,a,h,1,o)},t.LookAtLHToRefSIMD=function(e,t,r,i){var n=i.m,o=SIMD.float32x4(t.x,t.y,t.z,0),s=SIMD.float32x4(e.x,e.y,e.z,0),a=SIMD.float32x4(r.x,r.y,r.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),A=SIMD.float32x4.neg(s);A=SIMD.float32x4.withW(A,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(A,0,0,0,0),m),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(A,1,1,1,1),_),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(A,2,2,2,2),g),SIMD.float32x4.mul(SIMD.float32x4.swizzle(A,3,3,3,3),v)))))},t.OrthoLH=function(e,r,i,n){var o=t.Zero();return t.OrthoLHToRef(e,r,i,n,o),o},t.OrthoLHToRef=function(e,r,i,n,o){var s=2/e,a=2/r,h=1/(n-i),c=i/(i-n);t.FromValuesToRef(s,0,0,0,0,a,0,0,0,0,h,0,0,0,c,1,o)},t.OrthoOffCenterLH=function(e,r,i,n,o,s){var a=t.Zero();return t.OrthoOffCenterLHToRef(e,r,i,n,o,s,a),a},t.OrthoOffCenterLHToRef=function(e,t,r,i,n,o,s){s.m[0]=2/(t-e),s.m[1]=s.m[2]=s.m[3]=0,s.m[5]=2/(i-r),s.m[4]=s.m[6]=s.m[7]=0,s.m[10]=-1/(n-o),s.m[8]=s.m[9]=s.m[11]=0,s.m[12]=(e+t)/(e-t),s.m[13]=(i+r)/(r-i),s.m[14]=n/(n-o),s.m[15]=1},t.PerspectiveLH=function(e,r,i,n){var o=t.Zero();return o.m[0]=2*i/e,o.m[1]=o.m[2]=o.m[3]=0,o.m[5]=2*i/r,o.m[4]=o.m[6]=o.m[7]=0,o.m[10]=-n/(i-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]=i*n/(i-n),o},t.PerspectiveFovLH=function(e,r,i,n){var o=t.Zero();return t.PerspectiveFovLHToRef(e,r,i,n,o),o},t.PerspectiveFovLHToRef=function(t,r,i,n,o,s){void 0===s&&(s=e.Camera.FOVMODE_VERTICAL_FIXED);var a=1/Math.tan(.5*t),h=s===e.Camera.FOVMODE_VERTICAL_FIXED;o.m[0]=h?a/r:a,o.m[1]=o.m[2]=o.m[3]=0,o.m[5]=h?a:a*r,o.m[4]=o.m[6]=o.m[7]=0,o.m[8]=o.m[9]=0,o.m[10]=-n/(i-n),o.m[11]=1,o.m[12]=o.m[13]=o.m[15]=0,o.m[14]=i*n/(i-n)},t.GetFinalMatrix=function(e,r,i,n,o,s){var a=e.width,h=e.height,c=e.x,l=e.y,u=t.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 r.multiply(i).multiply(n).multiply(u)},t.Transpose=function(e){var r=new t;return r.m[0]=e.m[0],r.m[1]=e.m[4],r.m[2]=e.m[8],r.m[3]=e.m[12],r.m[4]=e.m[1],r.m[5]=e.m[5],r.m[6]=e.m[9],r.m[7]=e.m[13],r.m[8]=e.m[2],r.m[9]=e.m[6],r.m[10]=e.m[10],r.m[11]=e.m[14],r.m[12]=e.m[3],r.m[13]=e.m[7],r.m[14]=e.m[11],r.m[15]=e.m[15],r},t.Reflection=function(e){var r=new t;return t.ReflectionToRef(e,r),r},t.ReflectionToRef=function(e,t){e.normalize();var r=e.normal.x,i=e.normal.y,n=e.normal.z,o=-2*r,s=-2*i,a=-2*n;t.m[0]=o*r+1,t.m[1]=s*r,t.m[2]=a*r,t.m[3]=0,t.m[4]=o*i,t.m[5]=s*i+1,t.m[6]=a*i,t.m[7]=0,t.m[8]=o*n,t.m[9]=s*n,t.m[10]=a*n+1,t.m[11]=0,t.m[12]=o*e.d,t.m[13]=s*e.d,t.m[14]=a*e.d,t.m[15]=1},t._tempQuaternion=new s,t._xAxis=n.Zero(),t._yAxis=n.Zero(),t._zAxis=n.Zero(),t}();e.Matrix=a;var h=function(){function e(e,t,r,i){this.normal=new n(e,t,r),this.d=i}return e.prototype.asArray=function(){return[this.normal.x,this.normal.y,this.normal.z,this.d]},e.prototype.clone=function(){return new e(this.normal.x,this.normal.y,this.normal.z,this.d)},e.prototype.normalize=function(){var e=Math.sqrt(this.normal.x*this.normal.x+this.normal.y*this.normal.y+this.normal.z*this.normal.z),t=0;return 0!==e&&(t=1/e),this.normal.x*=t,this.normal.y*=t,this.normal.z*=t,this.d*=t,this},e.prototype.transform=function(t){var r=a.Transpose(t),i=this.normal.x,n=this.normal.y,o=this.normal.z,s=this.d,h=i*r.m[0]+n*r.m[1]+o*r.m[2]+s*r.m[3],c=i*r.m[4]+n*r.m[5]+o*r.m[6]+s*r.m[7],l=i*r.m[8]+n*r.m[9]+o*r.m[10]+s*r.m[11],u=i*r.m[12]+n*r.m[13]+o*r.m[14]+s*r.m[15];return new e(h,c,l,u)},e.prototype.dotCoordinate=function(e){return this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z+this.d},e.prototype.copyFromPoints=function(e,t,r){var i,n=t.x-e.x,o=t.y-e.y,s=t.z-e.z,a=r.x-e.x,h=r.y-e.y,c=r.z-e.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 i=0!==d?1/d:0,this.normal.x=l*i,this.normal.y=u*i,this.normal.z=f*i,this.d=-(this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z),this},e.prototype.isFrontFacingTo=function(e,t){var r=n.Dot(this.normal,e);return t>=r},e.prototype.signedDistanceTo=function(e){return n.Dot(e,this.normal)+this.d},e.FromArray=function(t){return new e(t[0],t[1],t[2],t[3])},e.FromPoints=function(t,r,i){var n=new e(0,0,0,0);return n.copyFromPoints(t,r,i),n},e.FromPositionAndNormal=function(t,r){var i=new e(0,0,0,0);return r.normalize(),i.normal=r,i.d=-(r.x*t.x+r.y*t.y+r.z*t.z),i},e.SignedDistanceToPlaneFromPositionAndNormal=function(e,t,r){var i=-(t.x*e.x+t.y*e.y+t.z*e.z);return n.Dot(r,t)+i},e}();e.Plane=h;var c=function(){function e(e,t,r,i){this.x=e,this.y=t,this.width=r,this.height=i}return e.prototype.toGlobal=function(t){var r=t.getRenderWidth(),i=t.getRenderHeight();return new e(this.x*r,this.y*i,this.width*r,this.height*i)},e}();e.Viewport=c;var l=function(){function e(){}return e.GetPlanes=function(t){for(var r=[],i=0;6>i;i++)r.push(new h(0,0,0,0));return e.GetPlanesToRef(t,r),r},e.GetPlanesToRef=function(e,t){t[0].normal.x=e.m[3]+e.m[2],t[0].normal.y=e.m[7]+e.m[6],t[0].normal.z=e.m[10]+e.m[10],t[0].d=e.m[15]+e.m[14],t[0].normalize(),t[1].normal.x=e.m[3]-e.m[2],t[1].normal.y=e.m[7]-e.m[6],t[1].normal.z=e.m[11]-e.m[10],t[1].d=e.m[15]-e.m[14],t[1].normalize(),t[2].normal.x=e.m[3]+e.m[0],t[2].normal.y=e.m[7]+e.m[4],t[2].normal.z=e.m[11]+e.m[8],t[2].d=e.m[15]+e.m[12],t[2].normalize(),t[3].normal.x=e.m[3]-e.m[0],t[3].normal.y=e.m[7]-e.m[4],t[3].normal.z=e.m[11]-e.m[8],t[3].d=e.m[15]-e.m[12],t[3].normalize(),t[4].normal.x=e.m[3]-e.m[1],t[4].normal.y=e.m[7]-e.m[5],t[4].normal.z=e.m[11]-e.m[9],t[4].d=e.m[15]-e.m[13],t[4].normalize(),t[5].normal.x=e.m[3]+e.m[1],t[5].normal.y=e.m[7]+e.m[5],t[5].normal.z=e.m[11]+e.m[9],t[5].d=e.m[15]+e.m[13],t[5].normalize()},e}();e.Frustum=l;var u=function(){function t(e,t,r){void 0===r&&(r=Number.MAX_VALUE),this.origin=e,this.direction=t,this.length=r}return t.prototype.intersectsBoxMinMax=function(e,t){var r=0,i=Number.MAX_VALUE;if(Math.abs(this.direction.x)<1e-7){if(this.origin.xt.x)return!1}else{var n=1/this.direction.x,o=(e.x-this.origin.x)*n,s=(t.x-this.origin.x)*n;if(s===-(1/0)&&(s=1/0),o>s){var a=o;o=s,s=a}if(r=Math.max(o,r),i=Math.min(s,i),r>i)return!1}if(Math.abs(this.direction.y)<1e-7){if(this.origin.yt.y)return!1}else if(n=1/this.direction.y,o=(e.y-this.origin.y)*n,s=(t.y-this.origin.y)*n,s===-(1/0)&&(s=1/0),o>s&&(a=o,o=s,s=a),r=Math.max(o,r),i=Math.min(s,i),r>i)return!1;if(Math.abs(this.direction.z)<1e-7){if(this.origin.zt.z)return!1}else if(n=1/this.direction.z,o=(e.z-this.origin.z)*n,s=(t.z-this.origin.z)*n,s===-(1/0)&&(s=1/0),o>s&&(a=o,o=s,s=a),r=Math.max(o,r),i=Math.min(s,i),r>i)return!1;return!0},t.prototype.intersectsBox=function(e){return this.intersectsBoxMinMax(e.minimum,e.maximum)},t.prototype.intersectsSphere=function(e){var t=e.center.x-this.origin.x,r=e.center.y-this.origin.y,i=e.center.z-this.origin.z,n=t*t+r*r+i*i,o=e.radius*e.radius;if(o>=n)return!0;var s=t*this.direction.x+r*this.direction.y+i*this.direction.z;if(0>s)return!1;var a=n-s*s;return o>=a},t.prototype.intersectsTriangle=function(t,r,i){this._edge1||(this._edge1=n.Zero(),this._edge2=n.Zero(),this._pvec=n.Zero(),this._tvec=n.Zero(),this._qvec=n.Zero()),r.subtractToRef(t,this._edge1),i.subtractToRef(t,this._edge2),n.CrossToRef(this.direction,this._edge2,this._pvec);var o=n.Dot(this._edge1,this._pvec);if(0===o)return null;var s=1/o;this.origin.subtractToRef(t,this._tvec);var a=n.Dot(this._tvec,this._pvec)*s;if(0>a||a>1)return null;n.CrossToRef(this._tvec,this._edge1,this._qvec);var h=n.Dot(this.direction,this._qvec)*s;if(0>h||a+h>1)return null;var c=n.Dot(this._edge2,this._qvec)*s;return c>this.length?null:new e.IntersectionInfo(a,h,c)},t.CreateNew=function(e,r,i,o,s,a,h){var c=n.Unproject(new n(e,r,0),i,o,s,a,h),l=n.Unproject(new n(e,r,1),i,o,s,a,h),u=l.subtract(c);return u.normalize(),new t(c,u)},t.CreateNewFromTo=function(e,r,i){void 0===i&&(i=a.Identity());var n=r.subtract(e),o=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z);return n.normalize(),t.Transform(new t(e,n,o),i)},t.Transform=function(e,r){var i=n.TransformCoordinates(e.origin,r),o=n.TransformNormal(e.direction,r);return new t(i,o,e.length)},t}();e.Ray=u,function(e){e[e.LOCAL=0]="LOCAL",e[e.WORLD=1]="WORLD"}(e.Space||(e.Space={}));var f=(e.Space,function(){function e(){}return e.X=new n(1,0,0),e.Y=new n(0,1,0),e.Z=new n(0,0,1),e}());e.Axis=f;var d=function(){function e(){}return e.interpolate=function(e,t,r,i,n){for(var o=1-3*i+3*t,s=3*i-6*t,a=3*t,h=e,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-e)*d,h=Math.min(1,Math.max(0,h))}return 3*Math.pow(1-h,2)*h*r+3*(1-h)*Math.pow(h,2)*n+Math.pow(h,3)},e}();e.BezierCurve=d,function(e){e[e.CW=0]="CW",e[e.CCW=1]="CCW"}(e.Orientation||(e.Orientation={}));var p=e.Orientation,m=function(){function e(e){var t=this;this.degrees=function(){return 180*t._radians/Math.PI},this.radians=function(){return t._radians},this._radians=e,this._radians<0&&(this._radians+=2*Math.PI)}return e.BetweenTwoPoints=function(t,r){var i=r.subtract(t),n=Math.atan2(i.y,i.x);return new e(n)},e.FromRadians=function(t){return new e(t)},e.FromDegrees=function(t){return new e(t*Math.PI/180)},e}();e.Angle=m;var _=function(){function e(e,t,r){this.startPoint=e,this.midPoint=t,this.endPoint=r;var n=Math.pow(t.x,2)+Math.pow(t.y,2),o=(Math.pow(e.x,2)+Math.pow(e.y,2)-n)/2,s=(n-Math.pow(r.x,2)-Math.pow(r.y,2))/2,a=(e.x-t.x)*(t.y-r.y)-(t.x-r.x)*(e.y-t.y);this.centerPoint=new i((o*(t.y-r.y)-s*(e.y-t.y))/a,((e.x-t.x)*s-(t.x-r.x)*o)/a),this.radius=this.centerPoint.subtract(this.startPoint).length(),this.startAngle=m.BetweenTwoPoints(this.centerPoint,this.startPoint);var h=this.startAngle.degrees(),c=m.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),l=m.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?p.CW:p.CCW,this.angle=m.FromDegrees(this.orientation===p.CW?h-l:l-h)}return e}();e.Arc2=_;var g=function(){function e(e){this.path=e,this._onchange=new Array,this.value=0,this.animations=new Array}return e.prototype.getPoint=function(){var e=this.path.getPointAtLengthPosition(this.value);return new n(e.x,0,e.y)},e.prototype.moveAhead=function(e){return void 0===e&&(e=.002),this.move(e),this},e.prototype.moveBack=function(e){return void 0===e&&(e=.002),this.move(-e),this},e.prototype.move=function(e){if(Math.abs(e)>1)throw"step size should be less than 1.";return this.value+=e,this.ensureLimits(),this.raiseOnChange(),this},e.prototype.ensureLimits=function(){for(;this.value>1;)this.value-=1;for(;this.value<0;)this.value+=1;return this},e.prototype.markAsDirty=function(e){return this.ensureLimits(),this.raiseOnChange(),this},e.prototype.raiseOnChange=function(){var e=this;return this._onchange.forEach(function(t){return t(e)}),this},e.prototype.onchange=function(e){return this._onchange.push(e),this},e}();e.PathCursor=g;var v=function(){function t(e,t){this._points=new Array,this._length=0,this.closed=!1,this._points.push(new i(e,t))}return t.prototype.addLineTo=function(t,r){if(closed)return e.Tools.Error("cannot add lines to closed paths"),this;var n=new i(t,r),o=this._points[this._points.length-1];return this._points.push(n),this._length+=n.subtract(o).length(),this},t.prototype.addArcTo=function(t,r,n,o,s){if(void 0===s&&(s=36),closed)return e.Tools.Error("cannot add arcs to closed paths"),this;var a=this._points[this._points.length-1],h=new i(t,r),c=new i(n,o),l=new _(a,h,c),u=l.angle.radians()/s;l.orientation===p.CW&&(u*=-1);for(var f=l.startAngle.radians()+u,d=0;s>d;d++){var m=Math.cos(f)*l.radius+l.centerPoint.x,g=Math.sin(f)*l.radius+l.centerPoint.y;this.addLineTo(m,g),f+=u}return this},t.prototype.close=function(){return this.closed=!0,this},t.prototype.length=function(){var e=this._length;if(!this.closed){var t=this._points[this._points.length-1],r=this._points[0];e+=r.subtract(t).length()}return e},t.prototype.getPoints=function(){return this._points},t.prototype.getPointAtLengthPosition=function(t){if(0>t||t>1)return e.Tools.Error("normalized length position should be between 0 and 1."),i.Zero();for(var r=t*this.length(),n=0,o=0;o=n&&l>=r){var u=c.normalize(),f=r-n;return new i(a.x+u.x*f,a.y+u.y*f)}n=l}return e.Tools.Error("internal error"),i.Zero()},t.StartingAt=function(e,r){return new t(e,r)},t}();e.Path2=v;var y=function(){function e(e,t){this.path=e,this._curve=new Array,this._distances=new Array,this._tangents=new Array,this._normals=new Array,this._binormals=new Array;for(var r=0;rl;l++)o=this._getLastNonNullVector(l),t-1>l&&(s=this._getFirstNonNullVector(l),this._tangents[l]=o.add(s),this._tangents[l].normalize()),this._distances[l]=this._distances[l-1]+o.length(),a=this._tangents[l],h=this._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()},e.prototype._getFirstNonNullVector=function(e){for(var t=1,r=this._curve[e+t].subtract(this._curve[e]);0==r.length()&&e+t+1t+1;)t++,r=this._curve[e].subtract(this._curve[e-t]);return r},e.prototype._normalVector=function(e,t,r){var i;if(void 0===r||null===r){var o;1!==t.y?o=new n(0,-1,0):1!==t.x?o=new n(1,0,0):1!==t.z&&(o=new n(0,0,1)),i=n.Cross(t,o)}else i=n.Cross(t,r),n.CrossToRef(i,t,i);return i.normalize(),i},e}();e.Path3D=y;var x=function(){function t(e){this._length=0,this._points=e,this._length=this._computeLength(e)}return t.CreateQuadraticBezier=function(e,r,i,o){o=o>2?o:3;for(var s=new Array,a=function(e,t,r,i){var n=(1-e)*(1-e)*t+2*e*(1-e)*r+e*e*i;return n},h=0;o>=h;h++)s.push(new n(a(h/o,e.x,r.x,i.x),a(h/o,e.y,r.y,i.y),a(h/o,e.z,r.z,i.z)));return new t(s)},t.CreateCubicBezier=function(e,r,i,o,s){s=s>3?s:4;for(var a=new Array,h=function(e,t,r,i,n){var o=(1-e)*(1-e)*(1-e)*t+3*e*(1-e)*(1-e)*r+3*e*e*(1-e)*i+e*e*e*n;return o},c=0;s>=c;c++)a.push(new n(h(c/s,e.x,r.x,i.x,o.x),h(c/s,e.y,r.y,i.y,o.y),h(c/s,e.z,r.z,i.z,o.z)));return new t(a)},t.CreateHermiteSpline=function(r,i,n,o,s){for(var a=new Array,h=1/s,c=0;s>=c;c++)a.push(e.Vector3.Hermite(r,i,n,o,c*h));return new t(a)},t.prototype.getPoints=function(){return this._points},t.prototype.length=function(){return this._length},t.prototype["continue"]=function(e){for(var r=this._points[this._points.length-1],i=this._points.slice(),n=e.getPoints(),o=1;oo.data?(n.mustUpdateRessources=!0,i()):r(o.data):(n.mustUpdateRessources=!0,i())},s.onabort=function(e){r(-1)};var a=s.objectStore("versions").get(t);a.onsuccess=function(e){o=e.target.result},a.onerror=function(i){e.Tools.Error("Error loading version for scene "+t+" from DB."),r(-1)}}catch(h){e.Tools.Error("Error while accessing 'versions' object store (READ OP). Exception: "+h.message),r(-1)}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),r(-1)},t.prototype._saveVersionIntoDBAsync=function(t,r){var i=this;if(this.isSupported&&!this.hasReachedQuota)try{var n=this.db.transaction(["versions"],"readwrite");n.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(i.hasReachedQuota=!0)}catch(t){}r(-1)},n.oncomplete=function(e){r(i.manifestVersionFound)};var o={sceneUrl:t,data:this.manifestVersionFound},s=n.objectStore("versions").put(o);s.onsuccess=function(e){},s.onerror=function(t){e.Tools.Error("Error in DB add version request in BABYLON.Database.")}}catch(a){e.Tools.Error("Error while accessing 'versions' object store (WRITE OP). Exception: "+a.message),r(-1)}else r(-1)},t.prototype.loadFileFromDB=function(e,r,i,n,o){var s=this,a=t.ReturnFullUrlLocation(e),h=function(e){s._saveFileIntoDBAsync(a,r,i)};this._checkVersionFromDB(a,function(e){-1!==e?s.mustUpdateRessources?s._saveFileIntoDBAsync(a,r,i,o):s._loadFileFromDBAsync(a,r,h,o):n()})},t.prototype._loadFileFromDBAsync=function(t,r,i,n){if(this.isSupported){var o;o=-1!==t.indexOf(".babylon")?"scenes":"textures";var s,a=this.db.transaction([o]);a.oncomplete=function(e){s?r(s.data):i()},a.onabort=function(e){i()};var h=a.objectStore(o).get(t);h.onsuccess=function(e){s=e.target.result},h.onerror=function(r){e.Tools.Error("Error loading file "+t+" from DB."),i()}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),r()},t.prototype._saveFileIntoDBAsync=function(t,r,i,n){var o=this;if(this.isSupported){var s;s=-1!==t.indexOf(".babylon")?"scenes":"textures";var a,h=new XMLHttpRequest;h.open("GET",t,!0),n&&(h.responseType="arraybuffer"),h.onprogress=i,h.addEventListener("load",function(){if(200===h.status||e.Tools.ValidateXHRData(h,n?6:1))if(a=n?h.response:h.responseText,o.hasReachedQuota)r(a);else{var i=o.db.transaction([s],"readwrite");i.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(t){}r(a)},i.oncomplete=function(e){r(a)};var c;c="scenes"===s?{sceneUrl:t,data:a,version:o.manifestVersionFound}:{textureUrl:t,data:a};try{var l=i.objectStore(s).put(c);l.onsuccess=function(e){},l.onerror=function(t){e.Tools.Error("Error in DB add file request in BABYLON.Database.")}}catch(u){r(a)}}else r()},!1),h.addEventListener("error",function(t){e.Tools.Error("error on XHR request."),r()},!1),h.send()}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),r()},t.isUASupportingBlobStorage=!0,t.parseURL=function(e){var t=document.createElement("a");t.href=e;var r=e.substring(0,e.lastIndexOf("#")),i=e.substring(r.lastIndexOf("/")+1,e.length),n=e.substring(0,e.indexOf(i,0)); return n},t.ReturnFullUrlLocation=function(t){return-1===t.indexOf("http:/")?e.Database.parseURL(window.location.href)+t:t},t}();e.Database=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){var r=function(){function t(){}return t.GetTGAHeader=function(e){var t=0,r={id_length:e[t++],colormap_type:e[t++],image_type:e[t++],colormap_index:e[t++]|e[t++]<<8,colormap_length:e[t++]|e[t++]<<8,colormap_size:e[t++],origin:[e[t++]|e[t++]<<8,e[t++]|e[t++]<<8],width:e[t++]|e[t++]<<8,height:e[t++]|e[t++]<<8,pixel_size:e[t++],flags:e[t++]};return r},t.UploadContent=function(r,i){if(i.length<19)return void e.Tools.Error("Unable to load TGA file - Not enough data to contain header");var n=18,o=t.GetTGAHeader(i);if(o.id_length+n>i.length)return void e.Tools.Error("Unable to load TGA file - Not enough data");n+=o.id_length;var s=!1,a=!1,h=!1,c=!1;switch(o.image_type){case t._TYPE_RLE_INDEXED:s=!0;case t._TYPE_INDEXED:a=!0;break;case t._TYPE_RLE_RGB:s=!0;case t._TYPE_RGB:h=!0;break;case t._TYPE_RLE_GREY:s=!0;case t._TYPE_GREY:c=!0}var l,u,f=(15&o.flags,o.pixel_size>>3),d=o.width*o.height*f;if(a&&(u=i.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=i[n++],m=(127&p)+1,128&p){for(_=0;f>_;++_)v[_]=i[n++];for(_=0;m>_;++_)l.set(v,g+_*f);g+=f*m}else{for(m*=f,_=0;m>_;++_)l[g+_]=i[n++];g+=m}}else l=i.subarray(n,n+=a?o.width*o.height:d);var y,x,b,A,M,T;switch((o.flags&t._ORIGIN_MASK)>>t._ORIGIN_SHIFT){default:case t._ORIGIN_UL:y=0,b=1,T=o.width,x=0,A=1,M=o.height;break;case t._ORIGIN_BL:y=0,b=1,T=o.width,x=o.height-1,A=-1,M=-1;break;case t._ORIGIN_UR:y=o.width-1,b=-1,T=-1,x=0,A=1,M=o.height;break;case t._ORIGIN_BR:y=o.width-1,b=-1,T=-1,x=o.height-1,A=-1,M=-1}var S="_getImageData"+(c?"Grey":"")+o.pixel_size+"bits",E=t[S](o,u,l,x,A,M,y,b,T);r.texImage2D(r.TEXTURE_2D,0,r.RGBA,o.width,o.height,0,r.RGBA,r.UNSIGNED_BYTE,E)},t._getImageData8bits=function(e,t,r,i,n,o,s,a,h){var c,l,u,f=r,d=t,p=e.width,m=e.height,_=0,g=new Uint8Array(p*m*4);for(u=i;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},t._getImageData16bits=function(e,t,r,i,n,o,s,a,h){var c,l,u,f=r,d=e.width,p=e.height,m=0,_=new Uint8Array(d*p*4);for(u=i;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 _},t._getImageData24bits=function(e,t,r,i,n,o,s,a,h){var c,l,u=r,f=e.width,d=e.height,p=0,m=new Uint8Array(f*d*4);for(l=i;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},t._getImageData32bits=function(e,t,r,i,n,o,s,a,h){var c,l,u=r,f=e.width,d=e.height,p=0,m=new Uint8Array(f*d*4);for(l=i;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},t._getImageDataGrey8bits=function(e,t,r,i,n,o,s,a,h){var c,l,u,f=r,d=e.width,p=e.height,m=0,_=new Uint8Array(d*p*4);for(u=i;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 _},t._getImageDataGrey16bits=function(e,t,r,i,n,o,s,a,h){var c,l,u=r,f=e.width,d=e.height,p=0,m=new Uint8Array(f*d*4);for(l=i;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},t._TYPE_NO_DATA=0,t._TYPE_INDEXED=1,t._TYPE_RGB=2,t._TYPE_GREY=3,t._TYPE_RLE_INDEXED=9,t._TYPE_RLE_RGB=10,t._TYPE_RLE_GREY=11,t._ORIGIN_MASK=48,t._ORIGIN_SHIFT=4,t._ORIGIN_BL=0,t._ORIGIN_BR=1,t._ORIGIN_UL=2,t._ORIGIN_UR=3,t}();t.TGATools=r}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){function r(e){return e.charCodeAt(0)+(e.charCodeAt(1)<<8)+(e.charCodeAt(2)<<16)+(e.charCodeAt(3)<<24)}function i(e){return String.fromCharCode(255&e,e>>8&255,e>>16&255,e>>24&255)}var n=542327876,o=131072,s=512,a=4,h=64,c=131072,l=r("DXT1"),u=r("DXT3"),f=r("DXT5"),d=31,p=0,m=1,_=2,g=3,v=4,y=7,x=20,b=21,A=22,M=28,T=function(){function t(){}return t.GetDDSInfo=function(e){var t=new Int32Array(e,0,d),r=1;return t[_]&o&&(r=Math.max(1,t[y])),{width:t[v],height:t[g],mipmapCount:r,isFourCC:(t[x]&a)===a,isRGB:(t[x]&h)===h,isLuminance:(t[x]&c)===c,isCube:(t[M]&s)===s}},t.GetRGBAArrayBuffer=function(e,t,r,i,n){for(var o=new Uint8Array(i),s=new Uint8Array(n),a=0,h=t-1;h>=0;h--)for(var c=0;e>c;c++){var l=r+4*(c+h*e);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},t.GetRGBArrayBuffer=function(e,t,r,i,n){for(var o=new Uint8Array(i),s=new Uint8Array(n),a=0,h=t-1;h>=0;h--)for(var c=0;e>c;c++){var l=r+3*(c+h*e);o[a+2]=s[l],o[a+1]=s[l+1],o[a]=s[l+2],a+=3}return o},t.GetLuminanceArrayBuffer=function(e,t,r,i,n){for(var o=new Uint8Array(i),s=new Uint8Array(n),a=0,h=t-1;h>=0;h--)for(var c=0;e>c;c++){var l=r+(c+h*e);o[a]=s[l],a++}return o},t.UploadDDSLevels=function(r,s,a,h,c,x){var M,T,S,E,C,P,D,w,I,L,O=new Int32Array(a,0,d);if(O[p]!=n)return void e.Tools.Error("Invalid magic number in DDS header");if(!h.isFourCC&&!h.isRGB&&!h.isLuminance)return void e.Tools.Error("Unsupported format, must contain a FourCC, RGB or LUMINANCE code");if(h.isFourCC)switch(M=O[b]){case l:T=8,S=s.COMPRESSED_RGBA_S3TC_DXT1_EXT;break;case u:T=16,S=s.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case f:T=16,S=s.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;default:return void console.error("Unsupported FourCC code:",i(M))}I=1,O[_]&o&&c!==!1&&(I=Math.max(1,O[y]));for(var B=O[A],R=0;x>R;R++){var F=1==x?r.TEXTURE_2D:r.TEXTURE_CUBE_MAP_POSITIVE_X+R;for(E=O[v],C=O[g],D=O[m]+4,L=0;I>L;++L){if(h.isRGB)24==B?(P=E*C*3,w=t.GetRGBArrayBuffer(E,C,D,P,a),r.texImage2D(F,L,r.RGB,E,C,0,r.RGB,r.UNSIGNED_BYTE,w)):(P=E*C*4,w=t.GetRGBAArrayBuffer(E,C,D,P,a),r.texImage2D(F,L,r.RGBA,E,C,0,r.RGBA,r.UNSIGNED_BYTE,w));else if(h.isLuminance){var V=r.getParameter(r.UNPACK_ALIGNMENT),N=E,k=Math.floor((E+V-1)/V)*V;P=k*(C-1)+N,w=t.GetLuminanceArrayBuffer(E,C,D,P,a),r.texImage2D(F,L,r.LUMINANCE,E,C,0,r.LUMINANCE,r.UNSIGNED_BYTE,w)}else P=Math.max(4,E)/4*Math.max(4,C)/4*T,w=new Uint8Array(a,D,P),r.compressedTexImage2D(F,L,S,E,C,0,w);D+=P,E*=.5,C*=.5,E=Math.max(1,E),C=Math.max(1,C)}}},t}();t.DDSTools=T}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(t){this.length=0,this._duplicateId=0,this.data=new Array(t),this._id=e._GlobalId++}return e.prototype.push=function(e){this.data[this.length++]=e,this.length>this.data.length&&(this.data.length*=2),e.__smartArrayFlags||(e.__smartArrayFlags={}),e.__smartArrayFlags[this._id]=this._duplicateId},e.prototype.pushNoDuplicate=function(e){e.__smartArrayFlags&&e.__smartArrayFlags[this._id]===this._duplicateId||this.push(e)},e.prototype.sort=function(e){this.data.sort(e)},e.prototype.reset=function(){this.length=0,this._duplicateId++},e.prototype.concat=function(e){if(0!==e.length){this.length+e.length>this.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;tthis.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t=this.length?-1:t},e._GlobalId=0,e}();e.SmartArray=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){void 0===e&&(e=10),this.count=0,this._initialCapacity=e,this.items={},this._keys=new Array(this._initialCapacity)}return e.prototype.add=function(e,t){return void 0!=this.items[e]?-1:(this.items[e]=t,this._keys[this.count++]=e,this.count>this._keys.length&&(this._keys.length*=2),this.count)},e.prototype.remove=function(e){return void 0==this.items[e]?-1:this.removeItemOfIndex(this.indexOf(e))},e.prototype.removeItemOfIndex=function(e){if(!(e-1))return-1;for(delete this.items[this._keys[e]];e0){for(var e=new Array(this.count),t=0;t-1?this._keys[e]:void 0},e.prototype.getItemByIndex=function(e){return e-1?this.items[this._keys[e]]:void 0},e.prototype.empty=function(){this.count>0&&(this.count=0,this.items={},this._keys=new Array(this._initialCapacity))},e.prototype.forEach=function(e){var t;for(t in this.items)this.items.hasOwnProperty(t)&&e(this.items[t])},e}();e.SmartCollection=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t,r=function(t,r){return t?t instanceof e.Mesh?null:t instanceof e.SubMesh?t.clone(r):t.clone?t.clone():null:null},i=function(){function i(){}return i.SetImmediate=function(e){window.setImmediate?window.setImmediate(e):setTimeout(e,1)},i.IsExponantOfTwo=function(e){var t=1;do t*=2;while(e>t);return t===e},i.GetExponantOfTwo=function(e,t){var r=1;do r*=2;while(e>r);return r>t&&(r=t),r},i.GetFilename=function(e){var t=e.lastIndexOf("/");return 0>t?e:e.substring(t+1)},i.GetDOMTextContent=function(e){for(var t="",r=e.firstChild;r;)3===r.nodeType&&(t+=r.textContent),r=r.nextSibling;return t},i.ToDegrees=function(e){return 180*e/Math.PI},i.ToRadians=function(e){return e*Math.PI/180},i.ExtractMinAndMaxIndexed=function(t,r,i,n){for(var o=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),s=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),a=i;i+n>a;a++){var h=new e.Vector3(t[3*r[a]],t[3*r[a]+1],t[3*r[a]+2]);o=e.Vector3.Minimize(h,o),s=e.Vector3.Maximize(h,s)}return{minimum:o,maximum:s}},i.ExtractMinAndMax=function(t,r,i){for(var n=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),o=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),s=r;r+i>s;s++){var a=new e.Vector3(t[3*s],t[3*s+1],t[3*s+2]);n=e.Vector3.Minimize(a,n),o=e.Vector3.Maximize(a,o)}return{minimum:n,maximum:o}},i.MakeArray=function(e,t){return t===!0||void 0!==e&&null!=e?Array.isArray(e)?e:[e]:void 0},i.GetPointerPrefix=function(){var e="pointer";return navigator.pointerEnabled||(e="mouse"),e},i.QueueNewFrame=function(e){window.requestAnimationFrame?window.requestAnimationFrame(e):window.msRequestAnimationFrame?window.msRequestAnimationFrame(e):window.webkitRequestAnimationFrame?window.webkitRequestAnimationFrame(e):window.mozRequestAnimationFrame?window.mozRequestAnimationFrame(e):window.oRequestAnimationFrame?window.oRequestAnimationFrame(e):window.setTimeout(e,16)},i.RequestFullscreen=function(e){e.requestFullscreen?e.requestFullscreen():e.msRequestFullscreen?e.msRequestFullscreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.mozRequestFullScreen&&e.mozRequestFullScreen()},i.ExitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.msCancelFullScreen&&document.msCancelFullScreen()},i.CleanUrl=function(e){return e=e.replace(/#/gm,"%23")},i.LoadImage=function(t,r,n,o){t=i.CleanUrl(t);var s=new Image;"data:"!==t.substr(0,5)&&(s.crossOrigin="anonymous"),s.onload=function(){r(s)},s.onerror=function(e){n(s,e)};var a=function(){s.src=t},h=function(){o.loadImageFromDB(t,s)};if(o&&o.enableTexturesOffline&&e.Database.isUASupportingBlobStorage)o.openAsync(h,a);else if(-1===t.indexOf("file:"))a();else try{var c,l=t.substring(5);try{c=URL.createObjectURL(e.FilesInput.FilesTextures[l],{oneTimeOnly:!0})}catch(u){c=URL.createObjectURL(e.FilesInput.FilesTextures[l])}s.src=c}catch(f){i.Log("Error while trying to load texture: "+l),s.src=null}return s},i.LoadFile=function(t,r,n,o,s,a){t=i.CleanUrl(t);var h=function(){var e=new XMLHttpRequest,o=i.BaseUrl+t;e.open("GET",o,!0),s&&(e.responseType="arraybuffer"),e.onprogress=n,e.onreadystatechange=function(){if(4===e.readyState)if(200===e.status||i.ValidateXHRData(e,s?6:1))r(s?e.response:e.responseText);else{if(!a)throw new Error("Error status: "+e.status+" - Unable to load "+o);a()}},e.send(null)},c=function(){o.loadFileFromDB(t,r,n,h,s)};if(-1!==t.indexOf("file:")){var l=t.substring(5);i.ReadFile(e.FilesInput.FilesToLoad[l],r,n,!0)}else o&&o.enableSceneOffline?o.openAsync(c,h):h()},i.ReadFileAsDataURL=function(e,t,r){var i=new FileReader;i.onload=function(e){t(e.target.result)},i.onprogress=r,i.readAsDataURL(e)},i.ReadFile=function(e,t,r,n){var o=new FileReader;o.onerror=function(r){i.Log("Error while reading file: "+e.name),t(JSON.stringify({autoClear:!0,clearColor:[1,0,0],ambientColor:[0,0,0],gravity:[0,-9.81,0],meshes:[],cameras:[],lights:[]}))},o.onload=function(e){t(e.target.result)},o.onprogress=r,n?o.readAsArrayBuffer(e):o.readAsText(e)},i.Clamp=function(e,t,r){return void 0===t&&(t=0),void 0===r&&(r=1),Math.min(r,Math.max(t,e))},i.Sign=function(e){return e=+e,0===e||isNaN(e)?e:e>0?1:-1},i.Format=function(e,t){return void 0===t&&(t=2),e.toFixed(t)},i.CheckExtends=function(e,t,r){e.xr.x&&(r.x=e.x),e.y>r.y&&(r.y=e.y),e.z>r.z&&(r.z=e.z)},i.WithinEpsilon=function(e,t,r){void 0===r&&(r=1.401298e-45);var i=e-t;return i>=-r&&r>=i},i.DeepCopy=function(e,t,i,n){for(var o in e)if(("_"!==o[0]||n&&-1!==n.indexOf(o))&&(!i||-1===i.indexOf(o))){var s=e[o],a=typeof s;if("function"!==a)if("object"===a)if(s instanceof Array){if(t[o]=[],s.length>0)if("object"==typeof s[0])for(var h=0;ha;a++)for(var h=0;n>h;h++){var c=h+a*n,l=r-a-1,u=h+l*n,f=s[c];s[c]=s[u],s[u]=f}t||(t=document.createElement("canvas")),t.width=e,t.height=r;var d=t.getContext("2d"),p=d.createImageData(e,r),m=p.data;m.set(s),d.putImageData(p,0,0);var _=t.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)}},i.CreateScreenshot=function(t,r,n){var o,s,a=r.getScene(),h=null;if(a.activeCamera!==r&&(h=a.activeCamera,a.activeCamera=r),n.precision)o=Math.round(t.getRenderWidth()*n.precision),s=Math.round(o/t.getAspectRatio(r)),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/t.getAspectRatio(r)),n={width:o,height:s};else if(n.height&&!n.width)s=n.height,o=Math.round(s*t.getAspectRatio(r)),n={width:o,height:s};else{if(isNaN(n))return void i.Error("Invalid 'size' parameter !");s=n,o=n}var c=new e.RenderTargetTexture("screenShot",n,a,!1,!1);c.renderList=a.meshes,c.onAfterRender=function(){i.DumpFramebuffer(o,s,t)},a.incrementRenderId(),c.render(!0),c.dispose(),h&&(a.activeCamera=h)},i.ValidateXHRData=function(t,r){void 0===r&&(r=7);try{if(1&r){if(t.responseText&&t.responseText.length>0)return!0;if(1===r)return!1}if(2&r){var i=e.Internals.TGATools.GetTGAHeader(t.response);if(i.width&&i.height&&i.width>0&&i.height>0)return!0;if(2===r)return!1}if(4&r){var n=new Uint8Array(t.response,0,3);return 68===n[0]&&68===n[1]&&83===n[2]?!0:!1}}catch(o){}return!1},Object.defineProperty(i,"NoneLogLevel",{get:function(){return i._NoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"MessageLogLevel",{get:function(){return i._MessageLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"WarningLogLevel",{get:function(){return i._WarningLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ErrorLogLevel",{get:function(){return i._ErrorLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"AllLogLevel",{get:function(){return i._MessageLogLevel|i._WarningLogLevel|i._ErrorLogLevel},enumerable:!0,configurable:!0}),i._AddLogEntry=function(e){i._LogCache=e+i._LogCache,i.OnNewCacheEntry&&i.OnNewCacheEntry(e)},i._FormatMessage=function(e){var t=function(e){return 10>e?"0"+e:""+e},r=new Date;return"["+t(r.getHours())+":"+t(r.getMinutes())+":"+t(r.getSeconds())+"]: "+e},i._LogDisabled=function(e){},i._LogEnabled=function(e){var t=i._FormatMessage(e);console.log("BJS - "+t);var r="
"+t+"

";i._AddLogEntry(r)},i._WarnDisabled=function(e){},i._WarnEnabled=function(e){var t=i._FormatMessage(e);console.warn("BJS - "+t);var r="
"+t+"

";i._AddLogEntry(r)},i._ErrorDisabled=function(e){},i._ErrorEnabled=function(e){var t=i._FormatMessage(e);console.error("BJS - "+t);var r="
"+t+"

";i._AddLogEntry(r)},Object.defineProperty(i,"LogCache",{get:function(){return i._LogCache},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LogLevels",{set:function(e){i.Log=(e&i.MessageLogLevel)===i.MessageLogLevel?i._LogEnabled:i._LogDisabled,i.Warn=(e&i.WarningLogLevel)===i.WarningLogLevel?i._WarnEnabled:i._WarnDisabled,i.Error=(e&i.ErrorLogLevel)===i.ErrorLogLevel?i._ErrorEnabled:i._ErrorDisabled},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PerformanceNoneLogLevel",{get:function(){return i._PerformanceNoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PerformanceUserMarkLogLevel",{get:function(){return i._PerformanceUserMarkLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PerformanceConsoleLogLevel",{get:function(){return i._PerformanceConsoleLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PerformanceLogLevel",{set:function(e){return(e&i.PerformanceUserMarkLogLevel)===i.PerformanceUserMarkLogLevel?(i.StartPerformanceCounter=i._StartUserMark,void(i.EndPerformanceCounter=i._EndUserMark)):(e&i.PerformanceConsoleLogLevel)===i.PerformanceConsoleLogLevel?(i.StartPerformanceCounter=i._StartPerformanceConsole,void(i.EndPerformanceCounter=i._EndPerformanceConsole)):(i.StartPerformanceCounter=i._StartPerformanceCounterDisabled,void(i.EndPerformanceCounter=i._EndPerformanceCounterDisabled))},enumerable:!0,configurable:!0}),i._StartPerformanceCounterDisabled=function(e,t){},i._EndPerformanceCounterDisabled=function(e,t){},i._StartUserMark=function(e,t){void 0===t&&(t=!0),t&&i._performance.mark&&i._performance.mark(e+"-Begin")},i._EndUserMark=function(e,t){void 0===t&&(t=!0),t&&i._performance.mark&&(i._performance.mark(e+"-End"),i._performance.measure(e,e+"-Begin",e+"-End"))},i._StartPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(i._StartUserMark(e,t),console.time&&console.time(e))},i._EndPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(i._EndUserMark(e,t),console.time&&console.timeEnd(e))},Object.defineProperty(i,"Now",{get:function(){return window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},enumerable:!0,configurable:!0}),i.GetFps=function(){return i.Warn("Tools.GetFps() is deprecated. Please use engine.getFps() instead"),0},i.BaseUrl="",i._NoneLogLevel=0,i._MessageLogLevel=1,i._WarningLogLevel=2,i._ErrorLogLevel=4,i._LogCache="",i.Log=i._LogEnabled,i.Warn=i._WarnEnabled,i.Error=i._ErrorEnabled,i._PerformanceNoneLogLevel=0,i._PerformanceUserMarkLogLevel=1,i._PerformanceConsoleLogLevel=2,i._performance=window.performance,i.StartPerformanceCounter=i._StartPerformanceCounterDisabled,i.EndPerformanceCounter=i._EndPerformanceCounterDisabled,i}();e.Tools=i;var n=function(){function e(e,t,r,i){void 0===i&&(i=0),this.iterations=e,this._fn=t,this._successCallback=r,this.index=i-1,this._done=!1}return e.prototype.executeNext=function(){this._done||(this.index+1n;++n){var s=e.index*r+n;if(s>=t)break;if(i(s),o&&o()){e.breakLoop();break}}e.executeNext()},s)},n)},e}();e.AsyncLoop=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this._isDepthTestDirty=!1,this._isDepthMaskDirty=!1,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1,this._isZOffsetDirty=!1}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isDepthFuncDirty||this._isDepthTestDirty||this._isDepthMaskDirty||this._isCullFaceDirty||this._isCullDirty||this._isZOffsetDirty},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"zOffset",{get:function(){return this._zOffset},set:function(e){this._zOffset!==e&&(this._zOffset=e,this._isZOffsetDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"cullFace",{get:function(){return this._cullFace},set:function(e){this._cullFace!==e&&(this._cullFace=e,this._isCullFaceDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"cull",{get:function(){return this._cull},set:function(e){this._cull!==e&&(this._cull=e,this._isCullDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthFunc",{get:function(){return this._depthFunc},set:function(e){this._depthFunc!==e&&(this._depthFunc=e,this._isDepthFuncDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthMask",{get:function(){return this._depthMask},set:function(e){this._depthMask!==e&&(this._depthMask=e,this._isDepthMaskDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthTest",{get:function(){return this._depthTest},set:function(e){this._depthTest!==e&&(this._depthTest=e,this._isDepthTestDirty=!0)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this._depthMask=!0,this._depthTest=!0,this._depthFunc=null,this._cull=null,this._cullFace=null,this._zOffset=0,this._isDepthTestDirty=!0,this._isDepthMaskDirty=!0,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1,this._isZOffsetDirty=!1},e.prototype.apply=function(e){this.isDirty&&(this._isCullDirty&&(this.cull?e.enable(e.CULL_FACE):e.disable(e.CULL_FACE),this._isCullDirty=!1),this._isCullFaceDirty&&(e.cullFace(this.cullFace),this._isCullFaceDirty=!1),this._isDepthMaskDirty&&(e.depthMask(this.depthMask),this._isDepthMaskDirty=!1),this._isDepthTestDirty&&(this.depthTest?e.enable(e.DEPTH_TEST):e.disable(e.DEPTH_TEST),this._isDepthTestDirty=!1),this._isDepthFuncDirty&&(e.depthFunc(this.depthFunc),this._isDepthFuncDirty=!1),this._isZOffsetDirty&&(this.zOffset?(e.enable(e.POLYGON_OFFSET_FILL),e.polygonOffset(this.zOffset,0)):e.disable(e.POLYGON_OFFSET_FILL),this._isZOffsetDirty=!1))},e}();e._DepthCullingState=t;var r=function(){function e(){this._isAlphaBlendDirty=!1,this._isBlendFunctionParametersDirty=!1,this._alphaBlend=!1,this._blendFunctionParameters=new Array(4)}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isAlphaBlendDirty||this._isBlendFunctionParametersDirty},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alphaBlend",{get:function(){return this._alphaBlend},set:function(e){this._alphaBlend!==e&&(this._alphaBlend=e,this._isAlphaBlendDirty=!0)},enumerable:!0,configurable:!0}),e.prototype.setAlphaBlendFunctionParameters=function(e,t,r,i){(this._blendFunctionParameters[0]!==e||this._blendFunctionParameters[1]!==t||this._blendFunctionParameters[2]!==r||this._blendFunctionParameters[3]!==i)&&(this._blendFunctionParameters[0]=e,this._blendFunctionParameters[1]=t,this._blendFunctionParameters[2]=r,this._blendFunctionParameters[3]=i,this._isBlendFunctionParametersDirty=!0)},e.prototype.reset=function(){this._alphaBlend=!1,this._blendFunctionParameters[0]=null,this._blendFunctionParameters[1]=null,this._blendFunctionParameters[2]=null,this._blendFunctionParameters[3]=null,this._isAlphaBlendDirty=!0,this._isBlendFunctionParametersDirty=!1},e.prototype.apply=function(e){this.isDirty&&(this._isAlphaBlendDirty&&(this._alphaBlend?e.enable(e.BLEND):e.disable(e.BLEND),this._isAlphaBlendDirty=!1),this._isBlendFunctionParametersDirty&&(e.blendFuncSeparate(this._blendFunctionParameters[0],this._blendFunctionParameters[1],this._blendFunctionParameters[2],this._blendFunctionParameters[3]),this._isBlendFunctionParametersDirty=!1))},e}();e._AlphaState=r;var i=function(e,t,r,i){var n=e.createShader("vertex"===r?e.VERTEX_SHADER:e.FRAGMENT_SHADER);if(e.shaderSource(n,(i?i+"\n":"")+t),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(n));return n},n=function(e,t){var r=e.UNSIGNED_BYTE;return t===l.TEXTURETYPE_FLOAT&&(r=e.FLOAT),r},o=function(t,r,i){var n=i.NEAREST,o=i.NEAREST;return t===e.Texture.BILINEAR_SAMPLINGMODE?(n=i.LINEAR,o=r?i.LINEAR_MIPMAP_NEAREST:i.LINEAR):t===e.Texture.TRILINEAR_SAMPLINGMODE?(n=i.LINEAR,o=r?i.LINEAR_MIPMAP_LINEAR:i.LINEAR):t===e.Texture.NEAREST_SAMPLINGMODE&&(n=i.NEAREST,o=r?i.NEAREST_MIPMAP_LINEAR:i.NEAREST),{min:o,mag:n}},s=function(t,r,i,n,s,a,h,c,l,u){void 0===u&&(u=e.Texture.TRILINEAR_SAMPLINGMODE);var f=i.getEngine(),d=e.Tools.GetExponantOfTwo(n,f.getCaps().maxTextureSize),p=e.Tools.GetExponantOfTwo(s,f.getCaps().maxTextureSize);r.bindTexture(r.TEXTURE_2D,t),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,void 0===a?1:a?1:0),t._baseWidth=n,t._baseHeight=s,t._width=d,t._height=p,t.isReady=!0,l(d,p);var m=o(u,!h,r);r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,m.mag),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,m.min),h||c||r.generateMipmap(r.TEXTURE_2D),r.bindTexture(r.TEXTURE_2D,null),f._activeTexturesCache=[],i._removePendingData(t)},a=function(t,r,i,n,o){var s=function(){i[r]=h,i._internalCount++,n._removePendingData(h),6===i._internalCount&&o(i)},a=function(){n._removePendingData(h)},h=e.Tools.LoadImage(t,s,a,n.database);n._addPendingData(h)},h=function(e,t,r,i){var n=[];n._internalCount=0;for(var o=0;6>o;o++)a(e+i[o],o,n,t,r)},c=function(){function e(){}return e}();e.EngineCapabilities=c;var l=function(){function a(i,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 t,this._alphaState=new r,this._alphaMode=a.ALPHA_DISABLE,this._loadedTexturesCache=new Array,this._activeTexturesCache=new Array,this._compiledEffects={},this._uintIndicesCurrentlySet=!1,this._renderingCanvas=i,this._canvasClientRect=this._renderingCanvas.getBoundingClientRect(),o=o||{},o.antialias=n;try{this._gl=i.getContext("webgl",o)||i.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&&(i.requestPointerLock=i.requestPointerLock||i.msRequestPointerLock||i.mozRequestPointerLock||i.webkitRequestPointerLock,i.requestPointerLock&&i.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===i||document.webkitPointerLockElement===i||document.msPointerLockElement===i||document.pointerLockElement===i},document.addEventListener("pointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mspointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mozpointerlockchange",this._onPointerLockChange,!1),document.addEventListener("webkitpointerlockchange",this._onPointerLockChange,!1),a.audioEngine||(a.audioEngine=new e.AudioEngine),e.Tools.Log("Babylon.js engine (v"+a.Version+") launched")}return Object.defineProperty(a,"ALPHA_DISABLE",{get:function(){return a._ALPHA_DISABLE},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_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(e){var t=e.viewport;return this.getRenderWidth()*t.width/(this.getRenderHeight()*t.height)},a.prototype.getRenderWidth=function(){return this._currentRenderTarget?this._currentRenderTarget._width:this._renderingCanvas.width},a.prototype.getRenderHeight=function(){return this._currentRenderTarget?this._currentRenderTarget._height:this._renderingCanvas.height},a.prototype.getRenderingCanvas=function(){return this._renderingCanvas},a.prototype.getRenderingCanvasClientRect=function(){return this._renderingCanvas.getBoundingClientRect()},a.prototype.setHardwareScalingLevel=function(e){this._hardwareScalingLevel=e,this.resize()},a.prototype.getHardwareScalingLevel=function(){return this._hardwareScalingLevel},a.prototype.getLoadedTexturesCache=function(){return this._loadedTexturesCache},a.prototype.getCaps=function(){return this._caps},Object.defineProperty(a.prototype,"drawCalls",{get:function(){return this._drawCalls},enumerable:!0,configurable:!0}),a.prototype.resetDrawCalls=function(){this._drawCalls=0},a.prototype.setDepthFunctionToGreater=function(){this._depthCullingState.depthFunc=this._gl.GREATER},a.prototype.setDepthFunctionToGreaterOrEqual=function(){this._depthCullingState.depthFunc=this._gl.GEQUAL},a.prototype.setDepthFunctionToLess=function(){this._depthCullingState.depthFunc=this._gl.LESS},a.prototype.setDepthFunctionToLessOrEqual=function(){this._depthCullingState.depthFunc=this._gl.LEQUAL},a.prototype.stopRenderLoop=function(e){if(!e)return void(this._activeRenderLoops=[]);var t=this._activeRenderLoops.indexOf(e);t>=0&&this._activeRenderLoops.splice(t,1)},a.prototype._renderLoop=function(){var t=this,r=!0;if(!this.renderEvenInBackground&&this._windowIsBackground&&(r=!1),r){this.beginFrame();for(var i=0;i0?e.Tools.QueueNewFrame(function(){t._renderLoop()}):this._renderingQueueLaunched=!1},a.prototype.runRenderLoop=function(t){var r=this;-1===this._activeRenderLoops.indexOf(t)&&(this._activeRenderLoops.push(t),this._renderingQueueLaunched||(this._renderingQueueLaunched=!0,e.Tools.QueueNewFrame(function(){r._renderLoop()})))},a.prototype.switchFullscreen=function(t){this.isFullscreen?e.Tools.ExitFullscreen():(this._pointerLockRequested=t,e.Tools.RequestFullscreen(this._renderingCanvas))},a.prototype.clear=function(e,t,r){this.applyStates(),this._gl.clearColor(e.r,e.g,e.b,void 0!==e.a?e.a:1),this._depthCullingState.depthMask&&this._gl.clearDepth(1);var i=0;t&&(i|=this._gl.COLOR_BUFFER_BIT),r&&this._depthCullingState.depthMask&&(i|=this._gl.DEPTH_BUFFER_BIT),this._gl.clear(i)},a.prototype.setViewport=function(e,t,r){var i=t||(navigator.isCocoonJS?window.innerWidth:this._renderingCanvas.width),n=r||(navigator.isCocoonJS?window.innerHeight:this._renderingCanvas.height),o=e.x||0,s=e.y||0;this._cachedViewport=e,this._gl.viewport(o*i,s*n,i*e.width,n*e.height)},a.prototype.setDirectViewport=function(e,t,r,i){this._cachedViewport=null,this._gl.viewport(e,t,r,i)},a.prototype.beginFrame=function(){this._measureFps()},a.prototype.endFrame=function(){},a.prototype.resize=function(){var e=navigator.isCocoonJS?window.innerWidth:this._renderingCanvas.clientWidth,t=navigator.isCocoonJS?window.innerHeight:this._renderingCanvas.clientHeight;this.setSize(e/this._hardwareScalingLevel,t/this._hardwareScalingLevel)},a.prototype.setSize=function(e,t){this._renderingCanvas.width=e,this._renderingCanvas.height=t,this._canvasClientRect=this._renderingCanvas.getBoundingClientRect();for(var r=0;r65535){i=!0;break}r=i?new Uint32Array(e):new Uint16Array(e)}else r=new Uint16Array(e);return this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,r,this._gl.STATIC_DRAW),this._resetIndexBufferBinding(),t.references=1,t.is32Bits=i,t},a.prototype.bindBuffers=function(e,t,r,i,n){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==n){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=n,this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e);for(var o=0,s=0;s=0&&this._gl.vertexAttribPointer(a,r[s],this._gl.FLOAT,!1,i,o),o+=4*r[s]}}this._cachedIndexBuffer!==t&&(this._cachedIndexBuffer=t,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,t),this._uintIndicesCurrentlySet=t.is32Bits)},a.prototype.bindMultiBuffers=function(e,t,r){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==r){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=r;for(var i=r.getAttributesNames(),n=0;n=0){var s=e[i[n]];if(!s)continue;var a=s.getStrideSize();this._gl.bindBuffer(this._gl.ARRAY_BUFFER,s.getBuffer()),this._gl.vertexAttribPointer(o,a,this._gl.FLOAT,!1,4*a,0)}}}null!=t&&this._cachedIndexBuffer!==t&&(this._cachedIndexBuffer=t,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,t),this._uintIndicesCurrentlySet=t.is32Bits)},a.prototype._releaseBuffer=function(e){return e.references--,0===e.references?(this._gl.deleteBuffer(e),!0):!1},a.prototype.createInstancesBuffer=function(e){var t=this._gl.createBuffer();return t.capacity=e,this._gl.bindBuffer(this._gl.ARRAY_BUFFER,t),this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.DYNAMIC_DRAW),t},a.prototype.deleteInstancesBuffer=function(e){this._gl.deleteBuffer(e)},a.prototype.updateAndBindInstancesBuffer=function(e,t,r){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e),this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,t);for(var i=0;4>i;i++){var n=r[i];this._gl.enableVertexAttribArray(n),this._gl.vertexAttribPointer(n,4,this._gl.FLOAT,!1,64,16*i),this._caps.instancedArrays.vertexAttribDivisorANGLE(n,1)}},a.prototype.unBindInstancesBuffer=function(e,t){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e);for(var r=0;4>r;r++){var i=t[r];this._gl.disableVertexAttribArray(i),this._caps.instancedArrays.vertexAttribDivisorANGLE(i,0)}},a.prototype.applyStates=function(){this._depthCullingState.apply(this._gl),this._alphaState.apply(this._gl)},a.prototype.draw=function(e,t,r,i){this.applyStates(),this._drawCalls++;var n=this._uintIndicesCurrentlySet?this._gl.UNSIGNED_INT:this._gl.UNSIGNED_SHORT,o=this._uintIndicesCurrentlySet?4:2;return i?void this._caps.instancedArrays.drawElementsInstancedANGLE(e?this._gl.TRIANGLES:this._gl.LINES,r,n,t*o,i):void this._gl.drawElements(e?this._gl.TRIANGLES:this._gl.LINES,r,n,t*o)},a.prototype.drawPointClouds=function(e,t,r){return this.applyStates(),this._drawCalls++,r?void this._caps.instancedArrays.drawArraysInstancedANGLE(this._gl.POINTS,e,t,r):void this._gl.drawArrays(this._gl.POINTS,e,t)},a.prototype._releaseEffect=function(e){this._compiledEffects[e._key]&&(delete this._compiledEffects[e._key],e.getProgram()&&this._gl.deleteProgram(e.getProgram()))},a.prototype.createEffect=function(t,r,i,n,o,s,a,h){var c=t.vertexElement||t.vertex||t,l=t.fragmentElement||t.fragment||t,u=c+"+"+l+"@"+o;if(this._compiledEffects[u])return this._compiledEffects[u];var f=new e.Effect(t,r,i,n,this,o,s,a,h);return f._key=u,this._compiledEffects[u]=f,f},a.prototype.createEffectForParticles=function(e,t,r,i,n,o,s){return void 0===t&&(t=[]),void 0===r&&(r=[]),void 0===i&&(i=""),this.createEffect({vertex:"particles",fragmentElement:e},["position","color","options"],["view","projection"].concat(t),["diffuseSampler"].concat(r),i,n,o,s)},a.prototype.createShaderProgram=function(e,t,r){var n=i(this._gl,e,"vertex",r),o=i(this._gl,t,"fragment",r),s=this._gl.createProgram();this._gl.attachShader(s,n),this._gl.attachShader(s,o),this._gl.linkProgram(s);var a=this._gl.getProgramParameter(s,this._gl.LINK_STATUS);if(!a){var h=this._gl.getProgramInfoLog(s);if(h)throw new Error(h)}return this._gl.deleteShader(n),this._gl.deleteShader(o),s},a.prototype.getUniforms=function(e,t){for(var r=[],i=0;ithis._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[t]||(this._vertexAttribArrays[t]=!1,this._gl.disableVertexAttribArray(t));for(var r=e.getAttributesCount(),i=0;r>i;i++){var n=e.getAttributeLocation(i);n>=0&&(this._vertexAttribArrays[n]=!0,this._gl.enableVertexAttribArray(n))}this._currentEffect=e,e.onBind&&e.onBind(e)},a.prototype.setArray=function(e,t){e&&this._gl.uniform1fv(e,t)},a.prototype.setArray2=function(e,t){e&&t.length%2===0&&this._gl.uniform2fv(e,t)},a.prototype.setArray3=function(e,t){e&&t.length%3===0&&this._gl.uniform3fv(e,t)},a.prototype.setArray4=function(e,t){e&&t.length%4===0&&this._gl.uniform4fv(e,t)},a.prototype.setMatrices=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t)},a.prototype.setMatrix=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t.toArray())},a.prototype.setFloat=function(e,t){e&&this._gl.uniform1f(e,t)},a.prototype.setFloat2=function(e,t,r){e&&this._gl.uniform2f(e,t,r)},a.prototype.setFloat3=function(e,t,r,i){e&&this._gl.uniform3f(e,t,r,i)},a.prototype.setBool=function(e,t){e&&this._gl.uniform1i(e,t)},a.prototype.setFloat4=function(e,t,r,i,n){e&&this._gl.uniform4f(e,t,r,i,n)},a.prototype.setColor3=function(e,t){e&&this._gl.uniform3f(e,t.r,t.g,t.b)},a.prototype.setColor4=function(e,t,r){e&&this._gl.uniform4f(e,t.r,t.g,t.b,r)},a.prototype.setState=function(e,t,r){void 0===t&&(t=0),(this._depthCullingState.cull!==e||r)&&(e?(this._depthCullingState.cullFace=this.cullBackFaces?this._gl.BACK:this._gl.FRONT,this._depthCullingState.cull=!0):this._depthCullingState.cull=!1),this._depthCullingState.zOffset=t},a.prototype.setDepthBuffer=function(e){this._depthCullingState.depthTest=e},a.prototype.getDepthWrite=function(){return this._depthCullingState.depthMask},a.prototype.setDepthWrite=function(e){this._depthCullingState.depthMask=e},a.prototype.setColorWrite=function(e){this._gl.colorMask(e,e,e,e)},a.prototype.setAlphaMode=function(e){switch(e){case a.ALPHA_DISABLE:this.setDepthWrite(!0),this._alphaState.alphaBlend=!1;break;case a.ALPHA_COMBINE:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_ALPHA,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case a.ALPHA_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=e},a.prototype.getAlphaMode=function(){return this._alphaMode},a.prototype.setAlphaTesting=function(e){this._alphaTest=e},a.prototype.getAlphaTesting=function(){return this._alphaTest},a.prototype.wipeCaches=function(){this._activeTexturesCache=[],this._currentEffect=null,this._depthCullingState.reset(),this._alphaState.reset(),this._cachedVertexBuffers=null,this._cachedIndexBuffer=null,this._cachedEffectForVertexBuffers=null},a.prototype.setSamplingMode=function(t,r){var i=this._gl;i.bindTexture(i.TEXTURE_2D,t);var n=i.NEAREST,o=i.NEAREST;r===e.Texture.BILINEAR_SAMPLINGMODE?(n=i.LINEAR,o=i.LINEAR):r===e.Texture.TRILINEAR_SAMPLINGMODE&&(n=i.LINEAR,o=i.LINEAR_MIPMAP_LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,n),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,o),i.bindTexture(i.TEXTURE_2D,null),t.samplingMode=r},a.prototype.createTexture=function(t,r,i,n,o,a,h,c){var l=this;void 0===o&&(o=e.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:"===t.substr(0,5)&&(d=!0),d){var p=t;d=p.split(":"),t=p,u=d[1].substr(d[1].length-4,4).toLowerCase()}else u=t.substr(t.length-4,4).toLowerCase();var m=this.getCaps().s3tc&&".dds"===u,_=".tga"===u;n._addPendingData(f),f.url=t,f.noMipmap=r,f.references=1,f.samplingMode=o,this._loadedTexturesCache.push(f);var g=function(){n._removePendingData(f),h&&h()};if(_){var v=function(t){var h=new Uint8Array(t),c=e.Internals.TGATools.GetTGAHeader(h);s(f,l._gl,n,c.width,c.height,i,r,!1,function(){e.Internals.TGATools.UploadContent(l._gl,h),a&&a()},o)};d instanceof Array?v(c):e.Tools.LoadFile(t,function(e){v(e)},g,n.database,!0)}else if(m)v=function(t){var h=e.Internals.DDSTools.GetDDSInfo(t),c=(h.isRGB||h.isLuminance||h.mipmapCount>1)&&!r&&h.width>>h.mipmapCount-1===1;s(f,l._gl,n,h.width,h.height,i,!c,h.isFourCC,function(){e.Internals.DDSTools.UploadDDSLevels(l._gl,l.getCaps().s3tc,t,h,c,1),a&&a()},o)},d instanceof Array?v(c):e.Tools.LoadFile(t,function(e){v(e)},g,n.database,!0);else{var y=function(t){s(f,l._gl,n,t.width,t.height,i,r,!1,function(r,i){var n=t.width===r&&t.height===i;n||(l._prepareWorkingCanvas(),l._workingCanvas.width=r,l._workingCanvas.height=i,o===e.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(t,0,0,t.width,t.height,0,0,r,i),o===e.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?t:l._workingCanvas),a&&a()},o)};d instanceof Array?e.Tools.LoadImage(c,y,g,n.database):e.Tools.LoadImage(t,y,g,n.database)}return f},a.prototype.createRawTexture=function(e,t,r,i,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(i){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,t,r,0,l,this._gl.UNSIGNED_BYTE,e),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=t,c._baseHeight=r,c._width=t,c._height=r,c.isReady=!0,c.references=1,c.samplingMode=h,this._loadedTexturesCache.push(c),c},a.prototype.createDynamicTexture=function(t,r,i,n,o){void 0===o&&(o=!0);var s=this._gl.createTexture();return s._baseWidth=t,s._baseHeight=r,o&&(t=e.Tools.GetExponantOfTwo(t,this._caps.maxTextureSize),r=e.Tools.GetExponantOfTwo(r,this._caps.maxTextureSize)),this._activeTexturesCache=[],s._width=t,s._height=r,s.isReady=!1,s.generateMipMaps=i,s.references=1,s.samplingMode=n,this.updateTextureSamplingMode(n,s),this._loadedTexturesCache.push(s),s},a.prototype.updateTextureSamplingMode=function(e,t){var r=o(e,t.generateMipMaps,this._gl);this._gl.bindTexture(this._gl.TEXTURE_2D,t),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,r.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,r.min),this._gl.bindTexture(this._gl.TEXTURE_2D,null)},a.prototype.updateDynamicTexture=function(e,t,r){this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,r?1:0),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],e.isReady=!0},a.prototype.updateVideoTexture=function(e,t,r){this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,r?0:1),void 0===this._videoTextureSupported&&(this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t),this._videoTextureSupported=0!==this._gl.getError()?!1:!0),this._videoTextureSupported?this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t):(e._workingCanvas||(e._workingCanvas=document.createElement("canvas"),e._workingContext=e._workingCanvas.getContext("2d"),e._workingCanvas.width=e._width,e._workingCanvas.height=e._height),e._workingContext.drawImage(t,0,0,t.videoWidth,t.videoHeight,0,0,e._width,e._height),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,e._workingCanvas)),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],e.isReady=!0},a.prototype.createRenderTargetTexture=function(t,r){var i=!1,s=!0,h=a.TEXTURETYPE_UNSIGNED_INT,c=e.Texture.TRILINEAR_SAMPLINGMODE;void 0!==r&&(i=void 0===r.generateMipMaps?r:r.generateMipmaps,s=void 0===r.generateDepthBuffer?!0:r.generateDepthBuffer,h=void 0===r.type?h:r.type,void 0!==r.samplingMode&&(c=r.samplingMode),h===a.TEXTURETYPE_FLOAT&&(c=e.Texture.NEAREST_SAMPLINGMODE));var l=this._gl,u=l.createTexture();l.bindTexture(l.TEXTURE_2D,u);var f=t.width||t,d=t.height||t,p=o(c,i,l);h!==a.TEXTURETYPE_FLOAT||this._caps.textureFloat||(h=a.TEXTURETYPE_UNSIGNED_INT,e.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type")),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=i,u.references=1,u.samplingMode=c,this._activeTexturesCache=[],this._loadedTexturesCache.push(u),u},a.prototype.createCubeTexture=function(t,r,i,n){var o=this,s=this._gl,a=s.createTexture();a.isCube=!0,a.url=t,a.references=1,this._loadedTexturesCache.push(a);var c=t.substr(t.length-4,4).toLowerCase(),l=this.getCaps().s3tc&&".dds"===c;return l?e.Tools.LoadFile(t,function(t){var r=e.Internals.DDSTools.GetDDSInfo(t),i=(r.isRGB||r.isLuminance||r.mipmapCount>1)&&!n;s.bindTexture(s.TEXTURE_CUBE_MAP,a),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,1),e.Internals.DDSTools.UploadDDSLevels(o._gl,o.getCaps().s3tc,t,r,i,6),n||r.isFourCC||1!==r.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,i?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=r.width,a._height=r.height,a.isReady=!0},null,null,!0):h(t,r,function(t){var r=e.Tools.GetExponantOfTwo(t[0].width,o._caps.maxCubemapTextureSize),i=r;o._prepareWorkingCanvas(),o._workingCanvas.width=r,o._workingCanvas.height=i;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;ct)){if(!r||!r.isReady())return void(null!=this._activeTexturesCache[t]&&(this._gl.activeTexture(this._gl["TEXTURE"+t]),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,null),this._activeTexturesCache[t]=null));if(r instanceof e.VideoTexture)r.update()&&(this._activeTexturesCache[t]=null);else if(r.delayLoadState===a.DELAYLOADSTATE_NOTLOADED)return void r.delayLoad();if(this._activeTexturesCache[t]!==r){this._activeTexturesCache[t]=r;var i=r.getInternalTexture();if(this._gl.activeTexture(this._gl["TEXTURE"+t]),i.isCube){if(this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,i),i._cachedCoordinatesMode!==r.coordinatesMode){i._cachedCoordinatesMode=r.coordinatesMode;var n=r.coordinatesMode!==e.Texture.CUBIC_MODE&&r.coordinatesMode!==e.Texture.SKYBOX_MODE?this._gl.REPEAT:this._gl.CLAMP_TO_EDGE;this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_S,n),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_T,n)}this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP,r)}else{if(this._gl.bindTexture(this._gl.TEXTURE_2D,i),i._cachedWrapU!==r.wrapU)switch(i._cachedWrapU=r.wrapU,r.wrapU){case e.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.REPEAT);break;case e.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.CLAMP_TO_EDGE);break;case e.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.MIRRORED_REPEAT)}if(i._cachedWrapV!==r.wrapV)switch(i._cachedWrapV=r.wrapV,r.wrapV){case e.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.REPEAT);break;case e.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.CLAMP_TO_EDGE);break;case e.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.MIRRORED_REPEAT)}this._setAnisotropicLevel(this._gl.TEXTURE_2D,r)}}}},a.prototype._setAnisotropicLevel=function(t,r){var i=this._caps.textureAnisotropicFilterExtension,n=r.anisotropicFilteringLevel;r.getInternalTexture().samplingMode===e.Texture.NEAREST_SAMPLINGMODE&&(n=1),i&&r._cachedAnisotropicFilteringLevel!==n&&(this._gl.texParameterf(t,i.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(n,this._caps.maxAnisotropy)),r._cachedAnisotropicFilteringLevel=n)},a.prototype.readPixels=function(e,t,r,i){var n=new Uint8Array(i*r*4);return this._gl.readPixels(0,0,r,i,this._gl.RGBA,this._gl.UNSIGNED_BYTE,n),n},a.prototype.dispose=function(){for(this.hideLoadingUI(),this.stopRenderLoop();this.scenes.length;)this.scenes[0].dispose();a.audioEngine.dispose();for(var e in this._compiledEffects)this._gl.deleteProgram(this._compiledEffects[e]._program);for(var t in this._vertexAttribArrays)t>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[t]||this._gl.disableVertexAttribArray(t);window.removeEventListener("blur",this._onBlur),window.removeEventListener("focus",this._onFocus),document.removeEventListener("fullscreenchange",this._onFullscreenChange),document.removeEventListener("mozfullscreenchange",this._onFullscreenChange),document.removeEventListener("webkitfullscreenchange",this._onFullscreenChange),document.removeEventListener("msfullscreenchange",this._onFullscreenChange),document.removeEventListener("pointerlockchange",this._onPointerLockChange),document.removeEventListener("mspointerlockchange",this._onPointerLockChange),document.removeEventListener("mozpointerlockchange",this._onPointerLockChange),document.removeEventListener("webkitpointerlockchange",this._onPointerLockChange)},a.prototype.displayLoadingUI=function(){var e=this;this._loadingDiv=document.createElement("div"),this._loadingDiv.style.opacity="0",this._loadingDiv.style.transition="opacity 1.5s ease",this._loadingTextDiv=document.createElement("div"),this._loadingTextDiv.style.position="absolute",this._loadingTextDiv.style.left="0",this._loadingTextDiv.style.top="50%",this._loadingTextDiv.style.marginTop="80px",this._loadingTextDiv.style.width="100%",this._loadingTextDiv.style.height="20px",this._loadingTextDiv.style.fontFamily="Arial",this._loadingTextDiv.style.fontSize="14px",this._loadingTextDiv.style.color="white",this._loadingTextDiv.style.textAlign="center",this._loadingTextDiv.innerHTML="Loading",this._loadingDiv.appendChild(this._loadingTextDiv);var t=new Image;t.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAARbSURBVHhe7Z09aFNRFMc716kuLrq4FdyLq4Wi4CAoRQcR0UJBUBdRiuLSIYMo6CA4FF2sgw6CFAdFUOpSQYcWO4hD26UQCfXrIQrx/JJzw1OSWq3NPeL/B4Fy+0jg/HO+7j3vpUcI8b/Q39+/49ihfWdPHT94Yf/e3Se3bd263f8lus218TPn6vV6Ya8Wi/MzNRNmj18iusX9W1evmP1/EKNEIVG6CMbG6E3bt+fT++pHha8NoHdT72bLE8NDg7tGU64gLLndV4Wc4m8j/pS+vr4tGB/DT16v3Fyr8dvBe/jbit8BL0AES9LX1iPAz+BR/hFiLVCynj95dPzNy6fv3IZ/k4L3948Sq7FzYGBg4vLFGxitabuOFCbWNKGrMnbiUuo18KaV6tIHv6YtvL9/nOgE31jCktmrY7k6+/zhE4yP4Vf7hiNqh/BWWEl8mzDol4p22Lf7cIdvdUMEvv0Y2S9fE5S1hLzpqTsPkiep//gFGPnR3Yl7GL5p/xYFBrTwM+iXio3GqpwDGL5p/xYNIX7XG8Q6IJRgdIzf1KBBgafII7oMidhyQtVFaMA2Bt7il4huQRhaXphbcR2g4RXqBzKAGHiCCwGFVUAj/m/RTRDj29cvn10I0PZ3LghH5f4CL1EFlQmqqXK3jDDKFxmhQ3Yt6oQseUZGKmMnTpsOqc8o1F9kBOMjQlOLeqEeIyOc6JV6jYLJD/+XyIFvnzdgl9aXRQ5I2qZDK1SpospMqaoqON/wZZGDciLnMMiXRS7IF4hhqMTNTdk7CFu+LHLhR7BQqBvPDJUUQqCGvCMATHUgBmhWNgApmdOda9YpM+VwRYfuyyIXDK8hBlilNerLIheMZCKGwlUAyru6GlwOgPUbRxADdJ9FAChxXY864viyyEXqPxhc0M2TAfAbatSdRyHtXymhByEdRnE3ky+JnHAIhSA0h74kckETmHoQbSgGwJrCIRMEPSRIBCRIMAhZaYhaggQhJXUJEoRU9mofKwh+F22dLRRfEjlJM7w6KQwCoQpBOKTyJZETjmwRxKqtGV8SOSkNOGjKPQppBEgDDkFgpxdBVGkFgaYQQXRIFQSObk0P5ZFIpAZRHXsQ0r0hCluBWKkuvVbYCkQaCdL5ehBScudJP4yY+rLISdps1NBDEJKXMMmoSfggWC4ZQRR17oFYXph7hSiquIKQ+hJGTX1J5MYSPD/GVdNzsgLBwZVCVyAQAkF0ohiI/c1fS6tNXq9UfEnkhudmIQolsS+J3Hh/UtNDzQLhj42VKJFInqLwFYiUU5ToA+HdfI0JevUpQUAIn+vSz2lHIuUV/dJOIHhOY/IWVWGBIHQtzs88s9zyWBuTgcBLzGOmeNnfF/QslSDgMeQW85i3DOQxuipxAkCyZ8SIm4Omp+7MMlCB59j6sKZcMoM4iIEoeI2J9AKxrFobZx0v4vYInuHFS4J1GQRCAGaLEYQXfyMML5XSQgghhBBCCCH+cXp6vgNhKpSKX/XdOAAAAABJRU5ErkJggg==",t.style.position="absolute",t.style.left="50%",t.style.top="50%",t.style.marginLeft="-50px",t.style.marginTop="-50px",t.style.transition="transform 1.0s ease",t.style.webkitTransition="-webkit-transform 1.0s ease";var r=360,i=function(){r+=360,t.style.transform="rotateZ("+r+"deg)",t.style.webkitTransform="rotateZ("+r+"deg)"};t.addEventListener("transitionend",i),t.addEventListener("webkitTransitionEnd",i),this._loadingDiv.appendChild(t);var n=new Image;n.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAAYJSURBVHhe7Zy/qx1FFMff/2Av2Nvbi4WFiiAEY/OQ2IgQsbCJQoqkCAgpFLXyoZURLfwBIiIpgqZJoYQYlWelNsIrNOxDJcrzfHe+G97dnTl75u7euzv7zgcWHrlnZmfOmXPmzI/NjuM4juM4juM4juM4juM4juM4juM4juM45fPic08/uHf5/CvffH7lnT8PfrtxdHS0n3p+/fHGl5+89/prr5599iEWd8bg0rkXHoFyqehKnlxQpjYSDHTm9JMPsGrHylOPPXofvICKXMcIGtXdf/76AYbm6xyNW9e/eAtKC7rbKLXnvHHx5Sf4auc4Ek7OQkFU1Dap/vv37k/wSjblZANFiFIGzw98hhizwqBgs04mCBdQRNCHidoAEtY+lLIvtSdoGFeyql2ZH57HBH4sE7O+o/r9l+8/ZXUni68+2jsHBQQ9qNRGeP/tSxdSYQX/roUcpL4/f3vtM9TD+jTq92n1LQ7jxF1hhGPtwWL3gGccy8JuS1r8sVWBGXNVdSKMYjBGPUJjCzooiGuSpnwlnnOGP2dhHRSLNgpHp2oMKIriK8TmG4Qh/rwW8D6pps9b9im+LDDipXOqMVJrAngBfg9i98gevWKA+/nnCod3Dr5GfaHaDgidVym6HKRjGIkpqthcAVKGxNqBImbEo66kjCih8AOpNmkUmbMuUrR8kEqiU6FvHZLGAPJ71JCYSyhiBqmwFE2GoD6jLGIfDHtG6EzoU4dK21PCqIRMEF0FGRjFzGDtIkXVAdATvsqfT9CJ0JcOFdYiFIsiMlqYy1YOFpQo2OddqBtyEaq9y+efoVh5oPHoROjLKn0j3JIE5Ka8UqZRtGrMnneX6yVofOhDh94MSbznTcpqmDOt1vyQzOgaJAF4F3JBfIXesrNEGWWmjIX7UBZ6jRJbBMLg/DmJiKUGVHleIpnVNTa+jakzkAviJqLhi4MC9XQGBrZeKJZESSrKy7ik0VGFWhQBRDTHIACKQ5l9nAjy75gya4a2w+Jhs0FJdc0xX/GwUbAqFBkZi7QpJ2w16WUbjFyK9MJF3KaoEM74KhVtLrQOrsmRxkbdHEqmSC/c+EuGnIFkjW7Ih2Kr4CCMIvNG2hrrgLpCjiFloooYCjyYrzCRyvhyBthkIPuQtsZGdnbMTezyDiU71KTC5zr7aVsHbsz2tllrEkS5UHwU1tq1HbtPW4UbeB0O7xx8R5EsMJql+BheUmHjkNVmIRP7LutoM3+D4O4tG7vCkNO9ESZ4lL3J6rKRMPx4qKbD/A0icf8CG7tC7kTahnMTwleuYSrsS7GatRAvfZh1tTm5BmmQCdZ8a0Sefe28xUrRBkmFLKy8KTIKUDRX0Y1xagPgwbaIdeFnQULmKak3xvwNMkVGgok/N5XNoehJvejRlCDl9escI28dJU0tZ++nBTJE9mEF647x5Ehbo4s5hDOKFIU0PdofeA5F5k1q63zIWmQqNI/P3ZubjFTqKxQ3jyjHAOX0RdlgVO9hzRFpczRcjZ3Gbxxpc7Qj6+5pTYF2OFXawNI+yDGf1k2NcvOlzBQeDQ/t7zD7DsEDpJ2xATXaNtDWUS4IzP4DS2ljajAVu57SUkYw245ptxZxA5JiZaJ0DswudGn3kYUy54426EjoT4dZfYbccxC2nI92cDkZHQr96jD4AGkMDKeSy/COBsRe6VTSKFN6irLeaCh3IteQjt1E5+oudsG/b/2DfZ5AqsYo8vMDK9LB1HzSsLWvlGThdxXvC6+NsqyPPWP0pMINtbdsajfVeC6f/GZ+cdAofQoB1d+Hf9waY98I7+RXWab3Lt4zYkjHtTnlOLXHYMsCh1zWeQYehu1zfNPOOiys/d91LAKEBSgh6MJMbSA82AaHofDgAIwbgvVvlLNS11nModMm4UZergLHZBZrodmBuA3lBB1thdorSjkOmATMDwg/UBQVtglqQyx6fbEJ+H3IWIapjYAjAfeIgeCMHldueJvFaqDaAHhwf8qNsEEQ1iQbOoUUGIbCLRc8+Bvfp4jyd2FEijuO4ziO4ziO4ziO4ziO4ziO4ziO4ziOUzw7O/8D0P7rcZ/GEboAAAAASUVORK5CYII=", n.style.position="absolute",n.style.left="50%",n.style.top="50%",n.style.marginLeft="-50px",n.style.marginTop="-50px",this._loadingDiv.appendChild(n),this._resizeLoadingUI=function(){var t=e.getRenderingCanvasClientRect();e._loadingDiv.style.position="absolute",e._loadingDiv.style.left=t.left+"px",e._loadingDiv.style.top=t.top+"px",e._loadingDiv.style.width=t.width+"px",e._loadingDiv.style.height=t.height+"px"},this._resizeLoadingUI(),window.addEventListener("resize",this._resizeLoadingUI),this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor,document.body.appendChild(this._loadingDiv),setTimeout(function(){e._loadingDiv.style.opacity="1",t.style.transform="rotateZ(360deg)",t.style.webkitTransform="rotateZ(360deg)"},0)},Object.defineProperty(a.prototype,"loadingUIText",{set:function(e){this._loadingDiv&&(this._loadingTextDiv.innerHTML=e)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"loadingUIBackgroundColor",{get:function(){return this._loadingDivBackgroundColor},set:function(e){this._loadingDivBackgroundColor=e,this._loadingDiv&&(this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor)},enumerable:!0,configurable:!0}),a.prototype.hideLoadingUI=function(){var e=this;if(this._loadingDiv){var t=function(){e._loadingDiv&&(document.body.removeChild(e._loadingDiv),window.removeEventListener("resize",e._resizeLoadingUI),e._loadingDiv=null)};this._loadingDiv.style.opacity="0",this._loadingDiv.addEventListener("transitionend",t)}},a.prototype.getFps=function(){return this.fps},a.prototype.getDeltaTime=function(){return this.deltaTime},a.prototype._measureFps=function(){this.previousFramesDuration.push(e.Tools.Now);var t=this.previousFramesDuration.length;if(t>=2&&(this.deltaTime=this.previousFramesDuration[t-1]-this.previousFramesDuration[t-2]),t>=this.fpsRange){t>this.fpsRange&&(this.previousFramesDuration.splice(0,1),t=this.previousFramesDuration.length);for(var r=0,i=0;t-1>i;i++)r+=this.previousFramesDuration[i+1]-this.previousFramesDuration[i];this.fps=1e3/(r/(t-1))}},a.isSupported=function(){try{if(navigator.isCocoonJS)return!0;var e=document.createElement("canvas"),t=e.getContext("webgl")||e.getContext("experimental-webgl");return null!=t&&!!window.WebGLRenderingContext}catch(r){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}();e.Engine=l}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t){this.state="",this.animations=new Array,this._childrenFlag=-1,this._isEnabled=!0,this._isReady=!0,this._currentRenderId=-1,this._parentRenderId=-1,this.name=e,this.id=e,this._scene=t,this._initCache()}return t.prototype.getScene=function(){return this._scene},t.prototype.getEngine=function(){return this._scene.getEngine()},t.prototype.getWorldMatrix=function(){return e.Matrix.Identity()},t.prototype._initCache=function(){this._cache={},this._cache.parent=void 0},t.prototype.updateCache=function(e){(e||!this.isSynchronized())&&(this._cache.parent=this.parent,this._updateCache())},t.prototype._updateCache=function(e){},t.prototype._isSynchronized=function(){return!0},t.prototype._markSyncedWithParent=function(){this._parentRenderId=this.parent._currentRenderId},t.prototype.isSynchronizedWithParent=function(){return this.parent?this._parentRenderId!==this.parent._currentRenderId?!1:this.parent.isSynchronized():!0},t.prototype.isSynchronized=function(e){var t=this.hasNewParent();return t=t||!this.isSynchronizedWithParent(),t=t||!this._isSynchronized(),e&&this.updateCache(!0),!t},t.prototype.hasNewParent=function(e){return this._cache.parent===this.parent?!1:(e&&(this._cache.parent=this.parent),!0)},t.prototype.isReady=function(){return this._isReady},t.prototype.isEnabled=function(){return this._isEnabled?this.parent?this.parent.isEnabled():!0:!1},t.prototype.setEnabled=function(e){this._isEnabled=e},t.prototype.isDescendantOf=function(e){return this.parent?this.parent===e?!0:this.parent.isDescendantOf(e):!1},t.prototype._getDescendants=function(e,t){for(var r=0;r0&&this._textureLoadingCallback(e)}this._currentScene.render()}},t.prototype.drag=function(e){e.stopPropagation(),e.preventDefault()},t.prototype.drop=function(e){e.stopPropagation(),e.preventDefault(),this.loadFiles(e)},t.prototype.loadFiles=function(e){if(this._startingProcessingFilesCallback&&this._startingProcessingFilesCallback(),e&&e.dataTransfer&&e.dataTransfer.files&&(this._filesToLoad=e.dataTransfer.files),e&&e.target&&e.target.files&&(this._filesToLoad=e.target.files),this._filesToLoad&&this._filesToLoad.length>0){for(var r=0;rt;t++)if(e[t].dotCoordinate(this.centerWorld)<=-this.radiusWorld)return!1;return!0},t.prototype.intersectsPoint=function(t){var r=this.centerWorld.x-t.x,i=this.centerWorld.y-t.y,n=this.centerWorld.z-t.z,o=Math.sqrt(r*r+i*i+n*n);return Math.abs(this.radiusWorld-o)this.maximumWorld.x&&(this.maximumWorld.x=i.x),i.y>this.maximumWorld.y&&(this.maximumWorld.y=i.y),i.z>this.maximumWorld.z&&(this.maximumWorld.z=i.z)}this.maximumWorld.addToRef(this.minimumWorld,this.center),this.center.scaleInPlace(.5),e.Vector3.FromFloatArrayToRef(t.m,0,this.directions[0]),e.Vector3.FromFloatArrayToRef(t.m,4,this.directions[1]),e.Vector3.FromFloatArrayToRef(t.m,8,this.directions[2]),this._worldMatrix=t},t.prototype.isInFrustum=function(e){return t.IsInFrustum(this.vectorsWorld,e)},t.prototype.isCompletelyInFrustum=function(e){return t.IsCompletelyInFrustum(this.vectorsWorld,e)},t.prototype.intersectsPoint=function(t){var r=-e.Engine.Epsilon;return this.maximumWorld.x-t.xt.x-this.minimumWorld.x?!1:this.maximumWorld.y-t.yt.y-this.minimumWorld.y?!1:this.maximumWorld.z-t.zt.z-this.minimumWorld.z?!1:!0},t.prototype.intersectsSphere=function(e){return t.IntersectsSphere(this.minimumWorld,this.maximumWorld,e.centerWorld,e.radiusWorld)},t.prototype.intersectsMinMax=function(e,t){return this.maximumWorld.xt.x?!1:this.maximumWorld.yt.y?!1:this.maximumWorld.zt.z?!1:!0},t.Intersects=function(e,t){return e.maximumWorld.xt.maximumWorld.x?!1:e.maximumWorld.yt.maximumWorld.y?!1:e.maximumWorld.zt.maximumWorld.z?!1:!0},t.IntersectsSphere=function(t,r,i,n){var o=e.Vector3.Clamp(i,t,r),s=e.Vector3.DistanceSquared(i,o);return n*n>=s},t.IsCompletelyInFrustum=function(e,t){for(var r=0;6>r;r++)for(var i=0;8>i;i++)if(t[r].dotCoordinate(e[i])<0)return!1;return!0},t.IsInFrustum=function(e,t){for(var r=0;6>r;r++){for(var i=8,n=0;8>n&&t[r].dotCoordinate(e[n])<0;n++)--i;if(0===i)return!1}return!0},t}();e.BoundingBox=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t,r){var i=e.Vector3.Dot(r.center,t),n=Math.abs(e.Vector3.Dot(r.directions[0],t))*r.extendSize.x,o=Math.abs(e.Vector3.Dot(r.directions[1],t))*r.extendSize.y,s=Math.abs(e.Vector3.Dot(r.directions[2],t))*r.extendSize.z,a=n+o+s;return{min:i-a,max:i+a}},r=function(e,t,r,i){return!(e>i||r>t)},i=function(e,i,n){var o=t(e,i),s=t(e,n);return r(o.min,o.max,s.min,s.max)},n=function(){function t(t,r){this.minimum=t,this.maximum=r,this.boundingBox=new e.BoundingBox(t,r),this.boundingSphere=new e.BoundingSphere(t,r)}return t.prototype._update=function(e){this.boundingBox._update(e),this.boundingSphere._update(e)},t.prototype.isInFrustum=function(e){return this.boundingSphere.isInFrustum(e)?this.boundingBox.isInFrustum(e):!1},t.prototype.isCompletelyInFrustum=function(e){return this.boundingBox.isCompletelyInFrustum(e)},t.prototype._checkCollision=function(e){return e._canDoCollision(this.boundingSphere.centerWorld,this.boundingSphere.radiusWorld,this.boundingBox.minimumWorld,this.boundingBox.maximumWorld)},t.prototype.intersectsPoint=function(e){return this.boundingSphere.centerWorld&&this.boundingSphere.intersectsPoint(e)&&this.boundingBox.intersectsPoint(e)?!0:!1},t.prototype.intersects=function(t,r){if(!this.boundingSphere.centerWorld||!t.boundingSphere.centerWorld)return!1;if(!e.BoundingSphere.Intersects(this.boundingSphere,t.boundingSphere))return!1;if(!e.BoundingBox.Intersects(this.boundingBox,t.boundingBox))return!1;if(!r)return!0;var n=this.boundingBox,o=t.boundingBox;return i(n.directions[0],n,o)&&i(n.directions[1],n,o)&&i(n.directions[2],n,o)&&i(o.directions[0],n,o)&&i(o.directions[1],n,o)&&i(o.directions[2],n,o)&&i(e.Vector3.Cross(n.directions[0],o.directions[0]),n,o)&&i(e.Vector3.Cross(n.directions[0],o.directions[1]),n,o)&&i(e.Vector3.Cross(n.directions[0],o.directions[2]),n,o)&&i(e.Vector3.Cross(n.directions[1],o.directions[0]),n,o)&&i(e.Vector3.Cross(n.directions[1],o.directions[1]),n,o)&&i(e.Vector3.Cross(n.directions[1],o.directions[2]),n,o)&&i(e.Vector3.Cross(n.directions[2],o.directions[0]),n,o)&&i(e.Vector3.Cross(n.directions[2],o.directions[1]),n,o)&&i(e.Vector3.Cross(n.directions[2],o.directions[2]),n,o)?!0:!1},t}();e.BoundingInfo=n}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(i,n){var o=this;t.call(this,i,n),this.definedFacingForward=!0,this.position=new e.Vector3(0,0,0),this.rotation=new e.Vector3(0,0,0),this.scaling=new e.Vector3(1,1,1),this.billboardMode=r.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=e.Color3.Red(),this.outlineWidth=.02,this.renderOverlay=!1,this.overlayColor=e.Color3.Red(),this.overlayAlpha=.5,this.hasVertexAlpha=!1,this.useVertexColors=!0,this.applyFog=!0,this.useOctreeForRenderingSelection=!0,this.useOctreeForPicking=!0,this.useOctreeForCollisions=!0,this.layerMask=268435455,this.alwaysSelectAsActiveMesh=!1,this._physicImpostor=e.PhysicsEngine.NoImpostor,this.ellipsoid=new e.Vector3(.5,1,.5),this.ellipsoidOffset=new e.Vector3(0,0,0),this._collider=new e.Collider,this._oldPositionForCollisions=new e.Vector3(0,0,0),this._diffPositionForCollisions=new e.Vector3(0,0,0),this._newPositionForCollisions=new e.Vector3(0,0,0),this._localScaling=e.Matrix.Zero(),this._localRotation=e.Matrix.Zero(),this._localTranslation=e.Matrix.Zero(),this._localBillboard=e.Matrix.Zero(),this._localPivotScaling=e.Matrix.Zero(),this._localPivotScalingRotation=e.Matrix.Zero(),this._localWorld=e.Matrix.Zero(),this._worldMatrix=e.Matrix.Zero(),this._rotateYByPI=e.Matrix.RotationY(Math.PI),this._absolutePosition=e.Vector3.Zero(),this._collisionsTransformMatrix=e.Matrix.Zero(),this._collisionsScalingMatrix=e.Matrix.Zero(),this._isDirty=!1,this._pivotMatrix=e.Matrix.Identity(),this._isDisposed=!1,this._renderId=0,this._intersectionsInProgress=new Array,this._onAfterWorldMatrixUpdate=new Array,this._isWorldMatrixFrozen=!1,this._onCollisionPositionChange=function(t,r,i){void 0===i&&(i=null),o.getScene().workerCollisions&&r.multiplyInPlace(o._collider.radius),r.subtractToRef(o._oldPositionForCollisions,o._diffPositionForCollisions),o._diffPositionForCollisions.length()>e.Engine.CollisionsEpsilon&&o.position.addInPlace(o._diffPositionForCollisions)},n.addMesh(this)}return __extends(r,t),Object.defineProperty(r,"BILLBOARDMODE_NONE",{get:function(){return r._BILLBOARDMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BILLBOARDMODE_X",{get:function(){return r._BILLBOARDMODE_X},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BILLBOARDMODE_Y",{get:function(){return r._BILLBOARDMODE_Y},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BILLBOARDMODE_Z",{get:function(){return r._BILLBOARDMODE_Z},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BILLBOARDMODE_ALL",{get:function(){return r._BILLBOARDMODE_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isBlocked",{get:function(){return!1},enumerable:!0,configurable:!0}),r.prototype.getLOD=function(e){return this},r.prototype.getTotalVertices=function(){return 0},r.prototype.getIndices=function(){return null},r.prototype.getVerticesData=function(e){return null},r.prototype.isVerticesDataPresent=function(e){return!1},r.prototype.getBoundingInfo=function(){return this._masterMesh?this._masterMesh.getBoundingInfo():(this._boundingInfo||this._updateBoundingInfo(),this._boundingInfo)},Object.defineProperty(r.prototype,"useBones",{get:function(){return this.skeleton&&this.getScene().skeletonsEnabled&&this.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&this.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)},enumerable:!0,configurable:!0}),r.prototype._preActivate=function(){},r.prototype._activate=function(e){this._renderId=e},r.prototype.getWorldMatrix=function(){return this._masterMesh?this._masterMesh.getWorldMatrix():(this._currentRenderId!==this.getScene().getRenderId()&&this.computeWorldMatrix(),this._worldMatrix)},Object.defineProperty(r.prototype,"worldMatrixFromCache",{get:function(){return this._worldMatrix},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"absolutePosition",{get:function(){return this._absolutePosition},enumerable:!0,configurable:!0}),r.prototype.freezeWorldMatrix=function(){this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0),this._isWorldMatrixFrozen=!0},r.prototype.unfreezeWorldMatrix=function(){this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0)},Object.defineProperty(r.prototype,"isWorldMatrixFrozen",{get:function(){return this._isWorldMatrixFrozen},enumerable:!0,configurable:!0}),r.prototype.rotate=function(t,r,i){if(t.normalize(),this.rotationQuaternion||(this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation=e.Vector3.Zero()),i&&i!==e.Space.LOCAL){if(this.parent){var n=this.parent.getWorldMatrix().clone();n.invert(),t=e.Vector3.TransformNormal(t,n)}o=e.Quaternion.RotationAxis(t,r),this.rotationQuaternion=o.multiply(this.rotationQuaternion)}else{var o=e.Quaternion.RotationAxis(t,r);this.rotationQuaternion=this.rotationQuaternion.multiply(o)}},r.prototype.translate=function(t,r,i){var n=t.scale(r);if(i&&i!==e.Space.LOCAL)this.setAbsolutePosition(this.getAbsolutePosition().add(n));else{var o=this.getPositionExpressedInLocalSpace().add(n);this.setPositionWithLocalVector(o)}},r.prototype.getAbsolutePosition=function(){return this.computeWorldMatrix(),this._absolutePosition},r.prototype.setAbsolutePosition=function(t){if(t){var r,i,n;if(void 0===t.x){if(arguments.length<3)return;r=arguments[0],i=arguments[1],n=arguments[2]}else r=t.x,i=t.y,n=t.z;if(this.parent){var o=this.parent.getWorldMatrix().clone();o.invert();var s=new e.Vector3(r,i,n);this.position=e.Vector3.TransformCoordinates(s,o)}else this.position.x=r,this.position.y=i,this.position.z=n}},r.prototype.movePOV=function(e,t,r){this.position.addInPlace(this.calcMovePOV(e,t,r))},r.prototype.calcMovePOV=function(t,r,i){var n=new e.Matrix,o=this.rotationQuaternion?this.rotationQuaternion:e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z);o.toRotationMatrix(n);var s=e.Vector3.Zero(),a=this.definedFacingForward?-1:1;return e.Vector3.TransformCoordinatesFromFloatsToRef(t*a,r,i*a,n,s),s},r.prototype.rotatePOV=function(e,t,r){this.rotation.addInPlace(this.calcRotatePOV(e,t,r))},r.prototype.calcRotatePOV=function(t,r,i){var n=this.definedFacingForward?1:-1;return new e.Vector3(t*n,r,i*n)},r.prototype.setPivotMatrix=function(e){this._pivotMatrix=e,this._cache.pivotMatrixUpdated=!0},r.prototype.getPivotMatrix=function(){return this._pivotMatrix},r.prototype._isSynchronized=function(){if(this._isDirty)return!1;if(this.billboardMode!==r.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},r.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.localMatrixUpdated=!1,this._cache.position=e.Vector3.Zero(),this._cache.scaling=e.Vector3.Zero(),this._cache.rotation=e.Vector3.Zero(),this._cache.rotationQuaternion=new e.Quaternion(0,0,0,0)},r.prototype.markAsDirty=function(e){"rotation"===e&&(this.rotationQuaternion=null),this._currentRenderId=Number.MAX_VALUE,this._isDirty=!0},r.prototype._updateBoundingInfo=function(){this._boundingInfo=this._boundingInfo||new e.BoundingInfo(this.absolutePosition,this.absolutePosition),this._boundingInfo._update(this.worldMatrixFromCache),this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)},r.prototype._updateSubMeshesBoundingInfo=function(e){if(this.subMeshes)for(var t=0;t-1&&this._onAfterWorldMatrixUpdate.splice(t,1)},r.prototype.setPositionWithLocalVector=function(t){this.computeWorldMatrix(),this.position=e.Vector3.TransformNormal(t,this._localWorld)},r.prototype.getPositionExpressedInLocalSpace=function(){this.computeWorldMatrix();var t=this._localWorld.clone();return t.invert(),e.Vector3.TransformNormal(this.position,t)},r.prototype.locallyTranslate=function(t){this.computeWorldMatrix(!0),this.position=e.Vector3.TransformCoordinates(t,this._localWorld)},r.prototype.lookAt=function(t,r,i,n){r=r||0,i=i||0,n=n||0;var o=t.subtract(this.position),s=-Math.atan2(o.z,o.x)-Math.PI/2,a=Math.sqrt(o.x*o.x+o.z*o.z),h=Math.atan2(o.y,a);this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(s+r,h+i,n)},r.prototype.isInFrustum=function(e){return this._boundingInfo.isInFrustum(e)},r.prototype.isCompletelyInFrustum=function(t){t||(t=this.getScene().activeCamera);var r=t.getViewMatrix().multiply(t.getProjectionMatrix());return this._boundingInfo.isCompletelyInFrustum(e.Frustum.GetPlanes(r))?!0:!1},r.prototype.intersectsMesh=function(e,t){return this._boundingInfo&&e._boundingInfo?this._boundingInfo.intersects(e._boundingInfo,t):!1},r.prototype.intersectsPoint=function(e){return this._boundingInfo?this._boundingInfo.intersectsPoint(e):!1},r.prototype.setPhysicsState=function(t,r){var i=this.getScene().getPhysicsEngine();if(i)return t=t||e.PhysicsEngine.NoImpostor,t.impostor&&(r=t,t=t.impostor),t===e.PhysicsEngine.NoImpostor?void i._unregisterMesh(this):(r?(r.mass||0===r.mass||(r.mass=0),r.friction||0===r.friction||(r.friction=.2),r.restitution||0===r.restitution||(r.restitution=.2)):r={mass:0,friction:.2,restitution:.2},this._physicImpostor=t,this._physicsMass=r.mass,this._physicsFriction=r.friction,this._physicRestitution=r.restitution,i._registerMesh(this,t,r))},r.prototype.getPhysicsImpostor=function(){return this._physicImpostor?this._physicImpostor:e.PhysicsEngine.NoImpostor},r.prototype.getPhysicsMass=function(){return this._physicsMass?this._physicsMass:0},r.prototype.getPhysicsFriction=function(){return this._physicsFriction?this._physicsFriction:0},r.prototype.getPhysicsRestitution=function(){return this._physicRestitution?this._physicRestitution:0},r.prototype.getPositionInCameraSpace=function(t){return t||(t=this.getScene().activeCamera),e.Vector3.TransformCoordinates(this.absolutePosition,t.getViewMatrix())},r.prototype.getDistanceToCamera=function(e){return e||(e=this.getScene().activeCamera),this.absolutePosition.subtract(e.position).length()},r.prototype.applyImpulse=function(e,t){this._physicImpostor&&this.getScene().getPhysicsEngine()._applyImpulse(this,e,t)},r.prototype.setPhysicsLinkWith=function(e,t,r,i){this._physicImpostor&&this.getScene().getPhysicsEngine()._createLink(this,e,t,r,i)},r.prototype.updatePhysicsBodyPosition=function(){this._physicImpostor&&this.getScene().getPhysicsEngine()._updateBodyPosition(this)},r.prototype.moveWithCollisions=function(e){var t=this.getAbsolutePosition();t.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPositionForCollisions),this._oldPositionForCollisions.addInPlace(this.ellipsoidOffset),this._collider.radius=this.ellipsoid,this.getScene().collisionCoordinator.getNewPosition(this._oldPositionForCollisions,e,this._collider,3,this,this._onCollisionPositionChange,this.uniqueId)},r.prototype.createOrUpdateSubmeshesOctree=function(t,r){void 0===t&&(t=64),void 0===r&&(r=2),this._submeshesOctree||(this._submeshesOctree=new e.Octree(e.Octree.CreationFuncForSubMeshes,t,r)),this.computeWorldMatrix(!0);var i=this.getBoundingInfo().boundingBox;return this._submeshesOctree.update(i.minimumWorld,i.maximumWorld,this.subMeshes),this._submeshesOctree},r.prototype._collideForSubMesh=function(t,r,i){if(this._generatePointsArray(),!t._lastColliderWorldVertices||!t._lastColliderTransformMatrix.equals(r)){t._lastColliderTransformMatrix=r.clone(),t._lastColliderWorldVertices=[],t._trianglePlanes=[];for(var n=t.verticesStart,o=t.verticesStart+t.verticesCount,s=n;o>s;s++)t._lastColliderWorldVertices.push(e.Vector3.TransformCoordinates(this._positions[s],r))}i._collide(t._trianglePlanes,t._lastColliderWorldVertices,this.getIndices(),t.indexStart,t.indexStart+t.indexCount,t.verticesStart,!!t.getMaterial()),i.collisionFound&&(i.collidedMesh=this)},r.prototype._processCollisionsForSubMeshes=function(e,t){var r,i;if(this._submeshesOctree&&this.useOctreeForCollisions){var n=e.velocityWorldLength+Math.max(e.radius.x,e.radius.y,e.radius.z),o=this._submeshesOctree.intersects(e.basePointWorld,n);i=o.length,r=o.data}else r=this.subMeshes,i=r.length;for(var s=0;i>s;s++){var a=r[s];i>1&&!a._checkCollision(e)||this._collideForSubMesh(a,t,e)}},r.prototype._checkCollision=function(t){this._boundingInfo._checkCollision(t)&&(e.Matrix.ScalingToRef(1/t.radius.x,1/t.radius.y,1/t.radius.z,this._collisionsScalingMatrix), this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix,this._collisionsTransformMatrix),this._processCollisionsForSubMeshes(t,this._collisionsTransformMatrix))},r.prototype._generatePointsArray=function(){return!1},r.prototype.intersects=function(t,r){var i=new e.PickingInfo;if(!(this.subMeshes&&this._boundingInfo&&t.intersectsSphere(this._boundingInfo.boundingSphere)&&t.intersectsBox(this._boundingInfo.boundingBox)))return i;if(!this._generatePointsArray())return i;var n,o,s=null;if(this._submeshesOctree&&this.useOctreeForPicking){var a=e.Ray.Transform(t,this.getWorldMatrix()),h=this._submeshesOctree.intersectsRay(a);o=h.length,n=h.data}else n=this.subMeshes,o=n.length;for(var c=0;o>c;c++){var l=n[c];if(!(o>1)||l.canIntersects(t)){var u=l.intersects(t,this._positions,this.getIndices(),r);if(u&&(r||!s||u.distance0&&-1===this.includedOnlyMeshes.indexOf(e)?!1:this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e)?!1:0!==this.includeOnlyWithLayerMask&&0===(this.includeOnlyWithLayerMask&e.layerMask)?!1:0!==this.excludeWithLayerMask&&this.excludeWithLayerMask&e.layerMask?!1:!0:!0},r.prototype.getWorldMatrix=function(){this._currentRenderId=this.getScene().getRenderId();var t=this._getWorldMatrix();return this.parent&&this.parent.getWorldMatrix?(this._parentedWorldMatrix||(this._parentedWorldMatrix=e.Matrix.Identity()),t.multiplyToRef(this.parent.getWorldMatrix(),this._parentedWorldMatrix),this._markSyncedWithParent(),this._parentedWorldMatrix):t},r.prototype.dispose=function(){this._shadowGenerator&&(this._shadowGenerator.dispose(),this._shadowGenerator=null),this.getScene().removeLight(this)},r}(e.Node);e.Light=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(e,r,i){t.call(this,e,i),this.position=r}return __extends(r,t),r.prototype.getAbsolutePosition=function(){return this._transformedPosition?this._transformedPosition:this.position},r.prototype.transferToEffect=function(t,r){return this.parent&&this.parent.getWorldMatrix?(this._transformedPosition||(this._transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this._transformedPosition),void t.setFloat4(r,this._transformedPosition.x,this._transformedPosition.y,this._transformedPosition.z,0)):void t.setFloat4(r,this.position.x,this.position.y,this.position.z,0)},r.prototype.getShadowGenerator=function(){return null},r.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},r}(e.Light);e.PointLight=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(e,r,i,n,o,s){t.call(this,e,s),this.position=r,this.direction=i,this.angle=n,this.exponent=o}return __extends(r,t),r.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},r.prototype.setShadowProjectionMatrix=function(t,r,i){var n=this.getScene().activeCamera;e.Matrix.PerspectiveFovLHToRef(this.angle,1,n.minZ,n.maxZ,t)},r.prototype.supportsVSM=function(){return!0},r.prototype.needRefreshPerFrame=function(){return!1},r.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(this.position)),this.direction},r.prototype.computeTransformedPosition=function(){return this.parent&&this.parent.getWorldMatrix?(this.transformedPosition||(this.transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),!0):!1},r.prototype.transferToEffect=function(t,r,i){var n;this.parent&&this.parent.getWorldMatrix?(this._transformedDirection||(this._transformedDirection=e.Vector3.Zero()),this.computeTransformedPosition(),e.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection),t.setFloat4(r,this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,this.exponent),n=e.Vector3.Normalize(this._transformedDirection)):(t.setFloat4(r,this.position.x,this.position.y,this.position.z,this.exponent),n=e.Vector3.Normalize(this.direction)),t.setFloat4(i,n.x,n.y,n.z,Math.cos(.5*this.angle))},r.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},r}(e.Light);e.SpotLight=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n){t.call(this,r,n),this.direction=i,this.groundColor=new e.Color3(0,0,0)}return __extends(r,t),r.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(e.Vector3.Zero())),this.direction},r.prototype.getShadowGenerator=function(){return null},r.prototype.transferToEffect=function(t,r,i){var n=e.Vector3.Normalize(this.direction);t.setFloat4(r,n.x,n.y,n.z,0),t.setColor3(i,this.groundColor.scale(this.intensity))},r.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._worldMatrix},r}(e.Light);e.HemisphericLight=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(e,r,i){t.call(this,e,i),this.direction=r,this.shadowOrthoScale=.5,this.position=r.scale(-1)}return __extends(r,t),r.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},r.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(this.position)),this.direction},r.prototype.setShadowProjectionMatrix=function(t,r,i){for(var n=Number.MAX_VALUE,o=Number.MIN_VALUE,s=Number.MIN_VALUE,a=Number.MAX_VALUE,h=e.Vector3.Zero(),c=this.getScene().activeCamera,l=0;lo&&(o=h.x),h.y>s&&(s=h.y)}}var m=o-n,_=s-a;e.Matrix.OrthoOffCenterLHToRef(n-m*this.shadowOrthoScale,o+m*this.shadowOrthoScale,a-_*this.shadowOrthoScale,s+_*this.shadowOrthoScale,-c.maxZ,c.maxZ,t)},r.prototype.supportsVSM=function(){return!0},r.prototype.needRefreshPerFrame=function(){return!0},r.prototype.computeTransformedPosition=function(){return this.parent&&this.parent.getWorldMatrix?(this.transformedPosition||(this.transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),!0):!1},r.prototype.transferToEffect=function(t,r){return this.parent&&this.parent.getWorldMatrix?(this._transformedDirection||(this._transformedDirection=e.Vector3.Zero()),e.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection),void t.setFloat4(r,this._transformedDirection.x,this._transformedDirection.y,this._transformedDirection.z,1)):void t.setFloat4(r,this.direction.x,this.direction.y,this.direction.z,1)},r.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},r}(e.Light);e.DirectionalLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(r,i){var n=this;this._filter=t.FILTER_NONE,this.blurScale=2,this._blurBoxOffset=0,this._bias=5e-5,this._darkness=0,this._transparencyShadow=!1,this._viewMatrix=e.Matrix.Zero(),this._projectionMatrix=e.Matrix.Zero(),this._transformMatrix=e.Matrix.Zero(),this._worldViewProjection=e.Matrix.Zero(),this._light=i,this._scene=i.getScene(),this._mapSize=r,i._shadowGenerator=this,this._shadowMap=new e.RenderTargetTexture(i.name+"_shadowMap",r,this._scene,!1),this._shadowMap.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(e.Texture.NEAREST_SAMPLINGMODE),this._shadowMap.renderParticles=!1,this._shadowMap.onAfterUnbind=function(){n.useBlurVarianceShadowMap&&(n._shadowMap2||(n._shadowMap2=new e.RenderTargetTexture(i.name+"_shadowMap",r,n._scene,!1),n._shadowMap2.wrapU=e.Texture.CLAMP_ADDRESSMODE,n._shadowMap2.wrapV=e.Texture.CLAMP_ADDRESSMODE,n._shadowMap2.updateSamplingMode(e.Texture.TRILINEAR_SAMPLINGMODE),n._downSamplePostprocess=new e.PassPostProcess("downScale",1/n.blurScale,null,e.Texture.BILINEAR_SAMPLINGMODE,n._scene.getEngine()),n._downSamplePostprocess.onApply=function(e){e.setTexture("textureSampler",n._shadowMap)},n.blurBoxOffset=1),n._scene.postProcessManager.directRender([n._downSamplePostprocess,n._boxBlurPostprocess],n._shadowMap2.getInternalTexture()))};var o=function(t){var r=t.getRenderingMesh(),i=n._scene,o=i.getEngine();o.setState(t.getMaterial().backFaceCulling);var s=r._getInstancesRenderList(t._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[t._id];if(n.isReady(t,a)){o.enableEffect(n._effect),r._bind(t,n._effect,e.Material.TriangleFillMode);var h=t.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())}r.useBones&&n._effect.setMatrices("mBones",r.skeleton.getTransformMatrices()),r._processRendering(t,n._effect,e.Material.TriangleFillMode,s,a,function(e,t){return n._effect.setMatrix("world",t)})}else n._shadowMap.resetRefreshCounter()}};this._shadowMap.customRenderFunction=function(e,t,r){var i;for(i=0;i=1?1:0>=e?0:e},t.prototype.setTransparencyShadow=function(e){this._transparencyShadow=e},t.prototype._packHalf=function(t){var r=255*t,i=r-Math.floor(r);return new e.Vector2(t-i/255,i)},t.prototype.dispose=function(){this._shadowMap.dispose(),this._shadowMap2&&this._shadowMap2.dispose(),this._downSamplePostprocess&&this._downSamplePostprocess.dispose(),this._boxBlurPostprocess&&this._boxBlurPostprocess.dispose()},t._FILTER_NONE=0,t._FILTER_VARIANCESHADOWMAP=1,t._FILTER_POISSONSAMPLING=2,t._FILTER_BLURVARIANCESHADOWMAP=3,t}();e.ShadowGenerator=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e,t,r,i){return e.x>r.x+i?!1:r.x-i>t.x?!1:e.y>r.y+i?!1:r.y-i>t.y?!1:e.z>r.z+i?!1:r.z-i>t.z?!1:!0},r=function(e,t,r,i){var n=t*t-4*e*r,o={root:0,found:!1};if(0>n)return o;var s=Math.sqrt(n),a=(-t-s)/(2*e),h=(-t+s)/(2*e);if(a>h){var c=h;h=a,a=c}return a>0&&i>a?(o.root=a,o.found=!0,o):h>0&&i>h?(o.root=h,o.found=!0,o):o},i=function(){function i(){this.radius=new e.Vector3(1,1,1),this.retry=0,this.basePointWorld=e.Vector3.Zero(),this.velocityWorld=e.Vector3.Zero(),this.normalizedVelocity=e.Vector3.Zero(),this._collisionPoint=e.Vector3.Zero(),this._planeIntersectionPoint=e.Vector3.Zero(),this._tempVector=e.Vector3.Zero(),this._tempVector2=e.Vector3.Zero(),this._tempVector3=e.Vector3.Zero(),this._tempVector4=e.Vector3.Zero(),this._edge=e.Vector3.Zero(),this._baseToVertex=e.Vector3.Zero(),this._destinationPoint=e.Vector3.Zero(),this._slidePlaneNormal=e.Vector3.Zero(),this._displacementVector=e.Vector3.Zero()}return i.prototype._initialize=function(t,r,i){this.velocity=r,e.Vector3.NormalizeToRef(r,this.normalizedVelocity),this.basePoint=t,t.multiplyToRef(this.radius,this.basePointWorld),r.multiplyToRef(this.radius,this.velocityWorld),this.velocityWorldLength=this.velocityWorld.length(),this.epsilon=i,this.collisionFound=!1},i.prototype._checkPointInTriangle=function(t,r,i,n,o){r.subtractToRef(t,this._tempVector),i.subtractToRef(t,this._tempVector2),e.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var s=e.Vector3.Dot(this._tempVector4,o);return 0>s?!1:(n.subtractToRef(t,this._tempVector3),e.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),s=e.Vector3.Dot(this._tempVector4,o),0>s?!1:(e.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),s=e.Vector3.Dot(this._tempVector4,o),s>=0))},i.prototype._canDoCollision=function(r,i,n,o){var s=e.Vector3.Distance(this.basePointWorld,r),a=Math.max(this.radius.x,this.radius.y,this.radius.z);return s>this.velocityWorldLength+a+i?!1:t(n,o,this.basePointWorld,this.velocityWorldLength+a)?!0:!1},i.prototype._testTriangle=function(t,i,n,o,s,a){var h,c=!1;i||(i=[]),i[t]||(i[t]=new e.Plane(0,0,0,0),i[t].copyFromPoints(n,o,s));var l=i[t];if(a||l.isFrontFacingTo(this.normalizedVelocity,0)){var u=l.signedDistanceTo(this.basePoint),f=e.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*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=r(v,y,x,_);b.found&&(_=b.root,m=!0,this._collisionPoint.copyFrom(n)),this.basePoint.subtractToRef(o,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=r(v,y,x,_),b.found&&(_=b.root,m=!0,this._collisionPoint.copyFrom(o)),this.basePoint.subtractToRef(s,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=r(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 A=this._edge.lengthSquared(),M=e.Vector3.Dot(this._edge,this.velocity),T=e.Vector3.Dot(this._edge,this._baseToVertex);if(v=A*-g+M*M,y=2*A*e.Vector3.Dot(this.velocity,this._baseToVertex)-2*M*T,x=A*(1-this._baseToVertex.lengthSquared())+T*T,b=r(v,y,x,_),b.found){var S=(M*b.root-T)/A;S>=0&&1>=S&&(_=b.root,m=!0,this._edge.scaleInPlace(S),n.addToRef(this._edge,this._collisionPoint))}s.subtractToRef(o,this._edge),o.subtractToRef(this.basePoint,this._baseToVertex),A=this._edge.lengthSquared(),M=e.Vector3.Dot(this._edge,this.velocity),T=e.Vector3.Dot(this._edge,this._baseToVertex),v=A*-g+M*M,y=2*A*e.Vector3.Dot(this.velocity,this._baseToVertex)-2*M*T,x=A*(1-this._baseToVertex.lengthSquared())+T*T,b=r(v,y,x,_),b.found&&(S=(M*b.root-T)/A,S>=0&&1>=S&&(_=b.root,m=!0,this._edge.scaleInPlace(S),o.addToRef(this._edge,this._collisionPoint))),n.subtractToRef(s,this._edge),s.subtractToRef(this.basePoint,this._baseToVertex),A=this._edge.lengthSquared(),M=e.Vector3.Dot(this._edge,this.velocity),T=e.Vector3.Dot(this._edge,this._baseToVertex),v=A*-g+M*M,y=2*A*e.Vector3.Dot(this.velocity,this._baseToVertex)-2*M*T,x=A*(1-this._baseToVertex.lengthSquared())+T*T,b=r(v,y,x,_),b.found&&(S=(M*b.root-T)/A,S>=0&&1>=S&&(_=b.root,m=!0,this._edge.scaleInPlace(S),s.addToRef(this._edge,this._collisionPoint)))}if(m){var E=_*this.velocity.length();(!this.collisionFound||Ea;a+=3){var h=t[r[a]-o],c=t[r[a+1]-o],l=t[r[a+2]-o];this._testTriangle(a,e,l,c,h,s)}},i.prototype._getResponse=function(t,r){t.addToRef(r,this._destinationPoint),r.scaleInPlace(this.nearestDistance/r.length()),this.basePoint.addToRef(r,t),t.subtractToRef(this.intersectionPoint,this._slidePlaneNormal),this._slidePlaneNormal.normalize(),this._slidePlaneNormal.scaleToRef(this.epsilon,this._displacementVector),t.addInPlace(this._displacementVector),this.intersectionPoint.addInPlace(this._displacementVector),this._slidePlaneNormal.scaleInPlace(e.Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint,this._slidePlaneNormal,this._destinationPoint)),this._destinationPoint.subtractInPlace(this._slidePlaneNormal),this._destinationPoint.subtractToRef(this.intersectionPoint,r)},i}();e.Collider=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){e.CollisionWorker="",function(e){e[e.INIT=0]="INIT",e[e.UPDATE=1]="UPDATE",e[e.COLLIDE=2]="COLLIDE"}(e.WorkerTaskType||(e.WorkerTaskType={}));var t=e.WorkerTaskType;!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.UNKNOWN_ERROR=1]="UNKNOWN_ERROR"}(e.WorkerReplyType||(e.WorkerReplyType={}));var r=e.WorkerReplyType,i=function(){function i(){var n=this;this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this.onMeshUpdated=function(e){n._addUpdateMeshesList[e.uniqueId]=i.SerializeMesh(e)},this.onGeometryUpdated=function(e){n._addUpdateGeometriesList[e.id]=i.SerializeGeometry(e)},this._afterRender=function(){if(n._init&&!(0==n._toRemoveGeometryArray.length&&0==n._toRemoveMeshesArray.length&&0==Object.keys(n._addUpdateGeometriesList).length&&0==Object.keys(n._addUpdateMeshesList).length||n._runningUpdated>4)){++n._runningUpdated;var e={updatedMeshes:n._addUpdateMeshesList,updatedGeometries:n._addUpdateGeometriesList,removedGeometries:n._toRemoveGeometryArray,removedMeshes:n._toRemoveMeshesArray},r={payload:e,taskType:t.UPDATE},i=[];for(var o in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(o)&&(i.push(r.payload.updatedGeometries[o].indices.buffer),i.push(r.payload.updatedGeometries[o].normals.buffer),i.push(r.payload.updatedGeometries[o].positions.buffer));n._worker.postMessage(r,i),n._addUpdateMeshesList={},n._addUpdateGeometriesList={},n._toRemoveGeometryArray=[],n._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(i){var o=i.data;if(o.error!=r.SUCCESS)return void e.Tools.Warn("error returned from worker!");switch(o.taskType){case t.INIT:n._init=!0,n._scene.meshes.forEach(function(e){n.onMeshAdded(e)}),n._scene.getGeometries().forEach(function(e){n.onGeometryAdded(e)});break;case t.UPDATE:n._runningUpdated--;break;case t.COLLIDE:n._runningCollisionTask=!1;var s=o.payload;if(!n._collisionsCallbackArray[s.collisionId])return;n._collisionsCallbackArray[s.collisionId](s.collisionId,e.Vector3.FromArray(s.newPosition),n._scene.getMeshByUniqueID(s.collidedMeshUniqueId)),n._collisionsCallbackArray[s.collisionId]=void 0}},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,this._runningCollisionTask=!1,this._addUpdateMeshesList={},this._addUpdateGeometriesList={},this._toRemoveGeometryArray=[],this._toRemoveMeshesArray=[]}return i.prototype.getNewPosition=function(e,r,i,n,o,s,a){if(this._init&&!this._collisionsCallbackArray[a]&&!this._collisionsCallbackArray[a+1e5]){e.divideToRef(i.radius,this._scaledPosition),r.divideToRef(i.radius,this._scaledVelocity),this._collisionsCallbackArray[a]=s;var h={collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:i.radius.asArray()},collisionId:a,excludedMeshUniqueId:o?o.uniqueId:null,maximumRetry:n},c={payload:h,taskType:t.COLLIDE};this._worker.postMessage(c)}},i.prototype.init=function(r){this._scene=r,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 n={payload:{},taskType:t.INIT};this._worker.postMessage(n)},i.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},i.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},i.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},i.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},i.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},i.SerializeMesh=function(e){var t=[];e.subMeshes&&(t=e.subMeshes.map(function(e,t){return{position:t,verticesStart:e.verticesStart,verticesCount:e.verticesCount,indexStart:e.indexStart,indexCount:e.indexCount,hasMaterial:!!e.getMaterial(),sphereCenter:e.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:e.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:e.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:e.getBoundingInfo().boundingBox.maximumWorld.asArray()}}));var r=e.geometry?e.geometry.id:null;return{uniqueId:e.uniqueId,id:e.id,name:e.name,geometryId:r,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:t,checkCollisions:e.checkCollisions}},i.SerializeGeometry=function(t){return{id:t.id,positions:new Float32Array(t.getVerticesData(e.VertexBuffer.PositionKind)||[]),normals:new Float32Array(t.getVerticesData(e.VertexBuffer.NormalKind)||[]),indices:new Int32Array(t.getIndices()||[])}},i}();e.CollisionCoordinatorWorker=i;var n=function(){function t(){this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this._finalPosition=e.Vector3.Zero()}return t.prototype.getNewPosition=function(e,t,r,i,n,o,s){e.divideToRef(r.radius,this._scaledPosition),t.divideToRef(r.radius,this._scaledVelocity),r.collidedMesh=null,r.retry=0,r.initialVelocity=this._scaledVelocity,r.initialPosition=this._scaledPosition,this._collideWithWorld(this._scaledPosition,this._scaledVelocity,r,i,this._finalPosition,n),this._finalPosition.multiplyInPlace(r.radius),o(s,this._finalPosition,r.collidedMesh)},t.prototype.init=function(e){this._scene=e},t.prototype.destroy=function(){},t.prototype.onMeshAdded=function(e){},t.prototype.onMeshUpdated=function(e){},t.prototype.onMeshRemoved=function(e){},t.prototype.onGeometryAdded=function(e){},t.prototype.onGeometryUpdated=function(e){},t.prototype.onGeometryDeleted=function(e){},t.prototype._collideWithWorld=function(t,r,i,n,o,s){void 0===s&&(s=null);var a=10*e.Engine.CollisionsEpsilon;if(i.retry>=n)return void o.copyFrom(t);i._initialize(t,r,a);for(var h=0;h-1)return e.Tools.Error("You're trying to reuse a post process not defined as reusable."),0;if(null==r||0>r)return this._postProcesses.push(t),this._postProcessesTakenIndices.push(this._postProcesses.length-1),this._postProcesses.length-1;var i=0;if(this._postProcesses[r]){for(var n=this._postProcesses.length-1,o=n;o>=r+1;--o)this._postProcesses[o+1]=this._postProcesses[o];i=1}for(o=0;o=o;--s)this._postProcessesTakenIndices[s+1]=this._postProcessesTakenIndices[s]+i;this._postProcessesTakenIndices[o]=r;break}i||-1!=this._postProcessesTakenIndices.indexOf(r)||this._postProcessesTakenIndices.push(r);var a=r+i;return this._postProcesses[a]=t,a},i.prototype.detachPostProcess=function(e,t){void 0===t&&(t=null);var r=[];if(t)for(t=t instanceof Array?t:[t],o=0;oo;o++)if(this._postProcesses[o]===e){delete this._postProcesses[o];var s=this._postProcessesTakenIndices.indexOf(o);this._postProcessesTakenIndices.splice(s,1)}return r},i.prototype.getWorldMatrix=function(){this._worldMatrix||(this._worldMatrix=e.Matrix.Identity());var t=this.getViewMatrix();return t.invertToRef(this._worldMatrix),this._worldMatrix},i.prototype._getViewMatrix=function(){return e.Matrix.Identity()},i.prototype.getViewMatrix=function(t){return this._computedViewMatrix=this._computeViewMatrix(t),!t&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this.parent&&this.parent.getWorldMatrix?(this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._computedViewMatrix.invertToRef(this._worldMatrix),this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(),this._computedViewMatrix),this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12],this._computedViewMatrix.m[13],this._computedViewMatrix.m[14]),this._computedViewMatrix.invert(),this._markSyncedWithParent()):this._globalPosition.copyFrom(this.position),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix)},i.prototype._computeViewMatrix=function(e){return!e&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this._computedViewMatrix=this._getViewMatrix(),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix)},i.prototype.getProjectionMatrix=function(t){if(!t&&this._isSynchronizedProjectionMatrix())return this._projectionMatrix;var r=this.getEngine();if(this.mode===i.PERSPECTIVE_CAMERA)return this.minZ<=0&&(this.minZ=.1),e.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 e.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(){for(this.getScene().removeCamera(this);this.subCameras.length>0;)this.subCameras.pop().dispose();for(var e=0;e0;)this.subCameras.pop().dispose();this._subCameraMode=r,this._subCamHalfSpace=e.Tools.ToRadians(n);var s,a,h=this.getSubCamera(this.name+"_A",!0),c=this.getSubCamera(this.name+"_B",!1);switch(this._subCameraMode){case i.SUB_CAMERA_MODE_ANAGLYPH:s=new e.PassPostProcess(this.name+"_leftTexture",1,h),h.isIntermediate=!0,a=new e.AnaglyphPostProcess(this.name+"_anaglyph",1,c),a.onApply=function(e){e.setTextureFromPostProcess("leftSampler",s)};break;case i.SUB_CAMERA_MODE_HORIZONTAL_STEREOSCOPIC:case i.SUB_CAMERA_MODE_VERTICAL_STEREOSCOPIC:var l=this._subCameraMode===i.SUB_CAMERA_MODE_HORIZONTAL_STEREOSCOPIC;s=new e.PassPostProcess("passthru",1,h),h.isIntermediate=!0,a=new e.StereoscopicInterlacePostProcess("st_interlace",c,s,l);break;case i.SUB_CAMERA_MODE_VR:o=o||t.GetDefault(),h._vrMetrics=o,h.viewport=new e.Viewport(0,0,.5,1),h._vrWorkMatrix=new e.Matrix,h._vrHMatrix=o.leftHMatrix,h._vrPreViewMatrix=o.leftPreViewMatrix,h.getProjectionMatrix=h._getVRProjectionMatrix,o.compensateDistorsion&&(s=new e.VRDistortionCorrectionPostProcess("Distortion Compensation Left",h,!1,o)),c._vrMetrics=h._vrMetrics,c.viewport=new e.Viewport(.5,0,.5,1),c._vrWorkMatrix=new e.Matrix,c._vrHMatrix=o.rightHMatrix,c._vrPreViewMatrix=o.rightPreViewMatrix,c.getProjectionMatrix=c._getVRProjectionMatrix,o.compensateDistorsion&&(a=new e.VRDistortionCorrectionPostProcess("Distortion Compensation Right",c,!0,o))}this._subCameraMode!==i.SUB_CAMERA_MODE_NONE&&(this.subCameras.push(h),this.subCameras.push(c)),this._update()},i.prototype._getVRProjectionMatrix=function(){return e.Matrix.PerspectiveFovLHToRef(this._vrMetrics.aspectRatioFov,this._vrMetrics.aspectRatio,this.minZ,this.maxZ,this._vrWorkMatrix),this._vrWorkMatrix.multiplyToRef(this._vrHMatrix,this._projectionMatrix),this._projectionMatrix},i.prototype.setSubCamHalfSpace=function(t){this._subCamHalfSpace=e.Tools.ToRadians(t)},i.prototype.getSubCamera=function(e,t){return null},i.prototype._updateSubCameras=function(){var e=this.subCameras[i.SUB_CAMERAID_A],t=this.subCameras[i.SUB_CAMERAID_B];e.minZ=t.minZ=this.minZ,e.maxZ=t.maxZ=this.maxZ,e.fov=t.fov=this.fov,this._subCameraMode===i.SUB_CAMERA_MODE_ANAGLYPH&&(e.viewport=t.viewport=this.viewport)},i._PERSPECTIVE_CAMERA=0,i._ORTHOGRAPHIC_CAMERA=1,i._FOVMODE_VERTICAL_FIXED=0,i._FOVMODE_HORIZONTAL_FIXED=1,i._SUB_CAMERA_MODE_NONE=0,i._SUB_CAMERA_MODE_ANAGLYPH=1,i._SUB_CAMERA_MODE_HORIZONTAL_STEREOSCOPIC=2,i._SUB_CAMERA_MODE_VERTICAL_STEREOSCOPIC=3,i._SUB_CAMERA_MODE_VR=4,i._SUB_CAMERAID_A=0,i._SUB_CAMERAID_B=1,i}(e.Node);e.Camera=r}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n){t.call(this,r,i,n),this.cameraDirection=new e.Vector3(0,0,0),this.cameraRotation=new e.Vector2(0,0),this.rotation=new e.Vector3(0,0,0),this.speed=2,this.noRotationConstraint=!1,this.lockedTarget=null,this._currentTarget=e.Vector3.Zero(),this._viewMatrix=e.Matrix.Zero(),this._camMatrix=e.Matrix.Zero(),this._cameraTransformMatrix=e.Matrix.Zero(),this._cameraRotationMatrix=e.Matrix.Zero(),this._referencePoint=new e.Vector3(0,0,1),this._transformedReferencePoint=e.Vector3.Zero(),this._lookAtTemp=e.Matrix.Zero(),this._tempMatrix=e.Matrix.Zero()}return __extends(r,t),r.prototype._getLockedTargetPosition=function(){return this.lockedTarget?this.lockedTarget.position||this.lockedTarget:null},r.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.lockedTarget=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.rotation=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},r.prototype._updateCache=function(e){e||t.prototype._updateCache.call(this);var r=this._getLockedTargetPosition();r?this._cache.lockedTarget?this._cache.lockedTarget.copyFrom(r):this._cache.lockedTarget=r.clone():this._cache.lockedTarget=null,this._cache.rotation.copyFrom(this.rotation)},r.prototype._isSynchronizedViewMatrix=function(){if(!t.prototype._isSynchronizedViewMatrix.call(this))return!1;var e=this._getLockedTargetPosition();return(this._cache.lockedTarget?this._cache.lockedTarget.equals(e):!e)&&this._cache.rotation.equals(this.rotation)},r.prototype._computeLocalCameraSpeed=function(){var e=this.getEngine();return this.speed*(e.getDeltaTime()/(10*e.getFps()))},r.prototype.setTarget=function(t){this.upVector.normalize(),e.Matrix.LookAtLHToRef(this.position,t,this.upVector,this._camMatrix),this._camMatrix.invert(),this.rotation.x=Math.atan(this._camMatrix.m[6]/this._camMatrix.m[10]);var r=t.subtract(this.position);this.rotation.y=r.x>=0?-Math.atan(r.z/r.x)+Math.PI/2:-Math.atan(r.z/r.x)-Math.PI/2,this.rotation.z=-Math.acos(e.Vector3.Dot(new e.Vector3(0,1,0),this.upVector)),isNaN(this.rotation.x)&&(this.rotation.x=0),isNaN(this.rotation.y)&&(this.rotation.y=0),isNaN(this.rotation.z)&&(this.rotation.z=0)},r.prototype.getTarget=function(){return this._currentTarget},r.prototype._decideIfNeedsToMove=function(){return Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},r.prototype._updatePosition=function(){this.position.addInPlace(this.cameraDirection)},r.prototype._checkInputs=function(){var r=this._decideIfNeedsToMove(),i=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(r&&this._updatePosition(),i&&(this.rotation.x+=this.cameraRotation.x,this.rotation.y+=this.cameraRotation.y,!this.noRotationConstraint)){var n=Math.PI/2*.95;this.rotation.x>n&&(this.rotation.x=n),this.rotation.x<-n&&(this.rotation.x=-n)}r&&(Math.abs(this.cameraDirection.x)e.Engine.CollisionsEpsilon&&(o.position.addInPlace(o._diffPosition),o.onCollide&&i&&o.onCollide(i))};n(r)}}return __extends(r,t),r.prototype.attachControl=function(t,r){var i,n=this,o=this.getEngine();this._attachedElement||(this._attachedElement=t,void 0===this._onMouseDown&&(this._onMouseDown=function(e){i={x:e.clientX,y:e.clientY},r||e.preventDefault()},this._onMouseUp=function(e){i=null,r||e.preventDefault()},this._onMouseOut=function(e){i=null,n._keys=[],r||e.preventDefault()},this._onMouseMove=function(e){if(i||o.isPointerLock){var t,s;o.isPointerLock?(t=e.movementX||e.mozMovementX||e.webkitMovementX||e.msMovementX||0,s=e.movementY||e.mozMovementY||e.webkitMovementY||e.msMovementY||0):(t=e.clientX-i.x,s=e.clientY-i.y),n.cameraRotation.y+=t/n.angularSensibility,n.cameraRotation.x+=s/n.angularSensibility,i={x:e.clientX,y:e.clientY},r||e.preventDefault()}},this._onKeyDown=function(e){if(-1!==n.keysUp.indexOf(e.keyCode)||-1!==n.keysDown.indexOf(e.keyCode)||-1!==n.keysLeft.indexOf(e.keyCode)||-1!==n.keysRight.indexOf(e.keyCode)){var t=n._keys.indexOf(e.keyCode);-1===t&&n._keys.push(e.keyCode),r||e.preventDefault()}},this._onKeyUp=function(e){if(-1!==n.keysUp.indexOf(e.keyCode)||-1!==n.keysDown.indexOf(e.keyCode)||-1!==n.keysLeft.indexOf(e.keyCode)||-1!==n.keysRight.indexOf(e.keyCode)){var t=n._keys.indexOf(e.keyCode);t>=0&&n._keys.splice(t,1),r||e.preventDefault()}},this._onLostFocus=function(){n._keys=[]},this._reset=function(){n._keys=[],i=null,n.cameraDirection=new e.Vector3(0,0,0),n.cameraRotation=new e.Vector2(0,0)}),t.addEventListener("mousedown",this._onMouseDown,!1),t.addEventListener("mouseup",this._onMouseUp,!1),t.addEventListener("mouseout",this._onMouseOut,!1),t.addEventListener("mousemove",this._onMouseMove,!1),e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]))},r.prototype.detachControl=function(t){this._attachedElement==t&&(t.removeEventListener("mousedown",this._onMouseDown),t.removeEventListener("mouseup",this._onMouseUp),t.removeEventListener("mouseout",this._onMouseOut),t.removeEventListener("mousemove",this._onMouseMove),e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]),this._attachedElement=null,this._reset&&this._reset())},r.prototype._collideWithWorld=function(t){var r;r=this.parent?e.Vector3.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position,r.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._collider.radius=this.ellipsoid,this.applyGravity&&t.addInPlace(this.getScene().gravity),this.getScene().collisionCoordinator.getNewPosition(this._oldPosition,t,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId)},r.prototype._checkInputs=function(){this._localDirection||(this._localDirection=e.Vector3.Zero(),this._transformedDirection=e.Vector3.Zero());for(var r=0;r0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},r.prototype._updatePosition=function(){this.checkCollisions&&this.getScene().collisionsEnabled?this._collideWithWorld(this.cameraDirection):this.position.addInPlace(this.cameraDirection)},r}(e.TargetCamera);e.FreeCamera=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(e,r,i){t.call(this,e,r,i),this.radius=12,this.rotationOffset=0,this.heightOffset=4,this.cameraAcceleration=.05,this.maxCameraSpeed=20}return __extends(r,t),r.prototype.getRadians=function(e){return e*Math.PI/180},r.prototype.follow=function(t){if(t){var r;if(t.rotationQuaternion){var i=new e.Matrix;t.rotationQuaternion.toRotationMatrix(i),r=Math.atan2(i.m[8],i.m[10])}else r=t.rotation.y;var n=this.getRadians(this.rotationOffset)+r,o=t.position.x+Math.sin(n)*this.radius,s=t.position.z+Math.cos(n)*this.radius,a=o-this.position.x,h=t.position.y+this.heightOffset-this.position.y,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 e.Vector3(this.position.x+l,this.position.y+u,this.position.z+f),this.setTarget(t.position)}},r.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.follow(this.target)},r}(e.TargetCamera);e.FollowCamera=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(e,r,i){t.call(this,e,r,i),this._offsetX=null,this._offsetY=null,this._pointerCount=0,this._pointerPressed=[],this.angularSensibility=2e5,this.moveSensibility=500}return __extends(r,t),r.prototype.attachControl=function(t,r){var i,n=this;this._attachedCanvas||(this._attachedCanvas=t,void 0===this._onPointerDown&&(this._onPointerDown=function(e){r||e.preventDefault(),n._pointerPressed.push(e.pointerId),1===n._pointerPressed.length&&(i={x:e.clientX,y:e.clientY})},this._onPointerUp=function(e){r||e.preventDefault();var t=n._pointerPressed.indexOf(e.pointerId);-1!==t&&(n._pointerPressed.splice(t,1),0==t&&(i=null,n._offsetX=null,n._offsetY=null))},this._onPointerMove=function(e){if(r||e.preventDefault(),i){var t=n._pointerPressed.indexOf(e.pointerId);0==t&&(n._offsetX=e.clientX-i.x,n._offsetY=-(e.clientY-i.y))}},this._onLostFocus=function(){n._offsetX=null,n._offsetY=null}),t.addEventListener("pointerdown",this._onPointerDown),t.addEventListener("pointerup",this._onPointerUp),t.addEventListener("pointerout",this._onPointerUp),t.addEventListener("pointermove",this._onPointerMove),e.Tools.RegisterTopRootEvents([{name:"blur",handler:this._onLostFocus}]))},r.prototype.detachControl=function(t){this._attachedCanvas==t&&(t.removeEventListener("pointerdown",this._onPointerDown),t.removeEventListener("pointerup",this._onPointerUp),t.removeEventListener("pointerout",this._onPointerUp),t.removeEventListener("pointermove",this._onPointerMove),e.Tools.UnregisterTopRootEvents([{name:"blur",handler:this._onLostFocus}]),this._attachedCanvas=null)},r.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 r=this._computeLocalCameraSpeed(),i=new e.Vector3(0,0,r*this._offsetY/this.moveSensibility);e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,0,this._cameraRotationMatrix),this.cameraDirection.addInPlace(e.Vector3.TransformCoordinates(i,this._cameraRotationMatrix))}t.prototype._checkInputs.call(this)}},r}(e.FreeCamera);e.TouchCamera=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=e.Tools.GetPointerPrefix(),r=function(r){function i(t,i,n,o,s,a){var h=this;r.call(this,t,e.Vector3.Zero(),a),this.alpha=i,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=e.Vector2.Zero(),this.pinchInwards=!0,this._keys=[],this._viewMatrix=new e.Matrix,this.checkCollisions=!1,this.collisionRadius=new e.Vector3(.5,.5,.5),this._collider=new e.Collider,this._previousPosition=e.Vector3.Zero(),this._collisionVelocity=e.Vector3.Zero(),this._newPosition=e.Vector3.Zero(),this._onCollisionPositionChange=function(t,r,i){void 0===i&&(i=null),h.getScene().workerCollisions&&h.checkCollisions&&r.multiplyInPlace(h._collider.radius),i?(h.setPosition(h._previousPosition),h.position.copyFrom(h._previousPosition),h.onCollide&&h.onCollide(i)):(h._previousPosition.copyFrom(h.position),h.setPosition(h._newPosition),h.position.copyFrom(h._newPosition)),e.Matrix.LookAtLHToRef(h.position,h._getTargetPosition(),h.upVector,h._viewMatrix),h._viewMatrix.m[12]+=h.targetScreenOffset.x,h._viewMatrix.m[13]+=h.targetScreenOffset.y,h._collisionTriggered=!1},this.target||(this.target=e.Vector3.Zero()),this.getViewMatrix()}return __extends(i,r),i.prototype._getTargetPosition=function(){return this.target.position||this.target},i.prototype._initCache=function(){r.prototype._initCache.call(this),this._cache.target=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.alpha=void 0,this._cache.beta=void 0,this._cache.radius=void 0,this._cache.targetScreenOffset=void 0},i.prototype._updateCache=function(e){e||r.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()},i.prototype._isSynchronizedViewMatrix=function(){return r.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},i.prototype.attachControl=function(r,i){var n,o=this,s=0,a=new e.SmartCollection;if(!this._attachedElement){this._attachedElement=r;var h=this.getEngine();void 0===this._onPointerDown&&(this._onPointerDown=function(e){a.add(e.pointerId,{x:e.clientX,y:e.clientY,type:e.pointerType}),n=a.item(e.pointerId),i||e.preventDefault()},this._onPointerUp=function(e){n=null,s=0,a.remove(e.pointerId),i||e.preventDefault()},this._onPointerMove=function(e){switch(i||e.preventDefault(),a.count){case 1:var t=e.clientX-n.x,r=e.clientY-n.y;o.inertialAlphaOffset-=t/o.angularSensibility,o.inertialBetaOffset-=r/o.angularSensibility,n.x=e.clientX,n.y=e.clientY;break;case 2:a.item(e.pointerId).x=e.clientX,a.item(e.pointerId).y=e.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(e.pointerId)&&(a.item(e.pointerId).x=e.clientX,a.item(e.pointerId).y=e.clientY)}},this._onMouseMove=function(e){if(h.isPointerLock){var t=e.movementX||e.mozMovementX||e.webkitMovementX||e.msMovementX||0,r=e.movementY||e.mozMovementY||e.webkitMovementY||e.msMovementY||0;o.inertialAlphaOffset-=t/o.angularSensibility,o.inertialBetaOffset-=r/o.angularSensibility,i||e.preventDefault()}},this._wheel=function(e){var t=0;e.wheelDelta?t=e.wheelDelta/(40*o.wheelPrecision):e.detail&&(t=-e.detail/o.wheelPrecision),t&&(o.inertialRadiusOffset+=t),e.preventDefault&&(i||e.preventDefault())},this._onKeyDown=function(e){if(-1!==o.keysUp.indexOf(e.keyCode)||-1!==o.keysDown.indexOf(e.keyCode)||-1!==o.keysLeft.indexOf(e.keyCode)||-1!==o.keysRight.indexOf(e.keyCode)){var t=o._keys.indexOf(e.keyCode);-1===t&&o._keys.push(e.keyCode),e.preventDefault&&(i||e.preventDefault())}},this._onKeyUp=function(e){if(-1!==o.keysUp.indexOf(e.keyCode)||-1!==o.keysDown.indexOf(e.keyCode)||-1!==o.keysLeft.indexOf(e.keyCode)||-1!==o.keysRight.indexOf(e.keyCode)){var t=o._keys.indexOf(e.keyCode);t>=0&&o._keys.splice(t,1),e.preventDefault&&(i||e.preventDefault())}},this._onLostFocus=function(){o._keys=[],a.empty(), s=0,n=null},this._onGestureStart=function(e){void 0!==window.MSGesture&&(o._MSGestureHandler||(o._MSGestureHandler=new MSGesture,o._MSGestureHandler.target=r),o._MSGestureHandler.addPointer(e.pointerId))},this._onGesture=function(e){o.radius*=e.scale,e.preventDefault&&(i||(e.stopPropagation(),e.preventDefault()))},this._reset=function(){o._keys=[],o.inertialAlphaOffset=0,o.inertialBetaOffset=0,o.inertialRadiusOffset=0,a.empty(),s=0,n=null}),r.addEventListener(t+"down",this._onPointerDown,!1),r.addEventListener(t+"up",this._onPointerUp,!1),r.addEventListener(t+"out",this._onPointerUp,!1),r.addEventListener(t+"move",this._onPointerMove,!1),r.addEventListener("mousemove",this._onMouseMove,!1),r.addEventListener("MSPointerDown",this._onGestureStart,!1),r.addEventListener("MSGestureChange",this._onGesture,!1),r.addEventListener("mousewheel",this._wheel,!1),r.addEventListener("DOMMouseScroll",this._wheel,!1),e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}])}},i.prototype.detachControl=function(r){this._attachedElement===r&&(r.removeEventListener(t+"down",this._onPointerDown),r.removeEventListener(t+"up",this._onPointerUp),r.removeEventListener(t+"out",this._onPointerUp),r.removeEventListener(t+"move",this._onPointerMove),r.removeEventListener("mousemove",this._onMouseMove),r.removeEventListener("MSPointerDown",this._onGestureStart),r.removeEventListener("MSGestureChange",this._onGesture),r.removeEventListener("mousewheel",this._wheel),r.removeEventListener("DOMMouseScroll",this._wheel),e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]),this._MSGestureHandler=null,this._attachedElement=null,this._reset&&this._reset())},i.prototype._checkInputs=function(){if(!this._collisionTriggered){for(var t=0;tMath.PI&&(this.beta=this.beta-2*Math.PI):this.betathis.upperBetaLimit&&(this.beta=this.upperBetaLimit),this.lowerAlphaLimit&&this.alphathis.upperAlphaLimit&&(this.alpha=this.upperAlphaLimit),this.lowerRadiusLimit&&this.radiusthis.upperRadiusLimit&&(this.radius=this.upperRadiusLimit),r.prototype._checkInputs.call(this)}},i.prototype.setPosition=function(e){var t=e.subtract(this._getTargetPosition());this.radius=t.length(),this.alpha=Math.acos(t.x/Math.sqrt(Math.pow(t.x,2)+Math.pow(t.z,2))),t.z<0&&(this.alpha=2*Math.PI-this.alpha),this.beta=Math.acos(t.y/this.radius)},i.prototype._getViewMatrix=function(){var t=Math.cos(this.alpha),r=Math.sin(this.alpha),i=Math.cos(this.beta),n=Math.sin(this.beta),o=this._getTargetPosition();o.addToRef(new e.Vector3(this.radius*t*n,this.radius*i,this.radius*r*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));var s=this.upVector.clone();return this.beta<0&&(s=s.negate()),e.Matrix.LookAtLHToRef(this.position,o,s,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},i.prototype.zoomOn=function(t){t=t||this.getScene().meshes;var r=e.Mesh.MinMax(t),i=e.Vector3.Distance(r.min,r.max);this.radius=i*this.zoomOnFactor,this.focusOn({min:r.min,max:r.max,distance:i})},i.prototype.focusOn=function(t){var r,i;void 0===t.min?(r=t||this.getScene().meshes,r=e.Mesh.MinMax(r),i=e.Vector3.Distance(r.min,r.max)):(r=t,i=t.distance),this.target=e.Mesh.Center(r),this.maxZ=2*i},i.prototype.getSubCamera=function(t,r){var i=this._subCamHalfSpace*(r?-1:1);return new e.ArcRotateCamera(t,this.alpha+i,this.beta,this.radius,this.target,this.getScene())},i.prototype._updateSubCameras=function(){var t=this.subCameras[e.Camera.SUB_CAMERAID_A],i=this.subCameras[e.Camera.SUB_CAMERAID_B];t.alpha=this.alpha-this._subCamHalfSpace,i.alpha=this.alpha+this._subCamHalfSpace,t.beta=i.beta=this.beta,t.radius=i.radius=this.radius,r.prototype._updateSubCameras.call(this)},i}(e.Camera);e.ArcRotateCamera=r}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(e,r,i){var n=this;t.call(this,e,r,i),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(r,t),r.prototype.attachControl=function(e,t){var r=this;this._attachedCanvas||(this._attachedCanvas=e,this._orientationChanged||(this._orientationChanged=function(e){r._initialOrientationGamma||(r._initialOrientationGamma=e.gamma,r._initialOrientationBeta=e.beta),r._orientationGamma=e.gamma,r._orientationBeta=e.beta,r._offsetY=r._initialOrientationBeta-r._orientationBeta,r._offsetX=r._initialOrientationGamma-r._orientationGamma}),window.addEventListener("deviceorientation",this._orientationChanged))},r.prototype.detachControl=function(e){this._attachedCanvas==e&&(window.removeEventListener("deviceorientation",this._orientationChanged),this._attachedCanvas=null,this._orientationGamma=0,this._orientationBeta=0,this._initialOrientationGamma=0,this._initialOrientationBeta=0)},r.prototype._checkInputs=function(){if(this._offsetX){this.cameraRotation.y-=this._offsetX/this.angularSensibility;var r=this._computeLocalCameraSpeed(),i=new e.Vector3(0,0,r*this._offsetY/this.moveSensibility);e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,0,this._cameraRotationMatrix),this.cameraDirection.addInPlace(e.Vector3.TransformCoordinates(i,this._cameraRotationMatrix)),t.prototype._checkInputs.call(this)}},r}(e.FreeCamera);e.DeviceOrientationCamera=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(){function t(e){var t=this;this.babylonGamepads=[],this.oneGamepadConnected=!1,this.isMonitoring=!1,this.gamepadEventSupported="GamepadEvent"in window,this.gamepadSupportAvailable=navigator.getGamepads||!!navigator.webkitGetGamepads||!!navigator.msGetGamepads||!!navigator.webkitGamepads,this.buttonADataURL="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAA9aSURBVHja7FtpbBzneX7m3otcihSpm9Z9UJalxPKhVLZlp6ktNzEaxE0CtAnQAgnSoPWPBi3syuiPwordFi5Qt2haFygCoylSV4Vby6os1I3kOLYrS65kXXQoypJJSaFEUTyXy925+rzfzC6HFFlL1kpAIe7i5czO7H7zPs97ft8MtTAMcSu/dNzirxkCZgiYIWCGgBkCZgi4hV/mDR5fSxAt+0ZiX0ucDxMSTJLK+f83BFSA6TFgK75OclshouKBFbA+xaV4k7Z+fD6sNRlmjYFXQMu4NiUVS/oHe5/ecnHo3MYxd7QthN9UcsdW6FqEPwgDOFbqpAajL2VlTrTULzj4Ow8+s4+nipSxWMoxIUkyrl/pGswFtIR7WzHgDCX77K7vfHNkbOA+AryjYZadb27OIJdzCNZBKmXw4kbk35qPsTEfJbeEkZESentHMdBfGtY142gu1bDvqV/925f4tQJlNCaj4hXX7RHXS0AFuJEAXvfHr/zmk67vPjir0V68aFEe8xtuQ6O1FHlrEXLmHBiaDUtzYBlpNYjrF+GFZfhhCcPeBQy53ehzT+H8QBe6uwfRf7l8xjKsvX/y5X98jl8fThDhJ4i46QQkrS5I6v7oX7/++77vPtLUlFnZtnIRlubvxRxnHbJmE79sxD/SqG0oZk8MFarRqufUkQAFrxcXSkfx0eB+nOggKX2jHYZhvf79r/z4L2IiipO84aYRkASfefnAX695p3P3c9mM/UufuaMVdzRvxVx7A0xaWdOMqVULJ6Z3TZv6KmHo0ztK6CkfxpHe3Th0pAuF0fLbn1u+9cmv3vW77bE3fGoSPi0BVfAvvPEHm9rPv//iooWz5m9Z/wCWZx+Go9UrN48QTD9IGMZ1cJIzTPisRQclPMrhME4W9mDfB2+i+2z/+TXz7/z2E7/85+9OIuGGE6BV3H77zm/d33nx6Ktr18zFg2t+DQude2n1tLJ8tcJ90vDhpG5Am7qTkJAQErywiLOld7G3/d9xvL0Hy1vWPbbtS3//00Q4hDeaAFXintrx1fu7+jp2r13bgofX/gaazbVkJQdLT9P6VqRFDSu2hIgXlBUBLgtCr3cce47/CMePX0Rr08qtzz7+8k8TpfKGtcKq1jPZre7oObyjdWkGd628l7AXwvMCeL7HjO6qrS8S1E5kTE9tfbiur665ccU9EB1EF9Ep0WXesEZIJb9j5/b/XUtzNrt29Rw0og2lchmBVqLo8LSAHlCixbTpddGm8Y7pjkttCCUP+JQy3FiatNuxdvUx9F4ayopO/OL9sQeEN4oA/eHn577oWPbGVes11PsrUBxjDafze1Te1VzouqnK2TgmLQljQqmrnAsT+iaPVb5b2co7EC+QhBgUeM1R1AcrsGp9Jy6+4W8U3fZ8r+e3EnOI2uaAX3l+zgNB4O9rW5/B8tY5WGo9BtOrJ4uMfUl+uj0B8HTmPXj8Pex86xVEnTDBBSE2r78fX9i09RPyZfT2A5ceIMSPwDOH8JH7Kk5+fAHtR0Zh6MZ9e7534Wc3wgO0sXLhD9OpFOa0egjGMhguD8BgTJooMfPbV1h/umz25ondcFP90IzY2iTgrfY9uH31aqSc9CeSEHkBEyITv28M8XMGc2/z0HGCpWCs8BS/9sWrDYOrJuCBZ+vu5sUfXbicia5kYGzUw4DWTwJKbApSjHuTBBjT2H68zg0MD4KlEwabZi0Y7wd85u/3O9/B6sVrPlEXeiF9nMmRxPt6Qf4y/HyIbh3HwkdF1zefGt5fUwK8wP2WAGwh02MFE/5ogYr3Qg/STL0W3d8aB1ppa+Pw0uI2Tz6/134Mg+UoIGZlZ2HMLaJYHkPICr6//RBamvPj/UA4dYKsegGrXqAXMaqNsDT6SreOY5Gu/FptCeBFN+caAphGiKFiGaOjA3AJHoGt6r7GgNbjqjo5yQkBUVHQ8PaJExjiaZ2yue12nO27gCNdHSptvf/xGdw11I2UZSmvCIJgQiJMhoEfeqpNDvUSRvUB5hMX9fUecg0aBi+Hm2uaAz633bmbm1VN8+h07LfKJdkOkQB2fL4BTlsj8No4YLG2putMSjwjp3QNvZdH8YsiExV501isFjU30lpF7D8dVfCA8sFHp7BuWYtaIwiCsCrCSDVhh9IX8k0CoHsoMQ84FrfFAE3zQAK0VaLzO9tK79XKAxSj+aYALt3XLfNipZD1v492YexrE/sP0zBgUIQIoYaflAXbz16CzyY6YKqYl8uheTarRioD7xAxCQHUpv18L1Yud+Iloujtk4zQo9WZcKURqjbHclzKvj0Gvcw8UA6oY2WqonSuGQGb5I+TJgEFEsB4daXzc0eopabcX13W0BXwgAnRZL4Q62s8ppnR/pFz/QjF+tRvxeIsY/cizGwRt83P4czACL8HdA1JUivCNGVogvdkNkgaGDNe4CvXFyJ8n+B5XGLJ1FmJXJ53AzjZKgGbatkKL5c/liNWIPO8uM/4VO2uKCQZjLmBqQAGJ4EmI8NMabDTOuyUobYXmPlCEpiqA1IkYdWSBpjpEDl6wsrF9aAjqHNOPXDyXAGprAknY5B0btOGGk/GlfE1taqofCNuuYNIJ+omOiZ1rpUHtEYWjkpWoP5EWV2sb5isA7aIQTHHxaIniNADui8PIs0Eb6SY/Z0UQc+j+mXYuoM7Vy/Age7zkBUyCZGLhRLSOYcWpfXFA1wPhqup8JNKq5UkKeoqSHxPLSoqnUQtw5ioc60IyE/VkOji8mYE2nZELNgCXLaOkGDFJBg4OzCMDEcxCfAzS1pQX5fHSNDLClLGwmwzls6vQ09hGFJYegdZ1hha2bqIBNelB5Qjog02TzpFNVEquYpMuTSYr/lcQPKPJHoRQ8W1GYO3lDgpO9pPWTEZEQGnuodg5Hyk66Lyd8fKOQQ6gqyWict7GeuWz8HQyWEFw+bB7ksF3Nk2V1nfpZTLQqSLslzXlDmHpsQ1osVoy/Solwf/GpdErpaAQUqjWxL2GWcWaSfAMIis7RBwiuCdtD1OgmNHBJCg7r4uZBnbdjaaq+3YewB+USYicY8juYPnMtloqdCjG3f39eO+3JKIAFadSiiZigBdgdcqItMxsmZbIbvUIKlzzQjoEgLGRjU2KTp8AjRCkzEnAG0mtQh8Ku0oAqok8JzP+Lw0MkB3jpKjKpapaL5WKZxafDdBqoC6O8LtyMAQhoZdzG7MwLU8FUYKPINcl+qimismRj26v2I71I3jDxfdpM41I6CTsmG4X0djKyc8RYu9t0Vl2QJbBJ5xFPiICJIg1hdhR3fs5HnWeldleZXABLA98b7Y5HtjkgwNEtbTN4iFC5oI3I1CTsAbsfVjAizJB3Qbx9HphRp6eqr3TDprSYA0FI/3ntOxbpUNM2OjpEcE6HYEWkhIKw+ICeBxi+T09F1WZU+iJq2n8fRDf4Ymu3XSrcOIgg8H9uOFn31fNUVC0oddZ7B5YxtDwlTgo66SEici2fokwCJjju0hw7J54WypQsB7tSRAza+H+nld30Y+m2b7SS+Qn9PKFl1egRciHIfWpxC8x+7tdA97+3zUcNyWX4Ci/THOoD2x/hmlQTox+3gDjWYeg/4gmF853xjBpUsjaGnJR24fu36FNzX5pmfY7EPStlSLIgb6gwk616QRYk8tS88/l/2PT/loyqbQkEmhPpNGNp1CmvtieQHvONGtL4sdy9Hjp5kkpTWmSzM7L529hErHs0cCpt2qW00BymDV3JXSU8HkAXKIjtNnedxS48m4Mr5cR9YlMrx+XTqNRmbP2ZkMOjvHKir/PNa5pouiitFjH44iZ6YwO5tFAy+eo6SdpOUJyhBQTJR+HT9HYLJaFve0PqQmTQLaVOCdmIRIWE+wrmWTzG8iAugF7qgWjSWkGbYa32EjJQTkGFv5dBZNJKCeHdb77UPXZP1rWhKLZ4Rqjv2Fz86lLMNlpusCY9BnqTNUIyTgrVhhs7rVq2KoW2TSxWlXLOCqWX4svmpzZdEjWvgQcdVWPnu+i4ClUS+HyLIFnsVf/9eBduw8eKYy2D1XMxO8Jg+IB9wl+3s/uAC3qKMpXY88m/ecnUHaSis3Na8Ab1UtaCh3j1y+sm8m9o0J+9Fv9MR4Zhw6DufTWasOebsOs+xZKHJOtvtQtertulrwV+0BtH5yWvyW7CxubsCTX9+KUQZ4ga7qmdGUFmrya8QWHwcxlReMF8Mw4QETrR8oy7tq2ivH5Tvya8n8aXZMGc4An/nRDpy52FfR8b5KCJCImt8YkYF/KDtnegfwz3sPodGajQajCTk9z/4mQ6iphMWv9AA9IeMWdyYdn+gBkVc5amwHWV6lHvVaI2YZzfinN95Ngv/htcT/p31CRNbdV8l8e++xD5HPNeHxhx5Bgf18kTN5T1kvjBfEjGjBJCai4gnjHqAnlvqS8e9NeujEjEul/NokDbai4V/2voafHD1S0evdWLeb8ojMNyly5fS//ffbcD0L33j4K4RX4rtMh/UUGLXmr6BWXN9MEFAhYfzmZ6hcXI+TpISRH8061Ui68gTWGUJP4aU9P8ZrB39S+Xkx1ummPSMkbebnJcxU1jm4D5eGhvB7j32HJcpUJHhxLIfxTZpxwGa8eKrHC51a9Tmp+N5P1RsQ01cJAwEflHw8/+pfYn/HgaQ+n7/a1vd6k+BUS2XvVD401TXhu488gQ0r71QUuLJsrWT8mSYtfkBMm0BAmFhNrgDX4oRqqeaJMw4c6TyIv/qPP0Xf8KUJ6sXuP1XluuEEyGsD5TXKgsqBNQvW4RtbnkDb4ttJQlGt/IQqLMJE7tWqOSBZCSrL6dFSqq3AnzhzDC/tewHt5w4nr3suvgN0+P8o3TeegFe3vYDHtj+xhLt/Q3kkeW5d693YuuHXsWHZPcixW4tCwo+trVU9QEs8G6HFqW5kdBiHTu3H64dfxpGuK8r665Tv7tz2D6e/tP23cT0E1OA5QR2iiIbs1i9u/9qTPPC12CtwlIofjZVvW/BZ3LVsC5bPW4u5DQuxaPay2NpRIuy61IkLA+dw8hdHceDUPpw49z9TXUysvWPXtl3bQ4yQtMJ1a18DAsbvRO/atvM5DXXPPbp9yzP8+GXBXTkngKYBdTWvE5RXdm87+HQEfLh2T57UIAdM95Js9+04LKSDbLzG31+Omxpx9xfxKR6AukkhMP0aKuUHsag5VEzE3fGSddsUVu6KFzIE+H/iJry0mX+bu8VfMwTMEDBDwAwBMwTMEHALv/5XgAEASpR5N6rB30UAAAAASUVORK5CYII=",this._callbackGamepadConnected=e,this.gamepadSupportAvailable?(this.gamepadEventSupported?(window.addEventListener("gamepadconnected",function(e){t._onGamepadConnected(e)},!1),window.addEventListener("gamepaddisconnected",function(e){t._onGamepadDisconnected(e)},!1)):this._startMonitoringGamepads(),this.oneGamepadConnected||this._insertGamepadDOMInstructions()):this._insertGamepadDOMNotSupported()}return t.prototype._insertGamepadDOMInstructions=function(){t.gamepadDOMInfo=document.createElement("div");var e=document.createElement("img");e.src=this.buttonADataURL;var r=document.createElement("span");r.innerHTML="to activate gamepad",t.gamepadDOMInfo.appendChild(e),t.gamepadDOMInfo.appendChild(r),t.gamepadDOMInfo.style.position="absolute",t.gamepadDOMInfo.style.width="100%",t.gamepadDOMInfo.style.height="48px",t.gamepadDOMInfo.style.bottom="0px",t.gamepadDOMInfo.style.backgroundColor="rgba(1, 1, 1, 0.15)",t.gamepadDOMInfo.style.textAlign="center",t.gamepadDOMInfo.style.zIndex="10",e.style.position="relative",e.style.bottom="8px",r.style.position="relative",r.style.fontSize="32px",r.style.bottom="32px",r.style.color="green",document.body.appendChild(t.gamepadDOMInfo)},t.prototype._insertGamepadDOMNotSupported=function(){t.gamepadDOMInfo=document.createElement("div");var e=document.createElement("span");e.innerHTML="gamepad not supported",t.gamepadDOMInfo.appendChild(e),t.gamepadDOMInfo.style.position="absolute",t.gamepadDOMInfo.style.width="100%",t.gamepadDOMInfo.style.height="40px",t.gamepadDOMInfo.style.bottom="0px",t.gamepadDOMInfo.style.backgroundColor="rgba(1, 1, 1, 0.15)",t.gamepadDOMInfo.style.textAlign="center",t.gamepadDOMInfo.style.zIndex="10",e.style.position="relative",e.style.fontSize="32px",e.style.color="red",document.body.appendChild(t.gamepadDOMInfo)},t.prototype.dispose=function(){t.gamepadDOMInfo&&document.body.removeChild(t.gamepadDOMInfo)},t.prototype._onGamepadConnected=function(e){var t=this._addNewGamepad(e.gamepad);this._callbackGamepadConnected&&this._callbackGamepadConnected(t),this._startMonitoringGamepads()},t.prototype._addNewGamepad=function(r){this.oneGamepadConnected||(this.oneGamepadConnected=!0,t.gamepadDOMInfo&&(document.body.removeChild(t.gamepadDOMInfo),t.gamepadDOMInfo=null));var i;return i=-1!==r.id.search("Xbox 360")||-1!==r.id.search("xinput")?new e.Xbox360Pad(r.id,r.index,r):new e.GenericPad(r.id,r.index,r),this.babylonGamepads.push(i),i},t.prototype._onGamepadDisconnected=function(e){for(var t in this.babylonGamepads)if(this.babylonGamepads[t].index==e.gamepad.index){this.babylonGamepads.splice(t,1);break}0==this.babylonGamepads.length&&this._stopMonitoringGamepads()},t.prototype._startMonitoringGamepads=function(){this.isMonitoring||(this.isMonitoring=!0,this._checkGamepadsStatus())},t.prototype._stopMonitoringGamepads=function(){this.isMonitoring=!1},t.prototype._checkGamepadsStatus=function(){var e=this;this._updateGamepadObjects();for(var t in this.babylonGamepads)this.babylonGamepads[t].update();this.isMonitoring&&(window.requestAnimationFrame?window.requestAnimationFrame(function(){e._checkGamepadsStatus()}):window.mozRequestAnimationFrame?window.mozRequestAnimationFrame(function(){e._checkGamepadsStatus()}):window.webkitRequestAnimationFrame&&window.webkitRequestAnimationFrame(function(){e._checkGamepadsStatus()}))},t.prototype._updateGamepadObjects=function(){for(var e=navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads():[],t=0;t=2&&(this._leftStick={x:this.browserGamepad.axes[0],y:this.browserGamepad.axes[1]}),this.browserGamepad.axes.length>=4&&(this._rightStick={x:this.browserGamepad.axes[2],y:this.browserGamepad.axes[3]})}return e.prototype.onleftstickchanged=function(e){this._onleftstickchanged=e},e.prototype.onrightstickchanged=function(e){this._onrightstickchanged=e},Object.defineProperty(e.prototype,"leftStick",{get:function(){return this._leftStick},set:function(e){!this._onleftstickchanged||this._leftStick.x===e.x&&this._leftStick.y===e.y||this._onleftstickchanged(e),this._leftStick=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rightStick",{get:function(){return this._rightStick},set:function(e){!this._onrightstickchanged||this._rightStick.x===e.x&&this._rightStick.y===e.y||this._onrightstickchanged(e),this._rightStick=e},enumerable:!0,configurable:!0}),e.prototype.update=function(){this._leftStick&&(this.leftStick={x:this.browserGamepad.axes[0],y:this.browserGamepad.axes[1]}),this._rightStick&&(this.rightStick={x:this.browserGamepad.axes[2],y:this.browserGamepad.axes[3]})},e}();e.Gamepad=i;var n=function(e){function t(t,r,i){e.call(this,t,r,i),this.id=t,this.index=r,this.gamepad=i,this._buttons=new Array(i.buttons.length)}return __extends(t,e),t.prototype.onbuttondown=function(e){this._onbuttondown=e},t.prototype.onbuttonup=function(e){this._onbuttonup=e},t.prototype._setButtonValue=function(e,t,r){return e!==t&&(this._onbuttondown&&1===e&&this._onbuttondown(r),this._onbuttonup&&0===e&&this._onbuttonup(r)),e},t.prototype.update=function(){e.prototype.update.call(this);for(var t=0;t.005?0+i:0,r.y=Math.abs(n)>.005?0+n:0;var o=this._gamepad.rightStick,s=o.x/this.angularSensibility,a=o.y/this.angularSensibility;o.x=Math.abs(s)>.001?0+s:0,o.y=Math.abs(a)>.001?0+a:0;var h=e.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,0),c=50*this._computeLocalCameraSpeed(),l=e.Vector3.TransformCoordinates(new e.Vector3(r.x*c,0,-r.y*c),h);this.cameraDirection=this.cameraDirection.add(l),this.cameraRotation=this.cameraRotation.add(new e.Vector2(o.y,o.x))}t.prototype._checkInputs.call(this)},r.prototype.dispose=function(){this._gamepads.dispose(),t.prototype.dispose.call(this)},r}(e.FreeCamera);e.GamepadCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e){this._renderingGroups=new Array,this._scene=e}return t.prototype._renderParticles=function(t,r){if(0!==this._scene._activeParticleSystems.length){for(var i=e.Tools.Now,n=0;nt._alphaIndex?1:e._alphaIndext._distanceToCamera?-1:0}),n.setAlphaMode(e.Engine.ALPHA_COMBINE),r=0;r0)return!1;for(var t=0;t-1&&this._onBeforeRenderCallbacks.splice(t,1)},t.prototype.registerAfterRender=function(e){this._onAfterRenderCallbacks.push(e)},t.prototype.unregisterAfterRender=function(e){var t=this._onAfterRenderCallbacks.indexOf(e);t>-1&&this._onAfterRenderCallbacks.splice(t,1)},t.prototype._addPendingData=function(e){this._pendingData.push(e)},t.prototype._removePendingData=function(e){var t=this._pendingData.indexOf(e);-1!==t&&this._pendingData.splice(t,1)},t.prototype.getWaitingItemsCount=function(){return this._pendingData.length},t.prototype.executeWhenReady=function(e){var t=this;this._onReadyCallbacks.push(e),-1===this._executeWhenReadyTimeoutId&&(this._executeWhenReadyTimeoutId=setTimeout(function(){t._checkIsReady()},150))},t.prototype._checkIsReady=function(){var e=this;return this.isReady()?(this._onReadyCallbacks.forEach(function(e){e()}),this._onReadyCallbacks=[],void(this._executeWhenReadyTimeoutId=-1)):void(this._executeWhenReadyTimeoutId=setTimeout(function(){e._checkIsReady()},150))},t.prototype.beginAnimation=function(t,r,i,n,o,s,a){if(void 0===o&&(o=1),this.stopAnimation(t),a||(a=new e.Animatable(this,t,r,i,n,o,s)),t.animations&&a.appendAnimations(t,t.animations),t.getAnimatables)for(var h=t.getAnimatables(),c=0;c0?this.cameras[0]:null),this.onCameraRemoved&&this.onCameraRemoved(e),t},t.prototype.addLight=function(e){e.uniqueId=this._uniqueIdCounter++;var t=this.lights.push(e);this.onNewLightAdded&&this.onNewLightAdded(e,t,this)},t.prototype.addCamera=function(e){e.uniqueId=this._uniqueIdCounter++;var t=this.cameras.push(e);this.onNewCameraAdded&&this.onNewCameraAdded(e,t,this)},t.prototype.setActiveCameraByID=function(e){var t=this.getCameraByID(e);return t?(this.activeCamera=t,t):null},t.prototype.setActiveCameraByName=function(e){var t=this.getCameraByName(e);return t?(this.activeCamera=t,t):null},t.prototype.getMaterialByID=function(e){for(var t=0;t-1?(this._geometries.splice(t,1),this.collisionCoordinator.onGeometryDeleted(e),this.onGeometryRemoved&&this.onGeometryRemoved(e),!0):!1},t.prototype.getGeometries=function(){return this._geometries},t.prototype.getMeshByID=function(e){for(var t=0;t=0;t--)if(this.meshes[t].id===e)return this.meshes[t];return null},t.prototype.getLastEntryByID=function(e){for(var t=this.meshes.length-1;t>=0;t--)if(this.meshes[t].id===e)return this.meshes[t];for(t=this.cameras.length-1;t>=0;t--)if(this.cameras[t].id===e)return this.cameras[t];for(t=this.lights.length-1;t>=0;t--)if(this.lights[t].id===e)return this.lights[t];return null},t.prototype.getNodeByName=function(e){var t=this.getMeshByName(e);if(t)return t;var r=this.getLightByName(e);return r?r:this.getCameraByName(e)},t.prototype.getMeshByName=function(e){for(var t=0;t=0;t--)if(this.skeletons[t].id===e)return this.skeletons[t];return null},t.prototype.getSkeletonById=function(e){for(var t=0;tn;n++){var o=t[n];if(!o.isBlocked&&(this._totalVertices+=o.getTotalVertices(),o.isReady()&&o.isEnabled())){o.computeWorldMatrix(),o.actionManager&&o.actionManager.hasSpecificTriggers([e.ActionManager.OnIntersectionEnterTrigger,e.ActionManager.OnIntersectionExitTrigger])&&this._meshesForIntersections.pushNoDuplicate(o);var s=o.getLOD(this.activeCamera);s&&(o._preActivate(),(o.alwaysSelectAsActiveMesh||o.isVisible&&o.visibility>0&&0!==(o.layerMask&this.activeCamera.layerMask)&&o.isInFrustum(this._frustumPlanes))&&(this._activeMeshes.push(o),this.activeCamera._activeMeshes.push(o),o._activate(this._renderId),this._activeMesh(s)))}}var a=e.Tools.Now;if(this.particlesEnabled){e.Tools.StartPerformanceCounter("Particles",this.particleSystems.length>0);for(var h=0;h0)}this._particlesDuration+=e.Tools.Now-a},t.prototype._activeMesh=function(e){if(e.skeleton&&this.skeletonsEnabled&&this._activeSkeletons.pushNoDuplicate(e.skeleton),(e.showBoundingBox||this.forceShowBoundingBoxes)&&this._boundingBoxRenderer.renderList.push(e.getBoundingInfo().boundingBox),e&&e.subMeshes){var t,r;if(e._submeshesOctree&&e.useOctreeForRenderingSelection){var i=e._submeshesOctree.select(this._frustumPlanes);t=i.length,r=i.data}else r=e.subMeshes,t=r.length;for(var n=0;t>n;n++){var o=r[n];this._evaluateSubMesh(o,e)}}},t.prototype.updateTransformMatrix=function(e){this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(e))},t.prototype._renderForCamera=function(t){var r=this._engine;if(this.activeCamera=t,!this.activeCamera)throw new Error("Active camera not set");e.Tools.StartPerformanceCounter("Rendering camera "+this.activeCamera.name),r.setViewport(this.activeCamera.viewport),this.resetCachedMaterial(),this._renderId++,this.updateTransformMatrix(),this.beforeCameraRender&&this.beforeCameraRender(this.activeCamera);var i=e.Tools.Now;e.Tools.StartPerformanceCounter("Active meshes evaluation"),this._evaluateActiveMeshes(),this._evaluateActiveMeshesDuration+=e.Tools.Now-i,e.Tools.EndPerformanceCounter("Active meshes evaluation");for(var n=0;n0);for(var a=0;a0),this._renderId++}this._renderTargets.length>0&&r.restoreDefaultFramebuffer(),this._renderTargetsDuration+=e.Tools.Now-s,this.postProcessManager._prepareFrame();var l=e.Tools.Now;if(this.layers.length){r.setDepthBuffer(!1);var u,f;for(u=0;u0);for(var d=0;d0)}if(this.layers.length){for(r.setDepthBuffer(!1),u=0;u-1&&(n.trigger===e.ActionManager.OnIntersectionExitTrigger&&n._executeCurrent(e.ActionEvent.CreateNew(r)),r.actionManager.hasSpecificTrigger(e.ActionManager.OnIntersectionExitTrigger)&&n.trigger!==e.ActionManager.OnIntersectionExitTrigger||r._intersectionsInProgress.splice(h,1))}}},t.prototype.render=function(){var r=e.Tools.Now;this._particlesDuration=0,this._spritesDuration=0,this._activeParticles=0,this._renderDuration=0,this._renderTargetsDuration=0,this._evaluateActiveMeshesDuration=0,this._totalVertices=0,this._activeIndices=0,this._activeBones=0,this.getEngine().resetDrawCalls(),this._meshesForIntersections.reset(),this.resetCachedMaterial(),e.Tools.StartPerformanceCounter("Scene rendering"),this.actionManager&&this.actionManager.processTrigger(e.ActionManager.OnEveryFrameTrigger,null),this.simplificationQueue.running||this.simplificationQueue.executeNext(),this.beforeRender&&this.beforeRender();for(var i=0;i0);for(var h=0;h0),this._renderId++}if(this.customRenderTargets.length>0&&s.restoreDefaultFramebuffer(),this._renderTargetsDuration+=e.Tools.Now-o,this.activeCamera=a,this.proceduralTexturesEnabled){e.Tools.StartPerformanceCounter("Procedural textures",this._proceduralTextures.length>0);for(var l=0;l0)}if(this._engine.clear(this.clearColor,this.autoClear||this.forceWireframe||this.forcePointsCloud,!0),this.shadowsEnabled)for(var f=0;f0)for(var m=this._renderId,_=0;_0?this.activeCameras[0]:this.activeCamera,t&&r.canUseWebAudio){r.audioContext.listener.setPosition(t.position.x,t.position.y,t.position.z);var i=e.Matrix.Invert(t.getViewMatrix()),n=e.Vector3.TransformNormal(new e.Vector3(0,0,-1),i);n.normalize(),r.audioContext.listener.setOrientation(n.x,n.y,n.z,0,1,0);for(var o=0;o-1&&this._engine.scenes.splice(e,1),this._engine.wipeCaches()},t.prototype.disposeSounds=function(){this.mainSoundTrack.dispose();for(var e=0;e=n.distance))&&(n=c,i))break}return n||new e.PickingInfo},t.prototype.pick=function(e,t,r,i,n){var o=this;return this._internalPick(function(r){return o.createPickingRay(e,t,r,n)},r,i)},t.prototype.pickWithRay=function(t,r,i){var n=this;return this._internalPick(function(r){return n._pickWithRayInverseMatrix||(n._pickWithRayInverseMatrix=e.Matrix.Identity()),r.invertToRef(n._pickWithRayInverseMatrix),e.Ray.Transform(t,n._pickWithRayInverseMatrix)},r,i)},t.prototype.setPointerOverMesh=function(t){this._pointerOverMesh!==t&&(this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(e.ActionManager.OnPointerOutTrigger,e.ActionEvent.CreateNew(this._pointerOverMesh)),this._pointerOverMesh=t,this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(e.ActionManager.OnPointerOverTrigger,e.ActionEvent.CreateNew(this._pointerOverMesh)))},t.prototype.getPointerOverMesh=function(){return this._pointerOverMesh},t.prototype.getPhysicsEngine=function(){return this._physicsEngine},t.prototype.enablePhysics=function(t,r){return this._physicsEngine?!0:(this._physicsEngine=new e.PhysicsEngine(r),this._physicsEngine.isSupported()?(this._physicsEngine._initialize(t),!0):(this._physicsEngine=null,!1))},t.prototype.disablePhysicsEngine=function(){this._physicsEngine&&(this._physicsEngine.dispose(),this._physicsEngine=void 0)},t.prototype.isPhysicsEnabled=function(){return void 0!==this._physicsEngine},t.prototype.setGravity=function(e){this._physicsEngine&&this._physicsEngine._setGravity(e)},t.prototype.createCompoundImpostor=function(e,t){if(e.parts&&(t=e,e=e.parts),!this._physicsEngine)return null;for(var r=0;r0},enumerable:!0,configurable:!0}),i.prototype._sortLODLevels=function(){this._LODLevels.sort(function(e,t){return e.distancet.distance?-1:0})},i.prototype.addLODLevel=function(t,r){if(r&&r._masterMesh)return e.Tools.Warn("You cannot use a mesh as LOD level twice"),this;var i=new e.Internals.MeshLODLevel(t,r);return this._LODLevels.push(i),r&&(r._masterMesh=this),this._sortLODLevels(),this},i.prototype.getLODLevelAtDistance=function(e){for(var t=0;tr)return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var i=0;it)){for(var r=this.getTotalIndices(),i=r/t|0,n=0;i%3!==0;)i++;this.releaseSubMeshes();for(var o=0;t>o&&!(n>=r);o++)e.SubMesh.CreateFromIndices(0,n,Math.min(i,r-n),this),n+=i;this.synchronizeInstances()}},i.prototype.setVerticesData=function(t,r,i,n){if(t instanceof Array){var o=r;r=t,t=o,e.Tools.Warn("Deprecated usage of setVerticesData detected (since v1.12). Current signature is setVerticesData(kind, data, updatable).")}if(this._geometry)this._geometry.setVerticesData(t,r,i,n);else{var s=new e.VertexData;s.set(r,t);var a=this.getScene();new e.Geometry(e.Geometry.RandomId(),a,s,i,this)}},i.prototype.updateVerticesData=function(e,t,r,i){this._geometry&&(i?(this.makeGeometryUnique(),this.updateVerticesData(e,t,r,!1)):this._geometry.updateVerticesData(e,t,r))},i.prototype.updateVerticesDataDirectly=function(e,t,r,i){this._geometry&&(i?(this.makeGeometryUnique(),this.updateVerticesDataDirectly(e,t,r,!1)):this._geometry.updateVerticesDataDirectly(e,t,r))},i.prototype.updateMeshPositions=function(t,r){void 0===r&&(r=!0);var i=this.getVerticesData(e.VertexBuffer.PositionKind);if(t(i),this.updateVerticesData(e.VertexBuffer.PositionKind,i,!1,!1),r){var n=this.getIndices(),o=this.getVerticesData(e.VertexBuffer.NormalKind);e.VertexData.ComputeNormals(i,n,o),this.updateVerticesData(e.VertexBuffer.NormalKind,o,!1,!1)}},i.prototype.makeGeometryUnique=function(){if(this._geometry){var t=this._geometry.copy(e.Geometry.RandomId());t.applyToMesh(this)}},i.prototype.setIndices=function(t,r){if(this._geometry)this._geometry.setIndices(t,r);else{var i=new e.VertexData;i.indices=t;var n=this.getScene();new e.Geometry(e.Geometry.RandomId(),n,i,!1,this)}},i.prototype._bind=function(t,r,i){var n,o=this.getScene().getEngine();switch(i){case e.Material.PointFillMode:n=null;break;case e.Material.WireFrameFillMode:n=t.getLinesIndexBuffer(this.getIndices(),o);break;default:case e.Material.TriangleFillMode:n=this._geometry.getIndexBuffer()}o.bindMultiBuffers(this._geometry.getVertexBuffers(),n,r)},i.prototype._draw=function(t,r,i){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var n=this.getScene().getEngine();switch(r){case e.Material.PointFillMode:n.drawPointClouds(t.verticesStart,t.verticesCount,i);break;case e.Material.WireFrameFillMode:n.draw(!1,0,t.linesIndexCount,i);break;default:n.draw(!0,t.indexStart,t.indexCount,i)}}},i.prototype.registerBeforeRender=function(e){this._onBeforeRenderCallbacks.push(e)},i.prototype.unregisterBeforeRender=function(e){var t=this._onBeforeRenderCallbacks.indexOf(e);t>-1&&this._onBeforeRenderCallbacks.splice(t,1)},i.prototype.registerAfterRender=function(e){this._onAfterRenderCallbacks.push(e)},i.prototype.unregisterAfterRender=function(e){var t=this._onAfterRenderCallbacks.indexOf(e);t>-1&&this._onAfterRenderCallbacks.splice(t,1)},i.prototype._getInstancesRenderList=function(e){var t=this.getScene();if(this._batchCache.mustReturn=!1,this._batchCache.renderSelf[e]=this.isEnabled()&&this.isVisible,this._batchCache.visibleInstances[e]=null,this._visibleInstances){var r=t.getRenderId();this._batchCache.visibleInstances[e]=this._visibleInstances[r];var i=this._renderId;if(!this._batchCache.visibleInstances[e]&&this._visibleInstances.defaultRenderId&&(this._batchCache.visibleInstances[e]=this._visibleInstances[this._visibleInstances.defaultRenderId],r=Math.max(this._visibleInstances.defaultRenderId,r),i=Math.max(this._visibleInstances.selfDefaultRenderId,r)),this._batchCache.visibleInstances[e]&&this._batchCache.visibleInstances[e].length){if(this._renderIdForInstances[e]===r)return this._batchCache.mustReturn=!0,this._batchCache;r!==i&&(this._batchCache.renderSelf[e]=!1)}this._renderIdForInstances[e]=r}return this._batchCache},i.prototype._renderWithInstances=function(e,t,r,i,n){for(var o=r.visibleInstances[e._id],s=o.length+1,a=16*s*4;this._instancesBufferSizef;f++){var d=l[f];for(s=0;sm;m++)n[a].push(i[a][d*p+m])}}var _=[],g=n[e.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=e.Vector3.FromArray(g,3*f),y=e.Vector3.FromArray(g,3*(f+1)),x=e.Vector3.FromArray(g,3*(f+2)),b=v.subtract(y),A=x.subtract(y),M=e.Vector3.Normalize(e.Vector3.Cross(b,A)),T=0;3>T;T++)_.push(M.x),_.push(M.y),_.push(M.z)}for(this.setIndices(l),this.setVerticesData(e.VertexBuffer.NormalKind,_,o),s=0;si;++i){var n=o[i];if(r.equals(n)){a[t]=i;break}}},function(){for(var e=0;e=s;s++)for(var a=0;ai?i:c;for(var u=0;i>u;)t[n]=h[u].x,t[n+1]=h[u].y,t[n+2]=h[u].z,u++,n+=3}},f=!l.areNormalsFrozen;return l.updateMeshPositions(u,f),l}var d=new i(t,a);d.sideOrientation=c;var p=e.VertexData.CreateRibbon(r,n,o,s,c);return p.applyToMesh(d,h),d},i.CreateDisc=function(t,r,n,o,s,a){void 0===a&&(a=i.DEFAULTSIDE);var h=new i(t,o),c=e.VertexData.CreateDisc(r,n,a);return c.applyToMesh(h,s),h},i.CreateBox=function(t,r,n,o,s){void 0===s&&(s=i.DEFAULTSIDE);var a=new i(t,n),h=e.VertexData.CreateBox(r,s);return h.applyToMesh(a,o),a},i.CreateSphere=function(t,r,n,o,s,a){void 0===a&&(a=i.DEFAULTSIDE);var h=new i(t,o),c=e.VertexData.CreateSphere(r,n,a);return c.applyToMesh(h,s),h},i.CreateCylinder=function(t,r,n,o,s,a,h,c,l){void 0===l&&(l=i.DEFAULTSIDE),void 0!==h&&h instanceof e.Scene||(void 0!==h&&(c=h),h=a,a=1);var u=new i(t,h),f=e.VertexData.CreateCylinder(r,n,o,s,a);return f.applyToMesh(u,c),u},i.CreateTorus=function(t,r,n,o,s,a,h){void 0===h&&(h=i.DEFAULTSIDE);var c=new i(t,s),l=e.VertexData.CreateTorus(r,n,o,h);return l.applyToMesh(c,a),c},i.CreateTorusKnot=function(t,r,n,o,s,a,h,c,l,u){void 0===u&&(u=i.DEFAULTSIDE);var f=new i(t,c),d=e.VertexData.CreateTorusKnot(r,n,o,s,a,h,u);return d.applyToMesh(f,l),f},i.CreateLines=function(t,r,i,n,o){if(void 0===o&&(o=null),o){var s=function(e){for(var t=0,i=0;id&&uu||u>3?0:u;var y=g(r,n,v,x,o,s,a,h,u,f),b=i.CreateRibbon(t,y,c,l,0,d,p,m);return b.pathArray=y,b.path3D=v,b.cap=u,b},i.CreateLathe=function(t,r,n,o,s,a,h){void 0===h&&(h=i.DEFAULTSIDE),n=n||1,o=o||60*n;for(var c=2*Math.PI,l=(e.Axis.Y,new Array),u=0;0===r[u].x;)u++;var f=r[u];for(u=0;uu;u++)d=new e.Vector3(Math.cos(u*p)*n,0,Math.sin(u*p)*n),m.push(d);m.push(m[0]);var _=function(){return 1},g=function(){return 0},v=i.ExtrudeShapeCustom(t,l,m,_,g,!0,!1,i.NO_CAP,s,a,h);return v},i.CreatePlane=function(t,r,n,o,s){void 0===s&&(s=i.DEFAULTSIDE);var a=new i(t,n),h=e.VertexData.CreatePlane(r,s);return h.applyToMesh(a,o),a},i.CreateGround=function(t,r,i,n,o,s){var a=new e.GroundMesh(t,o);a._setReady(!1),a._subdivisions=n;var h=e.VertexData.CreateGround(r,i,n);return h.applyToMesh(a,s),a._setReady(!0),a},i.CreateTiledGround=function(t,r,n,o,s,a,h,c,l){var u=new i(t,c),f=e.VertexData.CreateTiledGround(r,n,o,s,a,h);return f.applyToMesh(u,l),u},i.CreateGroundFromHeightMap=function(t,r,i,n,o,s,a,h,c,l){var u=new e.GroundMesh(t,h);u._subdivisions=o,u._setReady(!1);var f=function(t){var r=document.createElement("canvas"),h=r.getContext("2d"),f=t.width,d=t.height;r.width=f,r.height=d,h.drawImage(t,0,0);var p=h.getImageData(0,0,f,d).data,m=e.VertexData.CreateGroundFromHeightMap(i,n,o,s,a,p,f,d);m.applyToMesh(u,c),u._setReady(!0),l&&l(u)};return e.Tools.LoadImage(r,f,function(){},h.database),u},i.CreateTube=function(t,r,n,o,s,a,h,c,l,u){void 0===l&&(l=i.DEFAULTSIDE),void 0===u&&(u=null);var f=function(t,r,i,n,o,s,a){for(var h,c,l,u,f,d=r.getTangents(),p=r.getNormals(),m=r.getDistances(),_=2*Math.PI,g=_/o,v=function(e,t){return n},y=s||v,x=0,b=0;bA;A++)f=e.Matrix.RotationAxis(d[b],g*A),u=e.Vector3.TransformCoordinates(l,f).scaleInPlace(c).add(t[b]),h.push(u);h.push(h[0]),i[x]=h,x++}var M=function(e,r){for(var i=Array(),n=0;e>n;n++)i.push(t[r]);return i};switch(a){case e.Mesh.NO_CAP:break;case e.Mesh.CAP_START:i.unshift(M(o+1,0));break;case e.Mesh.CAP_END:i.push(M(o+1,t.length-1));break;case e.Mesh.CAP_ALL:i.unshift(M(o+1,0)),i.push(M(o+1,t.length-1))}return i};if(u){var d=u.path3D.update(r),p=f(r,d,u.pathArray,n,u.tessellation,s,u.cap);return u=i.CreateRibbon(null,p,null,null,null,null,null,null,u); }var d=new e.Path3D(r),m=new Array;a=0>a||a>3?0:a;var p=f(r,d,m,n,o,s,a),_=i.CreateRibbon(t,p,!1,!0,0,h,c,l);return _.pathArray=p,_.path3D=d,_.tessellation=o,_.cap=a,_},i.CreateDecal=function(t,r,n,o,s,a){void 0===a&&(a=0);var h=r.getIndices(),c=r.getVerticesData(e.VertexBuffer.PositionKind),l=r.getVerticesData(e.VertexBuffer.NormalKind);if(!o){var u=new e.Vector3(0,0,1),f=r.getScene().activeCamera,d=e.Vector3.TransformCoordinates(u,f.getWorldMatrix());o=f.globalPosition.subtract(d)}var p=-Math.atan2(o.z,o.x)-Math.PI/2,m=Math.sqrt(o.x*o.x+o.z*o.z),_=Math.atan2(o.y,m),g=e.Matrix.RotationYawPitchRoll(p,_,a).multiply(e.Matrix.Translation(n.x,n.y,n.z)),v=e.Matrix.Invert(g),y=r.getWorldMatrix(),x=y.multiply(v),b=new e.VertexData;b.indices=[],b.positions=[],b.normals=[],b.uvs=[];for(var A=0,M=function(t){var r=h[t],i=new e.PositionNormalVertex;return i.position=new e.Vector3(c[3*r],c[3*r+1],c[3*r+2]),i.position=e.Vector3.TransformCoordinates(i.position,x),i.normal=new e.Vector3(l[3*r],l[3*r+1],l[3*r+2]),i},T=function(t,r){if(0===t.length)return t;for(var i=.5*Math.abs(e.Vector3.Dot(s,r)),n=function(t,n){var o=e.Vector3.GetClipFactor(t.position,n.position,r,i);return new e.PositionNormalVertex(e.Vector3.Lerp(t.position,n.position,o),e.Vector3.Lerp(t.normal,n.normal,o))},o=new Array,a=0;a0,c=g>0,l=v>0,m=(h?1:0)+(c?1:0)+(l?1:0)){case 0:o.push(t[a]),o.push(t[a+1]),o.push(t[a+2]);break;case 1:if(h&&(u=t[a+1],f=t[a+2],d=n(t[a],u),p=n(t[a],f)),c){u=t[a],f=t[a+2],d=n(t[a+1],u),p=n(t[a+1],f),o.push(d),o.push(f.clone()),o.push(u.clone()),o.push(f.clone()),o.push(d.clone()),o.push(p);break}l&&(u=t[a],f=t[a+1],d=n(t[a+2],u),p=n(t[a+2],f)),o.push(u.clone()),o.push(f.clone()),o.push(d),o.push(p),o.push(d.clone()),o.push(f.clone());break;case 2:h||(u=t[a].clone(),f=n(u,t[a+1]),d=n(u,t[a+2]),o.push(u),o.push(f),o.push(d)),c||(u=t[a+1].clone(),f=n(u,t[a+2]),d=n(u,t[a]),o.push(u),o.push(f),o.push(d)),l||(u=t[a+2].clone(),f=n(u,t[a]),d=n(u,t[a+1]),o.push(u),o.push(f),o.push(d));break;case 3:}}return o},S=0;S65536))return e.Tools.Warn("Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices"),null;var h,c,l;for(a=0;ac;c++){var l=h[c];s>l&&(s=l),l>a&&(a=l)}return new e.SubMesh(t,s,a-s+1,r,i,n,o)},t}();e.SubMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this.hasAlpha=!1,this.getAlphaFromRGB=!1,this.level=1,this.isCube=!1,this.isRenderTarget=!1,this.animations=new Array,this.coordinatesIndex=0,this.coordinatesMode=e.Texture.EXPLICIT_MODE,this.wrapU=e.Texture.WRAP_ADDRESSMODE,this.wrapV=e.Texture.WRAP_ADDRESSMODE,this.anisotropicFilteringLevel=4,this._scene=t,this._scene.textures.push(this)}return t.prototype.getScene=function(){return this._scene},t.prototype.getTextureMatrix=function(){return null},t.prototype.getReflectionTextureMatrix=function(){return null},t.prototype.getInternalTexture=function(){return this._texture},t.prototype.isReady=function(){return this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED?!0:this._texture?this._texture.isReady:!1},t.prototype.getSize=function(){return this._texture._width?{width:this._texture._width,height:this._texture._height}:this._texture._size?{width:this._texture._size,height:this._texture._size}:{width:0,height:0}},t.prototype.getBaseSize=function(){return this.isReady()?this._texture._size?{width:this._texture._size,height:this._texture._size}:{width:this._texture._baseWidth,height:this._texture._baseHeight}:{width:0,height:0}},t.prototype.scale=function(e){},Object.defineProperty(t.prototype,"canRescale",{get:function(){return!1},enumerable:!0,configurable:!0}),t.prototype._removeFromCache=function(e,t){for(var r=this._scene.getEngine().getLoadedTexturesCache(),i=0;i=0&&this._scene.textures.splice(e,1),void 0!==this._texture&&(this.releaseInternalTexture(),this.onDispose&&this.onDispose())},t}();e.BaseTexture=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(i,n,o,s,a,h,c,l,u){void 0===a&&(a=r.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=null),void 0===c&&(c=null),void 0===l&&(l=null),void 0===u&&(u=!1),t.call(this,n),this.uOffset=0,this.vOffset=0,this.uScale=1,this.vScale=1,this.uAng=0,this.vAng=0,this.wAng=0,this.name=i,this.url=i,this._noMipmap=o,this._invertY=s,this._samplingMode=a,this._buffer=l,this._deleteBuffer=u,i&&(this._texture=this._getFromCache(i,o,a),this._texture?e.Tools.SetImmediate(function(){h&&h()}):n.useDelayedTextureLoading?this.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:(this._texture=n.getEngine().createTexture(i,o,s,n,this._samplingMode,h,c,this._buffer),u&&delete this._buffer))}return __extends(r,t),r.prototype.delayLoad=function(){this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap,this._samplingMode),this._texture||(this._texture=this.getScene().getEngine().createTexture(this.url,this._noMipmap,this._invertY,this.getScene(),this._samplingMode,null,null,this._buffer),this._deleteBuffer&&delete this._buffer))},r.prototype.updateSamplingMode=function(e){this._texture&&this.getScene().getEngine().updateTextureSamplingMode(e,this._texture)},r.prototype._prepareRowForTextureGeneration=function(t,r,i,n){t-=this.uOffset+.5,r-=this.vOffset+.5,i-=.5,e.Vector3.TransformCoordinatesFromFloatsToRef(t,r,i,this._rowGenerationMatrix,n),n.x*=this.uScale,n.y*=this.vScale,n.x+=.5,n.y+=.5,n.z+=.5},r.prototype.getTextureMatrix=function(){return this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.uAng===this._cachedUAng&&this.vAng===this._cachedVAng&&this.wAng===this._cachedWAng?this._cachedTextureMatrix:(this._cachedUOffset=this.uOffset,this._cachedVOffset=this.vOffset,this._cachedUScale=this.uScale,this._cachedVScale=this.vScale,this._cachedUAng=this.uAng,this._cachedVAng=this.vAng,this._cachedWAng=this.wAng,this._cachedTextureMatrix||(this._cachedTextureMatrix=e.Matrix.Zero(),this._rowGenerationMatrix=new e.Matrix,this._t0=e.Vector3.Zero(),this._t1=e.Vector3.Zero(),this._t2=e.Vector3.Zero()),e.Matrix.RotationYawPitchRollToRef(this.vAng,this.uAng,this.wAng,this._rowGenerationMatrix),this._prepareRowForTextureGeneration(0,0,0,this._t0),this._prepareRowForTextureGeneration(1,0,0,this._t1),this._prepareRowForTextureGeneration(0,1,0,this._t2),this._t1.subtractInPlace(this._t0),this._t2.subtractInPlace(this._t0),e.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix.m[0]=this._t1.x,this._cachedTextureMatrix.m[1]=this._t1.y,this._cachedTextureMatrix.m[2]=this._t1.z,this._cachedTextureMatrix.m[4]=this._t2.x,this._cachedTextureMatrix.m[5]=this._t2.y,this._cachedTextureMatrix.m[6]=this._t2.z,this._cachedTextureMatrix.m[8]=this._t0.x,this._cachedTextureMatrix.m[9]=this._t0.y,this._cachedTextureMatrix.m[10]=this._t0.z,this._cachedTextureMatrix)},r.prototype.getReflectionTextureMatrix=function(){if(this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.coordinatesMode===this._cachedCoordinatesMode)return this._cachedTextureMatrix;switch(this._cachedTextureMatrix||(this._cachedTextureMatrix=e.Matrix.Zero(),this._projectionModeMatrix=e.Matrix.Zero()),this._cachedCoordinatesMode=this.coordinatesMode,this.coordinatesMode){case r.SPHERICAL_MODE:e.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix[0]=-.5*this.uScale,this._cachedTextureMatrix[5]=-.5*this.vScale,this._cachedTextureMatrix[12]=.5+this.uOffset,this._cachedTextureMatrix[13]=.5+this.vOffset;break;case r.PLANAR_MODE:e.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix[0]=this.uScale,this._cachedTextureMatrix[5]=this.vScale,this._cachedTextureMatrix[12]=this.uOffset,this._cachedTextureMatrix[13]=this.vOffset;break;case r.PROJECTION_MODE:e.Matrix.IdentityToRef(this._projectionModeMatrix),this._projectionModeMatrix.m[0]=.5,this._projectionModeMatrix.m[5]=-.5,this._projectionModeMatrix.m[10]=0,this._projectionModeMatrix.m[12]=.5,this._projectionModeMatrix.m[13]=.5,this._projectionModeMatrix.m[14]=1,this._projectionModeMatrix.m[15]=1,this.getScene().getProjectionMatrix().multiplyToRef(this._projectionModeMatrix,this._cachedTextureMatrix);break;default:e.Matrix.IdentityToRef(this._cachedTextureMatrix)}return this._cachedTextureMatrix},r.prototype.clone=function(){var e=new r(this._texture.url,this.getScene(),this._noMipmap,this._invertY,this._samplingMode);return e.hasAlpha=this.hasAlpha,e.level=this.level,e.wrapU=this.wrapU,e.wrapV=this.wrapV,e.coordinatesIndex=this.coordinatesIndex,e.coordinatesMode=this.coordinatesMode,e.uOffset=this.uOffset,e.vOffset=this.vOffset,e.uScale=this.uScale,e.vScale=this.vScale,e.uAng=this.uAng,e.vAng=this.vAng,e.wAng=this.wAng,e},r.CreateFromBase64String=function(e,t,i,n,o,s,a,h){return void 0===s&&(s=r.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=null),void 0===h&&(h=null),new r("data:"+t,i,n,o,s,a,h,e)},r.NEAREST_SAMPLINGMODE=1,r.BILINEAR_SAMPLINGMODE=2,r.TRILINEAR_SAMPLINGMODE=3,r.EXPLICIT_MODE=0,r.SPHERICAL_MODE=1,r.PLANAR_MODE=2,r.CUBIC_MODE=3,r.PROJECTION_MODE=4,r.SKYBOX_MODE=5,r.CLAMP_ADDRESSMODE=0,r.WRAP_ADDRESSMODE=1,r.MIRROR_ADDRESSMODE=2,r}(e.BaseTexture);e.Texture=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n,o){t.call(this,i),this.coordinatesMode=e.Texture.CUBIC_MODE,this.name=r,this.url=r,this._noMipmap=o,this.hasAlpha=!1,this._texture=this._getFromCache(r,o),n||(n=["_px.jpg","_py.jpg","_pz.jpg","_nx.jpg","_ny.jpg","_nz.jpg"]),this._extensions=n,this._texture||(i.useDelayedTextureLoading?this.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:this._texture=i.getEngine().createCubeTexture(r,i,n,o)),this.isCube=!0,this._textureMatrix=e.Matrix.Identity()}return __extends(r,t),r.prototype.clone=function(){var e=new r(this.url,this.getScene(),this._extensions,this._noMipmap);return e.level=this.level,e.wrapU=this.wrapU,e.wrapV=this.wrapV,e.coordinatesIndex=this.coordinatesIndex,e.coordinatesMode=this.coordinatesMode,e},r.prototype.delayLoad=function(){this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap),this._texture||(this._texture=this.getScene().getEngine().createCubeTexture(this.url,this.getScene(),this._extensions)))},r.prototype.getReflectionTextureMatrix=function(){return this._textureMatrix},r}(e.BaseTexture);e.CubeTexture=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n,o,s,a){void 0===s&&(s=!0),void 0===a&&(a=e.Engine.TEXTURETYPE_UNSIGNED_INT),t.call(this,null,n,!o),this.renderList=new Array,this.renderParticles=!0,this.renderSprites=!1,this.coordinatesMode=e.Texture.PROJECTION_MODE,this._currentRefreshId=-1,this._refreshRate=1,this.name=r,this.isRenderTarget=!0,this._size=i,this._generateMipMaps=o,this._doNotChangeAspectRatio=s,this._texture=n.getEngine().createRenderTargetTexture(i,{generateMipMaps:o,type:a}),this._renderingManager=new e.RenderingManager(n)}return __extends(r,t),r.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},Object.defineProperty(r.prototype,"refreshRate",{get:function(){return this._refreshRate},set:function(e){this._refreshRate=e,this.resetRefreshCounter()},enumerable:!0,configurable:!0}),r.prototype._shouldRender=function(){return-1===this._currentRefreshId?(this._currentRefreshId=1,!0):this.refreshRate===this._currentRefreshId?(this._currentRefreshId=1,!0):(this._currentRefreshId++,!1)},r.prototype.isReady=function(){return this.getScene().renderTargetsEnabled?t.prototype.isReady.call(this):!1},r.prototype.getRenderSize=function(){return this._size},Object.defineProperty(r.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),r.prototype.scale=function(e){var t=this._size*e;this.resize(t,this._generateMipMaps)},r.prototype.resize=function(e,t){this.releaseInternalTexture(),this._texture=this.getScene().getEngine().createRenderTargetTexture(e,t)},r.prototype.render=function(t,r){var i=this.getScene(),n=i.getEngine();if(this._waitingRenderList){this.renderList=[];for(var o=0;o=0&&this.getScene()._proceduralTextures.splice(t,1),e.prototype.dispose.call(this)},t}(e.Texture);e.ProceduralTexture=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n,o){var s=this;t.call(this,r,i,n,o,!0),this.mirrorPlane=new e.Plane(0,1,0,1),this._transformMatrix=e.Matrix.Zero(),this._mirrorMatrix=e.Matrix.Zero(),this.onBeforeRender=function(){e.Matrix.ReflectionToRef(s.mirrorPlane,s._mirrorMatrix),s._savedViewMatrix=n.getViewMatrix(),s._mirrorMatrix.multiplyToRef(s._savedViewMatrix,s._transformMatrix),n.setTransformMatrix(s._transformMatrix,n.getProjectionMatrix()),n.clipPlane=s.mirrorPlane,n.getEngine().cullBackFaces=!1},this.onAfterRender=function(){n.setTransformMatrix(s._savedViewMatrix,n.getProjectionMatrix()),n.getEngine().cullBackFaces=!0,delete n.clipPlane}}return __extends(r,t),r.prototype.clone=function(){var t=this.getSize(),r=new e.MirrorTexture(this.name,t.width,this.getScene(),this._generateMipMaps);return r.hasAlpha=this.hasAlpha,r.level=this.level,r.mirrorPlane=this.mirrorPlane.clone(),r.renderList=this.renderList.slice(0),r},r}(e.RenderTargetTexture);e.MirrorTexture=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n,o,s){void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,n,!o),this.name=r,this.wrapU=e.Texture.CLAMP_ADDRESSMODE,this.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._generateMipMaps=o,i.getContext?(this._canvas=i,this._texture=n.getEngine().createDynamicTexture(i.width,i.height,o,s)):(this._canvas=document.createElement("canvas"),this._texture=i.width?n.getEngine().createDynamicTexture(i.width,i.height,o,s):n.getEngine().createDynamicTexture(i,i,o,s));var a=this.getSize();this._canvas.width=a.width,this._canvas.height=a.height,this._context=this._canvas.getContext("2d")}return __extends(r,t),Object.defineProperty(r.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),r.prototype.scale=function(e){var t=this.getSize();t.width*=e,t.height*=e,this._canvas.width=t.width,this._canvas.height=t.height,this.releaseInternalTexture(),this._texture=this.getScene().getEngine().createDynamicTexture(t.width,t.height,this._generateMipMaps,this._samplingMode)},r.prototype.getContext=function(){return this._context},r.prototype.clear=function(){var e=this.getSize();this._context.fillRect(0,0,e.width,e.height)},r.prototype.update=function(e){this.getScene().getEngine().updateDynamicTexture(this._texture,this._canvas,void 0===e?!0:e)},r.prototype.drawText=function(e,t,r,i,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=i,null===t){var c=this._context.measureText(e);t=(h.width-c.width)/2}this._context.fillStyle=n,this._context.fillText(e,t,r),a&&this.update(s)},r.prototype.clone=function(){var e=this.getSize(),t=new r(this.name,e.width,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.wrapU=this.wrapU,t.wrapV=this.wrapV,t},r}(e.Texture);e.DynamicTexture=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n,o,s,a){var h=this;void 0===o&&(o=!1),void 0===s&&(s=!1),void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,n,!o,s),this._autoLaunch=!0,this.name=r,this.video=document.createElement("video"),this.video.autoplay=!1,this.video.loop=!0,this.video.addEventListener("canplaythrough",function(){e.Tools.IsExponantOfTwo(h.video.videoWidth)&&e.Tools.IsExponantOfTwo(h.video.videoHeight)?(h.wrapU=e.Texture.WRAP_ADDRESSMODE,h.wrapV=e.Texture.WRAP_ADDRESSMODE):(h.wrapU=e.Texture.CLAMP_ADDRESSMODE,h.wrapV=e.Texture.CLAMP_ADDRESSMODE,o=!1),h._texture=n.getEngine().createDynamicTexture(h.video.videoWidth,h.video.videoHeight,o,a,!1),h._texture.isReady=!0}),i.forEach(function(e){var t=document.createElement("source");t.src=e,h.video.appendChild(t)}),this._lastUpdate=e.Tools.Now}return __extends(r,t),r.prototype.update=function(){this._autoLaunch&&(this._autoLaunch=!1,this.video.play());var t=e.Tools.Now;return t-this._lastUpdate<15||this.video.readyState!==this.video.HAVE_ENOUGH_DATA?!1:(this._lastUpdate=t,this.getScene().getEngine().updateVideoTexture(this._texture,this.video,this._invertY),!0)},r}(e.Texture);e.VideoTexture=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(e,r,i,n,o,s){t.call(this,e,i,null,n,o,s),this._animate=!0,this._time=0,this._texturePath=r,this.loadJson(r),this.refreshRate=1}return __extends(r,t),r.prototype.loadJson=function(t){function r(){e.Tools.Log("No config file found in "+t+" trying to use ShadersStore or DOM element");try{n.setFragment(n._texturePath)}catch(r){e.Tools.Error("No json or ShaderStore or DOM element found for CustomProceduralTexture")}}var i=this,n=this,o=t+"/config.json",s=new XMLHttpRequest;s.open("GET",o,!0),s.addEventListener("load",function(){if(200===s.status||e.Tools.ValidateXHRData(s,1))try{i._config=JSON.parse(s.response),i.updateShaderUniforms(),i.updateTextures(),i.setFragment(i._texturePath+"/custom"),i._animate=i._config.animate,i.refreshRate=i._config.refreshrate}catch(t){r()}else r()},!1),s.addEventListener("error",function(){r()},!1);try{s.send()}catch(a){e.Tools.Error("CustomProceduralTexture: Error on XHR send request.")}},r.prototype.isReady=function(){if(!t.prototype.isReady.call(this))return!1;for(var e in this._textures){var r=this._textures[e];if(!r.isReady())return!1}return!0},r.prototype.render=function(e){this._animate&&(this._time+=.03*this.getScene().getAnimationRatio(),this.updateShaderUniforms()),t.prototype.render.call(this,e)},r.prototype.updateTextures=function(){for(var t=0;tthis._maxRank&&(this._maxRank=e),this._defines[e]=new Array),this._defines[e].push(t)},Object.defineProperty(e.prototype,"isMoreFallbacks",{get:function(){return this._currentRank<=this._maxRank},enumerable:!0,configurable:!0}),e.prototype.reduce=function(e){for(var t=this._defines[this._currentRank],r=0;r0){for(var m=0;m0){for(var g=0;g0&&h.addFallback(f,"LIGHT"+f);var y;if(y=p instanceof e.SpotLight?"#define SPOTLIGHT"+f:p instanceof e.HemisphericLight?"#define HEMILIGHT"+f:"#define POINTDIRLIGHT"+f,a.push(y),f>0&&h.addFallback(f,y.replace("#define ","")),o.shadowsEnabled){var x=p.getShadowGenerator();r&&r.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===t)break}}}if(i.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 A=[e.VertexBuffer.PositionKind];r&&(c&&r.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(A.push(e.VertexBuffer.NormalKind),a.push("#define NORMAL")),l&&(r.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(A.push(e.VertexBuffer.UVKind),a.push("#define UV1")),r.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(A.push(e.VertexBuffer.UV2Kind),a.push("#define UV2"))),r.useVertexColors&&r.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(A.push(e.VertexBuffer.ColorKind),a.push("#define VERTEXCOLOR"),r.hasVertexAlpha&&a.push("#define VERTEXALPHA")),r.useBones&&(A.push(e.VertexBuffer.MatricesIndicesKind),A.push(e.VertexBuffer.MatricesWeightsKind),a.push("#define BONES"),a.push("#define BonesPerMesh "+(r.skeleton.bones.length+1)),a.push("#define BONES4"),h.addFallback(0,"BONES4")),n&&(a.push("#define INSTANCES"),A.push("world0"),A.push("world1"),A.push("world2"),A.push("world3")));var M=a.join("\n");if(this._cachedDefines!==M){this._cachedDefines=M,o.resetCachedMaterial();var T="default";o.getEngine().getCaps().standardDerivatives||(T="legacydefault"),this._effect=o.getEngine().createEffect(T,A,["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"],M,h,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=o.getRenderId(),this._wasPreviouslyReady=!0,!0):!1},i.prototype.unbind=function(){this.reflectionTexture&&this.reflectionTexture.isRenderTarget&&this._effect.setTexture("reflection2DSampler",null)},i.prototype.bindOnlyWorldMatrix=function(e){this._effect.setMatrix("world",e)},i.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(i.FresnelEnabled&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(this._effect.setColor4("diffuseLeftColor",this.diffuseFresnelParameters.leftColor,this.diffuseFresnelParameters.power),this._effect.setColor4("diffuseRightColor",this.diffuseFresnelParameters.rightColor,this.diffuseFresnelParameters.bias)),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&this._effect.setColor4("opacityParts",new e.Color3(this.opacityFresnelParameters.leftColor.toLuminance(),this.opacityFresnelParameters.rightColor.toLuminance(),this.opacityFresnelParameters.bias),this.opacityFresnelParameters.power),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(this._effect.setColor4("reflectionLeftColor",this.reflectionFresnelParameters.leftColor,this.reflectionFresnelParameters.power),this._effect.setColor4("reflectionRightColor",this.reflectionFresnelParameters.rightColor,this.reflectionFresnelParameters.bias)),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._effect.setColor4("emissiveLeftColor",this.emissiveFresnelParameters.leftColor,this.emissiveFresnelParameters.power),this._effect.setColor4("emissiveRightColor",this.emissiveFresnelParameters.rightColor,this.emissiveFresnelParameters.bias))),this.diffuseTexture&&i.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&&i.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&&i.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&&i.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&&i.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&&i.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&&i.BumpTextureEnabled&&(this._effect.setTexture("bumpSampler",this.bumpTexture),this._effect.setFloat2("vBumpInfos",this.bumpTexture.coordinatesIndex,1/this.bumpTexture.level),this._effect.setMatrix("bumpMatrix",this.bumpTexture.getTextureMatrix())),s.clipPlane){var a=s.clipPlane;this._effect.setFloat4("vClipPlane",a.normal.x,a.normal.y,a.normal.z,a.d)}this.pointsCloud&&this._effect.setFloat("pointSize",this.pointSize),s.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor),this._scaledSpecular.r=this.specularColor.r*e.Tools.Clamp(1-this.emissiveColor.r),this._scaledSpecular.g=this.specularColor.g*e.Tools.Clamp(1-this.emissiveColor.g),this._scaledSpecular.b=this.specularColor.b*e.Tools.Clamp(1-this.emissiveColor.b),this._effect.setVector3("vEyePosition",s.activeCamera.position),this._effect.setColor3("vAmbientColor",this._globalAmbientColor),this._effect.setColor4("vSpecularColor",this._scaledSpecular,this.specularPower),this._effect.setColor3("vEmissiveColor",this.emissiveColor)}if(this._scaledDiffuse.r=this.diffuseColor.r*e.Tools.Clamp(1-this.emissiveColor.r),this._scaledDiffuse.g=this.diffuseColor.g*e.Tools.Clamp(1-this.emissiveColor.g),this._scaledDiffuse.b=this.diffuseColor.b*e.Tools.Clamp(1-this.emissiveColor.b),this._effect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*o.visibility),s.lightsEnabled)for(var h=0,c=0;c0&&e.push(this.diffuseTexture),this.ambientTexture&&this.ambientTexture.animations&&this.ambientTexture.animations.length>0&&e.push(this.ambientTexture),this.opacityTexture&&this.opacityTexture.animations&&this.opacityTexture.animations.length>0&&e.push(this.opacityTexture),this.reflectionTexture&&this.reflectionTexture.animations&&this.reflectionTexture.animations.length>0&&e.push(this.reflectionTexture),this.emissiveTexture&&this.emissiveTexture.animations&&this.emissiveTexture.animations.length>0&&e.push(this.emissiveTexture),this.specularTexture&&this.specularTexture.animations&&this.specularTexture.animations.length>0&&e.push(this.specularTexture),this.bumpTexture&&this.bumpTexture.animations&&this.bumpTexture.animations.length>0&&e.push(this.bumpTexture),e},i.prototype.dispose=function(e){this.diffuseTexture&&this.diffuseTexture.dispose(),this.ambientTexture&&this.ambientTexture.dispose(),this.opacityTexture&&this.opacityTexture.dispose(),this.reflectionTexture&&this.reflectionTexture.dispose(),this.emissiveTexture&&this.emissiveTexture.dispose(),this.specularTexture&&this.specularTexture.dispose(),this.bumpTexture&&this.bumpTexture.dispose(),r.prototype.dispose.call(this,e)},i.prototype.clone=function(e){var t=new i(e,this.getScene());return t.checkReadyOnEveryCall=this.checkReadyOnEveryCall,t.alpha=this.alpha,t.fillMode=this.fillMode,t.backFaceCulling=this.backFaceCulling,this.diffuseTexture&&this.diffuseTexture.clone&&(t.diffuseTexture=this.diffuseTexture.clone()),this.ambientTexture&&this.ambientTexture.clone&&(t.ambientTexture=this.ambientTexture.clone()),this.opacityTexture&&this.opacityTexture.clone&&(t.opacityTexture=this.opacityTexture.clone()),this.reflectionTexture&&this.reflectionTexture.clone&&(t.reflectionTexture=this.reflectionTexture.clone()),this.emissiveTexture&&this.emissiveTexture.clone&&(t.emissiveTexture=this.emissiveTexture.clone()),this.specularTexture&&this.specularTexture.clone&&(t.specularTexture=this.specularTexture.clone()),this.bumpTexture&&this.bumpTexture.clone&&(t.bumpTexture=this.bumpTexture.clone()),t.ambientColor=this.ambientColor.clone(),t.diffuseColor=this.diffuseColor.clone(),t.specularColor=this.specularColor.clone(),t.specularPower=this.specularPower,t.emissiveColor=this.emissiveColor.clone(),t},i.DiffuseTextureEnabled=!0,i.AmbientTextureEnabled=!0,i.OpacityTextureEnabled=!0,i.ReflectionTextureEnabled=!0,i.EmissiveTextureEnabled=!0,i.SpecularTextureEnabled=!0,i.BumpTextureEnabled=!0,i.FresnelEnabled=!0,i}(e.Material);e.StandardMaterial=i}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(e){function t(t,r){e.call(this,t,r,!0),this.subMaterials=new Array,r.multiMaterials.push(this)}return __extends(t,e),t.prototype.getSubMaterial=function(e){return 0>e||e>=this.subMaterials.length?this.getScene().defaultMaterial:this.subMaterials[e]},t.prototype.isReady=function(e){for(var t=0;t-1&&(s=i.bones[o.parentBoneIndex]);var a=new e.Bone(o.name,i,s,e.Matrix.FromArray(o.matrix));o.animation&&a.animations.push(d(o.animation))}return i},s=function(t){var r=new e.FresnelParameters;return r.isEnabled=t.isEnabled,r.leftColor=e.Color3.FromArray(t.leftColor),r.rightColor=e.Color3.FromArray(t.rightColor),r.bias=t.bias,r.power=t.power||1,r},a=function(t,r,i){var o;return o=new e.StandardMaterial(t.name,r),o.ambientColor=e.Color3.FromArray(t.ambient),o.diffuseColor=e.Color3.FromArray(t.diffuse),o.specularColor=e.Color3.FromArray(t.specular),o.specularPower=t.specularPower,o.emissiveColor=e.Color3.FromArray(t.emissive),o.alpha=t.alpha,o.id=t.id,e.Tags.AddTagsTo(o,t.tags),o.backFaceCulling=t.backFaceCulling,o.wireframe=t.wireframe,t.diffuseTexture&&(o.diffuseTexture=n(i,t.diffuseTexture,r)),t.diffuseFresnelParameters&&(o.diffuseFresnelParameters=s(t.diffuseFresnelParameters)),t.ambientTexture&&(o.ambientTexture=n(i,t.ambientTexture,r)),t.opacityTexture&&(o.opacityTexture=n(i,t.opacityTexture,r)),t.opacityFresnelParameters&&(o.opacityFresnelParameters=s(t.opacityFresnelParameters)),t.reflectionTexture&&(o.reflectionTexture=n(i,t.reflectionTexture,r)),t.reflectionFresnelParameters&&(o.reflectionFresnelParameters=s(t.reflectionFresnelParameters)),t.emissiveTexture&&(o.emissiveTexture=n(i,t.emissiveTexture,r)),t.emissiveFresnelParameters&&(o.emissiveFresnelParameters=s(t.emissiveFresnelParameters)),t.specularTexture&&(o.specularTexture=n(i,t.specularTexture,r)),t.bumpTexture&&(o.bumpTexture=n(i,t.bumpTexture,r)),o},h=function(e,t,r,i){for(var n=0;n-1&&(n.skeleton=r.getLastSkeletonByID(t.skeletonId)),t.physicsImpostor&&(r.isPhysicsEnabled()||r.enablePhysics(),n.setPhysicsState({impostor:t.physicsImpostor,mass:t.physicsMass,friction:t.physicsFriction,restitution:t.physicsRestitution})),t.animations)for(var o=0;o0;if(u.push(2===t.type?n:r),p){for(var m=new Array,_=0;_0){var u=l.properties[0].value,f=null===l.properties[0].targetType?u:i.getMeshByName(u);c={trigger:e.ActionManager[l.name],parameter:f}}else c=e.ActionManager[l.name];for(var d=0;d0){var h=new Float32Array(t,a.positionsAttrDesc.offset,a.positionsAttrDesc.count);i.setVerticesData(e.VertexBuffer.PositionKind,h,!1)}if(a.normalsAttrDesc&&a.normalsAttrDesc.count>0){var c=new Float32Array(t,a.normalsAttrDesc.offset,a.normalsAttrDesc.count);i.setVerticesData(e.VertexBuffer.NormalKind,c,!1)}if(a.uvsAttrDesc&&a.uvsAttrDesc.count>0){var l=new Float32Array(t,a.uvsAttrDesc.offset,a.uvsAttrDesc.count);i.setVerticesData(e.VertexBuffer.UVKind,l,!1)}if(a.uvs2AttrDesc&&a.uvs2AttrDesc.count>0){var u=new Float32Array(t,a.uvs2AttrDesc.offset,a.uvs2AttrDesc.count);i.setVerticesData(e.VertexBuffer.UV2Kind,u,!1)}if(a.colorsAttrDesc&&a.colorsAttrDesc.count>0){var f=new Float32Array(t,a.colorsAttrDesc.offset,a.colorsAttrDesc.count);i.setVerticesData(e.VertexBuffer.ColorKind,f,!1)}if(a.matricesIndicesAttrDesc&&a.matricesIndicesAttrDesc.count>0){var d=new Int32Array(t,a.matricesIndicesAttrDesc.offset,a.matricesIndicesAttrDesc.count);i.setVerticesData(e.VertexBuffer.MatricesIndicesKind,d,!1)}if(a.matricesWeightsAttrDesc&&a.matricesWeightsAttrDesc.count>0){var p=new Float32Array(t,a.matricesWeightsAttrDesc.offset,a.matricesWeightsAttrDesc.count);i.setVerticesData(e.VertexBuffer.MatricesWeightsKind,p,!1)}if(a.indicesAttrDesc&&a.indicesAttrDesc.count>0){var m=new Int32Array(t,a.indicesAttrDesc.offset,a.indicesAttrDesc.count);i.setIndices(m)}if(a.subMeshesAttrDesc&&a.subMeshesAttrDesc.count>0){var _=new Int32Array(t,a.subMeshesAttrDesc.offset,5*a.subMeshesAttrDesc.count);i.subMeshes=[];for(var g=0;g>8),M.push((16711680&T)>>16),M.push(T>>24)}i.setVerticesData(e.VertexBuffer.MatricesIndicesKind,M,!1)}if(t.matricesWeights&&i.setVerticesData(e.VertexBuffer.MatricesWeightsKind,t.matricesWeights,!1),i.setIndices(t.indices),t.subMeshes){i.subMeshes=[];for(var S=0;S-1&&t.skeletons){var O=f.indexOf(_.skeletonId)>-1;if(!O)for(var B=0;Bl;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(i*this._vertexStrideSize),this._effectBase=this._scene.getEngine().createEffect("sprites",["position","options","cellInfo","color"],["view","projection","textureInfos","alphaTest"],["diffuseSampler"],""),this._effectFog=this._scene.getEngine().createEffect("sprites",["position","options","cellInfo","color"],["view","projection","textureInfos","alphaTest","vFogInfos","vFogColor"],["diffuseSampler"],"#define FOG")}return t.prototype._appendSpriteVertex=function(e,t,r,i,n){var o=16*e;0===r?r=this._epsilon:1===r&&(r=1-this._epsilon),0===i?i=this._epsilon:1===i&&(i=1-this._epsilon),this._vertices[o]=t.position.x,this._vertices[o+1]=t.position.y,this._vertices[o+2]=t.position.z,this._vertices[o+3]=t.angle,this._vertices[o+4]=t.width,this._vertices[o+5]=t.height,this._vertices[o+6]=r,this._vertices[o+7]=i,this._vertices[o+8]=t.invertU?1:0,this._vertices[o+9]=t.invertV?1:0;var s=t.cellIndex/n>>0;this._vertices[o+10]=t.cellIndex-s*n,this._vertices[o+11]=s,this._vertices[o+12]=t.color.r,this._vertices[o+13]=t.color.g,this._vertices[o+14]=t.color.b,this._vertices[o+15]=t.color.a},t.prototype.render=function(){if(this._effectBase.isReady()&&this._effectFog.isReady()&&this._spriteTexture&&this._spriteTexture.isReady()){for(var t=this._scene.getEngine(),r=this._spriteTexture.getBaseSize(),i=t.getDeltaTime(),n=Math.min(this._capacity,this.sprites.length),o=r.width/this.cellSize,s=0,a=0;n>a;a++){ var h=this.sprites[a];h&&(h._animate(i),this._appendSpriteVertex(s++,h,0,0,o),this._appendSpriteVertex(s++,h,1,0,o),this._appendSpriteVertex(s++,h,1,1,o),this._appendSpriteVertex(s++,h,0,1,o))}t.updateDynamicVertexBuffer(this._vertexBuffer,this._vertices);var c=this._effectBase;this._scene.fogEnabled&&this._scene.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(c=this._effectFog),t.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/r.width,this.cellSize/r.height),this._scene.fogEnabled&&this._scene.fogMode!==e.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)),t.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,c),t.setDepthFunctionToLessOrEqual(),c.setBool("alphaTest",!0),t.setColorWrite(!1),t.draw(!0,0,6*n),t.setColorWrite(!0),c.setBool("alphaTest",!1),t.setAlphaMode(e.Engine.ALPHA_COMBINE),t.draw(!0,0,6*n),t.setAlphaMode(e.Engine.ALPHA_DISABLE)}},t.prototype.dispose=function(){this._vertexBuffer&&(this._scene.getEngine()._releaseBuffer(this._vertexBuffer),this._vertexBuffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this._spriteTexture&&(this._spriteTexture.dispose(),this._spriteTexture=null);var e=this._scene.spriteManagers.indexOf(this);this._scene.spriteManagers.splice(e,1),this.onDispose&&this.onDispose()},t}();e.SpriteManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r){this.name=t,this.color=new e.Color4(1,1,1,1),this.width=1,this.height=1,this.angle=0,this.cellIndex=0,this.invertU=0,this.invertV=0,this.animations=new Array,this._animationStarted=!1,this._loopAnimation=!1,this._fromIndex=0,this._toIndex=0,this._delay=0,this._direction=1,this._frameCount=0,this._time=0,this._manager=r,this._manager.sprites.push(this),this.position=e.Vector3.Zero()}return Object.defineProperty(t.prototype,"size",{get:function(){return this.width},set:function(e){this.width=e,this.height=e},enumerable:!0,configurable:!0}),t.prototype.playAnimation=function(e,t,r,i){this._fromIndex=e,this._toIndex=t,this._loopAnimation=r,this._delay=i,this._animationStarted=!0,this._direction=t>e?1:-1,this.cellIndex=e,this._time=0},t.prototype.stopAnimation=function(){this._animationStarted=!1},t.prototype._animate=function(e){this._animationStarted&&(this._time+=e,this._time>this._delay&&(this._time=this._time%this._delay,this.cellIndex+=this._direction,this.cellIndex==this._toIndex&&(this._loopAnimation?this.cellIndex=this._fromIndex:(this._animationStarted=!1,this.disposeWhenFinishedAnimating&&this.dispose()))))},t.prototype.dispose=function(){for(var e=0;el;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(r,i,n){var o=t(a.direction1.x,a.direction2.x),s=t(a.direction1.y,a.direction2.y),h=t(a.direction1.z,a.direction2.z);e.Vector3.TransformNormalFromFloatsToRef(o*r,s*r,h*r,i,n)},this.startPositionFunction=function(r,i){var n=t(a.minEmitBox.x,a.maxEmitBox.x),o=t(a.minEmitBox.y,a.maxEmitBox.y),s=t(a.minEmitBox.z,a.maxEmitBox.z);e.Vector3.TransformCoordinatesFromFloatsToRef(n,o,s,r,i)},this.updateFunction=function(e){for(var t=0;t=r.lifeTime?(a.recycleParticle(r),t--):(r.colorStep.scaleToRef(a._scaledUpdateSpeed,a._scaledColorStep),r.color.addInPlace(a._scaledColorStep),r.color.a<0&&(r.color.a=0),r.angle+=r.angularSpeed*a._scaledUpdateSpeed,r.direction.scaleToRef(a._scaledUpdateSpeed,a._scaledDirection),r.position.addInPlace(a._scaledDirection),a.gravity.scaleToRef(a._scaledUpdateSpeed,a._scaledGravity),r.direction.addInPlace(a._scaledGravity))}}}return r.prototype.recycleParticle=function(e){var t=this.particles.pop();t!==e&&(t.copyTo(e),this._stockParticles.push(t))},r.prototype.getCapacity=function(){return this._capacity},r.prototype.isAlive=function(){return this._alive},r.prototype.isStarted=function(){return this._started},r.prototype.start=function(){this._started=!0,this._stopped=!1,this._actualFrame=0},r.prototype.stop=function(){this._stopped=!0},r.prototype._appendParticleVertex=function(e,t,r,i){var n=11*e;this._vertices[n]=t.position.x,this._vertices[n+1]=t.position.y,this._vertices[n+2]=t.position.z,this._vertices[n+3]=t.color.r,this._vertices[n+4]=t.color.g,this._vertices[n+5]=t.color.b,this._vertices[n+6]=t.color.a,this._vertices[n+7]=t.angle,this._vertices[n+8]=t.size,this._vertices[n+9]=r,this._vertices[n+10]=i},r.prototype._update=function(r){this._alive=this.particles.length>0,this.updateFunction(this.particles);var i;i=this.emitter.position?this.emitter.getWorldMatrix():e.Matrix.Translation(this.emitter.x,this.emitter.y,this.emitter.z);for(var n=0;r>n&&this.particles.length!==this._capacity;n++){if(0!==this._stockParticles.length){var o=this._stockParticles.pop();o.age=0}else o=new e.Particle;this.particles.push(o);var s=t(this.minEmitPower,this.maxEmitPower);this.startDirectionFunction(s,i,o.direction),o.lifeTime=t(this.minLifeTime,this.maxLifeTime),o.size=t(this.minSize,this.maxSize),o.angularSpeed=t(this.minAngularSpeed,this.maxAngularSpeed),this.startPositionFunction(i,o.position);var a=t(0,1);e.Color4.LerpToRef(this.color1,this.color2,a,o.color),this.colorDead.subtractToRef(o.color,this._colorDiff),this._colorDiff.scaleToRef(1/o.lifeTime,o.colorStep)}},r.prototype._getEffect=function(){if(this._customEffect)return this._customEffect;var e=[];this._scene.clipPlane&&e.push("#define CLIPPLANE");var t=e.join("\n");return this._cachedDefines!==t&&(this._cachedDefines=t,this._effect=this._scene.getEngine().createEffect("particles",["position","color","options"],["invView","view","projection","vClipPlane","textureMask"],["diffuseSampler"],t)),this._effect},r.prototype.animate=function(){if(this._started){var e=this._getEffect();if(this.emitter&&e.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this._currentRenderId!==this._scene.getRenderId()){this._currentRenderId=this._scene.getRenderId(),this._scaledUpdateSpeed=this.updateSpeed*this._scene.getAnimationRatio();var t;this.manualEmitCount>-1?(t=this.manualEmitCount,this.manualEmitCount=0):t=this.emitRate;var r=t*this._scaledUpdateSpeed>>0;this._newPartsExcess+=t*this._scaledUpdateSpeed-r,this._newPartsExcess>1&&(r+=this._newPartsExcess>>0,this._newPartsExcess-=this._newPartsExcess>>0),this._alive=!1,this._stopped?r=0:(this._actualFrame+=this._scaledUpdateSpeed,this.targetStopDuration&&this._actualFrame>=this.targetStopDuration&&this.stop()),this._update(r),this._stopped&&(this._alive||(this._started=!1,this.disposeOnStop&&this._scene._toBeDisposed.push(this)));for(var i=0,n=0;n0)return o.clone?o.clone():o;this.currentFrame=e;var s=Math.max(0,Math.min(this._keys.length-1,Math.floor(this._keys.length*(e-this._keys[0].frame)/(this._keys[this._keys.length-1].frame-this._keys[0].frame))-1));if(this._keys[s].frame>=e)for(;s-1>=0&&this._keys[s].frame>=e;)s--;for(var a=s;a=e){var h=this._getKeyValue(this._keys[a].value),c=this._getKeyValue(this._keys[a+1].value),l=(e-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 t.ANIMATIONTYPE_FLOAT:switch(i){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:return this.floatInterpolateFunction(h,c,l);case t.ANIMATIONLOOPMODE_RELATIVE:return n*r+this.floatInterpolateFunction(h,c,l)}break;case t.ANIMATIONTYPE_QUATERNION:var u=null;switch(i){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:u=this.quaternionInterpolateFunction(h,c,l);break;case t.ANIMATIONLOOPMODE_RELATIVE:u=this.quaternionInterpolateFunction(h,c,l).add(n.scale(r))}return u;case t.ANIMATIONTYPE_VECTOR3:switch(i){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:return this.vector3InterpolateFunction(h,c,l);case t.ANIMATIONLOOPMODE_RELATIVE:return this.vector3InterpolateFunction(h,c,l).add(n.scale(r))}case t.ANIMATIONTYPE_VECTOR2:switch(i){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:return this.vector2InterpolateFunction(h,c,l);case t.ANIMATIONLOOPMODE_RELATIVE:return this.vector2InterpolateFunction(h,c,l).add(n.scale(r))}case t.ANIMATIONTYPE_COLOR3:switch(i){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:return this.color3InterpolateFunction(h,c,l);case t.ANIMATIONLOOPMODE_RELATIVE:return this.color3InterpolateFunction(h,c,l).add(n.scale(r))}case t.ANIMATIONTYPE_MATRIX:switch(i){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:case t.ANIMATIONLOOPMODE_RELATIVE:return h}}break}return this._getKeyValue(this._keys[this._keys.length-1].value)},t.prototype.animate=function(r,i,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)}(ithis._keys[this._keys.length-1].frame)&&(i=this._keys[0].frame),(nthis._keys[this._keys.length-1].frame)&&(n=this._keys[this._keys.length-1].frame);var c,l=n-i,u=r*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!==t.ANIMATIONLOOPMODE_CYCLE){var d=n.toString()+i.toString();if(!this._offsetsCache[d]){var p=this._interpolate(i,0,t.ANIMATIONLOOPMODE_CYCLE),m=this._interpolate(n,0,t.ANIMATIONLOOPMODE_CYCLE);switch(this.dataType){case t.ANIMATIONTYPE_FLOAT:this._offsetsCache[d]=m-p;break;case t.ANIMATIONTYPE_QUATERNION:this._offsetsCache[d]=m.subtract(p);break;case t.ANIMATIONTYPE_VECTOR3:this._offsetsCache[d]=m.subtract(p);case t.ANIMATIONTYPE_VECTOR2:this._offsetsCache[d]=m.subtract(p);case t.ANIMATIONTYPE_COLOR3:this._offsetsCache[d]=m.subtract(p)}this._highLimitsCache[d]=m}f=this._highLimitsCache[d],c=this._offsetsCache[d]}if(void 0===c)switch(this.dataType){case t.ANIMATIONTYPE_FLOAT:c=0;break;case t.ANIMATIONTYPE_QUATERNION:c=new e.Quaternion(0,0,0,0);break;case t.ANIMATIONTYPE_VECTOR3:c=e.Vector3.Zero();break;case t.ANIMATIONTYPE_VECTOR2:c=e.Vector2.Zero();break;case t.ANIMATIONTYPE_COLOR3:c=e.Color3.Black()}var _=u/l>>0,g=a?i+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-1&&this._scene._activeAnimatables.splice(e,1),this.onAnimationEnd&&this.onAnimationEnd()},e.prototype._animate=function(e){if(this._paused)return this._pausedDelay||(this._pausedDelay=e),!0;this._localDelayOffset?this._pausedDelay&&(this._localDelayOffset+=e-this._pausedDelay,this._pausedDelay=null):this._localDelayOffset=e;for(var t=!1,r=this._animations,i=0;i=.5?.5*(1-this.easeInCore(2*(1-t)))+.5:.5*this.easeInCore(2*t)},e._EASINGMODE_EASEIN=0,e._EASINGMODE_EASEOUT=1,e._EASINGMODE_EASEINOUT=2,e}();e.EasingFunction=t;var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e=Math.max(0,Math.min(1,e)),1-Math.sqrt(1-e*e)},t}(t);e.CircleEase=r;var i=function(e){function t(t){void 0===t&&(t=1),e.call(this),this.amplitude=t}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.amplitude);return Math.pow(e,3)-e*t*Math.sin(3.141592653589793*e)},t}(t);e.BackEase=i;var n=function(e){function t(t,r){void 0===t&&(t=3),void 0===r&&(r=2),e.call(this),this.bounces=t,this.bounciness=r}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.bounces),r=this.bounciness;1>=r&&(r=1.001);var i=Math.pow(r,t),n=1-r,o=(1-i)/n+.5*i,s=e*o,a=Math.log(-s*(1-r)+1)/Math.log(r),h=Math.floor(a),c=h+1,l=(1-Math.pow(r,h))/(n*o),u=(1-Math.pow(r,c))/(n*o),f=.5*(l+u),d=e-f,p=f-l;return-Math.pow(1/r,t-h)/(p*p)*(d-p)*(d+p)},t}(t);e.BounceEase=n;var o=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e},t}(t);e.CubicEase=o;var s=function(e){function t(t,r){void 0===t&&(t=3),void 0===r&&(r=3),e.call(this),this.oscillations=t,this.springiness=r}return __extends(t,e),t.prototype.easeInCore=function(e){var t,r=Math.max(0,this.oscillations),i=Math.max(0,this.springiness);return t=0==i?e:(Math.exp(i*e)-1)/(Math.exp(i)-1),t*Math.sin((6.283185307179586*r+1.5707963267948966)*e)},t}(t);e.ElasticEase=s;var a=function(e){function t(t){void 0===t&&(t=2),e.call(this),this.exponent=t}return __extends(t,e),t.prototype.easeInCore=function(e){return this.exponent<=0?e:(Math.exp(this.exponent*e)-1)/(Math.exp(this.exponent)-1)},t}(t);e.ExponentialEase=a;var h=function(e){function t(t){void 0===t&&(t=2),e.call(this),this.power=t}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.power);return Math.pow(e,t)},t}(t);e.PowerEase=h;var c=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e},t}(t);e.QuadraticEase=c;var l=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e},t}(t);e.QuarticEase=l;var u=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e*e},t}(t);e.QuinticEase=u;var f=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return 1-Math.sin(1.5707963267948966*(1-e))},t}(t);e.SineEase=f;var d=function(t){function r(e,r,i,n){void 0===e&&(e=0),void 0===r&&(r=0),void 0===i&&(i=1),void 0===n&&(n=1),t.call(this),this.x1=e,this.y1=r,this.x2=i,this.y2=n}return __extends(r,t),r.prototype.easeInCore=function(t){return e.BezierCurve.interpolate(t,this.x1,this.y1,this.x2,this.y2)},r}(t);e.BezierCurveEase=d}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r,i){void 0===i&&(i=2),this.maxDepth=i,this.dynamicContent=new Array,this._maxBlockCapacity=r||64,this._selectionContent=new e.SmartArray(1024),this._creationFunc=t}return t.prototype.update=function(e,r,i){t._CreateBlocks(e,r,i,this._maxBlockCapacity,0,this.maxDepth,this,this._creationFunc)},t.prototype.addMesh=function(e){for(var t=0;tl;l++)for(var u=0;2>u;u++)for(var f=0;2>f;f++){var d=t.add(c.multiplyByFloats(l,u,f)),p=t.add(c.multiplyByFloats(l+1,u+1,f+1)),m=new e.OctreeBlock(d,p,n,o+1,s,h);m.addEntries(i),a.blocks.push(m)}},t.CreationFuncForMeshes=function(e,t){!e.isBlocked&&e.getBoundingInfo().boundingBox.intersectsMinMax(t.minPoint,t.maxPoint)&&t.entries.push(e)},t.CreationFuncForSubMeshes=function(e,t){e.getBoundingInfo().boundingBox.intersectsMinMax(t.minPoint,t.maxPoint)&&t.entries.push(e)},t}();e.Octree=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,r,i,n,o){this.entries=new Array,this._boundingVectors=new Array,this._capacity=r,this._depth=i,this._maxDepth=n,this._creationFunc=o,this._minPoint=e,this._maxPoint=t,this._boundingVectors.push(e.clone()),this._boundingVectors.push(t.clone()),this._boundingVectors.push(e.clone()),this._boundingVectors[2].x=t.x,this._boundingVectors.push(e.clone()),this._boundingVectors[3].y=t.y,this._boundingVectors.push(e.clone()),this._boundingVectors[4].z=t.z,this._boundingVectors.push(t.clone()),this._boundingVectors[5].z=e.z,this._boundingVectors.push(t.clone()),this._boundingVectors[6].x=e.x,this._boundingVectors.push(t.clone()),this._boundingVectors[7].y=e.y}return Object.defineProperty(t.prototype,"capacity",{get:function(){return this._capacity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"minPoint",{get:function(){return this._minPoint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxPoint",{get:function(){return this._maxPoint},enumerable:!0,configurable:!0}),t.prototype.addEntry=function(e){if(this.blocks)for(var t=0;tthis.capacity&&this._depth0){for(var a=0;a0){for(var t=0;t0&&(this._camera._postProcesses[e._postProcessesTakenIndices[0]].width=-1)}},t}();e.PostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){this._vertexDeclaration=[2],this._vertexStrideSize=8,this._scene=e}return e.prototype._prepareBuffers=function(){if(!this._vertexBuffer){var e=[];e.push(1,1),e.push(-1,1),e.push(-1,-1),e.push(1,-1),this._vertexBuffer=this._scene.getEngine().createVertexBuffer(e);var t=[];t.push(0),t.push(1),t.push(2),t.push(0),t.push(2),t.push(3),this._indexBuffer=this._scene.getEngine().createIndexBuffer(t)}},e.prototype._prepareFrame=function(e){var t=this._scene.activeCamera._postProcesses,r=this._scene.activeCamera._postProcessesTakenIndices;return 0!==r.length&&this._scene.postProcessesEnabled?(t[this._scene.activeCamera._postProcessesTakenIndices[0]].activate(this._scene.activeCamera,e),!0):!1},e.prototype.directRender=function(e,t){for(var r=this._scene.getEngine(),i=0;i0&&this._positionX>t.x&&this._positionXt.y&&this._positionYi},t.prototype.render=function(){if(!this._effect.isReady())return!1;var t=this._scene.getEngine(),r=this._scene.activeCamera.viewport,i=r.toGlobal(t);if(!this.computeEffectivePosition(i))return!1;if(!this._isVisible())return!1;var n,o;n=this._positionXi.x+i.width-this.borderLimit?this._positionX-i.x-i.width+this.borderLimit:0,o=this._positionYi.y+i.height-this.borderLimit?this._positionY-i.y-i.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=i.x+i.width/2,c=i.y+i.height/2,l=h-this._positionX,u=c-this._positionY;t.enableEffect(this._effect),t.setState(!1),t.setDepthBuffer(!1),t.setAlphaMode(e.Engine.ALPHA_ADD),t.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,this._effect);for(var f=0;f.1?e=.1:0>=e&&(e=1/60),this._currentPlugin.runOneStep(e)},t.prototype._setGravity=function(t){this.gravity=t||new e.Vector3(0,-9.82,0),this._currentPlugin.setGravity(this.gravity)},t.prototype._registerMesh=function(e,t,r){return this._currentPlugin.registerMesh(e,t,r)},t.prototype._registerMeshesAsCompound=function(e,t){return this._currentPlugin.registerMeshesAsCompound(e,t)},t.prototype._unregisterMesh=function(e){this._currentPlugin.unregisterMesh(e)},t.prototype._applyImpulse=function(e,t,r){this._currentPlugin.applyImpulse(e,t,r)},t.prototype._createLink=function(e,t,r,i,n){return this._currentPlugin.createLink(e,t,r,i,n)},t.prototype._updateBodyPosition=function(e){this._currentPlugin.updateBodyPosition(e)},t.prototype.dispose=function(){this._currentPlugin.dispose()},t.prototype.isSupported=function(){return this._currentPlugin.isSupported()},t.NoImpostor=0,t.SphereImpostor=1,t.BoxImpostor=2,t.PlaneImpostor=3,t.MeshImpostor=4,t.CapsuleImpostor=5,t.ConeImpostor=6,t.CylinderImpostor=7,t.ConvexHullImpostor=8,t.Epsilon=.001,t}();e.PhysicsEngine=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){var r={};if(r.name=t.name,r.id=t.id,r.tags=e.Tags.GetTags(t),t instanceof e.PointLight)r.type=0,r.position=t.position.asArray();else if(t instanceof e.DirectionalLight){r.type=1;var i=t;r.position=i.position.asArray(),r.direction=i.direction.asArray()}else if(t instanceof e.SpotLight){r.type=2;var n=t;r.position=n.position.asArray(),r.direction=n.position.asArray(),r.angle=n.angle,r.exponent=n.exponent}else if(t instanceof e.HemisphericLight){r.type=3;var o=t;r.direction=o.direction.asArray(),r.groundColor=o.groundColor.asArray()}return t.intensity&&(r.intensity=t.intensity),r.range=t.range,r.diffuse=t.diffuse.asArray(),r.specular=t.specular.asArray(),r},r=function(e){var t={};return t.isEnabled=e.isEnabled,t.leftColor=e.leftColor,t.rightColor=e.rightColor,t.bias=e.bias,t.power=e.power,t},i=function(e,t){if(e.animations){t.animations=[];for(var r=0;r0&&(n.animation=o(i.animations[0]))}return t},l=function(e){var t={};return t.emitterId=e.emitter.id,t.capacity=e.getCapacity(),e.particleTexture&&(t.textureName=e.particleTexture.name),t.minAngularSpeed=e.minAngularSpeed,t.maxAngularSpeed=e.maxAngularSpeed,t.minSize=e.minSize,t.maxSize=e.maxSize,t.minLifeTime=e.minLifeTime,t.maxLifeTime=e.maxLifeTime,t.emitRate=e.emitRate,t.minEmitBox=e.minEmitBox.asArray(),t.maxEmitBox=e.maxEmitBox.asArray(),t.gravity=e.gravity.asArray(),t.direction1=e.direction1.asArray(),t.direction2=e.direction2.asArray(),t.color1=e.color1.asArray(),t.color2=e.color2.asArray(),t.colorDead=e.colorDead.asArray(),t.updateSpeed=e.updateSpeed,t.targetStopDuration=e.targetStopDuration,t.textureMask=e.textureMask.asArray(),t.blendMode=e.blendMode,t},u=function(t){var r={};r.emitterId=t.getEmitter().id,r.borderLimit=t.borderLimit,r.flares=[];for(var i=0;it.EPSILON?c:h;f|=_,d.push(_)}switch(f){case h:(e.Vector3.Dot(this.normal,r.plane.normal)>0?i:o).push(r);break;case c:s.push(r);break;case l:a.push(r);break;case u:var g=[],v=[];for(p=0;p=3){var S=new n(g,r.shared);S.plane&&s.push(S)}v.length>=3&&(S=new n(v,r.shared),S.plane&&a.push(S))}},t.EPSILON=1e-5,t}(),n=function(){function e(e,t){this.vertices=e,this.shared=t,this.plane=i.FromPoints(e[0].pos,e[1].pos,e[2].pos)}return e.prototype.clone=function(){var t=this.vertices.map(function(e){return e.clone()});return new e(t,this.shared)},e.prototype.flip=function(){this.vertices.reverse().map(function(e){e.flip()}),this.plane.flip()},e}(),o=function(){function e(e){this.plane=null,this.front=null,this.back=null,this.polygons=[],e&&this.build(e)}return e.prototype.clone=function(){var t=new e;return t.plane=this.plane&&this.plane.clone(),t.front=this.front&&this.front.clone(),t.back=this.back&&this.back.clone(),t.polygons=this.polygons.map(function(e){return e.clone()}),t},e.prototype.invert=function(){for(var e=0;eM;M++)for(var S=A[M].indexStart,E=A[M].indexCount+A[M].indexStart;E>S;S+=3){u=[];for(var C=0;3>C;C++){var P=new e.Vector3(x[3*v[S+C]],x[3*v[S+C]+1],x[3*v[S+C]+2]);h=new e.Vector2(b[2*v[S+C]],b[2*v[S+C]+1]);var D=new e.Vector3(y[3*v[S+C]],y[3*v[S+C]+1],y[3*v[S+C]+2]);c=e.Vector3.TransformCoordinates(D,f),a=e.Vector3.TransformNormal(P,f),s=new r(c,a,h),u.push(s)}l=new n(u,{subMeshId:M,meshId:t,materialIndex:A[M].materialIndex}),l.plane&&g.push(l)}var w=i.FromPolygons(g);return w.matrix=f,w.position=d,w.rotation=p,w.scaling=_,w.rotationQuaternion=m,t++,w},i.FromPolygons=function(t){var r=new e.CSG;return r.polygons=t,r},i.prototype.clone=function(){var t=new e.CSG;return t.polygons=this.polygons.map(function(e){return e.clone()}),t.copyTransformAttributes(this),t},i.prototype.toPolygons=function(){return this.polygons},i.prototype.union=function(e){var t=new o(this.clone().polygons),r=new o(e.clone().polygons);return t.clipTo(r),r.clipTo(t),r.invert(),r.clipTo(t),r.invert(),t.build(r.allPolygons()),i.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},i.prototype.unionInPlace=function(e){var t=new o(this.polygons),r=new o(e.polygons);t.clipTo(r),r.clipTo(t),r.invert(),r.clipTo(t),r.invert(),t.build(r.allPolygons()),this.polygons=t.allPolygons()},i.prototype.subtract=function(e){var t=new o(this.clone().polygons),r=new o(e.clone().polygons);return t.invert(),t.clipTo(r),r.clipTo(t),r.invert(),r.clipTo(t),r.invert(),t.build(r.allPolygons()),t.invert(),i.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},i.prototype.subtractInPlace=function(e){var t=new o(this.polygons),r=new o(e.polygons);t.invert(),t.clipTo(r),r.clipTo(t),r.invert(),r.clipTo(t),r.invert(),t.build(r.allPolygons()),t.invert(),this.polygons=t.allPolygons()},i.prototype.intersect=function(e){var t=new o(this.clone().polygons),r=new o(e.clone().polygons);return t.invert(),r.clipTo(t),r.invert(),t.clipTo(r),r.clipTo(t),t.build(r.allPolygons()),t.invert(),i.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},i.prototype.intersectInPlace=function(e){var t=new o(this.polygons),r=new o(e.polygons);t.invert(),r.clipTo(t),r.invert(),t.clipTo(r),r.clipTo(t),t.build(r.allPolygons()),t.invert(),this.polygons=t.allPolygons()},i.prototype.inverse=function(){var e=this.clone();return e.inverseInPlace(),e},i.prototype.inverseInPlace=function(){this.polygons.map(function(e){e.flip()})},i.prototype.copyTransformAttributes=function(e){return this.matrix=e.matrix,this.position=e.position,this.rotation=e.rotation,this.scaling=e.scaling,this.rotationQuaternion=e.rotationQuaternion,this},i.prototype.buildMeshGeometry=function(t,r,i){var n=this.matrix.clone();n.invert();var o,s,a,h=new e.Mesh(t,r),c=[],l=[],u=[],f=[],d=e.Vector3.Zero(),p=e.Vector3.Zero(),m=e.Vector2.Zero(),_=this.polygons,g=[0,0,0],v={},y=0,x={};i&&_.sort(function(e,t){return e.shared.meshId===t.shared.meshId?e.shared.subMeshId-t.shared.subMeshId:e.shared.meshId-t.shared.meshId});for(var b=0,A=_.length;A>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 M=2,T=o.vertices.length;T>M;M++){g[0]=0,g[1]=M-1,g[2]=M;for(var S=0;3>S;S++){d.copyFrom(o.vertices[g[S]].pos),p.copyFrom(o.vertices[g[S]].normal),m.copyFrom(o.vertices[g[S]].uv);var E=e.Vector3.TransformCoordinates(d,n),C=e.Vector3.TransformNormal(p,n);s=v[E.x+","+E.y+","+E.z],("undefined"==typeof s||u[3*s]!==C.x||u[3*s+1]!==C.y||u[3*s+2]!==C.z||f[2*s]!==m.x||f[2*s+1]!==m.y)&&(c.push(E.x,E.y,E.z),f.push(m.x,m.y),u.push(p.x,p.y,p.z),s=v[E.x+","+E.y+","+E.z]=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(e.VertexBuffer.PositionKind,c),h.setVerticesData(e.VertexBuffer.NormalKind,u),h.setVerticesData(e.VertexBuffer.UVKind,f),h.setIndices(l),i){var P,D=0;h.subMeshes.length=0;for(var w in x){P=-1;for(var I in x[w])a=x[w][I],e.SubMesh.CreateFromIndices(a.materialIndex+D,a.indexStart,a.indexEnd-a.indexStart+1,h),P=Math.max(a.materialIndex,P);D+=++P}}return h},i.prototype.toMesh=function(e,t,r,i){var n=this.buildMeshGeometry(e,r,i);return n.material=t,n.position.copyFrom(this.position),n.rotation.copyFrom(this.rotation),this.rotationQuaternion&&(n.rotationQuaternion=this.rotationQuaternion.clone()),n.scaling.copyFrom(this.scaling),n.computeWorldMatrix(!0),n},i}();e.CSG=s}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n,o){var s=this;t.call(this,r,"vrDistortionCorrection",["LensCenter","Scale","ScaleIn","HmdWarpParam"],null,o.postProcessScaleFactor,i,e.Texture.BILINEAR_SAMPLINGMODE,null,null),this._isRightEye=n,this._distortionFactors=o.distortionK,this._postProcessScaleFactor=o.postProcessScaleFactor,this._lensCenterOffset=o.lensCenterOffset,this.onSizeChanged=function(){s.aspectRatio=.5*s.width/s.height,s._scaleIn=new e.Vector2(2,2/s.aspectRatio),s._scaleFactor=new e.Vector2(.5*(1/s._postProcessScaleFactor),.5*(1/s._postProcessScaleFactor)*s.aspectRatio),s._lensCenter=new e.Vector2(s._isRightEye?.5-.5*s._lensCenterOffset:.5+.5*s._lensCenterOffset,.5)},this.onApply=function(e){e.setFloat2("LensCenter",s._lensCenter.x,s._lensCenter.y),e.setFloat2("Scale",s._scaleFactor.x,s._scaleFactor.y),e.setFloat2("ScaleIn",s._scaleIn.x,s._scaleIn.y),e.setFloat4("HmdWarpParam",s._distortionFactors[0],s._distortionFactors[1],s._distortionFactors[2],s._distortionFactors[3])}}return __extends(r,t),r}(e.PostProcess);e.VRDistortionCorrectionPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){!function(e){e[e.X=0]="X",e[e.Y=1]="Y",e[e.Z=2]="Z"}(e.JoystickAxis||(e.JoystickAxis={}));var t=e.JoystickAxis,r=function(){function r(i){var n=this;this._leftJoystick=i?!0:!1,this._joystickIndex=r._globalJoystickIndex,r._globalJoystickIndex++,this._axisTargetedByLeftAndRight=t.X,this._axisTargetedByUpAndDown=t.Y,this.reverseLeftRight=!1,this.reverseUpDown=!1,this._touches=new e.SmartCollection,this.deltaPosition=e.Vector3.Zero(),this._joystickSensibility=25,this._inversedSensibility=1/(this._joystickSensibility/1e3),this._rotationSpeed=25,this._inverseRotationSpeed=1/(this._rotationSpeed/1e3),this._rotateOnAxisRelativeToMesh=!1,r.vjCanvas||(window.addEventListener("resize",function(){r.vjCanvasWidth=window.innerWidth,r.vjCanvasHeight=window.innerHeight,r.vjCanvas.width=r.vjCanvasWidth,r.vjCanvas.height=r.vjCanvasHeight,r.halfWidth=r.vjCanvasWidth/2,r.halfHeight=r.vjCanvasHeight/2},!1),r.vjCanvas=document.createElement("canvas"),r.vjCanvasWidth=window.innerWidth,r.vjCanvasHeight=window.innerHeight,r.vjCanvas.width=window.innerWidth,r.vjCanvas.height=window.innerHeight,r.vjCanvas.style.width="100%",r.vjCanvas.style.height="100%",r.vjCanvas.style.position="absolute",r.vjCanvas.style.backgroundColor="transparent",r.vjCanvas.style.top="0px",r.vjCanvas.style.left="0px",r.vjCanvas.style.zIndex="5",r.vjCanvas.style.msTouchAction="none",r.vjCanvasContext=r.vjCanvas.getContext("2d"),r.vjCanvasContext.strokeStyle="#ffffff",r.vjCanvasContext.lineWidth=2,document.body.appendChild(r.vjCanvas)),r.halfWidth=r.vjCanvas.width/2,r.halfHeight=r.vjCanvas.height/2,this.pressed=!1,this._joystickColor="cyan",this._joystickPointerID=-1,this._joystickPointerPos=new e.Vector2(0,0),this._joystickPointerStartPos=new e.Vector2(0,0),this._deltaJoystickVector=new e.Vector2(0,0),r.vjCanvas.addEventListener("pointerdown",function(e){n._onPointerDown(e)},!1),r.vjCanvas.addEventListener("pointermove",function(e){n._onPointerMove(e)},!1),r.vjCanvas.addEventListener("pointerup",function(e){n._onPointerUp(e)},!1),r.vjCanvas.addEventListener("pointerout",function(e){n._onPointerUp(e)},!1),r.vjCanvas.addEventListener("contextmenu",function(e){e.preventDefault()},!1),requestAnimationFrame(function(){n._drawVirtualJoystick()})}return r.prototype.setJoystickSensibility=function(e){this._joystickSensibility=e,this._inversedSensibility=1/(this._joystickSensibility/1e3)},r.prototype._onPointerDown=function(e){var t;e.preventDefault(),t=this._leftJoystick===!0?e.clientXr.halfWidth,t&&this._joystickPointerID<0?(this._joystickPointerID=e.pointerId,this._joystickPointerStartPos.x=e.clientX,this._joystickPointerStartPos.y=e.clientY,this._joystickPointerPos=this._joystickPointerStartPos.clone(),this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this.pressed=!0,this._touches.add(e.pointerId.toString(),e)):r._globalJoystickIndex<2&&this._action&&(this._action(),this._touches.add(e.pointerId.toString(),e))},r.prototype._onPointerMove=function(e){if(this._joystickPointerID==e.pointerId){this._joystickPointerPos.x=e.clientX,this._joystickPointerPos.y=e.clientY,this._deltaJoystickVector=this._joystickPointerPos.clone(),this._deltaJoystickVector=this._deltaJoystickVector.subtract(this._joystickPointerStartPos);var r=this.reverseLeftRight?-1:1,i=r*this._deltaJoystickVector.x/this._inversedSensibility;switch(this._axisTargetedByLeftAndRight){case t.X:this.deltaPosition.x=Math.min(1,Math.max(-1,i));break;case t.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,i));break;case t.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,i))}var n=this.reverseUpDown?1:-1,o=n*this._deltaJoystickVector.y/this._inversedSensibility;switch(this._axisTargetedByUpAndDown){case t.X:this.deltaPosition.x=Math.min(1,Math.max(-1,o));break;case t.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,o));break;case t.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,o))}}else this._touches.item(e.pointerId.toString())&&(this._touches.item(e.pointerId.toString()).x=e.clientX,this._touches.item(e.pointerId.toString()).y=e.clientY)},r.prototype._onPointerUp=function(e){this._clearCanvas(),this._joystickPointerID==e.pointerId&&(this._joystickPointerID=-1,this.pressed=!1),this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this._touches.remove(e.pointerId.toString())},r.prototype.setJoystickColor=function(e){this._joystickColor=e},r.prototype.setActionOnTouch=function(e){this._action=e},r.prototype.setAxisForLeftRight=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByLeftAndRight=e;break;default:this._axisTargetedByLeftAndRight=t.X}},r.prototype.setAxisForUpDown=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByUpAndDown=e;break;default:this._axisTargetedByUpAndDown=t.Y}},r.prototype._clearCanvas=function(){this._leftJoystick?r.vjCanvasContext.clearRect(0,0,r.vjCanvasWidth/2,r.vjCanvasHeight):r.vjCanvasContext.clearRect(r.vjCanvasWidth/2,0,r.vjCanvasWidth,r.vjCanvasHeight)},r.prototype._drawVirtualJoystick=function(){var e=this;this.pressed&&(this._clearCanvas(),this._touches.forEach(function(t){t.pointerId===e._joystickPointerID?(r.vjCanvasContext.beginPath(),r.vjCanvasContext.strokeStyle=e._joystickColor,r.vjCanvasContext.lineWidth=6,r.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,40,0,2*Math.PI,!0),r.vjCanvasContext.stroke(),r.vjCanvasContext.beginPath(),r.vjCanvasContext.strokeStyle=e._joystickColor,r.vjCanvasContext.lineWidth=2,r.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,60,0,2*Math.PI,!0),r.vjCanvasContext.stroke(),r.vjCanvasContext.beginPath(),r.vjCanvasContext.strokeStyle=e._joystickColor,r.vjCanvasContext.arc(e._joystickPointerPos.x,e._joystickPointerPos.y,40,0,2*Math.PI,!0),r.vjCanvasContext.stroke()):(r.vjCanvasContext.beginPath(),r.vjCanvasContext.fillStyle="white",r.vjCanvasContext.beginPath(),r.vjCanvasContext.strokeStyle="red",r.vjCanvasContext.lineWidth=6,r.vjCanvasContext.arc(t.x,t.y,40,0,2*Math.PI,!0),r.vjCanvasContext.stroke())})),requestAnimationFrame(function(){e._drawVirtualJoystick()})},r.prototype.releaseCanvas=function(){r.vjCanvas&&(document.body.removeChild(r.vjCanvas),r.vjCanvas=null)},r._globalJoystickIndex=0,r}();e.VirtualJoystick=r}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n){t.call(this,r,i,n),this._leftjoystick=new e.VirtualJoystick(!0),this._leftjoystick.setAxisForUpDown(e.JoystickAxis.Z),this._leftjoystick.setAxisForLeftRight(e.JoystickAxis.X),this._leftjoystick.setJoystickSensibility(.15),this._rightjoystick=new e.VirtualJoystick(!1),this._rightjoystick.setAxisForUpDown(e.JoystickAxis.X),this._rightjoystick.setAxisForLeftRight(e.JoystickAxis.Y),this._rightjoystick.reverseUpDown=!0,this._rightjoystick.setJoystickSensibility(.05),this._rightjoystick.setJoystickColor("yellow")}return __extends(r,t),r.prototype._checkInputs=function(){var r=e.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,0),i=e.Vector3.TransformCoordinates(this._leftjoystick.deltaPosition,r);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)),t.prototype._checkInputs.call(this)},r.prototype.dispose=function(){this._leftjoystick.releaseCanvas(),t.prototype.dispose.call(this)},r}(e.FreeCamera);e.VirtualJoysticksCamera=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n,o){t.call(this,r,i),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 e.Matrix,this._shaderPath=n,o.needAlphaBlending=o.needAlphaBlending||!1,o.needAlphaTesting=o.needAlphaTesting||!1,o.attributes=o.attributes||["position","normal","uv"],o.uniforms=o.uniforms||["worldViewProjection"],o.samplers=o.samplers||[],this._options=o}return __extends(r,t),r.prototype.needAlphaBlending=function(){return this._options.needAlphaBlending},r.prototype.needAlphaTesting=function(){return this._options.needAlphaTesting},r.prototype._checkUniform=function(e){-1===this._options.uniforms.indexOf(e)&&this._options.uniforms.push(e)},r.prototype.setTexture=function(e,t){return-1===this._options.samplers.indexOf(e)&&this._options.samplers.push(e),this._textures[e]=t,this},r.prototype.setFloat=function(e,t){return this._checkUniform(e),this._floats[e]=t,this},r.prototype.setFloats=function(e,t){return this._checkUniform(e),this._floatsArrays[e]=t,this},r.prototype.setColor3=function(e,t){return this._checkUniform(e),this._colors3[e]=t,this},r.prototype.setColor4=function(e,t){return this._checkUniform(e),this._colors4[e]=t,this},r.prototype.setVector2=function(e,t){return this._checkUniform(e),this._vectors2[e]=t,this},r.prototype.setVector3=function(e,t){return this._checkUniform(e),this._vectors3[e]=t,this},r.prototype.setMatrix=function(e,t){return this._checkUniform(e),this._matrices[e]=t,this},r.prototype.isReady=function(t,r){var i=this.getScene(),n=i.getEngine();if(!this.checkReadyOnEveryCall&&this._renderId===i.getRenderId())return!0;var o=[],s=new e.EffectFallbacks;r&&o.push("#define INSTANCES"),t&&t.useBones&&(o.push("#define BONES"),o.push("#define BonesPerMesh "+(t.skeleton.bones.length+1)),o.push("#define BONES4"),s.addFallback(0,"BONES4")),n.getAlphaTesting()&&o.push("#define ALPHATEST");var 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&&i.resetCachedMaterial(),this._renderId=i.getRenderId(),!0):!1},r.prototype.bindOnlyWorldMatrix=function(e){var t=this.getScene();-1!==this._options.uniforms.indexOf("world")&&this._effect.setMatrix("world",e),-1!==this._options.uniforms.indexOf("worldView")&&(e.multiplyToRef(t.getViewMatrix(),this._cachedWorldViewMatrix),this._effect.setMatrix("worldView",this._cachedWorldViewMatrix)),-1!==this._options.uniforms.indexOf("worldViewProjection")&&this._effect.setMatrix("worldViewProjection",e.multiply(t.getTransformMatrix()))},r.prototype.bind=function(e,r){if(this.bindOnlyWorldMatrix(e),this.getScene().getCachedMaterial()!==this){-1!==this._options.uniforms.indexOf("view")&&this._effect.setMatrix("view",this.getScene().getViewMatrix()),-1!==this._options.uniforms.indexOf("projection")&&this._effect.setMatrix("projection",this.getScene().getProjectionMatrix()),-1!==this._options.uniforms.indexOf("viewProjection")&&this._effect.setMatrix("viewProjection",this.getScene().getTransformMatrix()),r&&r.useBones&&this._effect.setMatrices("mBones",r.skeleton.getTransformMatrices());for(var i in this._textures)this._effect.setTexture(i,this._textures[i]);for(i in this._floats)this._effect.setFloat(i,this._floats[i]);for(i in this._floatsArrays)this._effect.setArray(i,this._floatsArrays[i]);for(i in this._colors3)this._effect.setColor3(i,this._colors3[i]);for(i in this._colors4){var n=this._colors4[i];this._effect.setFloat4(i,n.r,n.g,n.b,n.a)}for(i in this._vectors2)this._effect.setVector2(i,this._vectors2[i]);for(i in this._vectors3)this._effect.setVector3(i,this._vectors3[i]);for(i in this._matrices)this._effect.setMatrix(i,this._matrices[i])}t.prototype.bind.call(this,e,r)},r.prototype.dispose=function(e){for(var r in this._textures)this._textures[r].dispose();this._textures=[],t.prototype.dispose.call(this,e)},r}(e.Material);e.ShaderMaterial=t; }(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.prototype.set=function(t,r){switch(r){case e.VertexBuffer.PositionKind:this.positions=t;break;case e.VertexBuffer.NormalKind:this.normals=t;break;case e.VertexBuffer.UVKind:this.uvs=t;break;case e.VertexBuffer.UV2Kind:this.uv2s=t;break;case e.VertexBuffer.ColorKind:this.colors=t;break;case e.VertexBuffer.MatricesIndicesKind:this.matricesIndices=t;break;case e.VertexBuffer.MatricesWeightsKind:this.matricesWeights=t}},t.prototype.applyToMesh=function(e,t){this._applyTo(e,t)},t.prototype.applyToGeometry=function(e,t){this._applyTo(e,t)},t.prototype.updateMesh=function(e,t,r){this._update(e)},t.prototype.updateGeometry=function(e,t,r){this._update(e)},t.prototype._applyTo=function(t,r){this.positions&&t.setVerticesData(e.VertexBuffer.PositionKind,this.positions,r),this.normals&&t.setVerticesData(e.VertexBuffer.NormalKind,this.normals,r),this.uvs&&t.setVerticesData(e.VertexBuffer.UVKind,this.uvs,r),this.uv2s&&t.setVerticesData(e.VertexBuffer.UV2Kind,this.uv2s,r),this.colors&&t.setVerticesData(e.VertexBuffer.ColorKind,this.colors,r),this.matricesIndices&&t.setVerticesData(e.VertexBuffer.MatricesIndicesKind,this.matricesIndices,r),this.matricesWeights&&t.setVerticesData(e.VertexBuffer.MatricesWeightsKind,this.matricesWeights,r),this.indices&&t.setIndices(this.indices)},t.prototype._update=function(t,r,i){this.positions&&t.updateVerticesData(e.VertexBuffer.PositionKind,this.positions,r,i),this.normals&&t.updateVerticesData(e.VertexBuffer.NormalKind,this.normals,r,i),this.uvs&&t.updateVerticesData(e.VertexBuffer.UVKind,this.uvs,r,i),this.uv2s&&t.updateVerticesData(e.VertexBuffer.UV2Kind,this.uv2s,r,i),this.colors&&t.updateVerticesData(e.VertexBuffer.ColorKind,this.colors,r,i),this.matricesIndices&&t.updateVerticesData(e.VertexBuffer.MatricesIndicesKind,this.matricesIndices,r,i),this.matricesWeights&&t.updateVerticesData(e.VertexBuffer.MatricesWeightsKind,this.matricesWeights,r,i),this.indices&&t.setIndices(this.indices)},t.prototype.transform=function(t){var r=e.Vector3.Zero();if(this.positions)for(var i=e.Vector3.Zero(),n=0;na?a:Math.floor(o);var h,c,l,u,f=[],d=[],p=[],m=[],_=[],g=[],v=[],y=[],x=[],b=[];if(r.length<2){var A=[],M=[];for(l=0;lh?h:E,x[c]=E,b[c]=T,u=0;E>u;){if(f.push(S[u].x,S[u].y,S[u].z),u>0){var C=S[u].subtract(S[u-1]).length(),P=C+v[c];_[c].push(P),v[c]=P}u++}n&&(C=S[0].subtract(S[u-1]).length(),P=C+v[c],v[c]=P),T+=E}for(l=0;h>l;l++){y[l]=0,g[l]=[0];var D,w;for(c=0;cl;l++)I=_[c][l]/v[c],L=g[l][c]/y[l],m.push(I,L);c=0;for(var O,B,R,F,V=0,N=x[c]-1,k=x[c+1]-1,U=k>N?N:k,z=b[1]-b[0],W=i?x.length:x.length-1;U>=V&&W>c;)O=V,B=V+z,R=V+1,F=V+z+1,d.push(V,V+z,V+1),d.push(V+z+1,V+1,V+z),V+=1,V===U&&(n&&(d.push(V,V+z,b[c]),d.push(b[c]+z,b[c],V+z),R=b[c],F=b[c]+z),c++,c===x.length-1?(z=b[0]-b[c],N=x[c]-1,k=x[0]-1):(z=b[c+1]-b[c],N=x[c]-1,k=x[c+1]-1),V=b[c],U=k>N?N+V:k+V);t.ComputeNormals(f,d,p),t._ComputeSides(s,f,d,p,m);var G=new t;return G.indices=d,G.positions=f,G.normals=p,G.uvs=m,G},t.CreateBox=function(r,i){void 0===i&&(i=e.Mesh.DEFAULTSIDE);var n=[new e.Vector3(0,0,1),new e.Vector3(0,0,-1),new e.Vector3(1,0,0),new e.Vector3(-1,0,0),new e.Vector3(0,1,0),new e.Vector3(0,-1,0)],o=[],s=[],a=[],h=[];r=r||1;for(var c=0;c=f;f++){for(var d=f/s,p=d*Math.PI,m=0;a>=m;m++){var _=m/a,g=_*Math.PI*2,v=e.Matrix.RotationZ(-p),y=e.Matrix.RotationY(g),x=e.Vector3.TransformCoordinates(e.Vector3.Up(),v),b=e.Vector3.TransformCoordinates(x,y),A=b.scale(o),M=e.Vector3.Normalize(A);c.push(A.x,A.y,A.z),l.push(M.x,M.y,M.z),u.push(d,_)}if(f>0)for(var T=c.length/3,S=T-2*(a+1);T>S+a+2;S++)h.push(S),h.push(S+1),h.push(S+a+1),h.push(S+a+1),h.push(S+1),h.push(S+a+2)}t._ComputeSides(n,c,h,l,u);var E=new t;return E.indices=h,E.positions=c,E.normals=l,E.uvs=u,E},t.CreateCylinder=function(r,i,n,o,s,a){void 0===s&&(s=1),void 0===a&&(a=e.Mesh.DEFAULTSIDE);var h=i/2,c=n/2,l=[],u=[],f=[],d=[];r=r||1,i=i||.5,n=n||1,o=o||16,s=s||1,s=1>s?1:s;for(var p=function(t){var r=2*t*Math.PI/o,i=Math.cos(r),n=Math.sin(r);return new e.Vector3(i,0,n)},m=function(t){var i=t?h:c;if(0!==i){var n=u.length/3,s=new e.Vector3(0,r/2,0),a=new e.Vector2(.5,.5);t||(s.scaleInPlace(-1),a.x=-a.x);for(var f=0;o>f;f++){var m=p(f),_=m.scale(i).add(s),g=new e.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++)t?(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 e.Vector3(0,-1,0).scale(r/2),g=new e.Vector3(0,1,0).scale(r/s),v=o+1,y=0;o>=y;y++)for(var x,b=p(y),A=new e.Vector2(y/o,0),M=c,T=0;s>=T;T++)x=b.scale(M),x.addInPlace(_.add(g.scale(T))),A.y+=1/s,M+=(h-c)/s,u.push(x.x,x.y,x.z),d.push(A.x,A.y);for(s+=1,T=0;s-1>T;T++)for(y=0;o>=y;y++)l.push(y*s+T),l.push((y*s+(T+s))%(v*s)),l.push(y*s+(T+1)),l.push(y*s+(T+1)),l.push((y*s+(T+s))%(v*s)),l.push((y*s+(T+s+1))%(v*s));m(!0),m(!1),t.ComputeNormals(u,l,f),t._ComputeSides(a,u,l,f,d);var S=new t;return S.indices=l,S.positions=u,S.normals=f,S.uvs=d,S},t.CreateTorus=function(r,i,n,o){void 0===o&&(o=e.Mesh.DEFAULTSIDE);var s=[],a=[],h=[],c=[];r=r||1,i=i||.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=e.Matrix.Translation(r/2,0,0).multiply(e.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 e.Vector3(v,y,0),b=x.scale(i/2),A=new e.Vector2(f,_);b=e.Vector3.TransformCoordinates(b,p),x=e.Vector3.TransformNormal(x,p),a.push(b.x,b.y,b.z),h.push(x.x,x.y,x.z),c.push(A.x,A.y);var M=(u+1)%l,T=(m+1)%l;s.push(u*l+m),s.push(u*l+T),s.push(M*l+m),s.push(u*l+T),s.push(M*l+T),s.push(M*l+m)}t._ComputeSides(o,a,s,h,c);var S=new t;return S.indices=s,S.positions=a,S.normals=h,S.uvs=c,S},t.CreateLines=function(e){for(var r=[],i=[],n=0;n0&&(r.push(n-1),r.push(n));var o=new t;return o.indices=r,o.positions=i,o},t.CreateDashedLines=function(r,i,n,o){i=i||3,n=n||1,o=o||200;var s=new Array,a=new Array,h=e.Vector3.Zero(),c=0,l=0,u=0,f=0,d=0,p=0,m=0;for(m=0;m_;_++)d=u*_,s.push(r[m].x+d*h.x,r[m].y+d*h.y,r[m].z+d*h.z),s.push(r[m].x+(d+f)*h.x,r[m].y+(d+f)*h.y,r[m].z+(d+f)*h.z),a.push(p,p+1),p+=2}var g=new t;return g.positions=s,g.indices=a,g},t.CreateGround=function(r,i,n){var o,s,a=[],h=[],c=[],l=[];for(r=r||1,i=i||1,n=n||1,o=0;n>=o;o++)for(s=0;n>=s;s++){var u=new e.Vector3(s*r/n-r/2,0,(n-o)*i/n-i/2),f=new e.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 t;return d.indices=a,d.positions=h,d.normals=c,d.uvs=l,d},t.CreateTiledGround=function(r,i,n,o,s,a){function h(t,r,i,n){var o=p.length/3,s=a.w+1;for(c=0;c=l;l++)for(u=0;n>=u;u++){var _=new e.Vector3(u*r/n-r/2,0,(n-l)*i/n-i/2),g=(_.x+r/2)/r*(h-1)|0,v=(1-(_.z+i/2)/i)*(c-1)|0,y=4*(g+v*h),x=a[y]/255,b=a[y+1]/255,A=a[y+2]/255,M=.3*x+.59*b+.11*A;_.y=o+(s-o)*M,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));t.ComputeNormals(d,f,p);var T=new t;return T.indices=f,T.positions=d,T.normals=p,T.uvs=m,T},t.CreatePlane=function(r,i){void 0===i&&(i=e.Mesh.DEFAULTSIDE);var n=[],o=[],s=[],a=[];r=r||1;var h=r/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),t._ComputeSides(i,o,n,s,a);var c=new t;return c.indices=n,c.positions=o,c.normals=s,c.uvs=a,c},t.CreateDisc=function(r,i,n){void 0===n&&(n=e.Mesh.DEFAULTSIDE);var o=[],s=[],a=[],h=[];o.push(0,0,0),h.push(.5,.5);for(var c=2*Math.PI/i,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(r*u,r*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,_);t.ComputeNormals(o,s,a),t._ComputeSides(n,o,s,a,h);var g=new t;return g.indices=s,g.positions=o,g.normals=a,g.uvs=h,g},t.CreateTorusKnot=function(r,i,n,o,s,a,h){void 0===h&&(h=e.Mesh.DEFAULTSIDE);var c=[],l=[],u=[],f=[];r=r||2,i=i||.5,n=n||32,o=o||32,s=s||2,a=a||3;for(var d=function(t){var i=Math.cos(t),n=Math.sin(t),o=a/s*t,h=Math.cos(o),c=r*(2+h)*.5*i,l=r*(2+h)*n*.5,u=r*Math.sin(o)*.5;return new e.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=e.Vector3.Cross(y,x);x=e.Vector3.Cross(b,y),b.normalize(),x.normalize();for(var A=0;o>A;A++){var M=A%o,T=M/o*2*Math.PI,S=-i*Math.cos(T),E=i*Math.sin(T);l.push(g.x+S*x.x+E*b.x),l.push(g.y+S*x.y+E*b.y),l.push(g.z+S*x.z+E*b.z),f.push(p/n),f.push(A/o)}}for(p=0;n>p;p++)for(A=0;o>A;A++){var C=(A+1)%o,P=p*o+A,D=(p+1)*o+A,w=(p+1)*o+C,I=p*o+C;c.push(I),c.push(D),c.push(P),c.push(I),c.push(w),c.push(D)}t.ComputeNormals(l,c,u),t._ComputeSides(h,l,c,u,f);var L=new t;return L.indices=c,L.positions=l,L.normals=u,L.uvs=f,L},t.ComputeNormals=function(t,r,i){var n=0,o=e.Vector3.Zero(),s=e.Vector3.Zero(),a=e.Vector3.Zero(),h=e.Vector3.Zero(),c=e.Vector3.Zero(),l=e.Vector3.Zero(),u=e.Vector3.Zero(),f=e.Vector3.Zero(),d=e.Vector3.Zero(),p=r.length/3;for(n=0;p>n;n++){var m=r[3*n],_=r[3*n+1],g=r[3*n+2];e.Vector3.FromFloatsToRef(t[3*m],t[3*m+1],t[3*m+2],o),e.Vector3.FromFloatsToRef(t[3*_],t[3*_+1],t[3*_+2],s),e.Vector3.FromFloatsToRef(t[3*g],t[3*g+1],t[3*g+2],a),o.subtractToRef(s,h),a.subtractToRef(s,c),e.Vector3.CrossToRef(h,c,l),l.normalize(),i[3*m]=i[3*m]||0,i[3*m+1]=i[3*m+1]||0,i[3*m+2]=i[3*m+2]||0,i[3*_]=i[3*_]||0,i[3*_+1]=i[3*_+1]||0,i[3*_+2]=i[3*_+2]||0,i[3*g]=i[3*g]||0,i[3*g+1]=i[3*g+1]||0,i[3*g+2]=i[3*g+2]||0,e.Vector3.FromFloatsToRef(i[3*m],i[3*m+1],i[3*m+2],u),e.Vector3.FromFloatsToRef(i[3*_],i[3*_+1],i[3*_+2],f),e.Vector3.FromFloatsToRef(i[3*g],i[3*g+1],i[3*g+2],d),u=u.addInPlace(l),f=f.addInPlace(l),d=d.addInPlace(l),i[3*m]=u.x,i[3*m+1]=u.y,i[3*m+2]=u.z,i[3*_]=f.x,i[3*_+1]=f.y,i[3*_+2]=f.z,i[3*g]=d.x,i[3*g+1]=d.y,i[3*g+2]=d.z}for(n=0;ns;s+=3)l=i[s],i[s]=i[s+2],i[s+2]=l;for(a=0;c>a;a++)n[a]=-n[a];break;case e.Mesh.DOUBLESIDE:for(var u=r.length,f=u/3,d=0;u>d;d++)r[u+d]=r[d];for(s=0;h>s;s+=3)i[s+h]=i[s+2]+f,i[s+1+h]=i[s+1]+f,i[s+2+h]=i[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]}},t}();e.VertexData=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n,o){t.call(this,r,i,o),this.setSubCameraMode(e.Camera.SUB_CAMERA_MODE_ANAGLYPH,n)}return __extends(r,t),r}(e.FreeCamera);e.AnaglyphFreeCamera=t;var r=function(t){function r(r,i,n,o,s,a,h){t.call(this,r,i,n,o,s,h),this.setSubCameraMode(e.Camera.SUB_CAMERA_MODE_ANAGLYPH,a)}return __extends(r,t),r}(e.ArcRotateCamera);e.AnaglyphArcRotateCamera=r;var i=function(t){function r(r,i,n,o){t.call(this,r,i,o),this.setSubCameraMode(e.Camera.SUB_CAMERA_MODE_ANAGLYPH,n)}return __extends(r,t),r}(e.GamepadCamera);e.AnaglyphGamepadCamera=i}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(e){function t(t,r,i,n,o,s){e.call(this,t,"anaglyph",null,["leftSampler"],r,i,n,o,s)}return __extends(t,e),t}(e.PostProcess);e.AnaglyphPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.EnableFor=function(e){e._tags=e._tags||{},e.hasTags=function(){return t.HasTags(e)},e.addTags=function(r){return t.AddTagsTo(e,r)},e.removeTags=function(r){return t.RemoveTagsFrom(e,r)},e.matchesTagsQuery=function(r){return t.MatchesQuery(e,r)}},t.DisableFor=function(e){delete e._tags,delete e.hasTags,delete e.addTags,delete e.removeTags,delete e.matchesTagsQuery},t.HasTags=function(t){return t._tags?!e.Tools.IsEmpty(t._tags):!1},t.GetTags=function(e){return e._tags?e._tags:null},t.AddTagsTo=function(e,r){if(r){var i=r.split(" ");for(var n in i)t._AddTagTo(e,i[n])}},t._AddTagTo=function(e,r){r=r.trim(),""!==r&&"true"!==r&&"false"!==r&&(r.match(/[\s]/)||r.match(/^([!]|([|]|[&]){2})/)||(t.EnableFor(e),e._tags[r]=!0))},t.RemoveTagsFrom=function(e,r){if(t.HasTags(e)){var i=r.split(" ");for(var n in i)t._RemoveTagFrom(e,i[n])}},t._RemoveTagFrom=function(e,t){delete e._tags[t]},t.MatchesQuery=function(r,i){return void 0===i?!0:""===i?t.HasTags(r):e.Internals.AndOrNotEvaluator.Eval(i,function(e){return t.HasTags(r)&&r._tags[e]})},t}();e.Tags=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(e){var t=function(){function e(){}return e.Eval=function(t,r){return t=t.match(/\([^\(\)]*\)/g)?t.replace(/\([^\(\)]*\)/g,function(t){return t=t.slice(1,t.length-1),e._HandleParenthesisContent(t,r)}):e._HandleParenthesisContent(t,r),"true"===t?!0:"false"===t?!1:e.Eval(t,r)},e._HandleParenthesisContent=function(t,r){r=r||function(e){return"true"===e?!0:!1};var i,n=t.split("||");for(var o in n){var s=e._SimplifyNegation(n[o].trim()),a=s.split("&&");if(a.length>1)for(var h=0;hthis.value;case t.IsLesser:return this._target[this._property]-1&&this._scene._actionManagers.splice(e,1)},t.prototype.getScene=function(){return this._scene},t.prototype.hasSpecificTriggers=function(e){for(var t=0;t-1)return!0}return!1},t.prototype.hasSpecificTrigger=function(e){for(var t=0;t=t._OnPickTrigger&&r.trigger<=t._OnPointerOutTrigger)return!0;if(r.trigger==t._OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasPickTriggers",{get:function(){for(var e=0;e=t._OnPickTrigger&&r.trigger<=t._OnCenterPickTrigger)return!0}return!1},enumerable:!0,configurable:!0}),t.prototype.registerAction=function(r){return r.trigger===t.OnEveryFrameTrigger&&this.getScene().actionManager!==this?(e.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager"),null):(this.actions.push(r),r._actionManager=this,r._prepare(),r)},t.prototype.processTrigger=function(e,r){for(var i=0;ih;h++){var c=s[h];c._resetPointsArrayCache(),c._boundingInfo=new e.BoundingInfo(o.minimum,o.maximum),c._createGlobalSubMesh(),c.computeWorldMatrix(!0)}}this.notifyUpdate(t)},t.prototype.updateVerticesDataDirectly=function(e,t,r){var i=this.getVertexBuffer(e);i&&(i.updateDirectly(t,r),this.notifyUpdate(e))},t.prototype.updateVerticesData=function(t,r,i){var n=this.getVertexBuffer(t);if(n){if(n.update(r),t===e.VertexBuffer.PositionKind){var o,s=n.getStrideSize();this._totalVertices=r.length/s,i&&(o=e.Tools.ExtractMinAndMax(r,0,this._totalVertices));for(var a=this._meshes,h=a.length,c=0;h>c;c++){var l=a[c];if(l._resetPointsArrayCache(),i){l._boundingInfo=new e.BoundingInfo(o.minimum,o.maximum);for(var u=0;us;s++)o.push(i[s]);return o}return i},t.prototype.getVertexBuffer=function(e){return this.isReady()?this._vertexBuffers[e]:null},t.prototype.getVertexBuffers=function(){return this.isReady()?this._vertexBuffers:null},t.prototype.isVerticesDataPresent=function(e){return this._vertexBuffers?void 0!==this._vertexBuffers[e]:this._delayInfo?-1!==this._delayInfo.indexOf(e):!1},t.prototype.getVerticesDataKinds=function(){var e=[];if(!this._vertexBuffers&&this._delayInfo)for(var t in this._delayInfo)e.push(t);else for(t in this._vertexBuffers)e.push(t);return e},t.prototype.setIndices=function(e,t){this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indices=e,0!==this._meshes.length&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),void 0!==t&&(this._totalVertices=t);for(var r=this._meshes,i=r.length,n=0;i>n;n++)r[n]._createGlobalSubMesh();this.notifyUpdate()},t.prototype.getTotalIndices=function(){return this.isReady()?this._indices.length:0},t.prototype.getIndices=function(e){if(!this.isReady())return null;var t=this._indices;if(e&&1!==this._meshes.length){for(var r=t.length,i=[],n=0;r>n;n++)i.push(t[n]);return i}return t},t.prototype.getIndexBuffer=function(){return this.isReady()?this._indexBuffer:null},t.prototype.releaseForMesh=function(e,t){var r=this._meshes,i=r.indexOf(e);if(-1!==i){for(var n in this._vertexBuffers)this._vertexBuffers[n].dispose();this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer)&&(this._indexBuffer=null),r.splice(i,1),e._geometry=null,0===r.length&&t&&this.dispose()}},t.prototype.applyToMesh=function(e){if(e._geometry!==this){var t=e._geometry;t&&t.releaseForMesh(e);var r=this._meshes;e._geometry=this,this._scene.pushGeometry(this),r.push(e),this.isReady()?this._applyToMesh(e):e._boundingInfo=this._boundingInfo}},t.prototype._applyToMesh=function(t){var r=this._meshes.length;for(var i in this._vertexBuffers)if(1===r&&this._vertexBuffers[i].create(),this._vertexBuffers[i]._buffer.references=r,i===e.VertexBuffer.PositionKind){t._resetPointsArrayCache();var n=e.Tools.ExtractMinAndMax(this._vertexBuffers[i].getData(),0,this._totalVertices);t._boundingInfo=new e.BoundingInfo(n.minimum,n.maximum),t._createGlobalSubMesh(),t._updateBoundingInfo()}1===r&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),this._indexBuffer&&(this._indexBuffer.references=r)},t.prototype.notifyUpdate=function(e){this.onGeometryUpdated&&this.onGeometryUpdated(this,e)},t.prototype.load=function(t,r){var i=this;if(this.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADING){if(this.isReady())return void(r&&r());this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,t._addPendingData(this),e.Tools.LoadFile(this.delayLoadingFile,function(n){i._delayLoadingFunction(JSON.parse(n),i),i.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,i._delayInfo=[],t._removePendingData(i);for(var o=i._meshes,s=o.length,a=0;s>a;a++)i._applyToMesh(o[a]);r&&r()},function(){},t.database)}},t.prototype.isDisposed=function(){return this._isDisposed},t.prototype.dispose=function(){var t,r=this._meshes,i=r.length;for(t=0;i>t;t++)this.releaseForMesh(r[t]);this._meshes=[];for(var n in this._vertexBuffers)this._vertexBuffers[n].dispose();this._vertexBuffers=[],this._totalVertices=0,this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indexBuffer=null,this._indices=[],this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this.delayLoadingFile=null,this._delayLoadingFunction=null,this._delayInfo=[],this._boundingInfo=null,this._scene.removeGeometry(this),this._isDisposed=!0},t.prototype.copy=function(r){var i=new e.VertexData;i.indices=[];for(var n=this.getIndices(),o=0;or&&null===this._hmdDevice;)e[r]instanceof HMDVRDevice&&(this._hmdDevice=e[r]),r++;for(r=0;t>r&&null===this._sensorDevice;)e[r]instanceof PositionSensorVRDevice&&(!this._hmdDevice||e[r].hardwareUnitId===this._hmdDevice.hardwareUnitId)&&(this._sensorDevice=e[r]),r++;this._vrEnabled=this._sensorDevice&&this._hmdDevice?!0:!1},r.prototype._checkInputs=function(){ this._vrEnabled&&(this._cacheState=this._sensorDevice.getState(),this._cacheQuaternion.copyFromFloats(this._cacheState.orientation.x,this._cacheState.orientation.y,this._cacheState.orientation.z,this._cacheState.orientation.w),this._cacheQuaternion.toEulerAnglesToRef(this._cacheRotation),this.rotation.x=-this._cacheRotation.z,this.rotation.y=-this._cacheRotation.y,this.rotation.z=this._cacheRotation.x),t.prototype._checkInputs.call(this)},r.prototype.attachControl=function(e,r){t.prototype.attachControl.call(this,e,r),navigator.getVRDevices?navigator.getVRDevices().then(this._getWebVRDevices):navigator.mozGetVRDevices&&navigator.mozGetVRDevices(this._getWebVRDevices)},r.prototype.detachControl=function(e){t.prototype.detachControl.call(this,e),this._vrEnabled=!1},r}(e.FreeCamera);e.WebVRFreeCamera=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(){function e(e){void 0===e&&(e=0),this.priority=e,this.apply=function(e){return!0}}return e}();e.SceneOptimization=t;var r=function(e){function t(t,r){var i=this;void 0===t&&(t=0),void 0===r&&(r=1024),e.call(this,t),this.priority=t,this.maximumSize=r,this.apply=function(e){for(var t=!0,r=0;ri.maximumSize&&(n.scale(.5),t=!1)}}return t}}return __extends(t,e),t}(t);e.TextureOptimization=r;var i=function(e){function t(t,r){var i=this;void 0===t&&(t=0),void 0===r&&(r=2),e.call(this,t),this.priority=t,this.maximumScale=r,this._currentScale=1,this.apply=function(e){return i._currentScale++,e.getEngine().setHardwareScalingLevel(i._currentScale),i._currentScale>=i.maximumScale}}return __extends(t,e),t}(t);e.HardwareScalingOptimization=i;var n=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.shadowsEnabled=!1,!0}}return __extends(t,e),t}(t);e.ShadowsOptimization=n;var o=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.postProcessesEnabled=!1,!0}}return __extends(t,e),t}(t);e.PostProcessesOptimization=o;var s=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.lensFlaresEnabled=!1,!0}}return __extends(t,e),t}(t);e.LensFlaresOptimization=s;var a=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.particlesEnabled=!1,!0}}return __extends(t,e),t}(t);e.ParticlesOptimization=a;var h=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.renderTargetsEnabled=!1,!0}}return __extends(t,e),t}(t);e.RenderTargetsOptimization=h;var c=function(t){function r(){var r=this;t.apply(this,arguments),this._canBeMerged=function(t){if(!(t instanceof e.Mesh))return!1;var r=t;return r.isVisible&&r.isEnabled()?r.instances.length>0?!1:r.skeleton||r.hasLODLevels?!1:!0:!1},this.apply=function(t){for(var i=t.meshes.slice(0),n=i.length,o=0;n>o;o++){var s=new Array,a=i[o];if(r._canBeMerged(a)){s.push(a);for(var h=o+1;n>h;h++){var c=i[h];r._canBeMerged(c)&&c.material===a.material&&c.checkCollisions===a.checkCollisions&&(s.push(c),n--,i.splice(h,1),h--)}s.length<2||e.Mesh.MergeMeshes(s)}}return!0}}return __extends(r,t),r}(t);e.MergeMeshesOptimization=c;var l=function(){function e(e,t){void 0===e&&(e=60),void 0===t&&(t=2e3),this.targetFrameRate=e,this.trackerDuration=t,this.optimizations=new Array}return e.LowDegradationAllowed=function(t){var i=new e(t),h=0;return i.optimizations.push(new c(h)),i.optimizations.push(new n(h)),i.optimizations.push(new s(h)),h++,i.optimizations.push(new o(h)),i.optimizations.push(new a(h)),h++,i.optimizations.push(new r(h,1024)),i},e.ModerateDegradationAllowed=function(t){var l=new e(t),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 r(u,512)),u++,l.optimizations.push(new h(u)),u++,l.optimizations.push(new i(u,2)),l},e.HighDegradationAllowed=function(t){var l=new e(t),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 r(u,256)),u++,l.optimizations.push(new h(u)),u++,l.optimizations.push(new i(u,4)),l},e}();e.SceneOptimizerOptions=l;var u=function(){function e(){}return e._CheckCurrentState=function(t,r,i,n,o){if(t.getEngine().getFps()>=r.targetFrameRate)return void(n&&n());for(var s=!0,a=!0,h=0;ht?e*(1-t/r):0},o&&(this.autoplay=o.autoplay||!1,this.loop=o.loop||!1,void 0!==o.volume&&(this._volume=o.volume),this.spatialSound=o.spatialSound||!1,this.maxDistance=o.maxDistance||100,this.useCustomAttenuation=o.useCustomAttenuation||!1,this.rolloffFactor=o.rolloffFactor||1,this.refDistance=o.refDistance||1,this.distanceModel=o.distanceModel||"linear",this._playbackRate=o.playbackRate||1),e.Engine.audioEngine.canUseWebAudio?(this._soundGain=e.Engine.audioEngine.audioContext.createGain(),this._soundGain.gain.value=this._volume,this._inputAudioNode=this._soundGain,this._ouputAudioNode=this._soundGain,this.spatialSound&&this._createSpatialParameters(),this._scene.mainSoundTrack.AddSound(this),r&&("string"==typeof r?e.Tools.LoadFile(r,function(e){s._soundLoaded(e)},null,null,!0):r instanceof ArrayBuffer?this._soundLoaded(r):e.Tools.Error("Parameter must be a URL to the sound or an ArrayBuffer of the sound."))):(this._scene.mainSoundTrack.AddSound(this),e.Engine.audioEngine.WarnedWebAudioUnsupported||(e.Tools.Error("Web Audio is not supported by your browser."),e.Engine.audioEngine.WarnedWebAudioUnsupported=!0),this._readyToPlayCallback&&window.setTimeout(function(){s._readyToPlayCallback()},1e3))}return t.prototype.dispose=function(){e.Engine.audioEngine.canUseWebAudio&&this._isReadyToPlay&&(this.isPlaying&&this.stop(),this._isReadyToPlay=!1,-1===this.soundTrackId?this._scene.mainSoundTrack.RemoveSound(this):this._scene.soundTracks[this.soundTrackId].RemoveSound(this),this._soundGain&&(this._soundGain.disconnect(),this._soundGain=null),this._soundPanner&&(this._soundPanner.disconnect(),this._soundPanner=null),this._soundSource&&(this._soundSource.disconnect(),this._soundSource=null),this._audioBuffer=null,this._connectedMesh&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._connectedMesh=null))},t.prototype._soundLoaded=function(t){var r=this;this._isLoaded=!0,e.Engine.audioEngine.audioContext.decodeAudioData(t,function(e){r._audioBuffer=e,r._isReadyToPlay=!0,r.autoplay&&r.play(),r._readyToPlayCallback&&r._readyToPlayCallback()},function(t){e.Tools.Error("Error while decoding audio data: "+t.err)})},t.prototype.setAudioBuffer=function(t){e.Engine.audioEngine.canUseWebAudio&&(this._audioBuffer=t,this._isReadyToPlay=!0)},t.prototype.updateOptions=function(e){e&&(this.loop=e.loop||this.loop,this.maxDistance=e.maxDistance||this.maxDistance,this.useCustomAttenuation=e.useCustomAttenuation||this.useCustomAttenuation,this.rolloffFactor=e.rolloffFactor||this.rolloffFactor,this.refDistance=e.refDistance||this.refDistance,this.distanceModel=e.distanceModel||this.distanceModel,this._playbackRate=e.playbackRate||this._playbackRate,this._updateSpatialParameters(),this.isPlaying&&(this._soundSource.playbackRate.value=this._playbackRate))},t.prototype._createSpatialParameters=function(){e.Engine.audioEngine.canUseWebAudio&&(this._scene.headphone&&(this._panningModel="HRTF"),this._soundPanner=e.Engine.audioEngine.audioContext.createPanner(),this._updateSpatialParameters(),this._soundPanner.connect(this._ouputAudioNode),this._inputAudioNode=this._soundPanner)},t.prototype._updateSpatialParameters=function(){this.spatialSound&&(this.useCustomAttenuation?(this._soundPanner.distanceModel="linear",this._soundPanner.maxDistance=Number.MAX_VALUE,this._soundPanner.refDistance=1,this._soundPanner.rolloffFactor=1,this._soundPanner.panningModel=this._panningModel):(this._soundPanner.distanceModel=this.distanceModel,this._soundPanner.maxDistance=this.maxDistance,this._soundPanner.refDistance=this.refDistance,this._soundPanner.rolloffFactor=this.rolloffFactor,this._soundPanner.panningModel=this._panningModel))},t.prototype.switchPanningModelToHRTF=function(){this._panningModel="HRTF",this._switchPanningModel()},t.prototype.switchPanningModelToEqualPower=function(){this._panningModel="equalpower",this._switchPanningModel()},t.prototype._switchPanningModel=function(){e.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&(this._soundPanner.panningModel=this._panningModel)},t.prototype.connectToSoundTrackAudioNode=function(t){e.Engine.audioEngine.canUseWebAudio&&(this._ouputAudioNode.disconnect(),this._ouputAudioNode.connect(t))},t.prototype.setDirectionalCone=function(t,r,i){return t>r?void e.Tools.Error("setDirectionalCone(): outer angle of the cone must be superior or equal to the inner angle."):(this._coneInnerAngle=t,this._coneOuterAngle=r,this._coneOuterGain=i,this._isDirectional=!0,void(this.isPlaying&&this.loop&&(this.stop(),this.play())))},t.prototype.setPosition=function(t){this._position=t,e.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z)},t.prototype.setLocalDirectionToMesh=function(t){this._localDirection=t,e.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.isPlaying&&this._updateDirection()},t.prototype._updateDirection=function(){var t=this._connectedMesh.getWorldMatrix(),r=e.Vector3.TransformNormal(this._localDirection,t);r.normalize(),this._soundPanner.setOrientation(r.x,r.y,r.z)},t.prototype.updateDistanceFromListener=function(){if(e.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.useCustomAttenuation){var t=this._connectedMesh.getDistanceToCamera(this._scene.activeCamera);this._soundGain.gain.value=this._customAttenuationFunction(this._volume,t,this.maxDistance,this.refDistance,this.rolloffFactor)}},t.prototype.setAttenuationFunction=function(e){this._customAttenuationFunction=e},t.prototype.play=function(t){var r=this;if(this._isReadyToPlay&&this._scene.audioEnabled)try{var i=t?e.Engine.audioEngine.audioContext.currentTime+t:e.Engine.audioEngine.audioContext.currentTime;this._soundSource||this.spatialSound&&(this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z),this._isDirectional&&(this._soundPanner.coneInnerAngle=this._coneInnerAngle,this._soundPanner.coneOuterAngle=this._coneOuterAngle,this._soundPanner.coneOuterGain=this._coneOuterGain,this._connectedMesh?this._updateDirection():this._soundPanner.setOrientation(this._localDirection.x,this._localDirection.y,this._localDirection.z))),this._soundSource=e.Engine.audioEngine.audioContext.createBufferSource(),this._soundSource.buffer=this._audioBuffer,this._soundSource.connect(this._inputAudioNode),this._soundSource.loop=this.loop,this._soundSource.playbackRate.value=this._playbackRate,this._startTime=i,this._soundSource.onended=function(){r._onended()},this._soundSource.start(this._startTime,this.isPaused?this._startOffset%this._soundSource.buffer.duration:0),this.isPlaying=!0,this.isPaused=!1}catch(n){e.Tools.Error("Error while trying to play audio: "+this.name+", "+n.message)}},t.prototype._onended=function(){this.isPlaying=!1,this.onended&&this.onended()},t.prototype.stop=function(t){if(this.isPlaying){var r=t?e.Engine.audioEngine.audioContext.currentTime+t:e.Engine.audioEngine.audioContext.currentTime;this._soundSource.stop(r),this.isPlaying=!1}},t.prototype.pause=function(){this.isPlaying&&(this.stop(0),this._startOffset+=e.Engine.audioEngine.audioContext.currentTime-this._startTime,this.isPaused=!0)},t.prototype.setVolume=function(t,r){e.Engine.audioEngine.canUseWebAudio&&(r?(this._soundGain.gain.linearRampToValueAtTime(this._volume,e.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.linearRampToValueAtTime(t,r)):this._soundGain.gain.value=t),this._volume=t},t.prototype.setPlaybackRate=function(e){this._playbackRate=e,this.isPlaying&&(this._soundSource.playbackRate.value=this._playbackRate)},t.prototype.getVolume=function(){return this._volume},t.prototype.attachToMesh=function(e){var t=this;this._connectedMesh=e,this.spatialSound||(this.spatialSound=!0,this._createSpatialParameters(),this.isPlaying&&this.loop&&(this.stop(),this.play())),this._onRegisterAfterWorldMatrixUpdate(this._connectedMesh),this._registerFunc=function(e){return t._onRegisterAfterWorldMatrixUpdate(e)},e.registerAfterWorldMatrixUpdate(this._registerFunc)},t.prototype._onRegisterAfterWorldMatrixUpdate=function(t){this.setPosition(t.getBoundingInfo().boundingSphere.centerWorld),e.Engine.audioEngine.canUseWebAudio&&this._isDirectional&&this.isPlaying&&this._updateDirection()},t}();e.Sound=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r){this.id=-1,this._isMainTrack=!1,this._scene=t,this._audioEngine=e.Engine.audioEngine,this.soundCollection=new Array,this._audioEngine.canUseWebAudio&&(this._outputAudioNode=this._audioEngine.audioContext.createGain(),this._outputAudioNode.connect(this._audioEngine.masterGain),r&&(r.volume&&(this._outputAudioNode.gain.value=r.volume),r.mainTrack&&(this._isMainTrack=r.mainTrack))),this._isMainTrack||(this._scene.soundTracks.push(this),this.id=this._scene.soundTracks.length-1)}return t.prototype.dispose=function(){if(this._audioEngine.canUseWebAudio){for(this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas();this.soundCollection.length;)this.soundCollection[0].dispose();this._outputAudioNode.disconnect(),this._outputAudioNode=null}},t.prototype.AddSound=function(t){e.Engine.audioEngine.canUseWebAudio&&t.connectToSoundTrackAudioNode(this._outputAudioNode),t.soundTrackId&&(-1===t.soundTrackId?this._scene.mainSoundTrack.RemoveSound(t):this._scene.soundTracks[t.soundTrackId].RemoveSound(t)),this.soundCollection.push(t),t.soundTrackId=this.id},t.prototype.RemoveSound=function(e){var t=this.soundCollection.indexOf(e);-1!==t&&this.soundCollection.splice(t,1)},t.prototype.setVolume=function(e){this._audioEngine.canUseWebAudio&&(this._outputAudioNode.gain.value=e)},t.prototype.switchPanningModelToHRTF=function(){if(e.Engine.audioEngine.canUseWebAudio)for(var t=0;tt.name?1:-1});for(var t=0;t0&&t.z<1){this._drawingContext.font="normal 12px Segoe UI";var o=this._drawingContext.measureText(e),s=t.x-o.width/2,a=t.y,h=this._drawingCanvas.getBoundingClientRect();this._showUI&&this._isClickInsideRect(h.left*this._ratio+s-5,h.top*this._ratio+a-r-12,o.width+10,17)&&i(),this._drawingContext.beginPath(),this._drawingContext.rect(s-5,a-r-12,o.width+10,17),this._drawingContext.fillStyle=n(),this._drawingContext.globalAlpha=.5,this._drawingContext.fill(),this._drawingContext.globalAlpha=1,this._drawingContext.strokeStyle="#FFFFFF",this._drawingContext.lineWidth=1,this._drawingContext.stroke(),this._drawingContext.fillStyle="#FFFFFF",this._drawingContext.fillText(e,s,a-r),this._drawingContext.beginPath(),this._drawingContext.arc(t.x,a,5,0,2*Math.PI,!1),this._drawingContext.fill()}},t.prototype._isClickInsideRect=function(e,t,r,i){return this._clickPosition?this._clickPosition.xe+r?!1:this._clickPosition.yt+i?!1:!0:!1},t.prototype.isVisible=function(){return this._enabled},t.prototype.hide=function(){if(this._enabled){this._enabled=!1;var t=this._scene.getEngine();this._scene.unregisterBeforeRender(this._syncData),this._scene.unregisterAfterRender(this._syncUI),document.body.removeChild(this._globalDiv),window.removeEventListener("resize",this._syncPositions),this._scene.forceShowBoundingBoxes=!1,this._scene.forceWireframe=!1,e.StandardMaterial.DiffuseTextureEnabled=!0,e.StandardMaterial.AmbientTextureEnabled=!0,e.StandardMaterial.SpecularTextureEnabled=!0,e.StandardMaterial.EmissiveTextureEnabled=!0,e.StandardMaterial.BumpTextureEnabled=!0,e.StandardMaterial.OpacityTextureEnabled=!0,e.StandardMaterial.ReflectionTextureEnabled=!0,this._scene.shadowsEnabled=!0,this._scene.particlesEnabled=!0,this._scene.postProcessesEnabled=!0,this._scene.collisionsEnabled=!0,this._scene.lightsEnabled=!0,this._scene.texturesEnabled=!0,this._scene.lensFlaresEnabled=!0,this._scene.proceduralTexturesEnabled=!0,this._scene.renderTargetsEnabled=!0,t.getRenderingCanvas().removeEventListener("click",this._onCanvasClick)}},t.prototype.show=function(e,t){if(void 0===e&&(e=!0),void 0===t&&(t=null),!this._enabled){this._enabled=!0,this._camera=t?t:this._scene.activeCamera,this._showUI=e;var r=this._scene.getEngine();this._globalDiv=document.createElement("div"),document.body.appendChild(this._globalDiv),this._generateDOMelements(),window.addEventListener("resize",this._syncPositions),r.getRenderingCanvas().addEventListener("click",this._onCanvasClick),this._syncPositions(),this._scene.registerBeforeRender(this._syncData),this._scene.registerAfterRender(this._syncUI)}},t.prototype._clearLabels=function(){this._drawingContext.clearRect(0,0,this._drawingCanvas.width,this._drawingCanvas.height);for(var e=0;eWindows:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Statistics",this._displayStatistics,function(e){t._displayStatistics=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Logs",this._displayLogs,function(e){ t._displayLogs=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Meshes tree",this._displayTree,function(e){t._displayTree=e.checked,t._needToRefreshMeshesTree=!0}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"General:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Bounding boxes",this._scene.forceShowBoundingBoxes,function(e){t._scene.forceShowBoundingBoxes=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Clickable labels",this._labelsEnabled,function(e){t._labelsEnabled=e.checked,t._labelsEnabled||t._clearLabels()}),this._generateCheckBox(this._optionsSubsetDiv,"Generate user marks (F12)",e.Tools.PerformanceLogLevel===e.Tools.PerformanceUserMarkLogLevel,function(t){e.Tools.PerformanceLogLevel=t.checked?e.Tools.PerformanceUserMarkLogLevel:e.Tools.PerformanceNoneLogLevel}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Rendering mode:",this.accentColor),this._generateRadio(this._optionsSubsetDiv,"Solid","renderMode",!this._scene.forceWireframe&&!this._scene.forcePointsCloud,function(e){e.checked&&(t._scene.forceWireframe=!1,t._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Wireframe","renderMode",this._scene.forceWireframe,function(e){e.checked&&(t._scene.forceWireframe=!0,t._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Point","renderMode",this._scene.forcePointsCloud,function(e){e.checked&&(t._scene.forceWireframe=!1,t._scene.forcePointsCloud=!0)}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Texture channels:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Diffuse",e.StandardMaterial.DiffuseTextureEnabled,function(t){e.StandardMaterial.DiffuseTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Ambient",e.StandardMaterial.AmbientTextureEnabled,function(t){e.StandardMaterial.AmbientTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Specular",e.StandardMaterial.SpecularTextureEnabled,function(t){e.StandardMaterial.SpecularTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Emissive",e.StandardMaterial.EmissiveTextureEnabled,function(t){e.StandardMaterial.EmissiveTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Bump",e.StandardMaterial.BumpTextureEnabled,function(t){e.StandardMaterial.BumpTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Opacity",e.StandardMaterial.OpacityTextureEnabled,function(t){e.StandardMaterial.OpacityTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Reflection",e.StandardMaterial.ReflectionTextureEnabled,function(t){e.StandardMaterial.ReflectionTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fresnel",e.StandardMaterial.FresnelEnabled,function(t){e.StandardMaterial.FresnelEnabled=t.checked}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Options:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Animations",this._scene.animationsEnabled,function(e){t._scene.animationsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Collisions",this._scene.collisionsEnabled,function(e){t._scene.collisionsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fog",this._scene.fogEnabled,function(e){t._scene.fogEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lens flares",this._scene.lensFlaresEnabled,function(e){t._scene.lensFlaresEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lights",this._scene.lightsEnabled,function(e){t._scene.lightsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Particles",this._scene.particlesEnabled,function(e){t._scene.particlesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Post-processes",this._scene.postProcessesEnabled,function(e){t._scene.postProcessesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Procedural textures",this._scene.proceduralTexturesEnabled,function(e){t._scene.proceduralTexturesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Render targets",this._scene.renderTargetsEnabled,function(e){t._scene.renderTargetsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Shadows",this._scene.shadowsEnabled,function(e){t._scene.shadowsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Skeletons",this._scene.skeletonsEnabled,function(e){t._scene.skeletonsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Sprites",this._scene.spritesEnabled,function(e){t._scene.spritesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Textures",this._scene.texturesEnabled,function(e){t._scene.texturesEnabled=e.checked}),e.Engine.audioEngine.canUseWebAudio&&(this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Audio:",this.accentColor),this._generateRadio(this._optionsSubsetDiv,"Headphones","panningModel",this._scene.headphone,function(e){e.checked&&(t._scene.headphone=!0)}),this._generateRadio(this._optionsSubsetDiv,"Normal Speakers","panningModel",!this._scene.headphone,function(e){e.checked&&(t._scene.headphone=!1)}),this._generateCheckBox(this._optionsSubsetDiv,"Disable audio",!this._scene.audioEnabled,function(e){t._scene.audioEnabled=!e.checked})),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Tools:",this.accentColor),this._generateButton(this._optionsSubsetDiv,"Dump rendertargets",function(e){t._scene.dumpNextRenderTargets=!0}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._globalDiv.appendChild(this._statsDiv),this._globalDiv.appendChild(this._logDiv),this._globalDiv.appendChild(this._optionsDiv),this._globalDiv.appendChild(this._treeDiv)}},t.prototype._displayStats=function(){var t=this._scene,r=t.getEngine(),i=r.getGlInfo();this._statsSubsetDiv.innerHTML="Babylon.js v"+e.Engine.Version+" - "+e.Tools.Format(r.getFps(),0)+" fps

Count
Total meshes: "+t.meshes.length+"
Total vertices: "+t.getTotalVertices()+"
Total materials: "+t.materials.length+"
Total textures: "+t.textures.length+"
Active meshes: "+t.getActiveMeshes().length+"
Active indices: "+t.getActiveIndices()+"
Active bones: "+t.getActiveBones()+"
Active particles: "+t.getActiveParticles()+"
Draw calls: "+r.drawCalls+"

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

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

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



Info
"+i.version+"
"+i.renderer+"
",this.customStatsFunction&&(this._statsSubsetDiv.innerHTML+=this._statsSubsetDiv.innerHTML)},t}();e.DebugLayer=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n,o,s,a,h,c){void 0===a&&(a=!0),void 0===h&&(h=!1),void 0===c&&(c=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,s,!a,h),this._texture=s.getEngine().createRawTexture(r,i,n,o,a,h,c),this.wrapU=e.Texture.CLAMP_ADDRESSMODE,this.wrapV=e.Texture.CLAMP_ADDRESSMODE}return __extends(r,t),r.CreateLuminanceTexture=function(t,i,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new r(t,i,n,e.Engine.TEXTUREFORMAT_LUMINANCE,o,s,a,h)},r.CreateLuminanceAlphaTexture=function(t,i,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new r(t,i,n,e.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA,o,s,a,h)},r.CreateAlphaTexture=function(t,i,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new r(t,i,n,e.Engine.TEXTUREFORMAT_ALPHA,o,s,a,h)},r.CreateRGBTexture=function(t,i,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new r(t,i,n,e.Engine.TEXTUREFORMAT_RGB,o,s,a,h)},r.CreateRGBATexture=function(t,i,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new r(t,i,n,e.Engine.TEXTUREFORMAT_RGBA,o,s,a,h)},r}(e.Texture);e.RawTexture=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(e){function t(t,r){e.call(this,t.x,t.y),this.index=r}return __extends(t,e),t}(e.Vector2),r=function(){function r(){this.elements=new Array}return r.prototype.add=function(e){var r=this,i=new Array;return e.forEach(function(e){if(0===i.length||!e.equalsWithEpsilon(i[0])){var n=new t(e,r.elements.length);i.push(n),r.elements.push(n)}}),i},r.prototype.computeBounds=function(){var t=new e.Vector2(this.elements[0].x,this.elements[0].y),r=new e.Vector2(this.elements[0].x,this.elements[0].y);return this.elements.forEach(function(e){e.xr.x&&(r.x=e.x),e.yr.y&&(r.y=e.y)}),{min:t,max:r,width:r.x-t.x,height:r.y-t.y}},r}(),i=function(){function t(){}return t.Rectangle=function(t,r,i,n){return[new e.Vector2(t,r),new e.Vector2(i,r),new e.Vector2(i,n),new e.Vector2(t,n)]},t.Circle=function(t,r,i,n){void 0===r&&(r=0),void 0===i&&(i=0),void 0===n&&(n=32);for(var o=new Array,s=0,a=2*Math.PI/n,h=0;n>h;h++)o.push(new e.Vector2(r+Math.cos(s)*t,i+Math.sin(s)*t)),s-=a;return o},t.Parse=function(t){var r,i=t.split(/[^-+eE\.\d]+/).map(parseFloat).filter(function(e){return!isNaN(e)}),n=[];for(r=0;r<(2147483646&i.length);r+=2)n.push(new e.Vector2(i[r],i[r+1]));return n},t.StartingAt=function(t,r){return e.Path2.StartingAt(t,r)},t}();e.Polygon=i;var n=function(){function t(t,i,n){if(this._points=new r,this._outlinepoints=new r,this._holes=[],!("poly2tri"in window))throw"PolygonMeshBuilder cannot be used because poly2tri is not referenced";this._name=t,this._scene=n;var o;o=i instanceof e.Path2?i.getPoints():i,this._swctx=new poly2tri.SweepContext(this._points.add(o)),this._outlinepoints.add(o)}return t.prototype.addHole=function(e){this._swctx.addHole(this._points.add(e));var t=new r;return t.add(e),this._holes.push(t),this},t.prototype.build=function(t,r){var i=this;void 0===t&&(t=!1);var n=new e.Mesh(this._name,this._scene),o=[],s=[],a=[],h=this._points.computeBounds();this._points.elements.forEach(function(e){o.push(0,1,0),s.push(e.x,0,e.y),a.push((e.x-h.min.x)/h.width,(e.y-h.min.y)/h.height)});var c=[];if(this._swctx.triangulate(),this._swctx.getTriangles().forEach(function(e){e.getPoints().forEach(function(e){c.push(e.index)})}),r>0){var l=s.length/3;this._points.elements.forEach(function(e){o.push(0,-1,0),s.push(e.x,-r,e.y),a.push(1-(e.x-h.min.x)/h.width,1-(e.y-h.min.y)/h.height)});var u,f,d=0;this._swctx.getTriangles().forEach(function(e){e.getPoints().forEach(function(e){switch(d){case 0:u=e;break;case 1:f=e;break;case 2:c.push(e.index+l),c.push(f.index+l),c.push(u.index+l),d=-1}d++})}),this.addSide(s,o,a,c,h,this._outlinepoints,r,!1),this._holes.forEach(function(e){i.addSide(s,o,a,c,h,e,r,!0)})}return n.setVerticesData(s,e.VertexBuffer.PositionKind,t),n.setVerticesData(o,e.VertexBuffer.NormalKind,t),n.setVerticesData(a,e.VertexBuffer.UVKind,t),n.setIndices(c),n},t.prototype.addSide=function(t,r,i,n,o,s,a,h){for(var c=t.length/3,l=0,u=0;us.elements.length-1?s.elements[0]:s.elements[u+1],t.push(d.x,0,d.y),t.push(d.x,-a,d.y),t.push(f.x,0,f.y),t.push(f.x,-a,f.y);var p=new e.Vector3(d.x,0,d.y),m=new e.Vector3(f.x,0,f.y),_=m.subtract(p),g=new e.Vector3(0,1,0),v=e.Vector3.Cross(_,g);v=v.normalize(),i.push(l/o.width,0),i.push(l/o.width,1),l+=_.length(),i.push(l/o.width,0),i.push(l/o.width,1),h?(r.push(v.x,v.y,v.z),r.push(v.x,v.y,v.z),r.push(v.x,v.y,v.z),r.push(v.x,v.y,v.z),n.push(c),n.push(c+2),n.push(c+1),n.push(c+1),n.push(c+2),n.push(c+3)):(r.push(-v.x,-v.y,-v.z),r.push(-v.x,-v.y,-v.z),r.push(-v.x,-v.y,-v.z),r.push(-v.x,-v.y,-v.z),n.push(c),n.push(c+1),n.push(c+2),n.push(c+1),n.push(c+3),n.push(c+2)),c+=4}},t}();e.PolygonMeshBuilder=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,r){this.quality=e,this.distance=t,this.optimizeMesh=r}return e}();e.SimplificationSettings=t;var r=function(){function t(){this.running=!1,this._simplificationArray=[]}return t.prototype.addTask=function(e){this._simplificationArray.push(e)},t.prototype.executeNext=function(){var e=this._simplificationArray.pop();e?(this.running=!0,this.runSimplification(e)):this.running=!1},t.prototype.runSimplification=function(t){var r=this;if(t.parallelProcessing)t.settings.forEach(function(e){var i=r.getSimplifier(t);i.simplify(e,function(i){t.mesh.addLODLevel(e.distance,i),i.isVisible=!0,e.quality===t.settings[t.settings.length-1].quality&&t.successCallback&&t.successCallback(),r.executeNext()})});else{var i=this.getSimplifier(t),n=function(e,r){i.simplify(e,function(i){t.mesh.addLODLevel(e.distance,i),i.isVisible=!0,r()})};e.AsyncLoop.Run(t.settings.length,function(e){n(t.settings[e.index],function(){e.executeNext()})},function(){t.successCallback&&t.successCallback(),r.executeNext()})}},t.prototype.getSimplifier=function(e){switch(e.simplificationType){case i.QUADRATIC:default:return new h(e.mesh)}},t}();e.SimplificationQueue=r,function(e){e[e.QUADRATIC=0]="QUADRATIC"}(e.SimplificationType||(e.SimplificationType={}));var i=e.SimplificationType,n=function(){function e(e){this.vertices=e,this.error=new Array(4),this.deleted=!1,this.isDirty=!1,this.deletePending=!1,this.borderFactor=0}return e}();e.DecimationTriangle=n;var o=function(){function e(e,t){this.position=e,this.id=t,this.isBorder=!0,this.q=new s,this.triangleCount=0,this.triangleStart=0,this.originalOffsets=[]}return e.prototype.updatePosition=function(e){this.position.copyFrom(e)},e}();e.DecimationVertex=o;var s=function(){function e(e){this.data=new Array(10);for(var t=0;10>t;++t)this.data[t]=e&&e[t]?e[t]:0}return e.prototype.det=function(e,t,r,i,n,o,s,a,h){var c=this.data[e]*this.data[n]*this.data[h]+this.data[r]*this.data[i]*this.data[a]+this.data[t]*this.data[o]*this.data[s]-this.data[r]*this.data[n]*this.data[s]-this.data[e]*this.data[o]*this.data[a]-this.data[t]*this.data[i]*this.data[h];return c},e.prototype.addInPlace=function(e){for(var t=0;10>t;++t)this.data[t]+=e.data[t]},e.prototype.addArrayInPlace=function(e){for(var t=0;10>t;++t)this.data[t]+=e[t]},e.prototype.add=function(t){for(var r=new e,i=0;10>i;++i)r.data[i]=this.data[i]+t.data[i];return r},e.FromData=function(t,r,i,n){return new e(e.DataFromNumbers(t,r,i,n))},e.DataFromNumbers=function(e,t,r,i){return[e*e,e*t,e*r,e*i,t*t,t*r,t*i,r*r,r*i,i*i]},e}();e.QuadraticMatrix=s;var a=function(){function e(e,t){this.vertexId=e,this.triangleId=t}return e}();e.Reference=a;var h=function(){function t(t){this._mesh=t,this.initialized=!1,this.syncIterations=5e3,this.aggressiveness=7,this.decimationIterations=100,this.boundingBoxEpsilon=e.Engine.Epsilon}return t.prototype.simplify=function(t,r){var i=this;this.initDecimatedMesh(),e.AsyncLoop.Run(this._mesh.subMeshes.length,function(e){i.initWithMesh(e.index,function(){i.runDecimation(t,e.index,function(){e.executeNext()})},t.optimizeMesh)},function(){setTimeout(function(){r(i._reconstructedMesh)},0)})},t.prototype.isTriangleOnBoundingBox=function(e){var t=this,r=0;return e.vertices.forEach(function(e){var i=0,n=e.position,o=t._mesh.getBoundingInfo().boundingBox;(o.maximum.x-n.xt.boundingBoxEpsilon)&&++i,(o.maximum.y==n.y||n.y==o.minimum.y)&&++i,(o.maximum.z==n.z||n.z==o.minimum.z)&&++i,i>1&&++r}),r>1&&console.log(e,r),r>1},t.prototype.runDecimation=function(t,r,i){var n=this,o=~~(this.triangles.length*t.quality),s=0,a=this.triangles.length,h=function(t,r){setTimeout(function(){t%5===0&&n.updateMesh(0===t);for(var i=0;ih||i.deleted||i.isDirty))for(var o=0;3>o;++o)if(i.error[o]x;x++)n.references[l.triangleStart+x]=n.references[v+x]}else l.triangleStart=v;l.triangleCount=y;break}};e.AsyncLoop.SyncAsyncForLoop(n.triangles.length,n.syncIterations,c,r,function(){return o>=a-s})},0)};e.AsyncLoop.Run(this.decimationIterations,function(e){o>=a-s?e.breakLoop():h(e.index,function(){e.executeNext()})},function(){setTimeout(function(){n.reconstructMesh(r),i()},0)})},t.prototype.initWithMesh=function(t,r,i){var s=this;this.vertices=[],this.triangles=[];var a=this._mesh.getVerticesData(e.VertexBuffer.PositionKind),h=this._mesh.getIndices(),c=this._mesh.subMeshes[t],l=function(e){if(i)for(var t=0;t>0,f,function(){var t=function(e){var t=c.indexStart/3+e,r=3*t,i=h[r+0],o=h[r+1],a=h[r+2],l=s.vertices[u[i-c.verticesStart]],f=s.vertices[u[o-c.verticesStart]],d=s.vertices[u[a-c.verticesStart]],p=new n([l,f,d]);p.originalOffset=r,s.triangles.push(p)};e.AsyncLoop.SyncAsyncForLoop(c.indexCount/3,s.syncIterations,t,function(){s.init(r)})})},t.prototype.init=function(t){var r=this,i=function(t){var i=r.triangles[t];i.normal=e.Vector3.Cross(i.vertices[1].position.subtract(i.vertices[0].position),i.vertices[2].position.subtract(i.vertices[0].position)).normalize();for(var n=0;3>n;n++)i.vertices[n].q.addArrayInPlace(s.DataFromNumbers(i.normal.x,i.normal.y,i.normal.z,-e.Vector3.Dot(i.normal,i.vertices[0].position)))};e.AsyncLoop.SyncAsyncForLoop(this.triangles.length,this.syncIterations,i,function(){var i=function(e){for(var t=r.triangles[e],i=0;3>i;++i)t.error[i]=r.calculateError(t.vertices[i],t.vertices[(i+1)%3]);t.error[3]=Math.min(t.error[0],t.error[1],t.error[2])};e.AsyncLoop.SyncAsyncForLoop(r.triangles.length,r.syncIterations,i,function(){r.initialized=!0,t()})})},t.prototype.reconstructMesh=function(t){var r,i=[];for(r=0;ro;++o)n.vertices[o].triangleCount=1;i.push(n)}var s=this._reconstructedMesh.getVerticesData(e.VertexBuffer.PositionKind)||[],a=this._reconstructedMesh.getVerticesData(e.VertexBuffer.NormalKind)||[],h=this._reconstructedMesh.getVerticesData(e.VertexBuffer.UVKind)||[],c=this._reconstructedMesh.getVerticesData(e.VertexBuffer.ColorKind)||[],l=this._mesh.getVerticesData(e.VertexBuffer.NormalKind),u=this._mesh.getVerticesData(e.VertexBuffer.UVKind),f=this._mesh.getVerticesData(e.VertexBuffer.ColorKind),d=0;for(r=0;rr&&(r=0),v.push(n.vertices[e].id+r+_)})}this._reconstructedMesh.setIndices(v),this._reconstructedMesh.setVerticesData(e.VertexBuffer.PositionKind,s),this._reconstructedMesh.setVerticesData(e.VertexBuffer.NormalKind,a),h.length>0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.UVKind,h),c.length>0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.ColorKind,c);var x=this._mesh.subMeshes[t];if(t>0){this._reconstructedMesh.subMeshes=[],g.forEach(function(t){new e.SubMesh(t.materialIndex,t.verticesStart,t.verticesCount,t.indexStart,t.indexCount,t.getMesh())});{new e.SubMesh(x.materialIndex,_,d,m,3*i.length,this._reconstructedMesh)}}},t.prototype.initDecimatedMesh=function(){this._reconstructedMesh=new e.Mesh(this._mesh.name+"Decimated",this._mesh.getScene()),this._reconstructedMesh.material=this._mesh.material,this._reconstructedMesh.parent=this._mesh.parent,this._reconstructedMesh.isVisible=!1},t.prototype.isFlipped=function(t,r,i,n,o,s){for(var a=0;a.999)return!0;var p=e.Vector3.Cross(f,d).normalize();if(n[a]=!1,e.Vector3.Dot(p,h.normal)<.2)return!0}else n[a]=!0,s.push(h)}}return!1},t.prototype.updateTriangles=function(e,t,r,i){for(var n=i,o=0;os;s++){for(var a=0,h=o.vertices[s];an;++n)o=i.vertices[n],o.triangleCount++;var s=0;for(t=0;tn;++n)o=i.vertices[n],h[o.triangleStart+o.triangleCount]=new a(n,t),o.triangleCount++;this.references=h,e&&this.identifyBorder()},t.prototype.vertexError=function(e,t){var r=t.x,i=t.y,n=t.z;return e.data[0]*r*r+2*e.data[1]*r*i+2*e.data[2]*r*n+2*e.data[3]*r+e.data[4]*i*i+2*e.data[5]*i*n+2*e.data[6]*i+e.data[7]*n*n+2*e.data[8]*n+e.data[9]},t.prototype.calculateError=function(t,r,i,n,o,s){var a=t.q.add(r.q),h=t.isBorder&&r.isBorder,c=0,l=a.det(0,1,2,1,4,5,2,5,7);if(0===l||h){var u=t.position.add(r.position).divide(new e.Vector3(2,2,2)),f=this.vertexError(a,t.position),d=this.vertexError(a,r.position),p=this.vertexError(a,u);c=Math.min(f,d,p),c===f?i&&i.copyFrom(t.position):c===d?i&&i.copyFrom(r.position):i&&i.copyFrom(u)}else i||(i=e.Vector3.Zero()),i.x=-1/l*a.det(1,2,3,4,5,6,5,7,8),i.y=1/l*a.det(0,2,3,1,5,6,2,7,8),i.z=-1/l*a.det(0,1,3,1,4,6,2,5,8),c=this.vertexError(a,i);return c},t}();e.QuadraticErrorSimplification=h}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.SMOOTHING=.75,this.FFT_SIZE=512,this.BARGRAPHAMPLITUDE=256,this.DEBUGCANVASPOS={x:20,y:20},this.DEBUGCANVASSIZE={width:320,height:200},this._scene=t,this._audioEngine=e.Engine.audioEngine,this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser=this._audioEngine.audioContext.createAnalyser(),this._webAudioAnalyser.minDecibels=-140,this._webAudioAnalyser.maxDecibels=0,this._byteFreqs=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._byteTime=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._floatFreqs=new Float32Array(this._webAudioAnalyser.frequencyBinCount))}return t.prototype.getFrequencyBinCount=function(){return this._audioEngine.canUseWebAudio?this._webAudioAnalyser.frequencyBinCount:0},t.prototype.getByteFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteFrequencyData(this._byteFreqs)),this._byteFreqs},t.prototype.getByteTimeDomainData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteTimeDomainData(this._byteTime)),this._byteTime},t.prototype.getFloatFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getFloatFrequencyData(this._floatFreqs)),this._floatFreqs},t.prototype.drawDebugCanvas=function(){var e=this;if(this._audioEngine.canUseWebAudio&&(this._debugCanvas||(this._debugCanvas=document.createElement("canvas"),this._debugCanvas.width=this.DEBUGCANVASSIZE.width,this._debugCanvas.height=this.DEBUGCANVASSIZE.height,this._debugCanvas.style.position="absolute",this._debugCanvas.style.top=this.DEBUGCANVASPOS.y+"px",this._debugCanvas.style.left=this.DEBUGCANVASPOS.x+"px",this._debugCanvasContext=this._debugCanvas.getContext("2d"),document.body.appendChild(this._debugCanvas),this._registerFunc=function(){e.drawDebugCanvas()},this._scene.registerBeforeRender(this._registerFunc)),this._registerFunc)){var t=this.getByteFrequencyData();this._debugCanvasContext.fillStyle="rgb(0, 0, 0)",this._debugCanvasContext.fillRect(0,0,this.DEBUGCANVASSIZE.width,this.DEBUGCANVASSIZE.height);for(var r=0;rn;n++)for(var o=0;t>o;o++){var s=e.Vector3.Zero();s.x=Math.floor(255*i(0,1)),s.y=Math.floor(255*i(0,1)),s.z=Math.floor(255*i(0,1)),r.fillStyle="rgb("+s.x+", "+s.y+", "+s.z+")",r.fillRect(n,o,1,1)}this._randomTexture.update(!1)},r}(e.PostProcessRenderPipeline);e.SSAORenderingPipeline=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(i,n,o,s,a,h,c,l){var u=this;void 0===a&&(a=100),void 0===h&&(h=e.Texture.BILINEAR_SAMPLINGMODE),t.call(this,i,"volumetricLightScattering",["decay","exposure","weight","meshPositionOnScreen","density"],["lightScatteringSampler"],n.postProcessRatio||n,o,h,c,l,"#define NUM_SAMPLES "+a),this._screenCoordinates=e.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 e.Viewport(0,0,1,1).toGlobal(f.getEngine()),this.mesh=null!==s?s:r.CreateDefaultMesh("VolumetricLightScatteringMesh",f),this._createPass(f,n.passRatio||n),this.onApply=function(e){u._updateMeshScreenCoordinates(f),e.setTexture("lightScatteringSampler",u._volumetricLightScatteringRTT),e.setFloat("exposure",u.exposure),e.setFloat("decay",u.decay),e.setFloat("weight",u.weight),e.setFloat("density",u.density),e.setVector2("meshPositionOnScreen",u._screenCoordinates)}}return __extends(r,t),r.prototype.isReady=function(t,r){var i=t.getMesh(),n=[],o=[e.VertexBuffer.PositionKind],s=t.getMaterial(),a=!1;i===this.mesh&&(n.push("#define BASIC_RENDER"),n.push("#define NEED_UV"),a=!0),s&&((s.needAlphaTesting()||i===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")),i.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(o.push(e.VertexBuffer.UVKind),n.push("#define UV1")),i.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(o.push(e.VertexBuffer.UV2Kind),n.push("#define UV2"))),i.useBones&&(o.push(e.VertexBuffer.MatricesIndicesKind),o.push(e.VertexBuffer.MatricesWeightsKind),n.push("#define BONES"),n.push("#define BonesPerMesh "+(i.skeleton.bones.length+1))),r&&(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=i.getScene().getEngine().createEffect({vertexElement:"depth",fragmentElement:"volumetricLightScatteringPass"},o,["world","mBones","viewProjection","diffuseMatrix","opacityLevel"],["diffuseSampler","opacitySampler"],h)),this._volumetricLightScatteringPass.isReady()},r.prototype.setCustomMeshPosition=function(e){this._customMeshPosition=e},r.prototype.getCustomMeshPosition=function(){return this._customMeshPosition},r.prototype.dispose=function(e){var r=e.getScene().customRenderTargets.indexOf(this._volumetricLightScatteringRTT);-1!==r&&e.getScene().customRenderTargets.splice(r,1),this._volumetricLightScatteringRTT.dispose(),t.prototype.dispose.call(this,e)},r.prototype.getPass=function(){return this._volumetricLightScatteringRTT},r.prototype._meshExcluded=function(e){return this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e)?!0:!1},r.prototype._createPass=function(t,r){var i=this,n=t.getEngine();this._volumetricLightScatteringRTT=new e.RenderTargetTexture("volumetricLightScatteringMap",{width:n.getRenderWidth()*r,height:n.getRenderHeight()*r},t,!1,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT),this._volumetricLightScatteringRTT.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.renderList=null,this._volumetricLightScatteringRTT.renderParticles=!1,t.customRenderTargets.push(this._volumetricLightScatteringRTT);var o,s=function(t){var r=t.getRenderingMesh();if(!i._meshExcluded(r)){var n=r.getScene(),o=n.getEngine();o.setState(t.getMaterial().backFaceCulling);var s=r._getInstancesRenderList(t._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[t._id];if(i.isReady(t,a)){o.enableEffect(i._volumetricLightScatteringPass),r._bind(t,i._volumetricLightScatteringPass,e.Material.TriangleFillMode);var h=t.getMaterial();if(i._volumetricLightScatteringPass.setMatrix("viewProjection",n.getTransformMatrix()),h&&(r===i.mesh||h.needAlphaTesting()||void 0!==h.opacityTexture)){var c=h.getAlphaTestTexture();i._volumetricLightScatteringPass.setTexture("diffuseSampler",c),c&&i._volumetricLightScatteringPass.setMatrix("diffuseMatrix",c.getTextureMatrix()),void 0!==h.opacityTexture&&(i._volumetricLightScatteringPass.setTexture("opacitySampler",h.opacityTexture),i._volumetricLightScatteringPass.setFloat("opacityLevel",h.opacityTexture.level))}r.useBones&&i._volumetricLightScatteringPass.setMatrices("mBones",r.skeleton.getTransformMatrices()),r._processRendering(t,i._volumetricLightScatteringPass,e.Material.TriangleFillMode,s,a,function(e,t){return i._volumetricLightScatteringPass.setMatrix("world",t)})}}}},a=new e.Color4(0,0,0,1);this._volumetricLightScatteringRTT.onBeforeRender=function(){o=t.clearColor,t.clearColor=a},this._volumetricLightScatteringRTT.onAfterRender=function(){t.clearColor=o},this._volumetricLightScatteringRTT.customRenderFunction=function(r,i,n){var o,a=t.getEngine();for(o=0;ot._alphaIndex?1:e._alphaIndext._distanceToCamera?-1:0}),a.setAlphaMode(e.Engine.ALPHA_COMBINE),o=0;oo;o++)for(var s=0;t>s;s++)r=Math.floor(255*n(.42,.58)),i.fillStyle="rgb("+r+", "+r+", "+r+")",i.fillRect(o,s,1,1);this._grainTexture.update(!1)},r}(e.PostProcessRenderPipeline);e.LensRenderingPipeline=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n,o,s,a,h){var c=this;t.call(this,r,"colorCorrection",null,["colorTable"],n,o,s,a,h),this._colorTableTexture=new e.Texture(i,o.getScene(),!0,!1,e.Texture.TRILINEAR_SAMPLINGMODE),this._colorTableTexture.anisotropicFilteringLevel=1,this._colorTableTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._colorTableTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,this.onApply=function(e){e.setTexture("colorTable",c._colorTableTexture)}}return __extends(r,t),r}(e.PostProcess);e.ColorCorrectionPostProcess=t}(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=function(t){function r(r,i,n,o,s){t.call(this,r,i,s),this.setSubCameraMode(o?e.Camera.SUB_CAMERA_MODE_VERTICAL_STEREOSCOPIC:e.Camera.SUB_CAMERA_MODE_HORIZONTAL_STEREOSCOPIC,n)}return __extends(r,t),r}(e.FreeCamera);e.StereoscopicFreeCamera=t;var r=function(t){function r(r,i,n,o,s,a,h,c){t.call(this,r,i,n,o,s,c),this.setSubCameraMode(h?e.Camera.SUB_CAMERA_MODE_VERTICAL_STEREOSCOPIC:e.Camera.SUB_CAMERA_MODE_HORIZONTAL_STEREOSCOPIC,a)}return __extends(r,t),r}(e.ArcRotateCamera);e.StereoscopicArcRotateCamera=r;var i=function(t){function r(r,i,n,o,s){t.call(this,r,i,s),this.setSubCameraMode(o?e.Camera.SUB_CAMERA_MODE_VERTICAL_STEREOSCOPIC:e.Camera.SUB_CAMERA_MODE_HORIZONTAL_STEREOSCOPIC,n)}return __extends(r,t),r}(e.GamepadCamera);e.StereoscopicGamepadCamera=i}(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore={anaglyphPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D leftSampler;\r\n\r\nvoid main(void)\r\n{\r\n vec4 leftFrag = texture2D(leftSampler, vUV);\r\n leftFrag = vec4(1.0, leftFrag.g, leftFrag.b, 1.0);\r\n\r\n vec4 rightFrag = texture2D(textureSampler, vUV);\r\n rightFrag = vec4(rightFrag.r, 1.0, 1.0, 1.0);\r\n\r\n gl_FragColor = vec4(rightFrag.rgb * leftFrag.rgb, 1.0);\r\n}",blackAndWhitePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\nvoid main(void) \r\n{\r\n float luminance = dot(texture2D(textureSampler, vUV).rgb, vec3(0.3, 0.59, 0.11));\r\n gl_FragColor = vec4(luminance, luminance, luminance, 1.0);\r\n}",blurPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\n// Parameters\r\nuniform vec2 screenSize;\r\nuniform vec2 direction;\r\nuniform float blurWidth;\r\n\r\nvoid main(void)\r\n{\r\n float weights[7];\r\n weights[0] = 0.05;\r\n weights[1] = 0.1;\r\n weights[2] = 0.2;\r\n weights[3] = 0.3;\r\n weights[4] = 0.2;\r\n weights[5] = 0.1;\r\n weights[6] = 0.05;\r\n\r\n vec2 texelSize = vec2(1.0 / screenSize.x, 1.0 / screenSize.y);\r\n vec2 texelStep = texelSize * direction * blurWidth;\r\n vec2 start = vUV - 3.0 * texelStep;\r\n\r\n vec4 baseColor = vec4(0., 0., 0., 0.);\r\n vec2 texelOffset = vec2(0., 0.);\r\n\r\n for (int i = 0; i < 7; i++)\r\n {\r\n baseColor += texture2D(textureSampler, start + texelOffset) * weights[i];\r\n texelOffset += texelStep;\r\n }\r\n\r\n gl_FragColor = baseColor;\r\n}",brickPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nuniform float numberOfBricksHeight;\r\nuniform float numberOfBricksWidth;\r\nuniform vec3 brickColor;\r\nuniform vec3 jointColor;\r\n\r\nfloat rand(vec2 n) {\r\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n const vec2 d = vec2(0.0, 1.0);\r\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n float total = 0.0, amplitude = 1.0;\r\n for (int i = 0; i < 4; i++) {\r\n total += noise(n) * amplitude;\r\n n += n;\r\n amplitude *= 0.5;\r\n }\r\n return total;\r\n}\r\n\r\nfloat round(float number){\r\n return sign(number)*floor(abs(number) + 0.5);\r\n}\r\n\r\nvoid main(void)\r\n{\r\n float brickW = 1.0 / numberOfBricksWidth;\r\n float brickH = 1.0 / numberOfBricksHeight;\r\n float jointWPercentage = 0.01;\r\n float jointHPercentage = 0.05;\r\n vec3 color = brickColor;\r\n float yi = vUV.y / brickH;\r\n float nyi = round(yi);\r\n float xi = vUV.x / brickW;\r\n\r\n if (mod(floor(yi), 2.0) == 0.0){\r\n xi = xi - 0.5;\r\n }\r\n\r\n float nxi = round(xi);\r\n vec2 brickvUV = vec2((xi - floor(xi)) / brickH, (yi - floor(yi)) / brickW);\r\n\r\n if (yi < nyi + jointHPercentage && yi > nyi - jointHPercentage){\r\n color = mix(jointColor, vec3(0.37, 0.25, 0.25), (yi - nyi) / jointHPercentage + 0.2);\r\n }\r\n else if (xi < nxi + jointWPercentage && xi > nxi - jointWPercentage){\r\n color = mix(jointColor, vec3(0.44, 0.44, 0.44), (xi - nxi) / jointWPercentage + 0.2);\r\n }\r\n else {\r\n float brickColorSwitch = mod(floor(yi) + floor(xi), 3.0);\r\n\r\n if (brickColorSwitch == 0.0)\r\n color = mix(color, vec3(0.33, 0.33, 0.33), 0.3);\r\n else if (brickColorSwitch == 2.0)\r\n color = mix(color, vec3(0.11, 0.11, 0.11), 0.3);\r\n }\r\n\r\n gl_FragColor = vec4(color, 1.0);\r\n}",chromaticAberrationPixelShader:"// BABYLON.JS Chromatic Aberration GLSL Shader\r\n// Author: Olivier Guyot\r\n// Separates very slightly R, G and B colors on the edges of the screen\r\n// Inspired by Francois Tarlier & Martins Upitis\r\n\r\n#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// samplers\r\nuniform sampler2D textureSampler; // original color\r\n\r\n// uniforms\r\nuniform float chromatic_aberration;\r\nuniform float screen_width;\r\nuniform float screen_height;\r\n\r\n// varyings\r\nvarying vec2 vUV;\r\n\r\nvoid main(void)\r\n{\r\n vec2 centered_screen_pos = vec2(vUV.x - 0.5, vUV.y - 0.5);\r\n float radius2 = centered_screen_pos.x*centered_screen_pos.x\r\n + centered_screen_pos.y*centered_screen_pos.y;\r\n float radius = sqrt(radius2);\r\n\r\n vec4 original = texture2D(textureSampler, vUV);\r\n\r\n if (chromatic_aberration > 0.0) {\r\n //index of refraction of each color channel, causing chromatic dispersion\r\n vec3 ref_indices = vec3(-0.3, 0.0, 0.3);\r\n float ref_shiftX = chromatic_aberration * radius * 17.0 / screen_width;\r\n float ref_shiftY = chromatic_aberration * radius * 17.0 / screen_height;\r\n\r\n // shifts for red, green & blue\r\n vec2 ref_coords_r = vec2(vUV.x + ref_indices.r*ref_shiftX, vUV.y + ref_indices.r*ref_shiftY*0.5);\r\n vec2 ref_coords_g = vec2(vUV.x + ref_indices.g*ref_shiftX, vUV.y + ref_indices.g*ref_shiftY*0.5);\r\n vec2 ref_coords_b = vec2(vUV.x + ref_indices.b*ref_shiftX, vUV.y + ref_indices.b*ref_shiftY*0.5);\r\n\r\n original.r = texture2D(textureSampler, ref_coords_r).r;\r\n original.g = texture2D(textureSampler, ref_coords_g).g;\r\n original.b = texture2D(textureSampler, ref_coords_b).b;\r\n }\r\n\r\n gl_FragColor = original;\r\n}",cloudPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vUV;\r\n\r\nuniform 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}",outlinePixelShader:"precision highp float;\r\n\r\nuniform vec4 color;\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform sampler2D diffuseSampler;\r\n#endif\r\n\r\nvoid main(void) {\r\n#ifdef ALPHATEST\r\n if (texture2D(diffuseSampler, vUV).a < 0.4)\r\n discard;\r\n#endif\r\n\r\n gl_FragColor = color;\r\n}",outlineVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attribute\r\nattribute vec3 position;\r\nattribute vec3 normal;\r\n\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniform\r\nuniform float offset;\r\n\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 viewProjection;\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform mat4 diffuseMatrix;\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#ifdef INSTANCES\r\n mat4 finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n mat4 finalWorld = world;\r\n#endif\r\n\r\n vec3 offsetPosition = position + normal * offset;\r\n\r\n#ifdef BONES\r\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n gl_Position = viewProjection * finalWorld * vec4(offsetPosition, 1.0);\r\n#else\r\n gl_Position = viewProjection * finalWorld * vec4(offsetPosition, 1.0);\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\n#ifdef UV1\r\n vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n#endif\r\n#ifdef UV2\r\n vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n#endif\r\n#endif\r\n}",particlesPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nvarying vec4 vColor;\r\nuniform vec4 textureMask;\r\nuniform sampler2D diffuseSampler;\r\n\r\n#ifdef CLIPPLANE\r\nvarying float fClipDistance;\r\n#endif\r\n\r\nvoid main(void) {\r\n#ifdef CLIPPLANE\r\n if (fClipDistance > 0.0)\r\n discard;\r\n#endif\r\n vec4 baseColor = texture2D(diffuseSampler, vUV);\r\n\r\n gl_FragColor = (baseColor * textureMask + (vec4(1., 1., 1., 1.) - textureMask)) * vColor;\r\n}",particlesVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec3 position;\r\nattribute vec4 color;\r\nattribute vec4 options;\r\n\r\n// Uniforms\r\nuniform mat4 view;\r\nuniform mat4 projection;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\nvarying vec4 vColor;\r\n\r\n#ifdef CLIPPLANE\r\nuniform vec4 vClipPlane;\r\nuniform mat4 invView;\r\nvarying float fClipDistance;\r\n#endif\r\n\r\nvoid main(void) { \r\n vec3 viewPos = (view * vec4(position, 1.0)).xyz; \r\n vec3 cornerPos;\r\n float size = options.y;\r\n float angle = options.x;\r\n vec2 offset = options.zw;\r\n\r\n cornerPos = vec3(offset.x - 0.5, offset.y - 0.5, 0.) * size;\r\n\r\n // Rotate\r\n vec3 rotatedCorner;\r\n rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\r\n rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\r\n rotatedCorner.z = 0.;\r\n\r\n // Position\r\n viewPos += rotatedCorner;\r\n gl_Position = projection * vec4(viewPos, 1.0); \r\n \r\n vColor = color;\r\n vUV = offset;\r\n\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n vec4 worldPos = invView * vec4(viewPos, 1.0);\r\n fClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n}",passPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\nvoid main(void) \r\n{\r\n gl_FragColor = texture2D(textureSampler, vUV);\r\n}",postprocessVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec2 position;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\n\r\nconst vec2 madd = vec2(0.5, 0.5);\r\n\r\nvoid main(void) { \r\n\r\n vUV = position * madd + madd;\r\n gl_Position = vec4(position, 0.0, 1.0);\r\n}",proceduralVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec2 position;\r\n\r\n// Output\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nconst vec2 madd = vec2(0.5, 0.5);\r\n\r\nvoid main(void) { \r\n vPosition = position;\r\n vUV = position * madd + madd;\r\n gl_Position = vec4(position, 0.0, 1.0);\r\n}",refractionPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D refractionSampler;\r\n\r\n// Parameters\r\nuniform vec3 baseColor;\r\nuniform float depth;\r\nuniform float colorLevel;\r\n\r\nvoid main() {\r\n float ref = 1.0 - texture2D(refractionSampler, vUV).r;\r\n\r\n vec2 uv = vUV - vec2(0.5);\r\n vec2 offset = uv * depth * ref;\r\n vec3 sourceColor = texture2D(textureSampler, vUV - offset).rgb;\r\n\r\n gl_FragColor = vec4(sourceColor + sourceColor * ref * colorLevel, 1.0);\r\n}",roadPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vUV; \r\nuniform vec3 roadColor;\r\n\r\nfloat rand(vec2 n) {\r\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n const vec2 d = vec2(0.0, 1.0);\r\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n float total = 0.0, amplitude = 1.0;\r\n for (int i = 0; i < 4; i++) {\r\n total += noise(n) * amplitude;\r\n n += n;\r\n amplitude *= 0.5;\r\n }\r\n return total;\r\n}\r\n\r\nvoid main(void) {\r\n float ratioy = mod(gl_FragCoord.y * 100.0 , fbm(vUV * 2.0));\r\n vec3 color = roadColor * ratioy;\r\n gl_FragColor = vec4(color, 1.0);\r\n}",shadowMapPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvec4 pack(float depth)\r\n{\r\n const vec4 bit_shift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);\r\n const vec4 bit_mask = vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);\r\n\r\n vec4 res = fract(depth * bit_shift);\r\n res -= res.xxyz * bit_mask;\r\n\r\n return res;\r\n}\r\n\r\n// Thanks to http://devmaster.net/\r\nvec2 packHalf(float depth) \r\n{ \r\n const vec2 bitOffset = vec2(1.0 / 255., 0.);\r\n vec2 color = vec2(depth, fract(depth * 255.));\r\n\r\n return color - (color.yy * bitOffset);\r\n}\r\n\r\nvarying vec4 vPosition;\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform sampler2D diffuseSampler;\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#ifdef ALPHATEST\r\n if (texture2D(diffuseSampler, vUV).a < 0.4)\r\n discard;\r\n#endif\r\n float depth = vPosition.z / vPosition.w;\r\n depth = depth * 0.5 + 0.5;\r\n\r\n#ifdef VSM\r\n float moment1 = depth;\r\n float moment2 = moment1 * moment1;\r\n\r\n gl_FragColor = vec4(packHalf(moment1), packHalf(moment2));\r\n#else\r\n gl_FragColor = pack(depth);\r\n#endif\r\n}",shadowMapVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attribute\r\nattribute vec3 position;\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniform\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 viewProjection;\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\nvarying vec4 vPosition;\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform mat4 diffuseMatrix;\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#ifdef INSTANCES\r\n mat4 finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n mat4 finalWorld = world;\r\n#endif\r\n\r\n#ifdef BONES\r\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n#endif\r\n\r\n vPosition = viewProjection * finalWorld * vec4(position, 1.0);\r\n gl_Position = vPosition;\r\n\r\n#ifdef ALPHATEST\r\n#ifdef UV1\r\n vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n#endif\r\n#ifdef UV2\r\n vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n#endif\r\n#endif\r\n}",spritesPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nuniform bool alphaTest;\r\n\r\nvarying vec4 vColor;\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D diffuseSampler;\r\n\r\n// Fog\r\n#ifdef FOG\r\n\r\n#define FOGMODE_NONE 0.\r\n#define FOGMODE_EXP 1.\r\n#define FOGMODE_EXP2 2.\r\n#define FOGMODE_LINEAR 3.\r\n#define E 2.71828\r\n\r\nuniform vec4 vFogInfos;\r\nuniform vec3 vFogColor;\r\nvarying float fFogDistance;\r\n\r\nfloat CalcFogFactor()\r\n{\r\n float fogCoeff = 1.0;\r\n float fogStart = vFogInfos.y;\r\n float fogEnd = vFogInfos.z;\r\n float fogDensity = vFogInfos.w;\r\n\r\n if (FOGMODE_LINEAR == vFogInfos.x)\r\n {\r\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\r\n }\r\n else if (FOGMODE_EXP == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\r\n }\r\n else if (FOGMODE_EXP2 == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\r\n }\r\n\r\n return min(1., max(0., fogCoeff));\r\n}\r\n#endif\r\n\r\n\r\nvoid main(void) {\r\n vec4 baseColor = texture2D(diffuseSampler, vUV);\r\n\r\n if (alphaTest) \r\n {\r\n if (baseColor.a < 0.95)\r\n discard;\r\n }\r\n\r\n baseColor *= vColor;\r\n\r\n#ifdef FOG\r\n float fog = CalcFogFactor();\r\n baseColor.rgb = fog * baseColor.rgb + (1.0 - fog) * vFogColor;\r\n#endif\r\n\r\n gl_FragColor = baseColor;\r\n}",spritesVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec4 position;\r\nattribute vec4 options;\r\nattribute vec4 cellInfo;\r\nattribute vec4 color;\r\n\r\n// Uniforms\r\nuniform vec2 textureInfos;\r\nuniform mat4 view;\r\nuniform mat4 projection;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\nvarying vec4 vColor;\r\n\r\n#ifdef FOG\r\nvarying float fFogDistance;\r\n#endif\r\n\r\nvoid main(void) { \r\n vec3 viewPos = (view * vec4(position.xyz, 1.0)).xyz; \r\n vec2 cornerPos;\r\n \r\n float angle = position.w;\r\n vec2 size = vec2(options.x, options.y);\r\n vec2 offset = options.zw;\r\n vec2 uvScale = textureInfos.xy;\r\n\r\n cornerPos = vec2(offset.x - 0.5, offset.y - 0.5) * size;\r\n\r\n // Rotate\r\n vec3 rotatedCorner;\r\n rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\r\n rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\r\n rotatedCorner.z = 0.;\r\n\r\n // Position\r\n viewPos += rotatedCorner;\r\n gl_Position = projection * vec4(viewPos, 1.0); \r\n\r\n // Color\r\n vColor = color;\r\n \r\n // Texture\r\n vec2 uvOffset = vec2(abs(offset.x - cellInfo.x), 1.0 - abs(offset.y - cellInfo.y));\r\n\r\n vUV = (uvOffset + cellInfo.zw) * uvScale;\r\n\r\n // Fog\r\n#ifdef FOG\r\n fFogDistance = viewPos.z;\r\n#endif\r\n}",ssaoPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#define SAMPLES 16\r\n\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D randomSampler;\r\n\r\nuniform float randTextureTiles;\r\nuniform float samplesFactor;\r\nuniform vec3 sampleSphere[16];\r\n\r\nuniform float totalStrength;\r\nuniform float radius;\r\nuniform float area;\r\nuniform float fallOff;\r\n\r\nvarying vec2 vUV;\r\n\r\nconst vec2 offset1 = vec2(0.0, 0.001);\r\nconst vec2 offset2 = vec2(0.001, 0.0);\r\n\r\nvec3 normalFromDepth(const float depth, const vec2 coords) {\r\n float depth1 = texture2D(textureSampler, coords + offset1).r;\r\n float depth2 = texture2D(textureSampler, coords + offset2).r;\r\n\r\n vec3 p1 = vec3(offset1, depth1 - depth);\r\n vec3 p2 = vec3(offset2, depth2 - depth);\r\n\r\n vec3 normal = cross(p1, p2);\r\n normal.z = -normal.z;\r\n\r\n return normalize(normal);\r\n}\r\n\r\nvoid main(void)\r\n{\r\n const float base = 0.2;\r\n\r\n vec3 random = texture2D(randomSampler, vUV * randTextureTiles).rgb;\r\n float depth = texture2D(textureSampler, vUV).r;\r\n vec3 position = vec3(vUV, depth);\r\n vec3 normal = normalFromDepth(depth, vUV);\r\n float radiusDepth = radius / depth;\r\n float occlusion = 0.0;\r\n\r\n vec3 ray;\r\n vec3 hemiRay;\r\n float occlusionDepth;\r\n float difference;\r\n\r\n for (int i = 0; i < SAMPLES; i++)\r\n {\r\n ray = radiusDepth * reflect(sampleSphere[i], random);\r\n hemiRay = position + sign(dot(ray, normal)) * ray;\r\n\r\n occlusionDepth = texture2D(textureSampler, clamp(hemiRay.xy, 0.0, 1.0)).r;\r\n difference = depth - occlusionDepth;\r\n\r\n occlusion += step(fallOff, difference) * (1.0 - smoothstep(fallOff, area, difference));\r\n }\r\n\r\n float ao = 1.0 - totalStrength * occlusion * samplesFactor;\r\n\r\n float result = clamp(ao + base, 0.0, 1.0);\r\n gl_FragColor.r = result;\r\n gl_FragColor.g = result;\r\n gl_FragColor.b = result;\r\n gl_FragColor.a = 1.0;\r\n}\r\n",ssaoCombinePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D originalColor;\r\n\r\nvarying vec2 vUV;\r\n\r\nvoid main(void) {\r\n gl_FragColor = texture2D(originalColor, vUV) * texture2D(textureSampler, vUV);\r\n}\r\n",stereoscopicInterlacePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nconst vec3 TWO = vec3(2.0, 2.0, 2.0);\r\n\r\nvarying vec2 vUV;\r\nuniform sampler2D camASampler;\r\nuniform sampler2D textureSampler;\r\nuniform vec2 stepSize;\r\n\r\nvoid main(void)\r\n{\r\n bool useCamB;\r\n vec2 texCoord1;\r\n vec2 texCoord2;\r\n \r\n vec3 frag1;\r\n vec3 frag2;\r\n \r\n#ifdef IS_STEREOSCOPIC_HORIZ\r\n useCamB = vUV.x > 0.5;\r\n texCoord1 = vec2(useCamB ? (vUV.x - 0.5) * 2.0 : vUV.x * 2.0, vUV.y);\r\n texCoord2 = vec2(texCoord1.x + stepSize.x, vUV.y);\r\n#else\r\n useCamB = vUV.y > 0.5;\r\n texCoord1 = vec2(vUV.x, useCamB ? (vUV.y - 0.5) * 2.0 : vUV.y * 2.0);\r\n texCoord2 = vec2(vUV.x, texCoord1.y + stepSize.y);\r\n#endif\r\n \r\n // cannot assign a sampler to a variable, so must duplicate texture accesses\r\n if (useCamB){\r\n frag1 = texture2D(textureSampler, texCoord1).rgb;\r\n frag2 = texture2D(textureSampler, texCoord2).rgb;\r\n }else{\r\n frag1 = texture2D(camASampler , texCoord1).rgb;\r\n frag2 = texture2D(camASampler , texCoord2).rgb;\r\n }\r\n \r\n gl_FragColor = vec4((frag1 + frag2) / TWO, 1.0);\r\n}", 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",vrDistortionCorrectionPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform vec2 LensCenter;\r\nuniform vec2 Scale;\r\nuniform vec2 ScaleIn;\r\nuniform vec4 HmdWarpParam;\r\n\r\nvec2 HmdWarp(vec2 in01) {\r\n\r\n vec2 theta = (in01 - LensCenter) * ScaleIn; // Scales to [-1, 1]\r\n float rSq = theta.x * theta.x + theta.y * theta.y;\r\n vec2 rvector = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq + HmdWarpParam.z * rSq * rSq + HmdWarpParam.w * rSq * rSq * rSq);\r\n return LensCenter + Scale * rvector;\r\n}\r\n\r\nvoid main(void)\r\n{\r\n vec2 tc = HmdWarp(vUV);\r\n if (tc.x <0.0 || tc.x>1.0 || tc.y<0.0 || tc.y>1.0)\r\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\r\n else{\r\n gl_FragColor = vec4(texture2D(textureSampler, tc).rgb, 1.0);\r\n }\r\n}",woodPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nuniform float ampScale;\r\nuniform vec3 woodColor;\r\n\r\nfloat rand(vec2 n) {\r\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n const vec2 d = vec2(0.0, 1.0);\r\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n float total = 0.0, amplitude = 1.0;\r\n for (int i = 0; i < 4; i++) {\r\n total += noise(n) * amplitude;\r\n n += n;\r\n amplitude *= 0.5;\r\n }\r\n return total;\r\n}\r\n\r\nvoid main(void) {\r\n float ratioy = mod(vUV.x * ampScale, 2.0 + fbm(vUV * 0.8));\r\n vec3 wood = woodColor * ratioy;\r\n gl_FragColor = vec4(wood, 1.0);\r\n}"};