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

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

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

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

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

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

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

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



Info
"+r.version+"
"+r.renderer+"
",this.customStatsFunction&&(this._statsSubsetDiv.innerHTML+=this._statsSubsetDiv.innerHTML)},e}();t.DebugLayer=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o,s,a,h,c){void 0===a&&(a=!0),void 0===h&&(h=!1),void 0===c&&(c=t.Texture.TRILINEAR_SAMPLINGMODE),e.call(this,null,s,!a,h),this._texture=s.getEngine().createRawTexture(i,r,n,o,a,h,c),this.wrapU=t.Texture.CLAMP_ADDRESSMODE,this.wrapV=t.Texture.CLAMP_ADDRESSMODE}return __extends(i,e),i.CreateLuminanceTexture=function(e,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=t.Texture.TRILINEAR_SAMPLINGMODE),new i(e,r,n,t.Engine.TEXTUREFORMAT_LUMINANCE,o,s,a,h)},i.CreateLuminanceAlphaTexture=function(e,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=t.Texture.TRILINEAR_SAMPLINGMODE),new i(e,r,n,t.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA,o,s,a,h)},i.CreateAlphaTexture=function(e,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=t.Texture.TRILINEAR_SAMPLINGMODE),new i(e,r,n,t.Engine.TEXTUREFORMAT_ALPHA,o,s,a,h)},i.CreateRGBTexture=function(e,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=t.Texture.TRILINEAR_SAMPLINGMODE),new i(e,r,n,t.Engine.TEXTUREFORMAT_RGB,o,s,a,h)},i.CreateRGBATexture=function(e,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=t.Texture.TRILINEAR_SAMPLINGMODE),new i(e,r,n,t.Engine.TEXTUREFORMAT_RGBA,o,s,a,h)},i}(t.Texture);t.RawTexture=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i){t.call(this,e.x,e.y),this.index=i}return __extends(e,t),e}(t.Vector2),i=function(){function i(){this.elements=new Array}return i.prototype.add=function(i){var r=this,n=new Array;return i.forEach(function(i){if(0===n.length||!t.Tools.WithinEpsilon(i.x,n[0].x,1e-5)||!t.Tools.WithinEpsilon(i.y,n[0].y,1e-5)){var o=new e(i,r.elements.length);n.push(o),r.elements.push(o)}}),n},i.prototype.computeBounds=function(){var e=new t.Vector2(this.elements[0].x,this.elements[0].y),i=new t.Vector2(this.elements[0].x,this.elements[0].y);return this.elements.forEach(function(t){t.xi.x&&(i.x=t.x),t.yi.y&&(i.y=t.y)}),{min:e,max:i,width:i.x-e.x,height:i.y-e.y}},i}(),r=function(){function e(){}return e.Rectangle=function(e,i,r,n){return[new t.Vector2(e,i),new t.Vector2(r,i),new t.Vector2(r,n),new t.Vector2(e,n)]},e.Circle=function(e,i,r,n){void 0===i&&(i=0),void 0===r&&(r=0),void 0===n&&(n=32);for(var o=new Array,s=0,a=2*Math.PI/n,h=0;n>h;h++)o.push(new t.Vector2(i+Math.cos(s)*e,r+Math.sin(s)*e)),s-=a;return o},e.Parse=function(t){var e,i=t.split(/[^-+eE\.\d]+/).map(parseFloat).filter(function(t){return!isNaN(t)}),r=[];for(e=0;e<(2147483646&i.length);e+=2)r.push(new poly2tri.Point(i[e],i[e+1]));return r},e.StartingAt=function(e,i){return t.Path2.StartingAt(e,i)},e}();t.Polygon=r;var n=function(){function e(e,r,n){if(this._points=new i,!("poly2tri"in window))throw"PolygonMeshBuilder cannot be used because poly2tri is not referenced";this._name=e,this._scene=n;var o;o=r instanceof t.Path2?r.getPoints():r,this._swctx=new poly2tri.SweepContext(this._points.add(o))}return e.prototype.addHole=function(t){return this._swctx.addHole(this._points.add(t)),this},e.prototype.build=function(e){void 0===e&&(e=!1);var i=new t.Mesh(this._name,this._scene),r=[],n=[],o=[],s=this._points.computeBounds();this._points.elements.forEach(function(t){r.push(0,1,0),n.push(t.x,0,t.y),o.push((t.x-s.min.x)/s.width,(t.y-s.min.y)/s.height)});var a=[];return this._swctx.triangulate(),this._swctx.getTriangles().forEach(function(t){t.getPoints().forEach(function(t){a.push(t.index)})}),i.setVerticesData(t.VertexBuffer.PositionKind,n,e),i.setVerticesData(t.VertexBuffer.NormalKind,r,e),i.setVerticesData(t.VertexBuffer.UVKind,o,e),i.setIndices(a),i},e}();t.PolygonMeshBuilder=n}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(t,e,i){this.quality=t,this.distance=e,this.optimizeMesh=i}return t}();t.SimplificationSettings=e;var i=function(){function e(){this.running=!1,this._simplificationArray=[]}return e.prototype.addTask=function(t){this._simplificationArray.push(t)},e.prototype.executeNext=function(){var t=this._simplificationArray.pop();t?(this.running=!0,this.runSimplification(t)):this.running=!1},e.prototype.runSimplification=function(e){var i=this;if(e.parallelProcessing)e.settings.forEach(function(t){var r=i.getSimplifier(e);r.simplify(t,function(r){e.mesh.addLODLevel(t.distance,r),r.isVisible=!0,t.quality===e.settings[e.settings.length-1].quality&&e.successCallback&&e.successCallback(),i.executeNext()})});else{var r=this.getSimplifier(e),n=function(t,i){r.simplify(t,function(r){e.mesh.addLODLevel(t.distance,r),r.isVisible=!0,i()})};t.AsyncLoop.Run(e.settings.length,function(t){n(e.settings[t.index],function(){t.executeNext()})},function(){e.successCallback&&e.successCallback(),i.executeNext()})}},e.prototype.getSimplifier=function(t){switch(t.simplificationType){case 0:default:return new a(t.mesh)}},e}();t.SimplificationQueue=i,function(t){t[t.QUADRATIC=0]="QUADRATIC"}(t.SimplificationType||(t.SimplificationType={}));var r=(t.SimplificationType,function(){function t(t){this.vertices=t,this.error=new Array(4),this.deleted=!1,this.isDirty=!1,this.deletePending=!1,this.borderFactor=0}return t}());t.DecimationTriangle=r;var n=function(){function t(t,e){this.position=t,this.id=e,this.isBorder=!0,this.q=new o,this.triangleCount=0,this.triangleStart=0,this.originalOffsets=[]}return t.prototype.updatePosition=function(t){this.position.copyFrom(t)},t}();t.DecimationVertex=n;var o=function(){function t(t){this.data=new Array(10);for(var e=0;10>e;++e)this.data[e]=t&&t[e]?t[e]:0}return t.prototype.det=function(t,e,i,r,n,o,s,a,h){var c=this.data[t]*this.data[n]*this.data[h]+this.data[i]*this.data[r]*this.data[a]+this.data[e]*this.data[o]*this.data[s]-this.data[i]*this.data[n]*this.data[s]-this.data[t]*this.data[o]*this.data[a]-this.data[e]*this.data[r]*this.data[h];return c},t.prototype.addInPlace=function(t){for(var e=0;10>e;++e)this.data[e]+=t.data[e]},t.prototype.addArrayInPlace=function(t){for(var e=0;10>e;++e)this.data[e]+=t[e]},t.prototype.add=function(e){for(var i=new t,r=0;10>r;++r)i.data[r]=this.data[r]+e.data[r];return i},t.FromData=function(e,i,r,n){return new t(t.DataFromNumbers(e,i,r,n))},t.DataFromNumbers=function(t,e,i,r){return[t*t,t*e,t*i,t*r,e*e,e*i,e*r,i*i,i*r,r*r]},t}();t.QuadraticMatrix=o;var s=function(){function t(t,e){this.vertexId=t,this.triangleId=e}return t}();t.Reference=s;var a=function(){function e(e){this._mesh=e,this.initialized=!1,this.syncIterations=5e3,this.aggressiveness=7,this.decimationIterations=100,this.boundingBoxEpsilon=t.Engine.Epsilon}return e.prototype.simplify=function(e,i){var r=this;this.initDecimatedMesh(),t.AsyncLoop.Run(this._mesh.subMeshes.length,function(t){r.initWithMesh(t.index,function(){r.runDecimation(e,t.index,function(){t.executeNext()})},e.optimizeMesh)},function(){setTimeout(function(){i(r._reconstructedMesh)},0)})},e.prototype.isTriangleOnBoundingBox=function(t){var e=this,i=0;return t.vertices.forEach(function(t){var r=0,n=t.position,o=e._mesh.getBoundingInfo().boundingBox;(o.maximum.x-n.xe.boundingBoxEpsilon)&&++r,(o.maximum.y==n.y||n.y==o.minimum.y)&&++r,(o.maximum.z==n.z||n.z==o.minimum.z)&&++r,r>1&&++i}),i>1&&console.log(t,i),i>1},e.prototype.runDecimation=function(e,i,r){var n=this,o=~~(this.triangles.length*e.quality),s=0,a=this.triangles.length,h=function(e,i){setTimeout(function(){e%5===0&&n.updateMesh(0===e);for(var r=0;rh||r.deleted||r.isDirty))for(var o=0;3>o;++o)if(r.error[o]x;x++)n.references[l.triangleStart+x]=n.references[v+x]}else l.triangleStart=v;l.triangleCount=y;break}};t.AsyncLoop.SyncAsyncForLoop(n.triangles.length,n.syncIterations,c,i,function(){return o>=a-s})},0)};t.AsyncLoop.Run(this.decimationIterations,function(t){o>=a-s?t.breakLoop():h(t.index,function(){t.executeNext()})},function(){setTimeout(function(){n.reconstructMesh(i),r()},0)})},e.prototype.initWithMesh=function(e,i,o){var s=this;this.vertices=[],this.triangles=[];var a=this._mesh.getVerticesData(t.VertexBuffer.PositionKind),h=this._mesh.getIndices(),c=this._mesh.subMeshes[e],l=function(t){if(o)for(var e=0;e>0,f,function(){var e=function(t){var e=c.indexStart/3+t,i=3*e,n=h[i+0],o=h[i+1],a=h[i+2],l=s.vertices[u[n-c.verticesStart]],f=s.vertices[u[o-c.verticesStart]],d=s.vertices[u[a-c.verticesStart]],p=new r([l,f,d]);p.originalOffset=i,s.triangles.push(p)};t.AsyncLoop.SyncAsyncForLoop(c.indexCount/3,s.syncIterations,e,function(){s.init(i)})})},e.prototype.init=function(e){var i=this,r=function(e){var r=i.triangles[e];r.normal=t.Vector3.Cross(r.vertices[1].position.subtract(r.vertices[0].position),r.vertices[2].position.subtract(r.vertices[0].position)).normalize();for(var n=0;3>n;n++)r.vertices[n].q.addArrayInPlace(o.DataFromNumbers(r.normal.x,r.normal.y,r.normal.z,-t.Vector3.Dot(r.normal,r.vertices[0].position)))};t.AsyncLoop.SyncAsyncForLoop(this.triangles.length,this.syncIterations,r,function(){var r=function(t){for(var e=i.triangles[t],r=0;3>r;++r)e.error[r]=i.calculateError(e.vertices[r],e.vertices[(r+1)%3]);e.error[3]=Math.min(e.error[0],e.error[1],e.error[2])};t.AsyncLoop.SyncAsyncForLoop(i.triangles.length,i.syncIterations,r,function(){i.initialized=!0,e()})})},e.prototype.reconstructMesh=function(e){var i,r=[];for(i=0;io;++o)n.vertices[o].triangleCount=1;r.push(n)}var s=this._reconstructedMesh.getVerticesData(t.VertexBuffer.PositionKind)||[],a=this._reconstructedMesh.getVerticesData(t.VertexBuffer.NormalKind)||[],h=this._reconstructedMesh.getVerticesData(t.VertexBuffer.UVKind)||[],c=this._reconstructedMesh.getVerticesData(t.VertexBuffer.ColorKind)||[],l=this._mesh.getVerticesData(t.VertexBuffer.NormalKind),u=this._mesh.getVerticesData(t.VertexBuffer.UVKind),f=this._mesh.getVerticesData(t.VertexBuffer.ColorKind),d=0;for(i=0;ii&&(i=0),v.push(n.vertices[t].id+i+_)})}this._reconstructedMesh.setIndices(v),this._reconstructedMesh.setVerticesData(t.VertexBuffer.PositionKind,s),this._reconstructedMesh.setVerticesData(t.VertexBuffer.NormalKind,a),h.length>0&&this._reconstructedMesh.setVerticesData(t.VertexBuffer.UVKind,h),c.length>0&&this._reconstructedMesh.setVerticesData(t.VertexBuffer.ColorKind,c);var x=this._mesh.subMeshes[e];if(e>0){this._reconstructedMesh.subMeshes=[],g.forEach(function(e){new t.SubMesh(e.materialIndex,e.verticesStart,e.verticesCount,e.indexStart,e.indexCount,e.getMesh())});{new t.SubMesh(x.materialIndex,_,d,m,3*r.length,this._reconstructedMesh)}}},e.prototype.initDecimatedMesh=function(){this._reconstructedMesh=new t.Mesh(this._mesh.name+"Decimated",this._mesh.getScene()),this._reconstructedMesh.material=this._mesh.material,this._reconstructedMesh.parent=this._mesh.parent,this._reconstructedMesh.isVisible=!1},e.prototype.isFlipped=function(e,i,r,n,o,s){for(var a=0;a.999)return!0;var p=t.Vector3.Cross(f,d).normalize();if(n[a]=!1,t.Vector3.Dot(p,h.normal)<.2)return!0}else n[a]=!0,s.push(h)}}return!1},e.prototype.updateTriangles=function(t,e,i,r){for(var n=r,o=0;os;s++){for(var a=0,h=o.vertices[s];an;++n)o=r.vertices[n],o.triangleCount++;var a=0;for(e=0;en;++n)o=r.vertices[n],h[o.triangleStart+o.triangleCount]=new s(n,e),o.triangleCount++;this.references=h,t&&this.identifyBorder()},e.prototype.vertexError=function(t,e){var i=e.x,r=e.y,n=e.z;return t.data[0]*i*i+2*t.data[1]*i*r+2*t.data[2]*i*n+2*t.data[3]*i+t.data[4]*r*r+2*t.data[5]*r*n+2*t.data[6]*r+t.data[7]*n*n+2*t.data[8]*n+t.data[9]},e.prototype.calculateError=function(e,i,r,n,o,s){var a=e.q.add(i.q),h=e.isBorder&&i.isBorder,c=0,l=a.det(0,1,2,1,4,5,2,5,7);if(0===l||h){var u=e.position.add(i.position).divide(new t.Vector3(2,2,2)),f=this.vertexError(a,e.position),d=this.vertexError(a,i.position),p=this.vertexError(a,u);c=Math.min(f,d,p),c===f?r&&r.copyFrom(e.position):c===d?r&&r.copyFrom(i.position):r&&r.copyFrom(u)}else r||(r=t.Vector3.Zero()),r.x=-1/l*a.det(1,2,3,4,5,6,5,7,8),r.y=1/l*a.det(0,2,3,1,5,6,2,7,8),r.z=-1/l*a.det(0,1,3,1,4,6,2,5,8),c=this.vertexError(a,r);return c},e}();t.QuadraticErrorSimplification=a}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e){this.SMOOTHING=.75,this.FFT_SIZE=512,this.BARGRAPHAMPLITUDE=256,this.DEBUGCANVASPOS={x:20,y:20},this.DEBUGCANVASSIZE={width:320,height:200},this._scene=e,this._audioEngine=t.Engine.audioEngine,this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser=this._audioEngine.audioContext.createAnalyser(),this._webAudioAnalyser.minDecibels=-140,this._webAudioAnalyser.maxDecibels=0,this._byteFreqs=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._byteTime=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._floatFreqs=new Float32Array(this._webAudioAnalyser.frequencyBinCount))}return e.prototype.getFrequencyBinCount=function(){return this._audioEngine.canUseWebAudio?this._webAudioAnalyser.frequencyBinCount:0},e.prototype.getByteFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteFrequencyData(this._byteFreqs)),this._byteFreqs},e.prototype.getByteTimeDomainData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteTimeDomainData(this._byteTime)),this._byteTime},e.prototype.getFloatFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getFloatFrequencyData(this._floatFreqs)),this._floatFreqs},e.prototype.drawDebugCanvas=function(){var t=this;if(this._audioEngine.canUseWebAudio&&(this._debugCanvas||(this._debugCanvas=document.createElement("canvas"),this._debugCanvas.width=this.DEBUGCANVASSIZE.width,this._debugCanvas.height=this.DEBUGCANVASSIZE.height,this._debugCanvas.style.position="absolute",this._debugCanvas.style.top=this.DEBUGCANVASPOS.y+"px",this._debugCanvas.style.left=this.DEBUGCANVASPOS.x+"px",this._debugCanvasContext=this._debugCanvas.getContext("2d"),document.body.appendChild(this._debugCanvas),this._registerFunc=function(){t.drawDebugCanvas()},this._scene.registerBeforeRender(this._registerFunc)),this._registerFunc)){var e=this.getByteFrequencyData();this._debugCanvasContext.fillStyle="rgb(0, 0, 0)",this._debugCanvasContext.fillRect(0,0,this.DEBUGCANVASSIZE.width,this.DEBUGCANVASSIZE.height);for(var i=0;in;n++)for(var o=0;e>o;o++){var s=t.Vector3.Zero();s.x=Math.floor(255*r(0,1)),s.y=Math.floor(255*r(0,1)),s.z=Math.floor(255*r(0,1)),i.fillStyle="rgb("+s.x+", "+s.y+", "+s.z+")",i.fillRect(n,o,1,1)}this._randomTexture.update(!1)},i}(t.PostProcessRenderPipeline);t.SSAORenderingPipeline=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(r,n,o,s,a,h,c,l){var u=this;void 0===a&&(a=100),void 0===h&&(h=t.Texture.BILINEAR_SAMPLINGMODE),e.call(this,r,"volumetricLightScattering",["decay","exposure","weight","meshPositionOnScreen","density"],["lightScatteringSampler"],n.postProcessRatio||n,o,h,c,l,"#define NUM_SAMPLES "+a),this._screenCoordinates=t.Vector2.Zero(),this.useCustomMeshPosition=!1,this.invert=!0, this.excludedMeshes=new Array,this.exposure=.3,this.decay=.96815,this.weight=.58767,this.density=.926;var f=o.getScene();this._viewPort=new t.Viewport(0,0,1,1).toGlobal(f.getEngine()),this.mesh=null!==s?s:i.CreateDefaultMesh("VolumetricLightScatteringMesh",f),this._createPass(f,n.passRatio||n),this.onApply=function(t){u._updateMeshScreenCoordinates(f),t.setTexture("lightScatteringSampler",u._volumetricLightScatteringRTT),t.setFloat("exposure",u.exposure),t.setFloat("decay",u.decay),t.setFloat("weight",u.weight),t.setFloat("density",u.density),t.setVector2("meshPositionOnScreen",u._screenCoordinates)}}return __extends(i,e),i.prototype.isReady=function(e,i){var r=e.getMesh(),n=[],o=[t.VertexBuffer.PositionKind],s=e.getMaterial(),a=!1;r===this.mesh&&(n.push("#define BASIC_RENDER"),n.push("#define NEED_UV"),a=!0),s&&((s.needAlphaTesting()||r===this.mesh)&&n.push("#define ALPHATEST"),void 0!==s.opacityTexture&&(n.push("#define OPACITY"),s.opacityTexture.getAlphaFromRGB&&n.push("#define OPACITYRGB"),a||n.push("#define NEED_UV")),r.isVerticesDataPresent(t.VertexBuffer.UVKind)&&(o.push(t.VertexBuffer.UVKind),n.push("#define UV1")),r.isVerticesDataPresent(t.VertexBuffer.UV2Kind)&&(o.push(t.VertexBuffer.UV2Kind),n.push("#define UV2"))),r.useBones&&(o.push(t.VertexBuffer.MatricesIndicesKind),o.push(t.VertexBuffer.MatricesWeightsKind),n.push("#define BONES"),n.push("#define BonesPerMesh "+(r.skeleton.bones.length+1))),i&&(n.push("#define INSTANCES"),o.push("world0"),o.push("world1"),o.push("world2"),o.push("world3"));var h=n.join("\n");return this._cachedDefines!==h&&(this._cachedDefines=h,this._volumetricLightScatteringPass=r.getScene().getEngine().createEffect({vertexElement:"depth",fragmentElement:"volumetricLightScatteringPass"},o,["world","mBones","viewProjection","diffuseMatrix","opacityLevel"],["diffuseSampler","opacitySampler"],h)),this._volumetricLightScatteringPass.isReady()},i.prototype.setCustomMeshPosition=function(t){this._customMeshPosition=t},i.prototype.getCustomMeshPosition=function(){return this._customMeshPosition},i.prototype.dispose=function(t){var i=t.getScene().customRenderTargets.indexOf(this._volumetricLightScatteringRTT);-1!==i&&t.getScene().customRenderTargets.splice(i,1),this._volumetricLightScatteringRTT.dispose(),e.prototype.dispose.call(this,t)},i.prototype.getPass=function(){return this._volumetricLightScatteringRTT},i.prototype._meshExcluded=function(t){return this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(t)?!0:!1},i.prototype._createPass=function(e,i){var r=this,n=e.getEngine();this._volumetricLightScatteringRTT=new t.RenderTargetTexture("volumetricLightScatteringMap",{width:n.getRenderWidth()*i,height:n.getRenderHeight()*i},e,!1,!0,t.Engine.TEXTURETYPE_UNSIGNED_INT),this._volumetricLightScatteringRTT.wrapU=t.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.wrapV=t.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.renderList=null,this._volumetricLightScatteringRTT.renderParticles=!1,e.customRenderTargets.push(this._volumetricLightScatteringRTT);var o,s=function(e){var i=e.getRenderingMesh();if(!r._meshExcluded(i)){var n=i.getScene(),o=n.getEngine();o.setState(e.getMaterial().backFaceCulling);var s=i._getInstancesRenderList(e._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[e._id];if(r.isReady(e,a)){o.enableEffect(r._volumetricLightScatteringPass),i._bind(e,r._volumetricLightScatteringPass,t.Material.TriangleFillMode);var h=e.getMaterial();if(r._volumetricLightScatteringPass.setMatrix("viewProjection",n.getTransformMatrix()),h&&(i===r.mesh||h.needAlphaTesting()||void 0!==h.opacityTexture)){var c=h.getAlphaTestTexture();r._volumetricLightScatteringPass.setTexture("diffuseSampler",c),c&&r._volumetricLightScatteringPass.setMatrix("diffuseMatrix",c.getTextureMatrix()),void 0!==h.opacityTexture&&(r._volumetricLightScatteringPass.setTexture("opacitySampler",h.opacityTexture),r._volumetricLightScatteringPass.setFloat("opacityLevel",h.opacityTexture.level))}i.useBones&&r._volumetricLightScatteringPass.setMatrices("mBones",i.skeleton.getTransformMatrices()),i._processRendering(e,r._volumetricLightScatteringPass,t.Material.TriangleFillMode,s,a,function(t,e){return r._volumetricLightScatteringPass.setMatrix("world",e)})}}}},a=new t.Color4(0,0,0,1);this._volumetricLightScatteringRTT.onBeforeRender=function(){o=e.clearColor,e.clearColor=a},this._volumetricLightScatteringRTT.onAfterRender=function(){e.clearColor=o},this._volumetricLightScatteringRTT.customRenderFunction=function(i,r,n){var o,a=e.getEngine();for(o=0;oe._alphaIndex?1:t._alphaIndexe._distanceToCamera?-1:0}),a.setAlphaMode(t.Engine.ALPHA_COMBINE),o=0;oo;o++)for(var s=0;e>s;s++)i=Math.floor(255*n(.42,.58)),r.fillStyle="rgb("+i+", "+i+", "+i+")",r.fillRect(o,s,1,1);this._grainTexture.update(!1)},i}(t.PostProcessRenderPipeline);t.LensRenderingPipeline=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o,s,a,h){var c=this;e.call(this,i,"colorCorrection",null,["colorTable"],n,o,s,a,h),this._colorTableTexture=new t.Texture(r,o.getScene(),!0,!1,t.Texture.TRILINEAR_SAMPLINGMODE),this._colorTableTexture.anisotropicFilteringLevel=1,this._colorTableTexture.wrapU=t.Texture.CLAMP_ADDRESSMODE,this._colorTableTexture.wrapV=t.Texture.CLAMP_ADDRESSMODE,this.onApply=function(t){t.setTexture("colorTable",c._colorTableTexture)}}return __extends(i,e),i}(t.PostProcess);t.ColorCorrectionPostProcess=e}(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore={anaglyphPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D leftSampler;\r\n\r\nvoid main(void)\r\n{\r\n vec4 leftFrag = texture2D(leftSampler, vUV);\r\n leftFrag = vec4(1.0, leftFrag.g, leftFrag.b, 1.0);\r\n\r\n vec4 rightFrag = texture2D(textureSampler, vUV);\r\n rightFrag = vec4(rightFrag.r, 1.0, 1.0, 1.0);\r\n\r\n gl_FragColor = vec4(rightFrag.rgb * leftFrag.rgb, 1.0);\r\n}",blackAndWhitePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\nvoid main(void) \r\n{\r\n float luminance = dot(texture2D(textureSampler, vUV).rgb, vec3(0.3, 0.59, 0.11));\r\n gl_FragColor = vec4(luminance, luminance, luminance, 1.0);\r\n}",blurPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\n// Parameters\r\nuniform vec2 screenSize;\r\nuniform vec2 direction;\r\nuniform float blurWidth;\r\n\r\nvoid main(void)\r\n{\r\n float weights[7];\r\n weights[0] = 0.05;\r\n weights[1] = 0.1;\r\n weights[2] = 0.2;\r\n weights[3] = 0.3;\r\n weights[4] = 0.2;\r\n weights[5] = 0.1;\r\n weights[6] = 0.05;\r\n\r\n vec2 texelSize = vec2(1.0 / screenSize.x, 1.0 / screenSize.y);\r\n vec2 texelStep = texelSize * direction * blurWidth;\r\n vec2 start = vUV - 3.0 * texelStep;\r\n\r\n vec4 baseColor = vec4(0., 0., 0., 0.);\r\n vec2 texelOffset = vec2(0., 0.);\r\n\r\n for (int i = 0; i < 7; i++)\r\n {\r\n baseColor += texture2D(textureSampler, start + texelOffset) * weights[i];\r\n texelOffset += texelStep;\r\n }\r\n\r\n gl_FragColor = baseColor;\r\n}",brickPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nuniform float numberOfBricksHeight;\r\nuniform float numberOfBricksWidth;\r\nuniform vec3 brickColor;\r\nuniform vec3 jointColor;\r\n\r\nfloat rand(vec2 n) {\r\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n const vec2 d = vec2(0.0, 1.0);\r\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n float total = 0.0, amplitude = 1.0;\r\n for (int i = 0; i < 4; i++) {\r\n total += noise(n) * amplitude;\r\n n += n;\r\n amplitude *= 0.5;\r\n }\r\n return total;\r\n}\r\n\r\nfloat round(float number){\r\n return sign(number)*floor(abs(number) + 0.5);\r\n}\r\n\r\nvoid main(void)\r\n{\r\n float brickW = 1.0 / numberOfBricksWidth;\r\n float brickH = 1.0 / numberOfBricksHeight;\r\n float jointWPercentage = 0.01;\r\n float jointHPercentage = 0.05;\r\n vec3 color = brickColor;\r\n float yi = vUV.y / brickH;\r\n float nyi = round(yi);\r\n float xi = vUV.x / brickW;\r\n\r\n if (mod(floor(yi), 2.0) == 0.0){\r\n xi = xi - 0.5;\r\n }\r\n\r\n float nxi = round(xi);\r\n vec2 brickvUV = vec2((xi - floor(xi)) / brickH, (yi - floor(yi)) / brickW);\r\n\r\n if (yi < nyi + jointHPercentage && yi > nyi - jointHPercentage){\r\n color = mix(jointColor, vec3(0.37, 0.25, 0.25), (yi - nyi) / jointHPercentage + 0.2);\r\n }\r\n else if (xi < nxi + jointWPercentage && xi > nxi - jointWPercentage){\r\n color = mix(jointColor, vec3(0.44, 0.44, 0.44), (xi - nxi) / jointWPercentage + 0.2);\r\n }\r\n else {\r\n float brickColorSwitch = mod(floor(yi) + floor(xi), 3.0);\r\n\r\n if (brickColorSwitch == 0.0)\r\n color = mix(color, vec3(0.33, 0.33, 0.33), 0.3);\r\n else if (brickColorSwitch == 2.0)\r\n color = mix(color, vec3(0.11, 0.11, 0.11), 0.3);\r\n }\r\n\r\n gl_FragColor = vec4(color, 1.0);\r\n}",chromaticAberrationPixelShader:"// BABYLON.JS Chromatic Aberration GLSL Shader\r\n// Author: Olivier Guyot\r\n// Separates very slightly R, G and B colors on the edges of the screen\r\n// Inspired by Francois Tarlier & Martins Upitis\r\n\r\n#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// samplers\r\nuniform sampler2D textureSampler; // original color\r\n\r\n// uniforms\r\nuniform float chromatic_aberration;\r\nuniform float screen_width;\r\nuniform float screen_height;\r\n\r\n// varyings\r\nvarying vec2 vUV;\r\n\r\nvoid main(void)\r\n{\r\n vec2 centered_screen_pos = vec2(vUV.x - 0.5, vUV.y - 0.5);\r\n float radius2 = centered_screen_pos.x*centered_screen_pos.x\r\n + centered_screen_pos.y*centered_screen_pos.y;\r\n float radius = sqrt(radius2);\r\n\r\n vec4 original = texture2D(textureSampler, vUV);\r\n\r\n if (chromatic_aberration > 0.0) {\r\n //index of refraction of each color channel, causing chromatic dispersion\r\n vec3 ref_indices = vec3(-0.3, 0.0, 0.3);\r\n float ref_shiftX = chromatic_aberration * radius * 17.0 / screen_width;\r\n float ref_shiftY = chromatic_aberration * radius * 17.0 / screen_height;\r\n\r\n // shifts for red, green & blue\r\n vec2 ref_coords_r = vec2(vUV.x + ref_indices.r*ref_shiftX, vUV.y + ref_indices.r*ref_shiftY*0.5);\r\n vec2 ref_coords_g = vec2(vUV.x + ref_indices.g*ref_shiftX, vUV.y + ref_indices.g*ref_shiftY*0.5);\r\n vec2 ref_coords_b = vec2(vUV.x + ref_indices.b*ref_shiftX, vUV.y + ref_indices.b*ref_shiftY*0.5);\r\n\r\n original.r = texture2D(textureSampler, ref_coords_r).r;\r\n original.g = texture2D(textureSampler, ref_coords_g).g;\r\n original.b = texture2D(textureSampler, ref_coords_b).b;\r\n }\r\n\r\n gl_FragColor = original;\r\n}",cloudPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vUV;\r\n\r\nuniform vec3 skyColor;\r\nuniform vec3 cloudColor;\r\n\r\nfloat rand(vec2 n) {\r\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n const vec2 d = vec2(0.0, 1.0);\r\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n float total = 0.0, amplitude = 1.0;\r\n for (int i = 0; i < 4; i++) {\r\n total += noise(n) * amplitude;\r\n n += n;\r\n amplitude *= 0.5;\r\n }\r\n return total;\r\n}\r\n\r\nvoid main() {\r\n\r\n vec2 p = vUV * 12.0;\r\n vec3 c = mix(skyColor, cloudColor, fbm(p));\r\n gl_FragColor = vec4(c, 1);\r\n\r\n}",colorPixelShader:"precision highp float;\n\nuniform vec4 color;\n\nvoid main(void) {\n gl_FragColor = color;\n}",colorVertexShader:"precision highp float;\n\n// Attributes\nattribute vec3 position;\n\n// Uniforms\nuniform mat4 worldViewProjection;\n\nvoid main(void) {\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}",colorCorrectionPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// samplers\r\nuniform sampler2D textureSampler; // screen render\r\nuniform sampler2D colorTable; // color table with modified colors\r\n\r\n// varyings\r\nvarying vec2 vUV;\r\n\r\n// constants\r\nconst float SLICE_COUNT = 16.0; // how many slices in the color cube; 1 slice = 1 pixel\r\n// it means the image is 256x16 pixels\r\n\r\nvec4 sampleAs3DTexture(sampler2D texture, vec3 uv, float width) {\r\n float sliceSize = 1.0 / width; // space of 1 slice\r\n float slicePixelSize = sliceSize / width; // space of 1 pixel\r\n float sliceInnerSize = slicePixelSize * (width - 1.0); // space of width pixels\r\n float zSlice0 = min(floor(uv.z * width), width - 1.0);\r\n float zSlice1 = min(zSlice0 + 1.0, width - 1.0);\r\n float xOffset = slicePixelSize * 0.5 + uv.x * sliceInnerSize;\r\n float s0 = xOffset + (zSlice0 * sliceSize);\r\n float s1 = xOffset + (zSlice1 * sliceSize);\r\n vec4 slice0Color = texture2D(texture, vec2(s0, uv.y));\r\n vec4 slice1Color = texture2D(texture, vec2(s1, uv.y));\r\n float zOffset = mod(uv.z * width, 1.0);\r\n vec4 result = mix(slice0Color, slice1Color, zOffset);\r\n return result;\r\n}\r\n\r\nvoid main(void)\r\n{\r\n vec4 screen_color = texture2D(textureSampler, vUV);\r\n gl_FragColor = sampleAs3DTexture(colorTable, screen_color.rgb, SLICE_COUNT);\r\n\r\n}",convolutionPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\nuniform vec2 screenSize;\r\nuniform float kernel[9];\r\n\r\nvoid main(void)\r\n{\r\n vec2 onePixel = vec2(1.0, 1.0) / screenSize;\r\n vec4 colorSum =\r\n texture2D(textureSampler, vUV + onePixel * vec2(-1, -1)) * kernel[0] +\r\n texture2D(textureSampler, vUV + onePixel * vec2(0, -1)) * kernel[1] +\r\n texture2D(textureSampler, vUV + onePixel * vec2(1, -1)) * kernel[2] +\r\n texture2D(textureSampler, vUV + onePixel * vec2(-1, 0)) * kernel[3] +\r\n texture2D(textureSampler, vUV + onePixel * vec2(0, 0)) * kernel[4] +\r\n texture2D(textureSampler, vUV + onePixel * vec2(1, 0)) * kernel[5] +\r\n texture2D(textureSampler, vUV + onePixel * vec2(-1, 1)) * kernel[6] +\r\n texture2D(textureSampler, vUV + onePixel * vec2(0, 1)) * kernel[7] +\r\n texture2D(textureSampler, vUV + onePixel * vec2(1, 1)) * kernel[8];\r\n\r\n float kernelWeight =\r\n kernel[0] +\r\n kernel[1] +\r\n kernel[2] +\r\n kernel[3] +\r\n kernel[4] +\r\n kernel[5] +\r\n kernel[6] +\r\n kernel[7] +\r\n kernel[8];\r\n\r\n if (kernelWeight <= 0.0) {\r\n kernelWeight = 1.0;\r\n }\r\n\r\n gl_FragColor = vec4((colorSum / kernelWeight).rgb, 1);\r\n}",defaultPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#define MAP_EXPLICIT 0.\r\n#define MAP_SPHERICAL 1.\r\n#define MAP_PLANAR 2.\r\n#define MAP_CUBIC 3.\r\n#define MAP_PROJECTION 4.\r\n#define MAP_SKYBOX 5.\r\n\r\n// Constants\r\nuniform vec3 vEyePosition;\r\nuniform vec3 vAmbientColor;\r\nuniform vec4 vDiffuseColor;\r\nuniform vec4 vSpecularColor;\r\nuniform vec3 vEmissiveColor;\r\n\r\n// Input\r\nvarying vec3 vPositionW;\r\n\r\n#ifdef NORMAL\r\nvarying vec3 vNormalW;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n// Lights\r\n#ifdef LIGHT0\r\nuniform vec4 vLightData0;\r\nuniform vec4 vLightDiffuse0;\r\nuniform vec3 vLightSpecular0;\r\n#ifdef SHADOW0\r\nvarying vec4 vPositionFromLight0;\r\nuniform sampler2D shadowSampler0;\r\nuniform vec3 shadowsInfo0;\r\n#endif\r\n#ifdef SPOTLIGHT0\r\nuniform vec4 vLightDirection0;\r\n#endif\r\n#ifdef HEMILIGHT0\r\nuniform vec3 vLightGround0;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT1\r\nuniform vec4 vLightData1;\r\nuniform vec4 vLightDiffuse1;\r\nuniform vec3 vLightSpecular1;\r\n#ifdef SHADOW1\r\nvarying vec4 vPositionFromLight1;\r\nuniform sampler2D shadowSampler1;\r\nuniform vec3 shadowsInfo1;\r\n#endif\r\n#ifdef SPOTLIGHT1\r\nuniform vec4 vLightDirection1;\r\n#endif\r\n#ifdef HEMILIGHT1\r\nuniform vec3 vLightGround1;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT2\r\nuniform vec4 vLightData2;\r\nuniform vec4 vLightDiffuse2;\r\nuniform vec3 vLightSpecular2;\r\n#ifdef SHADOW2\r\nvarying vec4 vPositionFromLight2;\r\nuniform sampler2D shadowSampler2;\r\nuniform vec3 shadowsInfo2;\r\n#endif\r\n#ifdef SPOTLIGHT2\r\nuniform vec4 vLightDirection2;\r\n#endif\r\n#ifdef HEMILIGHT2\r\nuniform vec3 vLightGround2;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT3\r\nuniform vec4 vLightData3;\r\nuniform vec4 vLightDiffuse3;\r\nuniform vec3 vLightSpecular3;\r\n#ifdef SHADOW3\r\nvarying vec4 vPositionFromLight3;\r\nuniform sampler2D shadowSampler3;\r\nuniform vec3 shadowsInfo3;\r\n#endif\r\n#ifdef SPOTLIGHT3\r\nuniform vec4 vLightDirection3;\r\n#endif\r\n#ifdef HEMILIGHT3\r\nuniform vec3 vLightGround3;\r\n#endif\r\n#endif\r\n\r\n// Samplers\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\nuniform sampler2D diffuseSampler;\r\nuniform vec2 vDiffuseInfos;\r\n#endif\r\n\r\n#ifdef AMBIENT\r\nvarying vec2 vAmbientUV;\r\nuniform sampler2D ambientSampler;\r\nuniform vec2 vAmbientInfos;\r\n#endif\r\n\r\n#ifdef OPACITY \r\nvarying vec2 vOpacityUV;\r\nuniform sampler2D opacitySampler;\r\nuniform vec2 vOpacityInfos;\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\nvarying vec2 vEmissiveUV;\r\nuniform vec2 vEmissiveInfos;\r\nuniform sampler2D emissiveSampler;\r\n#endif\r\n\r\n#ifdef SPECULAR\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform sampler2D specularSampler;\r\n#endif\r\n\r\n// Fresnel\r\n#ifdef FRESNEL\r\nfloat computeFresnelTerm(vec3 viewDirection, vec3 worldNormal, float bias, float power)\r\n{\r\n float fresnelTerm = pow(bias + abs(dot(viewDirection, worldNormal)), power);\r\n return clamp(fresnelTerm, 0., 1.);\r\n}\r\n#endif\r\n\r\n#ifdef DIFFUSEFRESNEL\r\nuniform vec4 diffuseLeftColor;\r\nuniform vec4 diffuseRightColor;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\nuniform vec4 opacityParts;\r\n#endif\r\n\r\n#ifdef REFLECTIONFRESNEL\r\nuniform vec4 reflectionLeftColor;\r\nuniform vec4 reflectionRightColor;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\nuniform vec4 emissiveLeftColor;\r\nuniform vec4 emissiveRightColor;\r\n#endif\r\n\r\n// Reflection\r\n#ifdef REFLECTION\r\nvarying vec3 vPositionUVW;\r\nuniform samplerCube reflectionCubeSampler;\r\nuniform sampler2D reflection2DSampler;\r\nuniform vec3 vReflectionInfos;\r\nuniform mat4 reflectionMatrix;\r\nuniform mat4 view;\r\n\r\nvec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)\r\n{\r\n if (mode == MAP_SPHERICAL)\r\n {\r\n vec3 coords = vec3(view * vec4(worldNormal, 0.0));\r\n\r\n return vec3(reflectionMatrix * vec4(coords, 1.0));\r\n }\r\n else if (mode == MAP_PLANAR)\r\n {\r\n vec3 viewDir = worldPos.xyz - vEyePosition;\r\n vec3 coords = normalize(reflect(viewDir, worldNormal));\r\n\r\n return vec3(reflectionMatrix * vec4(coords, 1));\r\n }\r\n else if (mode == MAP_CUBIC)\r\n {\r\n vec3 viewDir = worldPos.xyz - vEyePosition;\r\n vec3 coords = reflect(viewDir, worldNormal);\r\n\r\n return vec3(reflectionMatrix * vec4(coords, 0));\r\n }\r\n else if (mode == MAP_PROJECTION)\r\n {\r\n return vec3(reflectionMatrix * (view * worldPos));\r\n }\r\n else if (mode == MAP_SKYBOX)\r\n {\r\n return vPositionUVW;\r\n }\r\n\r\n return vec3(0, 0, 0);\r\n}\r\n#endif\r\n\r\n// Shadows\r\n#ifdef SHADOWS\r\n\r\nfloat unpack(vec4 color)\r\n{\r\n const vec4 bit_shift = vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0);\r\n return dot(color, bit_shift);\r\n}\r\n\r\nfloat unpackHalf(vec2 color)\r\n{\r\n return color.x + (color.y / 255.0);\r\n}\r\n\r\nfloat computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness, float bias)\r\n{\r\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n depth = 0.5 * depth + vec3(0.5);\r\n vec2 uv = depth.xy;\r\n\r\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\r\n {\r\n return 1.0;\r\n }\r\n\r\n float shadow = unpack(texture2D(shadowSampler, uv)) + bias;\r\n\r\n if (depth.z > shadow)\r\n {\r\n return darkness;\r\n }\r\n return 1.;\r\n}\r\n\r\nfloat computeShadowWithPCF(vec4 vPositionFromLight, sampler2D shadowSampler, float mapSize, float bias)\r\n{\r\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n depth = 0.5 * depth + vec3(0.5);\r\n vec2 uv = depth.xy;\r\n\r\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\r\n {\r\n return 1.0;\r\n }\r\n\r\n float visibility = 1.;\r\n\r\n vec2 poissonDisk[4];\r\n poissonDisk[0] = vec2(-0.94201624, -0.39906216);\r\n poissonDisk[1] = vec2(0.94558609, -0.76890725);\r\n poissonDisk[2] = vec2(-0.094184101, -0.92938870);\r\n poissonDisk[3] = vec2(0.34495938, 0.29387760);\r\n\r\n // Poisson Sampling\r\n float biasedDepth = depth.z - bias;\r\n\r\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[0] / mapSize)) < biasedDepth) visibility -= 0.25;\r\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[1] / mapSize)) < biasedDepth) visibility -= 0.25;\r\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[2] / mapSize)) < biasedDepth) visibility -= 0.25;\r\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[3] / mapSize)) < biasedDepth) visibility -= 0.25;\r\n\r\n return visibility;\r\n}\r\n\r\n// Thanks to http://devmaster.net/\r\nfloat linstep(float low, float high, float v) {\r\n return clamp((v - low) / (high - low), 0.0, 1.0);\r\n}\r\n\r\nfloat ChebychevInequality(vec2 moments, float compare, float bias)\r\n{\r\n float p = smoothstep(compare - bias, compare, moments.x);\r\n float variance = max(moments.y - moments.x * moments.x, 0.02);\r\n float d = compare - moments.x;\r\n float p_max = linstep(0.2, 1.0, variance / (variance + d * d));\r\n\r\n return clamp(max(p, p_max), 0.0, 1.0);\r\n}\r\n\r\nfloat computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler, float bias)\r\n{\r\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n depth = 0.5 * depth + vec3(0.5);\r\n vec2 uv = depth.xy;\r\n\r\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0 || depth.z >= 1.0)\r\n {\r\n return 1.0;\r\n }\r\n\r\n vec4 texel = texture2D(shadowSampler, uv);\r\n\r\n vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));\r\n return 1.0 - ChebychevInequality(moments, depth.z, bias);\r\n}\r\n#endif\r\n\r\n// Bump\r\n#ifdef BUMP\r\n#extension GL_OES_standard_derivatives : enable\r\nvarying vec2 vBumpUV;\r\nuniform vec2 vBumpInfos;\r\nuniform sampler2D bumpSampler;\r\n\r\n// Thanks to http://www.thetenthplanet.de/archives/1180\r\nmat3 cotangent_frame(vec3 normal, vec3 p, vec2 uv)\r\n{\r\n // get edge vectors of the pixel triangle\r\n vec3 dp1 = dFdx(p);\r\n vec3 dp2 = dFdy(p);\r\n vec2 duv1 = dFdx(uv);\r\n vec2 duv2 = dFdy(uv);\r\n\r\n // solve the linear system\r\n vec3 dp2perp = cross(dp2, normal);\r\n vec3 dp1perp = cross(normal, dp1);\r\n vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x;\r\n vec3 binormal = dp2perp * duv1.y + dp1perp * duv2.y;\r\n\r\n // construct a scale-invariant frame \r\n float invmax = inversesqrt(max(dot(tangent, tangent), dot(binormal, binormal)));\r\n return mat3(tangent * invmax, binormal * invmax, normal);\r\n}\r\n\r\nvec3 perturbNormal(vec3 viewDir)\r\n{\r\n vec3 map = texture2D(bumpSampler, vBumpUV).xyz;\r\n map = map * 255. / 127. - 128. / 127.;\r\n mat3 TBN = cotangent_frame(vNormalW * vBumpInfos.y, -viewDir, vBumpUV);\r\n return normalize(TBN * map);\r\n}\r\n#endif\r\n\r\n#ifdef CLIPPLANE\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n// Fog\r\n#ifdef FOG\r\n\r\n#define FOGMODE_NONE 0.\r\n#define FOGMODE_EXP 1.\r\n#define FOGMODE_EXP2 2.\r\n#define FOGMODE_LINEAR 3.\r\n#define E 2.71828\r\n\r\nuniform vec4 vFogInfos;\r\nuniform vec3 vFogColor;\r\nvarying float fFogDistance;\r\n\r\nfloat CalcFogFactor()\r\n{\r\n float fogCoeff = 1.0;\r\n float fogStart = vFogInfos.y;\r\n float fogEnd = vFogInfos.z;\r\n float fogDensity = vFogInfos.w;\r\n\r\n if (FOGMODE_LINEAR == vFogInfos.x)\r\n {\r\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\r\n }\r\n else if (FOGMODE_EXP == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\r\n }\r\n else if (FOGMODE_EXP2 == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\r\n }\r\n\r\n return clamp(fogCoeff, 0.0, 1.0);\r\n}\r\n#endif\r\n\r\n// Light Computing\r\nstruct lightingInfo\r\n{\r\n vec3 diffuse;\r\n vec3 specular;\r\n};\r\n\r\nlightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, float range) {\r\n lightingInfo result;\r\n\r\n vec3 lightVectorW;\r\n float attenuation = 1.0;\r\n if (lightData.w == 0.)\r\n {\r\n vec3 direction = lightData.xyz - vPositionW;\r\n\r\n attenuation = max(0., 1.0 - length(direction) / range);\r\n lightVectorW = normalize(direction);\r\n }\r\n else\r\n {\r\n lightVectorW = normalize(-lightData.xyz);\r\n }\r\n\r\n // diffuse\r\n float ndl = max(0., dot(vNormal, lightVectorW));\r\n\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW + lightVectorW);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = pow(specComp, max(1., vSpecularColor.a));\r\n\r\n result.diffuse = ndl * diffuseColor * attenuation;\r\n result.specular = specComp * specularColor * attenuation;\r\n\r\n return result;\r\n}\r\n\r\nlightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 diffuseColor, vec3 specularColor, float range) {\r\n lightingInfo result;\r\n\r\n vec3 direction = lightData.xyz - vPositionW;\r\n vec3 lightVectorW = normalize(direction);\r\n float attenuation = max(0., 1.0 - length(direction) / range);\r\n\r\n // diffuse\r\n float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));\r\n float spotAtten = 0.0;\r\n\r\n if (cosAngle >= lightDirection.w)\r\n {\r\n cosAngle = max(0., pow(cosAngle, lightData.w));\r\n spotAtten = clamp((cosAngle - lightDirection.w) / (1. - cosAngle), 0.0, 1.0);\r\n\r\n // Diffuse\r\n float ndl = max(0., dot(vNormal, -lightDirection.xyz));\r\n\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = pow(specComp, vSpecularColor.a);\r\n\r\n result.diffuse = ndl * spotAtten * diffuseColor * attenuation;\r\n result.specular = specComp * specularColor * spotAtten * attenuation;\r\n\r\n return result;\r\n }\r\n\r\n result.diffuse = vec3(0.);\r\n result.specular = vec3(0.);\r\n\r\n return result;\r\n}\r\n\r\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor) {\r\n lightingInfo result;\r\n\r\n // Diffuse\r\n float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\r\n\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW + lightData.xyz);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = pow(specComp, vSpecularColor.a);\r\n\r\n result.diffuse = mix(groundColor, diffuseColor, ndl);\r\n result.specular = specComp * specularColor;\r\n\r\n return result;\r\n}\r\n\r\nvoid main(void) {\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n if (fClipDistance > 0.0)\r\n discard;\r\n#endif\r\n\r\n vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\r\n\r\n // Base color\r\n vec4 baseColor = vec4(1., 1., 1., 1.);\r\n vec3 diffuseColor = vDiffuseColor.rgb;\r\n\r\n // Alpha\r\n float alpha = vDiffuseColor.a;\r\n\r\n#ifdef VERTEXCOLOR\r\n baseColor.rgb *= vColor.rgb;\r\n#endif\r\n\r\n#ifdef DIFFUSE\r\n baseColor = texture2D(diffuseSampler, vDiffuseUV);\r\n\r\n#ifdef ALPHATEST\r\n if (baseColor.a < 0.4)\r\n discard;\r\n#endif\r\n\r\n#ifdef ALPHAFROMDIFFUSE\r\n alpha *= baseColor.a;\r\n#endif\r\n\r\n baseColor.rgb *= vDiffuseInfos.y;\r\n#endif\r\n\r\n // Bump\r\n#ifdef NORMAL\r\n vec3 normalW = normalize(vNormalW);\r\n#else\r\n vec3 normalW = vec3(1.0, 1.0, 1.0);\r\n#endif\r\n\r\n\r\n#ifdef BUMP\r\n normalW = perturbNormal(viewDirectionW);\r\n#endif\r\n\r\n\r\n // Ambient color\r\n vec3 baseAmbientColor = vec3(1., 1., 1.);\r\n\r\n#ifdef AMBIENT\r\n baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;\r\n#endif\r\n\r\n // Lighting\r\n vec3 diffuseBase = vec3(0., 0., 0.);\r\n vec3 specularBase = vec3(0., 0., 0.);\r\n float shadow = 1.;\r\n\r\n#ifdef LIGHT0\r\n#ifdef SPOTLIGHT0\r\n lightingInfo info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a);\r\n#endif\r\n#ifdef HEMILIGHT0\r\n lightingInfo info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightGround0);\r\n#endif\r\n#ifdef POINTDIRLIGHT0\r\n lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a);\r\n#endif\r\n#ifdef SHADOW0\r\n#ifdef SHADOWVSM0\r\n shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0, shadowsInfo0.z);\r\n#else\r\n #ifdef SHADOWPCF0\r\n shadow = computeShadowWithPCF(vPositionFromLight0, shadowSampler0, shadowsInfo0.y, shadowsInfo0.z);\r\n #else\r\n shadow = computeShadow(vPositionFromLight0, shadowSampler0, shadowsInfo0.x, shadowsInfo0.z);\r\n #endif\r\n#endif\r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info.diffuse * shadow;\r\n specularBase += info.specular * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT1\r\n#ifdef SPOTLIGHT1\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a);\r\n#endif\r\n#ifdef HEMILIGHT1\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightGround1);\r\n#endif\r\n#ifdef POINTDIRLIGHT1\r\n info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a);\r\n#endif\r\n#ifdef SHADOW1\r\n#ifdef SHADOWVSM1\r\n shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1, shadowsInfo1.z);\r\n#else\r\n #ifdef SHADOWPCF1\r\n shadow = computeShadowWithPCF(vPositionFromLight1, shadowSampler1, shadowsInfo1.y, shadowsInfo1.z);\r\n #else\r\n shadow = computeShadow(vPositionFromLight1, shadowSampler1, shadowsInfo1.x, shadowsInfo1.z);\r\n #endif\r\n#endif\r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info.diffuse * shadow;\r\n specularBase += info.specular * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT2\r\n#ifdef SPOTLIGHT2\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a);\r\n#endif\r\n#ifdef HEMILIGHT2\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightGround2);\r\n#endif\r\n#ifdef POINTDIRLIGHT2\r\n info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a);\r\n#endif\r\n#ifdef SHADOW2\r\n#ifdef SHADOWVSM2\r\n shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2, shadowsInfo2.z);\r\n#else\r\n #ifdef SHADOWPCF2\r\n shadow = computeShadowWithPCF(vPositionFromLight2, shadowSampler2, shadowsInfo2.y, shadowsInfo2.z);\r\n #else\r\n shadow = computeShadow(vPositionFromLight2, shadowSampler2, shadowsInfo2.x, shadowsInfo2.z);\r\n #endif \r\n#endif \r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info.diffuse * shadow;\r\n specularBase += info.specular * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT3\r\n#ifdef SPOTLIGHT3\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a);\r\n#endif\r\n#ifdef HEMILIGHT3\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightGround3);\r\n#endif\r\n#ifdef POINTDIRLIGHT3\r\n info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a);\r\n#endif\r\n#ifdef SHADOW3\r\n#ifdef SHADOWVSM3\r\n shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3, shadowsInfo3.z);\r\n#else\r\n #ifdef SHADOWPCF3\r\n shadow = computeShadowWithPCF(vPositionFromLight3, shadowSampler3, shadowsInfo3.y, shadowsInfo3.z);\r\n #else\r\n shadow = computeShadow(vPositionFromLight3, shadowSampler3, shadowsInfo3.x, shadowsInfo3.z);\r\n #endif \r\n#endif \r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info.diffuse * shadow;\r\n specularBase += info.specular * shadow;\r\n#endif\r\n\r\n // Reflection\r\n vec3 reflectionColor = vec3(0., 0., 0.);\r\n\r\n#ifdef REFLECTION\r\n vec3 vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), normalW);\r\n\r\n if (vReflectionInfos.z != 0.0)\r\n {\r\n reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.y * shadow;\r\n }\r\n else\r\n {\r\n vec2 coords = vReflectionUVW.xy;\r\n\r\n if (vReflectionInfos.x == MAP_PROJECTION)\r\n {\r\n coords /= vReflectionUVW.z;\r\n }\r\n\r\n coords.y = 1.0 - coords.y;\r\n\r\n reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.y * shadow;\r\n }\r\n\r\n#ifdef REFLECTIONFRESNEL\r\n float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);\r\n\r\n reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\r\n#endif\r\n#endif\r\n\r\n#ifdef OPACITY\r\n vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);\r\n\r\n#ifdef OPACITYRGB\r\n opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);\r\n alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;\r\n#else\r\n alpha *= opacityMap.a * vOpacityInfos.y;\r\n#endif\r\n\r\n#endif\r\n\r\n#ifdef VERTEXALPHA\r\n alpha *= vColor.a;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\n float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);\r\n\r\n alpha += opacityParts.x * (1.0 - opacityFresnelTerm) + opacityFresnelTerm * opacityParts.y;\r\n#endif\r\n\r\n // Emissive\r\n vec3 emissiveColor = vEmissiveColor;\r\n#ifdef EMISSIVE\r\n emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\n float emissiveFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, emissiveRightColor.a, emissiveLeftColor.a);\r\n\r\n emissiveColor *= emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * emissiveRightColor.rgb;\r\n#endif\r\n\r\n // Specular map\r\n vec3 specularColor = vSpecularColor.rgb;\r\n#ifdef SPECULAR\r\n specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;\r\n#endif\r\n\r\n // Fresnel\r\n#ifdef DIFFUSEFRESNEL\r\n float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, diffuseRightColor.a, diffuseLeftColor.a);\r\n\r\n diffuseBase *= diffuseLeftColor.rgb * (1.0 - diffuseFresnelTerm) + diffuseFresnelTerm * diffuseRightColor.rgb;\r\n#endif\r\n\r\n // Composition\r\n vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\r\n vec3 finalSpecular = specularBase * specularColor;\r\n\r\n#ifdef SPECULAROVERALPHA\r\n alpha = clamp(alpha + dot(finalSpecular, vec3(0.3, 0.59, 0.11)), 0., 1.);\r\n#endif\r\n\r\n vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\r\n\r\n#ifdef FOG\r\n float fog = CalcFogFactor();\r\n color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\r\n#endif\r\n\r\n gl_FragColor = color;\r\n}", defaultVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec3 position;\r\n#ifdef NORMAL\r\nattribute vec3 normal;\r\n#endif\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#ifdef VERTEXCOLOR\r\nattribute vec4 color;\r\n#endif\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniforms\r\n\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 view;\r\nuniform mat4 viewProjection;\r\n\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\nuniform mat4 diffuseMatrix;\r\nuniform vec2 vDiffuseInfos;\r\n#endif\r\n\r\n#ifdef AMBIENT\r\nvarying vec2 vAmbientUV;\r\nuniform mat4 ambientMatrix;\r\nuniform vec2 vAmbientInfos;\r\n#endif\r\n\r\n#ifdef OPACITY\r\nvarying vec2 vOpacityUV;\r\nuniform mat4 opacityMatrix;\r\nuniform vec2 vOpacityInfos;\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\nvarying vec2 vEmissiveUV;\r\nuniform vec2 vEmissiveInfos;\r\nuniform mat4 emissiveMatrix;\r\n#endif\r\n\r\n#ifdef SPECULAR\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform mat4 specularMatrix;\r\n#endif\r\n\r\n#ifdef BUMP\r\nvarying vec2 vBumpUV;\r\nuniform vec2 vBumpInfos;\r\nuniform mat4 bumpMatrix;\r\n#endif\r\n\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n#ifdef POINTSIZE\r\nuniform float pointSize;\r\n#endif\r\n\r\n// Output\r\nvarying vec3 vPositionW;\r\n#ifdef NORMAL\r\nvarying vec3 vNormalW;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n#ifdef CLIPPLANE\r\nuniform vec4 vClipPlane;\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n#ifdef FOG\r\nvarying float fFogDistance;\r\n#endif\r\n\r\n#ifdef SHADOWS\r\n#ifdef LIGHT0\r\nuniform mat4 lightMatrix0;\r\nvarying vec4 vPositionFromLight0;\r\n#endif\r\n#ifdef LIGHT1\r\nuniform mat4 lightMatrix1;\r\nvarying vec4 vPositionFromLight1;\r\n#endif\r\n#ifdef LIGHT2\r\nuniform mat4 lightMatrix2;\r\nvarying vec4 vPositionFromLight2;\r\n#endif\r\n#ifdef LIGHT3\r\nuniform mat4 lightMatrix3;\r\nvarying vec4 vPositionFromLight3;\r\n#endif\r\n#endif\r\n\r\n#ifdef REFLECTION\r\nvarying vec3 vPositionUVW;\r\n#endif\r\n\r\nvoid main(void) {\r\n mat4 finalWorld;\r\n\r\n#ifdef REFLECTION\r\n vPositionUVW = position;\r\n#endif \r\n\r\n#ifdef INSTANCES\r\n finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n finalWorld = world;\r\n#endif\r\n\r\n#ifdef BONES\r\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n\r\n#ifdef BONES4\r\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n#else\r\n finalWorld = finalWorld * (m0 + m1 + m2);\r\n#endif \r\n\r\n#endif\r\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\r\n\r\n vec4 worldPos = finalWorld * vec4(position, 1.0);\r\n vPositionW = vec3(worldPos);\r\n\r\n#ifdef NORMAL\r\n vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\r\n#endif\r\n\r\n // Texture coordinates\r\n#ifndef UV1\r\n vec2 uv = vec2(0., 0.);\r\n#endif\r\n#ifndef UV2\r\n vec2 uv2 = vec2(0., 0.);\r\n#endif\r\n\r\n#ifdef DIFFUSE\r\n if (vDiffuseInfos.x == 0.)\r\n {\r\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef AMBIENT\r\n if (vAmbientInfos.x == 0.)\r\n {\r\n vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef OPACITY\r\n if (vOpacityInfos.x == 0.)\r\n {\r\n vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\n if (vEmissiveInfos.x == 0.)\r\n {\r\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef SPECULAR\r\n if (vSpecularInfos.x == 0.)\r\n {\r\n vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef BUMP\r\n if (vBumpInfos.x == 0.)\r\n {\r\n vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n fClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n\r\n // Fog\r\n#ifdef FOG\r\n fFogDistance = (view * worldPos).z;\r\n#endif\r\n\r\n // Shadows\r\n#ifdef SHADOWS\r\n#ifdef LIGHT0\r\n vPositionFromLight0 = lightMatrix0 * worldPos;\r\n#endif\r\n#ifdef LIGHT1\r\n vPositionFromLight1 = lightMatrix1 * worldPos;\r\n#endif\r\n#ifdef LIGHT2\r\n vPositionFromLight2 = lightMatrix2 * worldPos;\r\n#endif\r\n#ifdef LIGHT3\r\n vPositionFromLight3 = lightMatrix3 * worldPos;\r\n#endif\r\n#endif\r\n\r\n // Vertex color\r\n#ifdef VERTEXCOLOR\r\n vColor = color;\r\n#endif\r\n\r\n // Point size\r\n#ifdef POINTSIZE\r\n gl_PointSize = pointSize;\r\n#endif\r\n}",depthPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform sampler2D diffuseSampler;\r\n#endif\r\n\r\nuniform float far;\r\n\r\nvoid main(void)\r\n{\r\n#ifdef ALPHATEST\r\n if (texture2D(diffuseSampler, vUV).a < 0.4)\r\n discard;\r\n#endif\r\n\r\n float depth = (gl_FragCoord.z / gl_FragCoord.w) / far;\r\n gl_FragColor = vec4(depth, depth * depth, 0.0, 1.0);\r\n}",depthVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attribute\r\nattribute vec3 position;\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniform\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 viewProjection;\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n#if defined(ALPHATEST) || defined(NEED_UV)\r\nvarying vec2 vUV;\r\nuniform mat4 diffuseMatrix;\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#ifdef INSTANCES\r\n mat4 finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n mat4 finalWorld = world;\r\n#endif\r\n\r\n#ifdef BONES\r\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\r\n#else\r\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\r\n#endif\r\n\r\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\r\n#ifdef UV1\r\n vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n#endif\r\n#ifdef UV2\r\n vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n#endif\r\n#endif\r\n}",depthBoxBlurPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\n// Parameters\r\nuniform vec2 screenSize;\r\n\r\nvoid main(void)\r\n{\r\n vec4 colorDepth = vec4(0.0);\r\n\r\n for (int x = -OFFSET; x <= OFFSET; x++)\r\n for (int y = -OFFSET; y <= OFFSET; y++)\r\n colorDepth += texture2D(textureSampler, vUV + vec2(x, y) / screenSize);\r\n\r\n gl_FragColor = (colorDepth / float((OFFSET * 2 + 1) * (OFFSET * 2 + 1)));\r\n}",depthOfFieldPixelShader:"// BABYLON.JS Depth-of-field GLSL Shader\r\n// Author: Olivier Guyot\r\n// Does depth-of-field blur, edge blur\r\n// Inspired by Francois Tarlier & Martins Upitis\r\n\r\n#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n\r\n// samplers\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D highlightsSampler;\r\nuniform sampler2D depthSampler;\r\nuniform sampler2D grainSampler;\r\n\r\n// uniforms\r\nuniform float grain_amount;\r\nuniform float maxZ;\r\nuniform bool blur_noise;\r\nuniform float screen_width;\r\nuniform float screen_height;\r\nuniform float distortion;\r\nuniform float focus_depth;\r\nuniform float aperture;\r\nuniform float edge_blur;\r\nuniform bool highlights;\r\n\r\n// varyings\r\nvarying vec2 vUV;\r\n\r\n// constants\r\n#define PI 3.14159265\r\n\r\n// common calculations\r\nvec2 centered_screen_pos;\r\nfloat radius2;\r\nfloat radius;\r\n\r\n\r\n// applies edge distortion on texture coords\r\nvec2 getDistortedCoords(vec2 coords) {\r\n\r\n if (distortion == 0.0) { return coords; }\r\n\r\n vec2 direction = 1.0 * normalize(centered_screen_pos);\r\n vec2 dist_coords = vec2(0.5, 0.5);\r\n dist_coords.x = 0.5 + direction.x * radius2 * 1.0;\r\n dist_coords.y = 0.5 + direction.y * radius2 * 1.0;\r\n float dist_amount = clamp(distortion*0.23, 0.0, 1.0);\r\n\r\n dist_coords = mix(coords, dist_coords, dist_amount);\r\n\r\n return dist_coords;\r\n}\r\n\r\n// returns original screen color after blur\r\nvec4 getBlurColor(vec2 coords, float size) {\r\n\r\n vec4 col = texture2D(textureSampler, coords);\r\n if (size == 0.0) { return col; }\r\n\r\n // there are max. 30 samples; the number of samples chosen is dependant on the blur size\r\n // there can be 10, 20 or 30 samples chosen; levels of blur are then 1, 2 or 3\r\n float blur_level = min(3.0, ceil(size / 1.0));\r\n\r\n float w = (size / screen_width);\r\n float h = (size / screen_height);\r\n float total_weight = 1.0;\r\n\r\n col += texture2D(textureSampler, coords + vec2(-0.53*w, 0.15*h))*0.93;\r\n col += texture2D(textureSampler, coords + vec2(0.42*w, -0.69*h))*0.90;\r\n col += texture2D(textureSampler, coords + vec2(0.20*w, 1.00*h))*0.87;\r\n col += texture2D(textureSampler, coords + vec2(-0.97*w, -0.72*h))*0.85;\r\n col += texture2D(textureSampler, coords + vec2(1.37*w, -0.14*h))*0.83;\r\n col += texture2D(textureSampler, coords + vec2(-1.02*w, 1.16*h))*0.80;\r\n col += texture2D(textureSampler, coords + vec2(-0.03*w, -1.69*h))*0.78;\r\n col += texture2D(textureSampler, coords + vec2(1.27*w, 1.34*h))*0.76;\r\n col += texture2D(textureSampler, coords + vec2(-1.98*w, -0.14*h))*0.74;\r\n col += texture2D(textureSampler, coords + vec2(1.66*w, -1.32*h))*0.72;\r\n total_weight += 8.18;\r\n\r\n if (blur_level > 1.0) {\r\n col += texture2D(textureSampler, coords + vec2(-0.35*w, 2.22*h))*0.70;\r\n col += texture2D(textureSampler, coords + vec2(-1.31*w, -1.98*h))*0.67;\r\n col += texture2D(textureSampler, coords + vec2(2.42*w, 0.61*h))*0.65;\r\n col += texture2D(textureSampler, coords + vec2(-2.31*w, 1.25*h))*0.63;\r\n col += texture2D(textureSampler, coords + vec2(0.90*w, -2.59*h))*0.61;\r\n col += texture2D(textureSampler, coords + vec2(1.14*w, 2.62*h))*0.59;\r\n col += texture2D(textureSampler, coords + vec2(-2.72*w, -1.21*h))*0.56;\r\n col += texture2D(textureSampler, coords + vec2(2.93*w, -0.98*h))*0.54;\r\n col += texture2D(textureSampler, coords + vec2(-1.56*w, 2.80*h))*0.52;\r\n col += texture2D(textureSampler, coords + vec2(-0.77*w, -3.22*h))*0.49;\r\n total_weight += 5.96;\r\n }\r\n\r\n if (blur_level > 2.0) {\r\n col += texture2D(textureSampler, coords + vec2(2.83*w, 1.92*h))*0.46;\r\n col += texture2D(textureSampler, coords + vec2(-3.49*w, 0.51*h))*0.44;\r\n col += texture2D(textureSampler, coords + vec2(2.30*w, -2.82*h))*0.41;\r\n col += texture2D(textureSampler, coords + vec2(0.22*w, 3.74*h))*0.38;\r\n col += texture2D(textureSampler, coords + vec2(-2.76*w, -2.68*h))*0.34;\r\n col += texture2D(textureSampler, coords + vec2(3.95*w, 0.11*h))*0.31;\r\n col += texture2D(textureSampler, coords + vec2(-3.07*w, 2.65*h))*0.26;\r\n col += texture2D(textureSampler, coords + vec2(0.48*w, -4.13*h))*0.22;\r\n col += texture2D(textureSampler, coords + vec2(2.49*w, 3.46*h))*0.15;\r\n total_weight += 2.97;\r\n }\r\n\r\n col /= total_weight; // scales color according to weights\r\n col.a = 1.0;\r\n\r\n // blur levels debug\r\n // if(blur_level == 1.0) { col.b = 0.0; }\r\n // if(blur_level == 2.0) { col.r = 0.0; }\r\n // if(blur_level == 3.0) { col.g = 0.0; }\r\n\r\n return col;\r\n}\r\n\r\n// on-the-fly constant noise\r\nvec2 rand(vec2 co)\r\n{\r\n float noise1 = (fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453));\r\n float noise2 = (fract(sin(dot(co, vec2(12.9898, 78.233)*2.0)) * 43758.5453));\r\n return clamp(vec2(noise1, noise2), 0.0, 1.0);\r\n}\r\n\r\nvoid main(void)\r\n{\r\n\r\n // Common calc\r\n centered_screen_pos = vec2(vUV.x - 0.5, vUV.y - 0.5);\r\n radius2 = centered_screen_pos.x*centered_screen_pos.x + centered_screen_pos.y*centered_screen_pos.y;\r\n radius = sqrt(radius2);\r\n\r\n vec4 final_color;\r\n vec2 distorted_coords = getDistortedCoords(vUV);\r\n vec2 texels_coords = vec2(vUV.x * screen_width, vUV.y * screen_height); // varies from 0 to SCREEN_WIDTH or _HEIGHT\r\n\r\n // blur from depth of field effect\r\n float dof_blur_amount = 0.0;\r\n float depth_bias = 0.0; // positive if the pixel is further than focus depth; negative if closer\r\n if (focus_depth != -1.0) {\r\n vec4 depth_sample = texture2D(depthSampler, distorted_coords);\r\n float depth = depth_sample.r;\r\n depth_bias = depth - focus_depth;\r\n\r\n // compute blur amount with distance\r\n if (depth_bias > 0.0) { dof_blur_amount = depth_bias * aperture * 2.2; }\r\n else { dof_blur_amount = depth_bias * depth_bias * aperture * 30.0; }\r\n\r\n if (dof_blur_amount < 0.05) { dof_blur_amount = 0.0; } // no blur at all\r\n }\r\n\r\n // blur from edge blur effect\r\n float edge_blur_amount = 0.0;\r\n if (edge_blur > 0.0) {\r\n edge_blur_amount = clamp((radius*2.0 - 1.0 + 0.15*edge_blur) * 1.5, 0.0, 1.0) * 1.3;\r\n }\r\n\r\n // total blur amount\r\n float blur_amount = max(edge_blur_amount, dof_blur_amount);\r\n\r\n // apply blur if necessary\r\n if (blur_amount == 0.0) {\r\n gl_FragColor = texture2D(textureSampler, distorted_coords);\r\n }\r\n else {\r\n\r\n // add blurred color\r\n gl_FragColor = getBlurColor(distorted_coords, blur_amount * 1.7);\r\n\r\n // if further than focus depth & we have computed highlights: enhance highlights\r\n if (depth_bias > 0.0 && highlights) {\r\n gl_FragColor += clamp(dof_blur_amount, 0.0, 1.0)*texture2D(highlightsSampler, distorted_coords);\r\n }\r\n\r\n if (blur_noise) {\r\n // we put a slight amount of noise in the blurred color\r\n vec2 noise = rand(distorted_coords) * 0.01 * blur_amount;\r\n vec2 blurred_coord = vec2(distorted_coords.x + noise.x, distorted_coords.y + noise.y);\r\n gl_FragColor = 0.04 * texture2D(textureSampler, blurred_coord) + 0.96 * gl_FragColor;\r\n }\r\n }\r\n\r\n // apply grain\r\n if (grain_amount > 0.0) {\r\n vec4 grain_color = texture2D(grainSampler, texels_coords*0.003);\r\n gl_FragColor.rgb += (-0.5 + grain_color.rgb) * 0.20;\r\n }\r\n}",displayPassPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D passSampler;\r\n\r\nvoid main(void)\r\n{\r\n gl_FragColor = texture2D(passSampler, vUV);\r\n}",filterPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\nuniform mat4 kernelMatrix;\r\n\r\nvoid main(void)\r\n{\r\n vec3 baseColor = texture2D(textureSampler, vUV).rgb;\r\n vec3 updatedColor = (kernelMatrix * vec4(baseColor, 1.0)).rgb;\r\n\r\n gl_FragColor = vec4(updatedColor, 1.0);\r\n}",firePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nuniform float time;\r\nuniform vec3 c1;\r\nuniform vec3 c2;\r\nuniform vec3 c3;\r\nuniform vec3 c4;\r\nuniform vec3 c5;\r\nuniform vec3 c6;\r\nuniform vec2 speed;\r\nuniform float shift;\r\nuniform float alphaThreshold;\r\n\r\nvarying vec2 vUV;\r\n\r\nfloat rand(vec2 n) {\r\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n const vec2 d = vec2(0.0, 1.0);\r\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n float total = 0.0, amplitude = 1.0;\r\n for (int i = 0; i < 4; i++) {\r\n total += noise(n) * amplitude;\r\n n += n;\r\n amplitude *= 0.5;\r\n }\r\n return total;\r\n}\r\n\r\nvoid main() {\r\n vec2 p = vUV * 8.0;\r\n float q = fbm(p - time * 0.1);\r\n vec2 r = vec2(fbm(p + q + time * speed.x - p.x - p.y), fbm(p + q - time * speed.y));\r\n vec3 c = mix(c1, c2, fbm(p + r)) + mix(c3, c4, r.x) - mix(c5, c6, r.y);\r\n vec3 color = c * cos(shift * vUV.y);\r\n float luminance = dot(color.rgb, vec3(0.3, 0.59, 0.11));\r\n\r\n gl_FragColor = vec4(color, luminance * alphaThreshold + (1.0 - alphaThreshold));\r\n}",fxaaPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#define FXAA_REDUCE_MIN (1.0/128.0)\r\n#define FXAA_REDUCE_MUL (1.0/8.0)\r\n#define FXAA_SPAN_MAX 8.0\r\n\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform vec2 texelSize;\r\n\r\nvoid main(){\r\n vec2 localTexelSize = texelSize;\r\n vec4 rgbNW = texture2D(textureSampler, (vUV + vec2(-1.0, -1.0) * localTexelSize));\r\n vec4 rgbNE = texture2D(textureSampler, (vUV + vec2(1.0, -1.0) * localTexelSize));\r\n vec4 rgbSW = texture2D(textureSampler, (vUV + vec2(-1.0, 1.0) * localTexelSize));\r\n vec4 rgbSE = texture2D(textureSampler, (vUV + vec2(1.0, 1.0) * localTexelSize));\r\n vec4 rgbM = texture2D(textureSampler, vUV);\r\n vec4 luma = vec4(0.299, 0.587, 0.114, 1.0);\r\n float lumaNW = dot(rgbNW, luma);\r\n float lumaNE = dot(rgbNE, luma);\r\n float lumaSW = dot(rgbSW, luma);\r\n float lumaSE = dot(rgbSE, luma);\r\n float lumaM = dot(rgbM, luma);\r\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\r\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\r\n\r\n vec2 dir = vec2(-((lumaNW + lumaNE) - (lumaSW + lumaSE)), ((lumaNW + lumaSW) - (lumaNE + lumaSE)));\r\n\r\n float dirReduce = max(\r\n (lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),\r\n FXAA_REDUCE_MIN);\r\n\r\n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\r\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\r\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\r\n dir * rcpDirMin)) * localTexelSize;\r\n\r\n vec4 rgbA = 0.5 * (\r\n texture2D(textureSampler, vUV + dir * (1.0 / 3.0 - 0.5)) +\r\n texture2D(textureSampler, vUV + dir * (2.0 / 3.0 - 0.5)));\r\n\r\n vec4 rgbB = rgbA * 0.5 + 0.25 * (\r\n texture2D(textureSampler, vUV + dir * -0.5) +\r\n texture2D(textureSampler, vUV + dir * 0.5));\r\n float lumaB = dot(rgbB, luma);\r\n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\r\n gl_FragColor = rgbA;\r\n }\r\n else {\r\n gl_FragColor = rgbB;\r\n }\r\n}",grassPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nuniform vec3 herb1Color;\r\nuniform vec3 herb2Color;\r\nuniform vec3 herb3Color;\r\nuniform vec3 groundColor;\r\n\r\nfloat rand(vec2 n) {\r\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n const vec2 d = vec2(0.0, 1.0);\r\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n float total = 0.0, amplitude = 1.0;\r\n for (int i = 0; i < 4; i++) {\r\n total += noise(n) * amplitude;\r\n n += n;\r\n amplitude *= 0.5;\r\n }\r\n return total;\r\n}\r\n\r\nvoid main(void) {\r\n vec3 color = mix(groundColor, herb1Color, rand(gl_FragCoord.xy * 4.0));\r\n color = mix(color, herb2Color, rand(gl_FragCoord.xy * 8.0));\r\n color = mix(color, herb3Color, rand(gl_FragCoord.xy));\r\n color = mix(color, herb1Color, fbm(gl_FragCoord.xy * 16.0));\r\n gl_FragColor = vec4(color, 1.0);\r\n}",layerPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\n// Color\r\nuniform vec4 color;\r\n\r\nvoid main(void) {\r\n vec4 baseColor = texture2D(textureSampler, vUV);\r\n\r\n gl_FragColor = baseColor * color;\r\n}",layerVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec2 position;\r\n\r\n// Uniforms\r\nuniform mat4 textureMatrix;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\n\r\nconst vec2 madd = vec2(0.5, 0.5);\r\n\r\nvoid main(void) { \r\n\r\n vUV = vec2(textureMatrix * vec4(position * madd + madd, 1.0, 0.0));\r\n gl_Position = vec4(position, 0.0, 1.0);\r\n}",legacydefaultPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#define MAP_PROJECTION 4.\r\n\r\n// Constants\r\nuniform vec3 vEyePosition;\r\nuniform vec3 vAmbientColor;\r\nuniform vec4 vDiffuseColor;\r\nuniform vec4 vSpecularColor;\r\nuniform vec3 vEmissiveColor;\r\n\r\n// Input\r\nvarying vec3 vPositionW;\r\nvarying vec3 vNormalW;\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n// Lights\r\n#ifdef LIGHT0\r\nuniform vec4 vLightData0;\r\nuniform vec4 vLightDiffuse0;\r\nuniform vec3 vLightSpecular0;\r\n#ifdef SHADOW0\r\nvarying vec4 vPositionFromLight0;\r\nuniform sampler2D shadowSampler0;\r\n#endif\r\n#ifdef SPOTLIGHT0\r\nuniform vec4 vLightDirection0;\r\n#endif\r\n#ifdef HEMILIGHT0\r\nuniform vec3 vLightGround0;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT1\r\nuniform vec4 vLightData1;\r\nuniform vec4 vLightDiffuse1;\r\nuniform vec3 vLightSpecular1;\r\n#ifdef SHADOW1\r\nvarying vec4 vPositionFromLight1;\r\nuniform sampler2D shadowSampler1;\r\n#endif\r\n#ifdef SPOTLIGHT1\r\nuniform vec4 vLightDirection1;\r\n#endif\r\n#ifdef HEMILIGHT1\r\nuniform vec3 vLightGround1;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT2\r\nuniform vec4 vLightData2;\r\nuniform vec4 vLightDiffuse2;\r\nuniform vec3 vLightSpecular2;\r\n#ifdef SHADOW2\r\nvarying vec4 vPositionFromLight2;\r\nuniform sampler2D shadowSampler2;\r\n#endif\r\n#ifdef SPOTLIGHT2\r\nuniform vec4 vLightDirection2;\r\n#endif\r\n#ifdef HEMILIGHT2\r\nuniform vec3 vLightGround2;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT3\r\nuniform vec4 vLightData3;\r\nuniform vec4 vLightDiffuse3;\r\nuniform vec3 vLightSpecular3;\r\n#ifdef SHADOW3\r\nvarying vec4 vPositionFromLight3;\r\nuniform sampler2D shadowSampler3;\r\n#endif\r\n#ifdef SPOTLIGHT3\r\nuniform vec4 vLightDirection3;\r\n#endif\r\n#ifdef HEMILIGHT3\r\nuniform vec3 vLightGround3;\r\n#endif\r\n#endif\r\n\r\n// Samplers\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\nuniform sampler2D diffuseSampler;\r\nuniform vec2 vDiffuseInfos;\r\n#endif\r\n\r\n#ifdef AMBIENT\r\nvarying vec2 vAmbientUV;\r\nuniform sampler2D ambientSampler;\r\nuniform vec2 vAmbientInfos;\r\n#endif\r\n\r\n#ifdef OPACITY \r\nvarying vec2 vOpacityUV;\r\nuniform sampler2D opacitySampler;\r\nuniform vec2 vOpacityInfos;\r\n#endif\r\n\r\n#ifdef REFLECTION\r\nvarying vec3 vReflectionUVW;\r\nuniform samplerCube reflectionCubeSampler;\r\nuniform sampler2D reflection2DSampler;\r\nuniform vec3 vReflectionInfos;\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\nvarying vec2 vEmissiveUV;\r\nuniform vec2 vEmissiveInfos;\r\nuniform sampler2D emissiveSampler;\r\n#endif\r\n\r\n#ifdef SPECULAR\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform sampler2D specularSampler;\r\n#endif\r\n\r\n// Fresnel\r\n#ifdef FRESNEL\r\nfloat computeFresnelTerm(vec3 viewDirection, vec3 worldNormal, float bias, float power)\r\n{\r\n float fresnelTerm = pow(bias + abs(dot(viewDirection, worldNormal)), power);\r\n return clamp(fresnelTerm, 0., 1.);\r\n}\r\n#endif\r\n\r\n#ifdef DIFFUSEFRESNEL\r\nuniform vec4 diffuseLeftColor;\r\nuniform vec4 diffuseRightColor;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\nuniform vec4 opacityParts;\r\n#endif\r\n\r\n#ifdef REFLECTIONFRESNEL\r\nuniform vec4 reflectionLeftColor;\r\nuniform vec4 reflectionRightColor;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\nuniform vec4 emissiveLeftColor;\r\nuniform vec4 emissiveRightColor;\r\n#endif\r\n\r\n// Shadows\r\n#ifdef SHADOWS\r\n\r\nfloat unpack(vec4 color)\r\n{\r\n const vec4 bitShift = vec4(1. / (255. * 255. * 255.), 1. / (255. * 255.), 1. / 255., 1.);\r\n return dot(color, bitShift);\r\n}\r\n\r\nfloat unpackHalf(vec2 color)\r\n{\r\n return color.x + (color.y / 255.0);\r\n}\r\n\r\nfloat computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler)\r\n{\r\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);\r\n\r\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\r\n {\r\n return 1.0;\r\n }\r\n\r\n float shadow = unpack(texture2D(shadowSampler, uv));\r\n\r\n if (depth.z > shadow)\r\n {\r\n return 0.;\r\n }\r\n return 1.;\r\n}\r\n\r\n// Thanks to http://devmaster.net/\r\nfloat ChebychevInequality(vec2 moments, float t)\r\n{\r\n if (t <= moments.x)\r\n {\r\n return 1.0;\r\n }\r\n\r\n float variance = moments.y - (moments.x * moments.x);\r\n variance = max(variance, 0.);\r\n\r\n float d = t - moments.x;\r\n return variance / (variance + d * d);\r\n}\r\n\r\nfloat computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler)\r\n{\r\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);\r\n\r\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\r\n {\r\n return 1.0;\r\n }\r\n\r\n vec4 texel = texture2D(shadowSampler, uv);\r\n\r\n vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));\r\n return clamp(1.3 - ChebychevInequality(moments, depth.z), 0., 1.0);\r\n}\r\n#endif\r\n\r\n#ifdef CLIPPLANE\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n// Fog\r\n#ifdef FOG\r\n\r\n#define FOGMODE_NONE 0.\r\n#define FOGMODE_EXP 1.\r\n#define FOGMODE_EXP2 2.\r\n#define FOGMODE_LINEAR 3.\r\n#define E 2.71828\r\n\r\nuniform vec4 vFogInfos;\r\nuniform vec3 vFogColor;\r\nvarying float fFogDistance;\r\n\r\nfloat CalcFogFactor()\r\n{\r\n float fogCoeff = 1.0;\r\n float fogStart = vFogInfos.y;\r\n float fogEnd = vFogInfos.z;\r\n float fogDensity = vFogInfos.w;\r\n\r\n if (FOGMODE_LINEAR == vFogInfos.x)\r\n {\r\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\r\n }\r\n else if (FOGMODE_EXP == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\r\n }\r\n else if (FOGMODE_EXP2 == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\r\n }\r\n\r\n return clamp(fogCoeff, 0.0, 1.0);\r\n}\r\n#endif\r\n\r\n// Light Computing\r\nmat3 computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 diffuseColor, vec3 specularColor) {\r\n mat3 result;\r\n\r\n vec3 lightVectorW;\r\n if (lightData.w == 0.)\r\n {\r\n lightVectorW = normalize(lightData.xyz - vPositionW);\r\n }\r\n else\r\n {\r\n lightVectorW = normalize(-lightData.xyz);\r\n }\r\n\r\n // diffuse\r\n float ndl = max(0., dot(vNormal, lightVectorW));\r\n\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW + lightVectorW);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = max(0., pow(specComp, max(1.0, vSpecularColor.a)));\r\n\r\n result[0] = ndl * diffuseColor.rgb;\r\n result[1] = specComp * specularColor;\r\n result[2] = vec3(0.);\r\n\r\n return result;\r\n}\r\n\r\nmat3 computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec4 diffuseColor, vec3 specularColor) {\r\n mat3 result;\r\n\r\n vec3 lightVectorW = normalize(lightData.xyz - vPositionW);\r\n\r\n // diffuse\r\n float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));\r\n float spotAtten = 0.0;\r\n\r\n if (cosAngle >= lightDirection.w)\r\n {\r\n cosAngle = max(0., pow(cosAngle, lightData.w));\r\n spotAtten = max(0., (cosAngle - lightDirection.w) / (1. - cosAngle));\r\n\r\n // Diffuse\r\n float ndl = max(0., dot(vNormal, -lightDirection.xyz));\r\n\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = pow(specComp, vSpecularColor.a);\r\n\r\n result[0] = ndl * spotAtten * diffuseColor.rgb;\r\n result[1] = specComp * specularColor * spotAtten;\r\n result[2] = vec3(0.);\r\n\r\n return result;\r\n }\r\n\r\n result[0] = vec3(0.);\r\n result[1] = vec3(0.);\r\n result[2] = vec3(0.);\r\n\r\n return result;\r\n}\r\n\r\nmat3 computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 diffuseColor, vec3 specularColor, vec3 groundColor) {\r\n mat3 result;\r\n\r\n // Diffuse\r\n float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\r\n\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW + lightData.xyz);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = pow(specComp, vSpecularColor.a);\r\n\r\n result[0] = mix(groundColor, diffuseColor.rgb, ndl);\r\n result[1] = specComp * specularColor;\r\n result[2] = vec3(0.);\r\n\r\n return result;\r\n}\r\n\r\nvoid main(void) {\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n if (fClipDistance > 0.0)\r\n discard;\r\n#endif\r\n\r\n vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\r\n\r\n // Base color\r\n vec4 baseColor = vec4(1., 1., 1., 1.);\r\n vec3 diffuseColor = vDiffuseColor.rgb;\r\n\r\n#ifdef VERTEXCOLOR\r\n baseColor.rgb *= vColor.rgb;\r\n#endif\r\n\r\n#ifdef DIFFUSE\r\n baseColor = texture2D(diffuseSampler, vDiffuseUV);\r\n\r\n#ifdef ALPHATEST\r\n if (baseColor.a < 0.4)\r\n discard;\r\n#endif\r\n\r\n baseColor.rgb *= vDiffuseInfos.y;\r\n#endif\r\n\r\n // Bump\r\n vec3 normalW = normalize(vNormalW);\r\n\r\n // Ambient color\r\n vec3 baseAmbientColor = vec3(1., 1., 1.);\r\n\r\n#ifdef AMBIENT\r\n baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;\r\n#endif\r\n\r\n // Lighting\r\n vec3 diffuseBase = vec3(0., 0., 0.);\r\n vec3 specularBase = vec3(0., 0., 0.);\r\n float shadow = 1.;\r\n\r\n#ifdef LIGHT0\r\n#ifdef SPOTLIGHT0\r\n mat3 info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0, vLightSpecular0);\r\n#endif\r\n#ifdef HEMILIGHT0\r\n mat3 info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0, vLightGround0);\r\n#endif\r\n#ifdef POINTDIRLIGHT0\r\n mat3 info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0);\r\n#endif\r\n#ifdef SHADOW0\r\n#ifdef SHADOWVSM0\r\n shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0);\r\n#else\r\n shadow = computeShadow(vPositionFromLight0, shadowSampler0);\r\n#endif\r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info[0] * shadow;\r\n specularBase += info[1] * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT1\r\n#ifdef SPOTLIGHT1\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1, vLightSpecular1);\r\n#endif\r\n#ifdef HEMILIGHT1\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1, vLightGround1);\r\n#endif\r\n#ifdef POINTDIRLIGHT1\r\n info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1);\r\n#endif\r\n#ifdef SHADOW1\r\n#ifdef SHADOWVSM1\r\n shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1);\r\n#else\r\n shadow = computeShadow(vPositionFromLight1, shadowSampler1);\r\n#endif\r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info[0] * shadow;\r\n specularBase += info[1] * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT2\r\n#ifdef SPOTLIGHT2\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2, vLightSpecular2);\r\n#endif\r\n#ifdef HEMILIGHT2\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2, vLightGround2);\r\n#endif\r\n#ifdef POINTDIRLIGHT2\r\n info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2);\r\n#endif\r\n#ifdef SHADOW2\r\n#ifdef SHADOWVSM2\r\n shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2);\r\n#else\r\n shadow = computeShadow(vPositionFromLight2, shadowSampler2);\r\n#endif \r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info[0] * shadow;\r\n specularBase += info[1] * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT3\r\n#ifdef SPOTLIGHT3\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3, vLightSpecular3);\r\n#endif\r\n#ifdef HEMILIGHT3\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3, vLightGround3);\r\n#endif\r\n#ifdef POINTDIRLIGHT3\r\n info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3);\r\n#endif\r\n#ifdef SHADOW3\r\n#ifdef SHADOWVSM3\r\n shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3);\r\n#else\r\n shadow = computeShadow(vPositionFromLight3, shadowSampler3);\r\n#endif \r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info[0] * shadow;\r\n specularBase += info[1] * shadow;\r\n#endif\r\n\r\n // Reflection\r\n vec3 reflectionColor = vec3(0., 0., 0.);\r\n\r\n#ifdef REFLECTION\r\n if (vReflectionInfos.z != 0.0)\r\n {\r\n reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.y;\r\n }\r\n else\r\n {\r\n vec2 coords = vReflectionUVW.xy;\r\n\r\n if (vReflectionInfos.x == MAP_PROJECTION)\r\n {\r\n coords /= vReflectionUVW.z;\r\n }\r\n\r\n coords.y = 1.0 - coords.y;\r\n\r\n reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.y;\r\n }\r\n\r\n#ifdef REFLECTIONFRESNEL\r\n float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);\r\n\r\n reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\r\n#endif\r\n#endif\r\n\r\n // Alpha\r\n float alpha = vDiffuseColor.a;\r\n\r\n#ifdef OPACITY\r\n vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);\r\n#ifdef OPACITYRGB\r\n opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);\r\n alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;\r\n#else\r\n alpha *= opacityMap.a * vOpacityInfos.y;\r\n#endif\r\n#endif\r\n\r\n#ifdef VERTEXALPHA\r\n alpha *= vColor.a;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\n float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);\r\n\r\n alpha += opacityParts.x * (1.0 - opacityFresnelTerm) + opacityFresnelTerm * opacityParts.y;\r\n#endif\r\n\r\n // Emissive\r\n vec3 emissiveColor = vEmissiveColor;\r\n#ifdef EMISSIVE\r\n emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\n float emissiveFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, emissiveRightColor.a, emissiveLeftColor.a);\r\n\r\n emissiveColor *= emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * emissiveRightColor.rgb;\r\n#endif\r\n\r\n // Specular map\r\n vec3 specularColor = vSpecularColor.rgb;\r\n#ifdef SPECULAR\r\n specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;\r\n#endif\r\n\r\n // Fresnel\r\n#ifdef DIFFUSEFRESNEL\r\n float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, diffuseRightColor.a, diffuseLeftColor.a);\r\n\r\n diffuseBase *= diffuseLeftColor.rgb * (1.0 - diffuseFresnelTerm) + diffuseFresnelTerm * diffuseRightColor.rgb;\r\n#endif\r\n\r\n // Composition\r\n vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\r\n vec3 finalSpecular = specularBase * specularColor;\r\n\r\n vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\r\n\r\n#ifdef FOG\r\n float fog = CalcFogFactor();\r\n color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\r\n#endif\r\n\r\n gl_FragColor = color;\r\n}", legacydefaultVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#define MAP_EXPLICIT 0.\r\n#define MAP_SPHERICAL 1.\r\n#define MAP_PLANAR 2.\r\n#define MAP_CUBIC 3.\r\n#define MAP_PROJECTION 4.\r\n#define MAP_SKYBOX 5.\r\n\r\n// Attributes\r\nattribute vec3 position;\r\nattribute vec3 normal;\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#ifdef VERTEXCOLOR\r\nattribute vec4 color;\r\n#endif\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniforms\r\nuniform mat4 world;\r\nuniform mat4 view;\r\nuniform mat4 viewProjection;\r\n\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\nuniform mat4 diffuseMatrix;\r\nuniform vec2 vDiffuseInfos;\r\n#endif\r\n\r\n#ifdef AMBIENT\r\nvarying vec2 vAmbientUV;\r\nuniform mat4 ambientMatrix;\r\nuniform vec2 vAmbientInfos;\r\n#endif\r\n\r\n#ifdef OPACITY\r\nvarying vec2 vOpacityUV;\r\nuniform mat4 opacityMatrix;\r\nuniform vec2 vOpacityInfos;\r\n#endif\r\n\r\n#ifdef REFLECTION\r\nuniform vec3 vEyePosition;\r\nvarying vec3 vReflectionUVW;\r\nuniform vec3 vReflectionInfos;\r\nuniform mat4 reflectionMatrix;\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\nvarying vec2 vEmissiveUV;\r\nuniform vec2 vEmissiveInfos;\r\nuniform mat4 emissiveMatrix;\r\n#endif\r\n\r\n#ifdef SPECULAR\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform mat4 specularMatrix;\r\n#endif\r\n\r\n#ifdef BUMP\r\nvarying vec2 vBumpUV;\r\nuniform vec2 vBumpInfos;\r\nuniform mat4 bumpMatrix;\r\n#endif\r\n\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n// Output\r\nvarying vec3 vPositionW;\r\nvarying vec3 vNormalW;\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n#ifdef CLIPPLANE\r\nuniform vec4 vClipPlane;\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n#ifdef FOG\r\nvarying float fFogDistance;\r\n#endif\r\n\r\n#ifdef SHADOWS\r\n#ifdef LIGHT0\r\nuniform mat4 lightMatrix0;\r\nvarying vec4 vPositionFromLight0;\r\n#endif\r\n#ifdef LIGHT1\r\nuniform mat4 lightMatrix1;\r\nvarying vec4 vPositionFromLight1;\r\n#endif\r\n#ifdef LIGHT2\r\nuniform mat4 lightMatrix2;\r\nvarying vec4 vPositionFromLight2;\r\n#endif\r\n#ifdef LIGHT3\r\nuniform mat4 lightMatrix3;\r\nvarying vec4 vPositionFromLight3;\r\n#endif\r\n#endif\r\n\r\n#ifdef REFLECTION\r\nvec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)\r\n{\r\n if (mode == MAP_SPHERICAL)\r\n {\r\n vec3 coords = vec3(view * vec4(worldNormal, 0.0));\r\n\r\n return vec3(reflectionMatrix * vec4(coords, 1.0));\r\n }\r\n else if (mode == MAP_PLANAR)\r\n {\r\n vec3 viewDir = worldPos.xyz - vEyePosition;\r\n vec3 coords = normalize(reflect(viewDir, worldNormal));\r\n\r\n return vec3(reflectionMatrix * vec4(coords, 1));\r\n }\r\n else if (mode == MAP_CUBIC)\r\n {\r\n vec3 viewDir = worldPos.xyz - vEyePosition;\r\n vec3 coords = reflect(viewDir, worldNormal);\r\n\r\n return vec3(reflectionMatrix * vec4(coords, 0));\r\n }\r\n else if (mode == MAP_PROJECTION)\r\n {\r\n return vec3(reflectionMatrix * (view * worldPos));\r\n }\r\n else if (mode == MAP_SKYBOX)\r\n {\r\n return position;\r\n }\r\n\r\n return vec3(0, 0, 0);\r\n}\r\n#endif\r\n\r\nvoid main(void) {\r\n mat4 finalWorld;\r\n\r\n#ifdef BONES\r\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n\r\n#ifdef BONES4\r\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n finalWorld = world * (m0 + m1 + m2 + m3);\r\n#else\r\n finalWorld = world * (m0 + m1 + m2);\r\n#endif \r\n\r\n#else\r\n finalWorld = world;\r\n#endif\r\n\r\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\r\n\r\n vec4 worldPos = finalWorld * vec4(position, 1.0);\r\n vPositionW = vec3(worldPos);\r\n vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\r\n\r\n // Texture coordinates\r\n#ifndef UV1\r\n vec2 uv = vec2(0., 0.);\r\n#endif\r\n#ifndef UV2\r\n vec2 uv2 = vec2(0., 0.);\r\n#endif\r\n\r\n#ifdef DIFFUSE\r\n if (vDiffuseInfos.x == 0.)\r\n {\r\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef AMBIENT\r\n if (vAmbientInfos.x == 0.)\r\n {\r\n vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef OPACITY\r\n if (vOpacityInfos.x == 0.)\r\n {\r\n vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef REFLECTION\r\n vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), vNormalW);\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\n if (vEmissiveInfos.x == 0.)\r\n {\r\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef SPECULAR\r\n if (vSpecularInfos.x == 0.)\r\n {\r\n vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef BUMP\r\n if (vBumpInfos.x == 0.)\r\n {\r\n vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n fClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n\r\n // Fog\r\n#ifdef FOG\r\n fFogDistance = (view * worldPos).z;\r\n#endif\r\n\r\n // Shadows\r\n#ifdef SHADOWS\r\n#ifdef LIGHT0\r\n vPositionFromLight0 = lightMatrix0 * worldPos;\r\n#endif\r\n#ifdef LIGHT1\r\n vPositionFromLight1 = lightMatrix1 * worldPos;\r\n#endif\r\n#ifdef LIGHT2\r\n vPositionFromLight2 = lightMatrix2 * worldPos;\r\n#endif\r\n#ifdef LIGHT3\r\n vPositionFromLight3 = lightMatrix3 * worldPos;\r\n#endif\r\n#endif\r\n\r\n // Vertex color\r\n#ifdef VERTEXCOLOR\r\n vColor = color;\r\n#endif\r\n}",lensFlarePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\n// Color\r\nuniform vec4 color;\r\n\r\nvoid main(void) {\r\n vec4 baseColor = texture2D(textureSampler, vUV);\r\n\r\n gl_FragColor = baseColor * color;\r\n}",lensFlareVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec2 position;\r\n\r\n// Uniforms\r\nuniform mat4 viewportMatrix;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\n\r\nconst vec2 madd = vec2(0.5, 0.5);\r\n\r\nvoid main(void) { \r\n\r\n vUV = position * madd + madd;\r\n gl_Position = viewportMatrix * vec4(position, 0.0, 1.0);\r\n}",lensHighlightsPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// samplers\r\nuniform sampler2D textureSampler; // original color\r\n\r\n// uniforms\r\nuniform float gain;\r\nuniform float threshold;\r\nuniform bool pentagon;\r\nuniform float screen_width;\r\nuniform float screen_height;\r\n\r\n// varyings\r\nvarying vec2 vUV;\r\n\r\n// apply luminance filter\r\nvec4 highlightColor(vec4 color) {\r\n vec4 highlight = color;\r\n float luminance = dot(highlight.rgb, vec3(0.2125, 0.7154, 0.0721));\r\n float lum_threshold;\r\n if (threshold > 1.0) { lum_threshold = 0.94 + 0.01 * threshold; }\r\n else { lum_threshold = 0.5 + 0.44 * threshold; }\r\n\r\n luminance = clamp((luminance - lum_threshold) * (1.0 / (1.0 - lum_threshold)), 0.0, 1.0);\r\n\r\n highlight *= luminance * gain;\r\n highlight.a = 1.0;\r\n\r\n return highlight;\r\n}\r\n\r\nvoid main(void)\r\n{\r\n vec4 original = texture2D(textureSampler, vUV);\r\n\r\n // quick exit if no highlight computing\r\n if (gain == -1.0) {\r\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\r\n return;\r\n }\r\n\r\n float w = 2.0 / screen_width;\r\n float h = 2.0 / screen_height;\r\n\r\n float weight = 1.0;\r\n\r\n // compute blurred color\r\n vec4 blurred = vec4(0.0, 0.0, 0.0, 0.0);\r\n\r\n if (pentagon) {\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.84*w, 0.43*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.48*w, -1.29*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.61*w, 1.51*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.55*w, -0.74*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.71*w, -0.52*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.94*w, 1.59*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.40*w, -1.87*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.62*w, 1.16*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.09*w, 0.25*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.46*w, -1.71*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.08*w, 2.42*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.85*w, -1.89*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.89*w, 0.16*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.29*w, 1.88*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.40*w, -2.81*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.54*w, 2.26*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.60*w, -0.61*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.31*w, -1.30*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.83*w, 2.53*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.12*w, -2.48*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.60*w, 1.11*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.82*w, 0.99*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.50*w, -2.81*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.85*w, 3.33*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.94*w, -1.92*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(3.27*w, -0.53*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.95*w, 2.48*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.23*w, -3.04*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.17*w, 2.05*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.97*w, -0.04*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.25*w, -2.00*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.31*w, 3.08*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.94*w, -2.59*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(3.37*w, 0.64*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-3.13*w, 1.93*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.03*w, -3.65*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.60*w, 3.17*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-3.14*w, -1.19*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(3.00*w, -1.19*h)));\r\n }\r\n else {\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.85*w, 0.36*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.52*w, -1.14*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.46*w, 1.42*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.46*w, -0.83*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.79*w, -0.42*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.11*w, 1.62*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.29*w, -2.07*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.69*w, 1.39*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.28*w, 0.12*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.65*w, -1.69*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.08*w, 2.44*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.63*w, -1.90*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.55*w, 0.31*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.13*w, 1.52*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.56*w, -2.61*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.38*w, 2.34*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.64*w, -0.81*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.53*w, -1.21*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.06*w, 2.63*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.00*w, -2.69*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.59*w, 1.32*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.82*w, 0.78*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.57*w, -2.50*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.54*w, 2.93*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.39*w, -1.81*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(3.01*w, -0.28*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.04*w, 2.25*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.02*w, -3.05*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.09*w, 2.25*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-3.07*w, -0.25*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.44*w, -1.90*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.52*w, 3.05*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.68*w, -2.61*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(3.01*w, 0.79*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.76*w, 1.46*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.05*w, -2.94*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.21*w, 2.88*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.84*w, -1.30*h)));\r\n blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.98*w, -0.96*h)));\r\n }\r\n\r\n blurred /= 39.0;\r\n\r\n gl_FragColor = blurred;\r\n\r\n //if(vUV.x > 0.5) { gl_FragColor.rgb *= 0.0; }\r\n}",marblePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nuniform float numberOfTilesHeight;\r\nuniform float numberOfTilesWidth;\r\nuniform float amplitude;\r\nuniform vec3 brickColor;\r\nuniform vec3 jointColor;\r\n\r\nconst vec3 tileSize = vec3(1.1, 1.0, 1.1);\r\nconst vec3 tilePct = vec3(0.98, 1.0, 0.98);\r\n\r\nfloat rand(vec2 n) {\r\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n const vec2 d = vec2(0.0, 1.0);\r\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\r\n}\r\n\r\nfloat turbulence(vec2 P)\r\n{\r\n float val = 0.0;\r\n float freq = 1.0;\r\n for (int i = 0; i < 4; i++)\r\n {\r\n val += abs(noise(P*freq) / freq);\r\n freq *= 2.07;\r\n }\r\n return val;\r\n}\r\n\r\nfloat round(float number){\r\n return sign(number)*floor(abs(number) + 0.5);\r\n}\r\n\r\nvec3 marble_color(float x)\r\n{\r\n vec3 col;\r\n x = 0.5*(x + 1.);\r\n x = sqrt(x); \r\n x = sqrt(x);\r\n x = sqrt(x);\r\n col = vec3(.2 + .75*x); \r\n col.b *= 0.95; \r\n return col;\r\n}\r\n\r\nvoid main()\r\n{\r\n float brickW = 1.0 / numberOfTilesWidth;\r\n float brickH = 1.0 / numberOfTilesHeight;\r\n float jointWPercentage = 0.01;\r\n float jointHPercentage = 0.01;\r\n vec3 color = brickColor;\r\n float yi = vUV.y / brickH;\r\n float nyi = round(yi);\r\n float xi = vUV.x / brickW;\r\n\r\n if (mod(floor(yi), 2.0) == 0.0){\r\n xi = xi - 0.5;\r\n }\r\n\r\n float nxi = round(xi);\r\n vec2 brickvUV = vec2((xi - floor(xi)) / brickH, (yi - floor(yi)) / brickW);\r\n\r\n if (yi < nyi + jointHPercentage && yi > nyi - jointHPercentage){\r\n color = mix(jointColor, vec3(0.37, 0.25, 0.25), (yi - nyi) / jointHPercentage + 0.2);\r\n }\r\n else if (xi < nxi + jointWPercentage && xi > nxi - jointWPercentage){\r\n color = mix(jointColor, vec3(0.44, 0.44, 0.44), (xi - nxi) / jointWPercentage + 0.2);\r\n }\r\n else {\r\n float t = 6.28 * brickvUV.x / (tileSize.x + noise(vec2(vUV)*6.0));\r\n t += amplitude * turbulence(brickvUV.xy);\r\n t = sin(t);\r\n color = marble_color(t);\r\n }\r\n\r\n gl_FragColor = vec4(color, 0.0);\r\n}",oculusDistortionCorrectionPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform vec2 LensCenter;\r\nuniform vec2 Scale;\r\nuniform vec2 ScaleIn;\r\nuniform vec4 HmdWarpParam;\r\n\r\nvec2 HmdWarp(vec2 in01) {\r\n\r\n vec2 theta = (in01 - LensCenter) * ScaleIn; // Scales to [-1, 1]\r\n float rSq = theta.x * theta.x + theta.y * theta.y;\r\n vec2 rvector = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq + HmdWarpParam.z * rSq * rSq + HmdWarpParam.w * rSq * rSq * rSq);\r\n return LensCenter + Scale * rvector;\r\n}\r\n\r\nvoid main(void)\r\n{\r\n vec2 tc = HmdWarp(vUV);\r\n if (tc.x <0.0 || tc.x>1.0 || tc.y<0.0 || tc.y>1.0)\r\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\r\n else{\r\n gl_FragColor = vec4(texture2D(textureSampler, tc).rgb, 1.0);\r\n }\r\n}",outlinePixelShader:"precision highp float;\r\n\r\nuniform vec4 color;\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform sampler2D diffuseSampler;\r\n#endif\r\n\r\nvoid main(void) {\r\n#ifdef ALPHATEST\r\n if (texture2D(diffuseSampler, vUV).a < 0.4)\r\n discard;\r\n#endif\r\n\r\n gl_FragColor = color;\r\n}",outlineVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attribute\r\nattribute vec3 position;\r\nattribute vec3 normal;\r\n\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniform\r\nuniform float offset;\r\n\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 viewProjection;\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform mat4 diffuseMatrix;\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#ifdef INSTANCES\r\n mat4 finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n mat4 finalWorld = world;\r\n#endif\r\n\r\n vec3 offsetPosition = position + normal * offset;\r\n\r\n#ifdef BONES\r\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n gl_Position = viewProjection * finalWorld * vec4(offsetPosition, 1.0);\r\n#else\r\n gl_Position = viewProjection * finalWorld * vec4(offsetPosition, 1.0);\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\n#ifdef UV1\r\n vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n#endif\r\n#ifdef UV2\r\n vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n#endif\r\n#endif\r\n}",particlesPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nvarying vec4 vColor;\r\nuniform vec4 textureMask;\r\nuniform sampler2D diffuseSampler;\r\n\r\n#ifdef CLIPPLANE\r\nvarying float fClipDistance;\r\n#endif\r\n\r\nvoid main(void) {\r\n#ifdef CLIPPLANE\r\n if (fClipDistance > 0.0)\r\n discard;\r\n#endif\r\n vec4 baseColor = texture2D(diffuseSampler, vUV);\r\n\r\n gl_FragColor = (baseColor * textureMask + (vec4(1., 1., 1., 1.) - textureMask)) * vColor;\r\n}",particlesVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec3 position;\r\nattribute vec4 color;\r\nattribute vec4 options;\r\n\r\n// Uniforms\r\nuniform mat4 view;\r\nuniform mat4 projection;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\nvarying vec4 vColor;\r\n\r\n#ifdef CLIPPLANE\r\nuniform vec4 vClipPlane;\r\nuniform mat4 invView;\r\nvarying float fClipDistance;\r\n#endif\r\n\r\nvoid main(void) { \r\n vec3 viewPos = (view * vec4(position, 1.0)).xyz; \r\n vec3 cornerPos;\r\n float size = options.y;\r\n float angle = options.x;\r\n vec2 offset = options.zw;\r\n\r\n cornerPos = vec3(offset.x - 0.5, offset.y - 0.5, 0.) * size;\r\n\r\n // Rotate\r\n vec3 rotatedCorner;\r\n rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\r\n rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\r\n rotatedCorner.z = 0.;\r\n\r\n // Position\r\n viewPos += rotatedCorner;\r\n gl_Position = projection * vec4(viewPos, 1.0); \r\n \r\n vColor = color;\r\n vUV = offset;\r\n\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n vec4 worldPos = invView * vec4(viewPos, 1.0);\r\n fClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n}",passPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\nvoid main(void) \r\n{\r\n gl_FragColor = texture2D(textureSampler, vUV);\r\n}",postprocessVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec2 position;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\n\r\nconst vec2 madd = vec2(0.5, 0.5);\r\n\r\nvoid main(void) { \r\n\r\n vUV = position * madd + madd;\r\n gl_Position = vec4(position, 0.0, 1.0);\r\n}",proceduralVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec2 position;\r\n\r\n// Output\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nconst vec2 madd = vec2(0.5, 0.5);\r\n\r\nvoid main(void) { \r\n vPosition = position;\r\n vUV = position * madd + madd;\r\n gl_Position = vec4(position, 0.0, 1.0);\r\n}",refractionPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D refractionSampler;\r\n\r\n// Parameters\r\nuniform vec3 baseColor;\r\nuniform float depth;\r\nuniform float colorLevel;\r\n\r\nvoid main() {\r\n float ref = 1.0 - texture2D(refractionSampler, vUV).r;\r\n\r\n vec2 uv = vUV - vec2(0.5);\r\n vec2 offset = uv * depth * ref;\r\n vec3 sourceColor = texture2D(textureSampler, vUV - offset).rgb;\r\n\r\n gl_FragColor = vec4(sourceColor + sourceColor * ref * colorLevel, 1.0);\r\n}",roadPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vUV; \r\nuniform vec3 roadColor;\r\n\r\nfloat rand(vec2 n) {\r\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n const vec2 d = vec2(0.0, 1.0);\r\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n float total = 0.0, amplitude = 1.0;\r\n for (int i = 0; i < 4; i++) {\r\n total += noise(n) * amplitude;\r\n n += n;\r\n amplitude *= 0.5;\r\n }\r\n return total;\r\n}\r\n\r\nvoid main(void) {\r\n float ratioy = mod(gl_FragCoord.y * 100.0 , fbm(vUV * 2.0));\r\n vec3 color = roadColor * ratioy;\r\n gl_FragColor = vec4(color, 1.0);\r\n}",shadowMapPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvec4 pack(float depth)\r\n{\r\n const vec4 bit_shift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);\r\n const vec4 bit_mask = vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);\r\n\r\n vec4 res = fract(depth * bit_shift);\r\n res -= res.xxyz * bit_mask;\r\n\r\n return res;\r\n}\r\n\r\n// Thanks to http://devmaster.net/\r\nvec2 packHalf(float depth) \r\n{ \r\n const vec2 bitOffset = vec2(1.0 / 255., 0.);\r\n vec2 color = vec2(depth, fract(depth * 255.));\r\n\r\n return color - (color.yy * bitOffset);\r\n}\r\n\r\nvarying vec4 vPosition;\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform sampler2D diffuseSampler;\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#ifdef ALPHATEST\r\n if (texture2D(diffuseSampler, vUV).a < 0.4)\r\n discard;\r\n#endif\r\n float depth = vPosition.z / vPosition.w;\r\n depth = depth * 0.5 + 0.5;\r\n\r\n#ifdef VSM\r\n float moment1 = depth;\r\n float moment2 = moment1 * moment1;\r\n\r\n gl_FragColor = vec4(packHalf(moment1), packHalf(moment2));\r\n#else\r\n gl_FragColor = pack(depth);\r\n#endif\r\n}",shadowMapVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attribute\r\nattribute vec3 position;\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniform\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 viewProjection;\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\nvarying vec4 vPosition;\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform mat4 diffuseMatrix;\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#ifdef INSTANCES\r\n mat4 finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n mat4 finalWorld = world;\r\n#endif\r\n\r\n#ifdef BONES\r\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n#endif\r\n\r\n vPosition = viewProjection * finalWorld * vec4(position, 1.0);\r\n gl_Position = vPosition;\r\n\r\n#ifdef ALPHATEST\r\n#ifdef UV1\r\n vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n#endif\r\n#ifdef UV2\r\n vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n#endif\r\n#endif\r\n}",spritesPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nuniform bool alphaTest;\r\n\r\nvarying vec4 vColor;\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D diffuseSampler;\r\n\r\n// Fog\r\n#ifdef FOG\r\n\r\n#define FOGMODE_NONE 0.\r\n#define FOGMODE_EXP 1.\r\n#define FOGMODE_EXP2 2.\r\n#define FOGMODE_LINEAR 3.\r\n#define E 2.71828\r\n\r\nuniform vec4 vFogInfos;\r\nuniform vec3 vFogColor;\r\nvarying float fFogDistance;\r\n\r\nfloat CalcFogFactor()\r\n{\r\n float fogCoeff = 1.0;\r\n float fogStart = vFogInfos.y;\r\n float fogEnd = vFogInfos.z;\r\n float fogDensity = vFogInfos.w;\r\n\r\n if (FOGMODE_LINEAR == vFogInfos.x)\r\n {\r\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\r\n }\r\n else if (FOGMODE_EXP == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\r\n }\r\n else if (FOGMODE_EXP2 == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\r\n }\r\n\r\n return min(1., max(0., fogCoeff));\r\n}\r\n#endif\r\n\r\n\r\nvoid main(void) {\r\n vec4 baseColor = texture2D(diffuseSampler, vUV);\r\n\r\n if (alphaTest) \r\n {\r\n if (baseColor.a < 0.95)\r\n discard;\r\n }\r\n\r\n baseColor *= vColor;\r\n\r\n#ifdef FOG\r\n float fog = CalcFogFactor();\r\n baseColor.rgb = fog * baseColor.rgb + (1.0 - fog) * vFogColor;\r\n#endif\r\n\r\n gl_FragColor = baseColor;\r\n}",spritesVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec4 position;\r\nattribute vec4 options;\r\nattribute vec4 cellInfo;\r\nattribute vec4 color;\r\n\r\n// Uniforms\r\nuniform vec2 textureInfos;\r\nuniform mat4 view;\r\nuniform mat4 projection;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\nvarying vec4 vColor;\r\n\r\n#ifdef FOG\r\nvarying float fFogDistance;\r\n#endif\r\n\r\nvoid main(void) { \r\n vec3 viewPos = (view * vec4(position.xyz, 1.0)).xyz; \r\n vec2 cornerPos;\r\n \r\n float angle = position.w;\r\n vec2 size = vec2(options.x, options.y);\r\n vec2 offset = options.zw;\r\n vec2 uvScale = textureInfos.xy;\r\n\r\n cornerPos = vec2(offset.x - 0.5, offset.y - 0.5) * size;\r\n\r\n // Rotate\r\n vec3 rotatedCorner;\r\n rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\r\n rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\r\n rotatedCorner.z = 0.;\r\n\r\n // Position\r\n viewPos += rotatedCorner;\r\n gl_Position = projection * vec4(viewPos, 1.0); \r\n\r\n // Color\r\n vColor = color;\r\n \r\n // Texture\r\n vec2 uvOffset = vec2(abs(offset.x - cellInfo.x), 1.0 - abs(offset.y - cellInfo.y));\r\n\r\n vUV = (uvOffset + cellInfo.zw) * uvScale;\r\n\r\n // Fog\r\n#ifdef FOG\r\n fFogDistance = viewPos.z;\r\n#endif\r\n}",ssaoPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#define SAMPLES 16\r\n\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D randomSampler;\r\n\r\nuniform float randTextureTiles;\r\nuniform float samplesFactor;\r\nuniform vec3 sampleSphere[16];\r\n\r\nuniform float totalStrength;\r\nuniform float radius;\r\nuniform float area;\r\nuniform float fallOff;\r\n\r\nvarying vec2 vUV;\r\n\r\nconst vec2 offset1 = vec2(0.0, 0.001);\r\nconst vec2 offset2 = vec2(0.001, 0.0);\r\n\r\nvec3 normalFromDepth(const float depth, const vec2 coords) {\r\n float depth1 = texture2D(textureSampler, coords + offset1).r;\r\n float depth2 = texture2D(textureSampler, coords + offset2).r;\r\n\r\n vec3 p1 = vec3(offset1, depth1 - depth);\r\n vec3 p2 = vec3(offset2, depth2 - depth);\r\n\r\n vec3 normal = cross(p1, p2);\r\n normal.z = -normal.z;\r\n\r\n return normalize(normal);\r\n}\r\n\r\nvoid main(void)\r\n{\r\n const float base = 0.2;\r\n\r\n vec3 random = texture2D(randomSampler, vUV * randTextureTiles).rgb;\r\n float depth = texture2D(textureSampler, vUV).r;\r\n vec3 position = vec3(vUV, depth);\r\n vec3 normal = normalFromDepth(depth, vUV);\r\n float radiusDepth = radius / depth;\r\n float occlusion = 0.0;\r\n\r\n vec3 ray;\r\n vec3 hemiRay;\r\n float occlusionDepth;\r\n float difference;\r\n\r\n for (int i = 0; i < SAMPLES; i++)\r\n {\r\n ray = radiusDepth * reflect(sampleSphere[i], random);\r\n hemiRay = position + sign(dot(ray, normal)) * ray;\r\n\r\n occlusionDepth = texture2D(textureSampler, clamp(hemiRay.xy, 0.0, 1.0)).r;\r\n difference = depth - occlusionDepth;\r\n\r\n occlusion += step(fallOff, difference) * (1.0 - smoothstep(fallOff, area, difference));\r\n }\r\n\r\n float ao = 1.0 - totalStrength * occlusion * samplesFactor;\r\n\r\n float result = clamp(ao + base, 0.0, 1.0);\r\n gl_FragColor.r = result;\r\n gl_FragColor.g = result;\r\n gl_FragColor.b = result;\r\n gl_FragColor.a = 1.0;\r\n}\r\n",ssaoCombinePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D originalColor;\r\n\r\nvarying vec2 vUV;\r\n\r\nvoid main(void) {\r\n gl_FragColor = texture2D(originalColor, vUV) * texture2D(textureSampler, vUV);\r\n}\r\n",volumetricLightScatteringPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D lightScatteringSampler;\r\n\r\nuniform float decay;\r\nuniform float exposure;\r\nuniform float weight;\r\nuniform float density;\r\nuniform vec2 meshPositionOnScreen;\r\n\r\nvarying vec2 vUV;\r\n\r\nvoid main(void) {\r\n vec2 tc = vUV;\r\n vec2 deltaTexCoord = (tc - meshPositionOnScreen.xy);\r\n deltaTexCoord *= 1.0 / float(NUM_SAMPLES) * density;\r\n\r\n float illuminationDecay = 1.0;\r\n\r\n vec4 color = texture2D(lightScatteringSampler, tc) * 0.4;\r\n\r\n for(int i=0; i < NUM_SAMPLES; i++) {\r\n tc -= deltaTexCoord;\r\n vec4 sample = texture2D(lightScatteringSampler, tc) * 0.4;\r\n sample *= illuminationDecay * weight;\r\n color += sample;\r\n illuminationDecay *= decay;\r\n }\r\n\r\n vec4 realColor = texture2D(textureSampler, vUV);\r\n gl_FragColor = ((vec4((vec3(color.r, color.g, color.b) * exposure), 1)) + (realColor * (1.5 - 0.4)));\r\n}\r\n", volumetricLightScatteringPassPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#if defined(ALPHATEST) || defined(BASIC_RENDER) || defined(OPACITY)\r\nvarying vec2 vUV;\r\n#endif\r\n\r\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\r\nuniform sampler2D diffuseSampler;\r\n#endif\r\n\r\n#if defined(OPACITY)\r\nuniform sampler2D opacitySampler;\r\nuniform float opacityLevel;\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\r\n vec4 diffuseColor = texture2D(diffuseSampler, vUV);\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\n if (diffuseColor.a < 0.4)\r\n discard;\r\n#endif\r\n\r\n#ifdef OPACITY\r\n vec4 opacityColor = texture2D(opacitySampler, vUV);\r\n float alpha = 1.0;\r\n\r\n #ifdef OPACITYRGB\r\n opacityColor.rgb = opacityColor.rgb * vec3(0.3, 0.59, 0.11);\r\n alpha *= (opacityColor.x + opacityColor.y + opacityColor.z) * opacityLevel;\r\n #else\r\n alpha *= opacityColor.a * opacityLevel;\r\n #endif\r\n\r\n #if defined(BASIC_RENDER)\r\n gl_FragColor = vec4(diffuseColor.rgb, alpha);\r\n #else\r\n gl_FragColor = vec4(0.0, 0.0, 0.0, alpha);\r\n #endif\r\n\r\n gl_FragColor.a = alpha;\r\n#else\r\n #ifndef BASIC_RENDER\r\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\r\n #else\r\n gl_FragColor = diffuseColor;\r\n #endif\r\n#endif\r\n\r\n}\r\n",woodPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nuniform float ampScale;\r\nuniform vec3 woodColor;\r\n\r\nfloat rand(vec2 n) {\r\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n const vec2 d = vec2(0.0, 1.0);\r\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n float total = 0.0, amplitude = 1.0;\r\n for (int i = 0; i < 4; i++) {\r\n total += noise(n) * amplitude;\r\n n += n;\r\n amplitude *= 0.5;\r\n }\r\n return total;\r\n}\r\n\r\nvoid main(void) {\r\n float ratioy = mod(vUV.x * ampScale, 2.0 + fbm(vUV * 0.8));\r\n vec3 wood = woodColor * ratioy;\r\n gl_FragColor = vec4(wood, 1.0);\r\n}"},BABYLON.CollisionWorker='var BABYLON;!function(t){var e=function(t,e,o,i){return t.x>o.x+i?!1:o.x-i>e.x?!1:t.y>o.y+i?!1:o.y-i>e.y?!1:t.z>o.z+i?!1:o.z-i>e.z?!1:!0},o=function(t,e,o,i){var s=e*e-4*t*o,r={root:0,found:!1};if(0>s)return r;var n=Math.sqrt(s),c=(-e-n)/(2*t),h=(-e+n)/(2*t);if(c>h){var a=h;h=c,c=a}return c>0&&i>c?(r.root=c,r.found=!0,r):h>0&&i>h?(r.root=h,r.found=!0,r):r},i=function(){function i(){this.radius=new t.Vector3(1,1,1),this.retry=0,this.basePointWorld=t.Vector3.Zero(),this.velocityWorld=t.Vector3.Zero(),this.normalizedVelocity=t.Vector3.Zero(),this._collisionPoint=t.Vector3.Zero(),this._planeIntersectionPoint=t.Vector3.Zero(),this._tempVector=t.Vector3.Zero(),this._tempVector2=t.Vector3.Zero(),this._tempVector3=t.Vector3.Zero(),this._tempVector4=t.Vector3.Zero(),this._edge=t.Vector3.Zero(),this._baseToVertex=t.Vector3.Zero(),this._destinationPoint=t.Vector3.Zero(),this._slidePlaneNormal=t.Vector3.Zero(),this._displacementVector=t.Vector3.Zero()}return i.prototype._initialize=function(e,o,i){this.velocity=o,t.Vector3.NormalizeToRef(o,this.normalizedVelocity),this.basePoint=e,e.multiplyToRef(this.radius,this.basePointWorld),o.multiplyToRef(this.radius,this.velocityWorld),this.velocityWorldLength=this.velocityWorld.length(),this.epsilon=i,this.collisionFound=!1},i.prototype._checkPointInTriangle=function(e,o,i,s,r){o.subtractToRef(e,this._tempVector),i.subtractToRef(e,this._tempVector2),t.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var n=t.Vector3.Dot(this._tempVector4,r);return 0>n?!1:(s.subtractToRef(e,this._tempVector3),t.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),n=t.Vector3.Dot(this._tempVector4,r),0>n?!1:(t.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),n=t.Vector3.Dot(this._tempVector4,r),n>=0))},i.prototype._canDoCollision=function(o,i,s,r){var n=t.Vector3.Distance(this.basePointWorld,o),c=Math.max(this.radius.x,this.radius.y,this.radius.z);return n>this.velocityWorldLength+c+i?!1:e(s,r,this.basePointWorld,this.velocityWorldLength+c)?!0:!1},i.prototype._testTriangle=function(e,i,s,r,n,c){var h,a=!1;i||(i=[]),i[e]||(i[e]=new t.Plane(0,0,0,0),i[e].copyFromPoints(s,r,n));var l=i[e];if(c||l.isFrontFacingTo(this.normalizedVelocity,0)){var _=l.signedDistanceTo(this.basePoint),d=t.Vector3.Dot(l.normal,this.velocity);if(0==d){if(Math.abs(_)>=1)return;a=!0,h=0}else{h=(-1-_)/d;var V=(1-_)/d;if(h>V){var u=V;V=h,h=u}if(h>1||0>V)return;0>h&&(h=0),h>1&&(h=1)}this._collisionPoint.copyFromFloats(0,0,0);var P=!1,p=1;if(a||(this.basePoint.subtractToRef(l.normal,this._planeIntersectionPoint),this.velocity.scaleToRef(h,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,s,r,n,l.normal)&&(P=!0,p=h,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!P){var m=this.velocity.lengthSquared(),f=m;this.basePoint.subtractToRef(s,this._tempVector);var T=2*t.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,y=o(f,T,b,p);y.found&&(p=y.root,P=!0,this._collisionPoint.copyFrom(s)),this.basePoint.subtractToRef(r,this._tempVector),T=2*t.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,y=o(f,T,b,p),y.found&&(p=y.root,P=!0,this._collisionPoint.copyFrom(r)),this.basePoint.subtractToRef(n,this._tempVector),T=2*t.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,y=o(f,T,b,p),y.found&&(p=y.root,P=!0,this._collisionPoint.copyFrom(n)),r.subtractToRef(s,this._edge),s.subtractToRef(this.basePoint,this._baseToVertex);var g=this._edge.lengthSquared(),v=t.Vector3.Dot(this._edge,this.velocity),R=t.Vector3.Dot(this._edge,this._baseToVertex);if(f=g*-m+v*v,T=2*g*t.Vector3.Dot(this.velocity,this._baseToVertex)-2*v*R,b=g*(1-this._baseToVertex.lengthSquared())+R*R,y=o(f,T,b,p),y.found){var D=(v*y.root-R)/g;D>=0&&1>=D&&(p=y.root,P=!0,this._edge.scaleInPlace(D),s.addToRef(this._edge,this._collisionPoint))}n.subtractToRef(r,this._edge),r.subtractToRef(this.basePoint,this._baseToVertex),g=this._edge.lengthSquared(),v=t.Vector3.Dot(this._edge,this.velocity),R=t.Vector3.Dot(this._edge,this._baseToVertex),f=g*-m+v*v,T=2*g*t.Vector3.Dot(this.velocity,this._baseToVertex)-2*v*R,b=g*(1-this._baseToVertex.lengthSquared())+R*R,y=o(f,T,b,p),y.found&&(D=(v*y.root-R)/g,D>=0&&1>=D&&(p=y.root,P=!0,this._edge.scaleInPlace(D),r.addToRef(this._edge,this._collisionPoint))),s.subtractToRef(n,this._edge),n.subtractToRef(this.basePoint,this._baseToVertex),g=this._edge.lengthSquared(),v=t.Vector3.Dot(this._edge,this.velocity),R=t.Vector3.Dot(this._edge,this._baseToVertex),f=g*-m+v*v,T=2*g*t.Vector3.Dot(this.velocity,this._baseToVertex)-2*v*R,b=g*(1-this._baseToVertex.lengthSquared())+R*R,y=o(f,T,b,p),y.found&&(D=(v*y.root-R)/g,D>=0&&1>=D&&(p=y.root,P=!0,this._edge.scaleInPlace(D),n.addToRef(this._edge,this._collisionPoint)))}if(P){var x=p*this.velocity.length();(!this.collisionFound||xc;c+=3){var h=e[o[c]-r],a=e[o[c+1]-r],l=e[o[c+2]-r];this._testTriangle(c,t,l,a,h,n)}},i.prototype._getResponse=function(e,o){e.addToRef(o,this._destinationPoint),o.scaleInPlace(this.nearestDistance/o.length()),this.basePoint.addToRef(o,e),e.subtractToRef(this.intersectionPoint,this._slidePlaneNormal),this._slidePlaneNormal.normalize(),this._slidePlaneNormal.scaleToRef(this.epsilon,this._displacementVector),e.addInPlace(this._displacementVector),this.intersectionPoint.addInPlace(this._displacementVector),this._slidePlaneNormal.scaleInPlace(t.Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint,this._slidePlaneNormal,this._destinationPoint)),this._destinationPoint.subtractInPlace(this._slidePlaneNormal),this._destinationPoint.subtractToRef(this.intersectionPoint,o)},i}();t.Collider=i}(BABYLON||(BABYLON={}));var BABYLON;!function(o){o.WorkerIncluded=!0;var i=function(){function o(){this._meshes={},this._geometries={}}return o.prototype.getMeshes=function(){return this._meshes},o.prototype.getGeometries=function(){return this._geometries},o.prototype.getMesh=function(o){return this._meshes[o]},o.prototype.addMesh=function(o){this._meshes[o.uniqueId]=o},o.prototype.getGeometry=function(o){return this._geometries[o]},o.prototype.addGeometry=function(o){this._geometries[o.id]=o},o}();o.CollisionCache=i;var e=function(){function i(i,e,r){this.collider=i,this._collisionCache=e,this.finalPosition=r,this.collisionsScalingMatrix=o.Matrix.Zero(),this.collisionTranformationMatrix=o.Matrix.Zero()}return i.prototype.collideWithWorld=function(o,i,e,r){var t=.01;if(this.collider.retry>=e)return void this.finalPosition.copyFrom(o);this.collider._initialize(o,i,t);var s=this._collisionCache.getMeshes();for(var l in s)if(s.hasOwnProperty(l)&&parseInt(l)!=r){var n=s[l];n.checkCollisions&&this.checkCollision(n)}return this.collider.collisionFound?((0!==i.x||0!==i.y||0!==i.z)&&this.collider._getResponse(o,i),i.length()<=t?void this.finalPosition.copyFrom(o):(this.collider.retry++,void this.collideWithWorld(o,i,e,r))):void o.addToRef(i,this.finalPosition)},i.prototype.checkCollision=function(i){if(this.collider._canDoCollision(o.Vector3.FromArray(i.sphereCenter),i.sphereRadius,o.Vector3.FromArray(i.boxMinimum),o.Vector3.FromArray(i.boxMaximum))){o.Matrix.ScalingToRef(1/this.collider.radius.x,1/this.collider.radius.y,1/this.collider.radius.z,this.collisionsScalingMatrix);var e=o.Matrix.FromArray(i.worldMatrixFromCache);e.multiplyToRef(this.collisionsScalingMatrix,this.collisionTranformationMatrix),this.processCollisionsForSubMeshes(this.collisionTranformationMatrix,i)}},i.prototype.processCollisionsForSubMeshes=function(o,i){var e,r;if(r=i.subMeshes,e=r.length,!i.geometryId)return void console.log("no mesh geometry id");var t=this._collisionCache.getGeometry(i.geometryId);if(!t)return void console.log("couldn\'t find geometry",i.geometryId);for(var s=0;e>s;s++){var l=r[s];e>1&&!this.checkSubmeshCollision(l)||this.collideForSubMesh(l,o,t)}},i.prototype.collideForSubMesh=function(i,e,r){for(var t=[],s=0;ss;s++)i._lastColliderWorldVertices.push(o.Vector3.TransformCoordinates(t[s],e));this.collider._collide(i._trianglePlanes=[],i._lastColliderWorldVertices,r.indices,i.indexStart,i.indexStart+i.indexCount,i.verticesStart,i.hasMaterial)},i.prototype.checkSubmeshCollision=function(i){return this.collider._canDoCollision(o.Vector3.FromArray(i.sphereCenter),i.sphereRadius,o.Vector3.FromArray(i.boxMinimum),o.Vector3.FromArray(i.boxMaximum))},i}();o.CollideWorker=e;var r=function(){function r(){}return r.prototype.onInit=function(o){this._collisionCache=new i;var e={error:0,taskType:0};postMessage(e,void 0)},r.prototype.onUpdate=function(o){for(var i in o.updatedGeometries)o.updatedGeometries.hasOwnProperty(i)&&this._collisionCache.addGeometry(o.updatedGeometries[i]);for(var e in o.updatedMeshes)o.updatedMeshes.hasOwnProperty(e)&&this._collisionCache.addMesh(o.updatedMeshes[e]);var r={error:0,taskType:1};postMessage(r,void 0)},r.prototype.onCollision=function(i){var r=o.Vector3.Zero(),t=new o.Collider;t.radius=o.Vector3.FromArray(i.collider.radius);var s=new e(t,this._collisionCache,r);s.collideWithWorld(o.Vector3.FromArray(i.collider.position),o.Vector3.FromArray(i.collider.velocity),i.maximumRetry,i.excludedMeshUniqueId);var l={collidedMeshUniqueId:t.collidedMesh,collisionId:i.collisionId,newPosition:r.asArray()},n={error:0,taskType:2,payload:l};postMessage(n,void 0)},r}();o.CollisionDetectorTransferable=r;try{if(self&&self instanceof WorkerGlobalScope){window={},o.Collider||(importScripts("./babylon.collisionCoordinator.js"),importScripts("./babylon.collider.js"),importScripts("../Math/babylon.math.js"));var t=new r,s=function(o){var i=o.data;switch(i.taskType){case 0:t.onInit(i.payload);break;case 2:t.onCollision(i.payload);break;case 1:t.onUpdate(i.payload)}};self.onmessage=s}}catch(l){console.log("single worker init")}}(BABYLON||(BABYLON={}));var BABYLON;!function(e){e.CollisionWorker="",function(e){e[e.INIT=0]="INIT",e[e.UPDATE=1]="UPDATE",e[e.COLLIDE=2]="COLLIDE"}(e.WorkerTaskType||(e.WorkerTaskType={}));e.WorkerTaskType;!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.UNKNOWN_ERROR=1]="UNKNOWN_ERROR"}(e.WorkerReplyType||(e.WorkerReplyType={}));var o=(e.WorkerReplyType,function(){function o(){var i=this;this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this.onMeshUpdated=function(e){i._addUpdateMeshesList[e.uniqueId]=o.SerializeMesh(e)},this.onGeometryUpdated=function(e){i._addUpdateGeometriesList[e.id]=o.SerializeGeometry(e)},this._afterRender=function(){if(i._init&&!(0==i._toRemoveGeometryArray.length&&0==i._toRemoveMeshesArray.length&&0==Object.keys(i._addUpdateGeometriesList).length&&0==Object.keys(i._addUpdateMeshesList).length||i._runningUpdated>4)){++i._runningUpdated;var e={updatedMeshes:i._addUpdateMeshesList,updatedGeometries:i._addUpdateGeometriesList,removedGeometries:i._toRemoveGeometryArray,removedMeshes:i._toRemoveMeshesArray},o={payload:e,taskType:1},t=[];for(var r in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(r)&&(t.push(o.payload.updatedGeometries[r].indices.buffer),t.push(o.payload.updatedGeometries[r].normals.buffer),t.push(o.payload.updatedGeometries[r].positions.buffer));i._worker.postMessage(o,t),i._addUpdateMeshesList={},i._addUpdateGeometriesList={},i._toRemoveGeometryArray=[],i._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(o){var t=o.data;if(0!=t.error)return void e.Tools.Warn("error returned from worker!");switch(t.taskType){case 0:i._init=!0,i._scene.meshes.forEach(function(e){i.onMeshAdded(e)}),i._scene.getGeometries().forEach(function(e){i.onGeometryAdded(e)});break;case 1:i._runningUpdated--;break;case 2:i._runningCollisionTask=!1;var r=t.payload;if(!i._collisionsCallbackArray[r.collisionId])return;i._collisionsCallbackArray[r.collisionId](r.collisionId,e.Vector3.FromArray(r.newPosition),i._scene.getMeshByUniqueID(r.collidedMeshUniqueId)),i._collisionsCallbackArray[r.collisionId]=void 0}},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,this._runningCollisionTask=!1,this._addUpdateMeshesList={},this._addUpdateGeometriesList={},this._toRemoveGeometryArray=[],this._toRemoveMeshesArray=[]}return o.prototype.getNewPosition=function(e,o,i,t,r,s,n){if(!this._init,!this._collisionsCallbackArray[n]){e.divideToRef(i.radius,this._scaledPosition),o.divideToRef(i.radius,this._scaledVelocity),this._collisionsCallbackArray[n]=s;var a={collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:i.radius.asArray()},collisionId:n,excludedMeshUniqueId:r?r.uniqueId:null,maximumRetry:t},d={payload:a,taskType:2};this._worker.postMessage(d)}},o.prototype.init=function(o){this._scene=o,this._scene.registerAfterRender(this._afterRender);var i=e.WorkerIncluded?e.Engine.CodeRepository+"Collisions/babylon.collisionWorker.js":URL.createObjectURL(new Blob([e.CollisionWorker],{type:"application/javascript"}));this._worker=new Worker(i),this._worker.onmessage=this._onMessageFromWorker;var t={payload:{},taskType:0};this._worker.postMessage(t)},o.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},o.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},o.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},o.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},o.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},o.SerializeMesh=function(e){var o=[];e.subMeshes&&(o=e.subMeshes.map(function(e,o){return{position:o,verticesStart:e.verticesStart,verticesCount:e.verticesCount,indexStart:e.indexStart,indexCount:e.indexCount,hasMaterial:!!e.getMaterial(),sphereCenter:e.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:e.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:e.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:e.getBoundingInfo().boundingBox.maximumWorld.asArray()}}));var i=e.geometry?e.geometry.id:null;return{uniqueId:e.uniqueId,id:e.id,name:e.name,geometryId:i,sphereCenter:e.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:e.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:e.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:e.getBoundingInfo().boundingBox.maximumWorld.asArray(),worldMatrixFromCache:e.worldMatrixFromCache.asArray(),subMeshes:o,checkCollisions:e.checkCollisions}},o.SerializeGeometry=function(o){return{id:o.id,positions:new Float32Array(o.getVerticesData(e.VertexBuffer.PositionKind)||[]),normals:new Float32Array(o.getVerticesData(e.VertexBuffer.NormalKind)||[]),indices:new Int32Array(o.getIndices()||[])}},o}());e.CollisionCoordinatorWorker=o;var i=function(){function o(){this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this._finalPosition=e.Vector3.Zero()}return o.prototype.getNewPosition=function(e,o,i,t,r,s,n){e.divideToRef(i.radius,this._scaledPosition),o.divideToRef(i.radius,this._scaledVelocity),i.retry=0,i.initialVelocity=this._scaledVelocity,i.initialPosition=this._scaledPosition,this._collideWithWorld(this._scaledPosition,this._scaledVelocity,i,t,this._finalPosition,r),this._finalPosition.multiplyInPlace(i.radius),s(null,this._finalPosition,i.collidedMesh)},o.prototype.init=function(e){this._scene=e},o.prototype.destroy=function(){},o.prototype.onMeshAdded=function(e){},o.prototype.onMeshUpdated=function(e){},o.prototype.onMeshRemoved=function(e){},o.prototype.onGeometryAdded=function(e){},o.prototype.onGeometryUpdated=function(e){},o.prototype.onGeometryDeleted=function(e){},o.prototype._collideWithWorld=function(o,i,t,r,s,n){void 0===n&&(n=null);var a=10*e.Engine.CollisionsEpsilon;if(t.retry>=r)return void s.copyFrom(o);t._initialize(o,i,a);for(var d=0;dn.x?n.x:r,r=rn.y?n.y:s,s=so.x?i.x:o.x,r=i.y>o.y?i.y:o.y;return new t(n,r)},t.Transform=function(i,o){var n=i.x*o.m[0]+i.y*o.m[4],r=i.x*o.m[1]+i.y*o.m[5];return new t(n,r)},t.Distance=function(i,o){return Math.sqrt(t.DistanceSquared(i,o))},t.DistanceSquared=function(t,i){var o=t.x-i.x,n=t.y-i.y;return o*o+n*n},t}();t.Vector2=n;var r=function(){function i(t,i,o){this.x=t,this.y=i,this.z=o}return i.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},i.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},i.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.x,t[i+1]=this.y,t[i+2]=this.z,this},i.prototype.toQuaternion=function(){var t=new e(0,0,0,1),i=Math.cos(.5*(this.x+this.z)),o=Math.sin(.5*(this.x+this.z)),n=Math.cos(.5*(this.z-this.x)),r=Math.sin(.5*(this.z-this.x)),s=Math.cos(.5*this.y),a=Math.sin(.5*this.y);return t.x=n*a,t.y=-r*a,t.z=o*s,t.w=i*s,t},i.prototype.addInPlace=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},i.prototype.add=function(t){return new i(this.x+t.x,this.y+t.y,this.z+t.z)},i.prototype.addToRef=function(t,i){return i.x=this.x+t.x,i.y=this.y+t.y,i.z=this.z+t.z,this},i.prototype.subtractInPlace=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},i.prototype.subtract=function(t){return new i(this.x-t.x,this.y-t.y,this.z-t.z)},i.prototype.subtractToRef=function(t,i){return i.x=this.x-t.x,i.y=this.y-t.y,i.z=this.z-t.z,this},i.prototype.subtractFromFloats=function(t,o,n){return new i(this.x-t,this.y-o,this.z-n)},i.prototype.subtractFromFloatsToRef=function(t,i,o,n){return n.x=this.x-t,n.y=this.y-i,n.z=this.z-o,this},i.prototype.negate=function(){return new i(-this.x,-this.y,-this.z)},i.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this.z*=t,this},i.prototype.scale=function(t){return new i(this.x*t,this.y*t,this.z*t)},i.prototype.scaleToRef=function(t,i){i.x=this.x*t,i.y=this.y*t,i.z=this.z*t},i.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y&&this.z===t.z},i.prototype.equalsWithEpsilon=function(i){return Math.abs(this.x-i.x)this.x&&(this.x=t.x),t.y>this.y&&(this.y=t.y),t.z>this.z&&(this.z=t.z),this},i.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},i.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},i.prototype.normalize=function(){var t=this.length();if(0===t)return this;var i=1/t;return this.x*=i,this.y*=i,this.z*=i,this},i.prototype.clone=function(){return new i(this.x,this.y,this.z)},i.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},i.prototype.copyFromFloats=function(t,i,o){return this.x=t,this.y=i,this.z=o,this},i.GetClipFactor=function(t,o,n,r){var s=i.Dot(t,n)-r,e=i.Dot(o,n)-r,a=s/(s-e);return a},i.FromArray=function(t,o){return o||(o=0),new i(t[o],t[o+1],t[o+2])},i.FromArrayToRef=function(t,i,o){o.x=t[i],o.y=t[i+1],o.z=t[i+2]},i.FromFloatArrayToRef=function(t,i,o){o.x=t[i],o.y=t[i+1],o.z=t[i+2]},i.FromFloatsToRef=function(t,i,o,n){n.x=t,n.y=i,n.z=o},i.Zero=function(){return new i(0,0,0)},i.Up=function(){return new i(0,1,0)},i.TransformCoordinates=function(t,o){var n=i.Zero();return i.TransformCoordinatesToRef(t,o,n),n},i.TransformCoordinatesToRef=function(t,i,o){var n=t.x*i.m[0]+t.y*i.m[4]+t.z*i.m[8]+i.m[12],r=t.x*i.m[1]+t.y*i.m[5]+t.z*i.m[9]+i.m[13],s=t.x*i.m[2]+t.y*i.m[6]+t.z*i.m[10]+i.m[14],e=t.x*i.m[3]+t.y*i.m[7]+t.z*i.m[11]+i.m[15];o.x=n/e,o.y=r/e,o.z=s/e},i.TransformCoordinatesFromFloatsToRef=function(t,i,o,n,r){var s=t*n.m[0]+i*n.m[4]+o*n.m[8]+n.m[12],e=t*n.m[1]+i*n.m[5]+o*n.m[9]+n.m[13],a=t*n.m[2]+i*n.m[6]+o*n.m[10]+n.m[14],h=t*n.m[3]+i*n.m[7]+o*n.m[11]+n.m[15];r.x=s/h,r.y=e/h,r.z=a/h},i.TransformCoordinatesToRefSIMD=function(t,i,o){var n=SIMD.float32x4.loadXYZ(t._data,0),r=SIMD.float32x4.load(i.m,0),s=SIMD.float32x4.load(i.m,4),e=SIMD.float32x4.load(i.m,8),a=SIMD.float32x4.load(i.m,12),h=SIMD.float32x4.add(SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(n,0,0,0,0),r),SIMD.float32x4.mul(SIMD.float32x4.swizzle(n,1,1,1,1),s)),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(n,2,2,2,2),e),a));h=SIMD.float32x4.div(h,SIMD.float32x4.swizzle(h,3,3,3,3)),SIMD.float32x4.storeXYZ(o._data,0,h)},i.TransformCoordinatesFromFloatsToRefSIMD=function(t,i,o,n,r){var s=SIMD.float32x4.splat(t),e=SIMD.float32x4.splat(i),a=SIMD.float32x4.splat(o),h=SIMD.float32x4.load(n.m,0),u=SIMD.float32x4.load(n.m,4),m=SIMD.float32x4.load(n.m,8),l=SIMD.float32x4.load(n.m,12),f=SIMD.float32x4.add(SIMD.float32x4.add(SIMD.float32x4.mul(s,h),SIMD.float32x4.mul(e,u)),SIMD.float32x4.add(SIMD.float32x4.mul(a,m),l));f=SIMD.float32x4.div(f,SIMD.float32x4.swizzle(f,3,3,3,3)),SIMD.float32x4.storeXYZ(r._data,0,f)},i.TransformNormal=function(t,o){var n=i.Zero();return i.TransformNormalToRef(t,o,n),n},i.TransformNormalToRef=function(t,i,o){o.x=t.x*i.m[0]+t.y*i.m[4]+t.z*i.m[8],o.y=t.x*i.m[1]+t.y*i.m[5]+t.z*i.m[9],o.z=t.x*i.m[2]+t.y*i.m[6]+t.z*i.m[10]},i.TransformNormalFromFloatsToRef=function(t,i,o,n,r){r.x=t*n.m[0]+i*n.m[4]+o*n.m[8],r.y=t*n.m[1]+i*n.m[5]+o*n.m[9],r.z=t*n.m[2]+i*n.m[6]+o*n.m[10]},i.CatmullRom=function(t,o,n,r,s){var e=s*s,a=s*e,h=.5*(2*o.x+(-t.x+n.x)*s+(2*t.x-5*o.x+4*n.x-r.x)*e+(-t.x+3*o.x-3*n.x+r.x)*a),u=.5*(2*o.y+(-t.y+n.y)*s+(2*t.y-5*o.y+4*n.y-r.y)*e+(-t.y+3*o.y-3*n.y+r.y)*a),m=.5*(2*o.z+(-t.z+n.z)*s+(2*t.z-5*o.z+4*n.z-r.z)*e+(-t.z+3*o.z-3*n.z+r.z)*a);return new i(h,u,m)},i.Clamp=function(t,o,n){var r=t.x;r=r>n.x?n.x:r,r=rn.y?n.y:s,s=sn.z?n.z:e,e=ethis.x&&(this.x=t.x),t.y>this.y&&(this.y=t.y),t.z>this.z&&(this.z=t.z),t.w>this.w&&(this.w=t.w),this},i.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},i.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},i.prototype.normalize=function(){var t=this.length();if(0===t)return this;var i=1/t;return this.x*=i,this.y*=i,this.z*=i,this.w*=i,this},i.prototype.clone=function(){return new i(this.x,this.y,this.z,this.w)},i.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},i.prototype.copyFromFloats=function(t,i,o,n){return this.x=t,this.y=i,this.z=o,this.w=n,this},i.FromArray=function(t,o){return o||(o=0),new i(t[o],t[o+1],t[o+2],t[o+3])},i.FromArrayToRef=function(t,i,o){o.x=t[i],o.y=t[i+1],o.z=t[i+2],o.w=t[i+3]},i.FromFloatArrayToRef=function(t,i,o){o.x=t[i],o.y=t[i+1],o.z=t[i+2],o.w=t[i+3]},i.FromFloatsToRef=function(t,i,o,n,r){r.x=t,r.y=i,r.z=o,r.w=n},i.Zero=function(){return new i(0,0,0,0)},i.Normalize=function(t){var o=i.Zero();return i.NormalizeToRef(t,o),o},i.NormalizeToRef=function(t,i){i.copyFrom(t),i.normalize()},i.Minimize=function(t,i){var o=t.clone();return o.MinimizeInPlace(i),o},i.Maximize=function(t,i){var o=t.clone();return o.MaximizeInPlace(i),o},i.Distance=function(t,o){return Math.sqrt(i.DistanceSquared(t,o))},i.DistanceSquared=function(t,i){var o=t.x-i.x,n=t.y-i.y,r=t.z-i.z,s=t.w-i.w;return o*o+n*n+r*r+s*s},i.Center=function(t,i){var o=t.add(i);return o.scaleInPlace(.5),o},i}();t.Vector4=s;var e=function(){function t(t,i,o,n){void 0===t&&(t=0),void 0===i&&(i=0),void 0===o&&(o=0),void 0===n&&(n=1),this.x=t,this.y=i,this.z=o,this.w=n}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},t.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},t.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},t.prototype.copyFromFloats=function(t,i,o,n){return this.x=t,this.y=i,this.z=o,this.w=n,this},t.prototype.add=function(i){return new t(this.x+i.x,this.y+i.y,this.z+i.z,this.w+i.w)},t.prototype.subtract=function(i){return new t(this.x-i.x,this.y-i.y,this.z-i.z,this.w-i.w)},t.prototype.scale=function(i){return new t(this.x*i,this.y*i,this.z*i,this.w*i)},t.prototype.multiply=function(i){var o=new t(0,0,0,1);return this.multiplyToRef(i,o),o},t.prototype.multiplyToRef=function(t,i){return i.x=this.x*t.w+this.y*t.z-this.z*t.y+this.w*t.x,i.y=-this.x*t.z+this.y*t.w+this.z*t.x+this.w*t.y,i.z=this.x*t.y-this.y*t.x+this.z*t.w+this.w*t.z,i.w=-this.x*t.x-this.y*t.y-this.z*t.z+this.w*t.w,this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},t.prototype.normalize=function(){var t=1/this.length();return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.toEulerAngles=function(){var t=r.Zero();return this.toEulerAnglesToRef(t),t},t.prototype.toEulerAnglesToRef=function(t){var i=this.x,o=this.y,n=this.z,r=this.w,s=i*o,e=i*n,a=r*o,h=r*n,u=r*i,m=o*n,l=i*i,f=o*o,x=l+f;return 0!==x&&1!==x?(t.x=Math.atan2(e+a,u-m),t.y=Math.acos(1-2*x),t.z=Math.atan2(e-a,u+m)):0===x?(t.x=0,t.y=0,t.z=Math.atan2(s-h,.5-f-n*n)):(t.x=Math.atan2(s-h,.5-f-n*n),t.y=Math.PI,t.z=0),this},t.prototype.toRotationMatrix=function(t){var i=this.x*this.x,o=this.y*this.y,n=this.z*this.z,r=this.x*this.y,s=this.z*this.w,e=this.z*this.x,a=this.y*this.w,h=this.y*this.z,u=this.x*this.w;return t.m[0]=1-2*(o+n),t.m[1]=2*(r+s),t.m[2]=2*(e-a),t.m[3]=0,t.m[4]=2*(r-s),t.m[5]=1-2*(n+i),t.m[6]=2*(h+u),t.m[7]=0,t.m[8]=2*(e+a),t.m[9]=2*(h-u),t.m[10]=1-2*(o+i),t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0,t.m[15]=1,this},t.prototype.fromRotationMatrix=function(i){return t.FromRotationMatrixToRef(i,this),this},t.FromRotationMatrix=function(i){var o=new t;return t.FromRotationMatrixToRef(i,o),o},t.FromRotationMatrixToRef=function(t,i){var o,n=t.m,r=n[0],s=n[4],e=n[8],a=n[1],h=n[5],u=n[9],m=n[2],l=n[6],f=n[10],x=r+h+f;x>0?(o=.5/Math.sqrt(x+1),i.w=.25/o,i.x=(l-u)*o,i.y=(e-m)*o,i.z=(a-s)*o):r>h&&r>f?(o=2*Math.sqrt(1+r-h-f),i.w=(l-u)/o,i.x=.25*o,i.y=(s+a)/o,i.z=(e+m)/o):h>f?(o=2*Math.sqrt(1+h-r-f),i.w=(e-m)/o,i.x=(s+a)/o,i.y=.25*o,i.z=(u+l)/o):(o=2*Math.sqrt(1+f-r-h),i.w=(a-s)/o,i.x=(e+m)/o,i.y=(u+l)/o,i.z=.25*o)},t.Inverse=function(i){return new t(-i.x,-i.y,-i.z,i.w)},t.Identity=function(){return new t(0,0,0,1)},t.RotationAxis=function(i,o){var n=new t,r=Math.sin(o/2);return n.w=Math.cos(o/2),n.x=i.x*r,n.y=i.y*r,n.z=i.z*r,n},t.FromArray=function(i,o){return o||(o=0),new t(i[o],i[o+1],i[o+2],i[o+3])},t.RotationYawPitchRoll=function(i,o,n){var r=new t;return t.RotationYawPitchRollToRef(i,o,n,r),r},t.RotationYawPitchRollToRef=function(t,i,o,n){var r=.5*o,s=.5*i,e=.5*t,a=Math.sin(r),h=Math.cos(r),u=Math.sin(s),m=Math.cos(s),l=Math.sin(e),f=Math.cos(e);n.x=f*u*h+l*m*a,n.y=l*m*h-f*u*a,n.z=f*m*a-l*u*h,n.w=f*m*h+l*u*a},t.RotationAlphaBetaGamma=function(i,o,n){var r=new t;return t.RotationAlphaBetaGammaToRef(i,o,n,r),r},t.RotationAlphaBetaGammaToRef=function(t,i,o,n){var r=.5*(o+t),s=.5*(o-t),e=.5*i;n.x=Math.cos(s)*Math.sin(e),n.y=Math.sin(s)*Math.sin(e),n.z=Math.sin(r)*Math.cos(e),n.w=Math.cos(r)*Math.cos(e)},t.Slerp=function(i,o,n){var r,s,e=n,a=i.x*o.x+i.y*o.y+i.z*o.z+i.w*o.w,h=!1;if(0>a&&(h=!0,a=-a),a>.999999)s=1-e,r=h?-e:e;else{var u=Math.acos(a),m=1/Math.sin(u);s=Math.sin((1-e)*u)*m,r=h?-Math.sin(e*u)*m:Math.sin(e*u)*m}return new t(s*i.x+r*o.x,s*i.y+r*o.y,s*i.z+r*o.z,s*i.w+r*o.w)},t}();t.Quaternion=e;var a=function(){function i(){this.m=new Float32Array(16)}return i.prototype.isIdentity=function(){return 1!==this.m[0]||1!==this.m[5]||1!==this.m[10]||1!==this.m[15]?!1:0!==this.m[1]||0!==this.m[2]||0!==this.m[3]||0!==this.m[4]||0!==this.m[6]||0!==this.m[7]||0!==this.m[8]||0!==this.m[9]||0!==this.m[11]||0!==this.m[12]||0!==this.m[13]||0!==this.m[14]?!1:!0},i.prototype.determinant=function(){var t=this.m[10]*this.m[15]-this.m[11]*this.m[14],i=this.m[9]*this.m[15]-this.m[11]*this.m[13],o=this.m[9]*this.m[14]-this.m[10]*this.m[13],n=this.m[8]*this.m[15]-this.m[11]*this.m[12],r=this.m[8]*this.m[14]-this.m[10]*this.m[12],s=this.m[8]*this.m[13]-this.m[9]*this.m[12];return this.m[0]*(this.m[5]*t-this.m[6]*i+this.m[7]*o)-this.m[1]*(this.m[4]*t-this.m[6]*n+this.m[7]*r)+this.m[2]*(this.m[4]*i-this.m[5]*n+this.m[7]*s)-this.m[3]*(this.m[4]*o-this.m[5]*r+this.m[6]*s)},i.prototype.toArray=function(){return this.m},i.prototype.asArray=function(){return this.toArray()},i.prototype.invert=function(){return this.invertToRef(this),this},i.prototype.invertToRef=function(t){var i=this.m[0],o=this.m[1],n=this.m[2],r=this.m[3],s=this.m[4],e=this.m[5],a=this.m[6],h=this.m[7],u=this.m[8],m=this.m[9],l=this.m[10],f=this.m[11],x=this.m[12],y=this.m[13],c=this.m[14],p=this.m[15],z=l*p-f*c,M=m*p-f*y,w=m*c-l*y,d=u*p-f*x,I=u*c-l*x,D=u*y-m*x,S=e*z-a*M+h*w,v=-(s*z-a*d+h*I),g=s*M-e*d+h*D,T=-(s*w-e*I+a*D),R=1/(i*S+o*v+n*g+r*T),_=a*p-h*c,b=e*p-h*y,A=e*c-a*y,F=s*p-h*x,P=s*c-a*x,C=s*y-e*x,L=a*f-h*l,q=e*f-h*m,E=e*l-a*m,Z=s*f-h*u,V=s*l-a*u,N=s*m-e*u;return t.m[0]=S*R,t.m[4]=v*R,t.m[8]=g*R,t.m[12]=T*R,t.m[1]=-(o*z-n*M+r*w)*R,t.m[5]=(i*z-n*d+r*I)*R,t.m[9]=-(i*M-o*d+r*D)*R,t.m[13]=(i*w-o*I+n*D)*R,t.m[2]=(o*_-n*b+r*A)*R,t.m[6]=-(i*_-n*F+r*P)*R,t.m[10]=(i*b-o*F+r*C)*R,t.m[14]=-(i*A-o*P+n*C)*R,t.m[3]=-(o*L-n*q+r*E)*R,t.m[7]=(i*L-n*Z+r*V)*R,t.m[11]=-(i*q-o*Z+r*N)*R,t.m[15]=(i*E-o*V+n*N)*R,this},i.prototype.invertToRefSIMD=function(t){var i,o,n,r,s,e,a,h,u,m,l=this.m,f=t.m,x=SIMD.float32x4.load(l,0),y=SIMD.float32x4.load(l,4),c=SIMD.float32x4.load(l,8),p=SIMD.float32x4.load(l,12);return s=SIMD.float32x4.shuffle(x,y,0,1,4,5),o=SIMD.float32x4.shuffle(c,p,0,1,4,5),i=SIMD.float32x4.shuffle(s,o,0,2,4,6),o=SIMD.float32x4.shuffle(o,s,1,3,5,7),s=SIMD.float32x4.shuffle(x,y,2,3,6,7),r=SIMD.float32x4.shuffle(c,p,2,3,6,7),n=SIMD.float32x4.shuffle(s,r,0,2,4,6),r=SIMD.float32x4.shuffle(r,s,1,3,5,7),s=SIMD.float32x4.mul(n,r),s=SIMD.float32x4.swizzle(s,1,0,3,2),e=SIMD.float32x4.mul(o,s),a=SIMD.float32x4.mul(i,s),s=SIMD.float32x4.swizzle(s,2,3,0,1),e=SIMD.float32x4.sub(SIMD.float32x4.mul(o,s),e),a=SIMD.float32x4.sub(SIMD.float32x4.mul(i,s),a),a=SIMD.float32x4.swizzle(a,2,3,0,1),s=SIMD.float32x4.mul(o,n),s=SIMD.float32x4.swizzle(s,1,0,3,2),e=SIMD.float32x4.add(SIMD.float32x4.mul(r,s),e),u=SIMD.float32x4.mul(i,s),s=SIMD.float32x4.swizzle(s,2,3,0,1),e=SIMD.float32x4.sub(e,SIMD.float32x4.mul(r,s)),u=SIMD.float32x4.sub(SIMD.float32x4.mul(i,s),u),u=SIMD.float32x4.swizzle(u,2,3,0,1),s=SIMD.float32x4.mul(SIMD.float32x4.swizzle(o,2,3,0,1),r),s=SIMD.float32x4.swizzle(s,1,0,3,2),n=SIMD.float32x4.swizzle(n,2,3,0,1),e=SIMD.float32x4.add(SIMD.float32x4.mul(n,s),e),h=SIMD.float32x4.mul(i,s),s=SIMD.float32x4.swizzle(s,2,3,0,1),e=SIMD.float32x4.sub(e,SIMD.float32x4.mul(n,s)),h=SIMD.float32x4.sub(SIMD.float32x4.mul(i,s),h),h=SIMD.float32x4.swizzle(h,2,3,0,1),s=SIMD.float32x4.mul(i,o),s=SIMD.float32x4.swizzle(s,1,0,3,2),h=SIMD.float32x4.add(SIMD.float32x4.mul(r,s),h),u=SIMD.float32x4.sub(SIMD.float32x4.mul(n,s),u),s=SIMD.float32x4.swizzle(s,2,3,0,1),h=SIMD.float32x4.sub(SIMD.float32x4.mul(r,s),h),u=SIMD.float32x4.sub(u,SIMD.float32x4.mul(n,s)),s=SIMD.float32x4.mul(i,r),s=SIMD.float32x4.swizzle(s,1,0,3,2),a=SIMD.float32x4.sub(a,SIMD.float32x4.mul(n,s)),h=SIMD.float32x4.add(SIMD.float32x4.mul(o,s),h),s=SIMD.float32x4.swizzle(s,2,3,0,1),a=SIMD.float32x4.add(SIMD.float32x4.mul(n,s),a),h=SIMD.float32x4.sub(h,SIMD.float32x4.mul(o,s)),s=SIMD.float32x4.mul(i,n),s=SIMD.float32x4.swizzle(s,1,0,3,2),a=SIMD.float32x4.add(SIMD.float32x4.mul(r,s),a),u=SIMD.float32x4.sub(u,SIMD.float32x4.mul(o,s)),s=SIMD.float32x4.swizzle(s,2,3,0,1),a=SIMD.float32x4.sub(a,SIMD.float32x4.mul(r,s)),u=SIMD.float32x4.add(SIMD.float32x4.mul(o,s),u),m=SIMD.float32x4.mul(i,e),m=SIMD.float32x4.add(SIMD.float32x4.swizzle(m,2,3,0,1),m),m=SIMD.float32x4.add(SIMD.float32x4.swizzle(m,1,0,3,2),m),s=SIMD.float32x4.reciprocalApproximation(m),m=SIMD.float32x4.sub(SIMD.float32x4.add(s,s),SIMD.float32x4.mul(m,SIMD.float32x4.mul(s,s))),m=SIMD.float32x4.swizzle(m,0,0,0,0),e=SIMD.float32x4.mul(m,e),a=SIMD.float32x4.mul(m,a),h=SIMD.float32x4.mul(m,h),u=SIMD.float32x4.mul(m,u),SIMD.float32x4.store(f,0,e),SIMD.float32x4.store(f,4,a),SIMD.float32x4.store(f,8,h),SIMD.float32x4.store(f,12,u),this},i.prototype.setTranslation=function(t){return this.m[12]=t.x,this.m[13]=t.y,this.m[14]=t.z,this},i.prototype.multiply=function(t){var o=new i;return this.multiplyToRef(t,o),o},i.prototype.copyFrom=function(t){for(var i=0;16>i;i++)this.m[i]=t.m[i];return this},i.prototype.copyToArray=function(t,i){void 0===i&&(i=0);for(var o=0;16>o;o++)t[i+o]=this.m[o];return this},i.prototype.multiplyToRef=function(t,i){return this.multiplyToArray(t,i.m,0),this},i.prototype.multiplyToArray=function(t,i,o){var n=this.m[0],r=this.m[1],s=this.m[2],e=this.m[3],a=this.m[4],h=this.m[5],u=this.m[6],m=this.m[7],l=this.m[8],f=this.m[9],x=this.m[10],y=this.m[11],c=this.m[12],p=this.m[13],z=this.m[14],M=this.m[15],w=t.m[0],d=t.m[1],I=t.m[2],D=t.m[3],S=t.m[4],v=t.m[5],g=t.m[6],T=t.m[7],R=t.m[8],_=t.m[9],b=t.m[10],A=t.m[11],F=t.m[12],P=t.m[13],C=t.m[14],L=t.m[15];return i[o]=n*w+r*S+s*R+e*F,i[o+1]=n*d+r*v+s*_+e*P,i[o+2]=n*I+r*g+s*b+e*C,i[o+3]=n*D+r*T+s*A+e*L,i[o+4]=a*w+h*S+u*R+m*F,i[o+5]=a*d+h*v+u*_+m*P,i[o+6]=a*I+h*g+u*b+m*C,i[o+7]=a*D+h*T+u*A+m*L,i[o+8]=l*w+f*S+x*R+y*F,i[o+9]=l*d+f*v+x*_+y*P,i[o+10]=l*I+f*g+x*b+y*C,i[o+11]=l*D+f*T+x*A+y*L,i[o+12]=c*w+p*S+z*R+M*F,i[o+13]=c*d+p*v+z*_+M*P,i[o+14]=c*I+p*g+z*b+M*C,i[o+15]=c*D+p*T+z*A+M*L,this},i.prototype.multiplyToArraySIMD=function(t,i,o){void 0===o&&(o=0);var n=this.m,r=t.m,s=SIMD.float32x4.load(r,0),e=SIMD.float32x4.load(r,4),a=SIMD.float32x4.load(r,8),h=SIMD.float32x4.load(r,12),u=SIMD.float32x4.load(n,0);SIMD.float32x4.store(i,o+0,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,0,0,0,0),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,1,1,1,1),e),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,3,3,3,3),h)))));var m=SIMD.float32x4.load(n,4);SIMD.float32x4.store(i,o+4,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,0,0,0,0),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,1,1,1,1),e),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,3,3,3,3),h)))));var l=SIMD.float32x4.load(n,8);SIMD.float32x4.store(i,o+8,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,0,0,0,0),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,1,1,1,1),e),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,3,3,3,3),h)))));var f=SIMD.float32x4.load(n,12);SIMD.float32x4.store(i,o+12,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,0,0,0,0),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,1,1,1,1),e),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,3,3,3,3),h)))))},i.prototype.equals=function(t){return t&&this.m[0]===t.m[0]&&this.m[1]===t.m[1]&&this.m[2]===t.m[2]&&this.m[3]===t.m[3]&&this.m[4]===t.m[4]&&this.m[5]===t.m[5]&&this.m[6]===t.m[6]&&this.m[7]===t.m[7]&&this.m[8]===t.m[8]&&this.m[9]===t.m[9]&&this.m[10]===t.m[10]&&this.m[11]===t.m[11]&&this.m[12]===t.m[12]&&this.m[13]===t.m[13]&&this.m[14]===t.m[14]&&this.m[15]===t.m[15]},i.prototype.clone=function(){return i.FromValues(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5],this.m[6],this.m[7],this.m[8],this.m[9],this.m[10],this.m[11],this.m[12],this.m[13],this.m[14],this.m[15])},i.prototype.decompose=function(o,n,r){r.x=this.m[12],r.y=this.m[13],r.z=this.m[14];var s=t.Tools.Sign(this.m[0]*this.m[1]*this.m[2]*this.m[3])<0?-1:1,a=t.Tools.Sign(this.m[4]*this.m[5]*this.m[6]*this.m[7])<0?-1:1,h=t.Tools.Sign(this.m[8]*this.m[9]*this.m[10]*this.m[11])<0?-1:1;if(o.x=s*Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]+this.m[2]*this.m[2]),o.y=a*Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]+this.m[6]*this.m[6]),o.z=h*Math.sqrt(this.m[8]*this.m[8]+this.m[9]*this.m[9]+this.m[10]*this.m[10]),0===o.x||0===o.y||0===o.z)return n.x=0,n.y=0,n.z=0,n.w=1,!1;var u=i.FromValues(this.m[0]/o.x,this.m[1]/o.x,this.m[2]/o.x,0,this.m[4]/o.y,this.m[5]/o.y,this.m[6]/o.y,0,this.m[8]/o.z,this.m[9]/o.z,this.m[10]/o.z,0,0,0,0,1);return e.FromRotationMatrixToRef(u,n),!0},i.FromArray=function(t,o){var n=new i;return o||(o=0),i.FromArrayToRef(t,o,n),n},i.FromArrayToRef=function(t,i,o){for(var n=0;16>n;n++)o.m[n]=t[n+i]},i.FromValuesToRef=function(t,i,o,n,r,s,e,a,h,u,m,l,f,x,y,c,p){\np.m[0]=t,p.m[1]=i,p.m[2]=o,p.m[3]=n,p.m[4]=r,p.m[5]=s,p.m[6]=e,p.m[7]=a,p.m[8]=h,p.m[9]=u,p.m[10]=m,p.m[11]=l,p.m[12]=f,p.m[13]=x,p.m[14]=y,p.m[15]=c},i.FromValues=function(t,o,n,r,s,e,a,h,u,m,l,f,x,y,c,p){var z=new i;return z.m[0]=t,z.m[1]=o,z.m[2]=n,z.m[3]=r,z.m[4]=s,z.m[5]=e,z.m[6]=a,z.m[7]=h,z.m[8]=u,z.m[9]=m,z.m[10]=l,z.m[11]=f,z.m[12]=x,z.m[13]=y,z.m[14]=c,z.m[15]=p,z},i.Compose=function(t,o,n){var r=i.FromValues(t.x,0,0,0,0,t.y,0,0,0,0,t.z,0,0,0,0,1),s=i.Identity();return o.toRotationMatrix(s),r=r.multiply(s),r.setTranslation(n),r},i.Identity=function(){return i.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},i.IdentityToRef=function(t){i.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,t)},i.Zero=function(){return i.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},i.RotationX=function(t){var o=new i;return i.RotationXToRef(t,o),o},i.Invert=function(t){var o=new i;return t.invertToRef(o),o},i.RotationXToRef=function(t,i){var o=Math.sin(t),n=Math.cos(t);i.m[0]=1,i.m[15]=1,i.m[5]=n,i.m[10]=n,i.m[9]=-o,i.m[6]=o,i.m[1]=0,i.m[2]=0,i.m[3]=0,i.m[4]=0,i.m[7]=0,i.m[8]=0,i.m[11]=0,i.m[12]=0,i.m[13]=0,i.m[14]=0},i.RotationY=function(t){var o=new i;return i.RotationYToRef(t,o),o},i.RotationYToRef=function(t,i){var o=Math.sin(t),n=Math.cos(t);i.m[5]=1,i.m[15]=1,i.m[0]=n,i.m[2]=-o,i.m[8]=o,i.m[10]=n,i.m[1]=0,i.m[3]=0,i.m[4]=0,i.m[6]=0,i.m[7]=0,i.m[9]=0,i.m[11]=0,i.m[12]=0,i.m[13]=0,i.m[14]=0},i.RotationZ=function(t){var o=new i;return i.RotationZToRef(t,o),o},i.RotationZToRef=function(t,i){var o=Math.sin(t),n=Math.cos(t);i.m[10]=1,i.m[15]=1,i.m[0]=n,i.m[1]=o,i.m[4]=-o,i.m[5]=n,i.m[2]=0,i.m[3]=0,i.m[6]=0,i.m[7]=0,i.m[8]=0,i.m[9]=0,i.m[11]=0,i.m[12]=0,i.m[13]=0,i.m[14]=0},i.RotationAxis=function(t,o){var n=Math.sin(-o),r=Math.cos(-o),s=1-r;t.normalize();var e=i.Zero();return e.m[0]=t.x*t.x*s+r,e.m[1]=t.x*t.y*s-t.z*n,e.m[2]=t.x*t.z*s+t.y*n,e.m[3]=0,e.m[4]=t.y*t.x*s+t.z*n,e.m[5]=t.y*t.y*s+r,e.m[6]=t.y*t.z*s-t.x*n,e.m[7]=0,e.m[8]=t.z*t.x*s-t.y*n,e.m[9]=t.z*t.y*s+t.x*n,e.m[10]=t.z*t.z*s+r,e.m[11]=0,e.m[15]=1,e},i.RotationYawPitchRoll=function(t,o,n){var r=new i;return i.RotationYawPitchRollToRef(t,o,n,r),r},i.RotationYawPitchRollToRef=function(t,i,o,n){e.RotationYawPitchRollToRef(t,i,o,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(n)},i.Scaling=function(t,o,n){var r=i.Zero();return i.ScalingToRef(t,o,n,r),r},i.ScalingToRef=function(t,i,o,n){n.m[0]=t,n.m[1]=0,n.m[2]=0,n.m[3]=0,n.m[4]=0,n.m[5]=i,n.m[6]=0,n.m[7]=0,n.m[8]=0,n.m[9]=0,n.m[10]=o,n.m[11]=0,n.m[12]=0,n.m[13]=0,n.m[14]=0,n.m[15]=1},i.Translation=function(t,o,n){var r=i.Identity();return i.TranslationToRef(t,o,n,r),r},i.TranslationToRef=function(t,o,n,r){i.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,t,o,n,1,r)},i.LookAtLH=function(t,o,n){var r=i.Zero();return i.LookAtLHToRef(t,o,n,r),r},i.LookAtLHToRef=function(t,o,n,s){o.subtractToRef(t,this._zAxis),this._zAxis.normalize(),r.CrossToRef(n,this._zAxis,this._xAxis),this._xAxis.normalize(),r.CrossToRef(this._zAxis,this._xAxis,this._yAxis),this._yAxis.normalize();var e=-r.Dot(this._xAxis,t),a=-r.Dot(this._yAxis,t),h=-r.Dot(this._zAxis,t);return i.FromValuesToRef(this._xAxis.x,this._yAxis.x,this._zAxis.x,0,this._xAxis.y,this._yAxis.y,this._zAxis.y,0,this._xAxis.z,this._yAxis.z,this._zAxis.z,0,e,a,h,1,s)},i.LookAtLHToRefSIMD=function(t,i,o,n){var r=n.m,s=SIMD.float32x4(i.x,i.y,i.z,0),e=SIMD.float32x4(t.x,t.y,t.z,0),a=SIMD.float32x4(o.x,o.y,o.z,0),h=SIMD.float32x4.sub(s,e),u=SIMD.float32x4.mul(h,h);u=SIMD.float32x4.add(u,SIMD.float32x4.add(SIMD.float32x4.swizzle(u,1,2,0,3),SIMD.float32x4.swizzle(u,2,0,1,3))),h=SIMD.float32x4.mul(h,SIMD.float32x4.reciprocalSqrtApproximation(u)),u=SIMD.float32x4.mul(a,a),u=SIMD.float32x4.add(u,SIMD.float32x4.add(SIMD.float32x4.swizzle(u,1,2,0,3),SIMD.float32x4.swizzle(u,2,0,1,3))),a=SIMD.float32x4.mul(a,SIMD.float32x4.reciprocalSqrtApproximation(u));var m=SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(h,1,2,0,3),SIMD.float32x4.swizzle(a,2,0,1,3)),SIMD.float32x4.mul(SIMD.float32x4.swizzle(h,2,0,1,3),SIMD.float32x4.swizzle(a,1,2,0,3)));u=SIMD.float32x4.mul(m,m),u=SIMD.float32x4.add(u,SIMD.float32x4.add(SIMD.float32x4.swizzle(u,1,2,0,3),SIMD.float32x4.swizzle(u,2,0,1,3))),m=SIMD.float32x4.mul(m,SIMD.float32x4.reciprocalSqrtApproximation(u));var l=SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,1,2,0,3),SIMD.float32x4.swizzle(h,2,0,1,3)),SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,2,0,1,3),SIMD.float32x4.swizzle(h,1,2,0,3)));u=SIMD.float32x4.mul(m,m),u=SIMD.float32x4.add(u,SIMD.float32x4.add(SIMD.float32x4.swizzle(u,1,2,0,3),SIMD.float32x4.swizzle(u,2,0,1,3))),m=SIMD.float32x4.mul(m,SIMD.float32x4.reciprocalSqrtApproximation(u));var f=SIMD.float32x4.splat(0);m=SIMD.float32x4.neg(m);var x=SIMD.float32x4.shuffle(m,l,0,1,4,5),y=SIMD.float32x4.shuffle(h,f,0,1,4,5),c=SIMD.float32x4.shuffle(x,y,0,2,4,6),p=SIMD.float32x4.shuffle(x,y,1,3,5,7);x=SIMD.float32x4.shuffle(m,l,2,3,6,7),y=SIMD.float32x4.shuffle(h,f,2,3,6,7);var z=SIMD.float32x4.shuffle(x,y,0,2,4,6),M=SIMD.float32x4(0,0,0,1),w=SIMD.float32x4(1,0,0,0),d=SIMD.float32x4(0,1,0,0),I=SIMD.float32x4(0,0,1,0),D=SIMD.float32x4.neg(e);D=SIMD.float32x4.withW(D,1),SIMD.float32x4.store(r,0,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(w,0,0,0,0),c),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(w,1,1,1,1),p),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(w,2,2,2,2),z),SIMD.float32x4.mul(SIMD.float32x4.swizzle(w,3,3,3,3),M))))),SIMD.float32x4.store(r,4,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,0,0,0,0),c),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,1,1,1,1),p),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,2,2,2,2),z),SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,3,3,3,3),M))))),SIMD.float32x4.store(r,8,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(I,0,0,0,0),c),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(I,1,1,1,1),p),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(I,2,2,2,2),z),SIMD.float32x4.mul(SIMD.float32x4.swizzle(I,3,3,3,3),M))))),SIMD.float32x4.store(r,12,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(D,0,0,0,0),c),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(D,1,1,1,1),p),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(D,2,2,2,2),z),SIMD.float32x4.mul(SIMD.float32x4.swizzle(D,3,3,3,3),M)))))},i.OrthoLH=function(t,o,n,r){var s=i.Zero();return i.OrthoLHToRef(t,o,n,r,s),s},i.OrthoLHToRef=function(t,o,n,r,s){var e=2/t,a=2/o,h=1/(r-n),u=n/(n-r);i.FromValuesToRef(e,0,0,0,0,a,0,0,0,0,h,0,0,0,u,1,s)},i.OrthoOffCenterLH=function(t,o,n,r,s,e){var a=i.Zero();return i.OrthoOffCenterLHToRef(t,o,n,r,s,e,a),a},i.OrthoOffCenterLHToRef=function(t,i,o,n,r,s,e){e.m[0]=2/(i-t),e.m[1]=e.m[2]=e.m[3]=0,e.m[5]=2/(n-o),e.m[4]=e.m[6]=e.m[7]=0,e.m[10]=-1/(r-s),e.m[8]=e.m[9]=e.m[11]=0,e.m[12]=(t+i)/(t-i),e.m[13]=(n+o)/(o-n),e.m[14]=r/(r-s),e.m[15]=1},i.PerspectiveLH=function(t,o,n,r){var s=i.Zero();return s.m[0]=2*n/t,s.m[1]=s.m[2]=s.m[3]=0,s.m[5]=2*n/o,s.m[4]=s.m[6]=s.m[7]=0,s.m[10]=-r/(n-r),s.m[8]=s.m[9]=0,s.m[11]=1,s.m[12]=s.m[13]=s.m[15]=0,s.m[14]=n*r/(n-r),s},i.PerspectiveFovLH=function(t,o,n,r){var s=i.Zero();return i.PerspectiveFovLHToRef(t,o,n,r,s),s},i.PerspectiveFovLHToRef=function(i,o,n,r,s,e){void 0===e&&(e=t.Camera.FOVMODE_VERTICAL_FIXED);var a=1/Math.tan(.5*i),h=e===t.Camera.FOVMODE_VERTICAL_FIXED;s.m[0]=h?a/o:a,s.m[1]=s.m[2]=s.m[3]=0,s.m[5]=h?a:a*o,s.m[4]=s.m[6]=s.m[7]=0,s.m[8]=s.m[9]=0,s.m[10]=-r/(n-r),s.m[11]=1,s.m[12]=s.m[13]=s.m[15]=0,s.m[14]=n*r/(n-r)},i.GetFinalMatrix=function(t,o,n,r,s,e){var a=t.width,h=t.height,u=t.x,m=t.y,l=i.FromValues(a/2,0,0,0,0,-h/2,0,0,0,0,e-s,0,u+a/2,h/2+m,s,1);return o.multiply(n).multiply(r).multiply(l)},i.Transpose=function(t){var o=new i;return o.m[0]=t.m[0],o.m[1]=t.m[4],o.m[2]=t.m[8],o.m[3]=t.m[12],o.m[4]=t.m[1],o.m[5]=t.m[5],o.m[6]=t.m[9],o.m[7]=t.m[13],o.m[8]=t.m[2],o.m[9]=t.m[6],o.m[10]=t.m[10],o.m[11]=t.m[14],o.m[12]=t.m[3],o.m[13]=t.m[7],o.m[14]=t.m[11],o.m[15]=t.m[15],o},i.Reflection=function(t){var o=new i;return i.ReflectionToRef(t,o),o},i.ReflectionToRef=function(t,i){t.normalize();var o=t.normal.x,n=t.normal.y,r=t.normal.z,s=-2*o,e=-2*n,a=-2*r;i.m[0]=s*o+1,i.m[1]=e*o,i.m[2]=a*o,i.m[3]=0,i.m[4]=s*n,i.m[5]=e*n+1,i.m[6]=a*n,i.m[7]=0,i.m[8]=s*r,i.m[9]=e*r,i.m[10]=a*r+1,i.m[11]=0,i.m[12]=s*t.d,i.m[13]=e*t.d,i.m[14]=a*t.d,i.m[15]=1},i._tempQuaternion=new e,i._xAxis=r.Zero(),i._yAxis=r.Zero(),i._zAxis=r.Zero(),i}();t.Matrix=a;var h=function(){function t(t,i,o,n){this.normal=new r(t,i,o),this.d=n}return t.prototype.asArray=function(){return[this.normal.x,this.normal.y,this.normal.z,this.d]},t.prototype.clone=function(){return new t(this.normal.x,this.normal.y,this.normal.z,this.d)},t.prototype.normalize=function(){var t=Math.sqrt(this.normal.x*this.normal.x+this.normal.y*this.normal.y+this.normal.z*this.normal.z),i=0;return 0!==t&&(i=1/t),this.normal.x*=i,this.normal.y*=i,this.normal.z*=i,this.d*=i,this},t.prototype.transform=function(i){var o=a.Transpose(i),n=this.normal.x,r=this.normal.y,s=this.normal.z,e=this.d,h=n*o.m[0]+r*o.m[1]+s*o.m[2]+e*o.m[3],u=n*o.m[4]+r*o.m[5]+s*o.m[6]+e*o.m[7],m=n*o.m[8]+r*o.m[9]+s*o.m[10]+e*o.m[11],l=n*o.m[12]+r*o.m[13]+s*o.m[14]+e*o.m[15];return new t(h,u,m,l)},t.prototype.dotCoordinate=function(t){return this.normal.x*t.x+this.normal.y*t.y+this.normal.z*t.z+this.d},t.prototype.copyFromPoints=function(t,i,o){var n,r=i.x-t.x,s=i.y-t.y,e=i.z-t.z,a=o.x-t.x,h=o.y-t.y,u=o.z-t.z,m=s*u-e*h,l=e*a-r*u,f=r*h-s*a,x=Math.sqrt(m*m+l*l+f*f);return n=0!==x?1/x:0,this.normal.x=m*n,this.normal.y=l*n,this.normal.z=f*n,this.d=-(this.normal.x*t.x+this.normal.y*t.y+this.normal.z*t.z),this},t.prototype.isFrontFacingTo=function(t,i){var o=r.Dot(this.normal,t);return i>=o},t.prototype.signedDistanceTo=function(t){return r.Dot(t,this.normal)+this.d},t.FromArray=function(i){return new t(i[0],i[1],i[2],i[3])},t.FromPoints=function(i,o,n){var r=new t(0,0,0,0);return r.copyFromPoints(i,o,n),r},t.FromPositionAndNormal=function(i,o){var n=new t(0,0,0,0);return o.normalize(),n.normal=o,n.d=-(o.x*i.x+o.y*i.y+o.z*i.z),n},t.SignedDistanceToPlaneFromPositionAndNormal=function(t,i,o){var n=-(i.x*t.x+i.y*t.y+i.z*t.z);return r.Dot(o,i)+n},t}();t.Plane=h;var u=function(){function t(t,i,o,n){this.x=t,this.y=i,this.width=o,this.height=n}return t.prototype.toGlobal=function(i){var o=i.getRenderWidth(),n=i.getRenderHeight();return new t(this.x*o,this.y*n,this.width*o,this.height*n)},t}();t.Viewport=u;var m=function(){function t(){}return t.GetPlanes=function(i){for(var o=[],n=0;6>n;n++)o.push(new h(0,0,0,0));return t.GetPlanesToRef(i,o),o},t.GetPlanesToRef=function(t,i){i[0].normal.x=t.m[3]+t.m[2],i[0].normal.y=t.m[7]+t.m[6],i[0].normal.z=t.m[10]+t.m[10],i[0].d=t.m[15]+t.m[14],i[0].normalize(),i[1].normal.x=t.m[3]-t.m[2],i[1].normal.y=t.m[7]-t.m[6],i[1].normal.z=t.m[11]-t.m[10],i[1].d=t.m[15]-t.m[14],i[1].normalize(),i[2].normal.x=t.m[3]+t.m[0],i[2].normal.y=t.m[7]+t.m[4],i[2].normal.z=t.m[11]+t.m[8],i[2].d=t.m[15]+t.m[12],i[2].normalize(),i[3].normal.x=t.m[3]-t.m[0],i[3].normal.y=t.m[7]-t.m[4],i[3].normal.z=t.m[11]-t.m[8],i[3].d=t.m[15]-t.m[12],i[3].normalize(),i[4].normal.x=t.m[3]-t.m[1],i[4].normal.y=t.m[7]-t.m[5],i[4].normal.z=t.m[11]-t.m[9],i[4].d=t.m[15]-t.m[13],i[4].normalize(),i[5].normal.x=t.m[3]+t.m[1],i[5].normal.y=t.m[7]+t.m[5],i[5].normal.z=t.m[11]+t.m[9],i[5].d=t.m[15]+t.m[13],i[5].normalize()},t}();t.Frustum=m;var l=function(){function i(t,i,o){void 0===o&&(o=Number.MAX_VALUE),this.origin=t,this.direction=i,this.length=o}return i.prototype.intersectsBoxMinMax=function(t,i){var o=0,n=Number.MAX_VALUE;if(Math.abs(this.direction.x)<1e-7){if(this.origin.xi.x)return!1}else{var r=1/this.direction.x,s=(t.x-this.origin.x)*r,e=(i.x-this.origin.x)*r;if(e===-(1/0)&&(e=1/0),s>e){var a=s;s=e,e=a}if(o=Math.max(s,o),n=Math.min(e,n),o>n)return!1}if(Math.abs(this.direction.y)<1e-7){if(this.origin.yi.y)return!1}else if(r=1/this.direction.y,s=(t.y-this.origin.y)*r,e=(i.y-this.origin.y)*r,e===-(1/0)&&(e=1/0),s>e&&(a=s,s=e,e=a),o=Math.max(s,o),n=Math.min(e,n),o>n)return!1;if(Math.abs(this.direction.z)<1e-7){if(this.origin.zi.z)return!1}else if(r=1/this.direction.z,s=(t.z-this.origin.z)*r,e=(i.z-this.origin.z)*r,e===-(1/0)&&(e=1/0),s>e&&(a=s,s=e,e=a),o=Math.max(s,o),n=Math.min(e,n),o>n)return!1;return!0},i.prototype.intersectsBox=function(t){return this.intersectsBoxMinMax(t.minimum,t.maximum)},i.prototype.intersectsSphere=function(t){var i=t.center.x-this.origin.x,o=t.center.y-this.origin.y,n=t.center.z-this.origin.z,r=i*i+o*o+n*n,s=t.radius*t.radius;if(s>=r)return!0;var e=i*this.direction.x+o*this.direction.y+n*this.direction.z;if(0>e)return!1;var a=r-e*e;return s>=a},i.prototype.intersectsTriangle=function(i,o,n){this._edge1||(this._edge1=r.Zero(),this._edge2=r.Zero(),this._pvec=r.Zero(),this._tvec=r.Zero(),this._qvec=r.Zero()),o.subtractToRef(i,this._edge1),n.subtractToRef(i,this._edge2),r.CrossToRef(this.direction,this._edge2,this._pvec);var s=r.Dot(this._edge1,this._pvec);if(0===s)return null;var e=1/s;this.origin.subtractToRef(i,this._tvec);var a=r.Dot(this._tvec,this._pvec)*e;if(0>a||a>1)return null;r.CrossToRef(this._tvec,this._edge1,this._qvec);var h=r.Dot(this.direction,this._qvec)*e;if(0>h||a+h>1)return null;var u=r.Dot(this._edge2,this._qvec)*e;return u>this.length?null:new t.IntersectionInfo(a,h,u)},i.CreateNew=function(t,o,n,s,e,a,h){var u=r.Unproject(new r(t,o,0),n,s,e,a,h),m=r.Unproject(new r(t,o,1),n,s,e,a,h),l=m.subtract(u);return l.normalize(),new i(u,l)},i.CreateNewFromTo=function(t,o,n){void 0===n&&(n=a.Identity());var r=o.subtract(t),s=Math.sqrt(r.x*r.x+r.y*r.y+r.z*r.z);return r.normalize(),i.Transform(new i(t,r,s),n)},i.Transform=function(t,o){var n=r.TransformCoordinates(t.origin,o),s=r.TransformNormal(t.direction,o);return new i(n,s,t.length)},i}();t.Ray=l,function(t){t[t.LOCAL=0]="LOCAL",t[t.WORLD=1]="WORLD"}(t.Space||(t.Space={}));var f=(t.Space,function(){function t(){}return t.X=new r(1,0,0),t.Y=new r(0,1,0),t.Z=new r(0,0,1),t}());t.Axis=f;var x=function(){function t(){}return t.interpolate=function(t,i,o,n,r){for(var s=1-3*n+3*i,e=3*n-6*i,a=3*i,h=t,u=0;5>u;u++){var m=h*h,l=m*h,f=s*l+e*m+a*h,x=1/(3*s*m+2*e*h+a);h-=(f-t)*x,h=Math.min(1,Math.max(0,h))}return 3*Math.pow(1-h,2)*h*o+3*(1-h)*Math.pow(h,2)*r+Math.pow(h,3)},t}();t.BezierCurve=x,function(t){t[t.CW=0]="CW",t[t.CCW=1]="CCW"}(t.Orientation||(t.Orientation={}));var y=(t.Orientation,function(){function t(t){var i=this;this.degrees=function(){return 180*i._radians/Math.PI},this.radians=function(){return i._radians},this._radians=t,this._radians<0&&(this._radians+=2*Math.PI)}return t.BetweenTwoPoints=function(i,o){var n=o.subtract(i),r=Math.atan2(n.y,n.x);return new t(r)},t.FromRadians=function(i){return new t(i)},t.FromDegrees=function(i){return new t(i*Math.PI/180)},t}());t.Angle=y;var c=function(){function t(t,i,o){this.startPoint=t,this.midPoint=i,this.endPoint=o;var r=Math.pow(i.x,2)+Math.pow(i.y,2),s=(Math.pow(t.x,2)+Math.pow(t.y,2)-r)/2,e=(r-Math.pow(o.x,2)-Math.pow(o.y,2))/2,a=(t.x-i.x)*(i.y-o.y)-(i.x-o.x)*(t.y-i.y);this.centerPoint=new n((s*(i.y-o.y)-e*(t.y-i.y))/a,((t.x-i.x)*e-(i.x-o.x)*s)/a),this.radius=this.centerPoint.subtract(this.startPoint).length(),this.startAngle=y.BetweenTwoPoints(this.centerPoint,this.startPoint);var h=this.startAngle.degrees(),u=y.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),m=y.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();u-h>180&&(u-=360),-180>u-h&&(u+=360),m-u>180&&(m-=360),-180>m-u&&(m+=360),this.orientation=0>u-h?0:1,this.angle=y.FromDegrees(0===this.orientation?h-m:m-h)}return t}();t.Arc2=c;var p=function(){function t(t){this.path=t,this._onchange=new Array,this.value=0,this.animations=new Array}return t.prototype.getPoint=function(){var t=this.path.getPointAtLengthPosition(this.value);return new r(t.x,0,t.y)},t.prototype.moveAhead=function(t){return void 0===t&&(t=.002),this.move(t),this},t.prototype.moveBack=function(t){return void 0===t&&(t=.002),this.move(-t),this},t.prototype.move=function(t){if(Math.abs(t)>1)throw"step size should be less than 1.";return this.value+=t,this.ensureLimits(),this.raiseOnChange(),this},t.prototype.ensureLimits=function(){for(;this.value>1;)this.value-=1;for(;this.value<0;)this.value+=1;return this},t.prototype.markAsDirty=function(t){return this.ensureLimits(),this.raiseOnChange(),this},t.prototype.raiseOnChange=function(){var t=this;return this._onchange.forEach(function(i){return i(t)}),this},t.prototype.onchange=function(t){return this._onchange.push(t),this},t}();t.PathCursor=p;var z=function(){function i(t,i){this._points=new Array,this._length=0,this.closed=!1,this._points.push(new n(t,i))}return i.prototype.addLineTo=function(i,o){if(closed)return t.Tools.Error("cannot add lines to closed paths"),this;var r=new n(i,o),s=this._points[this._points.length-1];return this._points.push(r),this._length+=r.subtract(s).length(),this},i.prototype.addArcTo=function(i,o,r,s,e){if(void 0===e&&(e=36),closed)return t.Tools.Error("cannot add arcs to closed paths"),this;var a=this._points[this._points.length-1],h=new n(i,o),u=new n(r,s),m=new c(a,h,u),l=m.angle.radians()/e;0===m.orientation&&(l*=-1);for(var f=m.startAngle.radians()+l,x=0;e>x;x++){var y=Math.cos(f)*m.radius+m.centerPoint.x,p=Math.sin(f)*m.radius+m.centerPoint.y;this.addLineTo(y,p),f+=l}return this},i.prototype.close=function(){return this.closed=!0,this},i.prototype.length=function(){var t=this._length;if(!this.closed){var i=this._points[this._points.length-1],o=this._points[0];t+=o.subtract(i).length()}return t},i.prototype.getPoints=function(){return this._points},i.prototype.getPointAtLengthPosition=function(i){if(0>i||i>1)return t.Tools.Error("normalized length position should be between 0 and 1."),n.Zero();for(var o=i*this.length(),r=0,s=0;s=r&&m>=o){var l=u.normalize(),f=o-r;return new n(a.x+l.x*f,a.y+l.y*f)}r=m}return t.Tools.Error("internal error"),n.Zero()},i.StartingAt=function(t,o){return new i(t,o)},i}();t.Path2=z;var M=function(){function t(t,i){this.path=t,this._curve=new Array,this._distances=new Array,this._tangents=new Array,this._normals=new Array,this._binormals=new Array;for(var o=0;om;m++)s=this._getLastNonNullVector(m),i-1>m&&(e=this._getFirstNonNullVector(m),this._tangents[m]=s.add(e),this._tangents[m].normalize()),this._distances[m]=this._distances[m-1]+s.length(),a=this._tangents[m],h=this._normals[m-1],u=this._binormals[m-1],this._normals[m]=r.Cross(u,a),this._normals[m].normalize(),this._binormals[m]=r.Cross(a,this._normals[m]),this._binormals[m].normalize()},t.prototype._getFirstNonNullVector=function(t){for(var i=1,o=this._curve[t+i].subtract(this._curve[t]);0==o.length()&&t+i+1i+1;)i++,o=this._curve[t].subtract(this._curve[t-i]);return o},t.prototype._normalVector=function(t,i,o){var n;if(void 0===o||null===o){var s;1!==i.x?s=new r(1,0,0):1!==i.y?s=new r(0,1,0):1!==i.z&&(s=new r(0,0,1)),n=r.Cross(i,s)}else n=r.Cross(i,o),r.CrossToRef(n,i,n);return n.normalize(),n},t}();t.Path3D=M;var w=function(){function i(t){this._length=0,this._points=t,this._length=this._computeLength(t)}return i.CreateQuadraticBezier=function(t,o,n,s){s=s>2?s:3;for(var e=new Array,a=function(t,i,o,n){var r=(1-t)*(1-t)*i+2*t*(1-t)*o+t*t*n;return r},h=0;s>=h;h++)e.push(new r(a(h/s,t.x,o.x,n.x),a(h/s,t.y,o.y,n.y),a(h/s,t.z,o.z,n.z)));return new i(e)},i.CreateCubicBezier=function(t,o,n,s,e){e=e>3?e:4;for(var a=new Array,h=function(t,i,o,n,r){var s=(1-t)*(1-t)*(1-t)*i+3*t*(1-t)*(1-t)*o+3*t*t*(1-t)*n+t*t*t*r;return s},u=0;e>=u;u++)a.push(new r(h(u/e,t.x,o.x,n.x,s.x),h(u/e,t.y,o.y,n.y,s.y),h(u/e,t.z,o.z,n.z,s.z)));return new i(a)},i.CreateHermiteSpline=function(o,n,r,s,e){for(var a=new Array,h=1/e,u=0;e>=u;u++)a.push(t.Vector3.Hermite(o,n,r,s,u*h));return new i(a)},i.prototype.getPoints=function(){return this._points},i.prototype.length=function(){return this._length},i.prototype["continue"]=function(t){for(var o=this._points[this._points.length-1],n=this._points.slice(),r=t.getPoints(),s=1;s