var __extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},BABYLON;!function(e){var t=1/2.2,r=2.2,i=function(){function i(e,t,r){void 0===e&&(e=0),void 0===t&&(t=0),void 0===r&&(r=0),this.r=e,this.g=t,this.b=r}return i.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+"}"},i.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,this},i.prototype.toColor4=function(e){return void 0===e&&(e=1),new n(this.r,this.g,this.b,e)},i.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},i.prototype.toLuminance=function(){return.3*this.r+.59*this.g+.11*this.b},i.prototype.multiply=function(e){return new i(this.r*e.r,this.g*e.g,this.b*e.b)},i.prototype.multiplyToRef=function(e,t){return t.r=this.r*e.r,t.g=this.g*e.g,t.b=this.b*e.b,this},i.prototype.equals=function(e){return e&&this.r===e.r&&this.g===e.g&&this.b===e.b},i.prototype.equalsFloats=function(e,t,r){return this.r===e&&this.g===t&&this.b===r},i.prototype.scale=function(e){return new i(this.r*e,this.g*e,this.b*e)},i.prototype.scaleToRef=function(e,t){return t.r=this.r*e,t.g=this.g*e,t.b=this.b*e,this},i.prototype.add=function(e){return new i(this.r+e.r,this.g+e.g,this.b+e.b)},i.prototype.addToRef=function(e,t){return t.r=this.r+e.r,t.g=this.g+e.g,t.b=this.b+e.b,this},i.prototype.subtract=function(e){return new i(this.r-e.r,this.g-e.g,this.b-e.b)},i.prototype.subtractToRef=function(e,t){return t.r=this.r-e.r,t.g=this.g-e.g,t.b=this.b-e.b,this},i.prototype.clone=function(){return new i(this.r,this.g,this.b)},i.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this},i.prototype.copyFromFloats=function(e,t,r){return this.r=e,this.g=t,this.b=r,this},i.prototype.toHexString=function(){var t=255*this.r|0,r=255*this.g|0,i=255*this.b|0;return"#"+e.Tools.ToHex(t)+e.Tools.ToHex(r)+e.Tools.ToHex(i)},i.prototype.toLinearSpace=function(){var e=new i;return this.toLinearSpaceToRef(e),e},i.prototype.toLinearSpaceToRef=function(e){return e.r=Math.pow(this.r,r),e.g=Math.pow(this.g,r),e.b=Math.pow(this.b,r),this},i.prototype.toGammaSpace=function(){var e=new i;return this.toGammaSpaceToRef(e),e},i.prototype.toGammaSpaceToRef=function(e){return e.r=Math.pow(this.r,t),e.g=Math.pow(this.g,t),e.b=Math.pow(this.b,t),this},i.FromHexString=function(t){if("#"!==t.substring(0,1)||7!==t.length)return e.Tools.Warn("Color3.FromHexString must be called with a string like #FFFFFF"),new i(0,0,0);var r=parseInt(t.substring(1,3),16),n=parseInt(t.substring(3,5),16),s=parseInt(t.substring(5,7),16);return i.FromInts(r,n,s)},i.FromArray=function(e,t){return void 0===t&&(t=0),new i(e[t],e[t+1],e[t+2])},i.FromInts=function(e,t,r){return new i(e/255,t/255,r/255)},i.Lerp=function(e,t,r){var n=e.r+(t.r-e.r)*r,s=e.g+(t.g-e.g)*r,o=e.b+(t.b-e.b)*r;return new i(n,s,o)},i.Red=function(){return new i(1,0,0)},i.Green=function(){return new i(0,1,0)},i.Blue=function(){return new i(0,0,1)},i.Black=function(){return new i(0,0,0)},i.White=function(){return new i(1,1,1)},i.Purple=function(){return new i(.5,0,.5)},i.Magenta=function(){return new i(1,0,1)},i.Yellow=function(){return new i(1,1,0)},i.Gray=function(){return new i(.5,.5,.5)},i}();e.Color3=i;var n=function(){function t(e,t,r,i){this.r=e,this.g=t,this.b=r,this.a=i}return t.prototype.addInPlace=function(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this.a+=e.a,this},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e[t+3]=this.a,this},t.prototype.add=function(e){return new t(this.r+e.r,this.g+e.g,this.b+e.b,this.a+e.a)},t.prototype.subtract=function(e){return new t(this.r-e.r,this.g-e.g,this.b-e.b,this.a-e.a)},t.prototype.subtractToRef=function(e,t){return t.r=this.r-e.r,t.g=this.g-e.g,t.b=this.b-e.b,t.a=this.a-e.a,this},t.prototype.scale=function(e){return new t(this.r*e,this.g*e,this.b*e,this.a*e)},t.prototype.scaleToRef=function(e,t){return t.r=this.r*e,t.g=this.g*e,t.b=this.b*e,t.a=this.a*e,this},t.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+" A:"+this.a+"}"},t.prototype.clone=function(){return new t(this.r,this.g,this.b,this.a)},t.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this},t.prototype.toHexString=function(){var t=255*this.r|0,r=255*this.g|0,i=255*this.b|0,n=255*this.a|0;return"#"+e.Tools.ToHex(t)+e.Tools.ToHex(r)+e.Tools.ToHex(i)+e.Tools.ToHex(n)},t.FromHexString=function(r){if("#"!==r.substring(0,1)||9!==r.length)return e.Tools.Warn("Color4.FromHexString must be called with a string like #FFFFFFFF"),new t(0,0,0,0);var i=parseInt(r.substring(1,3),16),n=parseInt(r.substring(3,5),16),s=parseInt(r.substring(5,7),16),o=parseInt(r.substring(7,9),16);return t.FromInts(i,n,s,o)},t.Lerp=function(e,r,i){var n=new t(0,0,0,0);return t.LerpToRef(e,r,i,n),n},t.LerpToRef=function(e,t,r,i){i.r=e.r+(t.r-e.r)*r,i.g=e.g+(t.g-e.g)*r,i.b=e.b+(t.b-e.b)*r,i.a=e.a+(t.a-e.a)*r},t.FromArray=function(e,r){return void 0===r&&(r=0),new t(e[r],e[r+1],e[r+2],e[r+3])},t.FromInts=function(e,r,i,n){return new t(e/255,r/255,i/255,n/255)},t.CheckColors4=function(e,t){if(e.length===3*t){for(var r=[],i=0;ii.x?i.x:n,n=ni.y?i.y:s,s=sr.x?e.x:r.x,n=e.y>r.y?e.y:r.y;return new t(i,n)},t.Transform=function(e,r){var i=e.x*r.m[0]+e.y*r.m[4],n=e.x*r.m[1]+e.y*r.m[5];return new t(i,n)},t.Distance=function(e,r){return Math.sqrt(t.DistanceSquared(e,r))},t.DistanceSquared=function(e,t){var r=e.x-t.x,i=e.y-t.y;return r*r+i*i},t}();e.Vector2=s;var o=function(){function t(e,t,r){this.x=e,this.y=t,this.z=r}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,this},t.prototype.toQuaternion=function(){var e=new h(0,0,0,1),t=Math.cos(.5*(this.x+this.z)),r=Math.sin(.5*(this.x+this.z)),i=Math.cos(.5*(this.z-this.x)),n=Math.sin(.5*(this.z-this.x)),s=Math.cos(.5*this.y),o=Math.sin(.5*this.y);return e.x=i*o,e.y=-n*o,e.z=r*s,e.w=t*s,e},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,this},t.prototype.subtractFromFloats=function(e,r,i){return new t(this.x-e,this.y-r,this.z-i)},t.prototype.subtractFromFloatsToRef=function(e,t,r,i){return i.x=this.x-e,i.y=this.y-t,i.z=this.z-r,this},t.prototype.negate=function(){return new t(-this.x,-this.y,-this.z)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e)},t.prototype.scaleToRef=function(e,t){t.x=this.x*e,t.y=this.y*e,t.z=this.z*e},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z},t.prototype.equalsWithEpsilon=function(t,r){return void 0===r&&(r=e.Engine.Epsilon),t&&e.Tools.WithinEpsilon(this.x,t.x,r)&&e.Tools.WithinEpsilon(this.y,t.y,r)&&e.Tools.WithinEpsilon(this.z,t.z,r)},t.prototype.equalsToFloats=function(e,t,r){return this.x===e&&this.y===t&&this.z===r},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y,this.z*e.z)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,t.z=this.z*e.z,this},t.prototype.multiplyByFloats=function(e,r,i){return new t(this.x*e,this.y*r,this.z*i)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y,this.z/e.z)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,t.z=this.z/e.z,this},t.prototype.MinimizeInPlace=function(e){return e.xthis.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},t.prototype.normalize=function(){var e=this.length();if(0===e||1===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.clone=function(){return new t(this.x,this.y,this.z)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},t.prototype.copyFromFloats=function(e,t,r){return this.x=e,this.y=t,this.z=r,this},t.GetClipFactor=function(e,r,i,n){var s=t.Dot(e,i)-n,o=t.Dot(r,i)-n,a=s/(s-o);return a},t.FromArray=function(e,r){return r||(r=0),new t(e[r],e[r+1],e[r+2])},t.FromFloatArray=function(e,r){return r||(r=0),new t(e[r],e[r+1],e[r+2])},t.FromArrayToRef=function(e,t,r){r.x=e[t],r.y=e[t+1],r.z=e[t+2]},t.FromFloatArrayToRef=function(e,t,r){r.x=e[t],r.y=e[t+1],r.z=e[t+2]},t.FromFloatsToRef=function(e,t,r,i){i.x=e,i.y=t,i.z=r},t.Zero=function(){return new t(0,0,0)},t.Up=function(){return new t(0,1,0)},t.TransformCoordinates=function(e,r){var i=t.Zero();return t.TransformCoordinatesToRef(e,r,i),i},t.TransformCoordinatesToRef=function(e,t,r){var i=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8]+t.m[12],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9]+t.m[13],s=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10]+t.m[14],o=e.x*t.m[3]+e.y*t.m[7]+e.z*t.m[11]+t.m[15];r.x=i/o,r.y=n/o,r.z=s/o},t.TransformCoordinatesFromFloatsToRef=function(e,t,r,i,n){var s=e*i.m[0]+t*i.m[4]+r*i.m[8]+i.m[12],o=e*i.m[1]+t*i.m[5]+r*i.m[9]+i.m[13],a=e*i.m[2]+t*i.m[6]+r*i.m[10]+i.m[14],h=e*i.m[3]+t*i.m[7]+r*i.m[11]+i.m[15];n.x=s/h,n.y=o/h,n.z=a/h},t.TransformNormal=function(e,r){var i=t.Zero();return t.TransformNormalToRef(e,r,i),i},t.TransformNormalToRef=function(e,t,r){r.x=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8],r.y=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9],r.z=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10]},t.TransformNormalFromFloatsToRef=function(e,t,r,i,n){n.x=e*i.m[0]+t*i.m[4]+r*i.m[8],n.y=e*i.m[1]+t*i.m[5]+r*i.m[9],n.z=e*i.m[2]+t*i.m[6]+r*i.m[10]},t.CatmullRom=function(e,r,i,n,s){var o=s*s,a=s*o,h=.5*(2*r.x+(-e.x+i.x)*s+(2*e.x-5*r.x+4*i.x-n.x)*o+(-e.x+3*r.x-3*i.x+n.x)*a),c=.5*(2*r.y+(-e.y+i.y)*s+(2*e.y-5*r.y+4*i.y-n.y)*o+(-e.y+3*r.y-3*i.y+n.y)*a),l=.5*(2*r.z+(-e.z+i.z)*s+(2*e.z-5*r.z+4*i.z-n.z)*o+(-e.z+3*r.z-3*i.z+n.z)*a);return new t(h,c,l)},t.Clamp=function(e,r,i){var n=e.x;n=n>i.x?i.x:n,n=ni.y?i.y:s,s=si.z?i.z:o,o=oE&&2>y&&(l=Math.PI+l),s.x=u,s.y=l,s.z=f},t}();e.Vector3=o;var a=function(){function t(e,t,r,i){this.x=e,this.y=t,this.z=r,this.w=i}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"W:"+this.w+"}"},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,this},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,t.w=this.w+e.w,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,t.w=this.w-e.w,this},t.prototype.subtractFromFloats=function(e,r,i,n){return new t(this.x-e,this.y-r,this.z-i,this.w-n)},t.prototype.subtractFromFloatsToRef=function(e,t,r,i,n){return n.x=this.x-e,n.y=this.y-t,n.z=this.z-r,n.w=this.w-i,this},t.prototype.negate=function(){return new t(-this.x,-this.y,-this.z,-this.w)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e,this.w*e)},t.prototype.scaleToRef=function(e,t){t.x=this.x*e,t.y=this.y*e,t.z=this.z*e,t.w=this.w*e},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},t.prototype.equalsWithEpsilon=function(t,r){return void 0===r&&(r=e.Engine.Epsilon),t&&e.Tools.WithinEpsilon(this.x,t.x,r)&&e.Tools.WithinEpsilon(this.y,t.y,r)&&e.Tools.WithinEpsilon(this.z,t.z,r)&&e.Tools.WithinEpsilon(this.w,t.w,r)},t.prototype.equalsToFloats=function(e,t,r,i){return this.x===e&&this.y===t&&this.z===r&&this.w===i},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y,this.z*e.z,this.w*e.w)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,t.z=this.z*e.z,t.w=this.w*e.w,this},t.prototype.multiplyByFloats=function(e,r,i,n){return new t(this.x*e,this.y*r,this.z*i,this.w*n)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y,this.z/e.z,this.w/e.w)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,t.z=this.z/e.z,t.w=this.w/e.w,this},t.prototype.MinimizeInPlace=function(e){return e.xthis.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),e.w>this.w&&(this.w=e.w),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},t.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},t.prototype.copyFromFloats=function(e,t,r,i){return this.x=e,this.y=t,this.z=r,this.w=i,this},t.FromArray=function(e,r){return r||(r=0),new t(e[r],e[r+1],e[r+2],e[r+3])},t.FromArrayToRef=function(e,t,r){r.x=e[t],r.y=e[t+1],r.z=e[t+2],r.w=e[t+3]},t.FromFloatArrayToRef=function(e,t,r){r.x=e[t],r.y=e[t+1],r.z=e[t+2],r.w=e[t+3]},t.FromFloatsToRef=function(e,t,r,i,n){n.x=e,n.y=t,n.z=r,n.w=i},t.Zero=function(){return new t(0,0,0,0)},t.Normalize=function(e){var r=t.Zero();return t.NormalizeToRef(e,r),r},t.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},t.Minimize=function(e,t){var r=e.clone();return r.MinimizeInPlace(t),r},t.Maximize=function(e,t){var r=e.clone();return r.MaximizeInPlace(t),r},t.Distance=function(e,r){return Math.sqrt(t.DistanceSquared(e,r))},t.DistanceSquared=function(e,t){var r=e.x-t.x,i=e.y-t.y,n=e.z-t.z,s=e.w-t.w;return r*r+i*i+n*n+s*s},t.Center=function(e,t){var r=e.add(t);return r.scaleInPlace(.5),r},t}();e.Vector4=a;var h=function(){function e(e,t,r,i){void 0===e&&(e=0),void 0===t&&(t=0),void 0===r&&(r=0),void 0===i&&(i=1),this.x=e,this.y=t,this.z=r,this.w=i}return e.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},e.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},e.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},e.prototype.clone=function(){return new e(this.x,this.y,this.z,this.w)},e.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},e.prototype.copyFromFloats=function(e,t,r,i){return this.x=e,this.y=t,this.z=r,this.w=i,this},e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y,this.z+t.z,this.w+t.w)},e.prototype.subtract=function(t){return new e(this.x-t.x,this.y-t.y,this.z-t.z,this.w-t.w)},e.prototype.scale=function(t){return new e(this.x*t,this.y*t,this.z*t,this.w*t)},e.prototype.multiply=function(t){var r=new e(0,0,0,1);return this.multiplyToRef(t,r),r},e.prototype.multiplyToRef=function(e,t){var r=this.x*e.w+this.y*e.z-this.z*e.y+this.w*e.x,i=-this.x*e.z+this.y*e.w+this.z*e.x+this.w*e.y,n=this.x*e.y-this.y*e.x+this.z*e.w+this.w*e.z,s=-this.x*e.x-this.y*e.y-this.z*e.z+this.w*e.w;return t.copyFromFloats(r,i,n,s),this},e.prototype.multiplyInPlace=function(e){return this.multiplyToRef(e,this),this},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},e.prototype.normalize=function(){var e=1/this.length();return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},e.prototype.toEulerAngles=function(e){void 0===e&&(e="YZX");var t=o.Zero();return this.toEulerAnglesToRef(t,e),t},e.prototype.toEulerAnglesToRef=function(e,t){void 0===t&&(t="YZX");var r,i,n,s=this.x,o=this.y,a=this.z,h=this.w;switch(t){case"YZX":var c=s*o+a*h;if(c>.499&&(r=2*Math.atan2(s,h),i=Math.PI/2,n=0),-.499>c&&(r=-2*Math.atan2(s,h),i=-Math.PI/2,n=0),isNaN(r)){var l=s*s,u=o*o,f=a*a;r=Math.atan2(2*o*h-2*s*a,1-2*u-2*f),i=Math.asin(2*c),n=Math.atan2(2*s*h-2*o*a,1-2*l-2*f)}break;default:throw new Error("Euler order "+t+" not supported yet.")}return e.y=r,e.z=i,e.x=n,this},e.prototype.toRotationMatrix=function(e){var t=this.x*this.x,r=this.y*this.y,i=this.z*this.z,n=this.x*this.y,s=this.z*this.w,o=this.z*this.x,a=this.y*this.w,h=this.y*this.z,c=this.x*this.w;return e.m[0]=1-2*(r+i),e.m[1]=2*(n+s),e.m[2]=2*(o-a),e.m[3]=0,e.m[4]=2*(n-s),e.m[5]=1-2*(i+t),e.m[6]=2*(h+c),e.m[7]=0,e.m[8]=2*(o+a),e.m[9]=2*(h-c),e.m[10]=1-2*(r+t),e.m[11]=0,e.m[12]=0,e.m[13]=0,e.m[14]=0,e.m[15]=1,this},e.prototype.fromRotationMatrix=function(t){return e.FromRotationMatrixToRef(t,this),this},e.FromRotationMatrix=function(t){var r=new e;return e.FromRotationMatrixToRef(t,r),r},e.FromRotationMatrixToRef=function(e,t){var r,i=e.m,n=i[0],s=i[4],o=i[8],a=i[1],h=i[5],c=i[9],l=i[2],u=i[6],f=i[10],d=n+h+f;d>0?(r=.5/Math.sqrt(d+1),t.w=.25/r,t.x=(u-c)*r,t.y=(o-l)*r,t.z=(a-s)*r):n>h&&n>f?(r=2*Math.sqrt(1+n-h-f),t.w=(u-c)/r,t.x=.25*r,t.y=(s+a)/r,t.z=(o+l)/r):h>f?(r=2*Math.sqrt(1+h-n-f),t.w=(o-l)/r,t.x=(s+a)/r,t.y=.25*r,t.z=(c+u)/r):(r=2*Math.sqrt(1+f-n-h),t.w=(a-s)/r,t.x=(o+l)/r,t.y=(c+u)/r,t.z=.25*r)},e.Inverse=function(t){return new e(-t.x,-t.y,-t.z,t.w)},e.Identity=function(){return new e(0,0,0,1)},e.RotationAxis=function(t,r){var i=new e,n=Math.sin(r/2);return t.normalize(),i.w=Math.cos(r/2),i.x=t.x*n,i.y=t.y*n,i.z=t.z*n,i},e.FromArray=function(t,r){return r||(r=0),new e(t[r],t[r+1],t[r+2],t[r+3])},e.RotationYawPitchRoll=function(t,r,i){var n=new e;return e.RotationYawPitchRollToRef(t,r,i,n),n},e.RotationYawPitchRollToRef=function(e,t,r,i){var n=.5*r,s=.5*t,o=.5*e,a=Math.sin(n),h=Math.cos(n),c=Math.sin(s),l=Math.cos(s),u=Math.sin(o),f=Math.cos(o);i.x=f*c*h+u*l*a,i.y=u*l*h-f*c*a,i.z=f*l*a-u*c*h,i.w=f*l*h+u*c*a},e.RotationAlphaBetaGamma=function(t,r,i){var n=new e;return e.RotationAlphaBetaGammaToRef(t,r,i,n),n},e.RotationAlphaBetaGammaToRef=function(e,t,r,i){var n=.5*(r+e),s=.5*(r-e),o=.5*t;i.x=Math.cos(s)*Math.sin(o),i.y=Math.sin(s)*Math.sin(o),i.z=Math.sin(n)*Math.cos(o),i.w=Math.cos(n)*Math.cos(o)},e.Slerp=function(t,r,i){var n,s,o=i,a=t.x*r.x+t.y*r.y+t.z*r.z+t.w*r.w,h=!1;if(0>a&&(h=!0,a=-a),a>.999999)s=1-o,n=h?-o:o;else{var c=Math.acos(a),l=1/Math.sin(c);s=Math.sin((1-o)*c)*l,n=h?-Math.sin(o*c)*l:Math.sin(o*c)*l}return new e(s*t.x+n*r.x,s*t.y+n*r.y,s*t.z+n*r.z,s*t.w+n*r.w)},e}();e.Quaternion=h;var c=function(){function t(){this.m=new Float32Array(16)}return t.prototype.isIdentity=function(){return 1!==this.m[0]||1!==this.m[5]||1!==this.m[10]||1!==this.m[15]?!1:0!==this.m[1]||0!==this.m[2]||0!==this.m[3]||0!==this.m[4]||0!==this.m[6]||0!==this.m[7]||0!==this.m[8]||0!==this.m[9]||0!==this.m[11]||0!==this.m[12]||0!==this.m[13]||0!==this.m[14]?!1:!0},t.prototype.determinant=function(){var e=this.m[10]*this.m[15]-this.m[11]*this.m[14],t=this.m[9]*this.m[15]-this.m[11]*this.m[13],r=this.m[9]*this.m[14]-this.m[10]*this.m[13],i=this.m[8]*this.m[15]-this.m[11]*this.m[12],n=this.m[8]*this.m[14]-this.m[10]*this.m[12],s=this.m[8]*this.m[13]-this.m[9]*this.m[12];return this.m[0]*(this.m[5]*e-this.m[6]*t+this.m[7]*r)-this.m[1]*(this.m[4]*e-this.m[6]*i+this.m[7]*n)+this.m[2]*(this.m[4]*t-this.m[5]*i+this.m[7]*s)-this.m[3]*(this.m[4]*r-this.m[5]*n+this.m[6]*s)},t.prototype.toArray=function(){return this.m},t.prototype.asArray=function(){return this.toArray()},t.prototype.invert=function(){return this.invertToRef(this),this},t.prototype.reset=function(){for(var e=0;16>e;e++)this.m[e]=0;return this},t.prototype.add=function(e){var r=new t;return this.addToRef(e,r),r},t.prototype.addToRef=function(e,t){for(var r=0;16>r;r++)t.m[r]=this.m[r]+e.m[r];return this},t.prototype.addToSelf=function(e){for(var t=0;16>t;t++)this.m[t]+=e.m[t];return this},t.prototype.invertToRef=function(e){var t=this.m[0],r=this.m[1],i=this.m[2],n=this.m[3],s=this.m[4],o=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],g=this.m[15],_=u*g-f*m,v=l*g-f*p,y=l*m-u*p,x=c*g-f*d,E=c*m-u*d,T=c*p-l*d,A=o*_-a*v+h*y,b=-(s*_-a*x+h*E),M=s*v-o*x+h*T,P=-(s*y-o*E+a*T),S=1/(t*A+r*b+i*M+n*P),C=a*g-h*m,I=o*g-h*p,D=o*m-a*p,R=s*g-h*d,w=s*m-a*d,L=s*p-o*d,O=a*f-h*u,B=o*f-h*l,F=o*u-a*l,V=s*f-h*c,N=s*u-a*c,U=s*l-o*c;return e.m[0]=A*S,e.m[4]=b*S,e.m[8]=M*S,e.m[12]=P*S,e.m[1]=-(r*_-i*v+n*y)*S,e.m[5]=(t*_-i*x+n*E)*S,e.m[9]=-(t*v-r*x+n*T)*S,e.m[13]=(t*y-r*E+i*T)*S,e.m[2]=(r*C-i*I+n*D)*S,e.m[6]=-(t*C-i*R+n*w)*S,e.m[10]=(t*I-r*R+n*L)*S,e.m[14]=-(t*D-r*w+i*L)*S,e.m[3]=-(r*O-i*B+n*F)*S,e.m[7]=(t*O-i*V+n*N)*S,e.m[11]=-(t*B-r*V+n*U)*S,e.m[15]=(t*F-r*N+i*U)*S,this},t.prototype.setTranslation=function(e){return this.m[12]=e.x,this.m[13]=e.y,this.m[14]=e.z,this},t.prototype.multiply=function(e){var r=new t;return this.multiplyToRef(e,r),r},t.prototype.copyFrom=function(e){for(var t=0;16>t;t++)this.m[t]=e.m[t];return this},t.prototype.copyToArray=function(e,t){void 0===t&&(t=0);for(var r=0;16>r;r++)e[t+r]=this.m[r];return this},t.prototype.multiplyToRef=function(e,t){return this.multiplyToArray(e,t.m,0),this},t.prototype.multiplyToArray=function(e,t,r){var i=this.m[0],n=this.m[1],s=this.m[2],o=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],g=this.m[13],_=this.m[14],v=this.m[15],y=e.m[0],x=e.m[1],E=e.m[2],T=e.m[3],A=e.m[4],b=e.m[5],M=e.m[6],P=e.m[7],S=e.m[8],C=e.m[9],I=e.m[10],D=e.m[11],R=e.m[12],w=e.m[13],L=e.m[14],O=e.m[15];return t[r]=i*y+n*A+s*S+o*R,t[r+1]=i*x+n*b+s*C+o*w,t[r+2]=i*E+n*M+s*I+o*L,t[r+3]=i*T+n*P+s*D+o*O,t[r+4]=a*y+h*A+c*S+l*R,t[r+5]=a*x+h*b+c*C+l*w,t[r+6]=a*E+h*M+c*I+l*L,t[r+7]=a*T+h*P+c*D+l*O,t[r+8]=u*y+f*A+d*S+p*R,t[r+9]=u*x+f*b+d*C+p*w,t[r+10]=u*E+f*M+d*I+p*L,t[r+11]=u*T+f*P+d*D+p*O,t[r+12]=m*y+g*A+_*S+v*R,t[r+13]=m*x+g*b+_*C+v*w,t[r+14]=m*E+g*M+_*I+v*L,t[r+15]=m*T+g*P+_*D+v*O,this},t.prototype.equals=function(e){return e&&this.m[0]===e.m[0]&&this.m[1]===e.m[1]&&this.m[2]===e.m[2]&&this.m[3]===e.m[3]&&this.m[4]===e.m[4]&&this.m[5]===e.m[5]&&this.m[6]===e.m[6]&&this.m[7]===e.m[7]&&this.m[8]===e.m[8]&&this.m[9]===e.m[9]&&this.m[10]===e.m[10]&&this.m[11]===e.m[11]&&this.m[12]===e.m[12]&&this.m[13]===e.m[13]&&this.m[14]===e.m[14]&&this.m[15]===e.m[15]},t.prototype.clone=function(){return t.FromValues(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5],this.m[6],this.m[7],this.m[8],this.m[9],this.m[10],this.m[11],this.m[12],this.m[13],this.m[14],this.m[15])},t.prototype.decompose=function(r,i,n){n.x=this.m[12],n.y=this.m[13],n.z=this.m[14];var s=e.Tools.Sign(this.m[0]*this.m[1]*this.m[2]*this.m[3])<0?-1:1,o=e.Tools.Sign(this.m[4]*this.m[5]*this.m[6]*this.m[7])<0?-1:1,a=e.Tools.Sign(this.m[8]*this.m[9]*this.m[10]*this.m[11])<0?-1:1;if(r.x=s*Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]+this.m[2]*this.m[2]),r.y=o*Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]+this.m[6]*this.m[6]),r.z=a*Math.sqrt(this.m[8]*this.m[8]+this.m[9]*this.m[9]+this.m[10]*this.m[10]),0===r.x||0===r.y||0===r.z)return i.x=0,i.y=0,i.z=0,i.w=1,!1;var c=t.FromValues(this.m[0]/r.x,this.m[1]/r.x,this.m[2]/r.x,0,this.m[4]/r.y,this.m[5]/r.y,this.m[6]/r.y,0,this.m[8]/r.z,this.m[9]/r.z,this.m[10]/r.z,0,0,0,0,1);return h.FromRotationMatrixToRef(c,i),!0},t.FromArray=function(e,r){var i=new t;return r||(r=0),t.FromArrayToRef(e,r,i),i},t.FromArrayToRef=function(e,t,r){for(var i=0;16>i;i++)r.m[i]=e[i+t]},t.FromFloat32ArrayToRefScaled=function(e,t,r,i){for(var n=0;16>n;n++)i.m[n]=e[n+t]*r},t.FromValuesToRef=function(e,t,r,i,n,s,o,a,h,c,l,u,f,d,p,m,g){g.m[0]=e,g.m[1]=t,g.m[2]=r,g.m[3]=i,g.m[4]=n,g.m[5]=s,g.m[6]=o,g.m[7]=a,g.m[8]=h,g.m[9]=c,g.m[10]=l,g.m[11]=u,g.m[12]=f,g.m[13]=d,g.m[14]=p,g.m[15]=m},t.FromValues=function(e,r,i,n,s,o,a,h,c,l,u,f,d,p,m,g){var _=new t;return _.m[0]=e,_.m[1]=r,_.m[2]=i,_.m[3]=n,_.m[4]=s,_.m[5]=o,_.m[6]=a,_.m[7]=h,_.m[8]=c,_.m[9]=l,_.m[10]=u,_.m[11]=f,_.m[12]=d,_.m[13]=p,_.m[14]=m,_.m[15]=g,_},t.Compose=function(e,r,i){var n=t.FromValues(e.x,0,0,0,0,e.y,0,0,0,0,e.z,0,0,0,0,1),s=t.Identity();return r.toRotationMatrix(s),n=n.multiply(s),n.setTranslation(i),n},t.Identity=function(){return t.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},t.IdentityToRef=function(e){t.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,e)},t.Zero=function(){return t.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},t.RotationX=function(e){var r=new t;return t.RotationXToRef(e,r),r},t.Invert=function(e){var r=new t;return e.invertToRef(r),r},t.RotationXToRef=function(e,t){var r=Math.sin(e),i=Math.cos(e);t.m[0]=1,t.m[15]=1,t.m[5]=i,t.m[10]=i,t.m[9]=-r,t.m[6]=r,t.m[1]=0,t.m[2]=0,t.m[3]=0,t.m[4]=0,t.m[7]=0,t.m[8]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},t.RotationY=function(e){var r=new t;return t.RotationYToRef(e,r),r},t.RotationYToRef=function(e,t){var r=Math.sin(e),i=Math.cos(e);t.m[5]=1,t.m[15]=1,t.m[0]=i,t.m[2]=-r,t.m[8]=r,t.m[10]=i,t.m[1]=0,t.m[3]=0,t.m[4]=0,t.m[6]=0,t.m[7]=0,t.m[9]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},t.RotationZ=function(e){var r=new t;return t.RotationZToRef(e,r),r},t.RotationZToRef=function(e,t){var r=Math.sin(e),i=Math.cos(e); t.m[10]=1,t.m[15]=1,t.m[0]=i,t.m[1]=r,t.m[4]=-r,t.m[5]=i,t.m[2]=0,t.m[3]=0,t.m[6]=0,t.m[7]=0,t.m[8]=0,t.m[9]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},t.RotationAxis=function(e,r){var i=t.Zero();return t.RotationAxisToRef(e,r,i),i},t.RotationAxisToRef=function(e,t,r){var i=Math.sin(-t),n=Math.cos(-t),s=1-n;e.normalize(),r.m[0]=e.x*e.x*s+n,r.m[1]=e.x*e.y*s-e.z*i,r.m[2]=e.x*e.z*s+e.y*i,r.m[3]=0,r.m[4]=e.y*e.x*s+e.z*i,r.m[5]=e.y*e.y*s+n,r.m[6]=e.y*e.z*s-e.x*i,r.m[7]=0,r.m[8]=e.z*e.x*s-e.y*i,r.m[9]=e.z*e.y*s+e.x*i,r.m[10]=e.z*e.z*s+n,r.m[11]=0,r.m[15]=1},t.RotationYawPitchRoll=function(e,r,i){var n=new t;return t.RotationYawPitchRollToRef(e,r,i,n),n},t.RotationYawPitchRollToRef=function(e,t,r,i){h.RotationYawPitchRollToRef(e,t,r,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(i)},t.Scaling=function(e,r,i){var n=t.Zero();return t.ScalingToRef(e,r,i,n),n},t.ScalingToRef=function(e,t,r,i){i.m[0]=e,i.m[1]=0,i.m[2]=0,i.m[3]=0,i.m[4]=0,i.m[5]=t,i.m[6]=0,i.m[7]=0,i.m[8]=0,i.m[9]=0,i.m[10]=r,i.m[11]=0,i.m[12]=0,i.m[13]=0,i.m[14]=0,i.m[15]=1},t.Translation=function(e,r,i){var n=t.Identity();return t.TranslationToRef(e,r,i,n),n},t.TranslationToRef=function(e,r,i,n){t.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,e,r,i,1,n)},t.Lerp=function(e,r,i){var n=new o(0,0,0),s=new h,a=new o(0,0,0);e.decompose(n,s,a);var c=new o(0,0,0),l=new h,u=new o(0,0,0);r.decompose(c,l,u);var f=o.Lerp(n,c,i),d=h.Slerp(s,l,i),p=o.Lerp(a,u,i);return t.Compose(f,d,p)},t.LookAtLH=function(e,r,i){var n=t.Zero();return t.LookAtLHToRef(e,r,i,n),n},t.LookAtLHToRef=function(e,r,i,n){r.subtractToRef(e,this._zAxis),this._zAxis.normalize(),o.CrossToRef(i,this._zAxis,this._xAxis),0===this._xAxis.lengthSquared()?this._xAxis.x=1:this._xAxis.normalize(),o.CrossToRef(this._zAxis,this._xAxis,this._yAxis),this._yAxis.normalize();var s=-o.Dot(this._xAxis,e),a=-o.Dot(this._yAxis,e),h=-o.Dot(this._zAxis,e);return t.FromValuesToRef(this._xAxis.x,this._yAxis.x,this._zAxis.x,0,this._xAxis.y,this._yAxis.y,this._zAxis.y,0,this._xAxis.z,this._yAxis.z,this._zAxis.z,0,s,a,h,1,n)},t.OrthoLH=function(e,r,i,n){var s=t.Zero();return t.OrthoLHToRef(e,r,i,n,s),s},t.OrthoLHToRef=function(e,r,i,n,s){var o=2/e,a=2/r,h=1/(n-i),c=i/(i-n);t.FromValuesToRef(o,0,0,0,0,a,0,0,0,0,h,0,0,0,c,1,s)},t.OrthoOffCenterLH=function(e,r,i,n,s,o){var a=t.Zero();return t.OrthoOffCenterLHToRef(e,r,i,n,s,o,a),a},t.OrthoOffCenterLHToRef=function(e,t,r,i,n,s,o){o.m[0]=2/(t-e),o.m[1]=o.m[2]=o.m[3]=0,o.m[5]=2/(i-r),o.m[4]=o.m[6]=o.m[7]=0,o.m[10]=-1/(n-s),o.m[8]=o.m[9]=o.m[11]=0,o.m[12]=(e+t)/(e-t),o.m[13]=(i+r)/(r-i),o.m[14]=n/(n-s),o.m[15]=1},t.PerspectiveLH=function(e,r,i,n){var s=t.Zero();return s.m[0]=2*i/e,s.m[1]=s.m[2]=s.m[3]=0,s.m[5]=2*i/r,s.m[4]=s.m[6]=s.m[7]=0,s.m[10]=-n/(i-n),s.m[8]=s.m[9]=0,s.m[11]=1,s.m[12]=s.m[13]=s.m[15]=0,s.m[14]=i*n/(i-n),s},t.PerspectiveFovLH=function(e,r,i,n){var s=t.Zero();return t.PerspectiveFovLHToRef(e,r,i,n,s),s},t.PerspectiveFovLHToRef=function(t,r,i,n,s,o){void 0===o&&(o=e.Camera.FOVMODE_VERTICAL_FIXED);var a=1/Math.tan(.5*t),h=o===e.Camera.FOVMODE_VERTICAL_FIXED;h?s.m[0]=a/r:s.m[0]=a,s.m[1]=s.m[2]=s.m[3]=0,h?s.m[5]=a:s.m[5]=a*r,s.m[4]=s.m[6]=s.m[7]=0,s.m[8]=s.m[9]=0,s.m[10]=-n/(i-n),s.m[11]=1,s.m[12]=s.m[13]=s.m[15]=0,s.m[14]=i*n/(i-n)},t.GetFinalMatrix=function(e,r,i,n,s,o){var a=e.width,h=e.height,c=e.x,l=e.y,u=t.FromValues(a/2,0,0,0,0,-h/2,0,0,0,0,o-s,0,c+a/2,h/2+l,s,1);return r.multiply(i).multiply(n).multiply(u)},t.GetAsMatrix2x2=function(e){return new Float32Array([e.m[0],e.m[1],e.m[4],e.m[5]])},t.GetAsMatrix3x3=function(e){return new Float32Array([e.m[0],e.m[1],e.m[2],e.m[4],e.m[5],e.m[6],e.m[8],e.m[9],e.m[10]])},t.Transpose=function(e){var r=new t;return r.m[0]=e.m[0],r.m[1]=e.m[4],r.m[2]=e.m[8],r.m[3]=e.m[12],r.m[4]=e.m[1],r.m[5]=e.m[5],r.m[6]=e.m[9],r.m[7]=e.m[13],r.m[8]=e.m[2],r.m[9]=e.m[6],r.m[10]=e.m[10],r.m[11]=e.m[14],r.m[12]=e.m[3],r.m[13]=e.m[7],r.m[14]=e.m[11],r.m[15]=e.m[15],r},t.Reflection=function(e){var r=new t;return t.ReflectionToRef(e,r),r},t.ReflectionToRef=function(e,t){e.normalize();var r=e.normal.x,i=e.normal.y,n=e.normal.z,s=-2*r,o=-2*i,a=-2*n;t.m[0]=s*r+1,t.m[1]=o*r,t.m[2]=a*r,t.m[3]=0,t.m[4]=s*i,t.m[5]=o*i+1,t.m[6]=a*i,t.m[7]=0,t.m[8]=s*n,t.m[9]=o*n,t.m[10]=a*n+1,t.m[11]=0,t.m[12]=s*e.d,t.m[13]=o*e.d,t.m[14]=a*e.d,t.m[15]=1},t._tempQuaternion=new h,t._xAxis=o.Zero(),t._yAxis=o.Zero(),t._zAxis=o.Zero(),t}();e.Matrix=c;var l=function(){function e(e,t,r,i){this.normal=new o(e,t,r),this.d=i}return e.prototype.asArray=function(){return[this.normal.x,this.normal.y,this.normal.z,this.d]},e.prototype.clone=function(){return new e(this.normal.x,this.normal.y,this.normal.z,this.d)},e.prototype.normalize=function(){var e=Math.sqrt(this.normal.x*this.normal.x+this.normal.y*this.normal.y+this.normal.z*this.normal.z),t=0;return 0!==e&&(t=1/e),this.normal.x*=t,this.normal.y*=t,this.normal.z*=t,this.d*=t,this},e.prototype.transform=function(t){var r=c.Transpose(t),i=this.normal.x,n=this.normal.y,s=this.normal.z,o=this.d,a=i*r.m[0]+n*r.m[1]+s*r.m[2]+o*r.m[3],h=i*r.m[4]+n*r.m[5]+s*r.m[6]+o*r.m[7],l=i*r.m[8]+n*r.m[9]+s*r.m[10]+o*r.m[11],u=i*r.m[12]+n*r.m[13]+s*r.m[14]+o*r.m[15];return new e(a,h,l,u)},e.prototype.dotCoordinate=function(e){return this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z+this.d},e.prototype.copyFromPoints=function(e,t,r){var i,n=t.x-e.x,s=t.y-e.y,o=t.z-e.z,a=r.x-e.x,h=r.y-e.y,c=r.z-e.z,l=s*c-o*h,u=o*a-n*c,f=n*h-s*a,d=Math.sqrt(l*l+u*u+f*f);return i=0!==d?1/d:0,this.normal.x=l*i,this.normal.y=u*i,this.normal.z=f*i,this.d=-(this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z),this},e.prototype.isFrontFacingTo=function(e,t){var r=o.Dot(this.normal,e);return t>=r},e.prototype.signedDistanceTo=function(e){return o.Dot(e,this.normal)+this.d},e.FromArray=function(t){return new e(t[0],t[1],t[2],t[3])},e.FromPoints=function(t,r,i){var n=new e(0,0,0,0);return n.copyFromPoints(t,r,i),n},e.FromPositionAndNormal=function(t,r){var i=new e(0,0,0,0);return r.normalize(),i.normal=r,i.d=-(r.x*t.x+r.y*t.y+r.z*t.z),i},e.SignedDistanceToPlaneFromPositionAndNormal=function(e,t,r){var i=-(t.x*e.x+t.y*e.y+t.z*e.z);return o.Dot(r,t)+i},e}();e.Plane=l;var u=function(){function e(e,t,r,i){this.x=e,this.y=t,this.width=r,this.height=i}return e.prototype.toGlobal=function(t){var r=t.getRenderWidth(),i=t.getRenderHeight();return new e(this.x*r,this.y*i,this.width*r,this.height*i)},e.prototype.toScreenGlobal=function(t){var r=t.getRenderWidth(!0),i=t.getRenderHeight(!0);return new e(this.x*r,this.y*i,this.width*r,this.height*i)},e}();e.Viewport=u;var f=function(){function e(){}return e.GetPlanes=function(t){for(var r=[],i=0;6>i;i++)r.push(new l(0,0,0,0));return e.GetPlanesToRef(t,r),r},e.GetPlanesToRef=function(e,t){t[0].normal.x=e.m[3]+e.m[2],t[0].normal.y=e.m[7]+e.m[6],t[0].normal.z=e.m[11]+e.m[10],t[0].d=e.m[15]+e.m[14],t[0].normalize(),t[1].normal.x=e.m[3]-e.m[2],t[1].normal.y=e.m[7]-e.m[6],t[1].normal.z=e.m[11]-e.m[10],t[1].d=e.m[15]-e.m[14],t[1].normalize(),t[2].normal.x=e.m[3]+e.m[0],t[2].normal.y=e.m[7]+e.m[4],t[2].normal.z=e.m[11]+e.m[8],t[2].d=e.m[15]+e.m[12],t[2].normalize(),t[3].normal.x=e.m[3]-e.m[0],t[3].normal.y=e.m[7]-e.m[4],t[3].normal.z=e.m[11]-e.m[8],t[3].d=e.m[15]-e.m[12],t[3].normalize(),t[4].normal.x=e.m[3]-e.m[1],t[4].normal.y=e.m[7]-e.m[5],t[4].normal.z=e.m[11]-e.m[9],t[4].d=e.m[15]-e.m[13],t[4].normalize(),t[5].normal.x=e.m[3]+e.m[1],t[5].normal.y=e.m[7]+e.m[5],t[5].normal.z=e.m[11]+e.m[9],t[5].d=e.m[15]+e.m[13],t[5].normalize()},e}();e.Frustum=f;var d=function(){function t(e,t,r){void 0===r&&(r=Number.MAX_VALUE),this.origin=e,this.direction=t,this.length=r}return t.prototype.intersectsBoxMinMax=function(e,t){var r,i,n,s,o=0,a=Number.MAX_VALUE;if(Math.abs(this.direction.x)<1e-7){if(this.origin.xt.x)return!1}else if(r=1/this.direction.x,i=(e.x-this.origin.x)*r,n=(t.x-this.origin.x)*r,n===-(1/0)&&(n=1/0),i>n&&(s=i,i=n,n=s),o=Math.max(i,o),a=Math.min(n,a),o>a)return!1;if(Math.abs(this.direction.y)<1e-7){if(this.origin.yt.y)return!1}else if(r=1/this.direction.y,i=(e.y-this.origin.y)*r,n=(t.y-this.origin.y)*r,n===-(1/0)&&(n=1/0),i>n&&(s=i,i=n,n=s),o=Math.max(i,o),a=Math.min(n,a),o>a)return!1;if(Math.abs(this.direction.z)<1e-7){if(this.origin.zt.z)return!1}else if(r=1/this.direction.z,i=(e.z-this.origin.z)*r,n=(t.z-this.origin.z)*r,n===-(1/0)&&(n=1/0),i>n&&(s=i,i=n,n=s),o=Math.max(i,o),a=Math.min(n,a),o>a)return!1;return!0},t.prototype.intersectsBox=function(e){return this.intersectsBoxMinMax(e.minimum,e.maximum)},t.prototype.intersectsSphere=function(e){var t=e.center.x-this.origin.x,r=e.center.y-this.origin.y,i=e.center.z-this.origin.z,n=t*t+r*r+i*i,s=e.radius*e.radius;if(s>=n)return!0;var o=t*this.direction.x+r*this.direction.y+i*this.direction.z;if(0>o)return!1;var a=n-o*o;return s>=a},t.prototype.intersectsTriangle=function(t,r,i){this._edge1||(this._edge1=o.Zero(),this._edge2=o.Zero(),this._pvec=o.Zero(),this._tvec=o.Zero(),this._qvec=o.Zero()),r.subtractToRef(t,this._edge1),i.subtractToRef(t,this._edge2),o.CrossToRef(this.direction,this._edge2,this._pvec);var n=o.Dot(this._edge1,this._pvec);if(0===n)return null;var s=1/n;this.origin.subtractToRef(t,this._tvec);var a=o.Dot(this._tvec,this._pvec)*s;if(0>a||a>1)return null;o.CrossToRef(this._tvec,this._edge1,this._qvec);var h=o.Dot(this.direction,this._qvec)*s;if(0>h||a+h>1)return null;var c=o.Dot(this._edge2,this._qvec)*s;return c>this.length?null:new e.IntersectionInfo(a,h,c)},t.CreateNew=function(e,r,i,n,s,a,h){var c=o.Unproject(new o(e,r,0),i,n,s,a,h),l=o.Unproject(new o(e,r,1),i,n,s,a,h),u=l.subtract(c);return u.normalize(),new t(c,u)},t.CreateNewFromTo=function(e,r,i){void 0===i&&(i=c.Identity());var n=r.subtract(e),s=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z);return n.normalize(),t.Transform(new t(e,n,s),i)},t.Transform=function(e,r){var i=o.TransformCoordinates(e.origin,r),n=o.TransformNormal(e.direction,r);return new t(i,n,e.length)},t}();e.Ray=d,function(e){e[e.LOCAL=0]="LOCAL",e[e.WORLD=1]="WORLD"}(e.Space||(e.Space={}));var p=(e.Space,function(){function e(){}return e.X=new o(1,0,0),e.Y=new o(0,1,0),e.Z=new o(0,0,1),e}());e.Axis=p;var m=function(){function e(){}return e.interpolate=function(e,t,r,i,n){for(var s=1-3*i+3*t,o=3*i-6*t,a=3*t,h=e,c=0;5>c;c++){var l=h*h,u=l*h,f=s*u+o*l+a*h,d=1/(3*s*l+2*o*h+a);h-=(f-e)*d,h=Math.min(1,Math.max(0,h))}return 3*Math.pow(1-h,2)*h*r+3*(1-h)*Math.pow(h,2)*n+Math.pow(h,3)},e}();e.BezierCurve=m,function(e){e[e.CW=0]="CW",e[e.CCW=1]="CCW"}(e.Orientation||(e.Orientation={}));var g=e.Orientation,_=function(){function e(e){var t=this;this.degrees=function(){return 180*t._radians/Math.PI},this.radians=function(){return t._radians},this._radians=e,this._radians<0&&(this._radians+=2*Math.PI)}return e.BetweenTwoPoints=function(t,r){var i=r.subtract(t),n=Math.atan2(i.y,i.x);return new e(n)},e.FromRadians=function(t){return new e(t)},e.FromDegrees=function(t){return new e(t*Math.PI/180)},e}();e.Angle=_;var v=function(){function e(e,t,r){this.startPoint=e,this.midPoint=t,this.endPoint=r;var i=Math.pow(t.x,2)+Math.pow(t.y,2),n=(Math.pow(e.x,2)+Math.pow(e.y,2)-i)/2,o=(i-Math.pow(r.x,2)-Math.pow(r.y,2))/2,a=(e.x-t.x)*(t.y-r.y)-(t.x-r.x)*(e.y-t.y);this.centerPoint=new s((n*(t.y-r.y)-o*(e.y-t.y))/a,((e.x-t.x)*o-(t.x-r.x)*n)/a),this.radius=this.centerPoint.subtract(this.startPoint).length(),this.startAngle=_.BetweenTwoPoints(this.centerPoint,this.startPoint);var h=this.startAngle.degrees(),c=_.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),l=_.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?g.CW:g.CCW,this.angle=_.FromDegrees(this.orientation===g.CW?h-l:l-h)}return e}();e.Arc2=v;var y=function(){function e(e){this.path=e,this._onchange=new Array,this.value=0,this.animations=new Array}return e.prototype.getPoint=function(){var e=this.path.getPointAtLengthPosition(this.value);return new o(e.x,0,e.y)},e.prototype.moveAhead=function(e){return void 0===e&&(e=.002),this.move(e),this},e.prototype.moveBack=function(e){return void 0===e&&(e=.002),this.move(-e),this},e.prototype.move=function(e){if(Math.abs(e)>1)throw"step size should be less than 1.";return this.value+=e,this.ensureLimits(),this.raiseOnChange(),this},e.prototype.ensureLimits=function(){for(;this.value>1;)this.value-=1;for(;this.value<0;)this.value+=1;return this},e.prototype.markAsDirty=function(e){return this.ensureLimits(),this.raiseOnChange(),this},e.prototype.raiseOnChange=function(){var e=this;return this._onchange.forEach(function(t){return t(e)}),this},e.prototype.onchange=function(e){return this._onchange.push(e),this},e}();e.PathCursor=y;var x=function(){function t(e,t){this._points=new Array,this._length=0,this.closed=!1,this._points.push(new s(e,t))}return t.prototype.addLineTo=function(t,r){if(closed)return e.Tools.Error("cannot add lines to closed paths"),this;var i=new s(t,r),n=this._points[this._points.length-1];return this._points.push(i),this._length+=i.subtract(n).length(),this},t.prototype.addArcTo=function(t,r,i,n,o){if(void 0===o&&(o=36),closed)return e.Tools.Error("cannot add arcs to closed paths"),this;var a=this._points[this._points.length-1],h=new s(t,r),c=new s(i,n),l=new v(a,h,c),u=l.angle.radians()/o;l.orientation===g.CW&&(u*=-1);for(var f=l.startAngle.radians()+u,d=0;o>d;d++){var p=Math.cos(f)*l.radius+l.centerPoint.x,m=Math.sin(f)*l.radius+l.centerPoint.y;this.addLineTo(p,m),f+=u}return this},t.prototype.close=function(){return this.closed=!0,this},t.prototype.length=function(){var e=this._length;if(!this.closed){var t=this._points[this._points.length-1],r=this._points[0];e+=r.subtract(t).length()}return e},t.prototype.getPoints=function(){return this._points},t.prototype.getPointAtLengthPosition=function(t){if(0>t||t>1)return e.Tools.Error("normalized length position should be between 0 and 1."),s.Zero();for(var r=t*this.length(),i=0,n=0;n=i&&l>=r){var u=c.normalize(),f=r-i;return new s(a.x+u.x*f,a.y+u.y*f)}i=l}return e.Tools.Error("internal error"),s.Zero()},t.StartingAt=function(e,r){return new t(e,r)},t}();e.Path2=x;var E=function(){function t(e,t,r){this.path=e,this._curve=new Array,this._distances=new Array,this._tangents=new Array,this._normals=new Array,this._binormals=new Array;for(var i=0;ic;c++)n=this._getLastNonNullVector(c),t-1>c&&(s=this._getFirstNonNullVector(c),this._tangents[c]=n.add(s),this._tangents[c].normalize()),this._distances[c]=this._distances[c-1]+n.length(),a=this._tangents[c],h=this._binormals[c-1],this._normals[c]=o.Cross(h,a),this._raw||this._normals[c].normalize(),this._binormals[c]=o.Cross(a,this._normals[c]),this._raw||this._binormals[c].normalize()},t.prototype._getFirstNonNullVector=function(e){for(var t=1,r=this._curve[e+t].subtract(this._curve[e]);0===r.length()&&e+t+1t+1;)t++,r=this._curve[e].subtract(this._curve[e-t]);return r},t.prototype._normalVector=function(t,r,i){var n;if(void 0===i||null===i){var s;e.Tools.WithinEpsilon(r.y,1,e.Engine.Epsilon)?e.Tools.WithinEpsilon(r.x,1,e.Engine.Epsilon)?e.Tools.WithinEpsilon(r.z,1,e.Engine.Epsilon)||(s=new o(0,0,1)):s=new o(1,0,0):s=new o(0,-1,0),n=o.Cross(r,s)}else n=o.Cross(r,i),o.CrossToRef(n,r,n);return n.normalize(),n},t}();e.Path3D=E;var T=function(){function e(e){this._length=0,this._points=e,this._length=this._computeLength(e)}return e.CreateQuadraticBezier=function(t,r,i,n){n=n>2?n:3;for(var s=new Array,a=function(e,t,r,i){var n=(1-e)*(1-e)*t+2*e*(1-e)*r+e*e*i;return n},h=0;n>=h;h++)s.push(new o(a(h/n,t.x,r.x,i.x),a(h/n,t.y,r.y,i.y),a(h/n,t.z,r.z,i.z)));return new e(s)},e.CreateCubicBezier=function(t,r,i,n,s){s=s>3?s:4;for(var a=new Array,h=function(e,t,r,i,n){var s=(1-e)*(1-e)*(1-e)*t+3*e*(1-e)*(1-e)*r+3*e*e*(1-e)*i+e*e*e*n;return s},c=0;s>=c;c++)a.push(new o(h(c/s,t.x,r.x,i.x,n.x),h(c/s,t.y,r.y,i.y,n.y),h(c/s,t.z,r.z,i.z,n.z)));return new e(a)},e.CreateHermiteSpline=function(t,r,i,n,s){for(var a=new Array,h=1/s,c=0;s>=c;c++)a.push(o.Hermite(t,r,i,n,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 r=this._points[this._points.length-1],i=this._points.slice(),n=t.getPoints(),s=1;ss.data?(n.mustUpdateRessources=!0,i()):r(s.data):(n.mustUpdateRessources=!0,i())},o.onabort=function(e){r(-1)};var a=o.objectStore("versions").get(t);a.onsuccess=function(e){s=e.target.result},a.onerror=function(i){e.Tools.Error("Error loading version for scene "+t+" from DB."),r(-1)}}catch(h){e.Tools.Error("Error while accessing 'versions' object store (READ OP). Exception: "+h.message),r(-1)}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),r(-1)},t.prototype._saveVersionIntoDBAsync=function(t,r){var i=this;if(this.isSupported&&!this.hasReachedQuota)try{var n=this.db.transaction(["versions"],"readwrite");n.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(i.hasReachedQuota=!0)}catch(t){}r(-1)},n.oncomplete=function(e){r(i.manifestVersionFound)};var s={sceneUrl:t,data:this.manifestVersionFound},o=n.objectStore("versions").put(s);o.onsuccess=function(e){},o.onerror=function(t){e.Tools.Error("Error in DB add version request in BABYLON.Database.")}}catch(a){e.Tools.Error("Error while accessing 'versions' object store (WRITE OP). Exception: "+a.message),r(-1)}else r(-1)},t.prototype.loadFileFromDB=function(e,r,i,n,s){var o=this,a=t.ReturnFullUrlLocation(e),h=function(e){o._saveFileIntoDBAsync(a,r,i)};this._checkVersionFromDB(a,function(e){-1!==e?o.mustUpdateRessources?o._saveFileIntoDBAsync(a,r,i,s):o._loadFileFromDBAsync(a,r,h,s):n()})},t.prototype._loadFileFromDBAsync=function(t,r,i,n){if(this.isSupported){var s;s=-1!==t.indexOf(".babylon")?"scenes":"textures";var o,a=this.db.transaction([s]);a.oncomplete=function(e){o?r(o.data):i()},a.onabort=function(e){i()};var h=a.objectStore(s).get(t);h.onsuccess=function(e){o=e.target.result},h.onerror=function(r){e.Tools.Error("Error loading file "+t+" from DB."),i()}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),r()},t.prototype._saveFileIntoDBAsync=function(t,r,i,n){var s=this;if(this.isSupported){var o;o=-1!==t.indexOf(".babylon")?"scenes":"textures";var a,h=new XMLHttpRequest;h.open("GET",t,!0),n&&(h.responseType="arraybuffer"),h.onprogress=i,h.addEventListener("load",function(){if(200===h.status||e.Tools.ValidateXHRData(h,n?6:1))if(a=n?h.response:h.responseText,s.hasReachedQuota)r(a);else{var i=s.db.transaction([o],"readwrite");i.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(t){}r(a)},i.oncomplete=function(e){r(a)};var c;c="scenes"===o?{sceneUrl:t,data:a,version:s.manifestVersionFound}:{textureUrl:t,data:a};try{var l=i.objectStore(o).put(c);l.onsuccess=function(e){},l.onerror=function(t){e.Tools.Error("Error in DB add file request in BABYLON.Database.")}}catch(u){r(a)}}else r()},!1),h.addEventListener("error",function(t){e.Tools.Error("error on XHR request."),r()},!1),h.send()}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),r()},t.IsUASupportingBlobStorage=!0,t.IDBStorageEnabled=!0,t.parseURL=function(e){var t=document.createElement("a");t.href=e;var r=e.substring(0,e.lastIndexOf("#")),i=e.substring(r.lastIndexOf("/")+1,e.length),n=e.substring(0,e.indexOf(i,0));return n},t.ReturnFullUrlLocation=function(e){return-1===e.indexOf("http:/")?t.parseURL(window.location.href)+e:e},t}();e.Database=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){var r=function(){function t(){}return t.GetTGAHeader=function(e){var t=0,r={id_length:e[t++],colormap_type:e[t++],image_type:e[t++],colormap_index:e[t++]|e[t++]<<8,colormap_length:e[t++]|e[t++]<<8,colormap_size:e[t++],origin:[e[t++]|e[t++]<<8,e[t++]|e[t++]<<8],width:e[t++]|e[t++]<<8,height:e[t++]|e[t++]<<8,pixel_size:e[t++],flags:e[t++]};return r},t.UploadContent=function(r,i){if(i.length<19)return void e.Tools.Error("Unable to load TGA file - Not enough data to contain header");var n=18,s=t.GetTGAHeader(i);if(s.id_length+n>i.length)return void e.Tools.Error("Unable to load TGA file - Not enough data");n+=s.id_length;var o=!1,a=!1,h=!1,c=!1;switch(s.image_type){case t._TYPE_RLE_INDEXED:o=!0;case t._TYPE_INDEXED:a=!0;break;case t._TYPE_RLE_RGB:o=!0;case t._TYPE_RGB:h=!0;break;case t._TYPE_RLE_GREY:o=!0;case t._TYPE_GREY:c=!0}var l,u,f=(15&s.flags,s.pixel_size>>3),d=s.width*s.height*f;if(a&&(u=i.subarray(n,n+=s.colormap_length*(s.colormap_size>>3))),o){l=new Uint8Array(d);for(var p,m,g,_=0,v=new Uint8Array(f);d>n&&d>_;)if(p=i[n++],m=(127&p)+1,128&p){for(g=0;f>g;++g)v[g]=i[n++];for(g=0;m>g;++g)l.set(v,_+g*f);_+=f*m}else{for(m*=f,g=0;m>g;++g)l[_+g]=i[n++];_+=m}}else l=i.subarray(n,n+=a?s.width*s.height:d);var y,x,E,T,A,b;switch((s.flags&t._ORIGIN_MASK)>>t._ORIGIN_SHIFT){default:case t._ORIGIN_UL:y=0,E=1,b=s.width,x=0,T=1,A=s.height;break;case t._ORIGIN_BL:y=0,E=1,b=s.width,x=s.height-1,T=-1,A=-1;break;case t._ORIGIN_UR:y=s.width-1,E=-1,b=-1,x=0,T=1,A=s.height;break;case t._ORIGIN_BR:y=s.width-1,E=-1,b=-1,x=s.height-1,T=-1,A=-1}var M="_getImageData"+(c?"Grey":"")+s.pixel_size+"bits",P=t[M](s,u,l,x,T,A,y,E,b);r.texImage2D(r.TEXTURE_2D,0,r.RGBA,s.width,s.height,0,r.RGBA,r.UNSIGNED_BYTE,P)},t._getImageData8bits=function(e,t,r,i,n,s,o,a,h){var c,l,u,f=r,d=t,p=e.width,m=e.height,g=0,_=new Uint8Array(p*m*4);for(u=i;u!==s;u+=n)for(l=o;l!==h;l+=a,g++)c=f[g],_[4*(l+p*u)+3]=255,_[4*(l+p*u)+2]=d[3*c+0],_[4*(l+p*u)+1]=d[3*c+1],_[4*(l+p*u)+0]=d[3*c+2];return _},t._getImageData16bits=function(e,t,r,i,n,s,o,a,h){var c,l,u,f=r,d=e.width,p=e.height,m=0,g=new Uint8Array(d*p*4);for(u=i;u!==s;u+=n)for(l=o;l!==h;l+=a,m+=2)c=f[m+0]+(f[m+1]<<8),g[4*(l+d*u)+0]=(31744&c)>>7,g[4*(l+d*u)+1]=(992&c)>>2,g[4*(l+d*u)+2]=(31&c)>>3,g[4*(l+d*u)+3]=32768&c?0:255;return g},t._getImageData24bits=function(e,t,r,i,n,s,o,a,h){var c,l,u=r,f=e.width,d=e.height,p=0,m=new Uint8Array(f*d*4);for(l=i;l!==s;l+=n)for(c=o;c!==h;c+=a,p+=3)m[4*(c+f*l)+3]=255,m[4*(c+f*l)+2]=u[p+0],m[4*(c+f*l)+1]=u[p+1],m[4*(c+f*l)+0]=u[p+2];return m},t._getImageData32bits=function(e,t,r,i,n,s,o,a,h){var c,l,u=r,f=e.width,d=e.height,p=0,m=new Uint8Array(f*d*4);for(l=i;l!==s;l+=n)for(c=o;c!==h;c+=a,p+=4)m[4*(c+f*l)+2]=u[p+0],m[4*(c+f*l)+1]=u[p+1],m[4*(c+f*l)+0]=u[p+2],m[4*(c+f*l)+3]=u[p+3];return m},t._getImageDataGrey8bits=function(e,t,r,i,n,s,o,a,h){var c,l,u,f=r,d=e.width,p=e.height,m=0,g=new Uint8Array(d*p*4);for(u=i;u!==s;u+=n)for(l=o;l!==h;l+=a,m++)c=f[m],g[4*(l+d*u)+0]=c,g[4*(l+d*u)+1]=c,g[4*(l+d*u)+2]=c,g[4*(l+d*u)+3]=255;return g},t._getImageDataGrey16bits=function(e,t,r,i,n,s,o,a,h){var c,l,u=r,f=e.width,d=e.height,p=0,m=new Uint8Array(f*d*4);for(l=i;l!==s;l+=n)for(c=o;c!==h;c+=a,p+=2)m[4*(c+f*l)+0]=u[p+0],m[4*(c+f*l)+1]=u[p+0],m[4*(c+f*l)+2]=u[p+0],m[4*(c+f*l)+3]=u[p+1];return m},t._TYPE_NO_DATA=0,t._TYPE_INDEXED=1,t._TYPE_RGB=2,t._TYPE_GREY=3,t._TYPE_RLE_INDEXED=9,t._TYPE_RLE_RGB=10,t._TYPE_RLE_GREY=11,t._ORIGIN_MASK=48,t._ORIGIN_SHIFT=4,t._ORIGIN_BL=0,t._ORIGIN_BR=1,t._ORIGIN_UL=2,t._ORIGIN_UR=3,t}();t.TGATools=r}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(t){this.length=0,this._duplicateId=0,this.data=new Array(t),this._id=e._GlobalId++}return e.prototype.push=function(e){this.data[this.length++]=e,this.length>this.data.length&&(this.data.length*=2),e.__smartArrayFlags||(e.__smartArrayFlags={}),e.__smartArrayFlags[this._id]=this._duplicateId},e.prototype.pushNoDuplicate=function(e){e.__smartArrayFlags&&e.__smartArrayFlags[this._id]===this._duplicateId||this.push(e)},e.prototype.sort=function(e){this.data.sort(e)},e.prototype.reset=function(){this.length=0,this._duplicateId++},e.prototype.concat=function(e){if(0!==e.length){this.length+e.length>this.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;tthis.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t=this.length?-1:t},e._GlobalId=0,e}();e.SmartArray=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){void 0===e&&(e=10),this.count=0,this._initialCapacity=e,this.items={},this._keys=new Array(this._initialCapacity)}return e.prototype.add=function(e,t){return void 0!=this.items[e]?-1:(this.items[e]=t,this._keys[this.count++]=e,this.count>this._keys.length&&(this._keys.length*=2),this.count)},e.prototype.remove=function(e){return void 0==this.items[e]?-1:this.removeItemOfIndex(this.indexOf(e))},e.prototype.removeItemOfIndex=function(e){if(!(e-1))return-1;for(delete this.items[this._keys[e]];e0){for(var e=new Array(this.count),t=0;t-1?this._keys[e]:void 0},e.prototype.getItemByIndex=function(e){return e-1?this.items[this._keys[e]]:void 0},e.prototype.empty=function(){this.count>0&&(this.count=0,this.items={},this._keys=new Array(this._initialCapacity))},e.prototype.forEach=function(e){var t;for(t in this.items)this.items.hasOwnProperty(t)&&e(this.items[t])},e}();e.SmartCollection=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t,r=function(t,r){return t?t instanceof e.Mesh?null:t instanceof e.SubMesh?t.clone(r):t.clone?t.clone():null:null},i=function(){function i(){}return i.Instantiate=function(e){for(var t=e.split("."),r=window||this,i=0,n=t.length;n>i;i++)r=r[t[i]];return"function"!=typeof r?null:r},i.GetConstructorName=function(e){var t=(e.prototype?e.prototype.constructor:e.constructor).toString(),r=t.match(/function\s(\w*)/)[1],i=["","anonymous","Anonymous"];return i.indexOf(r)>-1?"Function":r},i.ToHex=function(e){var t=e.toString(16);return 15>=e?("0"+t).toUpperCase():t.toUpperCase()},i.SetImmediate=function(e){window.setImmediate?window.setImmediate(e):setTimeout(e,1)},i.IsExponentOfTwo=function(e){var t=1;do t*=2;while(e>t);return t===e},i.GetExponentOfTwo=function(e,t){var r=1;do r*=2;while(e>r);return r>t&&(r=t),r},i.GetFilename=function(e){var t=e.lastIndexOf("/");return 0>t?e:e.substring(t+1)},i.GetDOMTextContent=function(e){for(var t="",r=e.firstChild;r;)3===r.nodeType&&(t+=r.textContent),r=r.nextSibling;return t},i.ToDegrees=function(e){return 180*e/Math.PI},i.ToRadians=function(e){return e*Math.PI/180},i.EncodeArrayBufferTobase64=function(e){for(var t,r,i,n,s,o,a,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c="",l=0,u=new Uint8Array(e);l>2,s=(3&t)<<4|r>>4,o=(15&r)<<2|i>>6,a=63&i,isNaN(r)?o=a=64:isNaN(i)&&(a=64),c+=h.charAt(n)+h.charAt(s)+h.charAt(o)+h.charAt(a);return"data:image/png;base64,"+c},i.ExtractMinAndMaxIndexed=function(t,r,i,n){for(var s=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),o=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),a=i;i+n>a;a++){var h=new e.Vector3(t[3*r[a]],t[3*r[a]+1],t[3*r[a]+2]);s=e.Vector3.Minimize(h,s),o=e.Vector3.Maximize(h,o)}return{minimum:s,maximum:o}},i.ExtractMinAndMax=function(t,r,i){for(var n=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),s=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),o=r;r+i>o;o++){var a=new e.Vector3(t[3*o],t[3*o+1],t[3*o+2]);n=e.Vector3.Minimize(a,n),s=e.Vector3.Maximize(a,s)}return{minimum:n,maximum:s}},i.MakeArray=function(e,t){return t===!0||void 0!==e&&null!=e?Array.isArray(e)?e:[e]:void 0},i.GetPointerPrefix=function(){var e="pointer";return window.PointerEvent||navigator.pointerEnabled||(e="mouse"),e},i.QueueNewFrame=function(e){window.requestAnimationFrame?window.requestAnimationFrame(e):window.msRequestAnimationFrame?window.msRequestAnimationFrame(e):window.webkitRequestAnimationFrame?window.webkitRequestAnimationFrame(e):window.mozRequestAnimationFrame?window.mozRequestAnimationFrame(e):window.oRequestAnimationFrame?window.oRequestAnimationFrame(e):window.setTimeout(e,16)},i.RequestFullscreen=function(e){e.requestFullscreen?e.requestFullscreen():e.msRequestFullscreen?e.msRequestFullscreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.mozRequestFullScreen&&e.mozRequestFullScreen()},i.ExitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.msCancelFullScreen&&document.msCancelFullScreen()},i.CleanUrl=function(e){return e=e.replace(/#/gm,"%23")},i.LoadImage=function(t,r,n,s){t instanceof ArrayBuffer&&(t=i.EncodeArrayBufferTobase64(t)),t=i.CleanUrl(t);var o=new Image;if("data:"!==t.substr(0,5)&&i.CorsBehavior)switch(typeof i.CorsBehavior){case"function":var a=i.CorsBehavior(t);a&&(o.crossOrigin=a);break;case"string":default:o.crossOrigin=i.CorsBehavior}o.onload=function(){r(o)},o.onerror=function(e){i.Error("Error while trying to load texture: "+t),i.UseFallbackTexture?(o.src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMC41AP/bAEMABAIDAwMCBAMDAwQEBAQFCQYFBQUFCwgIBgkNCw0NDQsMDA4QFBEODxMPDAwSGBITFRYXFxcOERkbGRYaFBYXFv/bAEMBBAQEBQUFCgYGChYPDA8WFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFv/AABEIAQABAAMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APH6KKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76P//Z",r(o)):n()};var h=function(){o.src=t},c=function(){s.loadImageFromDB(t,o)};if("data:"!==t.substr(0,5)&&s&&s.enableTexturesOffline&&e.Database.IsUASupportingBlobStorage)s.openAsync(c,h);else if(-1===t.indexOf("file:"))h();else try{var l,u=t.substring(5);try{l=URL.createObjectURL(e.FilesInput.FilesTextures[u],{oneTimeOnly:!0})}catch(f){l=URL.createObjectURL(e.FilesInput.FilesTextures[u])}o.src=l}catch(d){o.src=null}return o},i.LoadFile=function(t,r,n,s,o,a){t=i.CleanUrl(t);var h=function(){var e=new XMLHttpRequest,s=i.BaseUrl+t;e.open("GET",s,!0),o&&(e.responseType="arraybuffer"),e.onprogress=n,e.onreadystatechange=function(){if(4===e.readyState)if(200===e.status||i.ValidateXHRData(e,o?6:1))r(o?e.response:e.responseText);else{if(!a)throw new Error("Error status: "+e.status+" - Unable to load "+s);a()}},e.send(null)},c=function(){s.loadFileFromDB(t,r,n,h,o)};if(-1!==t.indexOf("file:")){var l=t.substring(5);i.ReadFile(e.FilesInput.FilesToLoad[l],r,n,!0)}else s&&s.enableSceneOffline?s.openAsync(c,h):h()},i.ReadFileAsDataURL=function(e,t,r){var i=new FileReader;i.onload=function(e){t(e.target.result)},i.onprogress=r,i.readAsDataURL(e)},i.ReadFile=function(e,t,r,n){var s=new FileReader;s.onerror=function(r){i.Log("Error while reading file: "+e.name),t(JSON.stringify({autoClear:!0,clearColor:[1,0,0],ambientColor:[0,0,0],gravity:[0,-9.807,0],meshes:[],cameras:[],lights:[]}))},s.onload=function(e){t(e.target.result)},s.onprogress=r,n?s.readAsArrayBuffer(e):s.readAsText(e)},i.FileAsURL=function(e){var t=new Blob([e]),r=window.URL||window.webkitURL,i=r.createObjectURL(t);return i},i.Clamp=function(e,t,r){return void 0===t&&(t=0),void 0===r&&(r=1),Math.min(r,Math.max(t,e))},i.Sign=function(e){return e=+e,0===e||isNaN(e)?e:e>0?1:-1},i.Format=function(e,t){return void 0===t&&(t=2),e.toFixed(t)},i.CheckExtends=function(e,t,r){e.xr.x&&(r.x=e.x),e.y>r.y&&(r.y=e.y),e.z>r.z&&(r.z=e.z)},i.WithinEpsilon=function(e,t,r){void 0===r&&(r=1.401298e-45);var i=e-t;return i>=-r&&r>=i},i.DeepCopy=function(e,t,i,n){for(var s in e)if(("_"!==s[0]||n&&-1!==n.indexOf(s))&&(!i||-1===i.indexOf(s))){var o=e[s],a=typeof o;if("function"!==a)if("object"===a)if(o instanceof Array){if(t[s]=[],o.length>0)if("object"==typeof o[0])for(var h=0;hh;h++)for(var c=0;s>c;c++){var l=c+h*s,u=r-h-1,f=c+u*s,d=a[l];a[l]=a[f],a[f]=d}t||(t=document.createElement("canvas")),t.width=e,t.height=r;var p=t.getContext("2d"),m=p.createImageData(e,r),g=m.data;g.set(a),p.putImageData(m,0,0);var _=t.toDataURL();if(n)n(_);else if("download"in document.createElement("a")){var v=window.document.createElement("a");v.href=_;var y=new Date,x=y.getFullYear()+"-"+y.getMonth()+"-"+y.getDate()+"_"+y.getHours()+"-"+("0"+y.getMinutes()).slice(-2);v.setAttribute("download","screenshot_"+x+".png"),window.document.body.appendChild(v),v.addEventListener("click",function(){v.parentElement.removeChild(v)}),v.click()}else{var E=window.open(""),T=E.document.createElement("img");T.src=_,E.document.body.appendChild(T)}},i.CreateScreenshot=function(t,r,n,s){var o,a;if(n.precision)o=Math.round(t.getRenderWidth()*n.precision),a=Math.round(o/t.getAspectRatio(r)),n={width:o,height:a};else if(n.width&&n.height)o=n.width,a=n.height;else if(n.width&&!n.height)o=n.width,a=Math.round(o/t.getAspectRatio(r)),n={width:o,height:a};else if(n.height&&!n.width)a=n.height,o=Math.round(a*t.getAspectRatio(r)),n={width:o,height:a};else{if(isNaN(n))return void i.Error("Invalid 'size' parameter !");a=n,o=n}var h=r.getScene(),c=null;h.activeCamera!==r&&(c=h.activeCamera,h.activeCamera=r);var l=new e.RenderTargetTexture("screenShot",n,h,!1,!1);l.renderList=h.meshes,l.onAfterRender=function(){i.DumpFramebuffer(o,a,t,s)},h.incrementRenderId(),l.render(!0),l.dispose(),c&&(h.activeCamera=c),r.getProjectionMatrix(!0)},i.ValidateXHRData=function(t,r){void 0===r&&(r=7);try{if(1&r){if(t.responseText&&t.responseText.length>0)return!0;if(1===r)return!1}if(2&r){var i=e.Internals.TGATools.GetTGAHeader(t.response);if(i.width&&i.height&&i.width>0&&i.height>0)return!0;if(2===r)return!1}if(4&r){var n=new Uint8Array(t.response,0,3);return 68===n[0]&&68===n[1]&&83===n[2]?!0:!1}}catch(s){}return!1},Object.defineProperty(i,"NoneLogLevel",{get:function(){return i._NoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"MessageLogLevel",{get:function(){return i._MessageLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"WarningLogLevel",{get:function(){return i._WarningLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ErrorLogLevel",{get:function(){return i._ErrorLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"AllLogLevel",{get:function(){return i._MessageLogLevel|i._WarningLogLevel|i._ErrorLogLevel},enumerable:!0,configurable:!0}),i._AddLogEntry=function(e){i._LogCache=e+i._LogCache,i.OnNewCacheEntry&&i.OnNewCacheEntry(e)},i._FormatMessage=function(e){var t=function(e){return 10>e?"0"+e:""+e},r=new Date;return"["+t(r.getHours())+":"+t(r.getMinutes())+":"+t(r.getSeconds())+"]: "+e},i._LogDisabled=function(e){},i._LogEnabled=function(e){var t=i._FormatMessage(e);console.log("BJS - "+t);var r="
"+t+"

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

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

";i._AddLogEntry(r)},Object.defineProperty(i,"LogCache",{get:function(){return i._LogCache},enumerable:!0,configurable:!0}),i.ClearLogCache=function(){i._LogCache="",i.errorsCount=0},Object.defineProperty(i,"LogLevels",{set:function(e){(e&i.MessageLogLevel)===i.MessageLogLevel?i.Log=i._LogEnabled:i.Log=i._LogDisabled,(e&i.WarningLogLevel)===i.WarningLogLevel?i.Warn=i._WarnEnabled:i.Warn=i._WarnDisabled,(e&i.ErrorLogLevel)===i.ErrorLogLevel?i.Error=i._ErrorEnabled:i.Error=i._ErrorDisabled},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PerformanceNoneLogLevel",{get:function(){return i._PerformanceNoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PerformanceUserMarkLogLevel",{get:function(){return i._PerformanceUserMarkLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PerformanceConsoleLogLevel",{get:function(){return i._PerformanceConsoleLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PerformanceLogLevel",{set:function(e){return(e&i.PerformanceUserMarkLogLevel)===i.PerformanceUserMarkLogLevel?(i.StartPerformanceCounter=i._StartUserMark,void(i.EndPerformanceCounter=i._EndUserMark)):(e&i.PerformanceConsoleLogLevel)===i.PerformanceConsoleLogLevel?(i.StartPerformanceCounter=i._StartPerformanceConsole,void(i.EndPerformanceCounter=i._EndPerformanceConsole)):(i.StartPerformanceCounter=i._StartPerformanceCounterDisabled,void(i.EndPerformanceCounter=i._EndPerformanceCounterDisabled))},enumerable:!0,configurable:!0}),i._StartPerformanceCounterDisabled=function(e,t){},i._EndPerformanceCounterDisabled=function(e,t){},i._StartUserMark=function(e,t){void 0===t&&(t=!0),t&&i._performance.mark&&i._performance.mark(e+"-Begin")},i._EndUserMark=function(e,t){void 0===t&&(t=!0),t&&i._performance.mark&&(i._performance.mark(e+"-End"),i._performance.measure(e,e+"-Begin",e+"-End"))},i._StartPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(i._StartUserMark(e,t),console.time&&console.time(e))},i._EndPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(i._EndUserMark(e,t),console.time&&console.timeEnd(e))},Object.defineProperty(i,"Now",{get:function(){return window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},enumerable:!0,configurable:!0}),i.BaseUrl="",i.CorsBehavior="anonymous",i.UseFallbackTexture=!0,i._NoneLogLevel=0,i._MessageLogLevel=1,i._WarningLogLevel=2,i._ErrorLogLevel=4,i._LogCache="",i.errorsCount=0,i.Log=i._LogEnabled,i.Warn=i._WarnEnabled,i.Error=i._ErrorEnabled,i._PerformanceNoneLogLevel=0,i._PerformanceUserMarkLogLevel=1,i._PerformanceConsoleLogLevel=2,i._performance=window.performance,i.StartPerformanceCounter=i._StartPerformanceCounterDisabled,i.EndPerformanceCounter=i._EndPerformanceCounterDisabled,i}();e.Tools=i;var n=function(){function e(e,t,r,i){void 0===i&&(i=0),this.iterations=e,this._fn=t,this._successCallback=r,this.index=i-1,this._done=!1}return e.prototype.executeNext=function(){this._done||(this.index+1n;++n){var o=e.index*r+n;if(o>=t)break;if(i(o),s&&s()){e.breakLoop();break}}e.executeNext()},o)},n)},e}();e.AsyncLoop=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this._isDepthTestDirty=!1,this._isDepthMaskDirty=!1,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1,this._isZOffsetDirty=!1}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isDepthFuncDirty||this._isDepthTestDirty||this._isDepthMaskDirty||this._isCullFaceDirty||this._isCullDirty||this._isZOffsetDirty},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"zOffset",{get:function(){return this._zOffset},set:function(e){this._zOffset!==e&&(this._zOffset=e,this._isZOffsetDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"cullFace",{get:function(){return this._cullFace},set:function(e){this._cullFace!==e&&(this._cullFace=e,this._isCullFaceDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"cull",{get:function(){return this._cull},set:function(e){this._cull!==e&&(this._cull=e,this._isCullDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthFunc",{get:function(){return this._depthFunc},set:function(e){this._depthFunc!==e&&(this._depthFunc=e,this._isDepthFuncDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthMask",{get:function(){return this._depthMask},set:function(e){this._depthMask!==e&&(this._depthMask=e,this._isDepthMaskDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthTest",{get:function(){return this._depthTest},set:function(e){this._depthTest!==e&&(this._depthTest=e,this._isDepthTestDirty=!0)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this._depthMask=!0,this._depthTest=!0,this._depthFunc=null,this._cull=null,this._cullFace=null,this._zOffset=0,this._isDepthTestDirty=!0,this._isDepthMaskDirty=!0,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1,this._isZOffsetDirty=!1},e.prototype.apply=function(e){this.isDirty&&(this._isCullDirty&&(this.cull?e.enable(e.CULL_FACE):e.disable(e.CULL_FACE),this._isCullDirty=!1),this._isCullFaceDirty&&(e.cullFace(this.cullFace),this._isCullFaceDirty=!1),this._isDepthMaskDirty&&(e.depthMask(this.depthMask),this._isDepthMaskDirty=!1),this._isDepthTestDirty&&(this.depthTest?e.enable(e.DEPTH_TEST):e.disable(e.DEPTH_TEST),this._isDepthTestDirty=!1),this._isDepthFuncDirty&&(e.depthFunc(this.depthFunc),this._isDepthFuncDirty=!1),this._isZOffsetDirty&&(this.zOffset?(e.enable(e.POLYGON_OFFSET_FILL),e.polygonOffset(this.zOffset,0)):e.disable(e.POLYGON_OFFSET_FILL),this._isZOffsetDirty=!1))},e}();e._DepthCullingState=t;var r=function(){function e(){this._isAlphaBlendDirty=!1,this._isBlendFunctionParametersDirty=!1,this._alphaBlend=!1,this._blendFunctionParameters=new Array(4)}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isAlphaBlendDirty||this._isBlendFunctionParametersDirty},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alphaBlend",{get:function(){return this._alphaBlend},set:function(e){this._alphaBlend!==e&&(this._alphaBlend=e,this._isAlphaBlendDirty=!0)},enumerable:!0,configurable:!0}),e.prototype.setAlphaBlendFunctionParameters=function(e,t,r,i){(this._blendFunctionParameters[0]!==e||this._blendFunctionParameters[1]!==t||this._blendFunctionParameters[2]!==r||this._blendFunctionParameters[3]!==i)&&(this._blendFunctionParameters[0]=e,this._blendFunctionParameters[1]=t,this._blendFunctionParameters[2]=r,this._blendFunctionParameters[3]=i,this._isBlendFunctionParametersDirty=!0)},e.prototype.reset=function(){this._alphaBlend=!1,this._blendFunctionParameters[0]=null,this._blendFunctionParameters[1]=null,this._blendFunctionParameters[2]=null,this._blendFunctionParameters[3]=null,this._isAlphaBlendDirty=!0,this._isBlendFunctionParametersDirty=!1},e.prototype.apply=function(e){this.isDirty&&(this._isAlphaBlendDirty&&(this._alphaBlend?e.enable(e.BLEND):e.disable(e.BLEND),this._isAlphaBlendDirty=!1),this._isBlendFunctionParametersDirty&&(e.blendFuncSeparate(this._blendFunctionParameters[0],this._blendFunctionParameters[1],this._blendFunctionParameters[2],this._blendFunctionParameters[3]),this._isBlendFunctionParametersDirty=!1))},e}();e._AlphaState=r;var i=function(e,t,r,i){var n=e.createShader("vertex"===r?e.VERTEX_SHADER:e.FRAGMENT_SHADER);if(e.shaderSource(n,(i?i+"\n":"")+t),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(n));return n},n=function(e,t){var r=e.UNSIGNED_BYTE;return t===l.TEXTURETYPE_FLOAT&&(r=e.FLOAT),r},s=function(t,r,i){var n=i.NEAREST,s=i.NEAREST;return t===e.Texture.BILINEAR_SAMPLINGMODE?(n=i.LINEAR,s=r?i.LINEAR_MIPMAP_NEAREST:i.LINEAR):t===e.Texture.TRILINEAR_SAMPLINGMODE?(n=i.LINEAR,s=r?i.LINEAR_MIPMAP_LINEAR:i.LINEAR):t===e.Texture.NEAREST_SAMPLINGMODE&&(n=i.NEAREST,s=r?i.NEAREST_MIPMAP_LINEAR:i.NEAREST),{min:s,mag:n}},o=function(t,r,i,n,o,a,h,c,l,u,f){void 0===f&&(f=e.Texture.TRILINEAR_SAMPLINGMODE);var d=i.getEngine(),p=e.Tools.GetExponentOfTwo(n,d.getCaps().maxTextureSize),m=e.Tools.GetExponentOfTwo(o,d.getCaps().maxTextureSize);r.bindTexture(r.TEXTURE_2D,t),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,void 0===a?1:a?1:0),t._baseWidth=n,t._baseHeight=o,t._width=p,t._height=m,t.isReady=!0,l(p,m);var g=s(f,!h,r);r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,g.mag),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,g.min),h||c||r.generateMipmap(r.TEXTURE_2D),r.bindTexture(r.TEXTURE_2D,null),d.resetTextureCache(),i._removePendingData(t),u&&u()},a=function(t,r,i,n,s){var o,a=function(){i[r]=o,i._internalCount++,n._removePendingData(o),6===i._internalCount&&s(i)},h=function(){n._removePendingData(o)};o=e.Tools.LoadImage(t,a,h,n.database),n._addPendingData(o)},h=function(e,t,r,i){var n=[];n._internalCount=0;for(var s=0;6>s;s++)a(i[s],s,n,t,r)},c=function(){function e(){}return e}();e.EngineCapabilities=c;var l=function(){function a(i,n,s,o){var h=this;void 0===o&&(o=!0),this.isFullscreen=!1,this.isPointerLock=!1,this.cullBackFaces=!0,this.renderEvenInBackground=!0,this.enableOfflineSupport=!0,this.scenes=new Array,this._windowIsBackground=!1,this._webGLVersion="1.0",this._drawCalls=0,this._renderingQueueLaunched=!1,this._activeRenderLoops=[],this.fpsRange=60,this.previousFramesDuration=[],this.fps=60,this.deltaTime=0,this._depthCullingState=new t,this._alphaState=new r,this._alphaMode=a.ALPHA_DISABLE,this._loadedTexturesCache=new Array,this._maxTextureChannels=16,this._activeTexturesCache=new Array(this._maxTextureChannels),this._compiledEffects={},this._uintIndicesCurrentlySet=!1,this._renderingCanvas=i,s=s||{},s.antialias=n,void 0===s.preserveDrawingBuffer&&(s.preserveDrawingBuffer=!1);try{this._gl=i.getContext("webgl2",s)||i.getContext("experimental-webgl2",s),this._gl&&(this._webGLVersion="2.0")}catch(l){}if(!this._gl)try{this._gl=i.getContext("webgl",s)||i.getContext("experimental-webgl",s)}catch(l){throw new Error("WebGL not supported")}if(!this._gl)throw new Error("WebGL not supported");this._onBlur=function(){h._windowIsBackground=!0},this._onFocus=function(){h._windowIsBackground=!1},window.addEventListener("blur",this._onBlur),window.addEventListener("focus",this._onFocus),this._hardwareScalingLevel=o?1/(window.devicePixelRatio||1):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 u=this._gl.getExtension("WEBGL_debug_renderer_info");if(null!=u&&(this._glRenderer=this._gl.getParameter(u.UNMASKED_RENDERER_WEBGL),this._glVendor=this._gl.getParameter(u.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.fragmentDepthSupported=null!==this._gl.getExtension("EXT_frag_depth"),this._caps.highPrecisionShaderSupported=!0,this._caps.drawBuffersExtension=this._gl.getExtension("WEBGL_draw_buffers"),this._gl.getShaderPrecisionFormat){var f=this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER,this._gl.HIGH_FLOAT);this._caps.highPrecisionShaderSupported=0!==f.precision}this.setDepthBuffer(!0),this.setDepthFunctionToLessOrEqual(),this.setDepthWrite(!0),this._onFullscreenChange=function(){void 0!==document.fullscreen?h.isFullscreen=document.fullscreen:void 0!==document.mozFullScreen?h.isFullscreen=document.mozFullScreen:void 0!==document.webkitIsFullScreen?h.isFullscreen=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(h.isFullscreen=document.msIsFullScreen),h.isFullscreen&&h._pointerLockRequested&&(i.requestPointerLock=i.requestPointerLock||i.msRequestPointerLock||i.mozRequestPointerLock||i.webkitRequestPointerLock,i.requestPointerLock&&i.requestPointerLock())},document.addEventListener("fullscreenchange",this._onFullscreenChange,!1),document.addEventListener("mozfullscreenchange",this._onFullscreenChange,!1),document.addEventListener("webkitfullscreenchange",this._onFullscreenChange,!1),document.addEventListener("msfullscreenchange",this._onFullscreenChange,!1),this._onPointerLockChange=function(){h.isPointerLock=document.mozPointerLockElement===i||document.webkitPointerLockElement===i||document.msPointerLockElement===i||document.pointerLockElement===i},document.addEventListener("pointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mspointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mozpointerlockchange",this._onPointerLockChange,!1),document.addEventListener("webkitpointerlockchange",this._onPointerLockChange,!1),e.AudioEngine&&!a.audioEngine&&(a.audioEngine=new e.AudioEngine),this._loadingScreen=new e.DefaultLoadingScreen(this._renderingCanvas),e.Tools.Log("Babylon.js engine (v"+a.Version+") launched")}return Object.defineProperty(a,"ALPHA_DISABLE",{get:function(){return a._ALPHA_DISABLE},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_ONEONE",{get:function(){return a._ALPHA_ONEONE},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_ADD",{get:function(){return a._ALPHA_ADD},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_COMBINE",{get:function(){return a._ALPHA_COMBINE},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_SUBTRACT",{get:function(){return a._ALPHA_SUBTRACT},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_MULTIPLY",{get:function(){return a._ALPHA_MULTIPLY},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_MAXIMIZED",{get:function(){return a._ALPHA_MAXIMIZED},enumerable:!0,configurable:!0}),Object.defineProperty(a,"DELAYLOADSTATE_NONE",{get:function(){return a._DELAYLOADSTATE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(a,"DELAYLOADSTATE_LOADED",{get:function(){return a._DELAYLOADSTATE_LOADED},enumerable:!0,configurable:!0}),Object.defineProperty(a,"DELAYLOADSTATE_LOADING",{get:function(){return a._DELAYLOADSTATE_LOADING},enumerable:!0,configurable:!0}),Object.defineProperty(a,"DELAYLOADSTATE_NOTLOADED",{get:function(){return a._DELAYLOADSTATE_NOTLOADED},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTUREFORMAT_ALPHA",{get:function(){return a._TEXTUREFORMAT_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTUREFORMAT_LUMINANCE",{get:function(){return a._TEXTUREFORMAT_LUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTUREFORMAT_LUMINANCE_ALPHA",{get:function(){return a._TEXTUREFORMAT_LUMINANCE_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTUREFORMAT_RGB",{get:function(){return a._TEXTUREFORMAT_RGB},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTUREFORMAT_RGBA",{get:function(){return a._TEXTUREFORMAT_RGBA},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTURETYPE_UNSIGNED_INT",{get:function(){return a._TEXTURETYPE_UNSIGNED_INT},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTURETYPE_FLOAT",{get:function(){return a._TEXTURETYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(a,"Version",{get:function(){return"2.3.0"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"webGLVersion",{get:function(){return this._webGLVersion},enumerable:!0,configurable:!0}),a.prototype._prepareWorkingCanvas=function(){this._workingCanvas||(this._workingCanvas=document.createElement("canvas"),this._workingContext=this._workingCanvas.getContext("2d"))},a.prototype.resetTextureCache=function(){for(var e=0;e=0&&this._activeRenderLoops.splice(t,1)},a.prototype._renderLoop=function(){var t=!0;if(!this.renderEvenInBackground&&this._windowIsBackground&&(t=!1),t){this.beginFrame();for(var r=0;r0?e.Tools.QueueNewFrame(this._bindedRenderFunction):this._renderingQueueLaunched=!1},a.prototype.runRenderLoop=function(t){-1===this._activeRenderLoops.indexOf(t)&&(this._activeRenderLoops.push(t),this._renderingQueueLaunched||(this._renderingQueueLaunched=!0,this._bindedRenderFunction=this._renderLoop.bind(this),e.Tools.QueueNewFrame(this._bindedRenderFunction)))},a.prototype.switchFullscreen=function(t){this.isFullscreen?e.Tools.ExitFullscreen():(this._pointerLockRequested=t,e.Tools.RequestFullscreen(this._renderingCanvas))},a.prototype.clear=function(e,t,r){this.applyStates(),t&&this._gl.clearColor(e.r,e.g,e.b,void 0!==e.a?e.a:1),r&&this._depthCullingState.depthMask&&this._gl.clearDepth(1);var i=0;t&&(i|=this._gl.COLOR_BUFFER_BIT),r&&this._depthCullingState.depthMask&&(i|=this._gl.DEPTH_BUFFER_BIT),this._gl.clear(i)},a.prototype.setViewport=function(e,t,r){var i=t||(navigator.isCocoonJS?window.innerWidth:this._renderingCanvas.width),n=r||(navigator.isCocoonJS?window.innerHeight:this._renderingCanvas.height),s=e.x||0,o=e.y||0;this._cachedViewport=e,this._gl.viewport(s*i,o*n,i*e.width,n*e.height)},a.prototype.setDirectViewport=function(e,t,r,i){this._cachedViewport=null,this._gl.viewport(e,t,r,i)},a.prototype.beginFrame=function(){this._measureFps()},a.prototype.endFrame=function(){},a.prototype.resize=function(){var e=navigator.isCocoonJS?window.innerWidth:this._renderingCanvas.clientWidth,t=navigator.isCocoonJS?window.innerHeight:this._renderingCanvas.clientHeight;this.setSize(e/this._hardwareScalingLevel,t/this._hardwareScalingLevel);for(var r=0;r65535){i=!0;break}r=i?new Uint32Array(e):new Uint16Array(e)}else r=new Uint16Array(e);return this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,r,this._gl.STATIC_DRAW),this._resetIndexBufferBinding(),t.references=1,t.is32Bits=i,t},a.prototype.bindBuffers=function(e,t,r,i,n){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==n){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=n,this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e);for(var s=0,o=0;o=0&&this._gl.vertexAttribPointer(a,r[o],this._gl.FLOAT,!1,i,s),s+=4*r[o]}}this._cachedIndexBuffer!==t&&(this._cachedIndexBuffer=t,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,t),this._uintIndicesCurrentlySet=t.is32Bits)},a.prototype.bindMultiBuffers=function(e,t,r){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==r){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=r;for(var i=r.getAttributesNames(),n=0;n=0){var o=e[i[n]];if(!o)continue;var a=o.getStrideSize();this._gl.bindBuffer(this._gl.ARRAY_BUFFER,o.getBuffer()),this._gl.vertexAttribPointer(s,a,this._gl.FLOAT,!1,4*a,0)}}}null!=t&&this._cachedIndexBuffer!==t&&(this._cachedIndexBuffer=t,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,t),this._uintIndicesCurrentlySet=t.is32Bits)},a.prototype._releaseBuffer=function(e){return e.references--,0===e.references?(this._gl.deleteBuffer(e),!0):!1},a.prototype.createInstancesBuffer=function(e){var t=this._gl.createBuffer();return t.capacity=e,this._gl.bindBuffer(this._gl.ARRAY_BUFFER,t),this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.DYNAMIC_DRAW),t},a.prototype.deleteInstancesBuffer=function(e){this._gl.deleteBuffer(e)},a.prototype.updateAndBindInstancesBuffer=function(e,t,r){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e),this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,t);for(var i=0;4>i;i++){var n=r[i];this._gl.enableVertexAttribArray(n),this._gl.vertexAttribPointer(n,4,this._gl.FLOAT,!1,64,16*i),this._caps.instancedArrays.vertexAttribDivisorANGLE(n,1)}},a.prototype.unBindInstancesBuffer=function(e,t){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e);for(var r=0;4>r;r++){var i=t[r];this._gl.disableVertexAttribArray(i),this._caps.instancedArrays.vertexAttribDivisorANGLE(i,0)}},a.prototype.applyStates=function(){this._depthCullingState.apply(this._gl),this._alphaState.apply(this._gl)},a.prototype.draw=function(e,t,r,i){this.applyStates(),this._drawCalls++;var n=this._uintIndicesCurrentlySet?this._gl.UNSIGNED_INT:this._gl.UNSIGNED_SHORT,s=this._uintIndicesCurrentlySet?4:2;return i?void this._caps.instancedArrays.drawElementsInstancedANGLE(e?this._gl.TRIANGLES:this._gl.LINES,r,n,t*s,i):void this._gl.drawElements(e?this._gl.TRIANGLES:this._gl.LINES,r,n,t*s)},a.prototype.drawPointClouds=function(e,t,r){return this.applyStates(),this._drawCalls++,r?void this._caps.instancedArrays.drawArraysInstancedANGLE(this._gl.POINTS,e,t,r):void this._gl.drawArrays(this._gl.POINTS,e,t)},a.prototype.drawUnIndexed=function(e,t,r,i){return this.applyStates(),this._drawCalls++,i?void this._caps.instancedArrays.drawArraysInstancedANGLE(e?this._gl.TRIANGLES:this._gl.LINES,t,r,i):void this._gl.drawArrays(e?this._gl.TRIANGLES:this._gl.LINES,t,r)},a.prototype._releaseEffect=function(e){this._compiledEffects[e._key]&&(delete this._compiledEffects[e._key],e.getProgram()&&this._gl.deleteProgram(e.getProgram()))},a.prototype.createEffect=function(t,r,i,n,s,o,a,h){var c=t.vertexElement||t.vertex||t,l=t.fragmentElement||t.fragment||t,u=c+"+"+l+"@"+s;if(this._compiledEffects[u])return this._compiledEffects[u];var f=new e.Effect(t,r,i,n,this,s,o,a,h);return f._key=u,this._compiledEffects[u]=f,f},a.prototype.createEffectForParticles=function(e,t,r,i,n,s,o){return void 0===t&&(t=[]),void 0===r&&(r=[]),void 0===i&&(i=""),this.createEffect({vertex:"particles",fragmentElement:e},["position","color","options"],["view","projection"].concat(t),["diffuseSampler"].concat(r),i,n,s,o)},a.prototype.createShaderProgram=function(e,t,r){var n=i(this._gl,e,"vertex",r),s=i(this._gl,t,"fragment",r),o=this._gl.createProgram();this._gl.attachShader(o,n),this._gl.attachShader(o,s),this._gl.linkProgram(o);var a=this._gl.getProgramParameter(o,this._gl.LINK_STATUS);if(!a){var h=this._gl.getProgramInfoLog(o);if(h)throw new Error(h)}return this._gl.deleteShader(n),this._gl.deleteShader(s),o},a.prototype.getUniforms=function(e,t){for(var r=[],i=0;ithis._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[t]||(this._vertexAttribArrays[t]=!1,this._gl.disableVertexAttribArray(t));for(var r=e.getAttributesCount(),i=0;r>i;i++){var n=e.getAttributeLocation(i);n>=0&&(this._vertexAttribArrays[n]=!0,this._gl.enableVertexAttribArray(n))}this._currentEffect=e,e.onBind&&e.onBind(e)},a.prototype.setArray=function(e,t){e&&this._gl.uniform1fv(e,t)},a.prototype.setArray2=function(e,t){e&&t.length%2===0&&this._gl.uniform2fv(e,t)},a.prototype.setArray3=function(e,t){e&&t.length%3===0&&this._gl.uniform3fv(e,t)},a.prototype.setArray4=function(e,t){e&&t.length%4===0&&this._gl.uniform4fv(e,t)},a.prototype.setMatrices=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t)},a.prototype.setMatrix=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t.toArray())},a.prototype.setMatrix3x3=function(e,t){e&&this._gl.uniformMatrix3fv(e,!1,t)},a.prototype.setMatrix2x2=function(e,t){e&&this._gl.uniformMatrix2fv(e,!1,t)},a.prototype.setFloat=function(e,t){e&&this._gl.uniform1f(e,t)},a.prototype.setFloat2=function(e,t,r){e&&this._gl.uniform2f(e,t,r)},a.prototype.setFloat3=function(e,t,r,i){e&&this._gl.uniform3f(e,t,r,i)},a.prototype.setBool=function(e,t){e&&this._gl.uniform1i(e,t)},a.prototype.setFloat4=function(e,t,r,i,n){e&&this._gl.uniform4f(e,t,r,i,n)},a.prototype.setColor3=function(e,t){e&&this._gl.uniform3f(e,t.r,t.g,t.b)},a.prototype.setColor4=function(e,t,r){e&&this._gl.uniform4f(e,t.r,t.g,t.b,r)},a.prototype.setState=function(e,t,r,i){void 0===t&&(t=0),void 0===i&&(i=!1);var n=i?this._gl.FRONT:this._gl.BACK,s=i?this._gl.BACK:this._gl.FRONT,o=this.cullBackFaces?n:s;(this._depthCullingState.cull!==e||r||this._depthCullingState.cullFace!==o)&&(e?(this._depthCullingState.cullFace=o,this._depthCullingState.cull=!0):this._depthCullingState.cull=!1),this._depthCullingState.zOffset=t},a.prototype.setDepthBuffer=function(e){this._depthCullingState.depthTest=e},a.prototype.getDepthWrite=function(){return this._depthCullingState.depthMask},a.prototype.setDepthWrite=function(e){this._depthCullingState.depthMask=e},a.prototype.setColorWrite=function(e){this._gl.colorMask(e,e,e,e)},a.prototype.setAlphaMode=function(e){if(this._alphaMode!==e){switch(e){case a.ALPHA_DISABLE:this.setDepthWrite(!0),this._alphaState.alphaBlend=!1;break;case a.ALPHA_COMBINE:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_ALPHA,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case a.ALPHA_ONEONE:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case a.ALPHA_ADD:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case a.ALPHA_SUBTRACT:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.ZERO,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case a.ALPHA_MULTIPLY:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_COLOR,this._gl.ZERO,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case a.ALPHA_MAXIMIZED:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0}this._alphaMode=e}},a.prototype.getAlphaMode=function(){return this._alphaMode},a.prototype.setAlphaTesting=function(e){this._alphaTest=e},a.prototype.getAlphaTesting=function(){return this._alphaTest},a.prototype.wipeCaches=function(){this.resetTextureCache(),this._currentEffect=null,this._depthCullingState.reset(),this._alphaState.reset(),this._cachedVertexBuffers=null,this._cachedIndexBuffer=null,this._cachedEffectForVertexBuffers=null},a.prototype.setSamplingMode=function(t,r){var i=this._gl;i.bindTexture(i.TEXTURE_2D,t);var n=i.NEAREST,s=i.NEAREST;r===e.Texture.BILINEAR_SAMPLINGMODE?(n=i.LINEAR,s=i.LINEAR):r===e.Texture.TRILINEAR_SAMPLINGMODE&&(n=i.LINEAR,s=i.LINEAR_MIPMAP_LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,n),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,s),i.bindTexture(i.TEXTURE_2D,null),t.samplingMode=r},a.prototype.createTexture=function(t,r,i,n,s,a,h,c){var l=this;void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=null),void 0===h&&(h=null),void 0===c&&(c=null);var u,f=this._gl.createTexture(),d=!1;if("data:"===t.substr(0,5)&&(d=!0),d){var p=t;d=p.split(":"),t=p,u=d[1].substr(d[1].length-4,4).toLowerCase()}else u=t.substr(t.length-4,4).toLowerCase();var m=this.getCaps().s3tc&&".dds"===u,g=".tga"===u;n._addPendingData(f),f.url=t,f.noMipmap=r,f.references=1,f.samplingMode=s,this._loadedTexturesCache.push(f);var _,v=function(){n._removePendingData(f),h&&h()};if(g)_=function(t){var h=new Uint8Array(t),c=e.Internals.TGATools.GetTGAHeader(h);o(f,l._gl,n,c.width,c.height,i,r,!1,function(){e.Internals.TGATools.UploadContent(l._gl,h)},a,s)},d instanceof Array?_(c):e.Tools.LoadFile(t,function(e){_(e)},v,n.database,!0);else if(m)_=function(t){var h=e.Internals.DDSTools.GetDDSInfo(t),c=(h.isRGB||h.isLuminance||h.mipmapCount>1)&&!r&&h.width>>h.mipmapCount-1===1;o(f,l._gl,n,h.width,h.height,i,!c,h.isFourCC,function(){e.Internals.DDSTools.UploadDDSLevels(l._gl,l.getCaps().s3tc,t,h,c,1)},a,s)},d instanceof Array?_(c):e.Tools.LoadFile(t,function(e){_(e)},v,n.database,!0);else{var y=function(t){o(f,l._gl,n,t.width,t.height,i,r,!1,function(r,i){var n=t.width===r&&t.height===i;n||(l._prepareWorkingCanvas(),l._workingCanvas.width=r,l._workingCanvas.height=i,s===e.Texture.NEAREST_SAMPLINGMODE&&(l._workingContext.imageSmoothingEnabled=!1,l._workingContext.mozImageSmoothingEnabled=!1,l._workingContext.oImageSmoothingEnabled=!1,l._workingContext.webkitImageSmoothingEnabled=!1,l._workingContext.msImageSmoothingEnabled=!1),l._workingContext.drawImage(t,0,0,t.width,t.height,0,0,r,i),s===e.Texture.NEAREST_SAMPLINGMODE&&(l._workingContext.imageSmoothingEnabled=!0,l._workingContext.mozImageSmoothingEnabled=!0,l._workingContext.oImageSmoothingEnabled=!0,l._workingContext.webkitImageSmoothingEnabled=!0,l._workingContext.msImageSmoothingEnabled=!0)),l._gl.texImage2D(l._gl.TEXTURE_2D,0,l._gl.RGBA,l._gl.RGBA,l._gl.UNSIGNED_BYTE,n?t:l._workingCanvas)},a,s)};d instanceof Array?e.Tools.LoadImage(c,y,v,n.database):e.Tools.LoadImage(t,y,v,n.database)}return f},a.prototype.updateRawTexture=function(e,t,r,i,n){void 0===n&&(n=null);var s=this._gl.RGBA;switch(r){case a.TEXTUREFORMAT_ALPHA:s=this._gl.ALPHA;break;case a.TEXTUREFORMAT_LUMINANCE:s=this._gl.LUMINANCE;break;case a.TEXTUREFORMAT_LUMINANCE_ALPHA:s=this._gl.LUMINANCE_ALPHA;break;case a.TEXTUREFORMAT_RGB:s=this._gl.RGB;break;case a.TEXTUREFORMAT_RGBA:s=this._gl.RGBA}this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,void 0===i?1:i?1:0),n?this._gl.compressedTexImage2D(this._gl.TEXTURE_2D,0,this.getCaps().s3tc[n],e._width,e._height,0,t):this._gl.texImage2D(this._gl.TEXTURE_2D,0,s,e._width,e._height,0,s,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this.resetTextureCache(),e.isReady=!0},a.prototype.createRawTexture=function(e,t,r,i,n,o,a,h){void 0===h&&(h=null);var c=this._gl.createTexture();c._baseWidth=t,c._baseHeight=r,c._width=t,c._height=r,c.references=1,this.updateRawTexture(c,e,i,o,h),this._gl.bindTexture(this._gl.TEXTURE_2D,c);var l=s(a,n,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,l.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,l.min),this._gl.bindTexture(this._gl.TEXTURE_2D,null),c.samplingMode=a,this._loadedTexturesCache.push(c),c},a.prototype.createDynamicTexture=function(t,r,i,n,s){void 0===s&&(s=!0);var o=this._gl.createTexture();return o._baseWidth=t,o._baseHeight=r,s&&(t=e.Tools.GetExponentOfTwo(t,this._caps.maxTextureSize),r=e.Tools.GetExponentOfTwo(r,this._caps.maxTextureSize)),this.resetTextureCache(),o._width=t,o._height=r,o.isReady=!1,o.generateMipMaps=i,o.references=1,o.samplingMode=n,this.updateTextureSamplingMode(n,o),this._loadedTexturesCache.push(o),o},a.prototype.updateTextureSamplingMode=function(e,t){var r=s(e,t.generateMipMaps,this._gl);t.isCube?(this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,t),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_MAG_FILTER,r.mag),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_MIN_FILTER,r.min),this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,null)):(this._gl.bindTexture(this._gl.TEXTURE_2D,t),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,r.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,r.min),this._gl.bindTexture(this._gl.TEXTURE_2D,null))},a.prototype.updateDynamicTexture=function(e,t,r){this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,r?1:0),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this.resetTextureCache(),e.isReady=!0},a.prototype.updateVideoTexture=function(e,t,r){if(!e._isDisabled){this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,r?0:1);try{void 0===this._videoTextureSupported&&(this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t),0!==this._gl.getError()?this._videoTextureSupported=!1:this._videoTextureSupported=!0),this._videoTextureSupported?this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t):(e._workingCanvas||(e._workingCanvas=document.createElement("canvas"),e._workingContext=e._workingCanvas.getContext("2d"),e._workingCanvas.width=e._width,e._workingCanvas.height=e._height),e._workingContext.drawImage(t,0,0,t.videoWidth,t.videoHeight,0,0,e._width,e._height),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,e._workingCanvas)),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this.resetTextureCache(),e.isReady=!0}catch(i){e._isDisabled=!0}}},a.prototype.createRenderTargetTexture=function(t,r){var i=!1,o=!0,h=a.TEXTURETYPE_UNSIGNED_INT,c=e.Texture.TRILINEAR_SAMPLINGMODE;void 0!==r&&(i=void 0===r.generateMipMaps?r:r.generateMipMaps,o=void 0===r.generateDepthBuffer?!0:r.generateDepthBuffer,h=void 0===r.type?h:r.type,void 0!==r.samplingMode&&(c=r.samplingMode),h===a.TEXTURETYPE_FLOAT&&(c=e.Texture.NEAREST_SAMPLINGMODE));var l=this._gl,u=l.createTexture();l.bindTexture(l.TEXTURE_2D,u);var f=t.width||t,d=t.height||t,p=s(c,i,l);h!==a.TEXTURETYPE_FLOAT||this._caps.textureFloat||(h=a.TEXTURETYPE_UNSIGNED_INT,e.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type")),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,p.mag),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,p.min),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,f,d,0,l.RGBA,n(l,h),null);var m;o&&(m=l.createRenderbuffer(),l.bindRenderbuffer(l.RENDERBUFFER,m),l.renderbufferStorage(l.RENDERBUFFER,l.DEPTH_COMPONENT16,f,d));var g=l.createFramebuffer();return l.bindFramebuffer(l.FRAMEBUFFER,g),o&&l.framebufferRenderbuffer(l.FRAMEBUFFER,l.DEPTH_ATTACHMENT,l.RENDERBUFFER,m),i&&this._gl.generateMipmap(this._gl.TEXTURE_2D),l.bindTexture(l.TEXTURE_2D,null),l.bindRenderbuffer(l.RENDERBUFFER,null),l.bindFramebuffer(l.FRAMEBUFFER,null),u._framebuffer=g,o&&(u._depthBuffer=m),u._width=f,u._height=d,u.isReady=!0,u.generateMipMaps=i,u.references=1,u.samplingMode=c,this.resetTextureCache(),this._loadedTexturesCache.push(u),u},a.prototype.createRenderTargetCubeTexture=function(t,r){var i=this._gl,n=i.createTexture(),o=!0,a=e.Texture.TRILINEAR_SAMPLINGMODE;void 0!==r&&(o=void 0===r.generateMipMaps?r:r.generateMipMaps,void 0!==r.samplingMode&&(a=r.samplingMode)),n.isCube=!0,n.references=1,n.generateMipMaps=o,n.references=1,n.samplingMode=a;var h=s(a,o,i);i.bindTexture(i.TEXTURE_CUBE_MAP,n);for(var c=0;6>c;c++)i.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+c,0,i.RGBA,t,t,0,i.RGBA,i.UNSIGNED_BYTE,null);i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_MAG_FILTER,h.mag),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_MIN_FILTER,h.min),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);var l=i.createRenderbuffer();i.bindRenderbuffer(i.RENDERBUFFER,l),i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_COMPONENT16,t,t);var u=i.createFramebuffer();return i.bindFramebuffer(i.FRAMEBUFFER,u),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,l),n.generateMipMaps&&(i.bindTexture(i.TEXTURE_CUBE_MAP,n),i.generateMipmap(i.TEXTURE_CUBE_MAP)),i.bindTexture(i.TEXTURE_CUBE_MAP,null),i.bindRenderbuffer(i.RENDERBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,null),n._framebuffer=u,n._depthBuffer=l,this.resetTextureCache(),n._width=t,n._height=t,n.isReady=!0,n},a.prototype.createCubeTexture=function(t,r,i,n){var s=this,o=this._gl,a=o.createTexture();a.isCube=!0,a.url=t,a.references=1;var c=t.substr(t.length-4,4).toLowerCase(),l=this.getCaps().s3tc&&".dds"===c;return l?e.Tools.LoadFile(t,function(t){var r=e.Internals.DDSTools.GetDDSInfo(t),i=(r.isRGB||r.isLuminance||r.mipmapCount>1)&&!n;o.bindTexture(o.TEXTURE_CUBE_MAP,a),o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,1),e.Internals.DDSTools.UploadDDSLevels(s._gl,s.getCaps().s3tc,t,r,i,6),n||r.isFourCC||1!==r.mipmapCount||o.generateMipmap(o.TEXTURE_CUBE_MAP),o.texParameteri(o.TEXTURE_CUBE_MAP,o.TEXTURE_MAG_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_CUBE_MAP,o.TEXTURE_MIN_FILTER,i?o.LINEAR_MIPMAP_LINEAR:o.LINEAR),o.texParameteri(o.TEXTURE_CUBE_MAP,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_CUBE_MAP,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.bindTexture(o.TEXTURE_CUBE_MAP,null),s.resetTextureCache(),a._width=r.width,a._height=r.height,a.isReady=!0},null,null,!0):h(t,r,function(t){var r=e.Tools.GetExponentOfTwo(t[0].width,s._caps.maxCubemapTextureSize),i=r;s._prepareWorkingCanvas(),s._workingCanvas.width=r,s._workingCanvas.height=i;var h=[o.TEXTURE_CUBE_MAP_POSITIVE_X,o.TEXTURE_CUBE_MAP_POSITIVE_Y,o.TEXTURE_CUBE_MAP_POSITIVE_Z,o.TEXTURE_CUBE_MAP_NEGATIVE_X,o.TEXTURE_CUBE_MAP_NEGATIVE_Y,o.TEXTURE_CUBE_MAP_NEGATIVE_Z];o.bindTexture(o.TEXTURE_CUBE_MAP,a),o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,0);for(var c=0;ct)){if(!r||!r.isReady())return void(null!=this._activeTexturesCache[t]&&(this._gl.activeTexture(this._gl["TEXTURE"+t]),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,null),this._activeTexturesCache[t]=null));var i=!1;if(r instanceof e.VideoTexture)this._gl.activeTexture(this._gl["TEXTURE"+t]),i=!0,r.update();else if(r.delayLoadState===a.DELAYLOADSTATE_NOTLOADED)return void r.delayLoad();if(this._activeTexturesCache[t]!==r){this._activeTexturesCache[t]=r;var n=r.getInternalTexture();if(i||this._gl.activeTexture(this._gl["TEXTURE"+t]),n.isCube){if(this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,n),n._cachedCoordinatesMode!==r.coordinatesMode){n._cachedCoordinatesMode=r.coordinatesMode;var s=r.coordinatesMode!==e.Texture.CUBIC_MODE&&r.coordinatesMode!==e.Texture.SKYBOX_MODE?this._gl.REPEAT:this._gl.CLAMP_TO_EDGE;this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_S,s),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_T,s)}this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP,r)}else{if(this._gl.bindTexture(this._gl.TEXTURE_2D,n),n._cachedWrapU!==r.wrapU)switch(n._cachedWrapU=r.wrapU,r.wrapU){case e.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.REPEAT);break;case e.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.CLAMP_TO_EDGE);break;case e.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.MIRRORED_REPEAT)}if(n._cachedWrapV!==r.wrapV)switch(n._cachedWrapV=r.wrapV,r.wrapV){case e.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.REPEAT);break;case e.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.CLAMP_TO_EDGE);break;case e.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.MIRRORED_REPEAT)}this._setAnisotropicLevel(this._gl.TEXTURE_2D,r)}}}},a.prototype._setAnisotropicLevel=function(t,r){var i=this._caps.textureAnisotropicFilterExtension,n=r.anisotropicFilteringLevel;r.getInternalTexture().samplingMode===e.Texture.NEAREST_SAMPLINGMODE&&(n=1),i&&r._cachedAnisotropicFilteringLevel!==n&&(this._gl.texParameterf(t,i.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(n,this._caps.maxAnisotropy)),r._cachedAnisotropicFilteringLevel=n)},a.prototype.readPixels=function(e,t,r,i){var n=new Uint8Array(i*r*4);return this._gl.readPixels(e,t,r,i,this._gl.RGBA,this._gl.UNSIGNED_BYTE,n),n},a.prototype.releaseInternalTexture=function(e){if(e&&(e.references--,0===e.references)){var t=this.getLoadedTexturesCache(),r=t.indexOf(e);r>-1&&t.splice(r,1),this._releaseTexture(e)}},a.prototype.dispose=function(){for(this.hideLoadingUI(),this.stopRenderLoop();this.scenes.length;)this.scenes[0].dispose();a.audioEngine.dispose();for(var e in this._compiledEffects)this._gl.deleteProgram(this._compiledEffects[e]._program);for(var t in this._vertexAttribArrays)t>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[t]||this._gl.disableVertexAttribArray(t);this._gl=null,window.removeEventListener("blur",this._onBlur),window.removeEventListener("focus",this._onFocus),document.removeEventListener("fullscreenchange",this._onFullscreenChange),document.removeEventListener("mozfullscreenchange",this._onFullscreenChange),document.removeEventListener("webkitfullscreenchange",this._onFullscreenChange),document.removeEventListener("msfullscreenchange",this._onFullscreenChange),document.removeEventListener("pointerlockchange",this._onPointerLockChange),document.removeEventListener("mspointerlockchange",this._onPointerLockChange),document.removeEventListener("mozpointerlockchange",this._onPointerLockChange),document.removeEventListener("webkitpointerlockchange",this._onPointerLockChange)},a.prototype.displayLoadingUI=function(){this._loadingScreen.displayLoadingUI()},a.prototype.hideLoadingUI=function(){this._loadingScreen.hideLoadingUI()},Object.defineProperty(a.prototype,"loadingScreen",{get:function(){return this._loadingScreen},set:function(e){this._loadingScreen=e},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"loadingUIText",{set:function(e){this._loadingScreen.loadingUIText=e},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"loadingUIBackgroundColor",{set:function(e){this._loadingScreen.loadingUIBackgroundColor=e},enumerable:!0,configurable:!0}),a.prototype.getFps=function(){return this.fps},a.prototype.getDeltaTime=function(){return this.deltaTime},a.prototype._measureFps=function(){this.previousFramesDuration.push(e.Tools.Now);var t=this.previousFramesDuration.length;if(t>=2&&(this.deltaTime=this.previousFramesDuration[t-1]-this.previousFramesDuration[t-2]), t>=this.fpsRange){t>this.fpsRange&&(this.previousFramesDuration.splice(0,1),t=this.previousFramesDuration.length);for(var r=0,i=0;t-1>i;i++)r+=this.previousFramesDuration[i+1]-this.previousFramesDuration[i];this.fps=1e3/(r/(t-1))}},a.isSupported=function(){try{if(navigator.isCocoonJS)return!0;var e=document.createElement("canvas"),t=e.getContext("webgl")||e.getContext("experimental-webgl");return null!=t&&!!window.WebGLRenderingContext}catch(r){return!1}},a._ALPHA_DISABLE=0,a._ALPHA_ADD=1,a._ALPHA_COMBINE=2,a._ALPHA_SUBTRACT=3,a._ALPHA_MULTIPLY=4,a._ALPHA_MAXIMIZED=5,a._ALPHA_ONEONE=6,a._DELAYLOADSTATE_NONE=0,a._DELAYLOADSTATE_LOADED=1,a._DELAYLOADSTATE_LOADING=2,a._DELAYLOADSTATE_NOTLOADED=4,a._TEXTUREFORMAT_ALPHA=0,a._TEXTUREFORMAT_LUMINANCE=1,a._TEXTUREFORMAT_LUMINANCE_ALPHA=2,a._TEXTUREFORMAT_RGB=4,a._TEXTUREFORMAT_RGBA=5,a._TEXTURETYPE_UNSIGNED_INT=0,a._TEXTURETYPE_FLOAT=1,a.Epsilon=.001,a.CollisionsEpsilon=.001,a.CodeRepository="src/",a.ShadersRepository="src/Shaders/",a}();e.Engine=l}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t){this.state="",this.animations=new Array,this._ranges={},this._childrenFlag=-1,this._isEnabled=!0,this._isReady=!0,this._currentRenderId=-1,this._parentRenderId=-1,this.name=e,this.id=e,this._scene=t,this._initCache()}return t.prototype.getScene=function(){return this._scene},t.prototype.getEngine=function(){return this._scene.getEngine()},t.prototype.getWorldMatrix=function(){return e.Matrix.Identity()},t.prototype._initCache=function(){this._cache={},this._cache.parent=void 0},t.prototype.updateCache=function(e){(e||!this.isSynchronized())&&(this._cache.parent=this.parent,this._updateCache())},t.prototype._updateCache=function(e){},t.prototype._isSynchronized=function(){return!0},t.prototype._markSyncedWithParent=function(){this._parentRenderId=this.parent._currentRenderId},t.prototype.isSynchronizedWithParent=function(){return this.parent?this._parentRenderId!==this.parent._currentRenderId?!1:this.parent.isSynchronized():!0},t.prototype.isSynchronized=function(e){var t=this.hasNewParent();return t=t||!this.isSynchronizedWithParent(),t=t||!this._isSynchronized(),e&&this.updateCache(!0),!t},t.prototype.hasNewParent=function(e){return this._cache.parent===this.parent?!1:(e&&(this._cache.parent=this.parent),!0)},t.prototype.isReady=function(){return this._isReady},t.prototype.isEnabled=function(){return this._isEnabled?this.parent?this.parent.isEnabled():!0:!1},t.prototype.setEnabled=function(e){this._isEnabled=e},t.prototype.isDescendantOf=function(e){return this.parent?this.parent===e?!0:this.parent.isDescendantOf(e):!1},t.prototype._getDescendants=function(e,t){for(var r=0;rn;n++)this.animations[n]&&this.animations[n].createRange(t,r,i)}},t.prototype.deleteAnimationRange=function(e,t){void 0===t&&(t=!0);for(var r=0,i=this.animations.length;i>r;r++)this.animations[r]&&this.animations[r].deleteRange(e,t);this._ranges[e]=void 0},t.prototype.getAnimationRange=function(e){return this._ranges[e]},t.prototype.beginAnimation=function(e,t,r,i){var n=this.getAnimationRange(e);return n?void this._scene.beginAnimation(this,n.from,n.to,t,r,i):null},t.prototype.serializeAnimationRanges=function(){var e=[];for(var t in this._ranges){var r={};r.name=t,r.from=this._ranges[t].from,r.to=this._ranges[t].to,e.push(r)}return e},t.ParseAnimationRanges=function(e,t,r){if(t.ranges)for(var i=0;i0&&this._textureLoadingCallback(e)}this._currentScene.render()}},t.prototype.drag=function(e){e.stopPropagation(),e.preventDefault()},t.prototype.drop=function(e){e.stopPropagation(),e.preventDefault(),this.loadFiles(e)},t.prototype.loadFiles=function(e){if(this._startingProcessingFilesCallback&&this._startingProcessingFilesCallback(),e&&e.dataTransfer&&e.dataTransfer.files&&(this._filesToLoad=e.dataTransfer.files),e&&e.target&&e.target.files&&(this._filesToLoad=e.target.files),this._filesToLoad&&this._filesToLoad.length>0){for(var r=0;r0&&(e.Tools.ClearLogCache(),e.Tools.Log("Babylon.js engine (v"+e.Engine.Version+") launched")),this._engine.stopRenderLoop(),this._currentScene.dispose()),e.SceneLoader.Load("file:",this._sceneFileToLoad,this._engine,function(e){r._currentScene=e,r._currentScene.executeWhenReady(function(){r._currentScene.activeCamera&&0!==r._currentScene.lights.length||r._currentScene.createDefaultCameraOrLight(),r._currentScene.activeCamera.attachControl(r._canvas),r._sceneLoadedCallback&&r._sceneLoadedCallback(t._sceneFileToLoad,r._currentScene),r._engine.runRenderLoop(function(){r.renderFunction()})})},function(e){t._progressCallback&&t._progressCallback(e)})):e.Tools.Error("Please provide a valid .babylon file.")},t.FilesTextures=new Array,t.FilesToLoad=new Array,t}();e.FilesInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,r){this.bu=e,this.bv=t,this.distance=r,this.faceId=0,this.subMeshId=0}return e}();e.IntersectionInfo=t;var r=function(){function t(){this.hit=!1,this.distance=0,this.pickedPoint=null,this.pickedMesh=null,this.bu=0,this.bv=0,this.faceId=-1,this.subMeshId=0,this.pickedSprite=null}return t.prototype.getNormal=function(t,r){if(void 0===t&&(t=!1),void 0===r&&(r=!0),!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(e.VertexBuffer.NormalKind))return null;var i,n=this.pickedMesh.getIndices();if(r){var s=this.pickedMesh.getVerticesData(e.VertexBuffer.NormalKind),o=e.Vector3.FromArray(s,3*n[3*this.faceId]),a=e.Vector3.FromArray(s,3*n[3*this.faceId+1]),h=e.Vector3.FromArray(s,3*n[3*this.faceId+2]);o=o.scale(this.bu),a=a.scale(this.bv),h=h.scale(1-this.bu-this.bv),i=new e.Vector3(o.x+a.x+h.x,o.y+a.y+h.y,o.z+a.z+h.z)}else{var c=this.pickedMesh.getVerticesData(e.VertexBuffer.PositionKind),l=e.Vector3.FromArray(c,3*n[3*this.faceId]),u=e.Vector3.FromArray(c,3*n[3*this.faceId+1]),f=e.Vector3.FromArray(c,3*n[3*this.faceId+2]),d=l.subtract(u),p=f.subtract(u);i=e.Vector3.Cross(d,p)}return t&&(i=e.Vector3.TransformNormal(i,this.pickedMesh.getWorldMatrix())),e.Vector3.Normalize(i)},t.prototype.getTextureCoordinates=function(){if(!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(e.VertexBuffer.UVKind))return null;var t=this.pickedMesh.getIndices(),r=this.pickedMesh.getVerticesData(e.VertexBuffer.UVKind),i=e.Vector2.FromArray(r,2*t[3*this.faceId]),n=e.Vector2.FromArray(r,2*t[3*this.faceId+1]),s=e.Vector2.FromArray(r,2*t[3*this.faceId+2]);return i=i.scale(1-this.bu-this.bv),n=n.scale(this.bu),s=s.scale(this.bv),new e.Vector2(i.x+n.x+s.x,i.y+n.y+s.y)},t}();e.PickingInfo=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r){this.minimum=t,this.maximum=r,this._tempRadiusVector=e.Vector3.Zero();var i=e.Vector3.Distance(t,r);this.center=e.Vector3.Lerp(t,r,.5),this.radius=.5*i,this.centerWorld=e.Vector3.Zero(),this._update(e.Matrix.Identity())}return t.prototype._update=function(t){e.Vector3.TransformCoordinatesToRef(this.center,t,this.centerWorld),e.Vector3.TransformNormalFromFloatsToRef(1,1,1,t,this._tempRadiusVector),this.radiusWorld=Math.max(Math.abs(this._tempRadiusVector.x),Math.abs(this._tempRadiusVector.y),Math.abs(this._tempRadiusVector.z))*this.radius},t.prototype.isInFrustum=function(e){for(var t=0;6>t;t++)if(e[t].dotCoordinate(this.centerWorld)<=-this.radiusWorld)return!1;return!0},t.prototype.intersectsPoint=function(t){var r=this.centerWorld.x-t.x,i=this.centerWorld.y-t.y,n=this.centerWorld.z-t.z,s=Math.sqrt(r*r+i*i+n*n);return Math.abs(this.radiusWorld-s)this.maximumWorld.x&&(this.maximumWorld.x=i.x),i.y>this.maximumWorld.y&&(this.maximumWorld.y=i.y),i.z>this.maximumWorld.z&&(this.maximumWorld.z=i.z)}this.maximumWorld.addToRef(this.minimumWorld,this.center),this.center.scaleInPlace(.5),e.Vector3.FromFloatArrayToRef(t.m,0,this.directions[0]),e.Vector3.FromFloatArrayToRef(t.m,4,this.directions[1]),e.Vector3.FromFloatArrayToRef(t.m,8,this.directions[2]),this._worldMatrix=t},t.prototype.isInFrustum=function(e){return t.IsInFrustum(this.vectorsWorld,e)},t.prototype.isCompletelyInFrustum=function(e){return t.IsCompletelyInFrustum(this.vectorsWorld,e)},t.prototype.intersectsPoint=function(t){var r=-e.Engine.Epsilon;return this.maximumWorld.x-t.xt.x-this.minimumWorld.x?!1:this.maximumWorld.y-t.yt.y-this.minimumWorld.y?!1:this.maximumWorld.z-t.zt.z-this.minimumWorld.z?!1:!0},t.prototype.intersectsSphere=function(e){return t.IntersectsSphere(this.minimumWorld,this.maximumWorld,e.centerWorld,e.radiusWorld)},t.prototype.intersectsMinMax=function(e,t){return this.maximumWorld.xt.x?!1:this.maximumWorld.yt.y?!1:this.maximumWorld.zt.z?!1:!0},t.Intersects=function(e,t){return e.maximumWorld.xt.maximumWorld.x?!1:e.maximumWorld.yt.maximumWorld.y?!1:e.maximumWorld.zt.maximumWorld.z?!1:!0},t.IntersectsSphere=function(t,r,i,n){var s=e.Vector3.Clamp(i,t,r),o=e.Vector3.DistanceSquared(i,s);return n*n>=o},t.IsCompletelyInFrustum=function(e,t){for(var r=0;6>r;r++)for(var i=0;8>i;i++)if(t[r].dotCoordinate(e[i])<0)return!1;return!0},t.IsInFrustum=function(e,t){for(var r=0;6>r;r++){for(var i=8,n=0;8>n&&t[r].dotCoordinate(e[n])<0;n++)--i;if(0===i)return!1}return!0},t}();e.BoundingBox=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t,r){var i=e.Vector3.Dot(r.center,t),n=Math.abs(e.Vector3.Dot(r.directions[0],t))*r.extendSize.x,s=Math.abs(e.Vector3.Dot(r.directions[1],t))*r.extendSize.y,o=Math.abs(e.Vector3.Dot(r.directions[2],t))*r.extendSize.z,a=n+s+o;return{min:i-a,max:i+a}},r=function(e,t,r,i){return!(e>i||r>t)},i=function(e,i,n){var s=t(e,i),o=t(e,n);return r(s.min,s.max,o.min,o.max)},n=function(){function t(t,r){this.minimum=t,this.maximum=r,this._isLocked=!1,this.boundingBox=new e.BoundingBox(t,r),this.boundingSphere=new e.BoundingSphere(t,r)}return Object.defineProperty(t.prototype,"isLocked",{get:function(){return this._isLocked},set:function(e){this._isLocked=e},enumerable:!0,configurable:!0}),t.prototype.update=function(e){this._isLocked||(this.boundingBox._update(e),this.boundingSphere._update(e))},t.prototype.isInFrustum=function(e){return this.boundingSphere.isInFrustum(e)?this.boundingBox.isInFrustum(e):!1},t.prototype.isCompletelyInFrustum=function(e){return this.boundingBox.isCompletelyInFrustum(e)},t.prototype._checkCollision=function(e){return e._canDoCollision(this.boundingSphere.centerWorld,this.boundingSphere.radiusWorld,this.boundingBox.minimumWorld,this.boundingBox.maximumWorld)},t.prototype.intersectsPoint=function(e){return this.boundingSphere.centerWorld&&this.boundingSphere.intersectsPoint(e)&&this.boundingBox.intersectsPoint(e)?!0:!1},t.prototype.intersects=function(t,r){if(!this.boundingSphere.centerWorld||!t.boundingSphere.centerWorld)return!1;if(!e.BoundingSphere.Intersects(this.boundingSphere,t.boundingSphere))return!1;if(!e.BoundingBox.Intersects(this.boundingBox,t.boundingBox))return!1;if(!r)return!0;var n=this.boundingBox,s=t.boundingBox;return i(n.directions[0],n,s)&&i(n.directions[1],n,s)&&i(n.directions[2],n,s)&&i(s.directions[0],n,s)&&i(s.directions[1],n,s)&&i(s.directions[2],n,s)&&i(e.Vector3.Cross(n.directions[0],s.directions[0]),n,s)&&i(e.Vector3.Cross(n.directions[0],s.directions[1]),n,s)&&i(e.Vector3.Cross(n.directions[0],s.directions[2]),n,s)&&i(e.Vector3.Cross(n.directions[1],s.directions[0]),n,s)&&i(e.Vector3.Cross(n.directions[1],s.directions[1]),n,s)&&i(e.Vector3.Cross(n.directions[1],s.directions[2]),n,s)&&i(e.Vector3.Cross(n.directions[2],s.directions[0]),n,s)&&i(e.Vector3.Cross(n.directions[2],s.directions[1]),n,s)&&i(e.Vector3.Cross(n.directions[2],s.directions[2]),n,s)?!0:!1},t}();e.BoundingInfo=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(i,n){var s=this;t.call(this,i,n),this.definedFacingForward=!0,this.position=new e.Vector3(0,0,0),this.rotation=new e.Vector3(0,0,0),this.scaling=new e.Vector3(1,1,1),this.billboardMode=r.BILLBOARDMODE_NONE,this.visibility=1,this.alphaIndex=Number.MAX_VALUE,this.infiniteDistance=!1,this.isVisible=!0,this.isPickable=!0,this.showBoundingBox=!1,this.showSubMeshesBoundingBox=!1,this.onDispose=null,this.isBlocker=!1,this.renderingGroupId=0,this.receiveShadows=!1,this.renderOutline=!1,this.outlineColor=e.Color3.Red(),this.outlineWidth=.02,this.renderOverlay=!1,this.overlayColor=e.Color3.Red(),this.overlayAlpha=.5,this.hasVertexAlpha=!1,this.useVertexColors=!0,this.applyFog=!0,this.computeBonesUsingShaders=!0,this.scalingDeterminant=1,this.numBoneInfluencers=4,this.useOctreeForRenderingSelection=!0,this.useOctreeForPicking=!0,this.useOctreeForCollisions=!0,this.layerMask=268435455,this.alwaysSelectAsActiveMesh=!1,this._physicImpostor=e.PhysicsEngine.NoImpostor,this._checkCollisions=!1,this.ellipsoid=new e.Vector3(.5,1,.5),this.ellipsoidOffset=new e.Vector3(0,0,0),this._collider=new e.Collider,this._oldPositionForCollisions=new e.Vector3(0,0,0),this._diffPositionForCollisions=new e.Vector3(0,0,0),this._newPositionForCollisions=new e.Vector3(0,0,0),this.edgesWidth=1,this.edgesColor=new e.Color4(1,0,0,1),this._localWorld=e.Matrix.Zero(),this._worldMatrix=e.Matrix.Zero(),this._rotateYByPI=e.Matrix.RotationY(Math.PI),this._absolutePosition=e.Vector3.Zero(),this._collisionsTransformMatrix=e.Matrix.Zero(),this._collisionsScalingMatrix=e.Matrix.Zero(),this._isDirty=!1,this._pivotMatrix=e.Matrix.Identity(),this._isDisposed=!1,this._renderId=0,this._intersectionsInProgress=new Array,this._onAfterWorldMatrixUpdate=new Array,this._isWorldMatrixFrozen=!1,this._unIndexed=!1,this._onCollisionPositionChange=function(t,r,i){void 0===i&&(i=null),s.getScene().workerCollisions&&r.multiplyInPlace(s._collider.radius),r.subtractToRef(s._oldPositionForCollisions,s._diffPositionForCollisions),s._diffPositionForCollisions.length()>e.Engine.CollisionsEpsilon&&s.position.addInPlace(s._diffPositionForCollisions),s.onCollide&&i&&s.onCollide(i),s.onCollisionPositionChange&&s.onCollisionPositionChange(s.position)},n.addMesh(this)}return __extends(r,t),Object.defineProperty(r,"BILLBOARDMODE_NONE",{get:function(){return r._BILLBOARDMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BILLBOARDMODE_X",{get:function(){return r._BILLBOARDMODE_X},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BILLBOARDMODE_Y",{get:function(){return r._BILLBOARDMODE_Y},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BILLBOARDMODE_Z",{get:function(){return r._BILLBOARDMODE_Z},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BILLBOARDMODE_ALL",{get:function(){return r._BILLBOARDMODE_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"skeleton",{get:function(){return this._skeleton},set:function(e){this._skeleton&&this._skeleton.needInitialSkinMatrix&&this._skeleton._unregisterMeshWithPoseMatrix(this),e&&e.needInitialSkinMatrix&&e._registerMeshWithPoseMatrix(this),this._skeleton=e,this._skeleton||(this._bonesTransformMatrices=null)},enumerable:!0,configurable:!0}),r.prototype.updatePoseMatrix=function(e){this._poseMatrix.copyFrom(e)},r.prototype.getPoseMatrix=function(){return this._poseMatrix},r.prototype.disableEdgesRendering=function(){void 0!==this._edgesRenderer&&(this._edgesRenderer.dispose(),this._edgesRenderer=void 0)},r.prototype.enableEdgesRendering=function(t,r){void 0===t&&(t=.95),void 0===r&&(r=!1),this.disableEdgesRendering(),this._edgesRenderer=new e.EdgesRenderer(this,t,r)},Object.defineProperty(r.prototype,"isBlocked",{get:function(){return!1},enumerable:!0,configurable:!0}),r.prototype.getLOD=function(e){return this},r.prototype.getTotalVertices=function(){return 0},r.prototype.getIndices=function(){return null},r.prototype.getVerticesData=function(e){return null},r.prototype.isVerticesDataPresent=function(e){return!1},r.prototype.getBoundingInfo=function(){return this._masterMesh?this._masterMesh.getBoundingInfo():(this._boundingInfo||this._updateBoundingInfo(),this._boundingInfo)},Object.defineProperty(r.prototype,"useBones",{get:function(){return this.skeleton&&this.getScene().skeletonsEnabled&&this.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&this.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)},enumerable:!0,configurable:!0}),r.prototype._preActivate=function(){},r.prototype._activate=function(e){this._renderId=e},r.prototype.getWorldMatrix=function(){return this._masterMesh?this._masterMesh.getWorldMatrix():(this._currentRenderId!==this.getScene().getRenderId()&&this.computeWorldMatrix(),this._worldMatrix)},Object.defineProperty(r.prototype,"worldMatrixFromCache",{get:function(){return this._worldMatrix},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"absolutePosition",{get:function(){return this._absolutePosition},enumerable:!0,configurable:!0}),r.prototype.freezeWorldMatrix=function(){this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0),this._isWorldMatrixFrozen=!0},r.prototype.unfreezeWorldMatrix=function(){this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0)},Object.defineProperty(r.prototype,"isWorldMatrixFrozen",{get:function(){return this._isWorldMatrixFrozen},enumerable:!0,configurable:!0}),r.prototype.rotate=function(t,r,i){t.normalize(),this.rotationQuaternion||(this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation=e.Vector3.Zero());var n;if(i&&i!==e.Space.LOCAL){if(this.parent){var s=this.parent.getWorldMatrix().clone();s.invert(),t=e.Vector3.TransformNormal(t,s)}n=e.Quaternion.RotationAxis(t,r),this.rotationQuaternion=n.multiply(this.rotationQuaternion)}else n=e.Quaternion.RotationAxis(t,r),this.rotationQuaternion=this.rotationQuaternion.multiply(n)},r.prototype.translate=function(t,r,i){var n=t.scale(r);if(i&&i!==e.Space.LOCAL)this.setAbsolutePosition(this.getAbsolutePosition().add(n));else{var s=this.getPositionExpressedInLocalSpace().add(n);this.setPositionWithLocalVector(s)}},r.prototype.getAbsolutePosition=function(){return this.computeWorldMatrix(),this._absolutePosition},r.prototype.setAbsolutePosition=function(t){if(t){var r,i,n;if(void 0===t.x){if(arguments.length<3)return;r=arguments[0],i=arguments[1],n=arguments[2]}else r=t.x,i=t.y,n=t.z;if(this.parent){var s=this.parent.getWorldMatrix().clone();s.invert();var o=new e.Vector3(r,i,n);this.position=e.Vector3.TransformCoordinates(o,s)}else this.position.x=r,this.position.y=i,this.position.z=n}},r.prototype.movePOV=function(e,t,r){this.position.addInPlace(this.calcMovePOV(e,t,r))},r.prototype.calcMovePOV=function(t,r,i){var n=new e.Matrix,s=this.rotationQuaternion?this.rotationQuaternion:e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z);s.toRotationMatrix(n);var o=e.Vector3.Zero(),a=this.definedFacingForward?-1:1;return e.Vector3.TransformCoordinatesFromFloatsToRef(t*a,r,i*a,n,o),o},r.prototype.rotatePOV=function(e,t,r){this.rotation.addInPlace(this.calcRotatePOV(e,t,r))},r.prototype.calcRotatePOV=function(t,r,i){var n=this.definedFacingForward?1:-1;return new e.Vector3(t*n,r,i*n)},r.prototype.setPivotMatrix=function(e){this._pivotMatrix=e,this._cache.pivotMatrixUpdated=!0},r.prototype.getPivotMatrix=function(){return this._pivotMatrix},r.prototype._isSynchronized=function(){if(this._isDirty)return!1;if(this.billboardMode!==this._cache.billboardMode||this.billboardMode!==r.BILLBOARDMODE_NONE)return!1;if(this._cache.pivotMatrixUpdated)return!1;if(this.infiniteDistance)return!1;if(!this._cache.position.equals(this.position))return!1;if(this.rotationQuaternion){if(!this._cache.rotationQuaternion.equals(this.rotationQuaternion))return!1}else if(!this._cache.rotation.equals(this.rotation))return!1;return this._cache.scaling.equals(this.scaling)?!0:!1},r.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.localMatrixUpdated=!1,this._cache.position=e.Vector3.Zero(),this._cache.scaling=e.Vector3.Zero(),this._cache.rotation=e.Vector3.Zero(),this._cache.rotationQuaternion=new e.Quaternion(0,0,0,0),this._cache.billboardMode=-1},r.prototype.markAsDirty=function(e){"rotation"===e&&(this.rotationQuaternion=null),this._currentRenderId=Number.MAX_VALUE,this._isDirty=!0},r.prototype._updateBoundingInfo=function(){this._boundingInfo=this._boundingInfo||new e.BoundingInfo(this.absolutePosition,this.absolutePosition),this._boundingInfo.update(this.worldMatrixFromCache),this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)},r.prototype._updateSubMeshesBoundingInfo=function(e){if(this.subMeshes)for(var t=0;t-1&&this._onAfterWorldMatrixUpdate.splice(t,1)},r.prototype.setPositionWithLocalVector=function(t){this.computeWorldMatrix(),this.position=e.Vector3.TransformNormal(t,this._localWorld)},r.prototype.getPositionExpressedInLocalSpace=function(){this.computeWorldMatrix();var t=this._localWorld.clone();return t.invert(),e.Vector3.TransformNormal(this.position,t)},r.prototype.locallyTranslate=function(t){this.computeWorldMatrix(!0),this.position=e.Vector3.TransformCoordinates(t,this._localWorld)},r.prototype.lookAt=function(t,r,i,n){r=r||0,i=i||0,n=n||0;var s=t.subtract(this.position),o=-Math.atan2(s.z,s.x)-Math.PI/2,a=Math.sqrt(s.x*s.x+s.z*s.z),h=Math.atan2(s.y,a);this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(o+r,h+i,n)},r.prototype.attachToBone=function(e,t){this._meshToBoneReferal=t,this.parent=e,e.getWorldMatrix().determinant()<0&&(this.scalingDeterminant*=-1)},r.prototype.detachFromBone=function(){this.parent.getWorldMatrix().determinant()<0&&(this.scalingDeterminant*=-1),this._meshToBoneReferal=null,this.parent=null},r.prototype.isInFrustum=function(e){return this._boundingInfo.isInFrustum(e)},r.prototype.isCompletelyInFrustum=function(t){t||(t=this.getScene().activeCamera);var r=t.getViewMatrix().multiply(t.getProjectionMatrix());return this._boundingInfo.isCompletelyInFrustum(e.Frustum.GetPlanes(r))?!0:!1},r.prototype.intersectsMesh=function(e,t){return this._boundingInfo&&e._boundingInfo?this._boundingInfo.intersects(e._boundingInfo,t):!1},r.prototype.intersectsPoint=function(e){return this._boundingInfo?this._boundingInfo.intersectsPoint(e):!1},r.prototype.setPhysicsState=function(t,r){var i=this.getScene().getPhysicsEngine();return i?(t=t||e.PhysicsEngine.NoImpostor,t.impostor&&(r=t,t=t.impostor),t===e.PhysicsEngine.NoImpostor?(i._unregisterMesh(this),null):(r?(r.mass||0===r.mass||(r.mass=0),r.friction||0===r.friction||(r.friction=.2),r.restitution||0===r.restitution||(r.restitution=.2)):r={mass:0,friction:.2,restitution:.2},this._physicImpostor=t,this._physicsMass=r.mass,this._physicsFriction=r.friction,this._physicRestitution=r.restitution,i._registerMesh(this,t,r))):null},r.prototype.getPhysicsImpostor=function(){return this._physicImpostor?this._physicImpostor:e.PhysicsEngine.NoImpostor},r.prototype.getPhysicsMass=function(){return this._physicsMass?this._physicsMass:0},r.prototype.getPhysicsFriction=function(){return this._physicsFriction?this._physicsFriction:0},r.prototype.getPhysicsRestitution=function(){return this._physicRestitution?this._physicRestitution:0},r.prototype.getPositionInCameraSpace=function(t){return t||(t=this.getScene().activeCamera),e.Vector3.TransformCoordinates(this.absolutePosition,t.getViewMatrix())},r.prototype.getDistanceToCamera=function(e){return e||(e=this.getScene().activeCamera),this.absolutePosition.subtract(e.position).length()},r.prototype.applyImpulse=function(e,t){this._physicImpostor&&this.getScene().getPhysicsEngine()._applyImpulse(this,e,t)},r.prototype.setPhysicsLinkWith=function(e,t,r,i){this._physicImpostor&&this.getScene().getPhysicsEngine()._createLink(this,e,t,r,i)},r.prototype.updatePhysicsBodyPosition=function(){this._physicImpostor&&this.getScene().getPhysicsEngine()._updateBodyPosition(this)},Object.defineProperty(r.prototype,"checkCollisions",{get:function(){return this._checkCollisions},set:function(e){this._checkCollisions=e,this.getScene().workerCollisions&&this.getScene().collisionCoordinator.onMeshUpdated(this)},enumerable:!0,configurable:!0 }),r.prototype.moveWithCollisions=function(e){var t=this.getAbsolutePosition();t.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPositionForCollisions),this._oldPositionForCollisions.addInPlace(this.ellipsoidOffset),this._collider.radius=this.ellipsoid,this.getScene().collisionCoordinator.getNewPosition(this._oldPositionForCollisions,e,this._collider,3,this,this._onCollisionPositionChange,this.uniqueId)},r.prototype.createOrUpdateSubmeshesOctree=function(t,r){void 0===t&&(t=64),void 0===r&&(r=2),this._submeshesOctree||(this._submeshesOctree=new e.Octree(e.Octree.CreationFuncForSubMeshes,t,r)),this.computeWorldMatrix(!0);var i=this.getBoundingInfo().boundingBox;return this._submeshesOctree.update(i.minimumWorld,i.maximumWorld,this.subMeshes),this._submeshesOctree},r.prototype._collideForSubMesh=function(t,r,i){if(this._generatePointsArray(),!t._lastColliderWorldVertices||!t._lastColliderTransformMatrix.equals(r)){t._lastColliderTransformMatrix=r.clone(),t._lastColliderWorldVertices=[],t._trianglePlanes=[];for(var n=t.verticesStart,s=t.verticesStart+t.verticesCount,o=n;s>o;o++)t._lastColliderWorldVertices.push(e.Vector3.TransformCoordinates(this._positions[o],r))}i._collide(t._trianglePlanes,t._lastColliderWorldVertices,this.getIndices(),t.indexStart,t.indexStart+t.indexCount,t.verticesStart,!!t.getMaterial()),i.collisionFound&&(i.collidedMesh=this)},r.prototype._processCollisionsForSubMeshes=function(e,t){var r,i;if(this._submeshesOctree&&this.useOctreeForCollisions){var n=e.velocityWorldLength+Math.max(e.radius.x,e.radius.y,e.radius.z),s=this._submeshesOctree.intersects(e.basePointWorld,n);i=s.length,r=s.data}else r=this.subMeshes,i=r.length;for(var o=0;i>o;o++){var a=r[o];i>1&&!a._checkCollision(e)||this._collideForSubMesh(a,t,e)}},r.prototype._checkCollision=function(t){this._boundingInfo._checkCollision(t)&&(e.Matrix.ScalingToRef(1/t.radius.x,1/t.radius.y,1/t.radius.z,this._collisionsScalingMatrix),this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix,this._collisionsTransformMatrix),this._processCollisionsForSubMeshes(t,this._collisionsTransformMatrix))},r.prototype._generatePointsArray=function(){return!1},r.prototype.intersects=function(t,r){var i=new e.PickingInfo;if(!(this.subMeshes&&this._boundingInfo&&t.intersectsSphere(this._boundingInfo.boundingSphere)&&t.intersectsBox(this._boundingInfo.boundingBox)))return i;if(!this._generatePointsArray())return i;var n,s,o=null;if(this._submeshesOctree&&this.useOctreeForPicking){var a=e.Ray.Transform(t,this.getWorldMatrix()),h=this._submeshesOctree.intersectsRay(a);s=h.length,n=h.data}else n=this.subMeshes,s=n.length;for(var c=0;s>c;c++){var l=n[c];if(!(s>1)||l.canIntersects(t)){var u=l.intersects(t,this._positions,this.getIndices(),r);if(u&&(r||!o||u.distance0&&-1===this.includedOnlyMeshes.indexOf(e)?!1:this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e)?!1:0!==this.includeOnlyWithLayerMask&&0===(this.includeOnlyWithLayerMask&e.layerMask)?!1:0!==this.excludeWithLayerMask&&this.excludeWithLayerMask&e.layerMask?!1:!0:!0},r.prototype.getWorldMatrix=function(){this._currentRenderId=this.getScene().getRenderId();var t=this._getWorldMatrix();return this.parent&&this.parent.getWorldMatrix?(this._parentedWorldMatrix||(this._parentedWorldMatrix=e.Matrix.Identity()),t.multiplyToRef(this.parent.getWorldMatrix(),this._parentedWorldMatrix),this._markSyncedWithParent(),this._parentedWorldMatrix):t},r.prototype.dispose=function(){this._shadowGenerator&&(this._shadowGenerator.dispose(),this._shadowGenerator=null),this.getScene().stopAnimation(this),this.getScene().removeLight(this)},r.prototype.serialize=function(){var t={};return t.name=this.name,t.id=this.id,t.tags=e.Tags.GetTags(this),this.intensity&&(t.intensity=this.intensity),this.parent&&(t.parentId=this.parent.id),t.range=this.range,t.diffuse=this.diffuse.asArray(),t.specular=this.specular.asArray(),t},r.Parse=function(t,r){var i;switch(t.type){case 0:i=new e.PointLight(t.name,e.Vector3.FromArray(t.position),r);break;case 1:i=new e.DirectionalLight(t.name,e.Vector3.FromArray(t.direction),r),i.position=e.Vector3.FromArray(t.position);break;case 2:i=new e.SpotLight(t.name,e.Vector3.FromArray(t.position),e.Vector3.FromArray(t.direction),t.angle,t.exponent,r);break;case 3:i=new e.HemisphericLight(t.name,e.Vector3.FromArray(t.direction),r),i.groundColor=e.Color3.FromArray(t.groundColor)}if(i.id=t.id,e.Tags.AddTagsTo(i,t.tags),void 0!==t.intensity&&(i.intensity=t.intensity),t.range&&(i.range=t.range),i.diffuse=e.Color3.FromArray(t.diffuse),i.specular=e.Color3.FromArray(t.specular),t.excludedMeshesIds&&(i._excludedMeshesIds=t.excludedMeshesIds),t.parentId&&(i._waitingParentId=t.parentId),t.includedOnlyMeshesIds&&(i._includedOnlyMeshesIds=t.includedOnlyMeshesIds),t.animations){for(var n=0;nthis._orthoRight&&(this._orthoRight=s.x),s.y>this._orthoTop&&(this._orthoTop=s.y)}}}var u=this._orthoRight-this._orthoLeft,f=this._orthoTop-this._orthoBottom;e.Matrix.OrthoOffCenterLHToRef(this._orthoLeft-u*this.shadowOrthoScale,this._orthoRight+u*this.shadowOrthoScale,this._orthoBottom-f*this.shadowOrthoScale,this._orthoTop+f*this.shadowOrthoScale,-n.maxZ,n.maxZ,t)},r.prototype.supportsVSM=function(){return!0},r.prototype.needRefreshPerFrame=function(){return!0},r.prototype.needCube=function(){return!1},r.prototype.getShadowDirection=function(e){return this.direction},r.prototype.computeTransformedPosition=function(){return this.parent&&this.parent.getWorldMatrix?(this.transformedPosition||(this.transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),!0):!1},r.prototype.transferToEffect=function(t,r){return this.parent&&this.parent.getWorldMatrix?(this._transformedDirection||(this._transformedDirection=e.Vector3.Zero()),e.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection),void t.setFloat4(r,this._transformedDirection.x,this._transformedDirection.y,this._transformedDirection.z,1)):void t.setFloat4(r,this.direction.x,this.direction.y,this.direction.z,1)},r.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},r.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.type=1,e.position=this.position.asArray(),e.direction=this.direction.asArray(),e},r}(e.Light);e.DirectionalLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(r,i){var n=this;this._filter=t.FILTER_NONE,this.blurScale=2,this._blurBoxOffset=0,this._bias=5e-5,this._lightDirection=e.Vector3.Zero(),this.forceBackFacesOnly=!1,this._darkness=0,this._transparencyShadow=!1,this._viewMatrix=e.Matrix.Zero(),this._projectionMatrix=e.Matrix.Zero(),this._transformMatrix=e.Matrix.Zero(),this._worldViewProjection=e.Matrix.Zero(),this._currentFaceIndex=0,this._currentFaceIndexCache=0,this._light=i,this._scene=i.getScene(),this._mapSize=r,i._shadowGenerator=this,this._shadowMap=new e.RenderTargetTexture(i.name+"_shadowMap",r,this._scene,!1,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT,i.needCube()),this._shadowMap.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(e.Texture.NEAREST_SAMPLINGMODE),this._shadowMap.renderParticles=!1,this._shadowMap.onBeforeRender=function(e){n._currentFaceIndex=e},this._shadowMap.onAfterUnbind=function(){n.useBlurVarianceShadowMap&&(n._shadowMap2||(n._shadowMap2=new e.RenderTargetTexture(i.name+"_shadowMap",r,n._scene,!1),n._shadowMap2.wrapU=e.Texture.CLAMP_ADDRESSMODE,n._shadowMap2.wrapV=e.Texture.CLAMP_ADDRESSMODE,n._shadowMap2.updateSamplingMode(e.Texture.TRILINEAR_SAMPLINGMODE),n._downSamplePostprocess=new e.PassPostProcess("downScale",1/n.blurScale,null,e.Texture.BILINEAR_SAMPLINGMODE,n._scene.getEngine()),n._downSamplePostprocess.onApply=function(e){e.setTexture("textureSampler",n._shadowMap)},n.blurBoxOffset=1),n._scene.postProcessManager.directRender([n._downSamplePostprocess,n._boxBlurPostprocess],n._shadowMap2.getInternalTexture()))};var s=function(t){var r=t.getRenderingMesh(),i=n._scene,s=i.getEngine();s.setState(t.getMaterial().backFaceCulling);var o=r._getInstancesRenderList(t._id);if(!o.mustReturn){var a=null!==s.getCaps().instancedArrays&&null!==o.visibleInstances[t._id]&&void 0!==o.visibleInstances[t._id];if(n.isReady(t,a)){s.enableEffect(n._effect),r._bind(t,n._effect,e.Material.TriangleFillMode);var h=t.getMaterial();if(n._effect.setMatrix("viewProjection",n.getTransformMatrix()),n._effect.setVector3("lightPosition",n.getLight().position),n.getLight().needCube()&&n._effect.setFloat2("depthValues",i.activeCamera.minZ,i.activeCamera.maxZ),h&&h.needAlphaTesting()){var c=h.getAlphaTestTexture();n._effect.setTexture("diffuseSampler",c),n._effect.setMatrix("diffuseMatrix",c.getTextureMatrix())}r.useBones&&r.computeBonesUsingShaders&&n._effect.setMatrices("mBones",r.skeleton.getTransformMatrices(r)),n.forceBackFacesOnly&&s.setState(!0,0,!1,!0),r._processRendering(t,n._effect,e.Material.TriangleFillMode,o,a,function(e,t){return n._effect.setMatrix("world",t)}),n.forceBackFacesOnly&&s.setState(!0,0,!1,!1)}else n._shadowMap.resetRefreshCounter()}};this._shadowMap.customRenderFunction=function(e,t,r){var i;for(i=0;i4&&(n.push(e.VertexBuffer.MatricesIndicesExtraKind),n.push(e.VertexBuffer.MatricesWeightsExtraKind)),i.push("#define NUM_BONE_INFLUENCERS "+s.numBoneInfluencers),i.push("#define BonesPerMesh "+(s.skeleton.bones.length+1))):i.push("#define NUM_BONE_INFLUENCERS 0"),r&&(i.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var a=i.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("shadowMap",n,["world","mBones","viewProjection","diffuseMatrix","lightPosition","depthValues"],["diffuseSampler"],a)),this._effect.isReady()},t.prototype.getShadowMap=function(){return this._shadowMap},t.prototype.getShadowMapForRendering=function(){return this._shadowMap2?this._shadowMap2:this._shadowMap},t.prototype.getLight=function(){return this._light},t.prototype.getTransformMatrix=function(){var t=this._scene;if(this._currentRenderID===t.getRenderId()&&this._currentFaceIndexCache===this._currentFaceIndex)return this._transformMatrix;this._currentRenderID=t.getRenderId(),this._currentFaceIndexCache=this._currentFaceIndex;var r=this._light.position;return e.Vector3.NormalizeToRef(this._light.getShadowDirection(this._currentFaceIndex),this._lightDirection),1===Math.abs(e.Vector3.Dot(this._lightDirection,e.Vector3.Up()))&&(this._lightDirection.z=1e-13),this._light.computeTransformedPosition()&&(r=this._light.transformedPosition),!this._light.needRefreshPerFrame()&&this._cachedPosition&&this._cachedDirection&&r.equals(this._cachedPosition)&&this._lightDirection.equals(this._cachedDirection)||(this._cachedPosition=r.clone(),this._cachedDirection=this._lightDirection.clone(),e.Matrix.LookAtLHToRef(r,r.add(this._lightDirection),e.Vector3.Up(),this._viewMatrix),this._light.setShadowProjectionMatrix(this._projectionMatrix,this._viewMatrix,this.getShadowMap().renderList),this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)),this._transformMatrix},t.prototype.getDarkness=function(){return this._darkness},t.prototype.setDarkness=function(e){e>=1?this._darkness=1:0>=e?this._darkness=0:this._darkness=e},t.prototype.setTransparencyShadow=function(e){this._transparencyShadow=e},t.prototype._packHalf=function(t){var r=255*t,i=r-Math.floor(r);return new e.Vector2(t-i/255,i)},t.prototype.dispose=function(){this._shadowMap.dispose(),this._shadowMap2&&this._shadowMap2.dispose(),this._downSamplePostprocess&&this._downSamplePostprocess.dispose(),this._boxBlurPostprocess&&this._boxBlurPostprocess.dispose()},t.prototype.serialize=function(){var e={};e.lightId=this._light.id,e.mapSize=this.getShadowMap().getRenderSize(),e.useVarianceShadowMap=this.useVarianceShadowMap,e.usePoissonSampling=this.usePoissonSampling,e.forceBackFacesOnly=this.forceBackFacesOnly,e.renderList=[];for(var t=0;tr.x+i?!1:r.x-i>t.x?!1:e.y>r.y+i?!1:r.y-i>t.y?!1:e.z>r.z+i?!1:r.z-i>t.z?!1:!0},r=function(e,t,r,i){var n=t*t-4*e*r,s={root:0,found:!1};if(0>n)return s;var o=Math.sqrt(n),a=(-t-o)/(2*e),h=(-t+o)/(2*e);if(a>h){var c=h;h=a,a=c}return a>0&&i>a?(s.root=a,s.found=!0,s):h>0&&i>h?(s.root=h,s.found=!0,s):s},i=function(){function i(){this.radius=new e.Vector3(1,1,1),this.retry=0,this.basePointWorld=e.Vector3.Zero(),this.velocityWorld=e.Vector3.Zero(),this.normalizedVelocity=e.Vector3.Zero(),this._collisionPoint=e.Vector3.Zero(),this._planeIntersectionPoint=e.Vector3.Zero(),this._tempVector=e.Vector3.Zero(),this._tempVector2=e.Vector3.Zero(),this._tempVector3=e.Vector3.Zero(),this._tempVector4=e.Vector3.Zero(),this._edge=e.Vector3.Zero(),this._baseToVertex=e.Vector3.Zero(),this._destinationPoint=e.Vector3.Zero(),this._slidePlaneNormal=e.Vector3.Zero(),this._displacementVector=e.Vector3.Zero()}return i.prototype._initialize=function(t,r,i){this.velocity=r,e.Vector3.NormalizeToRef(r,this.normalizedVelocity),this.basePoint=t,t.multiplyToRef(this.radius,this.basePointWorld),r.multiplyToRef(this.radius,this.velocityWorld),this.velocityWorldLength=this.velocityWorld.length(),this.epsilon=i,this.collisionFound=!1},i.prototype._checkPointInTriangle=function(t,r,i,n,s){r.subtractToRef(t,this._tempVector),i.subtractToRef(t,this._tempVector2),e.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var o=e.Vector3.Dot(this._tempVector4,s);return 0>o?!1:(n.subtractToRef(t,this._tempVector3),e.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),o=e.Vector3.Dot(this._tempVector4,s),0>o?!1:(e.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),o=e.Vector3.Dot(this._tempVector4,s),o>=0))},i.prototype._canDoCollision=function(r,i,n,s){var o=e.Vector3.Distance(this.basePointWorld,r),a=Math.max(this.radius.x,this.radius.y,this.radius.z);return o>this.velocityWorldLength+a+i?!1:t(n,s,this.basePointWorld,this.velocityWorldLength+a)?!0:!1},i.prototype._testTriangle=function(t,i,n,s,o,a){var h,c=!1;i||(i=[]),i[t]||(i[t]=new e.Plane(0,0,0,0),i[t].copyFromPoints(n,s,o));var l=i[t];if(a||l.isFrontFacingTo(this.normalizedVelocity,0)){var u=l.signedDistanceTo(this.basePoint),f=e.Vector3.Dot(l.normal,this.velocity);if(0==f){if(Math.abs(u)>=1)return;c=!0,h=0}else{h=(-1-u)/f;var d=(1-u)/f;if(h>d){var p=d;d=h,h=p}if(h>1||0>d)return;0>h&&(h=0),h>1&&(h=1)}this._collisionPoint.copyFromFloats(0,0,0);var m=!1,g=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,s,o,l.normal)&&(m=!0,g=h,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!m){var _=this.velocity.lengthSquared(),v=_;this.basePoint.subtractToRef(n,this._tempVector);var y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,E=r(v,y,x,g);E.found&&(g=E.root,m=!0,this._collisionPoint.copyFrom(n)),this.basePoint.subtractToRef(s,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,E=r(v,y,x,g),E.found&&(g=E.root,m=!0,this._collisionPoint.copyFrom(s)),this.basePoint.subtractToRef(o,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,E=r(v,y,x,g),E.found&&(g=E.root,m=!0,this._collisionPoint.copyFrom(o)),s.subtractToRef(n,this._edge),n.subtractToRef(this.basePoint,this._baseToVertex);var T=this._edge.lengthSquared(),A=e.Vector3.Dot(this._edge,this.velocity),b=e.Vector3.Dot(this._edge,this._baseToVertex);if(v=T*-_+A*A,y=T*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*A*b,x=T*(1-this._baseToVertex.lengthSquared())+b*b,E=r(v,y,x,g),E.found){var M=(A*E.root-b)/T;M>=0&&1>=M&&(g=E.root,m=!0,this._edge.scaleInPlace(M),n.addToRef(this._edge,this._collisionPoint))}o.subtractToRef(s,this._edge),s.subtractToRef(this.basePoint,this._baseToVertex),T=this._edge.lengthSquared(),A=e.Vector3.Dot(this._edge,this.velocity),b=e.Vector3.Dot(this._edge,this._baseToVertex),v=T*-_+A*A,y=T*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*A*b,x=T*(1-this._baseToVertex.lengthSquared())+b*b,E=r(v,y,x,g),E.found&&(M=(A*E.root-b)/T,M>=0&&1>=M&&(g=E.root,m=!0,this._edge.scaleInPlace(M),s.addToRef(this._edge,this._collisionPoint))),n.subtractToRef(o,this._edge),o.subtractToRef(this.basePoint,this._baseToVertex),T=this._edge.lengthSquared(),A=e.Vector3.Dot(this._edge,this.velocity),b=e.Vector3.Dot(this._edge,this._baseToVertex),v=T*-_+A*A,y=T*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*A*b,x=T*(1-this._baseToVertex.lengthSquared())+b*b,E=r(v,y,x,g),E.found&&(M=(A*E.root-b)/T,M>=0&&1>=M&&(g=E.root,m=!0,this._edge.scaleInPlace(M),o.addToRef(this._edge,this._collisionPoint)))}if(m){var P=g*this.velocity.length();(!this.collisionFound||Pa;a+=3){var h=t[r[a]-s],c=t[r[a+1]-s],l=t[r[a+2]-s];this._testTriangle(a,e,l,c,h,o)}},i.prototype._getResponse=function(t,r){t.addToRef(r,this._destinationPoint),r.scaleInPlace(this.nearestDistance/r.length()),this.basePoint.addToRef(r,t),t.subtractToRef(this.intersectionPoint,this._slidePlaneNormal),this._slidePlaneNormal.normalize(),this._slidePlaneNormal.scaleToRef(this.epsilon,this._displacementVector),t.addInPlace(this._displacementVector),this.intersectionPoint.addInPlace(this._displacementVector),this._slidePlaneNormal.scaleInPlace(e.Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint,this._slidePlaneNormal,this._destinationPoint)),this._destinationPoint.subtractInPlace(this._slidePlaneNormal),this._destinationPoint.subtractToRef(this.intersectionPoint,r)},i}();e.Collider=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){e.CollisionWorker="",function(e){e[e.INIT=0]="INIT",e[e.UPDATE=1]="UPDATE",e[e.COLLIDE=2]="COLLIDE"}(e.WorkerTaskType||(e.WorkerTaskType={}));var t=e.WorkerTaskType;!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.UNKNOWN_ERROR=1]="UNKNOWN_ERROR"}(e.WorkerReplyType||(e.WorkerReplyType={}));var r=e.WorkerReplyType,i=function(){function i(){var n=this;this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this.onMeshUpdated=function(e){n._addUpdateMeshesList[e.uniqueId]=i.SerializeMesh(e)},this.onGeometryUpdated=function(e){n._addUpdateGeometriesList[e.id]=i.SerializeGeometry(e)},this._afterRender=function(){ if(n._init&&!(0==n._toRemoveGeometryArray.length&&0==n._toRemoveMeshesArray.length&&0==Object.keys(n._addUpdateGeometriesList).length&&0==Object.keys(n._addUpdateMeshesList).length||n._runningUpdated>4)){++n._runningUpdated;var e={updatedMeshes:n._addUpdateMeshesList,updatedGeometries:n._addUpdateGeometriesList,removedGeometries:n._toRemoveGeometryArray,removedMeshes:n._toRemoveMeshesArray},r={payload:e,taskType:t.UPDATE},i=[];for(var s in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(s)&&(i.push(r.payload.updatedGeometries[s].indices.buffer),i.push(r.payload.updatedGeometries[s].normals.buffer),i.push(r.payload.updatedGeometries[s].positions.buffer));n._worker.postMessage(r,i),n._addUpdateMeshesList={},n._addUpdateGeometriesList={},n._toRemoveGeometryArray=[],n._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(i){var s=i.data;if(s.error!=r.SUCCESS)return void e.Tools.Warn("error returned from worker!");switch(s.taskType){case t.INIT:n._init=!0,n._scene.meshes.forEach(function(e){n.onMeshAdded(e)}),n._scene.getGeometries().forEach(function(e){n.onGeometryAdded(e)});break;case t.UPDATE:n._runningUpdated--;break;case t.COLLIDE:n._runningCollisionTask=!1;var o=s.payload;if(!n._collisionsCallbackArray[o.collisionId])return;n._collisionsCallbackArray[o.collisionId](o.collisionId,e.Vector3.FromArray(o.newPosition),n._scene.getMeshByUniqueID(o.collidedMeshUniqueId)),n._collisionsCallbackArray[o.collisionId]=void 0}},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,this._runningCollisionTask=!1,this._addUpdateMeshesList={},this._addUpdateGeometriesList={},this._toRemoveGeometryArray=[],this._toRemoveMeshesArray=[]}return i.prototype.getNewPosition=function(e,r,i,n,s,o,a){if(this._init&&!this._collisionsCallbackArray[a]&&!this._collisionsCallbackArray[a+1e5]){e.divideToRef(i.radius,this._scaledPosition),r.divideToRef(i.radius,this._scaledVelocity),this._collisionsCallbackArray[a]=o;var h={collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:i.radius.asArray()},collisionId:a,excludedMeshUniqueId:s?s.uniqueId:null,maximumRetry:n},c={payload:h,taskType:t.COLLIDE};this._worker.postMessage(c)}},i.prototype.init=function(r){this._scene=r,this._scene.registerAfterRender(this._afterRender);var i=e.WorkerIncluded?e.Engine.CodeRepository+"Collisions/babylon.collisionWorker.js":URL.createObjectURL(new Blob([e.CollisionWorker],{type:"application/javascript"}));this._worker=new Worker(i),this._worker.onmessage=this._onMessageFromWorker;var n={payload:{},taskType:t.INIT};this._worker.postMessage(n)},i.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},i.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},i.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},i.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},i.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},i.SerializeMesh=function(t){var r=[];t.subMeshes&&(r=t.subMeshes.map(function(e,t){return{position:t,verticesStart:e.verticesStart,verticesCount:e.verticesCount,indexStart:e.indexStart,indexCount:e.indexCount,hasMaterial:!!e.getMaterial(),sphereCenter:e.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:e.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:e.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:e.getBoundingInfo().boundingBox.maximumWorld.asArray()}}));var i=null;return t instanceof e.Mesh?i=t.geometry?t.geometry.id:null:t instanceof e.InstancedMesh&&(i=t.sourceMesh&&t.sourceMesh.geometry?t.sourceMesh.geometry.id:null),{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:r,checkCollisions:t.checkCollisions}},i.SerializeGeometry=function(t){return{id:t.id,positions:new Float32Array(t.getVerticesData(e.VertexBuffer.PositionKind)||[]),normals:new Float32Array(t.getVerticesData(e.VertexBuffer.NormalKind)||[]),indices:new Int32Array(t.getIndices()||[])}},i}();e.CollisionCoordinatorWorker=i;var n=function(){function t(){this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this._finalPosition=e.Vector3.Zero()}return t.prototype.getNewPosition=function(e,t,r,i,n,s,o){e.divideToRef(r.radius,this._scaledPosition),t.divideToRef(r.radius,this._scaledVelocity),r.collidedMesh=null,r.retry=0,r.initialVelocity=this._scaledVelocity,r.initialPosition=this._scaledPosition,this._collideWithWorld(this._scaledPosition,this._scaledVelocity,r,i,this._finalPosition,n),this._finalPosition.multiplyInPlace(r.radius),s(o,this._finalPosition,r.collidedMesh)},t.prototype.init=function(e){this._scene=e},t.prototype.destroy=function(){},t.prototype.onMeshAdded=function(e){},t.prototype.onMeshUpdated=function(e){},t.prototype.onMeshRemoved=function(e){},t.prototype.onGeometryAdded=function(e){},t.prototype.onGeometryUpdated=function(e){},t.prototype.onGeometryDeleted=function(e){},t.prototype._collideWithWorld=function(t,r,i,n,s,o){void 0===o&&(o=null);var a=10*e.Engine.CollisionsEpsilon;if(i.retry>=n)return void s.copyFrom(t);i._initialize(t,r,a);for(var h=0;h-1)return e.Tools.Error("You're trying to reuse a post process not defined as reusable."),0;if(null==r||0>r)return this._postProcesses.push(t),this._postProcessesTakenIndices.push(this._postProcesses.length-1),this._postProcesses.length-1;var i,n,s=0;if(this._postProcesses[r]){for(n=this._postProcesses.length-1,i=n;i>=r+1;--i)this._postProcesses[i+1]=this._postProcesses[i];s=1}for(i=0;i=i;--o)this._postProcessesTakenIndices[o+1]=this._postProcessesTakenIndices[o]+s;this._postProcessesTakenIndices[i]=r;break}s||-1!==this._postProcessesTakenIndices.indexOf(r)||this._postProcessesTakenIndices.push(r);var a=r+s;return this._postProcesses[a]=t,a},i.prototype.detachPostProcess=function(e,t){void 0===t&&(t=null);var r,i,n=[];if(t)for(t=t instanceof Array?t:[t],r=0;rr;r++)this._postProcesses[r]===e&&(delete this._postProcesses[r],i=this._postProcessesTakenIndices.indexOf(r),this._postProcessesTakenIndices.splice(i,1))}return n},i.prototype.getWorldMatrix=function(){this._worldMatrix||(this._worldMatrix=e.Matrix.Identity());var t=this.getViewMatrix();return t.invertToRef(this._worldMatrix),this._worldMatrix},i.prototype._getViewMatrix=function(){return e.Matrix.Identity()},i.prototype.getViewMatrix=function(t){return this._computedViewMatrix=this._computeViewMatrix(t),!t&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this.parent&&this.parent.getWorldMatrix?(this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._computedViewMatrix.invertToRef(this._worldMatrix),this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(),this._computedViewMatrix),this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12],this._computedViewMatrix.m[13],this._computedViewMatrix.m[14]),this._computedViewMatrix.invert(),this._markSyncedWithParent()):this._globalPosition.copyFrom(this.position),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix)},i.prototype._computeViewMatrix=function(e){return!e&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this._computedViewMatrix=this._getViewMatrix(),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix)},i.prototype.getProjectionMatrix=function(t){if(!t&&this._isSynchronizedProjectionMatrix())return this._projectionMatrix;var r=this.getEngine();if(this.mode===i.PERSPECTIVE_CAMERA)return this.minZ<=0&&(this.minZ=.1),e.Matrix.PerspectiveFovLHToRef(this.fov,r.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode),this._projectionMatrix;var n=r.getRenderWidth()/2,s=r.getRenderHeight()/2;return e.Matrix.OrthoOffCenterLHToRef(this.orthoLeft||-n,this.orthoRight||n,this.orthoBottom||-s,this.orthoTop||s,this.minZ,this.maxZ,this._projectionMatrix),this._projectionMatrix},i.prototype.dispose=function(){for(this.getScene().stopAnimation(this),this.getScene().removeCamera(this);this._rigCameras.length>0;)this._rigCameras.pop().dispose();for(var e=0;e0;)this._rigCameras.pop().dispose();switch(this.cameraRigMode=r,this._cameraRigParams={},this.cameraRigMode){case i.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case i.RIG_MODE_STEREOSCOPIC_OVERUNDER:this._cameraRigParams.interaxialDistance=n.interaxialDistance||.0637,this._cameraRigParams.stereoHalfAngle=e.Tools.ToRadians(this._cameraRigParams.interaxialDistance/.0637),this._rigCameras.push(this.createRigCamera(this.name+"_L",0)),this._rigCameras.push(this.createRigCamera(this.name+"_R",1))}var s=new Array;switch(this.cameraRigMode){case i.RIG_MODE_STEREOSCOPIC_ANAGLYPH:s.push(new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[0])),this._rigCameras[0].isIntermediate=!0,s.push(new e.AnaglyphPostProcess(this.name+"_anaglyph",1,this._rigCameras[1])),s[1].onApply=function(e){e.setTextureFromPostProcess("leftSampler",s[0])};break;case i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case i.RIG_MODE_STEREOSCOPIC_OVERUNDER:var o=this.cameraRigMode===i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL||this.cameraRigMode===i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED,a=this.cameraRigMode===i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED?1:0,h=1-a;s.push(new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[a])),this._rigCameras[a].isIntermediate=!0,s.push(new e.StereoscopicInterlacePostProcess(this.name+"_stereoInterlace",this._rigCameras[h],s[0],o));break;case i.RIG_MODE_VR:this._rigCameras.push(this.createRigCamera(this.name+"_L",0)),this._rigCameras.push(this.createRigCamera(this.name+"_R",1));var c=n.vrCameraMetrics||t.GetDefault();this._rigCameras[0]._cameraRigParams.vrMetrics=c,this._rigCameras[0].viewport=new e.Viewport(0,0,.5,1),this._rigCameras[0]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[0]._cameraRigParams.vrHMatrix=c.leftHMatrix,this._rigCameras[0]._cameraRigParams.vrPreViewMatrix=c.leftPreViewMatrix,this._rigCameras[0].getProjectionMatrix=this._rigCameras[0]._getVRProjectionMatrix,c.compensateDistortion&&s.push(new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Left",this._rigCameras[0],!1,c)),this._rigCameras[1]._cameraRigParams.vrMetrics=this._rigCameras[0]._cameraRigParams.vrMetrics,this._rigCameras[1].viewport=new e.Viewport(.5,0,.5,1),this._rigCameras[1]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[1]._cameraRigParams.vrHMatrix=c.rightHMatrix,this._rigCameras[1]._cameraRigParams.vrPreViewMatrix=c.rightPreViewMatrix,this._rigCameras[1].getProjectionMatrix=this._rigCameras[1]._getVRProjectionMatrix,c.compensateDistortion&&s.push(new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Right",this._rigCameras[1],!0,c))}this._update()},i.prototype._getVRProjectionMatrix=function(){return e.Matrix.PerspectiveFovLHToRef(this._cameraRigParams.vrMetrics.aspectRatioFov,this._cameraRigParams.vrMetrics.aspectRatio,this.minZ,this.maxZ,this._cameraRigParams.vrWorkMatrix),this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrHMatrix,this._projectionMatrix),this._projectionMatrix},i.prototype.setCameraRigParameter=function(t,r){this._cameraRigParams[t]=r,"interaxialDistance"===t&&(this._cameraRigParams.stereoHalfAngle=e.Tools.ToRadians(r/.0637))},i.prototype.createRigCamera=function(e,t){return null},i.prototype._updateRigCameras=function(){for(var e=0;e=0?this.rotation.y=-Math.atan(r.z/r.x)+Math.PI/2:this.rotation.y=-Math.atan(r.z/r.x)-Math.PI/2,this.rotation.z=-Math.acos(e.Vector3.Dot(new e.Vector3(0,1,0),this.upVector)),isNaN(this.rotation.x)&&(this.rotation.x=0),isNaN(this.rotation.y)&&(this.rotation.y=0),isNaN(this.rotation.z)&&(this.rotation.z=0)},r.prototype.getTarget=function(){return this._currentTarget},r.prototype._decideIfNeedsToMove=function(){return Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},r.prototype._updatePosition=function(){this.position.addInPlace(this.cameraDirection)},r.prototype._checkInputs=function(){var r=this._decideIfNeedsToMove(),i=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(r&&this._updatePosition(),i&&(this.rotation.x+=this.cameraRotation.x,this.rotation.y+=this.cameraRotation.y,!this.noRotationConstraint)){var n=Math.PI/2*.95;this.rotation.x>n&&(this.rotation.x=n),this.rotation.x<-n&&(this.rotation.x=-n)}r&&(Math.abs(this.cameraDirection.x)e.Engine.CollisionsEpsilon&&(s.position.addInPlace(s._diffPosition),s.onCollide&&i&&s.onCollide(i))};n(r)}}return __extends(r,t),r.prototype._onLostFocus=function(e){this._keys=[]},r.prototype.attachControl=function(t,r){var i,n=this,s=this.getEngine();this._attachedElement||(this._attachedElement=t,void 0===this._onMouseDown&&(this._onMouseDown=function(e){i={x:e.clientX,y:e.clientY},r||e.preventDefault()},this._onMouseUp=function(e){i=null,r||e.preventDefault()},this._onMouseOut=function(e){i=null,n._keys=[],r||e.preventDefault()},this._onMouseMove=function(e){if(i||s.isPointerLock){var t,o;s.isPointerLock?(t=e.movementX||e.mozMovementX||e.webkitMovementX||e.msMovementX||0,o=e.movementY||e.mozMovementY||e.webkitMovementY||e.msMovementY||0):(t=e.clientX-i.x,o=e.clientY-i.y),n.cameraRotation.y+=t/n.angularSensibility,n.cameraRotation.x+=o/n.angularSensibility,i={x:e.clientX,y:e.clientY},r||e.preventDefault()}},this._onKeyDown=function(e){if(-1!==n.keysUp.indexOf(e.keyCode)||-1!==n.keysDown.indexOf(e.keyCode)||-1!==n.keysLeft.indexOf(e.keyCode)||-1!==n.keysRight.indexOf(e.keyCode)){var t=n._keys.indexOf(e.keyCode);-1===t&&n._keys.push(e.keyCode),r||e.preventDefault()}},this._onKeyUp=function(e){if(-1!==n.keysUp.indexOf(e.keyCode)||-1!==n.keysDown.indexOf(e.keyCode)||-1!==n.keysLeft.indexOf(e.keyCode)||-1!==n.keysRight.indexOf(e.keyCode)){var t=n._keys.indexOf(e.keyCode);t>=0&&n._keys.splice(t,1),r||e.preventDefault()}},this._reset=function(){n._keys=[],i=null,n.cameraDirection=new e.Vector3(0,0,0),n.cameraRotation=new e.Vector2(0,0)}),t.addEventListener("mousedown",this._onMouseDown,!1), t.addEventListener("mouseup",this._onMouseUp,!1),t.addEventListener("mouseout",this._onMouseOut,!1),t.addEventListener("mousemove",this._onMouseMove,!1),e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]))},r.prototype.detachControl=function(t){this._attachedElement===t&&(t.removeEventListener("mousedown",this._onMouseDown),t.removeEventListener("mouseup",this._onMouseUp),t.removeEventListener("mouseout",this._onMouseOut),t.removeEventListener("mousemove",this._onMouseMove),e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]),this._attachedElement=null,this._reset&&this._reset())},r.prototype._collideWithWorld=function(t){var r;r=this.parent?e.Vector3.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position,r.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._collider.radius=this.ellipsoid;var i=t;this.applyGravity&&(i=t.add(this.getScene().gravity)),this.getScene().collisionCoordinator.getNewPosition(this._oldPosition,i,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId)},r.prototype._checkInputs=function(){this._localDirection||(this._localDirection=e.Vector3.Zero(),this._transformedDirection=e.Vector3.Zero());for(var r=0;r0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},r.prototype._updatePosition=function(){this.checkCollisions&&this.getScene().collisionsEnabled?this._collideWithWorld(this.cameraDirection):this.position.addInPlace(this.cameraDirection)},r.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.checkCollisions=this.checkCollisions,e.applyGravity=this.applyGravity,e.ellipsoid=this.ellipsoid.asArray(),e},r}(e.TargetCamera);e.FreeCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(e,r,i){t.call(this,e,r,i),this.radius=12,this.rotationOffset=0,this.heightOffset=4,this.cameraAcceleration=.05,this.maxCameraSpeed=20}return __extends(r,t),r.prototype.getRadians=function(e){return e*Math.PI/180},r.prototype.follow=function(t){if(t){var r;if(t.rotationQuaternion){var i=new e.Matrix;t.rotationQuaternion.toRotationMatrix(i),r=Math.atan2(i.m[8],i.m[10])}else r=t.rotation.y;var n=this.getRadians(this.rotationOffset)+r,s=t.position.x+Math.sin(n)*this.radius,o=t.position.z+Math.cos(n)*this.radius,a=s-this.position.x,h=t.position.y+this.heightOffset-this.position.y,c=o-this.position.z,l=a*this.cameraAcceleration*2,u=h*this.cameraAcceleration,f=c*this.cameraAcceleration*2;(l>this.maxCameraSpeed||l<-this.maxCameraSpeed)&&(l=1>l?-this.maxCameraSpeed:this.maxCameraSpeed),(u>this.maxCameraSpeed||u<-this.maxCameraSpeed)&&(u=1>u?-this.maxCameraSpeed:this.maxCameraSpeed),(f>this.maxCameraSpeed||f<-this.maxCameraSpeed)&&(f=1>f?-this.maxCameraSpeed:this.maxCameraSpeed),this.position=new e.Vector3(this.position.x+l,this.position.y+u,this.position.z+f),this.setTarget(t.position)}},r.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.follow(this.target)},r.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.radius=this.radius,e.heightOffset=this.heightOffset,e.rotationOffset=this.rotationOffset,e},r}(e.TargetCamera);e.FollowCamera=t;var r=function(t){function r(r,i,n,s,o,a){t.call(this,r,e.Vector3.Zero(),a),this.alpha=i,this.beta=n,this.radius=s,this.target=o,this._cartesianCoordinates=e.Vector3.Zero(),this.follow()}return __extends(r,t),r.prototype.follow=function(){this._cartesianCoordinates.x=this.radius*Math.cos(this.alpha)*Math.cos(this.beta),this._cartesianCoordinates.y=this.radius*Math.sin(this.beta),this._cartesianCoordinates.z=this.radius*Math.sin(this.alpha)*Math.cos(this.beta),this.position=this.target.position.add(this._cartesianCoordinates),this.setTarget(this.target.position)},r.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.follow()},r.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.radius=this.radius,e},r}(e.TargetCamera);e.ArcFollowCamera=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(e,r,i){t.call(this,e,r,i),this._offsetX=null,this._offsetY=null,this._pointerCount=0,this._pointerPressed=[],this.touchAngularSensibility=2e5,this.touchMoveSensibility=250}return __extends(r,t),r.prototype._onLostFocus=function(e){this._offsetX=null,this._offsetY=null,t.prototype._onLostFocus.call(this,e)},r.prototype.attachControl=function(e,r){var i,n=this;this._attachedCanvas||(void 0===this._onPointerDown&&(this._onPointerDown=function(e){"mouse"!==e.pointerType&&(r||e.preventDefault(),n._pointerPressed.push(e.pointerId),1===n._pointerPressed.length&&(i={x:e.clientX,y:e.clientY}))},this._onPointerUp=function(e){if("mouse"!==e.pointerType){r||e.preventDefault();var t=n._pointerPressed.indexOf(e.pointerId);-1!==t&&(n._pointerPressed.splice(t,1),0==t&&(i=null,n._offsetX=null,n._offsetY=null))}},this._onPointerMove=function(e){if("mouse"!==e.pointerType&&(r||e.preventDefault(),i)){var t=n._pointerPressed.indexOf(e.pointerId);0==t&&(n._offsetX=e.clientX-i.x,n._offsetY=-(e.clientY-i.y))}}),e.addEventListener("pointerdown",this._onPointerDown),e.addEventListener("pointerup",this._onPointerUp),e.addEventListener("pointerout",this._onPointerUp),e.addEventListener("pointermove",this._onPointerMove),t.prototype.attachControl.call(this,e))},r.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.prototype.detachControl.call(this,e))},r.prototype._checkInputs=function(){if(this._offsetX)if(this.cameraRotation.y+=this._offsetX/this.touchAngularSensibility,this._pointerPressed.length>1)this.cameraRotation.x+=-this._offsetY/this.touchAngularSensibility;else{var r=this._computeLocalCameraSpeed(),i=new e.Vector3(0,0,r*this._offsetY/this.touchMoveSensibility);e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,0,this._cameraRotationMatrix),this.cameraDirection.addInPlace(e.Vector3.TransformCoordinates(i,this._cameraRotationMatrix))}t.prototype._checkInputs.call(this)},r}(e.FreeCamera);e.TouchCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=e.Tools.GetPointerPrefix(),r=function(r){function i(t,i,n,s,o,a){var h=this;r.call(this,t,e.Vector3.Zero(),a),this.alpha=i,this.beta=n,this.radius=s,this.target=o,this.inertialAlphaOffset=0,this.inertialBetaOffset=0,this.inertialRadiusOffset=0,this.lowerAlphaLimit=null,this.upperAlphaLimit=null,this.lowerBetaLimit=.01,this.upperBetaLimit=Math.PI,this.lowerRadiusLimit=null,this.upperRadiusLimit=null,this.angularSensibilityX=1e3,this.angularSensibilityY=1e3,this.wheelPrecision=3,this.pinchPrecision=2,this.panningSensibility=50,this.inertialPanningX=0,this.inertialPanningY=0,this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39],this.zoomOnFactor=1,this.targetScreenOffset=e.Vector2.Zero(),this.pinchInwards=!0,this.allowUpsideDown=!0,this._keys=[],this._viewMatrix=new e.Matrix,this.panningAxis=new e.Vector3(1,0,1),this._isRightClick=!1,this._isCtrlPushed=!1,this.checkCollisions=!1,this.collisionRadius=new e.Vector3(.5,.5,.5),this._collider=new e.Collider,this._previousPosition=e.Vector3.Zero(),this._collisionVelocity=e.Vector3.Zero(),this._newPosition=e.Vector3.Zero(),this._onCollisionPositionChange=function(t,r,i){void 0===i&&(i=null),h.getScene().workerCollisions&&h.checkCollisions&&r.multiplyInPlace(h._collider.radius),i?(h.setPosition(r),h.onCollide&&h.onCollide(i)):h._previousPosition.copyFrom(h.position);var n=Math.cos(h.alpha),s=Math.sin(h.alpha),o=Math.cos(h.beta),a=Math.sin(h.beta),c=h._getTargetPosition();c.addToRef(new e.Vector3(h.radius*n*a,h.radius*o,h.radius*s*a),h._newPosition),h.position.copyFrom(h._newPosition);var l=h.upVector;h.allowUpsideDown&&h.beta<0&&(l=l.clone(),l=l.negate()),e.Matrix.LookAtLHToRef(h.position,c,l,h._viewMatrix),h._viewMatrix.m[12]+=h.targetScreenOffset.x,h._viewMatrix.m[13]+=h.targetScreenOffset.y,h._collisionTriggered=!1},this.target||(this.target=e.Vector3.Zero()),this.getViewMatrix()}return __extends(i,r),Object.defineProperty(i.prototype,"angularSensibility",{get:function(){return e.Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead."),Math.max(this.angularSensibilityX,this.angularSensibilityY)},set:function(t){e.Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead."),this.angularSensibilityX=t,this.angularSensibilityY=t},enumerable:!0,configurable:!0}),i.prototype._getTargetPosition=function(){return this.target.getAbsolutePosition?this.target.getAbsolutePosition():this.target},i.prototype._initCache=function(){r.prototype._initCache.call(this),this._cache.target=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.alpha=void 0,this._cache.beta=void 0,this._cache.radius=void 0,this._cache.targetScreenOffset=e.Vector2.Zero()},i.prototype._updateCache=function(e){e||r.prototype._updateCache.call(this),this._cache.target.copyFrom(this._getTargetPosition()),this._cache.alpha=this.alpha,this._cache.beta=this.beta,this._cache.radius=this.radius,this._cache.targetScreenOffset.copyFrom(this.targetScreenOffset)},i.prototype._isSynchronizedViewMatrix=function(){return r.prototype._isSynchronizedViewMatrix.call(this)?this._cache.target.equals(this._getTargetPosition())&&this._cache.alpha===this.alpha&&this._cache.beta===this.beta&&this._cache.radius===this.radius&&this._cache.targetScreenOffset.equals(this.targetScreenOffset):!1},i.prototype.attachControl=function(r,i,n){var s=this;void 0===n&&(n=!0);var o,a=0,h=new e.SmartCollection;if(!this._attachedElement){this._attachedElement=r;var c=this.getEngine();void 0===this._onPointerDown&&(this._onPointerDown=function(e){s._isRightClick=2===e.button,h.add(e.pointerId,{x:e.clientX,y:e.clientY,type:e.pointerType}),o=h.item(e.pointerId),i||e.preventDefault()},this._onPointerUp=function(e){o=null,a=0,h.empty(),i||e.preventDefault()},this._onContextMenu=function(e){e.preventDefault()},this._onPointerMove=function(e){switch(i||e.preventDefault(),h.count){case 1:if(0!==s.panningSensibility&&(s._isCtrlPushed&&n||!n&&s._isRightClick))s.inertialPanningX+=-(e.clientX-o.x)/s.panningSensibility,s.inertialPanningY+=(e.clientY-o.y)/s.panningSensibility;else{var t=e.clientX-o.x,r=e.clientY-o.y;s.inertialAlphaOffset-=t/s.angularSensibilityX,s.inertialBetaOffset-=r/s.angularSensibilityY}o.x=e.clientX,o.y=e.clientY;break;case 2:h.item(e.pointerId).x=e.clientX,h.item(e.pointerId).y=e.clientY;var c=s.pinchInwards?1:-1,l=h.getItemByIndex(0).x-h.getItemByIndex(1).x,u=h.getItemByIndex(0).y-h.getItemByIndex(1).y,f=l*l+u*u;if(0===a)return void(a=f);f!==a&&(s.inertialRadiusOffset+=(f-a)/(s.pinchPrecision*s.wheelPrecision*((s.angularSensibilityX+s.angularSensibilityY)/2)*c),a=f);break;default:h.item(e.pointerId)&&(h.item(e.pointerId).x=e.clientX,h.item(e.pointerId).y=e.clientY)}},this._onMouseMove=function(e){if(c.isPointerLock){var t=e.movementX||e.mozMovementX||e.webkitMovementX||e.msMovementX||0,r=e.movementY||e.mozMovementY||e.webkitMovementY||e.msMovementY||0;s.inertialAlphaOffset-=t/s.angularSensibilityX,s.inertialBetaOffset-=r/s.angularSensibilityY,i||e.preventDefault()}},this._wheel=function(e){var t=0;e.wheelDelta?t=e.wheelDelta/(40*s.wheelPrecision):e.detail&&(t=-e.detail/s.wheelPrecision),t&&(s.inertialRadiusOffset+=t),e.preventDefault&&(i||e.preventDefault())},this._onKeyDown=function(e){if(s._isCtrlPushed=e.ctrlKey,-1!==s.keysUp.indexOf(e.keyCode)||-1!==s.keysDown.indexOf(e.keyCode)||-1!==s.keysLeft.indexOf(e.keyCode)||-1!==s.keysRight.indexOf(e.keyCode)){var t=s._keys.indexOf(e.keyCode);-1===t&&s._keys.push(e.keyCode),e.preventDefault&&(i||e.preventDefault())}},this._onKeyUp=function(e){if(s._isCtrlPushed=e.ctrlKey,-1!==s.keysUp.indexOf(e.keyCode)||-1!==s.keysDown.indexOf(e.keyCode)||-1!==s.keysLeft.indexOf(e.keyCode)||-1!==s.keysRight.indexOf(e.keyCode)){var t=s._keys.indexOf(e.keyCode);t>=0&&s._keys.splice(t,1),e.preventDefault&&(i||e.preventDefault())}},this._onLostFocus=function(){s._keys=[],h.empty(),a=0,o=null},this._onGestureStart=function(e){void 0!==window.MSGesture&&(s._MSGestureHandler||(s._MSGestureHandler=new MSGesture,s._MSGestureHandler.target=r),s._MSGestureHandler.addPointer(e.pointerId))},this._onGesture=function(e){s.radius*=e.scale,e.preventDefault&&(i||(e.stopPropagation(),e.preventDefault()))},this._reset=function(){s._keys=[],s.inertialAlphaOffset=0,s.inertialBetaOffset=0,s.inertialRadiusOffset=0,h.empty(),a=0,o=null}),n||r.addEventListener("contextmenu",this._onContextMenu,!1),r.addEventListener(t+"down",this._onPointerDown,!1),r.addEventListener(t+"up",this._onPointerUp,!1),r.addEventListener(t+"out",this._onPointerUp,!1),r.addEventListener(t+"move",this._onPointerMove,!1),r.addEventListener("mousemove",this._onMouseMove,!1),r.addEventListener("MSPointerDown",this._onGestureStart,!1),r.addEventListener("MSGestureChange",this._onGesture,!1),r.addEventListener("mousewheel",this._wheel,!1),r.addEventListener("DOMMouseScroll",this._wheel,!1),e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}])}},i.prototype.detachControl=function(r){this._attachedElement===r&&(r.removeEventListener("contextmenu",this._onContextMenu),r.removeEventListener(t+"down",this._onPointerDown),r.removeEventListener(t+"up",this._onPointerUp),r.removeEventListener(t+"out",this._onPointerUp),r.removeEventListener(t+"move",this._onPointerMove),r.removeEventListener("mousemove",this._onMouseMove),r.removeEventListener("MSPointerDown",this._onGestureStart),r.removeEventListener("MSGestureChange",this._onGesture),r.removeEventListener("mousewheel",this._wheel),r.removeEventListener("DOMMouseScroll",this._wheel),e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]),this._MSGestureHandler=null,this._attachedElement=null,this._reset&&this._reset())},i.prototype._checkInputs=function(){if(!this._collisionTriggered){for(var t=0;tMath.PI&&(this.beta=this.beta-2*Math.PI):this.betathis.upperBetaLimit&&(this.beta=this.upperBetaLimit),this.lowerAlphaLimit&&this.alphathis.upperAlphaLimit&&(this.alpha=this.upperAlphaLimit),this.lowerRadiusLimit&&this.radiusthis.upperRadiusLimit&&(this.radius=this.upperRadiusLimit)},i.prototype.setPosition=function(e){if(!this.position.equals(e)){var t=e.subtract(this._getTargetPosition());this.radius=t.length(),this.alpha=Math.acos(t.x/Math.sqrt(Math.pow(t.x,2)+Math.pow(t.z,2))),t.z<0&&(this.alpha=2*Math.PI-this.alpha),this.beta=Math.acos(t.y/this.radius),this._checkLimits()}},i.prototype.setTarget=function(e){this.target=e},i.prototype._getViewMatrix=function(){var t=Math.cos(this.alpha),r=Math.sin(this.alpha),i=Math.cos(this.beta),n=Math.sin(this.beta),s=this._getTargetPosition();if(s.addToRef(new e.Vector3(this.radius*t*n,this.radius*i,this.radius*r*n),this._newPosition),this.getScene().collisionsEnabled&&this.checkCollisions)this._collider.radius=this.collisionRadius,this._newPosition.subtractToRef(this.position,this._collisionVelocity),this._collisionTriggered=!0,this.getScene().collisionCoordinator.getNewPosition(this.position,this._collisionVelocity,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId);else{this.position.copyFrom(this._newPosition);var o=this.upVector;this.allowUpsideDown&&this.beta<0&&(o=o.clone(),o=o.negate()),e.Matrix.LookAtLHToRef(this.position,s,o,this._viewMatrix),this._viewMatrix.m[12]+=this.targetScreenOffset.x,this._viewMatrix.m[13]+=this.targetScreenOffset.y}return this._viewMatrix},i.prototype.zoomOn=function(t,r){void 0===r&&(r=!1),t=t||this.getScene().meshes;var i=e.Mesh.MinMax(t),n=e.Vector3.Distance(i.min,i.max);this.radius=n*this.zoomOnFactor,this.focusOn({min:i.min,max:i.max,distance:n},r)},i.prototype.focusOn=function(t,r){void 0===r&&(r=!1);var i,n;void 0===t.min?(i=t||this.getScene().meshes,i=e.Mesh.MinMax(i),n=e.Vector3.Distance(i.min,i.max)):(i=t,n=t.distance),this.target=e.Mesh.Center(i),r||(this.maxZ=2*n)},i.prototype.createRigCamera=function(t,r){switch(this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:var n=this._cameraRigParams.stereoHalfAngle*(0===r?1:-1);return new i(t,this.alpha+n,this.beta,this.radius,this.target,this.getScene())}return null},i.prototype._updateRigCameras=function(){switch(this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:var t=this._rigCameras[0],i=this._rigCameras[1];t.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle,i.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle,t.beta=i.beta=this.beta,t.radius=i.radius=this.radius}r.prototype._updateRigCameras.call(this)},i.prototype.serialize=function(){var t=r.prototype.serialize.call(this);return this.target instanceof e.Vector3&&(t.target=this.target.asArray()),this.target&&this.target.id&&(t.lockedTargetId=this.target.id),t.checkCollisions=this.checkCollisions,t.alpha=this.alpha,t.beta=this.beta,t.radius=this.radius,t},i}(e.TargetCamera);e.ArcRotateCamera=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e){this._renderingGroups=new Array,this._scene=e}return t.prototype._renderParticles=function(t,r){if(0!==this._scene._activeParticleSystems.length){for(var i=this._scene.activeCamera,n=e.Tools.Now,s=0;st._alphaIndex?1:e._alphaIndext._distanceToCamera?-1:0}),r=0;re.ActionManager.LongPressDelay&&Math.abs(o._startingPointerPosition.x-o._pointerX)0&&(s=t.pickSprite(t._pointerX,t._pointerY,r,!1,t.cameraToUseForPointers),s.hit&&s.pickedSprite&&s.pickedSprite.actionManager)){switch(i.button){case 0:s.pickedSprite.actionManager.processTrigger(e.ActionManager.OnLeftPickTrigger,e.ActionEvent.CreateNewFromSprite(s.pickedSprite,t,i));break;case 1:s.pickedSprite.actionManager.processTrigger(e.ActionManager.OnCenterPickTrigger,e.ActionEvent.CreateNewFromSprite(s.pickedSprite,t,i));break;case 2:s.pickedSprite.actionManager.processTrigger(e.ActionManager.OnRightPickTrigger,e.ActionEvent.CreateNewFromSprite(s.pickedSprite,t,i))}s.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickDownTrigger,e.ActionEvent.CreateNewFromSprite(s.pickedSprite,t,i))}}},this._onPointerUp=function(i){if(t.cameraToUseForPointers||t.activeCamera){var n=null;t._updatePointerPosition(i),t.onPointerUp||t.onPointerPick||(n=function(t){return t.isPickable&&t.isVisible&&t.isReady()&&t.actionManager&&(t.actionManager.hasPickTriggers||t.actionManager.hasSpecificTrigger(e.ActionManager.OnLongPressTrigger))});var s=t.pick(t._pointerX,t._pointerY,n,!1,t.cameraToUseForPointers);s.hit&&s.pickedMesh&&(t.onPointerPick&&null!=t._pickedMeshName&&s.pickedMesh.name==t._pickedMeshName&&t.onPointerPick(i,s),s.pickedMesh.actionManager&&(s.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNew(s.pickedMesh,i)),Math.abs(t._startingPointerPosition.x-t._pointerX)0&&(s=t.pickSprite(t._pointerX,t._pointerY,r,!1,t.cameraToUseForPointers),s.hit&&s.pickedSprite&&s.pickedSprite.actionManager&&s.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNewFromSprite(s.pickedSprite,t,i)))}},this._onKeyDown=function(r){t.actionManager&&t.actionManager.processTrigger(e.ActionManager.OnKeyDownTrigger,e.ActionEvent.CreateNewFromScene(t,r))},this._onKeyUp=function(r){t.actionManager&&t.actionManager.processTrigger(e.ActionManager.OnKeyUpTrigger,e.ActionEvent.CreateNewFromScene(t,r))};var i=e.Tools.GetPointerPrefix();this._engine.getRenderingCanvas().addEventListener(i+"move",this._onPointerMove,!1),this._engine.getRenderingCanvas().addEventListener(i+"down",this._onPointerDown,!1),this._engine.getRenderingCanvas().addEventListener(i+"up",this._onPointerUp,!1),this._engine.getRenderingCanvas().addEventListener("mousewheel",this._onPointerMove,!1),this._engine.getRenderingCanvas().addEventListener("DOMMouseScroll",this._onPointerMove,!1),e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp}])},t.prototype.detachControl=function(){var t=e.Tools.GetPointerPrefix();this._engine.getRenderingCanvas().removeEventListener(t+"move",this._onPointerMove),this._engine.getRenderingCanvas().removeEventListener(t+"down",this._onPointerDown),this._engine.getRenderingCanvas().removeEventListener(t+"up",this._onPointerUp),this._engine.getRenderingCanvas().removeEventListener("mousewheel",this._onPointerMove),this._engine.getRenderingCanvas().removeEventListener("DOMMouseScroll",this._onPointerMove),e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp}])},t.prototype.isReady=function(){if(this._pendingData.length>0)return!1;var t;for(t=0;t-1&&this._onBeforeRenderCallbacks.splice(t,1)},t.prototype.registerAfterRender=function(e){this._onAfterRenderCallbacks.push(e)},t.prototype.unregisterAfterRender=function(e){var t=this._onAfterRenderCallbacks.indexOf(e);t>-1&&this._onAfterRenderCallbacks.splice(t,1)},t.prototype._addPendingData=function(e){this._pendingData.push(e)},t.prototype._removePendingData=function(e){var t=this._pendingData.indexOf(e);-1!==t&&this._pendingData.splice(t,1)},t.prototype.getWaitingItemsCount=function(){return this._pendingData.length},t.prototype.executeWhenReady=function(e){var t=this;this._onReadyCallbacks.push(e),-1===this._executeWhenReadyTimeoutId&&(this._executeWhenReadyTimeoutId=setTimeout(function(){t._checkIsReady()},150))},t.prototype._checkIsReady=function(){var e=this;return this.isReady()?(this._onReadyCallbacks.forEach(function(e){e()}),this._onReadyCallbacks=[],void(this._executeWhenReadyTimeoutId=-1)):void(this._executeWhenReadyTimeoutId=setTimeout(function(){e._checkIsReady()},150))},t.prototype.beginAnimation=function(t,r,i,n,s,o,a){if(void 0===s&&(s=1),this.stopAnimation(t),a||(a=new e.Animatable(this,t,r,i,n,s,o)),t.animations&&a.appendAnimations(t,t.animations),t.getAnimatables)for(var h=t.getAnimatables(),c=0;c0)return;this._animationStartDate=e.Tools.Now}for(var t=e.Tools.Now,r=t-this._animationStartDate,i=0;i0?this.activeCamera=this.cameras[0]:this.activeCamera=null),this.onCameraRemoved&&this.onCameraRemoved(e),t},t.prototype.addLight=function(e){e.uniqueId=this._uniqueIdCounter++;var t=this.lights.push(e);this.onNewLightAdded&&this.onNewLightAdded(e,t,this)},t.prototype.addCamera=function(e){e.uniqueId=this._uniqueIdCounter++;var t=this.cameras.push(e);this.onNewCameraAdded&&this.onNewCameraAdded(e,t,this)},t.prototype.swithActiveCamera=function(e,t){void 0===t&&(t=!0);var r=this._engine.getRenderingCanvas();this.activeCamera.detachControl(r),this.activeCamera=e,t&&e.attachControl(r)},t.prototype.setActiveCameraByID=function(e){var t=this.getCameraByID(e);return t?(this.activeCamera=t,t):null},t.prototype.setActiveCameraByName=function(e){var t=this.getCameraByName(e);return t?(this.activeCamera=t,t):null},t.prototype.getMaterialByID=function(e){for(var t=0;t-1?(this._geometries.splice(t,1),this.collisionCoordinator.onGeometryDeleted(e),this.onGeometryRemoved&&this.onGeometryRemoved(e),!0):!1},t.prototype.getGeometries=function(){return this._geometries},t.prototype.getMeshByID=function(e){for(var t=0;t=0;t--)if(this.meshes[t].id===e)return this.meshes[t];return null},t.prototype.getLastEntryByID=function(e){var t;for(t=this.meshes.length-1;t>=0;t--)if(this.meshes[t].id===e)return this.meshes[t];for(t=this.cameras.length-1;t>=0;t--)if(this.cameras[t].id===e)return this.cameras[t];for(t=this.lights.length-1;t>=0;t--)if(this.lights[t].id===e)return this.lights[t];return null},t.prototype.getNodeByID=function(e){var t=this.getMeshByID(e);if(t)return t;var r=this.getLightByID(e);if(r)return r;var i=this.getCameraByID(e);if(i)return i;var n=this.getBoneByID(e);return n},t.prototype.getNodeByName=function(e){var t=this.getMeshByName(e);if(t)return t;var r=this.getLightByName(e);if(r)return r;var i=this.getCameraByName(e);if(i)return i;var n=this.getBoneByName(e);return n},t.prototype.getMeshByName=function(e){for(var t=0;t=0;t--)if(this.skeletons[t].id===e)return this.skeletons[t];return null},t.prototype.getSkeletonById=function(e){for(var t=0;tn;n++){var s=t[n];if(!s.isBlocked&&(this._totalVertices+=s.getTotalVertices(),s.isReady()&&s.isEnabled())){s.computeWorldMatrix(),s.actionManager&&s.actionManager.hasSpecificTriggers([e.ActionManager.OnIntersectionEnterTrigger,e.ActionManager.OnIntersectionExitTrigger])&&this._meshesForIntersections.pushNoDuplicate(s);var o=s.getLOD(this.activeCamera);o&&(s._preActivate(),(s.alwaysSelectAsActiveMesh||s.isVisible&&s.visibility>0&&0!==(s.layerMask&this.activeCamera.layerMask)&&s.isInFrustum(this._frustumPlanes))&&(this._activeMeshes.push(s),this.activeCamera._activeMeshes.push(s),s._activate(this._renderId),this._activeMesh(o)))}}var a=e.Tools.Now;if(this.particlesEnabled){e.Tools.StartPerformanceCounter("Particles",this.particleSystems.length>0);for(var h=0;h0)}this._particlesDuration+=e.Tools.Now-a},t.prototype._activeMesh=function(e){if(e.skeleton&&this.skeletonsEnabled&&(this._activeSkeletons.pushNoDuplicate(e.skeleton),e.computeBonesUsingShaders||this._softwareSkinnedMeshes.pushNoDuplicate(e)),(e.showBoundingBox||this.forceShowBoundingBoxes)&&this._boundingBoxRenderer.renderList.push(e.getBoundingInfo().boundingBox),e._edgesRenderer&&this._edgesRenderers.push(e._edgesRenderer),e&&e.subMeshes){var t,r;if(e._submeshesOctree&&e.useOctreeForRenderingSelection){var i=e._submeshesOctree.select(this._frustumPlanes);t=i.length,r=i.data}else r=e.subMeshes,t=r.length;for(var n=0;t>n;n++){var s=r[n];this._evaluateSubMesh(s,e)}}},t.prototype.updateTransformMatrix=function(e){this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(e))},t.prototype._renderForCamera=function(t){var r=this._engine;if(this.activeCamera=t,!this.activeCamera)throw new Error("Active camera not set");e.Tools.StartPerformanceCounter("Rendering camera "+this.activeCamera.name),r.setViewport(this.activeCamera.viewport),this.resetCachedMaterial(),this._renderId++,this.updateTransformMatrix(),this.beforeCameraRender&&this.beforeCameraRender(this.activeCamera);var i=e.Tools.Now;e.Tools.StartPerformanceCounter("Active meshes evaluation"),this._evaluateActiveMeshes(),this._evaluateActiveMeshesDuration+=e.Tools.Now-i,e.Tools.EndPerformanceCounter("Active meshes evaluation");for(var n=0;n0){e.Tools.StartPerformanceCounter("Render targets",this._renderTargets.length>0);for(var c=0;c0),this._renderId++,r.restoreDefaultFramebuffer()}this._renderTargetsDuration+=e.Tools.Now-h,this.postProcessManager._prepareFrame();var f,d,p=e.Tools.Now;if(this.layers.length){for(r.setDepthBuffer(!1),f=0;f0);for(var g=0;g0)}if(this.layers.length){for(r.setDepthBuffer(!1),f=0;f-1&&(n.trigger===e.ActionManager.OnIntersectionExitTrigger&&n._executeCurrent(e.ActionEvent.CreateNew(r,null,o)),r.actionManager.hasSpecificTrigger(e.ActionManager.OnIntersectionExitTrigger)&&n.trigger!==e.ActionManager.OnIntersectionExitTrigger||r._intersectionsInProgress.splice(h,1))}}},t.prototype.render=function(){var r=e.Tools.Now;this._particlesDuration=0,this._spritesDuration=0,this._activeParticles=0,this._renderDuration=0,this._renderTargetsDuration=0,this._evaluateActiveMeshesDuration=0,this._totalVertices=0,this._activeIndices=0,this._activeBones=0,this.getEngine().resetDrawCalls(),this._meshesForIntersections.reset(),this.resetCachedMaterial(),e.Tools.StartPerformanceCounter("Scene rendering"),this.actionManager&&this.actionManager.processTrigger(e.ActionManager.OnEveryFrameTrigger,null),this.simplificationQueue&&!this.simplificationQueue.running&&this.simplificationQueue.executeNext();var i=Math.max(t.MinDeltaTime,Math.min(this._engine.getDeltaTime(),t.MaxDeltaTime));this._animationRatio=.06*i,this._animate(),this._physicsEngine&&(e.Tools.StartPerformanceCounter("Physics"),this._physicsEngine._runOneStep(i/1e3),e.Tools.EndPerformanceCounter("Physics")),this.beforeRender&&this.beforeRender();var n;for(n=0;n0);for(var h=0;h0),this._renderId++}if(this.customRenderTargets.length>0&&o.restoreDefaultFramebuffer(),this._renderTargetsDuration+=e.Tools.Now-s,this.activeCamera=a,this.proceduralTexturesEnabled){e.Tools.StartPerformanceCounter("Procedural textures",this._proceduralTextures.length>0);for(var l=0;l0)}if(this._engine.clear(this.clearColor,this.autoClear||this.forceWireframe||this.forcePointsCloud,!0),this.shadowsEnabled)for(var f=0;f0)for(var m=this._renderId,g=0;g0&&this._engine.clear(0,!1,!0),this._processSubCameras(this.activeCameras[g]);else{if(!this.activeCamera)throw new Error("No camera defined");this._processSubCameras(this.activeCamera)}for(this._checkIntersections(),e.AudioEngine&&this._updateAudioParameters(),this.afterRender&&this.afterRender(),n=0;n0?this.activeCameras[0]:this.activeCamera,t&&r.canUseWebAudio){r.audioContext.listener.setPosition(t.position.x,t.position.y,t.position.z);var i=e.Matrix.Invert(t.getViewMatrix()),n=e.Vector3.TransformNormal(new e.Vector3(0,0,-1),i);n.normalize(),r.audioContext.listener.setOrientation(n.x,n.y,n.z,0,1,0);var s;for(s=0;s-1&&this._engine.scenes.splice(t,1),this._engine.wipeCaches()},t.prototype.disposeSounds=function(){this.mainSoundTrack.dispose();for(var e=0;e=n.distance))&&(n=c,i))break}return n||new e.PickingInfo},t.prototype._internalPickSprites=function(t,r,i,n){var s=null;if(n=n||this.activeCamera,this.spriteManagers.length>0)for(var o=0;o=s.distance))&&(s=h,i))break}}return s||new e.PickingInfo; },t.prototype.pick=function(e,t,r,i,n){var s=this;return this._internalPick(function(r){return s.createPickingRay(e,t,r,n)},r,i)},t.prototype.pickSprite=function(e,t,r,i,n){return this._internalPickSprites(this.createPickingRayInCameraSpace(e,t,n),r,i,n)},t.prototype.pickWithRay=function(t,r,i){var n=this;return this._internalPick(function(r){return n._pickWithRayInverseMatrix||(n._pickWithRayInverseMatrix=e.Matrix.Identity()),r.invertToRef(n._pickWithRayInverseMatrix),e.Ray.Transform(t,n._pickWithRayInverseMatrix)},r,i)},t.prototype.setPointerOverMesh=function(t){this._pointerOverMesh!==t&&(this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(e.ActionManager.OnPointerOutTrigger,e.ActionEvent.CreateNew(this._pointerOverMesh)),this._pointerOverMesh=t,this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(e.ActionManager.OnPointerOverTrigger,e.ActionEvent.CreateNew(this._pointerOverMesh)))},t.prototype.getPointerOverMesh=function(){return this._pointerOverMesh},t.prototype.getPhysicsEngine=function(){return this._physicsEngine},t.prototype.enablePhysics=function(t,r){return this._physicsEngine?!0:(this._physicsEngine=new e.PhysicsEngine(r),this._physicsEngine.isSupported()?(this._physicsEngine._initialize(t),!0):(this._physicsEngine=null,!1))},t.prototype.disablePhysicsEngine=function(){this._physicsEngine&&(this._physicsEngine.dispose(),this._physicsEngine=void 0)},t.prototype.isPhysicsEnabled=function(){return void 0!==this._physicsEngine},t.prototype.setGravity=function(e){this._physicsEngine&&this._physicsEngine._setGravity(e)},t.prototype.createCompoundImpostor=function(e,t){if(e.parts&&(t=e,e=e.parts),!this._physicsEngine)return null;for(var r=0;r0},enumerable:!0,configurable:!0}),i.prototype._sortLODLevels=function(){this._LODLevels.sort(function(e,t){return e.distancet.distance?-1:0})},i.prototype.addLODLevel=function(t,r){if(r&&r._masterMesh)return e.Tools.Warn("You cannot use a mesh as LOD level twice"),this;var i=new e.Internals.MeshLODLevel(t,r);return this._LODLevels.push(i),r&&(r._masterMesh=this),this._sortLODLevels(),this},i.prototype.getLODLevelAtDistance=function(e){for(var t=0;tr)return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var i=0;it)){for(var r=this.getTotalIndices(),i=r/t|0,n=0;i%3!==0;)i++;this.releaseSubMeshes();for(var s=0;t>s&&!(n>=r);s++)e.SubMesh.CreateFromIndices(0,n,Math.min(i,r-n),this),n+=i;this.synchronizeInstances()}},i.prototype.setVerticesData=function(t,r,i,n){if(this._geometry)this._geometry.setVerticesData(t,r,i,n);else{var s=new e.VertexData;s.set(r,t);var o=this.getScene();new e.Geometry(e.Geometry.RandomId(),o,s,i,this)}},i.prototype.updateVerticesData=function(e,t,r,i){this._geometry&&(i?(this.makeGeometryUnique(),this.updateVerticesData(e,t,r,!1)):this._geometry.updateVerticesData(e,t,r))},i.prototype.updateVerticesDataDirectly=function(t,r,i,n){e.Tools.Warn("Mesh.updateVerticesDataDirectly deprecated since 2.3."),this._geometry&&(n?(this.makeGeometryUnique(),this.updateVerticesDataDirectly(t,r,i,!1)):this._geometry.updateVerticesDataDirectly(t,r,i))},i.prototype.updateMeshPositions=function(t,r){void 0===r&&(r=!0);var i=this.getVerticesData(e.VertexBuffer.PositionKind);if(t(i),this.updateVerticesData(e.VertexBuffer.PositionKind,i,!1,!1),r){var n=this.getIndices(),s=this.getVerticesData(e.VertexBuffer.NormalKind);e.VertexData.ComputeNormals(i,n,s),this.updateVerticesData(e.VertexBuffer.NormalKind,s,!1,!1)}},i.prototype.makeGeometryUnique=function(){if(this._geometry){var t=this._geometry.copy(e.Geometry.RandomId());t.applyToMesh(this)}},i.prototype.setIndices=function(t,r){if(this._geometry)this._geometry.setIndices(t,r);else{var i=new e.VertexData;i.indices=t;var n=this.getScene();new e.Geometry(e.Geometry.RandomId(),n,i,!1,this)}},i.prototype._bind=function(t,r,i){var n,s=this.getScene().getEngine();if(this._unIndexed)n=null;else switch(i){case e.Material.PointFillMode:n=null;break;case e.Material.WireFrameFillMode:n=t.getLinesIndexBuffer(this.getIndices(),s);break;default:case e.Material.TriangleFillMode:n=this._unIndexed?null:this._geometry.getIndexBuffer()}s.bindMultiBuffers(this._geometry.getVertexBuffers(),n,r)},i.prototype._draw=function(t,r,i){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){this.onBeforeDraw&&this.onBeforeDraw();var n=this.getScene().getEngine();switch(r){case e.Material.PointFillMode:n.drawPointClouds(t.verticesStart,t.verticesCount,i);break;case e.Material.WireFrameFillMode:this._unIndexed?n.drawUnIndexed(!1,t.verticesStart,t.verticesCount,i):n.draw(!1,0,t.linesIndexCount,i);break;default:this._unIndexed?n.drawUnIndexed(!0,t.verticesStart,t.verticesCount,i):n.draw(!0,t.indexStart,t.indexCount,i)}}},i.prototype.registerBeforeRender=function(e){this._onBeforeRenderCallbacks.push(e)},i.prototype.unregisterBeforeRender=function(e){var t=this._onBeforeRenderCallbacks.indexOf(e);t>-1&&this._onBeforeRenderCallbacks.splice(t,1)},i.prototype.registerAfterRender=function(e){this._onAfterRenderCallbacks.push(e)},i.prototype.unregisterAfterRender=function(e){var t=this._onAfterRenderCallbacks.indexOf(e);t>-1&&this._onAfterRenderCallbacks.splice(t,1)},i.prototype._getInstancesRenderList=function(e){var t=this.getScene();if(this._batchCache.mustReturn=!1,this._batchCache.renderSelf[e]=this.isEnabled()&&this.isVisible,this._batchCache.visibleInstances[e]=null,this._visibleInstances){var r=t.getRenderId();this._batchCache.visibleInstances[e]=this._visibleInstances[r];var i=this._renderId;if(!this._batchCache.visibleInstances[e]&&this._visibleInstances.defaultRenderId&&(this._batchCache.visibleInstances[e]=this._visibleInstances[this._visibleInstances.defaultRenderId],r=Math.max(this._visibleInstances.defaultRenderId,r),i=Math.max(this._visibleInstances.selfDefaultRenderId,r)),this._batchCache.visibleInstances[e]&&this._batchCache.visibleInstances[e].length){if(this._renderIdForInstances[e]===r)return this._batchCache.mustReturn=!0,this._batchCache;r!==i&&(this._batchCache.renderSelf[e]=!1)}this._renderIdForInstances[e]=r}return this._batchCache},i.prototype._renderWithInstances=function(e,t,r,i,n){for(var s=r.visibleInstances[e._id],o=s.length+1,a=16*o*4;this._instancesBufferSizec;c++){var d=u[c];for(t=0;tm;m++)o[r].push(s[r][d*p+m])}}var g=[],_=o[e.VertexBuffer.PositionKind];for(c=0;f>c;c+=3){u[c]=c,u[c+1]=c+1,u[c+2]=c+2;for(var v=e.Vector3.FromArray(_,3*c),y=e.Vector3.FromArray(_,3*(c+1)),x=e.Vector3.FromArray(_,3*(c+2)),E=v.subtract(y),T=x.subtract(y),A=e.Vector3.Normalize(e.Vector3.Cross(E,T)),b=0;3>b;b++)g.push(A.x),g.push(A.y),g.push(A.z)}for(this.setIndices(u),this.setVerticesData(e.VertexBuffer.NormalKind,g,a),t=0;th;h++){var f=l[h];for(t=0;tp;p++)o[r].push(s[r][f*d+p])}}for(h=0;u>h;h+=3)l[h]=h,l[h+1]=h+1,l[h+2]=h+2;for(this.setIndices(l),t=0;ti;++i){var n=s[i];if(r.equals(n)){a[t]=i;break}}},function(){for(var e=0;e-1&&(s.skeleton=r.getLastSkeletonByID(t.skeletonId),t.numBoneInfluencers&&(s.numBoneInfluencers=t.numBoneInfluencers)),t.physicsImpostor&&(r.isPhysicsEnabled()||r.enablePhysics(),s.setPhysicsState({impostor:t.physicsImpostor,mass:t.physicsMass,friction:t.physicsFriction,restitution:t.physicsRestitution})),t.animations){for(var o=0;o4,h=a?this.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind):null,c=a?this.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind):null,l=t.getTransformMatrices(this),u=e.Vector3.Zero(),f=new e.Matrix,d=new e.Matrix,p=0,m=0;mn&&(g=o[p+n],g>0);n++)e.Matrix.FromFloat32ArrayToRefScaled(l,16*s[p+n],g,d),f.addToSelf(d);if(a)for(n=0;4>n&&(g=c[p+n],g>0);n++)e.Matrix.FromFloat32ArrayToRefScaled(l,16*h[p+n],g,d),f.addToSelf(d);e.Vector3.TransformCoordinatesFromFloatsToRef(this._sourcePositions[m],this._sourcePositions[m+1],this._sourcePositions[m+2],f,u),u.toArray(r,m),e.Vector3.TransformNormalFromFloatsToRef(this._sourceNormals[m],this._sourceNormals[m+1],this._sourceNormals[m+2],f,u),u.toArray(i,m),f.reset()}return this.updateVerticesData(e.VertexBuffer.PositionKind,r),this.updateVerticesData(e.VertexBuffer.NormalKind,i),this}},i.MinMax=function(e){var t=null,r=null;for(var i in e){var n=e[i],s=n.getBoundingInfo().boundingBox;t?(t.MinimizeInPlace(s.minimumWorld),r.MaximizeInPlace(s.maximumWorld)):(t=s.minimumWorld,r=s.maximumWorld)}return{min:t,max:r}},i.Center=function(t){var r=void 0!==t.min?t:i.MinMax(t);return e.Vector3.Center(r.min,r.max)},i.MergeMeshes=function(t,r,n,s){void 0===r&&(r=!0);var o;if(!n){var a=0;for(o=0;o65536))return e.Tools.Warn("Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices"),null}var h,c,l;for(o=0;oc;c++){var l=h[c];o>l&&(o=l),l>a&&(a=l)}return new t(e,o,a-o+1,r,i,n,s)},t}();e.SubMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.CreateBox=function(t,r,i){var n=new e.Mesh(t,i),s=e.VertexData.CreateBox(r);return s.applyToMesh(n,r.updatable),n},t.CreateSphere=function(t,r,i){var n=new e.Mesh(t,i),s=e.VertexData.CreateSphere(r);return s.applyToMesh(n,r.updatable),n},t.CreateDisc=function(t,r,i){var n=new e.Mesh(t,i),s=e.VertexData.CreateDisc(r);return s.applyToMesh(n,r.updatable),n},t.CreateIcoSphere=function(t,r,i){var n=new e.Mesh(t,i),s=e.VertexData.CreateIcoSphere(r);return s.applyToMesh(n,r.updatable),n},t.CreateRibbon=function(t,r,i){var n=r.pathArray,s=r.closeArray,o=r.closePath,a=(r.offset,r.sideOrientation),h=r.instance,c=r.updatable;if(h){var l=function(t){for(var r=n[0].length,i=0,s=h.sideOrientation===e.Mesh.DOUBLESIDE?2:1,o=1;s>=o;o++)for(var a=0;ar?r:l;for(var u=0;r>u;)t[i]=c[u].x,t[i+1]=c[u].y,t[i+2]=c[u].z,u++,i+=3;h._closePath&&(t[i]=c[0].x,t[i+1]=c[0].y,t[i+2]=c[0].z,i+=3)}},u=h.getVerticesData(e.VertexBuffer.PositionKind);if(l(u),h.updateVerticesData(e.VertexBuffer.PositionKind,u,!1,!1),!h.areNormalsFrozen){var f=h.getIndices(),d=h.getVerticesData(e.VertexBuffer.NormalKind);if(e.VertexData.ComputeNormals(u,f,d),h._closePath)for(var p=0,m=0,g=0;gd&&u1?1:i.arc||1,a=void 0===i.closed?!0:i.closed,h=i.shape,c=i.radius||1,l=i.tessellation||64,u=i.updatable,f=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,d=i.cap||e.Mesh.NO_CAP,p=2*Math.PI,m=new Array,g=0,_=0,v=p/l*o,y=new Array;for(g=0;l>=g;g++){var y=[];for((d==e.Mesh.CAP_START||d==e.Mesh.CAP_ALL)&&(y.push(new e.Vector3(0,h[0].y,0)),y.push(new e.Vector3(Math.cos(g*v)*h[0].x*c,h[0].y,Math.sin(g*v)*h[0].x*c))),_=0;_1?1:i.arc||1;var d,p,m=function(t,r,i,n,s,o,a,h){for(var c,l,u,f,d=r.getTangents(),p=r.getNormals(),m=r.getDistances(),g=2*Math.PI,_=g/s*h,v=function(){return n},y=o||v,x=e.Tmp.Matrix[0],E=a===e.Mesh._NO_CAP||a===e.Mesh.CAP_END?0:2,T=0;TA;A++)e.Matrix.RotationAxisToRef(d[T],_*A,x),f=c[A]?c[A]:e.Vector3.Zero(),e.Vector3.TransformCoordinatesToRef(u,x,f),f.scaleInPlace(l).addInPlace(t[T]),c[A]=f;i[E]=c,E++}var b=function(e,r){for(var i=Array(),n=0;e>n;n++)i.push(t[r]);return i};switch(a){case e.Mesh.NO_CAP:break;case e.Mesh.CAP_START:i[0]=b(s,0),i[1]=i[2].slice(0);break;case e.Mesh.CAP_END:i[E]=i[E-1].slice(0),i[E+1]=b(s,t.length-1);break;case e.Mesh.CAP_ALL:i[0]=b(s,0),i[1]=i[2].slice(0),i[E]=i[E-1].slice(0),i[E+1]=b(s,t.length-1)}return i};if(f){var g=i.arc||f.arc;return d=f.path3D.update(s),p=m(s,d,f.pathArray,o,f.tessellation,h,f.cap,g),f=t.CreateRibbon(null,{pathArray:p,instance:f}),f.path3D=d,f.pathArray=p,f.arc=g,f}d=new e.Path3D(s);var _=new Array;c=0>c||c>3?0:c,p=m(s,d,_,o,a,h,c,i.arc);var v=t.CreateRibbon(r,{pathArray:p,closePath:!0,closeArray:!1,updatable:l,sideOrientation:u},n);return v.pathArray=p,v.path3D=d,v.tessellation=a,v.cap=c,v.arc=i.arc,v},t.CreatePolyhedron=function(t,r,i){var n=new e.Mesh(t,i),s=e.VertexData.CreatePolyhedron(r);return s.applyToMesh(n,r.updatable),n},t.CreateDecal=function(t,r,i){var n=r.getIndices(),s=r.getVerticesData(e.VertexBuffer.PositionKind),o=r.getVerticesData(e.VertexBuffer.NormalKind),a=i.position||e.Vector3.Zero(),h=i.normal||e.Vector3.Up(),c=i.size||new e.Vector3(1,1,1),l=i.angle||0;if(!h){var u=new e.Vector3(0,0,1),f=r.getScene().activeCamera,d=e.Vector3.TransformCoordinates(u,f.getWorldMatrix());h=f.globalPosition.subtract(d)}var p=-Math.atan2(h.z,h.x)-Math.PI/2,m=Math.sqrt(h.x*h.x+h.z*h.z),g=Math.atan2(h.y,m),_=e.Matrix.RotationYawPitchRoll(p,g,l).multiply(e.Matrix.Translation(a.x,a.y,a.z)),v=e.Matrix.Invert(_),y=r.getWorldMatrix(),x=y.multiply(v),E=new e.VertexData;E.indices=[],E.positions=[],E.normals=[],E.uvs=[];for(var T=0,A=function(t){var r=n[t],i=new e.PositionNormalVertex;return i.position=new e.Vector3(s[3*r],s[3*r+1],s[3*r+2]),i.position=e.Vector3.TransformCoordinates(i.position,x),i.normal=new e.Vector3(o[3*r],o[3*r+1],o[3*r+2]),i},b=function(t,r){if(0===t.length)return t;for(var i=.5*Math.abs(e.Vector3.Dot(c,r)),n=function(t,n){var s=e.Vector3.GetClipFactor(t.position,n.position,r,i);return new e.PositionNormalVertex(e.Vector3.Lerp(t.position,n.position,s),e.Vector3.Lerp(t.normal,n.normal,s))},s=new Array,o=0;o0,h=_>0,l=v>0,m=(a?1:0)+(h?1:0)+(l?1:0)){case 0:s.push(t[o]),s.push(t[o+1]),s.push(t[o+2]);break;case 1:if(a&&(u=t[o+1],f=t[o+2],d=n(t[o],u),p=n(t[o],f)),h){u=t[o],f=t[o+2],d=n(t[o+1],u),p=n(t[o+1],f),s.push(d),s.push(f.clone()),s.push(u.clone()),s.push(f.clone()),s.push(d.clone()),s.push(p);break}l&&(u=t[o],f=t[o+1],d=n(t[o+2],u),p=n(t[o+2],f)),s.push(u.clone()),s.push(f.clone()),s.push(d),s.push(p),s.push(d.clone()),s.push(f.clone());break;case 2:a||(u=t[o].clone(),f=n(u,t[o+1]),d=n(u,t[o+2]),s.push(u),s.push(f),s.push(d)),h||(u=t[o+1].clone(),f=n(u,t[o+2]),d=n(u,t[o]),s.push(u),s.push(f),s.push(d)),l||(u=t[o+2].clone(),f=n(u,t[o]),d=n(u,t[o+1]),s.push(u),s.push(f),s.push(d));break;case 3:}}return s},M=0;Ml||l>3?0:l,_=v(r,i,g,y,n,s,o,a,l,u);var x=e.Mesh.CreateRibbon(t,_,h,c,0,f,d,p);return x.pathArray=_,x.path3D=g,x.cap=l,x},t}();e.MeshBuilder=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this.hasAlpha=!1,this.getAlphaFromRGB=!1,this.level=1,this.isCube=!1,this.isRenderTarget=!1,this.animations=new Array,this.coordinatesIndex=0,this.coordinatesMode=e.Texture.EXPLICIT_MODE,this.wrapU=e.Texture.WRAP_ADDRESSMODE,this.wrapV=e.Texture.WRAP_ADDRESSMODE,this.anisotropicFilteringLevel=4,this._scene=t,this._scene.textures.push(this)}return t.prototype.getScene=function(){return this._scene},t.prototype.getTextureMatrix=function(){return null},t.prototype.getReflectionTextureMatrix=function(){return null},t.prototype.getInternalTexture=function(){return this._texture},t.prototype.isReady=function(){return this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED?!0:this._texture?this._texture.isReady:!1},t.prototype.getSize=function(){return this._texture._width?{width:this._texture._width,height:this._texture._height}:this._texture._size?{width:this._texture._size,height:this._texture._size}:{width:0,height:0}},t.prototype.getBaseSize=function(){return this.isReady()?this._texture._size?{width:this._texture._size,height:this._texture._size}:{width:this._texture._baseWidth,height:this._texture._baseHeight}:{width:0,height:0}},t.prototype.scale=function(e){},Object.defineProperty(t.prototype,"canRescale",{get:function(){return!1},enumerable:!0,configurable:!0}),t.prototype._removeFromCache=function(e,t){for(var r=this._scene.getEngine().getLoadedTexturesCache(),i=0;i=0&&this._scene.textures.splice(e,1),void 0!==this._texture&&(this.releaseInternalTexture(),this.onDispose&&this.onDispose())},t.prototype.serialize=function(){var t={};return this.name?(t.name=this.name,t.hasAlpha=this.hasAlpha,t.level=this.level,t.coordinatesIndex=this.coordinatesIndex,t.coordinatesMode=this.coordinatesMode,t.wrapU=this.wrapU,t.wrapV=this.wrapV,e.Animation.AppendSerializedAnimations(this,t),t):null},t}();e.BaseTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(i,n,s,o,a,h,c,l,u){void 0===a&&(a=r.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=null),void 0===c&&(c=null),void 0===l&&(l=null),void 0===u&&(u=!1),t.call(this,n),this.uOffset=0,this.vOffset=0,this.uScale=1,this.vScale=1,this.uAng=0,this.vAng=0,this.wAng=0,this.name=i,this.url=i,this._noMipmap=s,this._invertY=o,this._samplingMode=a,this._buffer=l,this._deleteBuffer=u,i&&(this._texture=this._getFromCache(i,s,a),this._texture?e.Tools.SetImmediate(function(){h&&h()}):n.useDelayedTextureLoading?this.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:(this._texture=n.getEngine().createTexture(i,s,o,n,this._samplingMode,h,c,this._buffer),u&&delete this._buffer))}return __extends(r,t),r.prototype.delayLoad=function(){this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap,this._samplingMode),this._texture||(this._texture=this.getScene().getEngine().createTexture(this.url,this._noMipmap,this._invertY,this.getScene(),this._samplingMode,null,null,this._buffer),this._deleteBuffer&&delete this._buffer))},r.prototype.updateSamplingMode=function(e){this._texture&&this.getScene().getEngine().updateTextureSamplingMode(e,this._texture)},r.prototype._prepareRowForTextureGeneration=function(t,r,i,n){t*=this.uScale,r*=this.vScale,t-=.5*this.uScale,r-=.5*this.vScale,i-=.5,e.Vector3.TransformCoordinatesFromFloatsToRef(t,r,i,this._rowGenerationMatrix,n),n.x+=.5*this.uScale+this.uOffset,n.y+=.5*this.vScale+this.vOffset,n.z+=.5},r.prototype.getTextureMatrix=function(){return this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.uAng===this._cachedUAng&&this.vAng===this._cachedVAng&&this.wAng===this._cachedWAng?this._cachedTextureMatrix:(this._cachedUOffset=this.uOffset,this._cachedVOffset=this.vOffset,this._cachedUScale=this.uScale,this._cachedVScale=this.vScale,this._cachedUAng=this.uAng,this._cachedVAng=this.vAng,this._cachedWAng=this.wAng,this._cachedTextureMatrix||(this._cachedTextureMatrix=e.Matrix.Zero(),this._rowGenerationMatrix=new e.Matrix,this._t0=e.Vector3.Zero(),this._t1=e.Vector3.Zero(),this._t2=e.Vector3.Zero()),e.Matrix.RotationYawPitchRollToRef(this.vAng,this.uAng,this.wAng,this._rowGenerationMatrix),this._prepareRowForTextureGeneration(0,0,0,this._t0),this._prepareRowForTextureGeneration(1,0,0,this._t1),this._prepareRowForTextureGeneration(0,1,0,this._t2),this._t1.subtractInPlace(this._t0),this._t2.subtractInPlace(this._t0),e.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix.m[0]=this._t1.x,this._cachedTextureMatrix.m[1]=this._t1.y,this._cachedTextureMatrix.m[2]=this._t1.z,this._cachedTextureMatrix.m[4]=this._t2.x,this._cachedTextureMatrix.m[5]=this._t2.y,this._cachedTextureMatrix.m[6]=this._t2.z,this._cachedTextureMatrix.m[8]=this._t0.x,this._cachedTextureMatrix.m[9]=this._t0.y,this._cachedTextureMatrix.m[10]=this._t0.z,this._cachedTextureMatrix)},r.prototype.getReflectionTextureMatrix=function(){if(this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.coordinatesMode===this._cachedCoordinatesMode)return this._cachedTextureMatrix;switch(this._cachedTextureMatrix||(this._cachedTextureMatrix=e.Matrix.Zero(),this._projectionModeMatrix=e.Matrix.Zero()),this._cachedCoordinatesMode=this.coordinatesMode,this.coordinatesMode){case r.PLANAR_MODE:e.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix[0]=this.uScale,this._cachedTextureMatrix[5]=this.vScale,this._cachedTextureMatrix[12]=this.uOffset,this._cachedTextureMatrix[13]=this.vOffset;break;case r.PROJECTION_MODE:e.Matrix.IdentityToRef(this._projectionModeMatrix),this._projectionModeMatrix.m[0]=.5,this._projectionModeMatrix.m[5]=-.5,this._projectionModeMatrix.m[10]=0,this._projectionModeMatrix.m[12]=.5,this._projectionModeMatrix.m[13]=.5,this._projectionModeMatrix.m[14]=1,this._projectionModeMatrix.m[15]=1,this.getScene().getProjectionMatrix().multiplyToRef(this._projectionModeMatrix,this._cachedTextureMatrix);break;default:e.Matrix.IdentityToRef(this._cachedTextureMatrix)}return this._cachedTextureMatrix},r.prototype.clone=function(){var e=new r(this._texture.url,this.getScene(),this._noMipmap,this._invertY,this._samplingMode);return e.hasAlpha=this.hasAlpha,e.level=this.level,e.wrapU=this.wrapU,e.wrapV=this.wrapV,e.coordinatesIndex=this.coordinatesIndex,e.coordinatesMode=this.coordinatesMode,e.uOffset=this.uOffset,e.vOffset=this.vOffset,e.uScale=this.uScale,e.vScale=this.vScale,e.uAng=this.uAng,e.vAng=this.vAng,e.wAng=this.wAng,e},r.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);return e.uOffset=this.uOffset,e.vOffset=this.vOffset,e.uScale=this.uScale,e.vScale=this.vScale,e.uAng=this.uAng,e.vAng=this.vAng,e.wAng=this.wAng,e},r.CreateFromBase64String=function(e,t,i,n,s,o,a,h){return void 0===o&&(o=r.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=null),void 0===h&&(h=null),new r("data:"+t,i,n,s,o,a,h,e)},r.Parse=function(t,i,n){if(t.isCube)return e.CubeTexture.Parse(t,i,n);if(!t.name&&!t.isRenderTarget)return null;var s;if(t.mirrorPlane?(s=new e.MirrorTexture(t.name,t.renderTargetSize,i),s._waitingRenderList=t.renderList,s.mirrorPlane=e.Plane.FromArray(t.mirrorPlane)):t.isRenderTarget?(s=new e.RenderTargetTexture(t.name,t.renderTargetSize,i), s._waitingRenderList=t.renderList):s=t.base64String?r.CreateFromBase64String(t.base64String,t.name,i):new r(n+t.name,i),s.name=t.name,s.hasAlpha=t.hasAlpha,s.getAlphaFromRGB=t.getAlphaFromRGB,s.level=t.level,s.coordinatesIndex=t.coordinatesIndex,s.coordinatesMode=t.coordinatesMode,s.uOffset=t.uOffset,s.vOffset=t.vOffset,s.uScale=t.uScale,s.vScale=t.vScale,s.uAng=t.uAng,s.vAng=t.vAng,s.wAng=t.wAng,s.wrapU=t.wrapU,s.wrapV=t.wrapV,t.animations)for(var o=0;ol;l++)this.renderToTarget(l,s,e,t),r.incrementRenderId();else this.renderToTarget(0,s,e,t);this.onAfterUnbind&&this.onAfterUnbind(),this.activeCamera&&this.activeCamera!==r.activeCamera&&r.setTransformMatrix(r.activeCamera.getViewMatrix(),r.activeCamera.getProjectionMatrix(!0)),r.resetCachedMaterial()}},r.prototype.renderToTarget=function(t,r,i,n){var s=this.getScene(),o=s.getEngine();i&&s.postProcessManager._prepareFrame(this._texture)||(this.isCube?o.bindFramebuffer(this._texture,t):o.bindFramebuffer(this._texture)),this.onBeforeRender&&this.onBeforeRender(t),this.onClear?this.onClear(o):o.clear(s.clearColor,!0,!0),this._doNotChangeAspectRatio||s.updateTransformMatrix(!0),this._renderingManager.render(this.customRenderFunction,r,this.renderParticles,this.renderSprites),i&&s.postProcessManager._finalizeFrame(!1,this._texture,t),this._doNotChangeAspectRatio||s.updateTransformMatrix(!0),this.onAfterRender&&this.onAfterRender(t),n&&e.Tools.DumpFramebuffer(this._size,this._size,o),this.isCube&&5!==t||(this.isCube&&5===t&&o.generateMipMapsForCubemap(this._texture),o.unBindFramebuffer(this._texture,this.isCube))},r.prototype.clone=function(){var e=this.getSize(),t=new r(this.name,e.width,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.coordinatesMode=this.coordinatesMode,t.renderList=this.renderList.slice(0),t},r.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);e.renderTargetSize=this.getRenderSize(),e.renderList=[];for(var r=0;rs;s++)r.bindFramebuffer(this._texture,s),this._effect.setFloat("face",s),r.clear(t.clearColor,!0,!0),r.draw(!0,0,6),5===s&&r.generateMipMapsForCubemap(this._texture);else r.bindFramebuffer(this._texture),r.clear(t.clearColor,!0,!0),r.draw(!0,0,6);r.unBindFramebuffer(this._texture,this.isCube),this.onGenerated&&this.onGenerated()},t.prototype.clone=function(){var e=this.getSize(),r=new t(this.name,e.width,this._fragment,this.getScene(),this._fallbackTexture,this._generateMipMaps);return r.hasAlpha=this.hasAlpha,r.level=this.level,r.coordinatesMode=this.coordinatesMode,r},t.prototype.dispose=function(){var t=this.getScene()._proceduralTextures.indexOf(this);t>=0&&this.getScene()._proceduralTextures.splice(t,1),e.prototype.dispose.call(this)},t}(e.Texture);e.ProceduralTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i,n,s){var o=this;t.call(this,r,i,n,s,!0),this.mirrorPlane=new e.Plane(0,1,0,1),this._transformMatrix=e.Matrix.Zero(),this._mirrorMatrix=e.Matrix.Zero(),this.onBeforeRender=function(){e.Matrix.ReflectionToRef(o.mirrorPlane,o._mirrorMatrix),o._savedViewMatrix=n.getViewMatrix(),o._mirrorMatrix.multiplyToRef(o._savedViewMatrix,o._transformMatrix),n.setTransformMatrix(o._transformMatrix,n.getProjectionMatrix()),n.clipPlane=o.mirrorPlane,n.getEngine().cullBackFaces=!1,n._mirroredCameraPosition=e.Vector3.TransformCoordinates(n.activeCamera.position,o._mirrorMatrix)},this.onAfterRender=function(){n.setTransformMatrix(o._savedViewMatrix,n.getProjectionMatrix()),n.getEngine().cullBackFaces=!0,n._mirroredCameraPosition=null,delete n.clipPlane}}return __extends(r,t),r.prototype.clone=function(){var e=this.getSize(),t=new r(this.name,e.width,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.mirrorPlane=this.mirrorPlane.clone(),t.renderList=this.renderList.slice(0),t},r.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);return e.mirrorPlane=this.mirrorPlane.asArray(),e},r}(e.RenderTargetTexture);e.MirrorTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i,n,s,o){void 0===o&&(o=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,n,!s),this.name=r,this.wrapU=e.Texture.CLAMP_ADDRESSMODE,this.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._generateMipMaps=s,i.getContext?(this._canvas=i,this._texture=n.getEngine().createDynamicTexture(i.width,i.height,s,o)):(this._canvas=document.createElement("canvas"),i.width?this._texture=n.getEngine().createDynamicTexture(i.width,i.height,s,o):this._texture=n.getEngine().createDynamicTexture(i,i,s,o));var a=this.getSize();this._canvas.width=a.width,this._canvas.height=a.height,this._context=this._canvas.getContext("2d")}return __extends(r,t),Object.defineProperty(r.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),r.prototype.scale=function(e){var t=this.getSize();t.width*=e,t.height*=e,this._canvas.width=t.width,this._canvas.height=t.height,this.releaseInternalTexture(),this._texture=this.getScene().getEngine().createDynamicTexture(t.width,t.height,this._generateMipMaps,this._samplingMode)},r.prototype.getContext=function(){return this._context},r.prototype.clear=function(){var e=this.getSize();this._context.fillRect(0,0,e.width,e.height)},r.prototype.update=function(e){this.getScene().getEngine().updateDynamicTexture(this._texture,this._canvas,void 0===e?!0:e)},r.prototype.drawText=function(e,t,r,i,n,s,o,a){void 0===a&&(a=!0);var h=this.getSize();if(s&&(this._context.fillStyle=s,this._context.fillRect(0,0,h.width,h.height)),this._context.font=i,null===t){var c=this._context.measureText(e);t=(h.width-c.width)/2}this._context.fillStyle=n,this._context.fillText(e,t,r),a&&this.update(o)},r.prototype.clone=function(){var e=this.getSize(),t=new r(this.name,e.width,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.wrapU=this.wrapU,t.wrapV=this.wrapV,t},r}(e.Texture);e.DynamicTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i,n,s,o,a){var h=this;void 0===s&&(s=!1),void 0===o&&(o=!1),void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,n,!s,o),this._autoLaunch=!0,this.name=r,this.video=document.createElement("video"),this.video.autoplay=!1,this.video.loop=!0,this.video.addEventListener("canplaythrough",function(){e.Tools.IsExponentOfTwo(h.video.videoWidth)&&e.Tools.IsExponentOfTwo(h.video.videoHeight)?(h.wrapU=e.Texture.WRAP_ADDRESSMODE,h.wrapV=e.Texture.WRAP_ADDRESSMODE):(h.wrapU=e.Texture.CLAMP_ADDRESSMODE,h.wrapV=e.Texture.CLAMP_ADDRESSMODE,s=!1),h._texture=n.getEngine().createDynamicTexture(h.video.videoWidth,h.video.videoHeight,s,a,!1),h._texture.isReady=!0}),i.forEach(function(e){var t=document.createElement("source");t.src=e,h.video.appendChild(t)}),this._lastUpdate=e.Tools.Now}return __extends(r,t),r.prototype.update=function(){this._autoLaunch&&(this._autoLaunch=!1,this.video.play());var t=e.Tools.Now;return t-this._lastUpdate<15||this.video.readyState!==this.video.HAVE_ENOUGH_DATA?!1:(this._lastUpdate=t,this.getScene().getEngine().updateVideoTexture(this._texture,this.video,this._invertY),!0)},r}(e.Texture);e.VideoTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(e,r,i,n,s,o){t.call(this,e,i,null,n,s,o),this._animate=!0,this._time=0,this._texturePath=r,this.loadJson(r),this.refreshRate=1}return __extends(r,t),r.prototype.loadJson=function(t){function r(){e.Tools.Log("No config file found in "+t+" trying to use ShadersStore or DOM element");try{n.setFragment(n._texturePath)}catch(r){e.Tools.Error("No json or ShaderStore or DOM element found for CustomProceduralTexture")}}var i=this,n=this,s=t+"/config.json",o=new XMLHttpRequest;o.open("GET",s,!0),o.addEventListener("load",function(){if(200===o.status||e.Tools.ValidateXHRData(o,1))try{i._config=JSON.parse(o.response),i.updateShaderUniforms(),i.updateTextures(),i.setFragment(i._texturePath+"/custom"),i._animate=i._config.animate,i.refreshRate=i._config.refreshrate}catch(t){r()}else r()},!1),o.addEventListener("error",function(){r()},!1);try{o.send()}catch(a){e.Tools.Error("CustomProceduralTexture: Error on XHR send request.")}},r.prototype.isReady=function(){if(!t.prototype.isReady.call(this))return!1;for(var e in this._textures){var r=this._textures[e];if(!r.isReady())return!1}return!0},r.prototype.render=function(e){this._animate&&(this._time+=.03*this.getScene().getAnimationRatio(),this.updateShaderUniforms()),t.prototype.render.call(this,e)},r.prototype.updateTextures=function(){for(var t=0;tthis._maxRank&&(this._maxRank=e),this._defines[e]=new Array),this._defines[e].push(t)},t.prototype.addCPUSkinningFallback=function(e,t){this._meshRank=e,this._mesh=t,e>this._maxRank&&(this._maxRank=e)},Object.defineProperty(t.prototype,"isMoreFallbacks",{get:function(){return this._currentRank<=this._maxRank},enumerable:!0,configurable:!0}),t.prototype.reduce=function(t){for(var r=this._defines[this._currentRank],i=0;i-1?r:e.Engine.ShadersRepository+r,e.Tools.LoadFile(s+".vertex.fx",i)},t.prototype._loadFragmentShader=function(r,i){if(r instanceof HTMLElement){var n=e.Tools.GetDOMTextContent(r);return void i(n)}if(t.ShadersStore[r+"PixelShader"])return void i(t.ShadersStore[r+"PixelShader"]);if(t.ShadersStore[r+"FragmentShader"])return void i(t.ShadersStore[r+"FragmentShader"]);var s;s="."===r[0]||"/"===r[0]||r.indexOf("http")>-1?r:e.Engine.ShadersRepository+r,e.Tools.LoadFile(s+".fragment.fx",i)},t.prototype._dumpShadersName=function(){this.name.vertexElement?(e.Tools.Error("Vertex shader:"+this.name.vertexElement),e.Tools.Error("Fragment shader:"+this.name.fragmentElement)):this.name.vertex?(e.Tools.Error("Vertex shader:"+this.name.vertex),e.Tools.Error("Fragment shader:"+this.name.fragment)):(e.Tools.Error("Vertex shader:"+this.name),e.Tools.Error("Fragment shader:"+this.name))},t.prototype._prepareEffect=function(t,r,i,n,s){try{var o=this._engine;o.getCaps().highPrecisionShaderSupported||(t=t.replace("precision highp float","precision mediump float"),r=r.replace("precision highp float","precision mediump float")),this._program=o.createShaderProgram(t,r,n),this._uniforms=o.getUniforms(this._program,this._uniformsNames),this._attributes=o.getAttributes(this._program,i);for(var a=0;ai;i++)this._valueCache[t].m[i]=r.m[i]},t.prototype._cacheFloat2=function(e,t,r){return this._valueCache[e]?(this._valueCache[e][0]=t,void(this._valueCache[e][1]=r)):void(this._valueCache[e]=[t,r])},t.prototype._cacheFloat3=function(e,t,r,i){return this._valueCache[e]?(this._valueCache[e][0]=t,this._valueCache[e][1]=r,void(this._valueCache[e][2]=i)):void(this._valueCache[e]=[t,r,i])},t.prototype._cacheFloat4=function(e,t,r,i,n){return this._valueCache[e]?(this._valueCache[e][0]=t,this._valueCache[e][1]=r,this._valueCache[e][2]=i,void(this._valueCache[e][3]=n)):void(this._valueCache[e]=[t,r,i,n])},t.prototype.setArray=function(e,t){return this._engine.setArray(this.getUniform(e),t),this},t.prototype.setArray2=function(e,t){return this._engine.setArray2(this.getUniform(e),t),this},t.prototype.setArray3=function(e,t){return this._engine.setArray3(this.getUniform(e),t),this},t.prototype.setArray4=function(e,t){return this._engine.setArray4(this.getUniform(e),t),this},t.prototype.setMatrices=function(e,t){return this._engine.setMatrices(this.getUniform(e),t),this},t.prototype.setMatrix=function(e,t){return this._engine.setMatrix(this.getUniform(e),t),this},t.prototype.setMatrix3x3=function(e,t){return this._engine.setMatrix3x3(this.getUniform(e),t),this},t.prototype.setMatrix2x2=function(e,t){return this._engine.setMatrix2x2(this.getUniform(e),t),this},t.prototype.setFloat=function(e,t){return this._valueCache[e]&&this._valueCache[e]===t?this:(this._valueCache[e]=t,this._engine.setFloat(this.getUniform(e),t),this)},t.prototype.setBool=function(e,t){return this._valueCache[e]&&this._valueCache[e]===t?this:(this._valueCache[e]=t,this._engine.setBool(this.getUniform(e),t?1:0),this)},t.prototype.setVector2=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.x&&this._valueCache[e][1]===t.y?this:(this._cacheFloat2(e,t.x,t.y),this._engine.setFloat2(this.getUniform(e),t.x,t.y),this)},t.prototype.setFloat2=function(e,t,r){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===r?this:(this._cacheFloat2(e,t,r),this._engine.setFloat2(this.getUniform(e),t,r),this)},t.prototype.setVector3=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.x&&this._valueCache[e][1]===t.y&&this._valueCache[e][2]===t.z?this:(this._cacheFloat3(e,t.x,t.y,t.z),this._engine.setFloat3(this.getUniform(e),t.x,t.y,t.z),this)},t.prototype.setFloat3=function(e,t,r,i){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===r&&this._valueCache[e][2]===i?this:(this._cacheFloat3(e,t,r,i),this._engine.setFloat3(this.getUniform(e),t,r,i),this)},t.prototype.setVector4=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.x&&this._valueCache[e][1]===t.y&&this._valueCache[e][2]===t.z&&this._valueCache[e][3]===t.w?this:(this._cacheFloat4(e,t.x,t.y,t.z,t.w),this._engine.setFloat4(this.getUniform(e),t.x,t.y,t.z,t.w),this)},t.prototype.setFloat4=function(e,t,r,i,n){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===r&&this._valueCache[e][2]===i&&this._valueCache[e][3]===n?this:(this._cacheFloat4(e,t,r,i,n),this._engine.setFloat4(this.getUniform(e),t,r,i,n),this)},t.prototype.setColor3=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.r&&this._valueCache[e][1]===t.g&&this._valueCache[e][2]===t.b?this:(this._cacheFloat3(e,t.r,t.g,t.b),this._engine.setColor3(this.getUniform(e),t),this)},t.prototype.setColor4=function(e,t,r){return this._valueCache[e]&&this._valueCache[e][0]===t.r&&this._valueCache[e][1]===t.g&&this._valueCache[e][2]===t.b&&this._valueCache[e][3]===r?this:(this._cacheFloat4(e,t.r,t.g,t.b,r),this._engine.setColor4(this.getUniform(e),t,r),this)},t.ShadersStore={},t}();e.Effect=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){}return e.prototype.isEqual=function(e){for(var t=0;t=0&&this._scene.materials.splice(t,1),e&&this._effect&&(this._scene.getEngine()._releaseEffect(this._effect),this._effect=null),t=0;t0){for(var c=0;c0){for(var u=0;u0&&(this._defines.ROUGHNESS=!0),this.reflectionTexture.coordinatesMode===e.Texture.INVCUBIC_MODE&&(this._defines.INVERTCUBICMAP=!0),this._defines.REFLECTIONMAP_3D=this.reflectionTexture.isCube,this.reflectionTexture.coordinatesMode){case e.Texture.CUBIC_MODE:case e.Texture.INVCUBIC_MODE:this._defines.REFLECTIONMAP_CUBIC=!0;break;case e.Texture.EXPLICIT_MODE:this._defines.REFLECTIONMAP_EXPLICIT=!0;break;case e.Texture.PLANAR_MODE:this._defines.REFLECTIONMAP_PLANAR=!0;break;case e.Texture.PROJECTION_MODE:this._defines.REFLECTIONMAP_PROJECTION=!0;break;case e.Texture.SKYBOX_MODE:this._defines.REFLECTIONMAP_SKYBOX=!0;break;case e.Texture.SPHERICAL_MODE:this._defines.REFLECTIONMAP_SPHERICAL=!0;break;case e.Texture.EQUIRECTANGULAR_MODE:this._defines.REFLECTIONMAP_EQUIRECTANGULAR=!0;break;case e.Texture.FIXED_EQUIRECTANGULAR_MODE:this._defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!0}}if(this.emissiveTexture&&s.EmissiveTextureEnabled){if(!this.emissiveTexture.isReady())return!1;c=!0,this._defines.EMISSIVE=!0}if(this.lightmapTexture&&s.LightmapEnabled){if(!this.lightmapTexture.isReady())return!1;c=!0,this._defines.LIGHTMAP=!0,this._defines.USELIGHTMAPASSHADOWMAP=this.useLightmapAsShadowmap}if(this.specularTexture&&s.SpecularTextureEnabled){if(!this.specularTexture.isReady())return!1;c=!0,this._defines.SPECULAR=!0,this._defines.GLOSSINESS=this.useGlossinessFromSpecularMapAlpha}}if(o.getEngine().getCaps().standardDerivatives&&this.bumpTexture&&s.BumpTextureEnabled){if(!this.bumpTexture.isReady())return!1;c=!0,this._defines.BUMP=!0}if(o.clipPlane&&(this._defines.CLIPPLANE=!0),a.getAlphaTesting()&&(this._defines.ALPHATEST=!0),this._shouldUseAlphaFromDiffuseTexture()&&(this._defines.ALPHAFROMDIFFUSE=!0),this.useEmissiveAsIllumination&&(this._defines.EMISSIVEASILLUMINATION=!0),this.linkEmissiveWithDiffuse&&(this._defines.LINKEMISSIVEWITHDIFFUSE=!0),this.useReflectionFresnelFromSpecular&&(this._defines.REFLECTIONFRESNELFROMSPECULAR=!0),this.useLogarithmicDepth&&(this._defines.LOGARITHMICDEPTH=!0),(this.pointsCloud||o.forcePointsCloud)&&(this._defines.POINTSIZE=!0),o.fogEnabled&&r&&r.applyFog&&o.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(this._defines.FOG=!0),o.lightsEnabled&&!this.disableLighting&&(h=s.PrepareDefinesForLights(o,r,this._defines)),s.FresnelEnabled&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled||this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled||this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled)&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(this._defines.DIFFUSEFRESNEL=!0),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&(this._defines.OPACITYFRESNEL=!0),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(this._defines.REFLECTIONFRESNEL=!0),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._defines.EMISSIVEFRESNEL=!0),h=!0,this._defines.FRESNEL=!0),this._defines.SPECULARTERM&&this.useSpecularOverAlpha&&(this._defines.SPECULAROVERALPHA=!0),r&&(h&&r.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(this._defines.NORMAL=!0),c&&(r.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(this._defines.UV1=!0),r.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(this._defines.UV2=!0)),r.useVertexColors&&r.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(this._defines.VERTEXCOLOR=!0,r.hasVertexAlpha&&(this._defines.VERTEXALPHA=!0)),r.useBones&&r.computeBonesUsingShaders&&(this._defines.NUM_BONE_INFLUENCERS=r.numBoneInfluencers,this._defines.BonesPerMesh=r.skeleton.bones.length+1),n&&(this._defines.INSTANCES=!0)),!this._defines.isEqual(this._cachedDefines)){this._defines.cloneTo(this._cachedDefines),o.resetCachedMaterial();var l=new e.EffectFallbacks;this._defines.REFLECTION&&l.addFallback(0,"REFLECTION"),this._defines.SPECULAR&&l.addFallback(0,"SPECULAR"),this._defines.BUMP&&l.addFallback(0,"BUMP"),this._defines.SPECULAROVERALPHA&&l.addFallback(0,"SPECULAROVERALPHA"),this._defines.FOG&&l.addFallback(1,"FOG"),this._defines.POINTSIZE&&l.addFallback(0,"POINTSIZE"),this._defines.LOGARITHMICDEPTH&&l.addFallback(0,"LOGARITHMICDEPTH");for(var u=0;t>u;u++)this._defines["LIGHT"+u]&&(u>0&&l.addFallback(u,"LIGHT"+u),this._defines["SHADOW"+u]&&l.addFallback(0,"SHADOW"+u),this._defines["SHADOWPCF"+u]&&l.addFallback(0,"SHADOWPCF"+u),this._defines["SHADOWVSM"+u]&&l.addFallback(0,"SHADOWVSM"+u));this._defines.SPECULARTERM&&l.addFallback(0,"SPECULARTERM"),this._defines.DIFFUSEFRESNEL&&l.addFallback(1,"DIFFUSEFRESNEL"),this._defines.OPACITYFRESNEL&&l.addFallback(2,"OPACITYFRESNEL"),this._defines.REFLECTIONFRESNEL&&l.addFallback(3,"REFLECTIONFRESNEL"),this._defines.EMISSIVEFRESNEL&&l.addFallback(4,"EMISSIVEFRESNEL"),this._defines.FRESNEL&&l.addFallback(4,"FRESNEL"),this._defines.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,r);var f=[e.VertexBuffer.PositionKind];this._defines.NORMAL&&f.push(e.VertexBuffer.NormalKind),this._defines.UV1&&f.push(e.VertexBuffer.UVKind),this._defines.UV2&&f.push(e.VertexBuffer.UV2Kind),this._defines.VERTEXCOLOR&&f.push(e.VertexBuffer.ColorKind),this._defines.NUM_BONE_INFLUENCERS>0&&(f.push(e.VertexBuffer.MatricesIndicesKind),f.push(e.VertexBuffer.MatricesWeightsKind),this._defines.NUM_BONE_INFLUENCERS>4&&(f.push(e.VertexBuffer.MatricesIndicesExtraKind),f.push(e.VertexBuffer.MatricesWeightsExtraKind))),this._defines.INSTANCES&&(f.push("world0"),f.push("world1"),f.push("world2"),f.push("world3"));var d="default";o.getEngine().getCaps().standardDerivatives||(d="legacydefault");var p=this._defines.toString();this._effect=o.getEngine().createEffect(d,f,["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","vLightmapInfos","mBones","vClipPlane","diffuseMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","specularMatrix","bumpMatrix","lightmapMatrix","shadowsInfo0","shadowsInfo1","shadowsInfo2","shadowsInfo3","depthValues","diffuseLeftColor","diffuseRightColor","opacityParts","reflectionLeftColor","reflectionRightColor","emissiveLeftColor","emissiveRightColor","logarithmicDepthConstant"],["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","lightmapSampler","shadowSampler0","shadowSampler1","shadowSampler2","shadowSampler3"],p,l,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=o.getRenderId(),this._wasPreviouslyReady=!0,r&&(r._materialDefines||(r._materialDefines=new i),this._defines.cloneTo(r._materialDefines)),!0):!1},s.prototype.unbind=function(){this.reflectionTexture&&this.reflectionTexture.isRenderTarget&&this._effect.setTexture("reflection2DSampler",null),n.prototype.unbind.call(this)},s.prototype.bindOnlyWorldMatrix=function(e){this._effect.setMatrix("world",e)},s.prototype.bind=function(t,r){var i=this.getScene();if(this.bindOnlyWorldMatrix(t),r&&r.useBones&&r.computeBonesUsingShaders&&this._effect.setMatrices("mBones",r.skeleton.getTransformMatrices(r)),i.getCachedMaterial()!==this){if(this._effect.setMatrix("viewProjection",i.getTransformMatrix()),s.FresnelEnabled&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(this._effect.setColor4("diffuseLeftColor",this.diffuseFresnelParameters.leftColor,this.diffuseFresnelParameters.power),this._effect.setColor4("diffuseRightColor",this.diffuseFresnelParameters.rightColor,this.diffuseFresnelParameters.bias)),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&this._effect.setColor4("opacityParts",new e.Color3(this.opacityFresnelParameters.leftColor.toLuminance(),this.opacityFresnelParameters.rightColor.toLuminance(),this.opacityFresnelParameters.bias),this.opacityFresnelParameters.power),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(this._effect.setColor4("reflectionLeftColor",this.reflectionFresnelParameters.leftColor,this.reflectionFresnelParameters.power),this._effect.setColor4("reflectionRightColor",this.reflectionFresnelParameters.rightColor,this.reflectionFresnelParameters.bias)),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._effect.setColor4("emissiveLeftColor",this.emissiveFresnelParameters.leftColor,this.emissiveFresnelParameters.power),this._effect.setColor4("emissiveRightColor",this.emissiveFresnelParameters.rightColor,this.emissiveFresnelParameters.bias))),i.texturesEnabled&&(this.diffuseTexture&&s.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&&s.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&&s.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&&s.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.setFloat2("vReflectionInfos",this.reflectionTexture.level,this.roughness)),this.emissiveTexture&&s.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.lightmapTexture&&s.LightmapEnabled&&(this._effect.setTexture("lightmapSampler",this.lightmapTexture),this._effect.setFloat2("vLightmapInfos",this.lightmapTexture.coordinatesIndex,this.lightmapTexture.level),this._effect.setMatrix("lightmapMatrix",this.lightmapTexture.getTextureMatrix())),this.specularTexture&&s.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&&i.getEngine().getCaps().standardDerivatives&&s.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()))),i.clipPlane){var o=i.clipPlane;this._effect.setFloat4("vClipPlane",o.normal.x,o.normal.y,o.normal.z,o.d)}this.pointsCloud&&this._effect.setFloat("pointSize",this.pointSize),i.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor),this._effect.setVector3("vEyePosition",i._mirroredCameraPosition?i._mirroredCameraPosition:i.activeCamera.position),this._effect.setColor3("vAmbientColor",this._globalAmbientColor),this._defines.SPECULARTERM&&this._effect.setColor4("vSpecularColor",this.specularColor,this.specularPower),this._effect.setColor3("vEmissiveColor",this.emissiveColor)}i.getCachedMaterial()===this&&this.isFrozen||(this._effect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*r.visibility),i.lightsEnabled&&!this.disableLighting&&s.BindLights(i,r,this._effect,this._defines),(i.fogEnabled&&r.applyFog&&i.fogMode!==e.Scene.FOGMODE_NONE||this.reflectionTexture)&&this._effect.setMatrix("view",i.getViewMatrix()),i.fogEnabled&&r.applyFog&&i.fogMode!==e.Scene.FOGMODE_NONE&&(this._effect.setFloat4("vFogInfos",i.fogMode,i.fogStart,i.fogEnd,i.fogDensity),this._effect.setColor3("vFogColor",i.fogColor)),this._defines.LOGARITHMICDEPTH&&this._effect.setFloat("logarithmicDepthConstant",2/(Math.log(i.activeCamera.maxZ+1)/Math.LN2))),n.prototype.bind.call(this,t,r)},s.prototype.getAnimatables=function(){var e=[];return this.diffuseTexture&&this.diffuseTexture.animations&&this.diffuseTexture.animations.length>0&&e.push(this.diffuseTexture),this.ambientTexture&&this.ambientTexture.animations&&this.ambientTexture.animations.length>0&&e.push(this.ambientTexture),this.opacityTexture&&this.opacityTexture.animations&&this.opacityTexture.animations.length>0&&e.push(this.opacityTexture),this.reflectionTexture&&this.reflectionTexture.animations&&this.reflectionTexture.animations.length>0&&e.push(this.reflectionTexture),this.emissiveTexture&&this.emissiveTexture.animations&&this.emissiveTexture.animations.length>0&&e.push(this.emissiveTexture),this.specularTexture&&this.specularTexture.animations&&this.specularTexture.animations.length>0&&e.push(this.specularTexture),this.bumpTexture&&this.bumpTexture.animations&&this.bumpTexture.animations.length>0&&e.push(this.bumpTexture),e},s.prototype.dispose=function(e){this.diffuseTexture&&this.diffuseTexture.dispose(),this.ambientTexture&&this.ambientTexture.dispose(),this.opacityTexture&&this.opacityTexture.dispose(),this.reflectionTexture&&this.reflectionTexture.dispose(),this.emissiveTexture&&this.emissiveTexture.dispose(),this.specularTexture&&this.specularTexture.dispose(),this.bumpTexture&&this.bumpTexture.dispose(),n.prototype.dispose.call(this,e)},s.prototype.clone=function(e){var t=new s(e,this.getScene());return this.copyTo(t),this.diffuseTexture&&this.diffuseTexture.clone&&(t.diffuseTexture=this.diffuseTexture.clone()),this.ambientTexture&&this.ambientTexture.clone&&(t.ambientTexture=this.ambientTexture.clone()),this.opacityTexture&&this.opacityTexture.clone&&(t.opacityTexture=this.opacityTexture.clone()),this.reflectionTexture&&this.reflectionTexture.clone&&(t.reflectionTexture=this.reflectionTexture.clone()),this.emissiveTexture&&this.emissiveTexture.clone&&(t.emissiveTexture=this.emissiveTexture.clone()),this.specularTexture&&this.specularTexture.clone&&(t.specularTexture=this.specularTexture.clone()),this.bumpTexture&&this.bumpTexture.clone&&(t.bumpTexture=this.bumpTexture.clone()),this.lightmapTexture&&this.lightmapTexture.clone&&(t.lightmapTexture=this.lightmapTexture.clone(),t.useLightmapAsShadowmap=this.useLightmapAsShadowmap),t.ambientColor=this.ambientColor.clone(),t.diffuseColor=this.diffuseColor.clone(),t.specularColor=this.specularColor.clone(),t.specularPower=this.specularPower,t.emissiveColor=this.emissiveColor.clone(),t.useAlphaFromDiffuseTexture=this.useAlphaFromDiffuseTexture,t.useEmissiveAsIllumination=this.useEmissiveAsIllumination,t.useGlossinessFromSpecularMapAlpha=this.useGlossinessFromSpecularMapAlpha,t.useReflectionFresnelFromSpecular=this.useReflectionFresnelFromSpecular,t.useSpecularOverAlpha=this.useSpecularOverAlpha,t.roughness=this.roughness,this.diffuseFresnelParameters&&this.diffuseFresnelParameters.clone&&(t.diffuseFresnelParameters=this.diffuseFresnelParameters.clone()),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.clone&&(t.emissiveFresnelParameters=this.emissiveFresnelParameters.clone()),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.clone&&(t.reflectionFresnelParameters=this.reflectionFresnelParameters.clone()),this.opacityFresnelParameters&&this.opacityFresnelParameters.clone&&(t.opacityFresnelParameters=this.opacityFresnelParameters.clone()),t},s.prototype.serialize=function(){var e=n.prototype.serialize.call(this);return e.ambient=this.ambientColor.asArray(),e.diffuse=this.diffuseColor.asArray(),e.specular=this.specularColor.asArray(),e.specularPower=this.specularPower,e.emissive=this.emissiveColor.asArray(),e.useReflectionFresnelFromSpecular=e.useReflectionFresnelFromSpecular,e.useEmissiveAsIllumination=e.useEmissiveAsIllumination,this.diffuseTexture&&(e.diffuseTexture=this.diffuseTexture.serialize()),this.diffuseFresnelParameters&&(e.diffuseFresnelParameters=this.diffuseFresnelParameters.serialize()),this.ambientTexture&&(e.ambientTexture=this.ambientTexture.serialize()),this.opacityTexture&&(e.opacityTexture=this.opacityTexture.serialize()),this.opacityFresnelParameters&&(e.opacityFresnelParameters=this.diffuseFresnelParameters.serialize()),this.reflectionTexture&&(e.reflectionTexture=this.reflectionTexture.serialize()),this.reflectionFresnelParameters&&(e.reflectionFresnelParameters=this.reflectionFresnelParameters.serialize()),this.emissiveTexture&&(e.emissiveTexture=this.emissiveTexture.serialize()),this.lightmapTexture&&(e.lightmapTexture=this.lightmapTexture.serialize(),e.useLightmapAsShadowmap=this.useLightmapAsShadowmap),this.emissiveFresnelParameters&&(e.emissiveFresnelParameters=this.emissiveFresnelParameters.serialize()),this.specularTexture&&(e.specularTexture=this.specularTexture.serialize()),this.bumpTexture&&(e.bumpTexture=this.bumpTexture.serialize()),e},s.Parse=function(t,i,n){var o=new s(t.name,i);return o.ambientColor=e.Color3.FromArray(t.ambient),o.diffuseColor=e.Color3.FromArray(t.diffuse),o.specularColor=e.Color3.FromArray(t.specular),o.specularPower=t.specularPower,o.emissiveColor=e.Color3.FromArray(t.emissive),o.useReflectionFresnelFromSpecular=t.useReflectionFresnelFromSpecular,o.useEmissiveAsIllumination=t.useEmissiveAsIllumination,o.alpha=t.alpha,o.id=t.id,t.disableDepthWrite&&(o.disableDepthWrite=t.disableDepthWrite),e.Tags.AddTagsTo(o,t.tags),o.backFaceCulling=t.backFaceCulling,o.wireframe=t.wireframe,t.diffuseTexture&&(o.diffuseTexture=e.Texture.Parse(t.diffuseTexture,i,n)),t.diffuseFresnelParameters&&(o.diffuseFresnelParameters=r.Parse(t.diffuseFresnelParameters)),t.ambientTexture&&(o.ambientTexture=e.Texture.Parse(t.ambientTexture,i,n)),t.opacityTexture&&(o.opacityTexture=e.Texture.Parse(t.opacityTexture,i,n)),t.opacityFresnelParameters&&(o.opacityFresnelParameters=r.Parse(t.opacityFresnelParameters)),t.reflectionTexture&&(o.reflectionTexture=e.Texture.Parse(t.reflectionTexture,i,n)),t.reflectionFresnelParameters&&(o.reflectionFresnelParameters=r.Parse(t.reflectionFresnelParameters)),t.emissiveTexture&&(o.emissiveTexture=e.Texture.Parse(t.emissiveTexture,i,n)),t.lightmapTexture&&(o.lightmapTexture=e.Texture.Parse(t.lightmapTexture,i,n),o.useLightmapAsShadowmap=t.useLightmapAsShadowmap),t.emissiveFresnelParameters&&(o.emissiveFresnelParameters=r.Parse(t.emissiveFresnelParameters)),t.specularTexture&&(o.specularTexture=e.Texture.Parse(t.specularTexture,i,n)),t.bumpTexture&&(o.bumpTexture=e.Texture.Parse(t.bumpTexture,i,n)),t.checkReadyOnlyOnce&&(o.checkReadyOnlyOnce=t.checkReadyOnlyOnce),o},s._scaledDiffuse=new e.Color3,s._scaledSpecular=new e.Color3,s.DiffuseTextureEnabled=!0,s.AmbientTextureEnabled=!0,s.OpacityTextureEnabled=!0,s.ReflectionTextureEnabled=!0,s.EmissiveTextureEnabled=!0,s.SpecularTextureEnabled=!0,s.BumpTextureEnabled=!0,s.FresnelEnabled=!0,s.LightmapEnabled=!0,s}(e.Material);e.StandardMaterial=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(e,r){t.call(this,e,r,!0),this.subMaterials=new Array,r.multiMaterials.push(this)}return __extends(r,t),r.prototype.getSubMaterial=function(e){return 0>e||e>=this.subMaterials.length?this.getScene().defaultMaterial:this.subMaterials[e]},r.prototype.isReady=function(e){for(var t=0;ts;s++){var a=r.materials[s];if(a.id===t)return e.Material.Parse(a,i,n)}return null},i=function(e,t,r){t=t instanceof Array?t:[t];for(var i in t)if(e.name===t[i])return r.push(e.id),!0;return e.parentId&&-1!==r.indexOf(e.parentId)?(r.push(e.id),!0):!1};e.SceneLoader.RegisterPlugin({extensions:".babylon",importMesh:function(t,n,s,o,a,h,c){var l,u,f=JSON.parse(s),d=[],p=[],m=[];for(l=0,u=f.meshes.length;u>l;l++){var g=f.meshes[l];if(!t||i(g,t,m)){if(t instanceof Array&&delete t[t.indexOf(g.name)],g.geometryId&&f.geometries){var _=!1;["boxes","spheres","cylinders","toruses","grounds","planes","torusKnots","vertexData"].forEach(function(t){!_&&f.geometries[t]&&f.geometries[t]instanceof Array&&f.geometries[t].forEach(function(r){if(r.id===g.geometryId){switch(t){case"boxes":e.Geometry.Primitives.Box.Parse(r,n);break;case"spheres":e.Geometry.Primitives.Sphere.Parse(r,n);break;case"cylinders":e.Geometry.Primitives.Cylinder.Parse(r,n);break;case"toruses":e.Geometry.Primitives.Torus.Parse(r,n);break;case"grounds":e.Geometry.Primitives.Ground.Parse(r,n);break;case"planes":e.Geometry.Primitives.Plane.Parse(r,n);break;case"torusKnots":e.Geometry.Primitives.TorusKnot.Parse(r,n);break;case"vertexData":e.Geometry.Parse(r,n,o)}_=!0}})}),_||e.Tools.Warn("Geometry not found for mesh "+g.id)}if(g.materialId){var v=-1!==p.indexOf(g.materialId);if(!v&&f.multiMaterials)for(var y=0,x=f.multiMaterials.length;x>y;y++){var E=f.multiMaterials[y];if(E.id===g.materialId){for(var T=0,A=E.materials.length;A>T;T++){var b=E.materials[T];p.push(b),r(b,f,n,o)}p.push(E.id),e.Material.ParseMultiMaterial(E,n),v=!0;break}}v||(p.push(g.materialId),r(g.materialId,f,n,o)||e.Tools.Warn("Material not found for mesh "+g.id))}if(g.skeletonId>-1&&n.skeletons){var M=d.indexOf(g.skeletonId)>-1;if(!M)for(var P=0,S=f.skeletons.length;S>P;P++){var C=f.skeletons[P];C.id===g.skeletonId&&(c.push(e.Skeleton.Parse(C,n)),d.push(C.id))}}var I=e.Mesh.Parse(g,n,o);a.push(I)}}var D;for(l=0,u=n.meshes.length;u>l;l++)D=n.meshes[l],D._waitingParentId&&(D.parent=n.getLastEntryByID(D._waitingParentId),D._waitingParentId=void 0);for(l=0,u=n.meshes.length;u>l;l++)D=n.meshes[l],D._waitingFreezeWorldMatrix?(D.freezeWorldMatrix(),D._waitingFreezeWorldMatrix=void 0):D.computeWorldMatrix(!0);if(f.particleSystems)for(l=0,u=f.particleSystems.length;u>l;l++){var R=f.particleSystems[l];-1!==m.indexOf(R.emitterId)&&h.push(e.ParticleSystem.Parse(R,n,o))}return!0},load:function(t,r,i){var n=JSON.parse(r);if(t.useDelayedTextureLoading=n.useDelayedTextureLoading&&!e.SceneLoader.ForceFullSceneLoadingForIncremental,t.autoClear=n.autoClear,t.clearColor=e.Color3.FromArray(n.clearColor),t.ambientColor=e.Color3.FromArray(n.ambientColor),n.gravity&&(t.gravity=e.Vector3.FromArray(n.gravity)),n.fogMode&&0!==n.fogMode&&(t.fogMode=n.fogMode,t.fogColor=e.Color3.FromArray(n.fogColor),t.fogStart=n.fogStart,t.fogEnd=n.fogEnd,t.fogDensity=n.fogDensity),n.physicsEnabled){var s;"cannon"===n.physicsEngine?s=new e.CannonJSPlugin:"oimo"===n.physicsEngine&&(s=new e.OimoJSPlugin);var o=n.physicsGravity?e.Vector3.FromArray(n.physicsGravity):null;t.enablePhysics(o,s)}void 0!=n.collisionsEnabled&&(t.collisionsEnabled=n.collisionsEnabled),t.workerCollisions=!!n.workerCollisions;var a,h;for(a=0,h=n.lights.length;h>a;a++){var c=n.lights[a];e.Light.Parse(c,t)}if(n.materials)for(a=0,h=n.materials.length;h>a;a++){var l=n.materials[a];e.Material.Parse(l,t,i)}if(n.multiMaterials)for(a=0,h=n.multiMaterials.length;h>a;a++){var u=n.multiMaterials[a];e.Material.ParseMultiMaterial(u,t)}if(n.skeletons)for(a=0,h=n.skeletons.length;h>a;a++){var f=n.skeletons[a];e.Skeleton.Parse(f,t)}var d=n.geometries;if(d){var p=d.boxes;if(p)for(a=0,h=p.length;h>a;a++){var m=p[a];e.Geometry.Primitives.Box.Parse(m,t)}var g=d.spheres;if(g)for(a=0,h=g.length;h>a;a++){var _=g[a];e.Geometry.Primitives.Sphere.Parse(_,t)}var v=d.cylinders;if(v)for(a=0,h=v.length;h>a;a++){var y=v[a];e.Geometry.Primitives.Cylinder.Parse(y,t)}var x=d.toruses;if(x)for(a=0,h=x.length;h>a;a++){var E=x[a];e.Geometry.Primitives.Torus.Parse(E,t)}var T=d.grounds;if(T)for(a=0,h=T.length;h>a;a++){var A=T[a];e.Geometry.Primitives.Ground.Parse(A,t)}var b=d.planes;if(b)for(a=0,h=b.length;h>a;a++){var M=b[a];e.Geometry.Primitives.Plane.Parse(M,t)}var P=d.torusKnots;if(P)for(a=0,h=P.length;h>a;a++){var S=P[a];e.Geometry.Primitives.TorusKnot.Parse(S,t)}var C=d.vertexData;if(C)for(a=0,h=C.length;h>a;a++){var I=C[a];e.Geometry.Parse(I,t,i)}}for(a=0,h=n.meshes.length;h>a;a++){var D=n.meshes[a];e.Mesh.Parse(D,t,i)}for(a=0,h=n.cameras.length;h>a;a++){var R=n.cameras[a];e.Camera.Parse(R,t)}for(n.activeCameraID&&t.setActiveCameraByID(n.activeCameraID),a=0,h=t.cameras.length;h>a;a++){var w=t.cameras[a];w._waitingParentId&&(w.parent=t.getLastEntryByID(w._waitingParentId),w._waitingParentId=void 0)}for(a=0,h=t.lights.length;h>a;a++){var L=t.lights[a];L._waitingParentId&&(L.parent=t.getLastEntryByID(L._waitingParentId),L._waitingParentId=void 0)}var O,B=[];if(e.AudioEngine&&n.sounds)for(a=0,h=n.sounds.length;h>a;a++){var F=n.sounds[a];if(e.Engine.audioEngine.canUseWebAudio)F.url||(F.url=F.name),B[F.url]?e.Sound.Parse(F,t,i,B[F.url]):(O=e.Sound.Parse(F,t,i),B[F.url]=O);else{new e.Sound(F.name,null,t)}}for(B=[],a=0,h=t.meshes.length;h>a;a++){var V=t.meshes[a];V._waitingParentId&&(V.parent=t.getLastEntryByID(V._waitingParentId),V._waitingParentId=void 0),V._waitingActions&&(e.ActionManager.Parse(V._waitingActions,V,t),V._waitingActions=void 0)}for(a=0,h=t.meshes.length;h>a;a++){var N=t.meshes[a];N._waitingFreezeWorldMatrix?(N.freezeWorldMatrix(),N._waitingFreezeWorldMatrix=void 0):N.computeWorldMatrix(!0)}if(n.particleSystems)for(a=0,h=n.particleSystems.length;h>a;a++){var U=n.particleSystems[a];e.ParticleSystem.Parse(U,t,i)}if(n.lensFlareSystems)for(a=0,h=n.lensFlareSystems.length;h>a;a++){var k=n.lensFlareSystems[a];e.LensFlareSystem.Parse(k,t,i)}if(n.shadowGenerators)for(a=0,h=n.shadowGenerators.length;h>a;a++){var z=n.shadowGenerators[a];e.ShadowGenerator.Parse(z,t)}return n.actions&&e.ActionManager.Parse(n.actions,null,t),!0}})}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r,i,n,s,o,a){void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE),this.name=t,this.cellSize=n,this.sprites=new Array,this.renderingGroupId=0,this.layerMask=268435455,this.fogEnabled=!0,this.isPickable=!1,this._vertexDeclaration=[4,4,4,4],this._vertexStrideSize=64,this._capacity=i,this._spriteTexture=new e.Texture(r,s,!0,!1,a),this._spriteTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._spriteTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._epsilon=void 0===o?.01:o,this._scene=s,this._scene.spriteManagers.push(this),this._vertexBuffer=s.getEngine().createDynamicVertexBuffer(i*this._vertexStrideSize*4);for(var h=[],c=0,l=0;i>l;l++)h.push(c),h.push(c+1),h.push(c+2),h.push(c),h.push(c+2),h.push(c+3),c+=4;this._indexBuffer=s.getEngine().createIndexBuffer(h),this._vertices=new Float32Array(i*this._vertexStrideSize),this._effectBase=this._scene.getEngine().createEffect("sprites",["position","options","cellInfo","color"],["view","projection","textureInfos","alphaTest"],["diffuseSampler"],""),this._effectFog=this._scene.getEngine().createEffect("sprites",["position","options","cellInfo","color"],["view","projection","textureInfos","alphaTest","vFogInfos","vFogColor"],["diffuseSampler"],"#define FOG")}return t.prototype._appendSpriteVertex=function(e,t,r,i,n){var s=16*e;0===r?r=this._epsilon:1===r&&(r=1-this._epsilon),0===i?i=this._epsilon:1===i&&(i=1-this._epsilon),this._vertices[s]=t.position.x,this._vertices[s+1]=t.position.y,this._vertices[s+2]=t.position.z,this._vertices[s+3]=t.angle,this._vertices[s+4]=t.width,this._vertices[s+5]=t.height,this._vertices[s+6]=r,this._vertices[s+7]=i,this._vertices[s+8]=t.invertU?1:0,this._vertices[s+9]=t.invertV?1:0;var o=t.cellIndex/n>>0;this._vertices[s+10]=t.cellIndex-o*n,this._vertices[s+11]=o,this._vertices[s+12]=t.color.r,this._vertices[s+13]=t.color.g,this._vertices[s+14]=t.color.b,this._vertices[s+15]=t.color.a},t.prototype.intersects=function(t,r,i,n){for(var s,o=Math.min(this._capacity,this.sprites.length),a=e.Vector3.Zero(),h=e.Vector3.Zero(),c=Number.MAX_VALUE,l=e.Vector3.Zero(),u=r.getViewMatrix(),f=0;o>f;f++){var d=this.sprites[f];if(d){if(i){if(!i(d))continue}else if(!d.isPickable)continue;if(e.Vector3.TransformCoordinatesToRef(d.position,u,l),a.copyFromFloats(l.x-d.width/2,l.y-d.height/2,l.z),h.copyFromFloats(l.x+d.width/2,l.y+d.height/2,l.z),t.intersectsBoxMinMax(a,h)){var p=e.Vector3.Distance(l,t.origin);if(c>p&&(c=p,s=d,n))break}}}if(s){var m=new e.PickingInfo;return m.hit=!0,m.pickedSprite=s,m.distance=c,m}return null},t.prototype.render=function(){if(this._effectBase.isReady()&&this._effectFog.isReady()&&this._spriteTexture&&this._spriteTexture.isReady()){for(var t=this._scene.getEngine(),r=this._spriteTexture.getBaseSize(),i=t.getDeltaTime(),n=Math.min(this._capacity,this.sprites.length),s=r.width/this.cellSize,o=0,a=0;n>a;a++){var h=this.sprites[a];h&&(h._animate(i),this._appendSpriteVertex(o++,h,0,0,s),this._appendSpriteVertex(o++,h,1,0,s),this._appendSpriteVertex(o++,h,1,1,s),this._appendSpriteVertex(o++,h,0,1,s))}t.updateDynamicVertexBuffer(this._vertexBuffer,this._vertices);var c=this._effectBase;this._scene.fogEnabled&&this._scene.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(c=this._effectFog),t.enableEffect(c);var l=this._scene.getViewMatrix();c.setTexture("diffuseSampler",this._spriteTexture),c.setMatrix("view",l),c.setMatrix("projection",this._scene.getProjectionMatrix()),c.setFloat2("textureInfos",this.cellSize/r.width,this.cellSize/r.height),this._scene.fogEnabled&&this._scene.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(c.setFloat4("vFogInfos",this._scene.fogMode,this._scene.fogStart,this._scene.fogEnd,this._scene.fogDensity),c.setColor3("vFogColor",this._scene.fogColor)),t.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,c),t.setDepthFunctionToLessOrEqual(),c.setBool("alphaTest",!0),t.setColorWrite(!1),t.draw(!0,0,6*n),t.setColorWrite(!0),c.setBool("alphaTest",!1),t.setAlphaMode(e.Engine.ALPHA_COMBINE),t.draw(!0,0,6*n),t.setAlphaMode(e.Engine.ALPHA_DISABLE)}},t.prototype.dispose=function(){this._vertexBuffer&&(this._scene.getEngine()._releaseBuffer(this._vertexBuffer),this._vertexBuffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this._spriteTexture&&(this._spriteTexture.dispose(),this._spriteTexture=null);var e=this._scene.spriteManagers.indexOf(this);this._scene.spriteManagers.splice(e,1),this.onDispose&&this.onDispose()},t}();e.SpriteManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r){this.name=t,this.color=new e.Color4(1,1,1,1),this.width=1,this.height=1,this.angle=0,this.cellIndex=0,this.invertU=0,this.invertV=0,this.animations=new Array,this.isPickable=!1,this._animationStarted=!1,this._loopAnimation=!1,this._fromIndex=0,this._toIndex=0,this._delay=0,this._direction=1,this._frameCount=0,this._time=0,this._manager=r,this._manager.sprites.push(this),this.position=e.Vector3.Zero()}return Object.defineProperty(t.prototype,"size",{get:function(){return this.width},set:function(e){this.width=e,this.height=e},enumerable:!0,configurable:!0}),t.prototype.playAnimation=function(e,t,r,i){this._fromIndex=e,this._toIndex=t,this._loopAnimation=r,this._delay=i,this._animationStarted=!0,this._direction=t>e?1:-1,this.cellIndex=e,this._time=0},t.prototype.stopAnimation=function(){this._animationStarted=!1},t.prototype._animate=function(e){this._animationStarted&&(this._time+=e,this._time>this._delay&&(this._time=this._time%this._delay,this.cellIndex+=this._direction,this.cellIndex==this._toIndex&&(this._loopAnimation?this.cellIndex=this._fromIndex:(this._animationStarted=!1,this.disposeWhenFinishedAnimating&&this.dispose()))))},t.prototype.dispose=function(){for(var e=0;el;l++)h.push(c),h.push(c+1),h.push(c+2),h.push(c),h.push(c+2),h.push(c+3),c+=4;this._indexBuffer=s.getEngine().createIndexBuffer(h),this._vertices=new Float32Array(n*this._vertexStrideSize),this.startDirectionFunction=function(r,i,n,s){var o=t(a.direction1.x,a.direction2.x),h=t(a.direction1.y,a.direction2.y),c=t(a.direction1.z,a.direction2.z);e.Vector3.TransformNormalFromFloatsToRef(o*r,h*r,c*r,i,n)},this.startPositionFunction=function(r,i,n){var s=t(a.minEmitBox.x,a.maxEmitBox.x),o=t(a.minEmitBox.y,a.maxEmitBox.y),h=t(a.minEmitBox.z,a.maxEmitBox.z);e.Vector3.TransformCoordinatesFromFloatsToRef(s,o,h,r,i)},this.updateFunction=function(e){for(var t=0;t=r.lifeTime?(a.recycleParticle(r),t--):(r.colorStep.scaleToRef(a._scaledUpdateSpeed,a._scaledColorStep),r.color.addInPlace(a._scaledColorStep),r.color.a<0&&(r.color.a=0),r.angle+=r.angularSpeed*a._scaledUpdateSpeed,r.direction.scaleToRef(a._scaledUpdateSpeed,a._scaledDirection),r.position.addInPlace(a._scaledDirection),a.gravity.scaleToRef(a._scaledUpdateSpeed,a._scaledGravity),r.direction.addInPlace(a._scaledGravity))}}}return r.prototype.recycleParticle=function(e){var t=this.particles.pop();t!==e&&(t.copyTo(e),this._stockParticles.push(t))},r.prototype.getCapacity=function(){return this._capacity},r.prototype.isAlive=function(){return this._alive},r.prototype.isStarted=function(){return this._started},r.prototype.start=function(){this._started=!0,this._stopped=!1,this._actualFrame=0},r.prototype.stop=function(){this._stopped=!0},r.prototype._appendParticleVertex=function(e,t,r,i){var n=11*e;this._vertices[n]=t.position.x,this._vertices[n+1]=t.position.y,this._vertices[n+2]=t.position.z,this._vertices[n+3]=t.color.r,this._vertices[n+4]=t.color.g,this._vertices[n+5]=t.color.b,this._vertices[n+6]=t.color.a,this._vertices[n+7]=t.angle,this._vertices[n+8]=t.size,this._vertices[n+9]=r,this._vertices[n+10]=i},r.prototype._update=function(r){this._alive=this.particles.length>0,this.updateFunction(this.particles);var i;i=this.emitter.position?this.emitter.getWorldMatrix():e.Matrix.Translation(this.emitter.x,this.emitter.y,this.emitter.z);for(var n,s=0;r>s&&this.particles.length!==this._capacity;s++){0!==this._stockParticles.length?(n=this._stockParticles.pop(),n.age=0):n=new e.Particle,this.particles.push(n);var o=t(this.minEmitPower,this.maxEmitPower);this.startDirectionFunction(o,i,n.direction,n),n.lifeTime=t(this.minLifeTime,this.maxLifeTime),n.size=t(this.minSize,this.maxSize),n.angularSpeed=t(this.minAngularSpeed,this.maxAngularSpeed),this.startPositionFunction(i,n.position,n);var a=t(0,1);e.Color4.LerpToRef(this.color1,this.color2,a,n.color),this.colorDead.subtractToRef(n.color,this._colorDiff),this._colorDiff.scaleToRef(1/n.lifeTime,n.colorStep)}},r.prototype._getEffect=function(){if(this._customEffect)return this._customEffect;var e=[];this._scene.clipPlane&&e.push("#define CLIPPLANE");var t=e.join("\n");return this._cachedDefines!==t&&(this._cachedDefines=t,this._effect=this._scene.getEngine().createEffect("particles",["position","color","options"],["invView","view","projection","vClipPlane","textureMask"],["diffuseSampler"],t)),this._effect},r.prototype.animate=function(){if(this._started){var e=this._getEffect();if(this.emitter&&e.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this._currentRenderId!==this._scene.getRenderId()){this._currentRenderId=this._scene.getRenderId(),this._scaledUpdateSpeed=this.updateSpeed*this._scene.getAnimationRatio();var t;this.manualEmitCount>-1?(t=this.manualEmitCount,this._newPartsExcess=0,this.manualEmitCount=0):(t=this.emitRate*this._scaledUpdateSpeed>>0,this._newPartsExcess+=this.emitRate*this._scaledUpdateSpeed-t),this._newPartsExcess>1&&(t+=this._newPartsExcess>>0,this._newPartsExcess-=this._newPartsExcess>>0),this._alive=!1,this._stopped?t=0:(this._actualFrame+=this._scaledUpdateSpeed,this.targetStopDuration&&this._actualFrame>=this.targetStopDuration&&this.stop()),this._update(t),this._stopped&&(this._alive||(this._started=!1,this.disposeOnStop&&this._scene._toBeDisposed.push(this)));for(var r=0,i=0;i=0;n--)this._keys[n].frame>=r&&this._keys[n].frame<=i&&this._keys.splice(n,1);this._ranges[e]=void 0}},r.prototype.getRange=function(e){return this._ranges[e]},r.prototype.reset=function(){this._offsetsCache={},this._highLimitsCache={},this.currentFrame=0},r.prototype.isStopped=function(){return this._stopped},r.prototype.getKeys=function(){return this._keys},r.prototype.getHighestFrame=function(){for(var e=0,t=0,r=this._keys.length;r>t;t++)e0)return s.clone?s.clone():s;this.currentFrame=e;var o=Math.max(0,Math.min(this._keys.length-1,Math.floor(this._keys.length*(e-this._keys[0].frame)/(this._keys[this._keys.length-1].frame-this._keys[0].frame))-1));if(this._keys[o].frame>=e)for(;o-1>=0&&this._keys[o].frame>=e;)o--;for(var a=o;a=e){var h=this._getKeyValue(this._keys[a].value),c=this._getKeyValue(this._keys[a+1].value),l=(e-this._keys[a].frame)/(this._keys[a+1].frame-this._keys[a].frame);switch(null!=this._easingFunction&&(l=this._easingFunction.ease(l)),this.dataType){case r.ANIMATIONTYPE_FLOAT:switch(i){case r.ANIMATIONLOOPMODE_CYCLE:case r.ANIMATIONLOOPMODE_CONSTANT:return this.floatInterpolateFunction(h,c,l);case r.ANIMATIONLOOPMODE_RELATIVE:return n*t+this.floatInterpolateFunction(h,c,l)}break;case r.ANIMATIONTYPE_QUATERNION:var u=null;switch(i){case r.ANIMATIONLOOPMODE_CYCLE:case r.ANIMATIONLOOPMODE_CONSTANT:u=this.quaternionInterpolateFunction(h,c,l);break;case r.ANIMATIONLOOPMODE_RELATIVE:u=this.quaternionInterpolateFunction(h,c,l).add(n.scale(t))}return u;case r.ANIMATIONTYPE_VECTOR3:switch(i){case r.ANIMATIONLOOPMODE_CYCLE:case r.ANIMATIONLOOPMODE_CONSTANT:return this.vector3InterpolateFunction(h,c,l);case r.ANIMATIONLOOPMODE_RELATIVE:return this.vector3InterpolateFunction(h,c,l).add(n.scale(t))}case r.ANIMATIONTYPE_VECTOR2:switch(i){case r.ANIMATIONLOOPMODE_CYCLE:case r.ANIMATIONLOOPMODE_CONSTANT:return this.vector2InterpolateFunction(h,c,l);case r.ANIMATIONLOOPMODE_RELATIVE:return this.vector2InterpolateFunction(h,c,l).add(n.scale(t))}case r.ANIMATIONTYPE_COLOR3:switch(i){case r.ANIMATIONLOOPMODE_CYCLE:case r.ANIMATIONLOOPMODE_CONSTANT:return this.color3InterpolateFunction(h,c,l);case r.ANIMATIONLOOPMODE_RELATIVE:return this.color3InterpolateFunction(h,c,l).add(n.scale(t))}case r.ANIMATIONTYPE_MATRIX:switch(i){case r.ANIMATIONLOOPMODE_CYCLE:case r.ANIMATIONLOOPMODE_CONSTANT:if(this.allowMatricesInterpolation)return this.matrixInterpolateFunction(h,c,l);case r.ANIMATIONLOOPMODE_RELATIVE:return h}}break}return this._getKeyValue(this._keys[this._keys.length-1].value)},r.prototype.setValue=function(e){if(this.targetPropertyPath.length>1){for(var t=this._target[this.targetPropertyPath[0]],r=1;rthis._keys[this._keys.length-1].frame&&(e=this._keys[this._keys.length-1].frame);var t=this._interpolate(e,0,this.loopMode);this.setValue(t)},r.prototype.animate=function(t,i,n,s,o){if(!this.targetPropertyPath||this.targetPropertyPath.length<1)return this._stopped=!0,!1;var a=!0;if(0!==this._keys[0].frame){var h={frame:0,value:this._keys[0].value};this._keys.splice(0,0,h)}(ithis._keys[this._keys.length-1].frame)&&(i=this._keys[0].frame),(nthis._keys[this._keys.length-1].frame)&&(n=this._keys[this._keys.length-1].frame);var c,l=n-i,u=t*(this.framePerSecond*o)/1e3,f=0;if(u>l&&!s)a=!1,f=this._getKeyValue(this._keys[this._keys.length-1].value);else if(this.loopMode!==r.ANIMATIONLOOPMODE_CYCLE){var d=n.toString()+i.toString();if(!this._offsetsCache[d]){var p=this._interpolate(i,0,r.ANIMATIONLOOPMODE_CYCLE),m=this._interpolate(n,0,r.ANIMATIONLOOPMODE_CYCLE);switch(this.dataType){case r.ANIMATIONTYPE_FLOAT:this._offsetsCache[d]=m-p; break;case r.ANIMATIONTYPE_QUATERNION:this._offsetsCache[d]=m.subtract(p);break;case r.ANIMATIONTYPE_VECTOR3:this._offsetsCache[d]=m.subtract(p);case r.ANIMATIONTYPE_VECTOR2:this._offsetsCache[d]=m.subtract(p);case r.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 r.ANIMATIONTYPE_FLOAT:c=0;break;case r.ANIMATIONTYPE_QUATERNION:c=new e.Quaternion(0,0,0,0);break;case r.ANIMATIONTYPE_VECTOR3:c=e.Vector3.Zero();break;case r.ANIMATIONTYPE_VECTOR2:c=e.Vector2.Zero();break;case r.ANIMATIONTYPE_COLOR3:c=e.Color3.Black()}var g=u/l>>0,_=a?i+u%l:n,v=this._interpolate(_,g,this.loopMode,c,f);this.setValue(v);for(var y=0;y=this._events[y].frame){var x=this._events[y];x.isDone||(x.onlyOnce&&(this._events.splice(y,1),y--),x.isDone=!0,x.action())}else this._events[y].isDone&&!this._events[y].onlyOnce&&(this._events[y].isDone=!1);return a||(this._stopped=!0),a},r.prototype.serialize=function(){var e={};e.name=this.name,e.property=this.targetProperty,e.framePerSecond=this.framePerSecond,e.dataType=this.dataType,e.loopBehavior=this.loopMode;var t=this.dataType;e.keys=[];for(var i=this.getKeys(),n=0;n-1&&this._scene._activeAnimatables.splice(e,1),this.onAnimationEnd&&this.onAnimationEnd()},e.prototype._animate=function(e){if(this._paused)return this.animationStarted=!1,this._pausedDelay||(this._pausedDelay=e),!0;this._localDelayOffset?this._pausedDelay&&(this._localDelayOffset+=e-this._pausedDelay,this._pausedDelay=null):this._localDelayOffset=e;var t,r=!1,i=this._animations;for(t=0;t=.5?.5*(1-this.easeInCore(2*(1-t)))+.5:.5*this.easeInCore(2*t)},e._EASINGMODE_EASEIN=0,e._EASINGMODE_EASEOUT=1,e._EASINGMODE_EASEINOUT=2,e}();e.EasingFunction=t;var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e=Math.max(0,Math.min(1,e)),1-Math.sqrt(1-e*e)},t}(t);e.CircleEase=r;var i=function(e){function t(t){void 0===t&&(t=1),e.call(this),this.amplitude=t}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.amplitude);return Math.pow(e,3)-e*t*Math.sin(3.141592653589793*e)},t}(t);e.BackEase=i;var n=function(e){function t(t,r){void 0===t&&(t=3),void 0===r&&(r=2),e.call(this),this.bounces=t,this.bounciness=r}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.bounces),r=this.bounciness;1>=r&&(r=1.001);var i=Math.pow(r,t),n=1-r,s=(1-i)/n+.5*i,o=e*s,a=Math.log(-o*(1-r)+1)/Math.log(r),h=Math.floor(a),c=h+1,l=(1-Math.pow(r,h))/(n*s),u=(1-Math.pow(r,c))/(n*s),f=.5*(l+u),d=e-f,p=f-l;return-Math.pow(1/r,t-h)/(p*p)*(d-p)*(d+p)},t}(t);e.BounceEase=n;var s=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e},t}(t);e.CubicEase=s;var o=function(e){function t(t,r){void 0===t&&(t=3),void 0===r&&(r=3),e.call(this),this.oscillations=t,this.springiness=r}return __extends(t,e),t.prototype.easeInCore=function(e){var t,r=Math.max(0,this.oscillations),i=Math.max(0,this.springiness);return t=0==i?e:(Math.exp(i*e)-1)/(Math.exp(i)-1),t*Math.sin((6.283185307179586*r+1.5707963267948966)*e)},t}(t);e.ElasticEase=o;var a=function(e){function t(t){void 0===t&&(t=2),e.call(this),this.exponent=t}return __extends(t,e),t.prototype.easeInCore=function(e){return this.exponent<=0?e:(Math.exp(this.exponent*e)-1)/(Math.exp(this.exponent)-1)},t}(t);e.ExponentialEase=a;var h=function(e){function t(t){void 0===t&&(t=2),e.call(this),this.power=t}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.power);return Math.pow(e,t)},t}(t);e.PowerEase=h;var c=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e},t}(t);e.QuadraticEase=c;var l=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e},t}(t);e.QuarticEase=l;var u=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e*e},t}(t);e.QuinticEase=u;var f=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return 1-Math.sin(1.5707963267948966*(1-e))},t}(t);e.SineEase=f;var d=function(t){function r(e,r,i,n){void 0===e&&(e=0),void 0===r&&(r=0),void 0===i&&(i=1),void 0===n&&(n=1),t.call(this),this.x1=e,this.y1=r,this.x2=i,this.y2=n}return __extends(r,t),r.prototype.easeInCore=function(t){return e.BezierCurve.interpolate(t,this.x1,this.y1,this.x2,this.y2)},r}(t);e.BezierCurveEase=d}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i,n,s,o){t.call(this,r,i.getScene()),this.name=r,this.children=new Array,this.animations=new Array,this._worldTransform=new e.Matrix,this._absoluteTransform=new e.Matrix,this._invertedAbsoluteTransform=new e.Matrix,this._skeleton=i,this._matrix=s,this._baseMatrix=s,this._restPose=o?o:s.clone(),i.bones.push(this),n?(this._parent=n,n.children.push(this)):this._parent=null,this._updateDifferenceMatrix()}return __extends(r,t),r.prototype.getParent=function(){return this._parent},r.prototype.getLocalMatrix=function(){return this._matrix},r.prototype.getBaseMatrix=function(){return this._baseMatrix},r.prototype.getRestPose=function(){return this._restPose},r.prototype.returnToRest=function(){this.updateMatrix(this._restPose.clone())},r.prototype.getWorldMatrix=function(){return this._worldTransform},r.prototype.getInvertedAbsoluteTransform=function(){return this._invertedAbsoluteTransform},r.prototype.getAbsoluteTransform=function(){return this._absoluteTransform},r.prototype.updateMatrix=function(e){this._baseMatrix=e.clone(),this._skeleton._markAsDirty(),this._updateDifferenceMatrix()},r.prototype._updateDifferenceMatrix=function(e){e||(e=this._baseMatrix),this._parent?e.multiplyToRef(this._parent._absoluteTransform,this._absoluteTransform):this._absoluteTransform.copyFrom(e),this._absoluteTransform.invertToRef(this._invertedAbsoluteTransform);for(var t=0;tv;v++)o=l[v],o.frame>=h&&o.frame<=c&&(f?(o.value.decompose(m,g,_),_.scaleInPlace(d),a=e.Matrix.Compose(m,g,_)):a=o.value,p.push({frame:o.frame+i,value:a}));return this.animations[0].createRange(r,h+i,c+i),!0},r}(e.Node);e.Bone=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r,i){this.name=t,this.id=r,this.bones=new Array,this.needInitialSkinMatrix=!1,this._isDirty=!0,this._meshesWithPoseMatrix=new Array,this._identity=e.Matrix.Identity(),this._ranges={},this.bones=[],this._scene=i,i.skeletons.push(this),this.prepare(),this._isDirty=!0}return t.prototype.getTransformMatrices=function(e){return this.needInitialSkinMatrix&&e._bonesTransformMatrices?e._bonesTransformMatrices:this._transformMatrices},t.prototype.getScene=function(){return this._scene},t.prototype.createAnimationRange=function(t,r,i){if(!this._ranges[t]){this._ranges[t]=new e.AnimationRange(t,r,i);for(var n=0,s=this.bones.length;s>n;n++)this.bones[n].animations[0]&&this.bones[n].animations[0].createRange(t,r,i)}},t.prototype.deleteAnimationRange=function(e,t){void 0===t&&(t=!0);for(var r=0,i=this.bones.length;i>r;r++)this.bones[r].animations[0]&&this.bones[r].animations[0].deleteRange(e,t);this._ranges[e]=void 0},t.prototype.getAnimationRange=function(e){return this._ranges[e]},t.prototype.copyAnimationRange=function(t,r,i){if(void 0===i&&(i=!1),this._ranges[r]||!t.getAnimationRange(r))return!1;for(var n=!0,s=this._getHighestAnimationFrame()+1,o={},a=t.bones,h=0,c=a.length;c>h;h++)o[a[h].name]=a[h];for(var h=0,c=this.bones.length;c>h;h++){var l=this.bones[h].name,u=o[l];u?n=n&&this.bones[h].copyAnimationRange(u,r,s,i):(e.Tools.Warn("copyAnimationRange: not same rig, missing source bone "+l),n=!1)}var f=t.getAnimationRange(r);return this._ranges[r]=new e.AnimationRange(r,f.from+s,f.to+s),n},t.prototype.returnToRest=function(){for(var e=0;et;t++)if(this.bones[t].animations[0]){var i=this.bones[t].animations[0].getHighestFrame();i>e&&(e=i)}return e},t.prototype.beginAnimation=function(e,t,r,i){var n=this.getAnimationRange(e);return n?void this._scene.beginAnimation(this,n.from,n.to,t,r,i):null},t.prototype._markAsDirty=function(){this._isDirty=!0},t.prototype._registerMeshWithPoseMatrix=function(e){this._meshesWithPoseMatrix.push(e)},t.prototype._unregisterMeshWithPoseMatrix=function(e){var t=this._meshesWithPoseMatrix.indexOf(e);t>-1&&this._meshesWithPoseMatrix.splice(t,1)},t.prototype._computeTransformMatrices=function(e,t){for(var r=0;r0&&(i.animation=r.animations[0].serialize()),e.ranges=[];for(var n in this._ranges){var s={};s.name=n,s.from=this._ranges[n].from,s.to=this._ranges[n].to,e.ranges.push(s)}}return e},t.Parse=function(r,i){var n=new t(r.name,r.id,i);n.needInitialSkinMatrix=r.needInitialSkinMatrix;for(var s=0;s-1&&(a=n.bones[o.parentBoneIndex]);var h=o.rest?e.Matrix.FromArray(o.rest):null,c=new e.Bone(o.name,n,a,e.Matrix.FromArray(o.matrix),h);o.length&&(c.length=o.length),o.animation&&c.animations.push(e.Animation.Parse(o.animation))}if(r.ranges)for(var s=0;s0){for(var a=0;a0){for(var t=0;t0&&(this._camera._postProcesses[e._postProcessesTakenIndices[0]].width=-1)}},t}();e.PostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){this._vertexDeclaration=[2],this._vertexStrideSize=8,this._scene=e}return e.prototype._prepareBuffers=function(){if(!this._vertexBuffer){var e=[];e.push(1,1),e.push(-1,1),e.push(-1,-1),e.push(1,-1),this._vertexBuffer=this._scene.getEngine().createVertexBuffer(e);var t=[];t.push(0),t.push(1),t.push(2),t.push(0),t.push(2),t.push(3),this._indexBuffer=this._scene.getEngine().createIndexBuffer(t)}},e.prototype._prepareFrame=function(e){var t=this._scene.activeCamera._postProcesses,r=this._scene.activeCamera._postProcessesTakenIndices;return 0!==r.length&&this._scene.postProcessesEnabled?(t[this._scene.activeCamera._postProcessesTakenIndices[0]].activate(this._scene.activeCamera,e),!0):!1},e.prototype.directRender=function(e,t){for(var r=this._scene.getEngine(),i=0;i.1?e=.1:0>=e&&(e=1/60),this._currentPlugin.runOneStep(e)},t.prototype._setGravity=function(t){this.gravity=t||new e.Vector3(0,-9.807,0),this._currentPlugin.setGravity(this.gravity)},t.prototype._getGravity=function(){return this._currentPlugin.getGravity()},t.prototype._registerMesh=function(e,t,r){return this._currentPlugin.registerMesh(e,t,r)},t.prototype._registerMeshesAsCompound=function(e,t){return this._currentPlugin.registerMeshesAsCompound(e,t)},t.prototype._unregisterMesh=function(e){this._currentPlugin.unregisterMesh(e)},t.prototype._applyImpulse=function(e,t,r){this._currentPlugin.applyImpulse(e,t,r)},t.prototype._createLink=function(e,t,r,i,n){return this._currentPlugin.createLink(e,t,r,i,n)},t.prototype._updateBodyPosition=function(e){this._currentPlugin.updateBodyPosition(e)},t.prototype.dispose=function(){this._currentPlugin.dispose()},t.prototype.isSupported=function(){return this._currentPlugin.isSupported()},t.prototype.getPhysicsBodyOfMesh=function(e){return this._currentPlugin.getPhysicsBodyOfMesh(e)},t.prototype.getPhysicsPluginName=function(){return this._currentPlugin.name},t.NoImpostor=0,t.SphereImpostor=1,t.BoxImpostor=2,t.PlaneImpostor=3,t.MeshImpostor=4,t.CapsuleImpostor=5,t.ConeImpostor=6,t.CylinderImpostor=7,t.ConvexHullImpostor=8,t.HeightmapImpostor=9,t.Epsilon=.001,t}();e.PhysicsEngine=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.prototype.set=function(t,r){switch(r){case e.VertexBuffer.PositionKind:this.positions=t;break;case e.VertexBuffer.NormalKind:this.normals=t;break;case e.VertexBuffer.UVKind:this.uvs=t;break;case e.VertexBuffer.UV2Kind:this.uvs2=t;break;case e.VertexBuffer.UV3Kind:this.uvs3=t;break;case e.VertexBuffer.UV4Kind:this.uvs4=t;break;case e.VertexBuffer.UV5Kind:this.uvs5=t;break;case e.VertexBuffer.UV6Kind:this.uvs6=t;break;case e.VertexBuffer.ColorKind:this.colors=t;break;case e.VertexBuffer.MatricesIndicesKind:this.matricesIndices=t;break;case e.VertexBuffer.MatricesWeightsKind:this.matricesWeights=t;break;case e.VertexBuffer.MatricesIndicesExtraKind:this.matricesIndicesExtra=t;break;case e.VertexBuffer.MatricesWeightsExtraKind:this.matricesWeightsExtra=t}},t.prototype.applyToMesh=function(e,t){this._applyTo(e,t)},t.prototype.applyToGeometry=function(e,t){this._applyTo(e,t)},t.prototype.updateMesh=function(e,t,r){this._update(e)},t.prototype.updateGeometry=function(e,t,r){this._update(e)},t.prototype._applyTo=function(t,r){this.positions&&t.setVerticesData(e.VertexBuffer.PositionKind,this.positions,r),this.normals&&t.setVerticesData(e.VertexBuffer.NormalKind,this.normals,r),this.uvs&&t.setVerticesData(e.VertexBuffer.UVKind,this.uvs,r),this.uvs2&&t.setVerticesData(e.VertexBuffer.UV2Kind,this.uvs2,r),this.uvs3&&t.setVerticesData(e.VertexBuffer.UV3Kind,this.uvs3,r),this.uvs4&&t.setVerticesData(e.VertexBuffer.UV4Kind,this.uvs4,r),this.uvs5&&t.setVerticesData(e.VertexBuffer.UV5Kind,this.uvs5,r),this.uvs6&&t.setVerticesData(e.VertexBuffer.UV6Kind,this.uvs6,r),this.colors&&t.setVerticesData(e.VertexBuffer.ColorKind,this.colors,r),this.matricesIndices&&t.setVerticesData(e.VertexBuffer.MatricesIndicesKind,this.matricesIndices,r),this.matricesWeights&&t.setVerticesData(e.VertexBuffer.MatricesWeightsKind,this.matricesWeights,r),this.matricesIndicesExtra&&t.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,this.matricesIndicesExtra,r),this.matricesWeightsExtra&&t.setVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,this.matricesWeightsExtra,r),this.indices&&t.setIndices(this.indices)},t.prototype._update=function(t,r,i){this.positions&&t.updateVerticesData(e.VertexBuffer.PositionKind,this.positions,r,i),this.normals&&t.updateVerticesData(e.VertexBuffer.NormalKind,this.normals,r,i),this.uvs&&t.updateVerticesData(e.VertexBuffer.UVKind,this.uvs,r,i),this.uvs2&&t.updateVerticesData(e.VertexBuffer.UV2Kind,this.uvs2,r,i),this.uvs3&&t.updateVerticesData(e.VertexBuffer.UV3Kind,this.uvs3,r,i),this.uvs4&&t.updateVerticesData(e.VertexBuffer.UV4Kind,this.uvs4,r,i),this.uvs5&&t.updateVerticesData(e.VertexBuffer.UV5Kind,this.uvs5,r,i),this.uvs6&&t.updateVerticesData(e.VertexBuffer.UV6Kind,this.uvs6,r,i),this.colors&&t.updateVerticesData(e.VertexBuffer.ColorKind,this.colors,r,i),this.matricesIndices&&t.updateVerticesData(e.VertexBuffer.MatricesIndicesKind,this.matricesIndices,r,i),this.matricesWeights&&t.updateVerticesData(e.VertexBuffer.MatricesWeightsKind,this.matricesWeights,r,i),this.matricesIndicesExtra&&t.updateVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,this.matricesIndicesExtra,r,i),this.matricesWeightsExtra&&t.updateVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,this.matricesWeightsExtra,r,i),this.indices&&t.setIndices(this.indices)},t.prototype.transform=function(t){var r,i=e.Vector3.Zero();if(this.positions){var n=e.Vector3.Zero();for(r=0;ra;a++)o.push(t[a]);return o}return e.concat(t)},t.prototype.serialize=function(){var e=this.serialize();return this.positions&&(e.positions=this.positions),this.normals&&(e.normals=this.normals),this.uvs&&(e.uvs=this.uvs),this.uvs2&&(e.uvs2=this.uvs2),this.uvs3&&(e.uvs3=this.uvs3),this.uvs4&&(e.uvs4=this.uvs4),this.uvs5&&(e.uvs5=this.uvs5),this.uvs6&&(e.uvs6=this.uvs6),this.colors&&(e.colors=this.colors),this.matricesIndices&&(e.matricesIndices=this.matricesIndices,e.matricesIndices._isExpanded=!0),this.matricesWeights&&(e.matricesWeights=this.matricesWeights),this.matricesIndicesExtra&&(e.matricesIndicesExtra=this.matricesIndicesExtra,e.matricesIndicesExtra._isExpanded=!0),this.matricesWeightsExtra&&(e.matricesWeightsExtra=this.matricesWeightsExtra),e.indices=this.indices,e},t.ExtractFromMesh=function(e,r){return t._ExtractFrom(e,r)},t.ExtractFromGeometry=function(e,r){return t._ExtractFrom(e,r)},t._ExtractFrom=function(r,i){var n=new t;return r.isVerticesDataPresent(e.VertexBuffer.PositionKind)&&(n.positions=r.getVerticesData(e.VertexBuffer.PositionKind,i)),r.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(n.normals=r.getVerticesData(e.VertexBuffer.NormalKind,i)),r.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(n.uvs=r.getVerticesData(e.VertexBuffer.UVKind,i)),r.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(n.uvs2=r.getVerticesData(e.VertexBuffer.UV2Kind,i)),r.isVerticesDataPresent(e.VertexBuffer.UV3Kind)&&(n.uvs3=r.getVerticesData(e.VertexBuffer.UV3Kind,i)),r.isVerticesDataPresent(e.VertexBuffer.UV4Kind)&&(n.uvs4=r.getVerticesData(e.VertexBuffer.UV4Kind,i)),r.isVerticesDataPresent(e.VertexBuffer.UV5Kind)&&(n.uvs5=r.getVerticesData(e.VertexBuffer.UV5Kind,i)),r.isVerticesDataPresent(e.VertexBuffer.UV6Kind)&&(n.uvs6=r.getVerticesData(e.VertexBuffer.UV6Kind,i)),r.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(n.colors=r.getVerticesData(e.VertexBuffer.ColorKind,i)), r.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&(n.matricesIndices=r.getVerticesData(e.VertexBuffer.MatricesIndicesKind,i)),r.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)&&(n.matricesWeights=r.getVerticesData(e.VertexBuffer.MatricesWeightsKind,i)),r.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesExtraKind)&&(n.matricesIndicesExtra=r.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,i)),r.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsExtraKind)&&(n.matricesWeightsExtra=r.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,i)),n.indices=r.getIndices(i),n},t.CreateRibbon=function(r){var i=r.pathArray,n=r.closeArray||!1,s=r.closePath||!1,o=Math.floor(i[0].length/2),a=r.offset||o;a=a>o?o:Math.floor(a);var h,c,l,u,f=0===r.sideOrientation?0:r.sideOrientation||e.Mesh.DEFAULTSIDE,d=[],p=[],m=[],g=[],_=[],v=[],y=[],x=[],E=[],T=[];if(i.length<2){var A=[],b=[];for(l=0;lh?h:P,u=0;P>u;)d.push(M[u].x,M[u].y,M[u].z),u>0&&(I=M[u].subtract(M[u-1]).length(),D=I+y[c],_[c].push(D),y[c]=D),u++;s&&(u--,d.push(M[0].x,M[0].y,M[0].z),I=M[u].subtract(M[0]).length(),D=I+y[c],_[c].push(D),y[c]=D),E[c]=P+C,T[c]=S,S+=P+C}var R,w,L,O;for(l=0;h+C>l;l++){for(x[l]=0,v[l]=[0],c=0;cl;l++)B=_[c][l]/y[c],F=v[l][c]/x[l],g.push(B,F);c=0;for(var V=0,N=E[c]-1,U=E[c+1]-1,k=U>N?N:U,z=T[1]-T[0],W=n?E.length:E.length-1;k>=V&&W>c;)p.push(V,V+z,V+1),p.push(V+z+1,V+1,V+z),V+=1,V===k&&(c++,c===E.length-1?(z=T[0]-T[c],N=E[c]-1,U=E[0]-1):(z=T[c+1]-T[c],N=E[c]-1,U=E[c+1]-1),V=T[c],k=U>N?N+V:U+V);if(t.ComputeNormals(d,p,m),s){var G=0,K=0;for(c=0;cm;m++)void 0===f[m]&&(f[m]=new e.Vector4(0,0,1,1)),d&&void 0===d[m]&&(d[m]=new e.Color4(1,1,1,1));for(var g=new e.Vector3(h/2,c/2,l/2),_=0;_1?1:r.arc||1,h=r.slice<=0?1:r.slice||1,c=0===r.sideOrientation?0:r.sideOrientation||e.Mesh.DEFAULTSIDE,l=new e.Vector3(n/2,s/2,o/2),u=2+i,f=2*u,d=[],p=[],m=[],g=[],_=0;u>=_;_++){for(var v=_/u,y=v*Math.PI*h,x=0;f>=x;x++){var E=x/f,T=E*Math.PI*2*a,A=e.Matrix.RotationZ(-y),b=e.Matrix.RotationY(T),M=e.Vector3.TransformCoordinates(e.Vector3.Up(),A),P=e.Vector3.TransformCoordinates(M,b),S=P.multiply(l),C=P.divide(l).normalize();p.push(S.x,S.y,S.z),m.push(C.x,C.y,C.z),g.push(E,v)}if(_>0)for(var I=p.length/3,D=I-2*(f+1);I>D+f+2;D++)d.push(D),d.push(D+1),d.push(D+f+1),d.push(D+f+1),d.push(D+1),d.push(D+f+2)}t._ComputeSides(c,p,d,m,g);var R=new t;return R.indices=d,R.positions=p,R.normals=m,R.uvs=g,R},t.CreateCylinder=function(r){var i,n=r.height||2,s=0===r.diameterTop?0:r.diameterTop||r.diameter||1,o=r.diameterBottom||r.diameter||1,a=r.tessellation||24,h=r.subdivisions||1,c=r.hasRings,l=r.enclose,u=r.arc<=0||r.arc>1?1:r.arc||1,f=0===r.sideOrientation?0:r.sideOrientation||e.Mesh.DEFAULTSIDE,d=r.faceUV||new Array(3),p=r.faceColors,m=1!==u&&l?2:0,g=c?h:1,_=2+(1+m)*g;for(i=0;_>i;i++)p&&void 0===p[i]&&(p[i]=new e.Color4(1,1,1,1));for(i=0;_>i;i++)d&&void 0===d[i]&&(d[i]=new e.Vector4(0,0,1,1));var v,y,x,E,T,A,b=[],M=[],P=[],S=[],C=[],I=2*Math.PI*u/a,D=(o-s)/2/n,R=e.Vector3.Zero(),w=e.Vector3.Zero(),L=e.Vector3.Zero(),O=e.Vector3.Zero(),B=e.Vector3.Zero(),F=e.Axis.Y,V=1,N=1,U=0,k=0;for(E=0;h>=E;E++)for(y=E/h,x=(y*(s-o)+o)/2,V=c&&0!==E&&E!==h?2:1,A=0;V>A;A++){for(c&&(N+=A),l&&(N+=2*A),T=0;a>=T;T++)v=T*I,R.x=Math.cos(-v)*x,R.y=-n/2+y*n,R.z=Math.sin(-v)*x,0===s&&E===h?(w.x=P[P.length-3*(a+1)],w.y=P[P.length-3*(a+1)+1],w.z=P[P.length-3*(a+1)+2]):(w.x=R.x,w.z=R.z,w.y=Math.sqrt(w.x*w.x+w.z*w.z)*D,w.normalize()),0===T&&(L.copyFrom(R),O.copyFrom(w)),M.push(R.x,R.y,R.z),P.push(w.x,w.y,w.z),k=c?U!==N?d[N].y:d[N].w:d[N].y+(d[N].w-d[N].y)*y,S.push(d[N].x+(d[N].z-d[N].x)*T/a,k),p&&C.push(p[N].r,p[N].g,p[N].b,p[N].a);1!==u&&l&&(M.push(R.x,R.y,R.z),M.push(0,R.y,0),M.push(0,R.y,0),M.push(L.x,L.y,L.z),e.Vector3.CrossToRef(F,w,B),B.normalize(),P.push(B.x,B.y,B.z,B.x,B.y,B.z),e.Vector3.CrossToRef(O,F,B),B.normalize(),P.push(B.x,B.y,B.z,B.x,B.y,B.z),k=c?U!==N?d[N+1].y:d[N+1].w:d[N+1].y+(d[N+1].w-d[N+1].y)*y,S.push(d[N+1].x,k),S.push(d[N+1].z,k),k=c?U!==N?d[N+2].y:d[N+2].w:d[N+2].y+(d[N+2].w-d[N+2].y)*y,S.push(d[N+2].x,k),S.push(d[N+2].z,k),p&&(C.push(p[N+1].r,p[N+1].g,p[N+1].b,p[N+1].a),C.push(p[N+1].r,p[N+1].g,p[N+1].b,p[N+1].a),C.push(p[N+2].r,p[N+2].g,p[N+2].b,p[N+2].a),C.push(p[N+2].r,p[N+2].g,p[N+2].b,p[N+2].a))),U!==N&&(U=N)}var N,z=1!==u&&l?a+4:a;for(E=0,N=0;h>N;N++){for(T=0;a>T;T++){var W=E*(z+1)+T,G=(E+1)*(z+1)+T,K=E*(z+1)+(T+1),Y=(E+1)*(z+1)+(T+1);b.push(W,G,K),b.push(Y,K,G)}1!==u&&l&&(b.push(W+2,G+2,K+2),b.push(Y+2,K+2,G+2),b.push(W+4,G+4,K+4),b.push(Y+4,K+4,G+4)),E=c?E+2:E+1}var H=function(t){var r=t?s/2:o/2;if(0!==r){var i,h,c,l,f=t?d[_-1]:d[0];p&&(l=t?p[_-1]:p[0]);var m=M.length/3,g=t?n/2:-n/2,v=new e.Vector3(0,g,0);M.push(v.x,v.y,v.z),P.push(0,t?1:-1,0),S.push(f.x+.5*(f.z-f.x),f.y+.5*(f.w-f.y)),p&&C.push(l.r,l.g,l.b,l.a);var y=new e.Vector2(.5,.5);for(c=0;a>=c;c++){i=2*Math.PI*c*u/a;var x=Math.cos(-i),E=Math.sin(-i);h=new e.Vector3(x*r,g,E*r);var T=new e.Vector2(x*y.x+.5,E*y.y+.5);M.push(h.x,h.y,h.z),P.push(0,t?1:-1,0),S.push(f.x+(f.z-f.x)*T.x,f.y+(f.w-f.y)*T.y),p&&C.push(l.r,l.g,l.b,l.a)}for(c=0;a>c;c++)t?(b.push(m),b.push(m+(c+2)),b.push(m+(c+1))):(b.push(m),b.push(m+(c+1)),b.push(m+(c+2)))}};H(!1),H(!0),t._ComputeSides(f,M,b,P,S);var X=new t;return X.indices=b,X.positions=M,X.normals=P,X.uvs=S,p&&(X.colors=C),X},t.CreateTorus=function(r){for(var i=[],n=[],s=[],o=[],a=r.diameter||1,h=r.thickness||.5,c=r.tessellation||16,l=0===r.sideOrientation?0:r.sideOrientation||e.Mesh.DEFAULTSIDE,u=c+1,f=0;c>=f;f++)for(var d=f/c,p=f*Math.PI*2/c-Math.PI/2,m=e.Matrix.Translation(a/2,0,0).multiply(e.Matrix.RotationY(p)),g=0;c>=g;g++){var _=1-g/c,v=g*Math.PI*2/c+Math.PI,y=Math.cos(v),x=Math.sin(v),E=new e.Vector3(y,x,0),T=E.scale(h/2),A=new e.Vector2(d,_);T=e.Vector3.TransformCoordinates(T,m),E=e.Vector3.TransformNormal(E,m),n.push(T.x,T.y,T.z),s.push(E.x,E.y,E.z),o.push(A.x,A.y);var b=(f+1)%u,M=(g+1)%u;i.push(f*u+g),i.push(f*u+M),i.push(b*u+g),i.push(f*u+M),i.push(b*u+M),i.push(b*u+g)}t._ComputeSides(l,n,i,s,o);var P=new t;return P.indices=i,P.positions=n,P.normals=s,P.uvs=o,P},t.CreateLines=function(e){for(var r=[],i=[],n=e.points,s=0;s0&&(r.push(s-1),r.push(s));var o=new t;return o.indices=r,o.positions=i,o},t.CreateDashedLines=function(r){var i=r.dashSize||3,n=r.gapSize||1,s=r.dashNb||200,o=r.points,a=new Array,h=new Array,c=e.Vector3.Zero(),l=0,u=0,f=0,d=0,p=0,m=0,g=0;for(g=0;g_;_++)p=f*_,a.push(o[g].x+p*c.x,o[g].y+p*c.y,o[g].z+p*c.z),a.push(o[g].x+(p+d)*c.x,o[g].y+(p+d)*c.y,o[g].z+(p+d)*c.z),h.push(m,m+1),m+=2}var v=new t;return v.positions=a,v.indices=h,v},t.CreateGround=function(r){var i,n,s=[],o=[],a=[],h=[],c=r.width||1,l=r.height||1,u=r.subdivisions||1;for(i=0;u>=i;i++)for(n=0;u>=n;n++){var f=new e.Vector3(n*c/u-c/2,0,(u-i)*l/u-l/2),d=new e.Vector3(0,1,0);o.push(f.x,f.y,f.z),a.push(d.x,d.y,d.z),h.push(n/u,1-i/u)}for(i=0;u>i;i++)for(n=0;u>n;n++)s.push(n+1+(i+1)*(u+1)),s.push(n+1+i*(u+1)),s.push(n+i*(u+1)),s.push(n+(i+1)*(u+1)),s.push(n+1+(i+1)*(u+1)),s.push(n+i*(u+1));var p=new t;return p.indices=s,p.positions=o,p.normals=a,p.uvs=h,p},t.CreateTiledGround=function(r){function i(t,r,i,o){var a=m.length/3,h=d.w+1;for(n=0;n1?1:r.arc||1,l=0===r.sideOrientation?0:r.sideOrientation||e.Mesh.DEFAULTSIDE;i.push(0,0,0),o.push(.5,.5);for(var u=2*Math.PI*c,f=u/h,d=0;u>d;d+=f){var p=Math.cos(d),m=Math.sin(d),g=(p+1)/2,_=(1-m)/2;i.push(a*p,a*m,0),o.push(g,_)}1===c&&(i.push(i[3],i[4],i[5]),o.push(o[2],o[3]));for(var v=i.length/3,y=1;v-1>y;y++)n.push(y+1,0,y);t.ComputeNormals(i,n,s),t._ComputeSides(l,i,n,s,o);var x=new t;return x.indices=n,x.positions=i,x.normals=s,x.uvs=o,x},t.CreateIcoSphere=function(r){var i,n=r.sideOrientation||e.Mesh.DEFAULTSIDE,s=r.radius||1,o=void 0===r.flat?!0:r.flat,a=r.subdivisions||4,h=r.radiusX||s,c=r.radiusY||s,l=r.radiusZ||s,u=(1+Math.sqrt(5))/2,f=[-1,u,-0,1,u,0,-1,-u,0,1,-u,0,0,-1,-u,0,1,-u,0,-1,u,0,1,u,u,0,1,u,0,-1,-u,0,1,-u,0,-1],d=[0,11,5,0,5,1,0,1,7,0,7,10,12,22,23,1,5,20,5,11,4,23,22,13,22,18,6,7,1,8,14,21,4,14,4,2,16,13,6,15,6,19,3,8,9,4,21,5,13,17,23,6,13,22,19,6,18,9,8,1],p=[0,1,2,3,4,5,6,7,8,9,10,11,0,2,3,3,3,4,7,8,9,9,10,11],m=[5,1,3,1,6,4,0,0,5,3,4,2,2,2,4,0,2,0,1,1,6,0,6,2,0,4,3,3,4,4,3,1,4,2,4,4,0,2,1,1,2,2,3,3,1,3,2,4],g=138/1024,_=239/1024,v=60/1024,y=26/1024,x=-40/1024,E=20/1024,T=[0,0,0,0,1,0,0,1,1,0,0,0,1,1,0,0,1,1,1,0],A=[],b=[],M=[],P=[],S=0,C=new Array(3),I=new Array(3);for(i=0;3>i;i++)C[i]=e.Vector3.Zero(),I[i]=e.Vector2.Zero();for(var D=0;20>D;D++){for(i=0;3>i;i++){var R=d[3*D+i];C[i].copyFromFloats(f[3*p[R]],f[3*p[R]+1],f[3*p[R]+2]),C[i].normalize().scaleInPlace(s),I[i].copyFromFloats(m[2*R]*g+v+T[D]*x,m[2*R+1]*_+y+T[D]*E)}for(var w=function(t,r,i,n){var s=e.Vector3.Lerp(C[0],C[2],r/a),u=e.Vector3.Lerp(C[1],C[2],r/a),f=a===r?C[2]:e.Vector3.Lerp(s,u,t/(a-r));f.normalize();var d;if(o){var p=e.Vector3.Lerp(C[0],C[2],n/a),m=e.Vector3.Lerp(C[1],C[2],n/a);d=e.Vector3.Lerp(p,m,i/(a-n))}else d=new e.Vector3(f.x,f.y,f.z);d.x/=h,d.y/=c,d.z/=l,d.normalize();var g=e.Vector2.Lerp(I[0],I[2],r/a),_=e.Vector2.Lerp(I[1],I[2],r/a),v=a===r?I[2]:e.Vector2.Lerp(g,_,t/(a-r));b.push(f.x*h,f.y*c,f.z*l),M.push(d.x,d.y,d.z),P.push(v.x,v.y),A.push(S),S++},L=0;a>L;L++)for(var O=0;a>O+L;O++)w(O,L,O+1/3,L+1/3),w(O+1,L,O+1/3,L+1/3),w(O,L+1,O+1/3,L+1/3),a>O+L+1&&(w(O+1,L,O+2/3,L+2/3),w(O+1,L+1,O+2/3,L+2/3),w(O,L+1,O+2/3,L+2/3))}t._ComputeSides(n,b,A,M,P);var B=new t;return B.indices=A,B.positions=b,B.normals=M,B.uvs=P,B},t.CreatePolyhedron=function(r){var i=[];i[0]={vertex:[[0,0,1.732051],[1.632993,0,-.5773503],[-.8164966,1.414214,-.5773503],[-.8164966,-1.414214,-.5773503]],face:[[0,1,2],[0,2,3],[0,3,1],[1,3,2]]},i[1]={vertex:[[0,0,1.414214],[1.414214,0,0],[0,1.414214,0],[-1.414214,0,0],[0,-1.414214,0],[0,0,-1.414214]],face:[[0,1,2],[0,2,3],[0,3,4],[0,4,1],[1,4,5],[1,5,2],[2,5,3],[3,5,4]]},i[2]={vertex:[[0,0,1.070466],[.7136442,0,.7978784],[-.3568221,.618034,.7978784],[-.3568221,-.618034,.7978784],[.7978784,.618034,.3568221],[.7978784,-.618034,.3568221],[-.9341724,.381966,.3568221],[.1362939,1,.3568221],[.1362939,-1,.3568221],[-.9341724,-.381966,.3568221],[.9341724,.381966,-.3568221],[.9341724,-.381966,-.3568221],[-.7978784,.618034,-.3568221],[-.1362939,1,-.3568221],[-.1362939,-1,-.3568221],[-.7978784,-.618034,-.3568221],[.3568221,.618034,-.7978784],[.3568221,-.618034,-.7978784],[-.7136442,0,-.7978784],[0,0,-1.070466]],face:[[0,1,4,7,2],[0,2,6,9,3],[0,3,8,5,1],[1,5,11,10,4],[2,7,13,12,6],[3,9,15,14,8],[4,10,16,13,7],[5,8,14,17,11],[6,12,18,15,9],[10,11,17,19,16],[12,13,16,19,18],[14,15,18,19,17]]},i[3]={vertex:[[0,0,1.175571],[1.051462,0,.5257311],[.3249197,1,.5257311],[-.8506508,.618034,.5257311],[-.8506508,-.618034,.5257311],[.3249197,-1,.5257311],[.8506508,.618034,-.5257311],[.8506508,-.618034,-.5257311],[-.3249197,1,-.5257311],[-1.051462,0,-.5257311],[-.3249197,-1,-.5257311],[0,0,-1.175571]],face:[[0,1,2],[0,2,3],[0,3,4],[0,4,5],[0,5,1],[1,5,7],[1,7,6],[1,6,2],[2,6,8],[2,8,3],[3,8,9],[3,9,4],[4,9,10],[4,10,5],[5,10,7],[6,7,11],[6,11,8],[7,10,11],[8,11,9],[9,11,10]]},i[4]={vertex:[[0,0,1.070722],[.7148135,0,.7971752],[-.104682,.7071068,.7971752],[-.6841528,.2071068,.7971752],[-.104682,-.7071068,.7971752],[.6101315,.7071068,.5236279],[1.04156,.2071068,.1367736],[.6101315,-.7071068,.5236279],[-.3574067,1,.1367736],[-.7888348,-.5,.5236279],[-.9368776,.5,.1367736],[-.3574067,-1,.1367736],[.3574067,1,-.1367736],[.9368776,-.5,-.1367736],[.7888348,.5,-.5236279],[.3574067,-1,-.1367736],[-.6101315,.7071068,-.5236279],[-1.04156,-.2071068,-.1367736],[-.6101315,-.7071068,-.5236279],[.104682,.7071068,-.7971752],[.6841528,-.2071068,-.7971752],[.104682,-.7071068,-.7971752],[-.7148135,0,-.7971752],[0,0,-1.070722]],face:[[0,2,3],[1,6,5],[4,9,11],[7,15,13],[8,16,10],[12,14,19],[17,22,18],[20,21,23],[0,1,5,2],[0,3,9,4],[0,4,7,1],[1,7,13,6],[2,5,12,8],[2,8,10,3],[3,10,17,9],[4,11,15,7],[5,6,14,12],[6,13,20,14],[8,12,19,16],[9,17,18,11],[10,16,22,17],[11,18,21,15],[13,15,21,20],[14,20,23,19],[16,19,23,22],[18,22,23,21]]},i[5]={vertex:[[0,0,1.322876],[1.309307,0,.1889822],[-.9819805,.8660254,.1889822],[.1636634,-1.299038,.1889822],[.3273268,.8660254,-.9449112],[-.8183171,-.4330127,-.9449112]],face:[[0,3,1],[2,4,5],[0,1,4,2],[0,2,5,3],[1,3,5,4]]},i[6]={vertex:[[0,0,1.159953],[1.013464,0,.5642542],[-.3501431,.9510565,.5642542],[-.7715208,-.6571639,.5642542],[.6633206,.9510565,-.03144481],[.8682979,-.6571639,-.3996071],[-1.121664,.2938926,-.03144481],[-.2348831,-1.063314,-.3996071],[.5181548,.2938926,-.9953061],[-.5850262,-.112257,-.9953061]],face:[[0,1,4,2],[0,2,6,3],[1,5,8,4],[3,6,9,7],[5,7,9,8],[0,3,7,5,1],[2,4,8,9,6]]},i[7]={vertex:[[0,0,1.118034],[.8944272,0,.6708204],[-.2236068,.8660254,.6708204],[-.7826238,-.4330127,.6708204],[.6708204,.8660254,.2236068],[1.006231,-.4330127,-.2236068],[-1.006231,.4330127,.2236068],[-.6708204,-.8660254,-.2236068],[.7826238,.4330127,-.6708204],[.2236068,-.8660254,-.6708204],[-.8944272,0,-.6708204],[0,0,-1.118034]],face:[[0,1,4,2],[0,2,6,3],[1,5,8,4],[3,6,10,7],[5,9,11,8],[7,10,11,9],[0,3,7,9,5,1],[2,4,8,11,10,6]]},i[8]={vertex:[[-.729665,.670121,.319155],[-.655235,-.29213,-.754096],[-.093922,-.607123,.537818],[.702196,.595691,.485187],[.776626,-.36656,-.588064]],face:[[1,4,2],[0,1,2],[3,0,2],[4,3,2],[4,1,0,3]]},i[9]={vertex:[[-.868849,-.100041,.61257],[-.329458,.976099,.28078],[-.26629,-.013796,-.477654],[-.13392,-1.034115,.229829],[.738834,.707117,-.307018],[.859683,-.535264,-.338508]],face:[[3,0,2],[5,3,2],[4,5,2],[1,4,2],[0,1,2],[0,3,5,4,1]]},i[10]={vertex:[[-.610389,.243975,.531213],[-.187812,-.48795,-.664016],[-.187812,.9759,-.664016],[.187812,-.9759,.664016],[.798201,.243975,.132803]],face:[[1,3,0],[3,4,0],[3,1,4],[0,2,1],[0,4,2],[2,4,1]]},i[11]={vertex:[[-1.028778,.392027,-.048786],[-.640503,-.646161,.621837],[-.125162,-.395663,-.540059],[.004683,.888447,-.651988],[.125161,.395663,.540059],[.632925,-.791376,.433102],[1.031672,.157063,-.354165]],face:[[3,2,0],[2,1,0],[2,5,1],[0,4,3],[0,1,4],[4,1,5],[2,3,6],[3,4,6],[5,2,6],[4,5,6]]},i[12]={vertex:[[-.669867,.334933,-.529576],[-.669867,.334933,.529577],[-.4043,1.212901,0],[-.334933,-.669867,-.529576],[-.334933,-.669867,.529577],[.334933,.669867,-.529576],[.334933,.669867,.529577],[.4043,-1.212901,0],[.669867,-.334933,-.529576],[.669867,-.334933,.529577]],face:[[8,9,7],[6,5,2],[3,8,7],[5,0,2],[4,3,7],[0,1,2],[9,4,7],[1,6,2],[9,8,5,6],[8,3,0,5],[3,4,1,0],[4,9,6,1]]},i[13]={vertex:[[-.931836,.219976,-.264632],[-.636706,.318353,.692816],[-.613483,-.735083,-.264632],[-.326545,.979634,0],[-.318353,-.636706,.692816],[-.159176,.477529,-.856368],[.159176,-.477529,-.856368],[.318353,.636706,.692816],[.326545,-.979634,0],[.613482,.735082,-.264632],[.636706,-.318353,.692816],[.931835,-.219977,-.264632]],face:[[11,10,8],[7,9,3],[6,11,8],[9,5,3],[2,6,8],[5,0,3],[4,2,8],[0,1,3],[10,4,8],[1,7,3],[10,11,9,7],[11,6,5,9],[6,2,0,5],[2,4,1,0],[4,10,7,1]]},i[14]={vertex:[[-.93465,.300459,-.271185],[-.838689,-.260219,-.516017],[-.711319,.717591,.128359],[-.710334,-.156922,.080946],[-.599799,.556003,-.725148],[-.503838,-.004675,-.969981],[-.487004,.26021,.48049],[-.460089,-.750282,-.512622],[-.376468,.973135,-.325605],[-.331735,-.646985,.084342],[-.254001,.831847,.530001],[-.125239,-.494738,-.966586],[.029622,.027949,.730817],[.056536,-.982543,-.262295],[.08085,1.087391,.076037],[.125583,-.532729,.485984],[.262625,.599586,.780328],[.391387,-.726999,-.716259],[.513854,-.868287,.139347],[.597475,.85513,.326364],[.641224,.109523,.783723],[.737185,-.451155,.538891],[.848705,-.612742,-.314616],[.976075,.365067,.32976],[1.072036,-.19561,.084927]],face:[[15,18,21],[12,20,16],[6,10,2],[3,0,1],[9,7,13],[2,8,4,0],[0,4,5,1],[1,5,11,7],[7,11,17,13],[13,17,22,18],[18,22,24,21],[21,24,23,20],[20,23,19,16],[16,19,14,10],[10,14,8,2],[15,9,13,18],[12,15,21,20],[6,12,16,10],[3,6,2,0],[9,3,1,7],[9,15,12,6,3],[22,17,11,5,4,8,14,19,23,24]]};var n,s,o,a,h,c,l=r.type<0||r.type>=i.length?0:r.type||0,u=r.size,f=r.sizeX||u||1,d=r.sizeY||u||1,p=r.sizeZ||u||1,m=r.custom||i[l],g=m.face.length,_=r.faceUV||new Array(g),v=r.faceColors,y=void 0===r.flat?!0:r.flat,x=0===r.sideOrientation?0:r.sideOrientation||e.Mesh.DEFAULTSIDE,E=[],T=[],A=[],b=[],M=[],P=0,S=0,C=[],I=0,D=0;if(y)for(D=0;g>D;D++)v&&void 0===v[D]&&(v[D]=new e.Color4(1,1,1,1)),_&&void 0===_[D]&&(_[D]=new e.Vector4(0,0,1,1));if(y)for(D=0;g>D;D++){var R=m.face[D].length;for(o=2*Math.PI/R,a=.5*Math.tan(o/2),h=.5,I=0;R>I;I++)E.push(m.vertex[m.face[D][I]][0]*f,m.vertex[m.face[D][I]][1]*d,m.vertex[m.face[D][I]][2]*p),C.push(P),P++,n=_[D].x+(_[D].z-_[D].x)*(.5+a),s=_[D].y+(_[D].w-_[D].y)*(h-.5),b.push(n,s),c=a*Math.cos(o)-h*Math.sin(o),h=a*Math.sin(o)+h*Math.cos(o),a=c,v&&M.push(v[D].r,v[D].g,v[D].b,v[D].a);for(I=0;R-2>I;I++)T.push(C[0+S],C[I+2+S],C[I+1+S]);S+=R}else{for(I=0;ID;D++)for(I=0;I=i;i++){var _=i%u,v=_/u*2*d*Math.PI,y=g(v),x=g(v+.01),E=x.subtract(y),T=x.add(y),A=e.Vector3.Cross(E,T);for(T=e.Vector3.Cross(A,E),A.normalize(),T.normalize(),n=0;f>n;n++){var b=n%f,M=b/f*2*Math.PI,P=-l*Math.cos(M),S=l*Math.sin(M);o.push(y.x+P*T.x+S*A.x),o.push(y.y+P*T.y+S*A.y),o.push(y.z+P*T.z+S*A.z),h.push(i/u),h.push(n/f)}}for(i=0;u>i;i++)for(n=0;f>n;n++){var C=(n+1)%f,I=i*f+n,D=(i+1)*f+n,R=(i+1)*f+C,w=i*f+C;s.push(w),s.push(D),s.push(I),s.push(w),s.push(R),s.push(D)}t.ComputeNormals(o,s,a),t._ComputeSides(m,o,s,a,h);var L=new t;return L.indices=s,L.positions=o,L.normals=a,L.uvs=h,L},t.ComputeNormals=function(e,t,r){var i=0,n=0,s=0,o=0,a=0,h=0,c=0,l=0,u=0,f=0,d=0,p=0,m=0,g=0;for(i=0;ii;i++)p=t[3*i],m=t[3*i+1],g=t[3*i+2],n=e[3*p]-e[3*m],s=e[3*p+1]-e[3*m+1],o=e[3*p+2]-e[3*m+2],a=e[3*g]-e[3*m],h=e[3*g+1]-e[3*m+1],c=e[3*g+2]-e[3*m+2],l=s*c-o*h,u=o*a-n*c,f=n*h-s*a,d=Math.sqrt(l*l+u*u+f*f),d=0===d?1:d,l/=d,u/=d,f/=d,r[3*p]+=l,r[3*p+1]+=u,r[3*p+2]+=f,r[3*m]+=l,r[3*m+1]+=u,r[3*m+2]+=f,r[3*g]+=l,r[3*g+1]+=u,r[3*g+2]+=f;for(i=0;io;o+=3)l=i[o],i[o]=i[o+2],i[o+2]=l;for(a=0;c>a;a++)n[a]=-n[a];break;case e.Mesh.DOUBLESIDE:for(var u=r.length,f=u/3,d=0;u>d;d++)r[u+d]=r[d];for(o=0;h>o;o+=3)i[o+h]=i[o+2]+f,i[o+1+h]=i[o+1]+f,i[o+2+h]=i[o]+f;for(a=0;c>a;a++)n[c+a]=-n[a];for(var p=s.length,m=0;p>m;m++)s[m+p]=s[m]}},t.ImportVertexData=function(r,i){var n=new t,s=r.positions;s&&n.set(s,e.VertexBuffer.PositionKind);var o=r.normals;o&&n.set(o,e.VertexBuffer.NormalKind);var a=r.uvs;a&&n.set(a,e.VertexBuffer.UVKind);var h=r.uv2s;h&&n.set(h,e.VertexBuffer.UV2Kind);var c=r.uv3s;c&&n.set(c,e.VertexBuffer.UV3Kind);var l=r.uv4s;l&&n.set(l,e.VertexBuffer.UV4Kind);var u=r.uv5s;u&&n.set(u,e.VertexBuffer.UV5Kind);var f=r.uv6s;f&&n.set(f,e.VertexBuffer.UV6Kind);var d=r.colors;d&&n.set(e.Color4.CheckColors4(d,s.length/3),e.VertexBuffer.ColorKind);var p=r.matricesIndices;p&&n.set(p,e.VertexBuffer.MatricesIndicesKind);var m=r.matricesWeights;m&&n.set(m,e.VertexBuffer.MatricesWeightsKind);var g=r.indices;g&&(n.indices=g),i.setAllVerticesData(n,r.updatable)},t}();e.VertexData=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.EnableFor=function(e){e._tags=e._tags||{},e.hasTags=function(){return t.HasTags(e)},e.addTags=function(r){return t.AddTagsTo(e,r)},e.removeTags=function(r){return t.RemoveTagsFrom(e,r)},e.matchesTagsQuery=function(r){return t.MatchesQuery(e,r)}},t.DisableFor=function(e){delete e._tags,delete e.hasTags,delete e.addTags,delete e.removeTags,delete e.matchesTagsQuery},t.HasTags=function(t){return t._tags?!e.Tools.IsEmpty(t._tags):!1},t.GetTags=function(e,t){if(void 0===t&&(t=!0),!e._tags)return null;if(t){var r=[];for(var i in e._tags)e._tags.hasOwnProperty(i)&&e._tags[i]===!0&&r.push(i);return r.join(" ")}return e._tags},t.AddTagsTo=function(e,r){if(r&&"string"==typeof r){var i=r.split(" ");for(var n in i)t._AddTagTo(e,i[n])}},t._AddTagTo=function(e,r){r=r.trim(),""!==r&&"true"!==r&&"false"!==r&&(r.match(/[\s]/)||r.match(/^([!]|([|]|[&]){2})/)||(t.EnableFor(e),e._tags[r]=!0))},t.RemoveTagsFrom=function(e,r){if(t.HasTags(e)){var i=r.split(" ");for(var n in i)t._RemoveTagFrom(e,i[n])}},t._RemoveTagFrom=function(e,t){delete e._tags[t]},t.MatchesQuery=function(r,i){return void 0===i?!0:""===i?t.HasTags(r):e.Internals.AndOrNotEvaluator.Eval(i,function(e){return t.HasTags(r)&&r._tags[e]})},t}();e.Tags=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(e){var t=function(){function e(){}return e.Eval=function(t,r){return t=t.match(/\([^\(\)]*\)/g)?t.replace(/\([^\(\)]*\)/g,function(t){return t=t.slice(1,t.length-1),e._HandleParenthesisContent(t,r)}):e._HandleParenthesisContent(t,r),"true"===t?!0:"false"===t?!1:e.Eval(t,r)},e._HandleParenthesisContent=function(t,r){r=r||function(e){return"true"===e?!0:!1};var i,n=t.split("||");for(var s in n){var o=e._SimplifyNegation(n[s].trim()),a=o.split("&&");if(a.length>1)for(var h=0;hthis.value;case t.IsLesser:return this._target[this._property]-1&&this._scene._actionManagers.splice(e,1)},t.prototype.getScene=function(){return this._scene},t.prototype.hasSpecificTriggers=function(e){for(var t=0;t-1)return!0}return!1},t.prototype.hasSpecificTrigger=function(e){for(var t=0;t=t._OnPickTrigger&&r.trigger<=t._OnPointerOutTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasPickTriggers",{get:function(){for(var e=0;e=t._OnPickTrigger&&r.trigger<=t._OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),t.prototype.registerAction=function(r){return r.trigger===t.OnEveryFrameTrigger&&this.getScene().actionManager!==this?(e.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager"),null):(this.actions.push(r),r._actionManager=this,r._prepare(),r)},t.prototype.processTrigger=function(e,r){for(var i=0;i0;if(2===r.type?f.push(s):f.push(i),m){for(var g=new Array,_=0;_0){var f=u.properties[0].value,d=null===u.properties[0].targetType?f:n.getMeshByName(f);l={trigger:e.ActionManager[u.name],parameter:d}}else l=e.ActionManager[u.name];for(var p=0;pa;a++){var h=s[a];h._resetPointsArrayCache(),h._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),h._createGlobalSubMesh(),h.computeWorldMatrix(!0)}}this.notifyUpdate(t)},t.prototype.updateVerticesDataDirectly=function(e,t,r){var i=this.getVertexBuffer(e);i&&(i.updateDirectly(t,r),this.notifyUpdate(e))},t.prototype.updateVerticesData=function(t,r,i){var n=this.getVertexBuffer(t);if(n){if(n.update(r),t===e.VertexBuffer.PositionKind){var s=n.getStrideSize();this._totalVertices=r.length/s,i&&(this._extend=e.Tools.ExtractMinAndMax(r,0,this._totalVertices));for(var o=this._meshes,a=o.length,h=0;a>h;h++){var c=o[h];if(c._resetPointsArrayCache(),i){c._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum);for(var l=0;lo;o++)s.push(i[o]);return s}return i},t.prototype.getVertexBuffer=function(e){return this.isReady()?this._vertexBuffers[e]:null},t.prototype.getVertexBuffers=function(){return this.isReady()?this._vertexBuffers:null},t.prototype.isVerticesDataPresent=function(e){return this._vertexBuffers?void 0!==this._vertexBuffers[e]:this._delayInfo?-1!==this._delayInfo.indexOf(e):!1},t.prototype.getVerticesDataKinds=function(){var e,t=[];if(!this._vertexBuffers&&this._delayInfo)for(e in this._delayInfo)t.push(e);else for(e in this._vertexBuffers)t.push(e);return t},t.prototype.setIndices=function(e,t){this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indices=e,0!==this._meshes.length&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),void 0!==t&&(this._totalVertices=t);for(var r=this._meshes,i=r.length,n=0;i>n;n++)r[n]._createGlobalSubMesh();this.notifyUpdate()},t.prototype.getTotalIndices=function(){return this.isReady()?this._indices.length:0},t.prototype.getIndices=function(e){if(!this.isReady())return null;var t=this._indices;if(e&&1!==this._meshes.length){for(var r=t.length,i=[],n=0;r>n;n++)i.push(t[n]);return i}return t},t.prototype.getIndexBuffer=function(){return this.isReady()?this._indexBuffer:null},t.prototype.releaseForMesh=function(e,t){var r=this._meshes,i=r.indexOf(e);if(-1!==i){for(var n in this._vertexBuffers)this._vertexBuffers[n].dispose();this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer)&&(this._indexBuffer=null),r.splice(i,1),e._geometry=null,0===r.length&&t&&this.dispose()}},t.prototype.applyToMesh=function(e){if(e._geometry!==this){var t=e._geometry;t&&t.releaseForMesh(e);var r=this._meshes;e._geometry=this,this._scene.pushGeometry(this),r.push(e),this.isReady()?this._applyToMesh(e):e._boundingInfo=this._boundingInfo}},t.prototype._applyToMesh=function(t){var r=this._meshes.length;for(var i in this._vertexBuffers)1===r&&this._vertexBuffers[i].create(),this._vertexBuffers[i]._buffer.references=r,i===e.VertexBuffer.PositionKind&&(t._resetPointsArrayCache(),this._extend||(this._extend=e.Tools.ExtractMinAndMax(this._vertexBuffers[i].getData(),0,this._totalVertices)),t._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),t._createGlobalSubMesh(),t._updateBoundingInfo());1===r&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),this._indexBuffer&&(this._indexBuffer.references=r)},t.prototype.notifyUpdate=function(e){this.onGeometryUpdated&&this.onGeometryUpdated(this,e)},t.prototype.load=function(t,r){var i=this;if(this.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADING){if(this.isReady())return void(r&&r());this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,t._addPendingData(this),e.Tools.LoadFile(this.delayLoadingFile,function(n){i._delayLoadingFunction(JSON.parse(n),i),i.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,i._delayInfo=[],t._removePendingData(i);for(var s=i._meshes,o=s.length,a=0;o>a;a++)i._applyToMesh(s[a]);r&&r()},function(){},t.database)}},t.prototype.isDisposed=function(){return this._isDisposed},t.prototype.dispose=function(){var t,r=this._meshes,i=r.length;for(t=0;i>t;t++)this.releaseForMesh(r[t]);this._meshes=[];for(var n in this._vertexBuffers)this._vertexBuffers[n].dispose();this._vertexBuffers=[],this._totalVertices=0,this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indexBuffer=null,this._indices=[],this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this.delayLoadingFile=null,this._delayLoadingFunction=null,this._delayInfo=[],this._boundingInfo=null,this._scene.removeGeometry(this),this._isDisposed=!0},t.prototype.copy=function(r){var i=new e.VertexData;i.indices=[];for(var n=this.getIndices(),s=0;s0){var a=new Float32Array(t,o.positionsAttrDesc.offset,o.positionsAttrDesc.count);r.setVerticesData(e.VertexBuffer.PositionKind,a,!1)}if(o.normalsAttrDesc&&o.normalsAttrDesc.count>0){var h=new Float32Array(t,o.normalsAttrDesc.offset,o.normalsAttrDesc.count);r.setVerticesData(e.VertexBuffer.NormalKind,h,!1)}if(o.uvsAttrDesc&&o.uvsAttrDesc.count>0){var c=new Float32Array(t,o.uvsAttrDesc.offset,o.uvsAttrDesc.count);r.setVerticesData(e.VertexBuffer.UVKind,c,!1)}if(o.uvs2AttrDesc&&o.uvs2AttrDesc.count>0){var l=new Float32Array(t,o.uvs2AttrDesc.offset,o.uvs2AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV2Kind,l,!1)}if(o.uvs3AttrDesc&&o.uvs3AttrDesc.count>0){var u=new Float32Array(t,o.uvs3AttrDesc.offset,o.uvs3AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV3Kind,u,!1)}if(o.uvs4AttrDesc&&o.uvs4AttrDesc.count>0){var f=new Float32Array(t,o.uvs4AttrDesc.offset,o.uvs4AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV4Kind,f,!1)}if(o.uvs5AttrDesc&&o.uvs5AttrDesc.count>0){var d=new Float32Array(t,o.uvs5AttrDesc.offset,o.uvs5AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV5Kind,d,!1)}if(o.uvs6AttrDesc&&o.uvs6AttrDesc.count>0){var p=new Float32Array(t,o.uvs6AttrDesc.offset,o.uvs6AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV6Kind,p,!1)}if(o.colorsAttrDesc&&o.colorsAttrDesc.count>0){var m=new Float32Array(t,o.colorsAttrDesc.offset,o.colorsAttrDesc.count);r.setVerticesData(e.VertexBuffer.ColorKind,m,!1,o.colorsAttrDesc.stride)}if(o.matricesIndicesAttrDesc&&o.matricesIndicesAttrDesc.count>0){var g=new Int32Array(t,o.matricesIndicesAttrDesc.offset,o.matricesIndicesAttrDesc.count);r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,g,!1)}if(o.matricesWeightsAttrDesc&&o.matricesWeightsAttrDesc.count>0){var _=new Float32Array(t,o.matricesWeightsAttrDesc.offset,o.matricesWeightsAttrDesc.count);r.setVerticesData(e.VertexBuffer.MatricesWeightsKind,_,!1)}if(o.indicesAttrDesc&&o.indicesAttrDesc.count>0){var v=new Int32Array(t,o.indicesAttrDesc.offset,o.indicesAttrDesc.count);r.setIndices(v)}if(o.subMeshesAttrDesc&&o.subMeshesAttrDesc.count>0){var y=new Int32Array(t,o.subMeshesAttrDesc.offset,5*o.subMeshesAttrDesc.count);r.subMeshes=[];for(var x=0;x>8),P.push((16711680&S)>>16),P.push(S>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,P,!1)}if(t.matricesIndicesExtra)if(t.matricesIndicesExtra._isExpanded)delete t.matricesIndices._isExpanded,r.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,t.matricesIndicesExtra,!1);else{for(var P=[],x=0;x>8),P.push((16711680&S)>>16),P.push(S>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,P,!1); }t.matricesWeights&&r.setVerticesData(e.VertexBuffer.MatricesWeightsKind,t.matricesWeights,!1),t.matricesWeightsExtra&&r.setVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,t.matricesWeightsExtra,!1),r.setIndices(t.indices)}if(t.subMeshes){r.subMeshes=[];for(var C=0;Cthis._maxX||tthis._maxZ)return this.position.y;this._heightQuads&&0!=this._heightQuads.length||this._computeHeightQuads();var r=this._getFacetAt(e,t),i=-(r.x*e+r.z*t+r.w)/r.y;return i*this.scaling.y+this.position.y},r.prototype.getNormalAtCoordinates=function(t,r){var i=new e.Vector3(0,1,0);return this.getNormalAtCoordinatesToRef(t,r,i),i},r.prototype.getNormalAtCoordinatesToRef=function(e,t,r){if(e-=this.position.x,t-=this.position.z,e/=this.scaling.x,t/=this.scaling.z,!(ethis._maxX||tthis._maxZ)){this._heightQuads&&0!=this._heightQuads.length||this._computeHeightQuads();var i=this._getFacetAt(e,t);r.x=i.x,r.y=i.y,r.z=i.z}},r.prototype._getFacetAt=function(e,t){var r,i=Math.floor((e+this._maxX)*this._subdivisions/this._width),n=Math.floor(-(t+this._maxZ)*this._subdivisions/this._height+this._subdivisions),s=this._heightQuads[n*this._subdivisions+i];return r=tt.name?1:-1});for(var t=0;t0&&t.z<1){this._drawingContext.font="normal 12px Segoe UI";var s=this._drawingContext.measureText(e),o=t.x-s.width/2,a=t.y,h=this._drawingCanvas.getBoundingClientRect();this._showUI&&this._isClickInsideRect(h.left*this._ratio+o-5,h.top*this._ratio+a-r-12,s.width+10,17)&&i(),this._drawingContext.beginPath(),this._drawingContext.rect(o-5,a-r-12,s.width+10,17),this._drawingContext.fillStyle=n(),this._drawingContext.globalAlpha=.5,this._drawingContext.fill(),this._drawingContext.globalAlpha=1,this._drawingContext.strokeStyle="#FFFFFF",this._drawingContext.lineWidth=1,this._drawingContext.stroke(),this._drawingContext.fillStyle="#FFFFFF",this._drawingContext.fillText(e,o,a-r),this._drawingContext.beginPath(),this._drawingContext.arc(t.x,a,5,0,2*Math.PI,!1),this._drawingContext.fill()}},t.prototype._isClickInsideRect=function(e,t,r,i){return this._clickPosition?this._clickPosition.xe+r?!1:this._clickPosition.yt+i?!1:!0:!1},t.prototype.isVisible=function(){return this._enabled},t.prototype.hide=function(){if(this._enabled){this._enabled=!1;var t=this._scene.getEngine();this._scene.unregisterBeforeRender(this._syncData),this._scene.unregisterAfterRender(this._syncUI),this._rootElement.removeChild(this._globalDiv),this._scene.forceShowBoundingBoxes=!1,this._scene.forceWireframe=!1,e.StandardMaterial.DiffuseTextureEnabled=!0,e.StandardMaterial.AmbientTextureEnabled=!0,e.StandardMaterial.SpecularTextureEnabled=!0,e.StandardMaterial.EmissiveTextureEnabled=!0,e.StandardMaterial.BumpTextureEnabled=!0,e.StandardMaterial.OpacityTextureEnabled=!0,e.StandardMaterial.ReflectionTextureEnabled=!0,e.StandardMaterial.LightmapEnabled=!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,this._scene.probesEnabled=!0,t.getRenderingCanvas().removeEventListener("click",this._onCanvasClick)}},t.prototype.show=function(e,t,r){if(void 0===e&&(e=!0),void 0===t&&(t=null),void 0===r&&(r=null),!this._enabled){this._enabled=!0,t?this._camera=t:this._camera=this._scene.activeCamera,this._showUI=e;var i=this._scene.getEngine();this._globalDiv=document.createElement("div"),this._rootElement=r||document.body,this._rootElement.appendChild(this._globalDiv),this._generateDOMelements(),i.getRenderingCanvas().addEventListener("click",this._onCanvasClick),this._syncPositions(),this._scene.registerBeforeRender(this._syncData),this._scene.registerAfterRender(this._syncUI)}},t.prototype._clearLabels=function(){this._drawingContext.clearRect(0,0,this._drawingCanvas.width,this._drawingCanvas.height);for(var e=0;eWindows:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Statistics",this._displayStatistics,function(e){t._displayStatistics=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Logs",this._displayLogs,function(e){t._displayLogs=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Meshes tree",this._displayTree,function(e){t._displayTree=e.checked,t._needToRefreshMeshesTree=!0}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"General:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Bounding boxes",this._scene.forceShowBoundingBoxes,function(e){t._scene.forceShowBoundingBoxes=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Clickable labels",this._labelsEnabled,function(e){t._labelsEnabled=e.checked,t._labelsEnabled||t._clearLabels()}),this._generateCheckBox(this._optionsSubsetDiv,"Generate user marks (F12)",e.Tools.PerformanceLogLevel===e.Tools.PerformanceUserMarkLogLevel,function(t){t.checked?e.Tools.PerformanceLogLevel=e.Tools.PerformanceUserMarkLogLevel:e.Tools.PerformanceLogLevel=e.Tools.PerformanceNoneLogLevel}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Rendering mode:",this.accentColor),this._generateRadio(this._optionsSubsetDiv,"Solid","renderMode",!this._scene.forceWireframe&&!this._scene.forcePointsCloud,function(e){e.checked&&(t._scene.forceWireframe=!1,t._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Wireframe","renderMode",this._scene.forceWireframe,function(e){e.checked&&(t._scene.forceWireframe=!0,t._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Point","renderMode",this._scene.forcePointsCloud,function(e){e.checked&&(t._scene.forceWireframe=!1,t._scene.forcePointsCloud=!0)}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Texture channels:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Diffuse",e.StandardMaterial.DiffuseTextureEnabled,function(t){e.StandardMaterial.DiffuseTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Ambient",e.StandardMaterial.AmbientTextureEnabled,function(t){e.StandardMaterial.AmbientTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Specular",e.StandardMaterial.SpecularTextureEnabled,function(t){e.StandardMaterial.SpecularTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Emissive",e.StandardMaterial.EmissiveTextureEnabled,function(t){e.StandardMaterial.EmissiveTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Bump",e.StandardMaterial.BumpTextureEnabled,function(t){e.StandardMaterial.BumpTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Opacity",e.StandardMaterial.OpacityTextureEnabled,function(t){e.StandardMaterial.OpacityTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Reflection",e.StandardMaterial.ReflectionTextureEnabled,function(t){e.StandardMaterial.ReflectionTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fresnel",e.StandardMaterial.FresnelEnabled,function(t){e.StandardMaterial.FresnelEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lightmap",e.StandardMaterial.LightmapEnabled,function(t){ e.StandardMaterial.LightmapEnabled=t.checked}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Options:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Animations",this._scene.animationsEnabled,function(e){t._scene.animationsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Collisions",this._scene.collisionsEnabled,function(e){t._scene.collisionsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fog",this._scene.fogEnabled,function(e){t._scene.fogEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lens flares",this._scene.lensFlaresEnabled,function(e){t._scene.lensFlaresEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lights",this._scene.lightsEnabled,function(e){t._scene.lightsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Particles",this._scene.particlesEnabled,function(e){t._scene.particlesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Post-processes",this._scene.postProcessesEnabled,function(e){t._scene.postProcessesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Probes",this._scene.probesEnabled,function(e){t._scene.probesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Procedural textures",this._scene.proceduralTexturesEnabled,function(e){t._scene.proceduralTexturesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Render targets",this._scene.renderTargetsEnabled,function(e){t._scene.renderTargetsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Shadows",this._scene.shadowsEnabled,function(e){t._scene.shadowsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Skeletons",this._scene.skeletonsEnabled,function(e){t._scene.skeletonsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Sprites",this._scene.spritesEnabled,function(e){t._scene.spritesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Textures",this._scene.texturesEnabled,function(e){t._scene.texturesEnabled=e.checked}),e.AudioEngine&&e.Engine.audioEngine.canUseWebAudio&&(this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Audio:",this.accentColor),this._generateRadio(this._optionsSubsetDiv,"Headphones","panningModel",this._scene.headphone,function(e){e.checked&&(t._scene.headphone=!0)}),this._generateRadio(this._optionsSubsetDiv,"Normal Speakers","panningModel",!this._scene.headphone,function(e){e.checked&&(t._scene.headphone=!1)}),this._generateCheckBox(this._optionsSubsetDiv,"Disable audio",!this._scene.audioEnabled,function(e){t._scene.audioEnabled=!e.checked})),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Tools:",this.accentColor),this._generateButton(this._optionsSubsetDiv,"Dump rendertargets",function(e){t._scene.dumpNextRenderTargets=!0}),this._generateButton(this._optionsSubsetDiv,"Run SceneOptimizer",function(r){e.SceneOptimizer.OptimizeAsync(t._scene)}),this._generateButton(this._optionsSubsetDiv,"Log camera object",function(e){t._camera?console.log(t._camera):console.warn("No camera defined, or debug layer created before camera creation!")}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._globalDiv.appendChild(this._statsDiv),this._globalDiv.appendChild(this._logDiv),this._globalDiv.appendChild(this._optionsDiv),this._globalDiv.appendChild(this._treeDiv)}},t.prototype._displayStats=function(){var t=this._scene,r=t.getEngine(),i=r.getGlInfo();this._statsSubsetDiv.innerHTML="Babylon.js v"+e.Engine.Version+" - "+e.Tools.Format(r.getFps(),0)+" fps

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


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

Render: "+e.Tools.Format(t.getRenderDuration())+" ms
Frame: "+e.Tools.Format(t.getLastFrameDuration())+" ms
Potential FPS: "+e.Tools.Format(1e3/t.getLastFrameDuration(),0)+"
Resolution: "+r.getRenderWidth()+"x"+r.getRenderHeight()+"
Extensions
Std derivatives: "+(r.getCaps().standardDerivatives?"Yes":"No")+"
Compressed textures: "+(r.getCaps().s3tc?"Yes":"No")+"
Hardware instances: "+(r.getCaps().instancedArrays?"Yes":"No")+"
Texture float: "+(r.getCaps().textureFloat?"Yes":"No")+"

32bits indices: "+(r.getCaps().uintIndices?"Yes":"No")+"
Fragment depth: "+(r.getCaps().fragmentDepthSupported?"Yes":"No")+"
High precision shaders: "+(r.getCaps().highPrecisionShaderSupported?"Yes":"No")+"
Draw buffers: "+(r.getCaps().drawBuffersExtension?"Yes":"No")+"

Caps.
Max textures units: "+r.getCaps().maxTexturesImageUnits+"
Max textures size: "+r.getCaps().maxTextureSize+"
Max anisotropy: "+r.getCaps().maxAnisotropy+"
Info
WebGL feature level: "+r.webGLVersion+"
"+i.version+"

"+i.renderer+"
",this.customStatsFunction&&(this._statsSubsetDiv.innerHTML+=this._statsSubsetDiv.innerHTML)},t}();e.DebugLayer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,r){var i=this;void 0===t&&(t=""),void 0===r&&(r="black"),this._renderingCanvas=e,this._loadingText=t,this._loadingDivBackgroundColor=r,this._resizeLoadingUI=function(){var e=i._renderingCanvas.getBoundingClientRect();i._loadingDiv.style.position="absolute",i._loadingDiv.style.left=e.left+"px",i._loadingDiv.style.top=e.top+"px",i._loadingDiv.style.width=e.width+"px",i._loadingDiv.style.height=e.height+"px"}}return e.prototype.displayLoadingUI=function(){var e=this;if(!this._loadingDiv){this._loadingDiv=document.createElement("div"),this._loadingDiv.id="babylonjsLoadingDiv",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),this._loadingTextDiv.innerHTML=this._loadingText;var t=new Image;t.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAARbSURBVHhe7Z09aFNRFMc716kuLrq4FdyLq4Wi4CAoRQcR0UJBUBdRiuLSIYMo6CA4FF2sgw6CFAdFUOpSQYcWO4hD26UQCfXrIQrx/JJzw1OSWq3NPeL/B4Fy+0jg/HO+7j3vpUcI8b/Q39+/49ihfWdPHT94Yf/e3Se3bd263f8lus218TPn6vV6Ya8Wi/MzNRNmj18iusX9W1evmP1/EKNEIVG6CMbG6E3bt+fT++pHha8NoHdT72bLE8NDg7tGU64gLLndV4Wc4m8j/pS+vr4tGB/DT16v3Fyr8dvBe/jbit8BL0AES9LX1iPAz+BR/hFiLVCynj95dPzNy6fv3IZ/k4L3948Sq7FzYGBg4vLFGxitabuOFCbWNKGrMnbiUuo18KaV6tIHv6YtvL9/nOgE31jCktmrY7k6+/zhE4yP4Vf7hiNqh/BWWEl8mzDol4p22Lf7cIdvdUMEvv0Y2S9fE5S1hLzpqTsPkiep//gFGPnR3Yl7GL5p/xYFBrTwM+iXio3GqpwDGL5p/xYNIX7XG8Q6IJRgdIzf1KBBgafII7oMidhyQtVFaMA2Bt7il4huQRhaXphbcR2g4RXqBzKAGHiCCwGFVUAj/m/RTRDj29cvn10I0PZ3LghH5f4CL1EFlQmqqXK3jDDKFxmhQ3Yt6oQseUZGKmMnTpsOqc8o1F9kBOMjQlOLeqEeIyOc6JV6jYLJD/+XyIFvnzdgl9aXRQ5I2qZDK1SpospMqaoqON/wZZGDciLnMMiXRS7IF4hhqMTNTdk7CFu+LHLhR7BQqBvPDJUUQqCGvCMATHUgBmhWNgApmdOda9YpM+VwRYfuyyIXDK8hBlilNerLIheMZCKGwlUAyru6GlwOgPUbRxADdJ9FAChxXY864viyyEXqPxhc0M2TAfAbatSdRyHtXymhByEdRnE3ky+JnHAIhSA0h74kckETmHoQbSgGwJrCIRMEPSRIBCRIMAhZaYhaggQhJXUJEoRU9mofKwh+F22dLRRfEjlJM7w6KQwCoQpBOKTyJZETjmwRxKqtGV8SOSkNOGjKPQppBEgDDkFgpxdBVGkFgaYQQXRIFQSObk0P5ZFIpAZRHXsQ0r0hCluBWKkuvVbYCkQaCdL5ehBScudJP4yY+rLISdps1NBDEJKXMMmoSfggWC4ZQRR17oFYXph7hSiquIKQ+hJGTX1J5MYSPD/GVdNzsgLBwZVCVyAQAkF0ohiI/c1fS6tNXq9UfEnkhudmIQolsS+J3Hh/UtNDzQLhj42VKJFInqLwFYiUU5ToA+HdfI0JevUpQUAIn+vSz2lHIuUV/dJOIHhOY/IWVWGBIHQtzs88s9zyWBuTgcBLzGOmeNnfF/QslSDgMeQW85i3DOQxuipxAkCyZ8SIm4Omp+7MMlCB59j6sKZcMoM4iIEoeI2J9AKxrFobZx0v4vYInuHFS4J1GQRCAGaLEYQXfyMML5XSQgghhBBCCCH+cXp6vgNhKpSKX/XdOAAAAABJRU5ErkJggg==",t.style.position="absolute",t.style.left="50%",t.style.top="50%",t.style.marginLeft="-50px",t.style.marginTop="-50px",t.style.transition="transform 1.0s ease",t.style.webkitTransition="-webkit-transform 1.0s ease";var r=360,i=function(){r+=360,t.style.transform="rotateZ("+r+"deg)",t.style.webkitTransform="rotateZ("+r+"deg)"};t.addEventListener("transitionend",i),t.addEventListener("webkitTransitionEnd",i),this._loadingDiv.appendChild(t);var n=new Image;n.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAAYJSURBVHhe7Zy/qx1FFMff/2Av2Nvbi4WFiiAEY/OQ2IgQsbCJQoqkCAgpFLXyoZURLfwBIiIpgqZJoYQYlWelNsIrNOxDJcrzfHe+G97dnTl75u7euzv7zgcWHrlnZmfOmXPmzI/NjuM4juM4juM4juM4juM4juM4juM4juM45fPic08/uHf5/CvffH7lnT8PfrtxdHS0n3p+/fHGl5+89/prr5599iEWd8bg0rkXHoFyqehKnlxQpjYSDHTm9JMPsGrHylOPPXofvICKXMcIGtXdf/76AYbm6xyNW9e/eAtKC7rbKLXnvHHx5Sf4auc4Ek7OQkFU1Dap/vv37k/wSjblZANFiFIGzw98hhizwqBgs04mCBdQRNCHidoAEtY+lLIvtSdoGFeyql2ZH57HBH4sE7O+o/r9l+8/ZXUni68+2jsHBQQ9qNRGeP/tSxdSYQX/roUcpL4/f3vtM9TD+jTq92n1LQ7jxF1hhGPtwWL3gGccy8JuS1r8sVWBGXNVdSKMYjBGPUJjCzooiGuSpnwlnnOGP2dhHRSLNgpHp2oMKIriK8TmG4Qh/rwW8D6pps9b9im+LDDipXOqMVJrAngBfg9i98gevWKA+/nnCod3Dr5GfaHaDgidVym6HKRjGIkpqthcAVKGxNqBImbEo66kjCih8AOpNmkUmbMuUrR8kEqiU6FvHZLGAPJ71JCYSyhiBqmwFE2GoD6jLGIfDHtG6EzoU4dK21PCqIRMEF0FGRjFzGDtIkXVAdATvsqfT9CJ0JcOFdYiFIsiMlqYy1YOFpQo2OddqBtyEaq9y+efoVh5oPHoROjLKn0j3JIE5Ka8UqZRtGrMnneX6yVofOhDh94MSbznTcpqmDOt1vyQzOgaJAF4F3JBfIXesrNEGWWmjIX7UBZ6jRJbBMLg/DmJiKUGVHleIpnVNTa+jakzkAviJqLhi4MC9XQGBrZeKJZESSrKy7ik0VGFWhQBRDTHIACKQ5l9nAjy75gya4a2w+Jhs0FJdc0xX/GwUbAqFBkZi7QpJ2w16WUbjFyK9MJF3KaoEM74KhVtLrQOrsmRxkbdHEqmSC/c+EuGnIFkjW7Ih2Kr4CCMIvNG2hrrgLpCjiFloooYCjyYrzCRyvhyBthkIPuQtsZGdnbMTezyDiU71KTC5zr7aVsHbsz2tllrEkS5UHwU1tq1HbtPW4UbeB0O7xx8R5EsMJql+BheUmHjkNVmIRP7LutoM3+D4O4tG7vCkNO9ESZ4lL3J6rKRMPx4qKbD/A0icf8CG7tC7kTahnMTwleuYSrsS7GatRAvfZh1tTm5BmmQCdZ8a0Sefe28xUrRBkmFLKy8KTIKUDRX0Y1xagPgwbaIdeFnQULmKak3xvwNMkVGgok/N5XNoehJvejRlCDl9escI28dJU0tZ++nBTJE9mEF647x5Ehbo4s5hDOKFIU0PdofeA5F5k1q63zIWmQqNI/P3ZubjFTqKxQ3jyjHAOX0RdlgVO9hzRFpczRcjZ3Gbxxpc7Qj6+5pTYF2OFXawNI+yDGf1k2NcvOlzBQeDQ/t7zD7DsEDpJ2xATXaNtDWUS4IzP4DS2ljajAVu57SUkYw245ptxZxA5JiZaJ0DswudGn3kYUy54426EjoT4dZfYbccxC2nI92cDkZHQr96jD4AGkMDKeSy/COBsRe6VTSKFN6irLeaCh3IteQjt1E5+oudsG/b/2DfZ5AqsYo8vMDK9LB1HzSsLWvlGThdxXvC6+NsqyPPWP0pMINtbdsajfVeC6f/GZ+cdAofQoB1d+Hf9waY98I7+RXWab3Lt4zYkjHtTnlOLXHYMsCh1zWeQYehu1zfNPOOiys/d91LAKEBSgh6MJMbSA82AaHofDgAIwbgvVvlLNS11nModMm4UZergLHZBZrodmBuA3lBB1thdorSjkOmATMDwg/UBQVtglqQyx6fbEJ+H3IWIapjYAjAfeIgeCMHldueJvFaqDaAHhwf8qNsEEQ1iQbOoUUGIbCLRc8+Bvfp4jyd2FEijuO4ziO4ziO4ziO4ziO4ziO4ziO4ziOUzw7O/8D0P7rcZ/GEboAAAAASUVORK5CYII=",n.style.position="absolute",n.style.left="50%",n.style.top="50%",n.style.marginLeft="-50px",n.style.marginTop="-50px",this._loadingDiv.appendChild(n),this._resizeLoadingUI(),window.addEventListener("resize",this._resizeLoadingUI),this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor,document.body.appendChild(this._loadingDiv),setTimeout(function(){e._loadingDiv.style.opacity="1",t.style.transform="rotateZ(360deg)",t.style.webkitTransform="rotateZ(360deg)"},0)}},e.prototype.hideLoadingUI=function(){var e=this;if(this._loadingDiv){var t=function(){e._loadingDiv&&(document.body.removeChild(e._loadingDiv),window.removeEventListener("resize",e._resizeLoadingUI),e._loadingDiv=null)};this._loadingDiv.style.opacity="0",this._loadingDiv.addEventListener("transitionend",t)}},Object.defineProperty(e.prototype,"loadingUIText",{set:function(e){this._loadingText=e,this._loadingTextDiv&&(this._loadingTextDiv.innerHTML=this._loadingText)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"loadingUIBackgroundColor",{get:function(){return this._loadingDivBackgroundColor},set:function(e){this._loadingDivBackgroundColor=e,this._loadingDiv&&(this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor)},enumerable:!0,configurable:!0}),e}();e.DefaultLoadingScreen=t}(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore={anaglyphPixelShader:"precision highp float;\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:"precision highp float;\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:"precision highp float;\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}",chromaticAberrationPixelShader:"precision highp float;\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}",colorPixelShader:"precision highp float;\r\n\r\nuniform vec4 color;\r\n\r\nvoid main(void) {\r\n gl_FragColor = color;\r\n}",colorVertexShader:"precision highp float;\r\n\r\n// Attributes\r\nattribute vec3 position;\r\n\r\n// Uniforms\r\nuniform mat4 worldViewProjection;\r\n\r\nvoid main(void) {\r\n gl_Position = worldViewProjection * vec4(position, 1.0);\r\n}",colorCorrectionPixelShader:"precision highp float;\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:"precision highp float;\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 BUMP\r\n#extension GL_OES_standard_derivatives : enable\r\n#endif\r\n\r\n#ifdef LOGARITHMICDEPTH\r\n#extension GL_EXT_frag_depth : enable\r\n#endif\r\n\r\nprecision highp float;\r\n\r\n// Constants\r\n#define RECIPROCAL_PI2 0.15915494\r\n\r\nuniform vec3 vEyePosition;\r\nuniform vec3 vAmbientColor;\r\nuniform vec4 vDiffuseColor;\r\n#ifdef SPECULARTERM\r\nuniform vec4 vSpecularColor;\r\n#endif\r\nuniform vec3 vEmissiveColor;\r\n\r\n// Input\r\nvarying vec3 vPositionW;\r\n\r\n#ifdef NORMAL\r\nvarying vec3 vNormalW;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n// Lights\r\n#ifdef LIGHT0\r\nuniform vec4 vLightData0;\r\nuniform vec4 vLightDiffuse0;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular0;\r\n#endif\r\n#ifdef SHADOW0\r\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\r\nvarying vec4 vPositionFromLight0;\r\nuniform sampler2D shadowSampler0;\r\n#else\r\nuniform samplerCube shadowSampler0;\r\n#endif\r\nuniform vec3 shadowsInfo0;\r\n#endif\r\n#ifdef SPOTLIGHT0\r\nuniform vec4 vLightDirection0;\r\n#endif\r\n#ifdef HEMILIGHT0\r\nuniform vec3 vLightGround0;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT1\r\nuniform vec4 vLightData1;\r\nuniform vec4 vLightDiffuse1;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular1;\r\n#endif\r\n#ifdef SHADOW1\r\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\r\nvarying vec4 vPositionFromLight1;\r\nuniform sampler2D shadowSampler1;\r\n#else\r\nuniform samplerCube shadowSampler1;\r\n#endif\r\nuniform vec3 shadowsInfo1;\r\n#endif\r\n#ifdef SPOTLIGHT1\r\nuniform vec4 vLightDirection1;\r\n#endif\r\n#ifdef HEMILIGHT1\r\nuniform vec3 vLightGround1;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT2\r\nuniform vec4 vLightData2;\r\nuniform vec4 vLightDiffuse2;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular2;\r\n#endif\r\n#ifdef SHADOW2\r\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\r\nvarying vec4 vPositionFromLight2;\r\nuniform sampler2D shadowSampler2;\r\n#else\r\nuniform samplerCube shadowSampler2;\r\n#endif\r\nuniform vec3 shadowsInfo2;\r\n#endif\r\n#ifdef SPOTLIGHT2\r\nuniform vec4 vLightDirection2;\r\n#endif\r\n#ifdef HEMILIGHT2\r\nuniform vec3 vLightGround2;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT3\r\nuniform vec4 vLightData3;\r\nuniform vec4 vLightDiffuse3;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular3;\r\n#endif\r\n#ifdef SHADOW3\r\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\r\nvarying vec4 vPositionFromLight3;\r\nuniform sampler2D shadowSampler3;\r\n#else\r\nuniform samplerCube shadowSampler3;\r\n#endif\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 LIGHTMAP\r\nvarying vec2 vLightmapUV;\r\nuniform vec2 vLightmapInfos;\r\nuniform sampler2D lightmapSampler;\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform sampler2D specularSampler;\r\n#endif\r\n\r\n// Fresnel\r\n#ifdef FRESNEL\r\nfloat computeFresnelTerm(vec3 viewDirection, vec3 worldNormal, float bias, float power)\r\n{\r\n float fresnelTerm = pow(bias + abs(dot(viewDirection, worldNormal)), power);\r\n return clamp(fresnelTerm, 0., 1.);\r\n}\r\n#endif\r\n\r\n#ifdef DIFFUSEFRESNEL\r\nuniform vec4 diffuseLeftColor;\r\nuniform vec4 diffuseRightColor;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\nuniform vec4 opacityParts;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\nuniform vec4 emissiveLeftColor;\r\nuniform vec4 emissiveRightColor;\r\n#endif\r\n\r\n// Reflection\r\n#ifdef REFLECTION\r\nuniform vec2 vReflectionInfos;\r\n\r\n#ifdef REFLECTIONMAP_3D\r\nuniform samplerCube reflectionCubeSampler;\r\n#else\r\nuniform sampler2D reflection2DSampler;\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_SKYBOX\r\nvarying vec3 vPositionUVW;\r\n#else\r\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\r\nvarying vec3 vDirectionW;\r\n#endif\r\n\r\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\r\nuniform mat4 reflectionMatrix;\r\n#endif\r\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION)\r\nuniform mat4 view;\r\n#endif\r\n#endif\r\n\r\nvec3 computeReflectionCoords(vec4 worldPos, vec3 worldNormal)\r\n{\r\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\r\n vec3 direction = normalize(vDirectionW);\r\n\r\n float t = clamp(direction.y * -0.5 + 0.5, 0., 1.0);\r\n float s = atan(direction.z, direction.x) * RECIPROCAL_PI2 + 0.5;\r\n\r\n return vec3(s, t, 0);\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR\r\n\r\n vec3 cameraToVertex = normalize(worldPos.xyz - vEyePosition);\r\n vec3 r = reflect(cameraToVertex, worldNormal);\r\n float t = clamp(r.y * -0.5 + 0.5, 0., 1.0);\r\n float s = atan(r.z, r.x) * RECIPROCAL_PI2 + 0.5;\r\n\r\n return vec3(s, t, 0);\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_SPHERICAL\r\n vec3 viewDir = normalize(vec3(view * worldPos));\r\n vec3 viewNormal = normalize(vec3(view * vec4(worldNormal, 0.0)));\r\n\r\n vec3 r = reflect(viewDir, viewNormal);\r\n r.z = r.z - 1.0;\r\n\r\n float m = 2.0 * length(r);\r\n\r\n return vec3(r.x / m + 0.5, 1.0 - r.y / m - 0.5, 0);\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_PLANAR\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#endif\r\n\r\n#ifdef REFLECTIONMAP_CUBIC\r\n vec3 viewDir = worldPos.xyz - vEyePosition;\r\n vec3 coords = reflect(viewDir, worldNormal);\r\n#ifdef INVERTCUBICMAP\r\n coords.y = 1.0 - coords.y;\r\n#endif\r\n return vec3(reflectionMatrix * vec4(coords, 0));\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_PROJECTION\r\n return vec3(reflectionMatrix * (view * worldPos));\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_SKYBOX\r\n return vPositionUVW;\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_EXPLICIT\r\n return vec3(0, 0, 0);\r\n#endif\r\n}\r\n\r\n#ifdef REFLECTIONFRESNEL\r\nuniform vec4 reflectionLeftColor;\r\nuniform vec4 reflectionRightColor;\r\n#endif\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\n#if defined(POINTLIGHT0) || defined(POINTLIGHT1) || defined(POINTLIGHT2) || defined(POINTLIGHT3)\r\nuniform vec2 depthValues;\r\n\r\nfloat computeShadowCube(vec3 lightPosition, samplerCube shadowSampler, float darkness, float bias)\r\n{\r\n vec3 directionToLight = vPositionW - lightPosition;\r\n float depth = length(directionToLight);\r\n depth = (depth - depthValues.x) / (depthValues.y - depthValues.x);\r\n depth = clamp(depth, 0., 1.0);\r\n\r\n directionToLight = normalize(directionToLight);\r\n directionToLight.y = - directionToLight.y;\r\n\r\n float shadow = unpack(textureCube(shadowSampler, directionToLight)) + bias;\r\n\r\n if (depth > shadow)\r\n {\r\n return darkness;\r\n }\r\n return 1.0;\r\n}\r\n\r\nfloat computeShadowWithPCFCube(vec3 lightPosition, samplerCube shadowSampler, float mapSize, float bias, float darkness)\r\n{\r\n vec3 directionToLight = vPositionW - lightPosition;\r\n float depth = length(directionToLight);\r\n\r\n depth = (depth - depthValues.x) / (depthValues.y - depthValues.x);\r\n depth = clamp(depth, 0., 1.0);\r\n\r\n directionToLight = normalize(directionToLight);\r\n directionToLight.y = -directionToLight.y;\r\n\r\n float visibility = 1.;\r\n\r\n vec3 poissonDisk[4];\r\n poissonDisk[0] = vec3(-1.0, 1.0, -1.0);\r\n poissonDisk[1] = vec3(1.0, -1.0, -1.0);\r\n poissonDisk[2] = vec3(-1.0, -1.0, -1.0);\r\n poissonDisk[3] = vec3(1.0, -1.0, 1.0);\r\n\r\n // Poisson Sampling\r\n float biasedDepth = depth - bias;\r\n\r\n if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[0] * mapSize)) < biasedDepth) visibility -= 0.25;\r\n if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[1] * mapSize)) < biasedDepth) visibility -= 0.25;\r\n if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[2] * mapSize)) < biasedDepth) visibility -= 0.25;\r\n if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[3] * mapSize)) < biasedDepth) visibility -= 0.25;\r\n\r\n return min(1.0, visibility + darkness);\r\n}\r\n#endif\r\n\r\n#if defined(SPOTLIGHT0) || defined(SPOTLIGHT1) || defined(SPOTLIGHT2) || defined(SPOTLIGHT3) || defined(DIRLIGHT0) || defined(DIRLIGHT1) || defined(DIRLIGHT2) || defined(DIRLIGHT3)\r\nfloat computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness, float bias)\r\n{\r\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n depth = 0.5 * depth + vec3(0.5);\r\n vec2 uv = depth.xy;\r\n\r\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\r\n {\r\n return 1.0;\r\n }\r\n\r\n float shadow = unpack(texture2D(shadowSampler, uv)) + bias;\r\n\r\n if (depth.z > shadow)\r\n {\r\n return darkness;\r\n }\r\n return 1.;\r\n}\r\n\r\nfloat computeShadowWithPCF(vec4 vPositionFromLight, sampler2D shadowSampler, float mapSize, float bias, float darkness)\r\n{\r\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n depth = 0.5 * depth + vec3(0.5);\r\n vec2 uv = depth.xy;\r\n\r\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\r\n {\r\n return 1.0;\r\n }\r\n\r\n float visibility = 1.;\r\n\r\n vec2 poissonDisk[4];\r\n poissonDisk[0] = vec2(-0.94201624, -0.39906216);\r\n poissonDisk[1] = vec2(0.94558609, -0.76890725);\r\n poissonDisk[2] = vec2(-0.094184101, -0.92938870);\r\n poissonDisk[3] = vec2(0.34495938, 0.29387760);\r\n\r\n // Poisson Sampling\r\n float biasedDepth = depth.z - bias;\r\n\r\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[0] * mapSize)) < biasedDepth) visibility -= 0.25;\r\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[1] * mapSize)) < biasedDepth) visibility -= 0.25;\r\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[2] * mapSize)) < biasedDepth) visibility -= 0.25;\r\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[3] * mapSize)) < biasedDepth) visibility -= 0.25;\r\n\r\n return min(1.0, visibility + darkness);\r\n}\r\n\r\n// Thanks to http://devmaster.net/\r\nfloat unpackHalf(vec2 color)\r\n{\r\n return color.x + (color.y / 255.0);\r\n}\r\n\r\nfloat linstep(float low, float high, float v) {\r\n return clamp((v - low) / (high - low), 0.0, 1.0);\r\n}\r\n\r\nfloat ChebychevInequality(vec2 moments, float compare, float bias)\r\n{\r\n float p = smoothstep(compare - bias, compare, moments.x);\r\n float variance = max(moments.y - moments.x * moments.x, 0.02);\r\n float d = compare - moments.x;\r\n float p_max = linstep(0.2, 1.0, variance / (variance + d * d));\r\n\r\n return clamp(max(p, p_max), 0.0, 1.0);\r\n}\r\n\r\nfloat computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler, float bias, float darkness)\r\n{\r\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n depth = 0.5 * depth + vec3(0.5);\r\n vec2 uv = depth.xy;\r\n\r\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0 || depth.z >= 1.0)\r\n {\r\n return 1.0;\r\n }\r\n\r\n vec4 texel = texture2D(shadowSampler, uv);\r\n\r\n vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));\r\n return min(1.0, 1.0 - ChebychevInequality(moments, depth.z, bias) + darkness);\r\n}\r\n#endif\r\n#endif\r\n\r\n// Bump\r\n#ifdef BUMP\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#ifdef LOGARITHMICDEPTH\r\nuniform float logarithmicDepthConstant;\r\nvarying float vFragmentDepth;\r\n#endif\r\n\r\n// Fog\r\n#ifdef FOG\r\n\r\n#define FOGMODE_NONE 0.\r\n#define FOGMODE_EXP 1.\r\n#define FOGMODE_EXP2 2.\r\n#define FOGMODE_LINEAR 3.\r\n#define E 2.71828\r\n\r\nuniform vec4 vFogInfos;\r\nuniform vec3 vFogColor;\r\nvarying float fFogDistance;\r\n\r\nfloat CalcFogFactor()\r\n{\r\n float fogCoeff = 1.0;\r\n float fogStart = vFogInfos.y;\r\n float fogEnd = vFogInfos.z;\r\n float fogDensity = vFogInfos.w;\r\n\r\n if (FOGMODE_LINEAR == vFogInfos.x)\r\n {\r\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\r\n }\r\n else if (FOGMODE_EXP == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\r\n }\r\n else if (FOGMODE_EXP2 == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\r\n }\r\n\r\n return clamp(fogCoeff, 0.0, 1.0);\r\n}\r\n#endif\r\n\r\n// Light Computing\r\nstruct lightingInfo\r\n{\r\n vec3 diffuse;\r\n#ifdef SPECULARTERM\r\n vec3 specular;\r\n#endif\r\n};\r\n\r\nlightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, float range, float glossiness) {\r\n lightingInfo result;\r\n\r\n vec3 lightVectorW;\r\n float attenuation = 1.0;\r\n if (lightData.w == 0.)\r\n {\r\n vec3 direction = lightData.xyz - vPositionW;\r\n\r\n attenuation = max(0., 1.0 - length(direction) / range);\r\n lightVectorW = normalize(direction);\r\n }\r\n else\r\n {\r\n lightVectorW = normalize(-lightData.xyz);\r\n }\r\n\r\n // diffuse\r\n float ndl = max(0., dot(vNormal, lightVectorW));\r\n result.diffuse = ndl * diffuseColor * attenuation;\r\n\r\n#ifdef SPECULARTERM\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW + lightVectorW);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = pow(specComp, max(1., glossiness));\r\n\r\n result.specular = specComp * specularColor * attenuation;\r\n#endif\r\n return result;\r\n}\r\n\r\nlightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 diffuseColor, vec3 specularColor, float range, float glossiness) {\r\n lightingInfo result;\r\n\r\n vec3 direction = lightData.xyz - vPositionW;\r\n vec3 lightVectorW = normalize(direction);\r\n float attenuation = max(0., 1.0 - length(direction) / range);\r\n\r\n // diffuse\r\n float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));\r\n\r\n if (cosAngle >= lightDirection.w)\r\n {\r\n cosAngle = max(0., pow(cosAngle, lightData.w));\r\n attenuation *= cosAngle;\r\n\r\n // Diffuse\r\n float ndl = max(0., dot(vNormal, -lightDirection.xyz));\r\n result.diffuse = ndl * diffuseColor * attenuation;\r\n\r\n#ifdef SPECULARTERM\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = pow(specComp, max(1., glossiness));\r\n\r\n result.specular = specComp * specularColor * attenuation;\r\n#endif\r\n\r\n return result;\r\n }\r\n\r\n result.diffuse = vec3(0.);\r\n#ifdef SPECULARTERM\r\n result.specular = vec3(0.);\r\n#endif\r\n\r\n return result;\r\n}\r\n\r\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor, float glossiness) {\r\n lightingInfo result;\r\n\r\n // Diffuse\r\n float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\r\n result.diffuse = mix(groundColor, diffuseColor, ndl);\r\n\r\n#ifdef SPECULARTERM\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW + lightData.xyz);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = pow(specComp, max(1., glossiness));\r\n\r\n result.specular = specComp * specularColor;\r\n#endif\r\n\r\n return result;\r\n}\r\n\r\nvoid main(void) {\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n if (fClipDistance > 0.0)\r\n discard;\r\n#endif\r\n\r\n vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\r\n\r\n // Base color\r\n vec4 baseColor = vec4(1., 1., 1., 1.);\r\n vec3 diffuseColor = vDiffuseColor.rgb;\r\n\r\n // Alpha\r\n float alpha = vDiffuseColor.a;\r\n\r\n#ifdef DIFFUSE\r\n baseColor = texture2D(diffuseSampler, vDiffuseUV);\r\n\r\n#ifdef ALPHATEST\r\n if (baseColor.a < 0.4)\r\n discard;\r\n#endif\r\n\r\n#ifdef ALPHAFROMDIFFUSE\r\n alpha *= baseColor.a;\r\n#endif\r\n\r\n baseColor.rgb *= vDiffuseInfos.y;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\n baseColor.rgb *= vColor.rgb;\r\n#endif\r\n\r\n // Bump\r\n#ifdef NORMAL\r\n vec3 normalW = normalize(vNormalW);\r\n#else\r\n vec3 normalW = vec3(1.0, 1.0, 1.0);\r\n#endif\r\n\r\n\r\n#ifdef BUMP\r\n normalW = perturbNormal(viewDirectionW);\r\n#endif\r\n\r\n // Ambient color\r\n vec3 baseAmbientColor = vec3(1., 1., 1.);\r\n\r\n#ifdef AMBIENT\r\n baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;\r\n#endif\r\n\r\n\r\n // Specular map\r\n#ifdef SPECULARTERM\r\n float glossiness = vSpecularColor.a;\r\n vec3 specularColor = vSpecularColor.rgb;\r\n\r\n#ifdef SPECULAR\r\n vec4 specularMapColor = texture2D(specularSampler, vSpecularUV);\r\n specularColor = specularMapColor.rgb;\r\n#ifdef GLOSSINESS\r\n glossiness = glossiness * specularMapColor.a;\r\n#endif\r\n#endif\r\n#else\r\n float glossiness = 0.;\r\n#endif\r\n\r\n // Lighting\r\n vec3 diffuseBase = vec3(0., 0., 0.);\r\n#ifdef SPECULARTERM\r\n vec3 specularBase = vec3(0., 0., 0.);\r\n#endif\r\n float shadow = 1.;\r\n\r\n#ifdef LIGHT0\r\n#ifndef SPECULARTERM\r\n vec3 vLightSpecular0 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT0\r\n lightingInfo info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a, glossiness);\r\n#endif\r\n#ifdef HEMILIGHT0\r\n lightingInfo info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightGround0, glossiness);\r\n#endif\r\n#if defined(POINTLIGHT0) || defined(DIRLIGHT0)\r\n lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a, glossiness);\r\n#endif\r\n#ifdef SHADOW0\r\n#ifdef SHADOWVSM0\r\n shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0, shadowsInfo0.z, shadowsInfo0.x);\r\n#else\r\n#ifdef SHADOWPCF0\r\n#if defined(POINTLIGHT0)\r\n shadow = computeShadowWithPCFCube(vLightData0.xyz, shadowSampler0, shadowsInfo0.y, shadowsInfo0.z, shadowsInfo0.x);\r\n#else\r\n shadow = computeShadowWithPCF(vPositionFromLight0, shadowSampler0, shadowsInfo0.y, shadowsInfo0.z, shadowsInfo0.x);\r\n#endif\r\n#else\r\n#if defined(POINTLIGHT0)\r\n shadow = computeShadowCube(vLightData0.xyz, shadowSampler0, shadowsInfo0.x, shadowsInfo0.z);\r\n#else\r\n shadow = computeShadow(vPositionFromLight0, shadowSampler0, shadowsInfo0.x, shadowsInfo0.z);\r\n#endif\r\n#endif\r\n#endif\r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info.diffuse * shadow;\r\n#ifdef SPECULARTERM\r\n specularBase += info.specular * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT1\r\n#ifndef SPECULARTERM\r\n vec3 vLightSpecular1 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT1\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a, glossiness);\r\n#endif\r\n#ifdef HEMILIGHT1\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightGround1, glossiness);\r\n#endif\r\n#if defined(POINTLIGHT1) || defined(DIRLIGHT1)\r\n info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a, glossiness);\r\n#endif\r\n#ifdef SHADOW1\r\n#ifdef SHADOWVSM1\r\n shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1, shadowsInfo1.z, shadowsInfo1.x);\r\n#else\r\n#ifdef SHADOWPCF1\r\n#if defined(POINTLIGHT1)\r\n shadow = computeShadowWithPCFCube(vLightData1.xyz, shadowSampler1, shadowsInfo1.y, shadowsInfo1.z, shadowsInfo1.x);\r\n#else\r\n shadow = computeShadowWithPCF(vPositionFromLight1, shadowSampler1, shadowsInfo1.y, shadowsInfo1.z, shadowsInfo1.x);\r\n#endif\r\n#else\r\n#if defined(POINTLIGHT1)\r\n shadow = computeShadowCube(vLightData1.xyz, shadowSampler1, shadowsInfo1.x, shadowsInfo1.z);\r\n#else\r\n shadow = computeShadow(vPositionFromLight1, shadowSampler1, shadowsInfo1.x, shadowsInfo1.z);\r\n#endif\r\n#endif\r\n#endif\r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info.diffuse * shadow;\r\n#ifdef SPECULARTERM\r\n specularBase += info.specular * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT2\r\n#ifndef SPECULARTERM\r\n vec3 vLightSpecular2 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT2\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a, glossiness);\r\n#endif\r\n#ifdef HEMILIGHT2\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightGround2, glossiness);\r\n#endif\r\n#if defined(POINTLIGHT2) || defined(DIRLIGHT2)\r\n info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a, glossiness);\r\n#endif\r\n#ifdef SHADOW2\r\n#ifdef SHADOWVSM2\r\n shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2, shadowsInfo2.z, shadowsInfo2.x);\r\n#else\r\n#ifdef SHADOWPCF2\r\n#if defined(POINTLIGHT2)\r\n shadow = computeShadowWithPCFCube(vLightData2.xyz, shadowSampler2, shadowsInfo2.y, shadowsInfo2.z, shadowsInfo2.x);\r\n#else\r\n shadow = computeShadowWithPCF(vPositionFromLight2, shadowSampler2, shadowsInfo2.y, shadowsInfo2.z, shadowsInfo2.x);\r\n#endif\r\n#else\r\n#if defined(POINTLIGHT2)\r\n shadow = computeShadowCube(vLightData2.xyz, shadowSampler2, shadowsInfo2.x, shadowsInfo2.z);\r\n#else\r\n shadow = computeShadow(vPositionFromLight2, shadowSampler2, shadowsInfo2.x, shadowsInfo2.z);\r\n#endif\r\n#endif \r\n#endif \r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info.diffuse * shadow;\r\n#ifdef SPECULARTERM\r\n specularBase += info.specular * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT3\r\n#ifndef SPECULARTERM\r\n vec3 vLightSpecular3 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT3\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a, glossiness);\r\n#endif\r\n#ifdef HEMILIGHT3\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightGround3, glossiness);\r\n#endif\r\n#if defined(POINTLIGHT3) || defined(DIRLIGHT3)\r\n info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a, glossiness);\r\n#endif\r\n#ifdef SHADOW3\r\n#ifdef SHADOWVSM3\r\n shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3, shadowsInfo3.z, shadowsInfo3.x);\r\n#else\r\n#ifdef SHADOWPCF3\r\n#if defined(POINTLIGHT3)\r\n shadow = computeShadowWithPCFCube(vLightData3.xyz, shadowSampler3, shadowsInfo3.y, shadowsInfo3.z, shadowsInfo3.x);\r\n#else\r\n shadow = computeShadowWithPCF(vPositionFromLight3, shadowSampler3, shadowsInfo3.y, shadowsInfo3.z, shadowsInfo3.x);\r\n#endif\r\n#else\r\n#if defined(POINTLIGHT3)\r\n shadow = computeShadowCube(vLightData3.xyz, shadowSampler3, shadowsInfo3.x, shadowsInfo3.z);\r\n#else\r\n shadow = computeShadow(vPositionFromLight3, shadowSampler3, shadowsInfo3.x, shadowsInfo3.z);\r\n#endif\r\n#endif \r\n#endif \r\n#else\r\n shadow = 1.;\r\n#endif\r\n diffuseBase += info.diffuse * shadow;\r\n#ifdef SPECULARTERM\r\n specularBase += info.specular * shadow;\r\n#endif\r\n#endif\r\n\r\n // Reflection\r\n vec3 reflectionColor = vec3(0., 0., 0.);\r\n\r\n#ifdef REFLECTION\r\n vec3 vReflectionUVW = computeReflectionCoords(vec4(vPositionW, 1.0), normalW);\r\n\r\n#ifdef REFLECTIONMAP_3D\r\n#ifdef ROUGHNESS\r\n float bias = vReflectionInfos.y;\r\n\r\n #ifdef SPECULARTERM\r\n #ifdef SPECULAR\r\n #ifdef GLOSSINESS\r\n bias *= (1.0 - specularMapColor.a);\r\n #endif\r\n #endif\r\n #endif\r\n\r\n reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * vReflectionInfos.x;\r\n#else\r\n reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.x;\r\n#endif\r\n\r\n#else\r\n vec2 coords = vReflectionUVW.xy;\r\n\r\n#ifdef REFLECTIONMAP_PROJECTION\r\n coords /= vReflectionUVW.z;\r\n#endif\r\n\r\n coords.y = 1.0 - coords.y;\r\n\r\n reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.x;\r\n#endif\r\n\r\n#ifdef REFLECTIONFRESNEL\r\n float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);\r\n\r\n#ifdef REFLECTIONFRESNELFROMSPECULAR\r\n#ifdef SPECULARTERM\r\n reflectionColor *= specularColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\r\n#else\r\n reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\r\n#endif\r\n#else\r\n reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\r\n#endif\r\n#endif\r\n#endif\r\n\r\n#ifdef OPACITY\r\n vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);\r\n\r\n#ifdef OPACITYRGB\r\n opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);\r\n alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;\r\n#else\r\n alpha *= opacityMap.a * vOpacityInfos.y;\r\n#endif\r\n\r\n#endif\r\n\r\n#ifdef VERTEXALPHA\r\n alpha *= vColor.a;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\n float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);\r\n\r\n alpha += opacityParts.x * (1.0 - opacityFresnelTerm) + opacityFresnelTerm * opacityParts.y;\r\n#endif\r\n\r\n // Emissive\r\n vec3 emissiveColor = vEmissiveColor;\r\n#ifdef EMISSIVE\r\n emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\n float emissiveFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, emissiveRightColor.a, emissiveLeftColor.a);\r\n\r\n emissiveColor *= emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * emissiveRightColor.rgb;\r\n#endif\r\n\r\n // Fresnel\r\n#ifdef DIFFUSEFRESNEL\r\n float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, diffuseRightColor.a, diffuseLeftColor.a);\r\n\r\n diffuseBase *= diffuseLeftColor.rgb * (1.0 - diffuseFresnelTerm) + diffuseFresnelTerm * diffuseRightColor.rgb;\r\n#endif\r\n\r\n // Composition\r\n#ifdef EMISSIVEASILLUMINATION\r\n vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\r\n#else\r\n#ifdef LINKEMISSIVEWITHDIFFUSE\r\n vec3 finalDiffuse = clamp((diffuseBase + emissiveColor) * diffuseColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\r\n#else\r\n vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\r\n#endif\r\n#endif\r\n\r\n#ifdef SPECULARTERM\r\n vec3 finalSpecular = specularBase * specularColor;\r\n#else\r\n vec3 finalSpecular = vec3(0.0);\r\n#endif\r\n\r\n#ifdef SPECULAROVERALPHA\r\n alpha = clamp(alpha + dot(finalSpecular, vec3(0.3, 0.59, 0.11)), 0., 1.);\r\n#endif\r\n\r\n // Composition\r\n#ifdef EMISSIVEASILLUMINATION\r\n vec4 color = vec4(clamp(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor + emissiveColor, 0.0, 1.0), alpha);\r\n#else\r\n vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\r\n#endif\r\n\r\n#ifdef LIGHTMAP\r\n vec3 lightmapColor = texture2D(lightmapSampler, vLightmapUV).rgb * vLightmapInfos.y;\r\n\r\n#ifdef USELIGHTMAPASSHADOWMAP\r\n color.rgb *= lightmapColor;\r\n#else\r\n color.rgb += lightmapColor;\r\n#endif\r\n#endif\r\n\r\n#ifdef LOGARITHMICDEPTH\r\n gl_FragDepthEXT = log2(vFragmentDepth) * logarithmicDepthConstant * 0.5;\r\n#endif\r\n\r\n#ifdef FOG\r\n float fog = CalcFogFactor();\r\n color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\r\n#endif\r\n\r\n gl_FragColor = color;\r\n}", defaultVertexShader:"precision highp float;\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\r\n#if NUM_BONE_INFLUENCERS > 0\r\n uniform mat4 mBones[BonesPerMesh];\r\n\r\n attribute vec4 matricesIndices;\r\n attribute vec4 matricesWeights;\r\n #if NUM_BONE_INFLUENCERS > 4\r\n attribute vec4 matricesIndicesExtra;\r\n attribute vec4 matricesWeightsExtra;\r\n #endif\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 LIGHTMAP\r\nvarying vec2 vLightmapUV;\r\nuniform vec2 vLightmapInfos;\r\nuniform mat4 lightmapMatrix;\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform mat4 specularMatrix;\r\n#endif\r\n\r\n#ifdef BUMP\r\nvarying vec2 vBumpUV;\r\nuniform vec2 vBumpInfos;\r\nuniform mat4 bumpMatrix;\r\n#endif\r\n\r\n#ifdef 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#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\r\nuniform mat4 lightMatrix0;\r\nvarying vec4 vPositionFromLight0;\r\n#endif\r\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\r\nuniform mat4 lightMatrix1;\r\nvarying vec4 vPositionFromLight1;\r\n#endif\r\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\r\nuniform mat4 lightMatrix2;\r\nvarying vec4 vPositionFromLight2;\r\n#endif\r\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\r\nuniform mat4 lightMatrix3;\r\nvarying vec4 vPositionFromLight3;\r\n#endif\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_SKYBOX\r\nvarying vec3 vPositionUVW;\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\r\nvarying vec3 vDirectionW;\r\n#endif\r\n\r\n#ifdef LOGARITHMICDEPTH\r\nuniform float logarithmicDepthConstant;\r\nvarying float vFragmentDepth;\r\n#endif\r\n\r\nvoid main(void) {\r\n#ifdef REFLECTIONMAP_SKYBOX\r\n vPositionUVW = position;\r\n#endif \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#if NUM_BONE_INFLUENCERS > 0\r\n mat4 influence;\r\n influence = mBones[int(matricesIndices[0])] * matricesWeights[0];\r\n\r\n #if NUM_BONE_INFLUENCERS > 1\r\n influence += mBones[int(matricesIndices[1])] * matricesWeights[1];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 2\r\n influence += mBones[int(matricesIndices[2])] * matricesWeights[2];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 3\r\n influence += mBones[int(matricesIndices[3])] * matricesWeights[3];\r\n #endif \r\n\r\n #if NUM_BONE_INFLUENCERS > 4\r\n influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];\r\n #endif\r\n #if NUM_BONE_INFLUENCERS > 5\r\n influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 6\r\n influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 7\r\n influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];\r\n #endif \r\n\r\n finalWorld = finalWorld * influence;\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#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\r\n vDirectionW = normalize(vec3(finalWorld * vec4(position, 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 LIGHTMAP\r\n if (vLightmapInfos.x == 0.)\r\n {\r\n vLightmapUV = vec2(lightmapMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vLightmapUV = vec2(lightmapMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\n if (vSpecularInfos.x == 0.)\r\n {\r\n vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef BUMP\r\n if (vBumpInfos.x == 0.)\r\n {\r\n vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n fClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n\r\n // Fog\r\n#ifdef FOG\r\n fFogDistance = (view * worldPos).z;\r\n#endif\r\n\r\n // Shadows\r\n#ifdef SHADOWS\r\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\r\n vPositionFromLight0 = lightMatrix0 * worldPos;\r\n#endif\r\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\r\n vPositionFromLight1 = lightMatrix1 * worldPos;\r\n#endif\r\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\r\n vPositionFromLight2 = lightMatrix2 * worldPos;\r\n#endif\r\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\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\r\n // Log. depth\r\n#ifdef LOGARITHMICDEPTH\r\n vFragmentDepth = 1.0 + gl_Position.w;\r\n gl_Position.z = log2(max(0.000001, vFragmentDepth)) * logarithmicDepthConstant;\r\n#endif\r\n}",depthPixelShader:"precision highp float;\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:"precision highp float;\r\n\r\n// Attribute\r\nattribute vec3 position;\r\n#if NUM_BONE_INFLUENCERS > 0\r\n\r\n // having bone influencers implies you have bones\r\n uniform mat4 mBones[BonesPerMesh];\r\n\r\n attribute vec4 matricesIndices;\r\n attribute vec4 matricesWeights;\r\n #if NUM_BONE_INFLUENCERS > 4\r\n attribute vec4 matricesIndicesExtra;\r\n attribute vec4 matricesWeightsExtra;\r\n #endif\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\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#if NUM_BONE_INFLUENCERS > 0\r\n mat4 influence;\r\n influence = mBones[int(matricesIndices[0])] * matricesWeights[0];\r\n\r\n #if NUM_BONE_INFLUENCERS > 1\r\n influence += mBones[int(matricesIndices[1])] * matricesWeights[1];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 2\r\n influence += mBones[int(matricesIndices[2])] * matricesWeights[2];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 3\r\n influence += mBones[int(matricesIndices[3])] * matricesWeights[3];\r\n #endif \r\n \r\n #if NUM_BONE_INFLUENCERS > 4\r\n influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 5\r\n influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 6\r\n influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 7\r\n influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];\r\n #endif \r\n\r\n finalWorld = finalWorld * influence;\r\n#endif\r\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\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:"precision highp float;\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\nprecision highp float;\r\n\r\n\r\n// samplers\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D highlightsSampler;\r\nuniform sampler2D depthSampler;\r\nuniform sampler2D grainSampler;\r\n\r\n// uniforms\r\nuniform float grain_amount;\r\nuniform bool blur_noise;\r\nuniform float screen_width;\r\nuniform float screen_height;\r\nuniform float distortion;\r\nuniform bool dof_enabled;\r\n//uniform float focus_distance; // not needed; already used to compute screen distance\r\nuniform float screen_distance; // precomputed screen distance from lens center; based on focal length & desired focus distance\r\nuniform float aperture;\r\nuniform float darken;\r\nuniform float edge_blur;\r\nuniform bool highlights;\r\n\r\n// preconputed uniforms (not effect parameters)\r\nuniform float near;\r\nuniform float far;\r\n\r\n// varyings\r\nvarying vec2 vUV;\r\n\r\n// constants\r\n#define PI 3.14159265\r\n#define TWOPI 6.28318530\r\n#define inverse_focal_length 0.1 // a property of the lens used\r\n\r\n// common calculations\r\nvec2 centered_screen_pos;\r\nvec2 distorted_coords;\r\nfloat radius2;\r\nfloat radius;\r\n\r\n\r\n// on-the-fly constant noise\r\nvec2 rand(vec2 co)\r\n{\r\n float noise1 = (fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453));\r\n float noise2 = (fract(sin(dot(co, vec2(12.9898, 78.233)*2.0)) * 43758.5453));\r\n return clamp(vec2(noise1, noise2), 0.0, 1.0);\r\n}\r\n\r\n// applies edge distortion on texture coords\r\nvec2 getDistortedCoords(vec2 coords) {\r\n\r\n if (distortion == 0.0) { return coords; }\r\n\r\n vec2 direction = 1.0 * normalize(centered_screen_pos);\r\n vec2 dist_coords = vec2(0.5, 0.5);\r\n dist_coords.x = 0.5 + direction.x * radius2 * 1.0;\r\n dist_coords.y = 0.5 + direction.y * radius2 * 1.0;\r\n float dist_amount = clamp(distortion*0.23, 0.0, 1.0);\r\n\r\n dist_coords = mix(coords, dist_coords, dist_amount);\r\n\r\n return dist_coords;\r\n}\r\n\r\n// sample screen with an offset (randomize offset angle for better smothness), returns partial sample weight\r\nfloat sampleScreen(inout vec4 color, const in vec2 offset, const in float weight) {\r\n\r\n // compute coords with offset (a random angle is added)\r\n vec2 coords = distorted_coords;\r\n float angle = rand(coords * 100.0).x * TWOPI;\r\n coords += vec2(offset.x * cos(angle) - offset.y * sin(angle), offset.x * sin(angle) + offset.y * cos(angle));\r\n\r\n color += texture2D(textureSampler, coords)*weight;\r\n\r\n return weight;\r\n}\r\n\r\n// returns blur level according to blur size required\r\nfloat getBlurLevel(float size) {\r\n return min(3.0, ceil(size / 1.0));\r\n}\r\n\r\n// returns original screen color after blur\r\nvec4 getBlurColor(float size) {\r\n\r\n vec4 col = texture2D(textureSampler, distorted_coords);\r\n if (size == 0.0) { return col; }\r\n\r\n // there are max. 30 samples; the number of samples chosen is dependant on the blur size\r\n // there can be 10, 20 or 30 samples chosen; levels of blur are then 1, 2 or 3\r\n float blur_level = getBlurLevel(size);\r\n\r\n float w = (size / screen_width);\r\n float h = (size / screen_height);\r\n float total_weight = 1.0;\r\n vec2 sample_coords;\r\n\r\n total_weight += sampleScreen(col, vec2(-0.50*w, 0.24*h), 0.93);\r\n total_weight += sampleScreen(col, vec2(0.30*w, -0.75*h), 0.90);\r\n total_weight += sampleScreen(col, vec2(0.36*w, 0.96*h), 0.87);\r\n total_weight += sampleScreen(col, vec2(-1.08*w, -0.55*h), 0.85);\r\n total_weight += sampleScreen(col, vec2(1.33*w, -0.37*h), 0.83);\r\n total_weight += sampleScreen(col, vec2(-0.82*w, 1.31*h), 0.80);\r\n total_weight += sampleScreen(col, vec2(-0.31*w, -1.67*h), 0.78);\r\n total_weight += sampleScreen(col, vec2(1.47*w, 1.11*h), 0.76);\r\n total_weight += sampleScreen(col, vec2(-1.97*w, 0.19*h), 0.74);\r\n total_weight += sampleScreen(col, vec2(1.42*w, -1.57*h), 0.72);\r\n\r\n if (blur_level > 1.0) {\r\n total_weight += sampleScreen(col, vec2(0.01*w, 2.25*h), 0.70);\r\n total_weight += sampleScreen(col, vec2(-1.62*w, -1.74*h), 0.67);\r\n total_weight += sampleScreen(col, vec2(2.49*w, 0.20*h), 0.65);\r\n total_weight += sampleScreen(col, vec2(-2.07*w, 1.61*h), 0.63);\r\n total_weight += sampleScreen(col, vec2(0.46*w, -2.70*h), 0.61);\r\n total_weight += sampleScreen(col, vec2(1.55*w, 2.40*h), 0.59);\r\n total_weight += sampleScreen(col, vec2(-2.88*w, -0.75*h), 0.56);\r\n total_weight += sampleScreen(col, vec2(2.73*w, -1.44*h), 0.54);\r\n total_weight += sampleScreen(col, vec2(-1.08*w, 3.02*h), 0.52);\r\n total_weight += sampleScreen(col, vec2(-1.28*w, -3.05*h), 0.49);\r\n }\r\n\r\n if (blur_level > 2.0) {\r\n total_weight += sampleScreen(col, vec2(3.11*w, 1.43*h), 0.46);\r\n total_weight += sampleScreen(col, vec2(-3.36*w, 1.08*h), 0.44);\r\n total_weight += sampleScreen(col, vec2(1.80*w, -3.16*h), 0.41);\r\n total_weight += sampleScreen(col, vec2(0.83*w, 3.65*h), 0.38);\r\n total_weight += sampleScreen(col, vec2(-3.16*w, -2.19*h), 0.34);\r\n total_weight += sampleScreen(col, vec2(3.92*w, -0.53*h), 0.31);\r\n total_weight += sampleScreen(col, vec2(-2.59*w, 3.12*h), 0.26);\r\n total_weight += sampleScreen(col, vec2(-0.20*w, -4.15*h), 0.22);\r\n total_weight += sampleScreen(col, vec2(3.02*w, 3.00*h), 0.15);\r\n }\r\n\r\n col /= total_weight; // scales color according to weights\r\n\r\n // darken if out of focus\r\n if (darken > 0.0) {\r\n col.rgb *= clamp(0.3, 1.0, 1.05 - size*0.5*darken);\r\n }\r\n\r\n // blur levels debug\r\n // if(blur_level == 1.0) { col.b *= 0.5; }\r\n // if(blur_level == 2.0) { col.r *= 0.5; }\r\n // if(blur_level == 3.0) { col.g *= 0.5; }\r\n\r\n return col;\r\n}\r\n\r\nvoid main(void)\r\n{\r\n\r\n // Common calc: position relative to screen center, screen radius, distorted coords, position in texel space\r\n centered_screen_pos = vec2(vUV.x - 0.5, vUV.y - 0.5);\r\n radius2 = centered_screen_pos.x*centered_screen_pos.x + centered_screen_pos.y*centered_screen_pos.y;\r\n radius = sqrt(radius2);\r\n distorted_coords = getDistortedCoords(vUV); // we distort the screen coordinates (lens "magnifying" effect)\r\n vec2 texels_coords = vec2(vUV.x * screen_width, vUV.y * screen_height); // varies from 0 to SCREEN_WIDTH or _HEIGHT\r\n\r\n float depth = texture2D(depthSampler, distorted_coords).r; // depth value from DepthRenderer: 0 to 1\r\n float distance = near + (far - near)*depth; // actual distance from the lens\r\n vec4 color = texture2D(textureSampler, vUV); // original raster\r\n\r\n\r\n // compute the circle of confusion size (CoC), i.e. blur radius depending on depth\r\n // screen_distance is precomputed in code\r\n float coc = abs(aperture * (screen_distance * (inverse_focal_length - 1.0 / distance) - 1.0));\r\n\r\n // disable blur\r\n if (dof_enabled == false || coc < 0.07) { coc = 0.0; }\r\n\r\n // blur from edge blur effect\r\n float edge_blur_amount = 0.0;\r\n if (edge_blur > 0.0) {\r\n edge_blur_amount = clamp((radius*2.0 - 1.0 + 0.15*edge_blur) * 1.5, 0.0, 1.0) * 1.3;\r\n }\r\n\r\n // total blur amount\r\n float blur_amount = max(edge_blur_amount, coc);\r\n\r\n // apply blur if necessary\r\n if (blur_amount == 0.0) {\r\n gl_FragColor = texture2D(textureSampler, distorted_coords);\r\n }\r\n else {\r\n\r\n // add blurred color\r\n gl_FragColor = getBlurColor(blur_amount * 1.7);\r\n\r\n // if we have computed highlights: enhance highlights\r\n if (highlights) {\r\n gl_FragColor.rgb += clamp(coc, 0.0, 1.0)*texture2D(highlightsSampler, distorted_coords).rgb;\r\n }\r\n\r\n if (blur_noise) {\r\n // we put a slight amount of noise in the blurred color\r\n vec2 noise = rand(distorted_coords) * 0.01 * blur_amount;\r\n vec2 blurred_coord = vec2(distorted_coords.x + noise.x, distorted_coords.y + noise.y);\r\n gl_FragColor = 0.04 * texture2D(textureSampler, blurred_coord) + 0.96 * gl_FragColor;\r\n }\r\n }\r\n\r\n\r\n // apply grain\r\n if (grain_amount > 0.0) {\r\n vec4 grain_color = texture2D(grainSampler, texels_coords*0.003);\r\n gl_FragColor.rgb += (-0.5 + grain_color.rgb) * 0.30 * grain_amount;\r\n }\r\n\r\n}\r\n',displayPassPixelShader:"precision highp float;\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:"precision highp float;\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}",fxaaPixelShader:"precision highp float;\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}",hdrPixelShader:"precision highp float;\r\n\r\nuniform sampler2D textureSampler;\r\nvarying vec2 vUV;\r\n\r\n#if defined(GAUSSIAN_BLUR_H) || defined(GAUSSIAN_BLUR_V)\r\nuniform float blurOffsets[9];\r\nuniform float blurWeights[9];\r\nuniform float multiplier;\r\n\r\nvoid main(void) {\r\n vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\r\n\r\n for (int i = 0; i < 9; i++) {\r\n #ifdef GAUSSIAN_BLUR_H\r\n color += (texture2D(textureSampler, vUV + vec2(blurOffsets[i] * multiplier, 0.0)) * blurWeights[i]);\r\n #else\r\n color += (texture2D(textureSampler, vUV + vec2(0.0, blurOffsets[i] * multiplier)) * blurWeights[i]);\r\n #endif\r\n }\r\n\r\n color.a = 1.0;\r\n gl_FragColor = color;\r\n}\r\n#endif\r\n\r\n#if defined(TEXTURE_ADDER)\r\nuniform sampler2D otherSampler;\r\n\r\nvoid main() {\r\n vec4 sum = texture2D(textureSampler, vUV) + texture2D(otherSampler, vUV);\r\n sum.a = clamp(sum.a, 0.0, 1.0);\r\n\r\n gl_FragColor = sum;\r\n}\r\n#endif\r\n\r\n#if defined(LUMINANCE_GENERATOR)\r\nuniform vec2 lumOffsets[4];\r\n\r\nvoid main() {\r\n float average = 0.0;\r\n vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\r\n float maximum = -1e20;\r\n\r\n for (int i = 0; i < 4; i++) {\r\n color = texture2D(textureSampler, vUV + lumOffsets[i]);\r\n\r\n float GreyValue = length(color.rgb);\r\n\r\n maximum = max(maximum, GreyValue);\r\n average += (0.25 * log(1e-5 + GreyValue));\r\n }\r\n\r\n average = exp(average);\r\n\r\n gl_FragColor = vec4(average, maximum, 0.0, 1.0);\r\n\r\n}\r\n#endif\r\n\r\n#if defined(DOWN_SAMPLE)\r\nuniform vec2 dsOffsets[9];\r\nuniform float halfDestPixelSize;\r\n\r\n#ifdef FINAL_DOWN_SAMPLE\r\nvec4 pack(float value) {\r\n const vec4 bit_shift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);\r\n const vec4 bit_mask = vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);\r\n\r\n vec4 res = fract(value * bit_shift);\r\n res -= res.xxyz * bit_mask;\r\n\r\n return res;\r\n}\r\n#endif\r\n\r\nvoid main() {\r\n vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\r\n float average = 0.0;\r\n\r\n for (int i = 0; i < 9; i++) {\r\n color = texture2D(textureSampler, vUV + vec2(halfDestPixelSize, halfDestPixelSize) + dsOffsets[i]);\r\n average += color.r;\r\n }\r\n\r\n average /= 9.0;\r\n\r\n #ifndef FINAL_DOWN_SAMPLE\r\n gl_FragColor = vec4(average, average, 0.0, 1.0);\r\n #else\r\n gl_FragColor = pack(average);\r\n #endif\r\n}\r\n#endif\r\n\r\n#if defined(BRIGHT_PASS)\r\nuniform vec2 dsOffsets[4];\r\nuniform float brightThreshold;\r\n\r\nvoid main() {\r\n vec4 average = vec4(0.0, 0.0, 0.0, 0.0);\r\n\r\n average = texture2D(textureSampler, vUV + vec2(dsOffsets[0].x, dsOffsets[0].y));\r\n average += texture2D(textureSampler, vUV + vec2(dsOffsets[1].x, dsOffsets[1].y));\r\n average += texture2D(textureSampler, vUV + vec2(dsOffsets[2].x, dsOffsets[2].y));\r\n average += texture2D(textureSampler, vUV + vec2(dsOffsets[3].x, dsOffsets[3].y));\r\n\r\n average *= 0.25;\r\n\r\n float luminance = length(average.rgb);\r\n\r\n if (luminance < brightThreshold) {\r\n average = vec4(0.0, 0.0, 0.0, 1.0);\r\n }\r\n\r\n gl_FragColor = average;\r\n}\r\n#endif\r\n\r\n#if defined(DOWN_SAMPLE_X4)\r\nuniform vec2 dsOffsets[16];\r\n\r\nvoid main() {\r\n vec4 average = vec4(0.0, 0.0, 0.0, 0.0);\r\n\r\n average = texture2D(textureSampler, vUV + dsOffsets[0]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[1]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[2]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[3]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[4]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[5]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[6]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[7]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[8]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[9]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[10]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[11]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[12]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[13]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[14]);\r\n average += texture2D(textureSampler, vUV + dsOffsets[15]);\r\n\r\n average /= 16.0;\r\n\r\n gl_FragColor = average;\r\n}\r\n#endif\r\n\r\n#if defined(HDR)\r\nuniform sampler2D otherSampler;\r\n\r\nuniform float exposure;\r\nuniform float avgLuminance;\r\n\r\nvoid main() {\r\n vec4 color = texture2D(textureSampler, vUV) + texture2D(otherSampler, vUV);\r\n vec4 adjustedColor = color / avgLuminance * exposure;\r\n\r\n color = adjustedColor;\r\n color.a = 1.0;\r\n\r\n gl_FragColor = color;\r\n}\r\n#endif\r\n",layerPixelShader:"precision highp float;\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:"precision highp float;\r\n\r\n// Attributes\r\nattribute vec2 position;\r\n\r\n// Uniforms\r\nuniform vec2 scale;\r\nuniform vec2 offset;\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 vec2 shiftedPosition = position * scale + offset;\r\n vUV = vec2(textureMatrix * vec4(shiftedPosition * madd + madd, 1.0, 0.0));\r\n gl_Position = vec4(shiftedPosition, 0.0, 1.0);\r\n}",legacydefaultPixelShader:"precision highp float;\r\n\r\n#define MAP_PROJECTION 4.\r\n\r\n// Constants\r\nuniform vec3 vEyePosition;\r\nuniform vec3 vAmbientColor;\r\nuniform vec4 vDiffuseColor;\r\n#ifdef SPECULARTERM\r\nuniform vec4 vSpecularColor;\r\n#endif\r\nuniform vec3 vEmissiveColor;\r\n\r\n// Input\r\nvarying vec3 vPositionW;\r\nvarying vec3 vNormalW;\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n// Lights\r\n#ifdef LIGHT0\r\nuniform vec4 vLightData0;\r\nuniform vec4 vLightDiffuse0;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular0;\r\n#endif\r\n#ifdef SHADOW0\r\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\r\nvarying vec4 vPositionFromLight0;\r\nuniform sampler2D shadowSampler0;\r\n#else\r\nuniform samplerCube shadowSampler0;\r\n#endif\r\nuniform vec3 shadowsInfo0;\r\n#endif\r\n#ifdef SPOTLIGHT0\r\nuniform vec4 vLightDirection0;\r\n#endif\r\n#ifdef HEMILIGHT0\r\nuniform vec3 vLightGround0;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT1\r\nuniform vec4 vLightData1;\r\nuniform vec4 vLightDiffuse1;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular1;\r\n#endif\r\n#ifdef SHADOW1\r\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\r\nvarying vec4 vPositionFromLight1;\r\nuniform sampler2D shadowSampler1;\r\n#else\r\nuniform samplerCube shadowSampler1;\r\n#endif\r\nuniform vec3 shadowsInfo1;\r\n#endif\r\n#ifdef SPOTLIGHT1\r\nuniform vec4 vLightDirection1;\r\n#endif\r\n#ifdef HEMILIGHT1\r\nuniform vec3 vLightGround1;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT2\r\nuniform vec4 vLightData2;\r\nuniform vec4 vLightDiffuse2;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular2;\r\n#endif\r\n#ifdef SHADOW2\r\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\r\nvarying vec4 vPositionFromLight2;\r\nuniform sampler2D shadowSampler2;\r\n#else\r\nuniform samplerCube shadowSampler2;\r\n#endif\r\nuniform vec3 shadowsInfo2;\r\n#endif\r\n#ifdef SPOTLIGHT2\r\nuniform vec4 vLightDirection2;\r\n#endif\r\n#ifdef HEMILIGHT2\r\nuniform vec3 vLightGround2;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT3\r\nuniform vec4 vLightData3;\r\nuniform vec4 vLightDiffuse3;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular3;\r\n#endif\r\n#ifdef SHADOW3\r\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\r\nvarying vec4 vPositionFromLight3;\r\nuniform sampler2D shadowSampler3;\r\n#else\r\nuniform samplerCube shadowSampler3;\r\n#endif\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 REFLECTION\r\nvarying vec3 vReflectionUVW;\r\n#ifdef REFLECTIONMAP_3D\r\nuniform samplerCube reflectionCubeSampler;\r\n#else\r\nuniform sampler2D reflection2DSampler;\r\n#endif\r\nuniform vec2 vReflectionInfos;\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\nvarying vec2 vEmissiveUV;\r\nuniform vec2 vEmissiveInfos;\r\nuniform sampler2D emissiveSampler;\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform sampler2D specularSampler;\r\n#endif\r\n\r\n// Fresnel\r\n#ifdef FRESNEL\r\nfloat computeFresnelTerm(vec3 viewDirection, vec3 worldNormal, float bias, float power)\r\n{\r\n float fresnelTerm = pow(bias + abs(dot(viewDirection, worldNormal)), power);\r\n return clamp(fresnelTerm, 0., 1.);\r\n}\r\n#endif\r\n\r\n#ifdef DIFFUSEFRESNEL\r\nuniform vec4 diffuseLeftColor;\r\nuniform vec4 diffuseRightColor;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\nuniform vec4 opacityParts;\r\n#endif\r\n\r\n#ifdef REFLECTIONFRESNEL\r\nuniform vec4 reflectionLeftColor;\r\nuniform vec4 reflectionRightColor;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\nuniform vec4 emissiveLeftColor;\r\nuniform vec4 emissiveRightColor;\r\n#endif\r\n\r\n// Shadows\r\n#ifdef SHADOWS\r\n\r\nfloat unpack(vec4 color)\r\n{\r\n const vec4 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\n#if defined(POINTLIGHT0) || defined(POINTLIGHT1) || defined(POINTLIGHT2) || defined(POINTLIGHT3)\r\nfloat computeShadowCube(vec3 lightPosition, samplerCube shadowSampler, float darkness, float bias)\r\n{\r\n vec3 directionToLight = vPositionW - lightPosition;\r\n float depth = length(directionToLight);\r\n\r\n depth = clamp(depth, 0., 1.);\r\n\r\n directionToLight.y = 1.0 - directionToLight.y;\r\n\r\n float shadow = unpack(textureCube(shadowSampler, directionToLight)) + bias;\r\n\r\n if (depth > shadow)\r\n {\r\n return darkness;\r\n }\r\n return 1.0;\r\n}\r\n#endif\r\n\r\n#if defined(SPOTLIGHT0) || defined(SPOTLIGHT1) || defined(SPOTLIGHT2) || defined(SPOTLIGHT3) || defined(DIRLIGHT0) || defined(DIRLIGHT1) || defined(DIRLIGHT2) || defined(DIRLIGHT3)\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\n// Thanks to http://devmaster.net/\r\nfloat unpackHalf(vec2 color)\r\n{\r\n return color.x + (color.y / 255.0);\r\n}\r\n\r\nfloat linstep(float low, float high, float v) {\r\n return clamp((v - low) / (high - low), 0.0, 1.0);\r\n}\r\n\r\nfloat ChebychevInequality(vec2 moments, float compare, float bias)\r\n{\r\n float p = smoothstep(compare - bias, compare, moments.x);\r\n float variance = max(moments.y - moments.x * moments.x, 0.02);\r\n float d = compare - moments.x;\r\n float p_max = linstep(0.2, 1.0, variance / (variance + d * d));\r\n\r\n return clamp(max(p, p_max), 0.0, 1.0);\r\n}\r\n\r\nfloat computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler, float bias, float darkness)\r\n{\r\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n depth = 0.5 * depth + vec3(0.5);\r\n vec2 uv = depth.xy;\r\n\r\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0 || depth.z >= 1.0)\r\n {\r\n return 1.0;\r\n }\r\n\r\n vec4 texel = texture2D(shadowSampler, uv);\r\n\r\n vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));\r\n return min(1.0, 1.0 - ChebychevInequality(moments, depth.z, bias) + darkness);\r\n}\r\n#endif\r\n#endif\r\n\r\n#ifdef CLIPPLANE\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n// Fog\r\n#ifdef FOG\r\n\r\n#define FOGMODE_NONE 0.\r\n#define FOGMODE_EXP 1.\r\n#define FOGMODE_EXP2 2.\r\n#define FOGMODE_LINEAR 3.\r\n#define E 2.71828\r\n\r\nuniform vec4 vFogInfos;\r\nuniform vec3 vFogColor;\r\nvarying float fFogDistance;\r\n\r\nfloat CalcFogFactor()\r\n{\r\n float fogCoeff = 1.0;\r\n float fogStart = vFogInfos.y;\r\n float fogEnd = vFogInfos.z;\r\n float fogDensity = vFogInfos.w;\r\n\r\n if (FOGMODE_LINEAR == vFogInfos.x)\r\n {\r\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\r\n }\r\n else if (FOGMODE_EXP == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\r\n }\r\n else if (FOGMODE_EXP2 == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\r\n }\r\n\r\n return clamp(fogCoeff, 0.0, 1.0);\r\n}\r\n#endif\r\n\r\n// Light Computing\r\nmat3 computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 diffuseColor, vec3 specularColor) {\r\n mat3 result;\r\n\r\n vec3 lightVectorW;\r\n if (lightData.w == 0.)\r\n {\r\n lightVectorW = normalize(lightData.xyz - vPositionW);\r\n }\r\n else\r\n {\r\n lightVectorW = normalize(-lightData.xyz);\r\n }\r\n\r\n // diffuse\r\n float ndl = max(0., dot(vNormal, lightVectorW));\r\n\r\n result[0] = ndl * diffuseColor.rgb;\r\n\r\n#ifdef SPECULARTERM\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW + lightVectorW);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = max(0., pow(specComp, max(1.0, vSpecularColor.a)));\r\n result[1] = specComp * specularColor;\r\n#else\r\n result[1] = vec3(0.);\r\n#endif\r\n\r\n result[2] = vec3(0.);\r\n\r\n return result;\r\n}\r\n\r\nmat3 computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec4 diffuseColor, vec3 specularColor) {\r\n mat3 result;\r\n\r\n vec3 lightVectorW = normalize(lightData.xyz - vPositionW);\r\n\r\n // diffuse\r\n float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));\r\n float spotAtten = 0.0;\r\n\r\n if (cosAngle >= lightDirection.w)\r\n {\r\n cosAngle = max(0., pow(cosAngle, lightData.w));\r\n spotAtten = max(0., (cosAngle - lightDirection.w) / (1. - cosAngle));\r\n\r\n // Diffuse\r\n float ndl = max(0., dot(vNormal, -lightDirection.xyz));\r\n result[0] = ndl * spotAtten * diffuseColor.rgb;\r\n\r\n#ifdef SPECULARTERM\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = pow(specComp, vSpecularColor.a);\r\n result[1] = specComp * specularColor * spotAtten;\r\n#else\r\n result[1] = vec3(0.);\r\n#endif\r\n result[2] = vec3(0.);\r\n\r\n return result;\r\n }\r\n\r\n result[0] = vec3(0.);\r\n result[1] = vec3(0.);\r\n result[2] = vec3(0.);\r\n\r\n return result;\r\n}\r\n\r\nmat3 computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 diffuseColor, vec3 specularColor, vec3 groundColor) {\r\n mat3 result;\r\n\r\n // Diffuse\r\n float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\r\n result[0] = mix(groundColor, diffuseColor.rgb, ndl);\r\n\r\n#ifdef SPECULARTERM\r\n // Specular\r\n vec3 angleW = normalize(viewDirectionW + lightData.xyz);\r\n float specComp = max(0., dot(vNormal, angleW));\r\n specComp = pow(specComp, vSpecularColor.a);\r\n result[1] = specComp * specularColor;\r\n#else\r\n result[1] = vec3(0.);\r\n#endif\r\n\r\n result[2] = vec3(0.);\r\n\r\n return result;\r\n}\r\n\r\nvoid main(void) {\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n if (fClipDistance > 0.0)\r\n discard;\r\n#endif\r\n\r\n vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\r\n\r\n // Base color\r\n vec4 baseColor = vec4(1., 1., 1., 1.);\r\n vec3 diffuseColor = vDiffuseColor.rgb;\r\n\r\n#ifdef DIFFUSE\r\n baseColor = texture2D(diffuseSampler, vDiffuseUV);\r\n\r\n#ifdef ALPHATEST\r\n if (baseColor.a < 0.4)\r\n discard;\r\n#endif\r\n\r\n baseColor.rgb *= vDiffuseInfos.y;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\n baseColor.rgb *= vColor.rgb;\r\n#endif\r\n\r\n // Bump\r\n vec3 normalW = normalize(vNormalW);\r\n\r\n // Ambient color\r\n vec3 baseAmbientColor = vec3(1., 1., 1.);\r\n\r\n#ifdef AMBIENT\r\n baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;\r\n#endif\r\n\r\n // Lighting\r\n vec3 diffuseBase = vec3(0., 0., 0.);\r\n#ifdef SPECULARTERM\r\n vec3 specularBase = vec3(0., 0., 0.);\r\n#endif\r\n float shadow = 1.;\r\n\r\n#ifdef LIGHT0\r\n#ifndef SPECULARTERM\r\n vec3 vLightSpecular0 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT0\r\n mat3 info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0, vLightSpecular0);\r\n#endif\r\n#ifdef HEMILIGHT0\r\n mat3 info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0, vLightGround0);\r\n#endif\r\n#if defined(POINTLIGHT0) || defined(DIRLIGHT0)\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, shadowsInfo0.z, shadowsInfo0.x);\r\n#else\r\n#if defined(POINTLIGHT0)\r\n shadow = computeShadowCube(vLightData0.xyz, shadowSampler0, shadowsInfo0.x, 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[0] * shadow;\r\n#ifdef SPECULARTERM\r\n specularBase += info[1] * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT1\r\n#ifndef SPECULARTERM\r\n vec3 vLightSpecular1 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT1\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1, vLightSpecular1);\r\n#endif\r\n#ifdef HEMILIGHT1\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1, vLightGround1);\r\n#endif\r\n#if defined(POINTLIGHT1) || defined(DIRLIGHT1)\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, shadowsInfo1.z, shadowsInfo1.x);\r\n#else\r\n#if defined(POINTLIGHT1)\r\n shadow = computeShadowCube(vLightData1.xyz, shadowSampler1, shadowsInfo1.x, 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[0] * shadow;\r\n#ifdef SPECULARTERM\r\n specularBase += info[1] * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT2\r\n#ifndef SPECULARTERM\r\n vec3 vLightSpecular2 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT2\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2, vLightSpecular2);\r\n#endif\r\n#ifdef HEMILIGHT2\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2, vLightGround2);\r\n#endif\r\n#if defined(POINTLIGHT2) || defined(DIRLIGHT2)\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, shadowsInfo2.z, shadowsInfo2.x);\r\n#else\r\n#if defined(POINTLIGHT2)\r\n shadow = computeShadowCube(vLightData2.xyz, shadowSampler2, shadowsInfo2.x, 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[0] * shadow;\r\n#ifdef SPECULARTERM\r\n specularBase += info[1] * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT3\r\n#ifndef SPECULARTERM\r\n vec3 vLightSpecular3 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT3\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3, vLightSpecular3);\r\n#endif\r\n#ifdef HEMILIGHT3\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3, vLightGround3);\r\n#endif\r\n#if defined(POINTLIGHT3) || defined(DIRLIGHT3)\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, shadowsInfo3.z, shadowsInfo3.x);\r\n#else\r\n#if defined(POINTLIGHT3)\r\n shadow = computeShadowCube(vLightData3.xyz, shadowSampler3, shadowsInfo3.x, 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[0] * shadow;\r\n#ifdef SPECULARTERM\r\n specularBase += info[1] * shadow;\r\n#endif\r\n#endif\r\n\r\n // Reflection\r\n vec3 reflectionColor = vec3(0., 0., 0.);\r\n\r\n#ifdef REFLECTION\r\n#ifdef REFLECTIONMAP_3D\r\n reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.x;\r\n#else\r\n vec2 coords = vReflectionUVW.xy;\r\n\r\n#ifdef REFLECTIONMAP_PROJECTION\r\n coords /= vReflectionUVW.z;\r\n#endif\r\n\r\n coords.y = 1.0 - coords.y;\r\n\r\n reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.x;\r\n#endif\r\n\r\n#ifdef REFLECTIONFRESNEL\r\n float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);\r\n\r\n reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\r\n#endif\r\n#endif\r\n\r\n // Alpha\r\n float alpha = vDiffuseColor.a;\r\n\r\n#ifdef OPACITY\r\n vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);\r\n#ifdef OPACITYRGB\r\n opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);\r\n alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;\r\n#else\r\n alpha *= opacityMap.a * vOpacityInfos.y;\r\n#endif\r\n#endif\r\n\r\n#ifdef VERTEXALPHA\r\n alpha *= vColor.a;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\n float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);\r\n\r\n alpha += opacityParts.x * (1.0 - opacityFresnelTerm) + opacityFresnelTerm * opacityParts.y;\r\n#endif\r\n\r\n // Emissive\r\n vec3 emissiveColor = vEmissiveColor;\r\n#ifdef EMISSIVE\r\n emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\n float emissiveFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, emissiveRightColor.a, emissiveLeftColor.a);\r\n\r\n emissiveColor *= emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * emissiveRightColor.rgb;\r\n#endif\r\n\r\n // Specular map\r\n#ifdef SPECULARTERM\r\n vec3 specularColor = vSpecularColor.rgb;\r\n#ifdef SPECULAR\r\n specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;\r\n#endif\r\n#endif\r\n\r\n // Fresnel\r\n#ifdef DIFFUSEFRESNEL\r\n float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, diffuseRightColor.a, diffuseLeftColor.a);\r\n\r\n diffuseBase *= diffuseLeftColor.rgb * (1.0 - diffuseFresnelTerm) + diffuseFresnelTerm * diffuseRightColor.rgb;\r\n#endif\r\n\r\n // Composition\r\n vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\r\n#ifdef SPECULARTERM\r\n vec3 finalSpecular = specularBase * specularColor;\r\n#else\r\n vec3 finalSpecular = vec3(0.0);\r\n#endif\r\n\r\n vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\r\n\r\n#ifdef FOG\r\n float fog = CalcFogFactor();\r\n color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\r\n#endif\r\n\r\n gl_FragColor = color;\r\n}", legacydefaultVertexShader:"precision highp float;\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#if NUM_BONE_INFLUENCERS > 0\r\n\r\n // having bone influencers implies you have bones\r\n uniform mat4 mBones[BonesPerMesh];\r\n\r\n attribute vec4 matricesIndices;\r\n attribute vec4 matricesWeights;\r\n #if NUM_BONE_INFLUENCERS > 4\r\n attribute vec4 matricesIndicesExtra;\r\n attribute vec4 matricesWeightsExtra;\r\n #endif\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 EMISSIVE\r\nvarying vec2 vEmissiveUV;\r\nuniform vec2 vEmissiveInfos;\r\nuniform mat4 emissiveMatrix;\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform mat4 specularMatrix;\r\n#endif\r\n\r\n#ifdef BUMP\r\nvarying vec2 vBumpUV;\r\nuniform vec2 vBumpInfos;\r\nuniform mat4 bumpMatrix;\r\n#endif\r\n\r\n// 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#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\r\nuniform mat4 lightMatrix0;\r\nvarying vec4 vPositionFromLight0;\r\n#endif\r\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\r\nuniform mat4 lightMatrix1;\r\nvarying vec4 vPositionFromLight1;\r\n#endif\r\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\r\nuniform mat4 lightMatrix2;\r\nvarying vec4 vPositionFromLight2;\r\n#endif\r\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\r\nuniform mat4 lightMatrix3;\r\nvarying vec4 vPositionFromLight3;\r\n#endif\r\n#endif\r\n\r\n#ifdef REFLECTION\r\nuniform vec3 vEyePosition;\r\nvarying vec3 vReflectionUVW;\r\nuniform mat4 reflectionMatrix;\r\n\r\nvec3 computeReflectionCoords(vec4 worldPos, vec3 worldNormal)\r\n{\r\n#ifdef REFLECTIONMAP_SPHERICAL\r\n vec3 coords = vec3(view * vec4(worldNormal, 0.0));\r\n\r\n return vec3(reflectionMatrix * vec4(coords, 1.0));\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_PLANAR\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#endif\r\n\r\n#ifdef REFLECTIONMAP_CUBIC\r\n vec3 viewDir = worldPos.xyz - vEyePosition;\r\n vec3 coords = reflect(viewDir, worldNormal);\r\n#ifdef INVERTCUBICMAP\r\n coords.y = 1.0 - coords.y;\r\n#endif\r\n return vec3(reflectionMatrix * vec4(coords, 0));\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_PROJECTION\r\n return vec3(reflectionMatrix * (view * worldPos));\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_SKYBOX\r\n return position;\r\n#endif\r\n\r\n#ifdef REFLECTIONMAP_EXPLICIT\r\n return vec3(0, 0, 0);\r\n#endif\r\n}\r\n#endif\r\n\r\nvoid main(void) {\r\n mat4 finalWorld = world;\r\n\r\n#if NUM_BONE_INFLUENCERS > 0\r\n mat4 influence;\r\n influence = mBones[int(matricesIndices[0])] * matricesWeights[0];\r\n\r\n #if NUM_BONE_INFLUENCERS > 1\r\n influence += mBones[int(matricesIndices[1])] * matricesWeights[1];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 2\r\n influence += mBones[int(matricesIndices[2])] * matricesWeights[2];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 3\r\n influence += mBones[int(matricesIndices[3])] * matricesWeights[3];\r\n #endif \r\n\r\n #if NUM_BONE_INFLUENCERS > 4\r\n influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];\r\n #endif\r\n #if NUM_BONE_INFLUENCERS > 5\r\n influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 6\r\n influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];\r\n #endif \r\n #if NUM_BONE_INFLUENCERS > 7\r\n influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];\r\n #endif \r\n\r\n finalWorld = finalWorld * influence;\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 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(vec4(vPositionW, 1.0), vNormalW);\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\n if (vEmissiveInfos.x == 0.)\r\n {\r\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\n if (vSpecularInfos.x == 0.)\r\n {\r\n vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n#ifdef BUMP\r\n if (vBumpInfos.x == 0.)\r\n {\r\n vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n fClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n\r\n // Fog\r\n#ifdef FOG\r\n fFogDistance = (view * worldPos).z;\r\n#endif\r\n\r\n // Shadows\r\n#ifdef SHADOWS\r\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\r\n vPositionFromLight0 = lightMatrix0 * worldPos;\r\n#endif\r\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\r\n vPositionFromLight1 = lightMatrix1 * worldPos;\r\n#endif\r\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\r\n vPositionFromLight2 = lightMatrix2 * worldPos;\r\n#endif\r\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\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:"precision highp float;\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:"precision highp float;\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:"precision highp float;\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 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#ifdef 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#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#endif\r\n\r\n blurred /= 39.0;\r\n\r\n gl_FragColor = blurred;\r\n\r\n //if(vUV.x > 0.5) { gl_FragColor.rgb *= 0.0; }\r\n}",linePixelShader:"precision highp float;\r\n\r\nuniform vec4 color;\r\n\r\nvoid main(void) {\r\n gl_FragColor = color;\r\n}",lineVertexShader:"precision highp float;\r\n\r\n// Attributes\r\nattribute vec3 position;\r\nattribute vec4 normal;\r\n\r\n// Uniforms\r\nuniform mat4 worldViewProjection;\r\n\r\nuniform float width;\r\nuniform float aspectRatio;\r\n\r\nvoid main(void) {\r\n vec4 viewPosition = worldViewProjection * vec4(position, 1.0);\r\n vec4 viewPositionNext = worldViewProjection * vec4(normal.xyz, 1.0);\r\n\r\n vec2 currentScreen = viewPosition.xy / viewPosition.w;\r\n vec2 nextScreen = viewPositionNext.xy / viewPositionNext.w;\r\n\r\n currentScreen.x *= aspectRatio;\r\n nextScreen.x *= aspectRatio;\r\n\r\n vec2 dir = normalize(nextScreen - currentScreen);\r\n vec2 normalDir = vec2(-dir.y, dir.x);\r\n\r\n normalDir *= width / 2.0;\r\n normalDir.x /= aspectRatio;\r\n\r\n vec4 offset = vec4(normalDir * normal.w, 0.0, 0.0);\r\n gl_Position = viewPosition + offset;\r\n}",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:"precision highp float;\r\n\r\n// Attribute\r\nattribute vec3 position;\r\nattribute vec3 normal;\r\n\r\n#if NUM_BONE_INFLUENCERS > 0\r\nuniform mat4 mBones[BonesPerMesh];\r\n\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#if NUM_BONE_INFLUENCERS > 4\r\nattribute vec4 matricesIndicesExtra;\r\nattribute vec4 matricesWeightsExtra;\r\n#endif\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\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 vec3 offsetPosition = position + normal * offset;\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#if NUM_BONE_INFLUENCERS > 0\r\n mat4 influence;\r\n influence = mBones[int(matricesIndices[0])] * matricesWeights[0];\r\n\r\n#if NUM_BONE_INFLUENCERS > 1\r\n influence += mBones[int(matricesIndices[1])] * matricesWeights[1];\r\n#endif \r\n#if NUM_BONE_INFLUENCERS > 2\r\n influence += mBones[int(matricesIndices[2])] * matricesWeights[2];\r\n#endif \r\n#if NUM_BONE_INFLUENCERS > 3\r\n influence += mBones[int(matricesIndices[3])] * matricesWeights[3];\r\n#endif \r\n\r\n#if NUM_BONE_INFLUENCERS > 4\r\n influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];\r\n#endif \r\n#if NUM_BONE_INFLUENCERS > 5\r\n influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];\r\n#endif \r\n#if NUM_BONE_INFLUENCERS > 6\r\n influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];\r\n#endif \r\n#if NUM_BONE_INFLUENCERS > 7\r\n influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];\r\n#endif \r\n\r\n finalWorld = finalWorld * influence;\r\n#endif\r\n gl_Position = viewProjection * finalWorld * vec4(offsetPosition, 1.0);\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}\r\n",particlesPixelShader:"precision highp float;\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:"precision highp float;\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:"precision highp float;\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:"precision highp float;\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:"precision highp float;\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:"precision highp float;\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}",shadowMapPixelShader:"precision highp float;\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\n#ifdef CUBEMAP\r\nuniform vec3 lightPosition;\r\nuniform vec2 depthValues;\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\r\n#ifdef CUBEMAP\r\n vec3 directionToLight = vPosition.xyz - lightPosition;\r\n \r\n float depth = length(directionToLight);\r\n depth = (depth - depthValues.x) / (depthValues.y - depthValues.x);\r\n depth = clamp(depth, 0., 1.0);\r\n#else\r\n float depth = vPosition.z / vPosition.w;\r\n depth = depth * 0.5 + 0.5;\r\n#endif\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:"precision highp float;\r\n\r\n// Attribute\r\nattribute vec3 position;\r\n#if NUM_BONE_INFLUENCERS > 0\r\n\r\n// having bone influencers implies you have bones\r\nuniform mat4 mBones[BonesPerMesh];\r\n\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#if NUM_BONE_INFLUENCERS > 4\r\nattribute vec4 matricesIndicesExtra;\r\nattribute vec4 matricesWeightsExtra;\r\n#endif\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\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#if NUM_BONE_INFLUENCERS > 0\r\n mat4 influence;\r\n influence = mBones[int(matricesIndices[0])] * matricesWeights[0];\r\n\r\n#if NUM_BONE_INFLUENCERS > 1\r\n influence += mBones[int(matricesIndices[1])] * matricesWeights[1];\r\n#endif \r\n#if NUM_BONE_INFLUENCERS > 2\r\n influence += mBones[int(matricesIndices[2])] * matricesWeights[2];\r\n#endif \r\n#if NUM_BONE_INFLUENCERS > 3\r\n influence += mBones[int(matricesIndices[3])] * matricesWeights[3];\r\n#endif \r\n\r\n#if NUM_BONE_INFLUENCERS > 4\r\n influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];\r\n#endif \r\n#if NUM_BONE_INFLUENCERS > 5\r\n influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];\r\n#endif \r\n#if NUM_BONE_INFLUENCERS > 6\r\n influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];\r\n#endif \r\n#if NUM_BONE_INFLUENCERS > 7\r\n influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];\r\n#endif \r\n\r\n finalWorld = finalWorld * influence;\r\n#endif\r\n\r\n#ifdef CUBEMAP\r\n vPosition = finalWorld * vec4(position, 1.0);\r\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\r\n#else\r\n vPosition = viewProjection * finalWorld * vec4(position, 1.0);\r\n gl_Position = vPosition;\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}",spritesPixelShader:"precision highp float;\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:"precision highp float;\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:"precision highp float;\r\n\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D randomSampler;\r\n\r\nuniform float randTextureTiles;\r\nuniform float samplesFactor;\r\nuniform vec3 sampleSphere[SAMPLES];\r\n\r\nuniform float totalStrength;\r\nuniform float radius;\r\nuniform float area;\r\nuniform float fallOff;\r\nuniform float base;\r\n\r\nvarying vec2 vUV;\r\n\r\nvec3 normalFromDepth(float depth, vec2 coords) {\r\n vec2 offset1 = vec2(0.0, radius);\r\n vec2 offset2 = vec2(radius, 0.0);\r\n\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()\r\n{\r\n vec3 random = normalize(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, vec2(0.001, 0.001), vec2(0.999, 0.999))).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:"precision highp float;\r\n\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D originalColor;\r\n\r\nvarying vec2 vUV;\r\n\r\nvoid main(void) {\r\n vec4 ssaoColor = texture2D(textureSampler, vUV);\r\n vec4 sceneColor = texture2D(originalColor, vUV);\r\n\r\n gl_FragColor = sceneColor * ssaoColor;\r\n}\r\n",stereoscopicInterlacePixelShader:"precision highp float;\r\n\r\nconst vec3 TWO = vec3(2.0, 2.0, 2.0);\r\n\r\nvarying vec2 vUV;\r\nuniform sampler2D camASampler;\r\nuniform sampler2D textureSampler;\r\nuniform vec2 stepSize;\r\n\r\nvoid main(void)\r\n{\r\n bool useCamB;\r\n vec2 texCoord1;\r\n vec2 texCoord2;\r\n \r\n vec3 frag1;\r\n vec3 frag2;\r\n \r\n#ifdef IS_STEREOSCOPIC_HORIZ\r\n useCamB = vUV.x > 0.5;\r\n texCoord1 = vec2(useCamB ? (vUV.x - 0.5) * 2.0 : vUV.x * 2.0, vUV.y);\r\n texCoord2 = vec2(texCoord1.x + stepSize.x, vUV.y);\r\n#else\r\n useCamB = vUV.y > 0.5;\r\n texCoord1 = vec2(vUV.x, useCamB ? (vUV.y - 0.5) * 2.0 : vUV.y * 2.0);\r\n texCoord2 = vec2(vUV.x, texCoord1.y + stepSize.y);\r\n#endif\r\n \r\n // cannot assign a sampler to a variable, so must duplicate texture accesses\r\n if (useCamB){\r\n frag1 = texture2D(textureSampler, texCoord1).rgb;\r\n frag2 = texture2D(textureSampler, texCoord2).rgb;\r\n }else{\r\n frag1 = texture2D(camASampler , texCoord1).rgb;\r\n frag2 = texture2D(camASampler , texCoord2).rgb;\r\n }\r\n \r\n gl_FragColor = vec4((frag1 + frag2) / TWO, 1.0);\r\n}", tonemapPixelShader:"precision highp float;\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\n// Constants\r\nuniform float _ExposureAdjustment;\r\n\r\n#if defined(HABLE_TONEMAPPING)\r\n const float A = 0.15;\r\n const float B = 0.50;\r\n const float C = 0.10;\r\n const float D = 0.20;\r\n const float E = 0.02;\r\n const float F = 0.30;\r\n const float W = 11.2;\r\n#endif\r\n\r\nfloat Luminance(vec3 c)\r\n{\r\n return dot(c, vec3(0.22, 0.707, 0.071));\r\n}\r\n\r\nvoid main(void) \r\n{\r\n vec3 colour = texture2D(textureSampler, vUV).rgb;\r\n\r\n#if defined(REINHARD_TONEMAPPING)\r\n\r\n float lum = Luminance(colour.rgb); \r\n float lumTm = lum * _ExposureAdjustment;\r\n float scale = lumTm / (1.0 + lumTm); \r\n\r\n colour *= scale / lum;\r\n\r\n#elif defined(HABLE_TONEMAPPING)\r\n\r\n colour *= _ExposureAdjustment;\r\n\r\n const float ExposureBias = 2.0;\r\n vec3 x = ExposureBias * colour;\r\n\r\n vec3 curr = ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F;\r\n \r\n x = vec3(W, W, W);\r\n vec3 whiteScale = 1.0 / (((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F);\r\n colour = curr * whiteScale;\r\n\r\n#elif defined(OPTIMIZED_HEJIDAWSON_TONEMAPPING)\r\n\r\n colour *= _ExposureAdjustment;\r\n \r\n vec3 X = max(vec3(0.0, 0.0, 0.0), colour - 0.004);\r\n vec3 retColor = (X * (6.2 * X + 0.5)) / (X * (6.2 * X + 1.7) + 0.06);\r\n\r\n colour = retColor * retColor;\r\n\r\n#elif defined(PHOTOGRAPHIC_TONEMAPPING)\r\n\r\n colour = vec3(1.0, 1.0, 1.0) - exp2(-_ExposureAdjustment * colour);\r\n\r\n#endif\r\n\r\n gl_FragColor = vec4(colour.rgb, 1.0);\r\n}",volumetricLightScatteringPixelShader:"precision highp float;\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:"precision highp float;\r\n\r\n#if defined(ALPHATEST) || defined(NEED_UV)\r\nvarying vec2 vUV;\r\n#endif\r\n\r\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\r\nuniform sampler2D diffuseSampler;\r\n#endif\r\n\r\n#if defined(DIFFUSE_COLOR_RENDER)\r\nuniform vec3 color;\r\n#endif\r\n\r\n#if defined(OPACITY)\r\nuniform sampler2D opacitySampler;\r\nuniform float opacityLevel;\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\r\n vec4 diffuseColor = texture2D(diffuseSampler, vUV);\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\n if (diffuseColor.a < 0.4)\r\n discard;\r\n#endif\r\n\r\n#ifdef OPACITY\r\n vec4 opacityColor = texture2D(opacitySampler, vUV);\r\n float alpha = 1.0;\r\n\r\n #ifdef OPACITYRGB\r\n opacityColor.rgb = opacityColor.rgb * vec3(0.3, 0.59, 0.11);\r\n alpha *= (opacityColor.x + opacityColor.y + opacityColor.z) * opacityLevel;\r\n #else\r\n alpha *= opacityColor.a * opacityLevel;\r\n #endif\r\n\r\n #if defined(BASIC_RENDER)\r\n gl_FragColor = vec4(diffuseColor.rgb, alpha);\r\n #elif defined(DIFFUSE_COLOR_RENDER)\r\n gl_FragColor = vec4(color.rgb, alpha);\r\n #else\r\n gl_FragColor = vec4(0.0, 0.0, 0.0, alpha);\r\n #endif\r\n\r\n gl_FragColor.a = alpha;\r\n#else\r\n\r\n #if defined(BASIC_RENDER)\r\n gl_FragColor = diffuseColor;\r\n #elif defined(DIFFUSE_COLOR_RENDER)\r\n gl_FragColor = vec4(color.rgb, 1.0);\r\n #else\r\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\r\n #endif\r\n#endif\r\n\r\n}\r\n",vrDistortionCorrectionPixelShader:"precision highp float;\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}"},("undefined"!=typeof window&&window.module||"undefined"!=typeof module)&&"undefined"!=typeof module.exports&&(module.exports=BABYLON);