babylon.2.3.core.js 692 KB

12345678910111213141516171819202122
  1. 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;i<e.length;i+=3){var n=i/3*4;r[n]=e[i],r[n+1]=e[i+1],r[n+2]=e[i+2],r[n+3]=1}return r}return e},t}();e.Color4=n;var s=function(){function t(e,t){this.x=e,this.y=t}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}"},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,this},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this},t.prototype.copyFromFloats=function(e,t){return this.x=e,this.y=t,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.addVector3=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y)},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,this},t.prototype.multiplyByFloats=function(e,r){return new t(this.x*e,this.y*r)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,this},t.prototype.negate=function(){return new t(-this.x,-this.y)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e)},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y},t.prototype.equalsWithEpsilon=function(t,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)},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},t.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this},t.prototype.clone=function(){return new t(this.x,this.y)},t.Zero=function(){return new t(0,0)},t.FromArray=function(e,r){return void 0===r&&(r=0),new t(e[r],e[r+1])},t.FromArrayToRef=function(e,t,r){r.x=e[t],r.y=e[t+1]},t.CatmullRom=function(e,r,i,n,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);return new t(h,c)},t.Clamp=function(e,r,i){var n=e.x;n=n>i.x?i.x:n,n=n<r.x?r.x:n;var s=e.y;return s=s>i.y?i.y:s,s=s<r.y?r.y:s,new t(n,s)},t.Hermite=function(e,r,i,n,s){var o=s*s,a=s*o,h=2*a-3*o+1,c=-2*a+3*o,l=a-2*o+s,u=a-o,f=e.x*h+i.x*c+r.x*l+n.x*u,d=e.y*h+i.y*c+r.y*l+n.y*u;return new t(f,d)},t.Lerp=function(e,r,i){var n=e.x+(r.x-e.x)*i,s=e.y+(r.y-e.y)*i;return new t(n,s)},t.Dot=function(e,t){return e.x*t.x+e.y*t.y},t.Normalize=function(e){var t=e.clone();return t.normalize(),t},t.Minimize=function(e,r){var i=e.x<r.x?e.x:r.x,n=e.y<r.y?e.y:r.y;return new t(i,n)},t.Maximize=function(e,r){var i=e.x>r.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.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),this},t.prototype.MaximizeInPlace=function(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},t.prototype.normalize=function(){var e=this.length();if(0===e||1===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.clone=function(){return new t(this.x,this.y,this.z)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},t.prototype.copyFromFloats=function(e,t,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=n<r.x?r.x:n;var s=e.y;s=s>i.y?i.y:s,s=s<r.y?r.y:s;var o=e.z;return o=o>i.z?i.z:o,o=o<r.z?r.z:o,new t(n,s,o)},t.Hermite=function(e,r,i,n,s){var o=s*s,a=s*o,h=2*a-3*o+1,c=-2*a+3*o,l=a-2*o+s,u=a-o,f=e.x*h+i.x*c+r.x*l+n.x*u,d=e.y*h+i.y*c+r.y*l+n.y*u,p=e.z*h+i.z*c+r.z*l+n.z*u;return new t(f,d,p)},t.Lerp=function(e,r,i){var n=e.x+(r.x-e.x)*i,s=e.y+(r.y-e.y)*i,o=e.z+(r.z-e.z)*i;return new t(n,s,o)},t.Dot=function(e,t){return e.x*t.x+e.y*t.y+e.z*t.z},t.Cross=function(e,r){var i=t.Zero();return t.CrossToRef(e,r,i),i},t.CrossToRef=function(e,t,r){r.x=e.y*t.z-e.z*t.y,r.y=e.z*t.x-e.x*t.z,r.z=e.x*t.y-e.y*t.x},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.Project=function(e,r,i,n){var s=n.width,o=n.height,a=n.x,h=n.y,l=c.FromValues(s/2,0,0,0,0,-o/2,0,0,0,0,1,0,a+s/2,o/2+h,0,1),u=r.multiply(i).multiply(l);return t.TransformCoordinates(e,u)},t.UnprojectFromTransform=function(r,i,n,s,o){var a=s.multiply(o);a.invert(),r.x=r.x/i*2-1,r.y=-(r.y/n*2-1);var h=t.TransformCoordinates(r,a),c=r.x*a.m[3]+r.y*a.m[7]+r.z*a.m[11]+a.m[15];return e.Tools.WithinEpsilon(c,1)&&(h=h.scale(1/c)),h},t.Unproject=function(r,i,n,s,o,a){var h=s.multiply(o).multiply(a);h.invert();var c=new t(r.x/i*2-1,-(r.y/n*2-1),r.z),l=t.TransformCoordinates(c,h),u=c.x*h.m[3]+c.y*h.m[7]+c.z*h.m[11]+h.m[15];return e.Tools.WithinEpsilon(u,1)&&(l=l.scale(1/u)),l},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;return r*r+i*i+n*n},t.Center=function(e,t){var r=e.add(t);return r.scaleInPlace(.5),r},t.RotationFromAxis=function(e,r,i){var n=t.Zero();return t.RotationFromAxisToRef(e,r,i,n),n},t.RotationFromAxisToRef=function(r,i,n,s){var o=r.normalize(),a=n.normalize(),h=p.X,c=p.Y,l=0,u=0,f=0,d=0,m=0,g=0,_=0,v=-1,y=0,x=M.Vector3[0],E=0,T=M.Vector3[1];e.Tools.WithinEpsilon(a.z,0,e.Engine.Epsilon)?g=1:e.Tools.WithinEpsilon(a.x,0,e.Engine.Epsilon)?d=1:(_=a.z/a.x,d=-_*Math.sqrt(1/(1+_*_)),g=Math.sqrt(1/(1+_*_))),T.x=d,T.y=m,T.z=g,T.normalize(),t.CrossToRef(o,T,x),x.normalize(),t.Dot(a,x)<0&&(v=1),E=t.Dot(o,T),E=Math.min(1,Math.max(-1,E)),f=Math.acos(E)*v,t.Dot(T,h)<0&&(f=Math.PI+f,T=T.scaleInPlace(-1),y++);var A=M.Vector3[2],b=M.Vector3[3];d=0,m=0,g=0,v=-1,e.Tools.WithinEpsilon(a.z,0,e.Engine.Epsilon)?d=1:(_=T.z/T.x,d=-_*Math.sqrt(1/(1+_*_)),g=Math.sqrt(1/(1+_*_))),A.x=d,A.y=m,A.z=g,A.normalize(),t.CrossToRef(A,T,b),b.normalize(),t.CrossToRef(a,A,x),x.normalize(),t.Dot(T,x)<0&&(v=1),E=t.Dot(a,A),E=Math.min(1,Math.max(-1,E)),u=Math.acos(E)*v,t.Dot(b,c)<0&&(u=Math.PI+u,y++),v=-1,t.CrossToRef(h,T,x),x.normalize(),t.Dot(x,c)<0&&(v=1),E=t.Dot(T,h),E=Math.min(1,Math.max(-1,E)),l=-Math.acos(E)*v,0>E&&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.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),e.w<this.w&&(this.w=e.w),this},t.prototype.MaximizeInPlace=function(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),e.w>this.w&&(this.w=e.w),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},t.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},t.prototype.copyFromFloats=function(e,t,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);
  2. 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.x<e.x||this.origin.x>t.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.y<e.y||this.origin.y>t.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.z<e.z||this.origin.z>t.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<this._points.length;n++){var o=(n+1)%this._points.length,a=this._points[n],h=this._points[o],c=h.subtract(a),l=c.length()+i;if(r>=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;i<e.length;i++)this._curve[i]=e[i].clone();this._raw=r||!1,this._compute(t)}return t.prototype.getCurve=function(){return this._curve},t.prototype.getTangents=function(){return this._tangents},t.prototype.getNormals=function(){return this._normals},t.prototype.getBinormals=function(){return this._binormals},t.prototype.getDistances=function(){return this._distances},t.prototype.update=function(e,t){for(var r=0;r<e.length;r++)this._curve[r].x=e[r].x,this._curve[r].y=e[r].y,this._curve[r].z=e[r].z;return this._compute(t),this},t.prototype._compute=function(e){var t=this._curve.length;this._tangents[0]=this._getFirstNonNullVector(0),this._raw||this._tangents[0].normalize(),this._tangents[t-1]=this._curve[t-1].subtract(this._curve[t-2]),this._raw||this._tangents[t-1].normalize();var r=this._tangents[0],i=this._normalVector(this._curve[0],r,e);this._normals[0]=i,this._raw||this._normals[0].normalize(),this._binormals[0]=o.Cross(r,this._normals[0]),this._raw||this._binormals[0].normalize(),this._distances[0]=0;for(var n,s,a,h,c=1;t>c;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+1<this._curve.length;)t++,r=this._curve[e+t].subtract(this._curve[e]);return r},t.prototype._getLastNonNullVector=function(e){for(var t=1,r=this._curve[e].subtract(this._curve[e-t]);0===r.length()&&e>t+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;s<n.length;s++)i.push(n[s].subtract(n[0]).add(r));var o=new e(i);return o},e.prototype._computeLength=function(e){for(var t=0,r=1;r<e.length;r++)t+=e[r].subtract(e[r-1]).length();return t},e}();e.Curve3=T;var A=function(){function e(e,t){void 0===e&&(e=o.Zero()),void 0===t&&(t=o.Up()),this.position=e,this.normal=t}return e.prototype.clone=function(){return new e(this.position.clone(),this.normal.clone())},e}();e.PositionNormalVertex=A;var b=function(){function e(e,t,r){void 0===e&&(e=o.Zero()),void 0===t&&(t=o.Up()),void 0===r&&(r=s.Zero()),this.position=e,this.normal=t,this.uv=r}return e.prototype.clone=function(){return new e(this.position.clone(),this.normal.clone(),this.uv.clone())},e}();e.PositionNormalTextureVertex=b;var M=function(){function e(){}return e.Vector2=[s.Zero(),s.Zero(),s.Zero()],e.Vector3=[o.Zero(),o.Zero(),o.Zero(),o.Zero(),o.Zero(),o.Zero()],e.Vector4=[a.Zero(),a.Zero(),a.Zero()],e.Quaternion=[new h(0,0,0,0)],e.Matrix=[c.Zero(),c.Zero(),c.Zero(),c.Zero(),c.Zero(),c.Zero(),c.Zero(),c.Zero()],e}();e.Tmp=M}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,r){this.idbFactory=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,this.callbackManifestChecked=r,this.currentSceneUrl=t.ReturnFullUrlLocation(e),this.db=null,this.enableSceneOffline=!1,this.enableTexturesOffline=!1,this.manifestVersionFound=0,this.mustUpdateRessources=!1,this.hasReachedQuota=!1,t.IDBStorageEnabled?this.checkManifestFile():this.callbackManifestChecked(!0)}return t.prototype.checkManifestFile=function(){function t(){i.enableSceneOffline=!1,i.enableTexturesOffline=!1,i.callbackManifestChecked(!1)}var r=this,i=this,n=!1,s=this.currentSceneUrl+".manifest",o=new XMLHttpRequest;navigator.onLine&&(n=!0,s=s+(null==s.match(/\?/)?"?":"&")+(new Date).getTime()),o.open("GET",s,!0),o.addEventListener("load",function(){if(200===o.status||e.Tools.ValidateXHRData(o,1))try{var i=JSON.parse(o.response);r.enableSceneOffline=i.enableSceneOffline,r.enableTexturesOffline=i.enableTexturesOffline,i.version&&!isNaN(parseInt(i.version))&&(r.manifestVersionFound=i.version),r.callbackManifestChecked&&r.callbackManifestChecked(!0)}catch(n){t()}else t()},!1),o.addEventListener("error",function(e){if(n){n=!1;var i=r.currentSceneUrl+".manifest";o.open("GET",i,!0),o.send()}else t()},!1);try{o.send()}catch(a){e.Tools.Error("Error on XHR send request."),i.callbackManifestChecked(!1)}},t.prototype.openAsync=function(t,r){function i(){s.isSupported=!1,r&&r()}var n=this,s=this;if(this.idbFactory&&(this.enableSceneOffline||this.enableTexturesOffline))if(this.db)t&&t();else{this.hasReachedQuota=!1,this.isSupported=!0;var o=this.idbFactory.open("babylonjs",1);o.onerror=function(e){i()},o.onblocked=function(t){e.Tools.Error("IDB request blocked. Please reload the page."),i()},o.onsuccess=function(e){n.db=o.result,t()},o.onupgradeneeded=function(t){n.db=t.target.result;try{n.db.createObjectStore("scenes",{keyPath:"sceneUrl"}),n.db.createObjectStore("versions",{keyPath:"sceneUrl"}),n.db.createObjectStore("textures",{keyPath:"textureUrl"})}catch(r){e.Tools.Error("Error while creating object stores. Exception: "+r.message),i()}}}else this.isSupported=!1,r&&r()},t.prototype.loadImageFromDB=function(e,r){var i=this,n=t.ReturnFullUrlLocation(e),s=function(){i.hasReachedQuota||null===i.db?r.src=e:i._saveImageIntoDBAsync(n,r)};this.mustUpdateRessources?s():this._loadImageFromDBAsync(n,r,s)},t.prototype._loadImageFromDBAsync=function(t,r,i){if(this.isSupported&&null!==this.db){var n,s=this.db.transaction(["textures"]);s.onabort=function(e){r.src=t},s.oncomplete=function(s){var o;if(n){var a=window.URL||window.webkitURL;o=a.createObjectURL(n.data,{oneTimeOnly:!0}),r.onerror=function(){e.Tools.Error("Error loading image from blob URL: "+o+" switching back to web url: "+t),r.src=t},r.src=o}else i()};var o=s.objectStore("textures").get(t);o.onsuccess=function(e){n=e.target.result},o.onerror=function(i){e.Tools.Error("Error loading texture "+t+" from DB."),r.src=t}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),r.src=t},t.prototype._saveImageIntoDBAsync=function(r,i){var n=this;if(this.isSupported){var s=function(){var e;if(o){var t=window.URL||window.webkitURL;try{e=t.createObjectURL(o,{oneTimeOnly:!0})}catch(r){e=t.createObjectURL(o)}}i.src=e};if(t.IsUASupportingBlobStorage){var o,a=new XMLHttpRequest;a.open("GET",r,!0),a.responseType="blob",a.addEventListener("load",function(){if(200===a.status){o=a.response;var e=n.db.transaction(["textures"],"readwrite");e.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(t){}s()},e.oncomplete=function(e){s()};var h={textureUrl:r,data:o};try{var c=e.objectStore("textures").put(h);c.onsuccess=function(e){},c.onerror=function(e){s()}}catch(l){25===l.code&&(t.IsUASupportingBlobStorage=!1),i.src=r}}else i.src=r},!1),a.addEventListener("error",function(t){e.Tools.Error("Error in XHR request in BABYLON.Database."),i.src=r},!1),a.send()}else i.src=r}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i.src=r},t.prototype._checkVersionFromDB=function(e,t){var r=this,i=function(i){r._saveVersionIntoDBAsync(e,t)};this._loadVersionFromDBAsync(e,t,i)},t.prototype._loadVersionFromDBAsync=function(t,r,i){var n=this;if(this.isSupported){var s;try{var o=this.db.transaction(["versions"]);o.oncomplete=function(e){s?n.manifestVersionFound>s.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;t<e.length;t++)this.data[this.length++]=(e.data||e)[t]}},e.prototype.concatWithNoDuplicate=function(e){if(0!==e.length){this.length+e.length>this.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t<e.length;t++){var r=(e.data||e)[t];this.pushNoDuplicate(r)}}},e.prototype.indexOf=function(e){var t=this.data.indexOf(e);return t>=this.length?-1:t},e._GlobalId=0,e}();e.SmartArray=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){void 0===e&&(e=10),this.count=0,this._initialCapacity=e,this.items={},this._keys=new Array(this._initialCapacity)}return e.prototype.add=function(e,t){return void 0!=this.items[e]?-1:(this.items[e]=t,this._keys[this.count++]=e,this.count>this._keys.length&&(this._keys.length*=2),this.count)},e.prototype.remove=function(e){return void 0==this.items[e]?-1:this.removeItemOfIndex(this.indexOf(e))},e.prototype.removeItemOfIndex=function(e){if(!(e<this.count&&e>-1))return-1;for(delete this.items[this._keys[e]];e<this.count;)this._keys[e]=this._keys[e+1],e++;return--this.count},e.prototype.indexOf=function(e){for(var t=0;t!==this.count;t++)if(this._keys[t]===e)return t;
  3. return-1},e.prototype.item=function(e){return this.items[e]},e.prototype.getAllKeys=function(){if(this.count>0){for(var e=new Array(this.count),t=0;t<this.count;t++)e[t]=this._keys[t];return e}return void 0},e.prototype.getKeyByIndex=function(e){return e<this.count&&e>-1?this._keys[e]:void 0},e.prototype.getItemByIndex=function(e){return e<this.count&&e>-1?this.items[this._keys[e]]:void 0},e.prototype.empty=function(){this.count>0&&(this.count=0,this.items={},this._keys=new Array(this._initialCapacity))},e.prototype.forEach=function(e){var t;for(t in this.items)this.items.hasOwnProperty(t)&&e(this.items[t])},e}();e.SmartCollection=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t,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<u.length;)t=u[l++],r=l<u.length?u[l++]:Number.NaN,i=l<u.length?u[l++]:Number.NaN,n=t>>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.x<t.x&&(t.x=e.x),e.y<t.y&&(t.y=e.y),e.z<t.z&&(t.z=e.z),e.x>r.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;h<o.length;h++){var c=r(o[h],t);-1===t[s].indexOf(c)&&t[s].push(c)}else t[s]=o.slice(0)}else t[s]=r(o,t);else t[s]=o}},i.IsEmpty=function(e){for(var t in e)return!1;return!0},i.RegisterTopRootEvents=function(e){for(var t=0;t<e.length;t++){var r=e[t];window.addEventListener(r.name,r.handler,!1);try{window.parent&&window.parent.addEventListener(r.name,r.handler,!1)}catch(i){}}},i.UnregisterTopRootEvents=function(e){for(var t=0;t<e.length;t++){var r=e[t];window.removeEventListener(r.name,r.handler);try{window.parent&&window.parent.removeEventListener(r.name,r.handler)}catch(i){}}},i.DumpFramebuffer=function(e,r,i,n){for(var s=4*e,o=r/2,a=i.readPixels(0,0,e,r),h=0;o>h;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="<div style='color:white'>"+t+"</div><br>";i._AddLogEntry(r)},i._WarnDisabled=function(e){},i._WarnEnabled=function(e){var t=i._FormatMessage(e);console.warn("BJS - "+t);var r="<div style='color:orange'>"+t+"</div><br>";i._AddLogEntry(r)},i._ErrorDisabled=function(e){},i._ErrorEnabled=function(e){i.errorsCount++;var t=i._FormatMessage(e);console.error("BJS - "+t);var r="<div style='color:red'>"+t+"</div><br>";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+1<this.iterations?(++this.index,this._fn(this)):this.breakLoop())},e.prototype.breakLoop=function(){this._done=!0,this._successCallback()},e.Run=function(t,r,i,n){void 0===n&&(n=0);var s=new e(t,r,i,n);return s.executeNext(),s},e.SyncAsyncForLoop=function(t,r,i,n,s,o){void 0===o&&(o=0),e.Run(Math.ceil(t/r),function(e){s&&s()?e.breakLoop():setTimeout(function(){for(var n=0;r>n;++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<this._maxTextureChannels;e++)this._activeTexturesCache[e]=null},a.prototype.getGlInfo=function(){return{vendor:this._glVendor,renderer:this._glRenderer,version:this._glVersion}},a.prototype.getAspectRatio=function(e,t){void 0===t&&(t=!1);var r=e.viewport;return this.getRenderWidth(t)*r.width/(this.getRenderHeight(t)*r.height)},a.prototype.getRenderWidth=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget._width:this._renderingCanvas.width},a.prototype.getRenderHeight=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget._height:this._renderingCanvas.height;
  4. },a.prototype.getRenderingCanvas=function(){return this._renderingCanvas},a.prototype.getRenderingCanvasClientRect=function(){return this._renderingCanvas.getBoundingClientRect()},a.prototype.setHardwareScalingLevel=function(e){this._hardwareScalingLevel=e,this.resize()},a.prototype.getHardwareScalingLevel=function(){return this._hardwareScalingLevel},a.prototype.getLoadedTexturesCache=function(){return this._loadedTexturesCache},a.prototype.getCaps=function(){return this._caps},Object.defineProperty(a.prototype,"drawCalls",{get:function(){return this._drawCalls},enumerable:!0,configurable:!0}),a.prototype.resetDrawCalls=function(){this._drawCalls=0},a.prototype.setDepthFunctionToGreater=function(){this._depthCullingState.depthFunc=this._gl.GREATER},a.prototype.setDepthFunctionToGreaterOrEqual=function(){this._depthCullingState.depthFunc=this._gl.GEQUAL},a.prototype.setDepthFunctionToLess=function(){this._depthCullingState.depthFunc=this._gl.LESS},a.prototype.setDepthFunctionToLessOrEqual=function(){this._depthCullingState.depthFunc=this._gl.LEQUAL},a.prototype.stopRenderLoop=function(e){if(!e)return void(this._activeRenderLoops=[]);var t=this._activeRenderLoops.indexOf(e);t>=0&&this._activeRenderLoops.splice(t,1)},a.prototype._renderLoop=function(){var t=!0;if(!this.renderEvenInBackground&&this._windowIsBackground&&(t=!1),t){this.beginFrame();for(var r=0;r<this._activeRenderLoops.length;r++){var i=this._activeRenderLoops[r];i()}this.endFrame()}this._activeRenderLoops.length>0?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;r<this.scenes.length;r++){var i=this.scenes[r];i.debugLayer.isVisible()&&i.debugLayer._syncPositions()}},a.prototype.setSize=function(e,t){this._renderingCanvas.width=e,this._renderingCanvas.height=t;for(var r=0;r<this.scenes.length;r++)for(var i=this.scenes[r],n=0;n<i.cameras.length;n++){var s=i.cameras[n];s._currentRenderId=0}},a.prototype.bindFramebuffer=function(e,t){this._currentRenderTarget=e;var r=this._gl;r.bindFramebuffer(r.FRAMEBUFFER,e._framebuffer),e.isCube?r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_CUBE_MAP_POSITIVE_X+t,e,0):r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,e,0),this._gl.viewport(0,0,e._width,e._height),this.wipeCaches()},a.prototype.unBindFramebuffer=function(e,t){if(void 0===t&&(t=!1),this._currentRenderTarget=null,e.generateMipMaps&&!t){var r=this._gl;r.bindTexture(r.TEXTURE_2D,e),r.generateMipmap(r.TEXTURE_2D),r.bindTexture(r.TEXTURE_2D,null)}this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,null)},a.prototype.generateMipMapsForCubemap=function(e){if(e.generateMipMaps){var t=this._gl;t.bindTexture(t.TEXTURE_CUBE_MAP,e),t.generateMipmap(t.TEXTURE_CUBE_MAP),t.bindTexture(t.TEXTURE_CUBE_MAP,null)}},a.prototype.flushFramebuffer=function(){this._gl.flush()},a.prototype.restoreDefaultFramebuffer=function(){this._currentRenderTarget=null,this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,null),this.setViewport(this._cachedViewport),this.wipeCaches()},a.prototype._resetVertexBufferBinding=function(){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,null),this._cachedVertexBuffers=null},a.prototype.createVertexBuffer=function(e){var t=this._gl.createBuffer();return this._gl.bindBuffer(this._gl.ARRAY_BUFFER,t),e instanceof Float32Array?this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.STATIC_DRAW):this._gl.bufferData(this._gl.ARRAY_BUFFER,new Float32Array(e),this._gl.STATIC_DRAW),this._resetVertexBufferBinding(),t.references=1,t},a.prototype.createDynamicVertexBuffer=function(e){var t=this._gl.createBuffer();return this._gl.bindBuffer(this._gl.ARRAY_BUFFER,t),this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.DYNAMIC_DRAW),this._resetVertexBufferBinding(),t.references=1,t},a.prototype.updateDynamicVertexBuffer=function(e,t,r){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e),void 0===r&&(r=0),t instanceof Float32Array?this._gl.bufferSubData(this._gl.ARRAY_BUFFER,r,t):this._gl.bufferSubData(this._gl.ARRAY_BUFFER,r,new Float32Array(t)),this._resetVertexBufferBinding()},a.prototype._resetIndexBufferBinding=function(){this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,null),this._cachedIndexBuffer=null},a.prototype.createIndexBuffer=function(e){var t=this._gl.createBuffer();this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,t);var r,i=!1;if(this._caps.uintIndices){for(var n=0;n<e.length;n++)if(e[n]>65535){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<r.length;o++){var a=n.getAttributeLocation(o);a>=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<i.length;n++){var s=r.getAttributeLocation(n);if(s>=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;i<t.length;i++)r.push(this._gl.getUniformLocation(e,t[i]));return r},a.prototype.getAttributes=function(e,t){for(var r=[],i=0;i<t.length;i++)try{r.push(this._gl.getAttribLocation(e,t[i]))}catch(n){r.push(-1)}return r},a.prototype.enableEffect=function(e){if(!e||!e.getAttributesCount()||this._currentEffect===e)return void(e&&e.onBind&&e.onBind(e));this._vertexAttribArrays=this._vertexAttribArrays||[],this._gl.useProgram(e.getProgram());for(var t in this._vertexAttribArrays)t>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[t]||(this._vertexAttribArrays[t]=!1,this._gl.disableVertexAttribArray(t));for(var 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;c<h.length;c++)s._workingContext.drawImage(t[c],0,0,t[c].width,t[c].height,0,0,r,i),o.texImage2D(h[c],0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,s._workingCanvas);n||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,n?o.LINEAR:o.LINEAR_MIPMAP_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,a._height=i,a.isReady=!0},i),a},a.prototype._releaseTexture=function(e){var t=this._gl;e._framebuffer&&t.deleteFramebuffer(e._framebuffer),e._depthBuffer&&t.deleteRenderbuffer(e._depthBuffer),t.deleteTexture(e),this.unbindAllTextures();var r=this._loadedTexturesCache.indexOf(e);-1!==r&&this._loadedTexturesCache.splice(r,1)},a.prototype.bindSamplers=function(e){this._gl.useProgram(e.getProgram());for(var t=e.getSamplers(),r=0;r<t.length;r++){var i=e.getUniform(t[r]);this._gl.uniform1i(i,r)}this._currentEffect=null},a.prototype._bindTexture=function(e,t){this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,t),this._activeTexturesCache[e]=null},a.prototype.setTextureFromPostProcess=function(e,t){this._bindTexture(e,t._textures.data[t._currentRenderTextureInd])},a.prototype.unbindAllTextures=function(){for(var e=0;e<this._caps.maxTexturesImageUnits;e++)this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,null),this._activeTexturesCache[e]=null},a.prototype.setTexture=function(t,r){if(!(0>t)){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]),
  5. 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;r<e.length;r++){var i=e[r];i.isDescendantOf(this)&&t.push(i)}},t.prototype.getDescendants=function(){var e=[];return this._getDescendants(this._scene.meshes,e),this._getDescendants(this._scene.lights,e),this._getDescendants(this._scene.cameras,e),e},t.prototype._setReady=function(e){if(e!==this._isReady){if(!e)return void(this._isReady=!1);this._isReady=!0,this.onReady&&this.onReady(this)}},t.prototype.getAnimationByName=function(e){for(var t=0;t<this.animations.length;t++){var r=this.animations[t];if(r.name===e)return r}return null},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.animations.length;s>n;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;i<t.ranges.length;i++){var n=t.ranges[i];e.createAnimationRange(n.name,n.from,n.to)}},t}();e.Node=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,r,i,n,s,o,a){this._engine=e,this._canvas=r,this._currentScene=t,this._sceneLoadedCallback=i,this._progressCallback=n,this._additionnalRenderLoopLogicCallback=s,this._textureLoadingCallback=o,this._startingProcessingFilesCallback=a}return t.prototype.monitorElementForDragNDrop=function(e){var t=this;e&&(this._elementToMonitor=e,this._elementToMonitor.addEventListener("dragenter",function(e){t.drag(e)},!1),this._elementToMonitor.addEventListener("dragover",function(e){t.drag(e)},!1),this._elementToMonitor.addEventListener("drop",function(e){t.drop(e)},!1))},t.prototype.renderFunction=function(){if(this._additionnalRenderLoopLogicCallback&&this._additionnalRenderLoopLogicCallback(),this._currentScene){if(this._textureLoadingCallback){var e=this._currentScene.getWaitingItemsCount();e>0&&this._textureLoadingCallback(e)}this._currentScene.render()}},t.prototype.drag=function(e){e.stopPropagation(),e.preventDefault()},t.prototype.drop=function(e){e.stopPropagation(),e.preventDefault(),this.loadFiles(e)},t.prototype.loadFiles=function(e){if(this._startingProcessingFilesCallback&&this._startingProcessingFilesCallback(),e&&e.dataTransfer&&e.dataTransfer.files&&(this._filesToLoad=e.dataTransfer.files),e&&e.target&&e.target.files&&(this._filesToLoad=e.target.files),this._filesToLoad&&this._filesToLoad.length>0){for(var r=0;r<this._filesToLoad.length;r++)switch(this._filesToLoad[r].type){case"image/jpeg":case"image/png":case"image/bmp":t.FilesTextures[this._filesToLoad[r].name]=this._filesToLoad[r];break;case"image/targa":case"image/vnd.ms-dds":case"audio/wav":case"audio/x-wav":case"audio/mp3":case"audio/mpeg":case"audio/mpeg3":case"audio/x-mpeg-3":case"audio/ogg":t.FilesToLoad[this._filesToLoad[r].name]=this._filesToLoad[r];break;default:-1===this._filesToLoad[r].name.indexOf(".babylon")&&-1===this._filesToLoad[r].name.indexOf(".stl")&&-1===this._filesToLoad[r].name.indexOf(".obj")&&-1===this._filesToLoad[r].name.indexOf(".mtl")||-1!==this._filesToLoad[r].name.indexOf(".manifest")||-1!==this._filesToLoad[r].name.indexOf(".incremental")||-1!==this._filesToLoad[r].name.indexOf(".babylonmeshdata")||-1!==this._filesToLoad[r].name.indexOf(".babylongeometrydata")||-1!==this._filesToLoad[r].name.indexOf(".babylonbinarymeshdata")||-1!==this._filesToLoad[r].name.indexOf(".binary.babylon")||(this._sceneFileToLoad=this._filesToLoad[r])}this.reload()}},t.prototype.reload=function(){var t=this,r=this;this._sceneFileToLoad?(this._currentScene&&(e.Tools.errorsCount>0&&(e.Tools.ClearLogCache(),e.Tools.Log("Babylon.js engine (v"+e.Engine.Version+") launched")),this._engine.stopRenderLoop(),this._currentScene.dispose()),e.SceneLoader.Load("file:",this._sceneFileToLoad,this._engine,function(e){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)<e.Engine.Epsilon?!1:!0},t.Intersects=function(e,t){var r=e.centerWorld.x-t.centerWorld.x,i=e.centerWorld.y-t.centerWorld.y,n=e.centerWorld.z-t.centerWorld.z,s=Math.sqrt(r*r+i*i+n*n);return e.radiusWorld+t.radiusWorld<s?!1:!0},t}();e.BoundingSphere=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r){this.minimum=t,this.maximum=r,this.vectors=new Array,this.vectorsWorld=new Array,this.vectors.push(this.minimum.clone()),this.vectors.push(this.maximum.clone()),this.vectors.push(this.minimum.clone()),this.vectors[2].x=this.maximum.x,this.vectors.push(this.minimum.clone()),this.vectors[3].y=this.maximum.y,this.vectors.push(this.minimum.clone()),this.vectors[4].z=this.maximum.z,this.vectors.push(this.maximum.clone()),this.vectors[5].z=this.minimum.z,this.vectors.push(this.maximum.clone()),this.vectors[6].x=this.minimum.x,this.vectors.push(this.maximum.clone()),this.vectors[7].y=this.minimum.y,this.center=this.maximum.add(this.minimum).scale(.5),this.extendSize=this.maximum.subtract(this.minimum).scale(.5),this.directions=[e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero()];for(var i=0;i<this.vectors.length;i++)this.vectorsWorld[i]=e.Vector3.Zero();this.minimumWorld=e.Vector3.Zero(),this.maximumWorld=e.Vector3.Zero(),this._update(e.Matrix.Identity())}return t.prototype.getWorldMatrix=function(){return this._worldMatrix},t.prototype._update=function(t){e.Vector3.FromFloatsToRef(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,this.minimumWorld),e.Vector3.FromFloatsToRef(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE,this.maximumWorld);for(var r=0;r<this.vectors.length;r++){var i=this.vectorsWorld[r];e.Vector3.TransformCoordinatesToRef(this.vectors[r],t,i),i.x<this.minimumWorld.x&&(this.minimumWorld.x=i.x),i.y<this.minimumWorld.y&&(this.minimumWorld.y=i.y),i.z<this.minimumWorld.z&&(this.minimumWorld.z=i.z),i.x>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.x<r||r>t.x-this.minimumWorld.x?!1:this.maximumWorld.y-t.y<r||r>t.y-this.minimumWorld.y?!1:this.maximumWorld.z-t.z<r||r>t.z-this.minimumWorld.z?!1:!0},t.prototype.intersectsSphere=function(e){return t.IntersectsSphere(this.minimumWorld,this.maximumWorld,e.centerWorld,e.radiusWorld)},t.prototype.intersectsMinMax=function(e,t){return this.maximumWorld.x<e.x||this.minimumWorld.x>t.x?!1:this.maximumWorld.y<e.y||this.minimumWorld.y>t.y?!1:this.maximumWorld.z<e.z||this.minimumWorld.z>t.z?!1:!0},t.Intersects=function(e,t){return e.maximumWorld.x<t.minimumWorld.x||e.minimumWorld.x>t.maximumWorld.x?!1:e.maximumWorld.y<t.minimumWorld.y||e.minimumWorld.y>t.maximumWorld.y?!1:e.maximumWorld.z<t.minimumWorld.z||e.minimumWorld.z>t.maximumWorld.z?!1:!0},t.IntersectsSphere=function(t,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<this.subMeshes.length;t++){var r=this.subMeshes[t];r.IsGlobal||r.updateBoundingInfo(e)}},r.prototype.computeWorldMatrix=function(t){if(this._isWorldMatrixFrozen)return this._worldMatrix;if(!t&&(this._currentRenderId===this.getScene().getRenderId()||this.isSynchronized(!0)))return this._currentRenderId=this.getScene().getRenderId(),this._worldMatrix;if(this._cache.position.copyFrom(this.position),this._cache.scaling.copyFrom(this.scaling),this._cache.pivotMatrixUpdated=!1,this._cache.billboardMode=this.billboardMode,this._currentRenderId=this.getScene().getRenderId(),this._isDirty=!1,e.Matrix.ScalingToRef(this.scaling.x*this.scalingDeterminant,this.scaling.y*this.scalingDeterminant,this.scaling.z*this.scalingDeterminant,e.Tmp.Matrix[1]),this.rotationQuaternion?(this.rotationQuaternion.toRotationMatrix(e.Tmp.Matrix[0]),this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion)):(e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,e.Tmp.Matrix[0]),this._cache.rotation.copyFrom(this.rotation)),this.infiniteDistance&&!this.parent){var i=this.getScene().activeCamera;if(i){var n=i.getWorldMatrix(),s=new e.Vector3(n.m[12],n.m[13],n.m[14]);e.Matrix.TranslationToRef(this.position.x+s.x,this.position.y+s.y,this.position.z+s.z,e.Tmp.Matrix[2])}}else e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,e.Tmp.Matrix[2]);if(this._pivotMatrix.multiplyToRef(e.Tmp.Matrix[1],e.Tmp.Matrix[4]),e.Tmp.Matrix[4].multiplyToRef(e.Tmp.Matrix[0],e.Tmp.Matrix[5]),this.billboardMode!==r.BILLBOARDMODE_NONE&&this.getScene().activeCamera){var o=this.position.clone(),a=this.getScene().activeCamera.globalPosition.clone();this.parent&&this.parent.position&&(o.addInPlace(this.parent.position),e.Matrix.TranslationToRef(o.x,o.y,o.z,e.Tmp.Matrix[2])),(this.billboardMode&r.BILLBOARDMODE_ALL)!==r.BILLBOARDMODE_ALL&&(this.billboardMode&r.BILLBOARDMODE_X&&(a.x=o.x+e.Engine.Epsilon),this.billboardMode&r.BILLBOARDMODE_Y&&(a.y=o.y+.001),this.billboardMode&r.BILLBOARDMODE_Z&&(a.z=o.z+.001)),e.Matrix.LookAtLHToRef(o,a,e.Vector3.Up(),e.Tmp.Matrix[3]),e.Tmp.Matrix[3].m[12]=e.Tmp.Matrix[3].m[13]=e.Tmp.Matrix[3].m[14]=0,e.Tmp.Matrix[3].invert(),e.Tmp.Matrix[5].multiplyToRef(e.Tmp.Matrix[3],this._localWorld),this._rotateYByPI.multiplyToRef(this._localWorld,e.Tmp.Matrix[5])}e.Tmp.Matrix[5].multiplyToRef(e.Tmp.Matrix[2],this._localWorld),this.parent&&this.parent.getWorldMatrix&&this.billboardMode===r.BILLBOARDMODE_NONE?(this._markSyncedWithParent(),this._meshToBoneReferal?(this._localWorld.multiplyToRef(this.parent.getWorldMatrix(),e.Tmp.Matrix[6]),e.Tmp.Matrix[6].multiplyToRef(this._meshToBoneReferal.getWorldMatrix(),this._worldMatrix)):this._localWorld.multiplyToRef(this.parent.getWorldMatrix(),this._worldMatrix)):this._worldMatrix.copyFrom(this._localWorld),this._updateBoundingInfo(),this._absolutePosition.copyFromFloats(this._worldMatrix.m[12],this._worldMatrix.m[13],this._worldMatrix.m[14]);for(var h=0;h<this._onAfterWorldMatrixUpdate.length;h++)this._onAfterWorldMatrixUpdate[h](this);return this._poseMatrix||(this._poseMatrix=e.Matrix.Invert(this._worldMatrix)),this._worldMatrix},r.prototype.registerAfterWorldMatrixUpdate=function(e){this._onAfterWorldMatrixUpdate.push(e)},r.prototype.unregisterAfterWorldMatrixUpdate=function(e){var t=this._onAfterWorldMatrixUpdate.indexOf(e);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
  6. }),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.distance<o.distance)&&(o=u,o.subMeshId=c,r))break}}if(o){var f=this.getWorldMatrix(),d=e.Vector3.TransformCoordinates(t.origin,f),p=t.direction.clone();p=p.scale(o.distance);var m=e.Vector3.TransformNormal(p,f),g=d.add(m);return i.hit=!0,i.distance=e.Vector3.Distance(d,g),i.pickedPoint=g,i.pickedMesh=this,i.bu=o.bu,i.bv=o.bv,i.faceId=o.faceId,i.subMeshId=o.subMeshId,i}return i},r.prototype.clone=function(e,t,r){return null},r.prototype.releaseSubMeshes=function(){if(this.subMeshes)for(;this.subMeshes.length;)this.subMeshes[0].dispose();else this.subMeshes=new Array},r.prototype.dispose=function(t){var r;for(this.skeleton=null,this.getScene().stopAnimation(this),this.getPhysicsImpostor()!==e.PhysicsEngine.NoImpostor&&this.setPhysicsState(e.PhysicsEngine.NoImpostor),r=0;r<this._intersectionsInProgress.length;r++){var i=this._intersectionsInProgress[r],n=i._intersectionsInProgress.indexOf(this);i._intersectionsInProgress.splice(n,1)}if(this._intersectionsInProgress=[],this._edgesRenderer&&(this._edgesRenderer.dispose(),this._edgesRenderer=null),this.releaseSubMeshes(),this.getScene().removeMesh(this),t)for(r=0;r<this.getScene().meshes.length;r++){var s=this.getScene().meshes[r];s.parent===this&&(s.parent=null,s.computeWorldMatrix(!0))}else{for(r=0;r<this.getScene().particleSystems.length;r++)this.getScene().particleSystems[r].emitter===this&&(this.getScene().particleSystems[r].dispose(),r--);var o=this.getScene().meshes.slice(0);for(r=0;r<o.length;r++)o[r].parent===this&&o[r].dispose()}this._onAfterWorldMatrixUpdate=[],this._isDisposed=!0,this.onDispose&&this.onDispose()},r._BILLBOARDMODE_NONE=0,r._BILLBOARDMODE_X=1,r._BILLBOARDMODE_Y=2,r._BILLBOARDMODE_Z=4,r._BILLBOARDMODE_ALL=7,r}(e.Node);e.AbstractMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i){t.call(this,r,i),this.diffuse=new e.Color3(1,1,1),this.specular=new e.Color3(1,1,1),this.intensity=1,this.range=Number.MAX_VALUE,this.includeOnlyWithLayerMask=0,this.includedOnlyMeshes=new Array,this.excludedMeshes=new Array,this.excludeWithLayerMask=0,this._excludedMeshesIds=new Array,this._includedOnlyMeshesIds=new Array,i.addLight(this)}return __extends(r,t),r.prototype.getShadowGenerator=function(){return this._shadowGenerator},r.prototype.getAbsolutePosition=function(){return e.Vector3.Zero()},r.prototype.transferToEffect=function(e,t,r){},r.prototype._getWorldMatrix=function(){return e.Matrix.Identity()},r.prototype.canAffectMesh=function(e){return e?this.includedOnlyMeshes.length>0&&-1===this.includedOnlyMeshes.indexOf(e)?!1:this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e)?!1:0!==this.includeOnlyWithLayerMask&&0===(this.includeOnlyWithLayerMask&e.layerMask)?!1:0!==this.excludeWithLayerMask&&this.excludeWithLayerMask&e.layerMask?!1:!0:!0},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;n<t.animations.length;n++){var s=t.animations[n];i.animations.push(e.Animation.Parse(s))}e.Node.ParseAnimationRanges(i,t,r)}return t.autoAnimate&&r.beginAnimation(i,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,1),i},r}(e.Node);e.Light=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(e,r,i){t.call(this,e,i),this.position=r}return __extends(r,t),r.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},r.prototype.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(e,t){return this.parent&&this.parent.getWorldMatrix?(this.computeTransformedPosition(),void e.setFloat4(t,this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,0)):void e.setFloat4(t,this.position.x,this.position.y,this.position.z,0)},r.prototype.needCube=function(){return!0},r.prototype.supportsVSM=function(){return!1},r.prototype.needRefreshPerFrame=function(){return!1},r.prototype.getShadowDirection=function(t){switch(t){case 0:return new e.Vector3(1,0,0);case 1:return new e.Vector3(-1,0,0);case 2:return new e.Vector3(0,-1,0);case 3:return new e.Vector3(0,1,0);case 4:return new e.Vector3(0,0,1);case 5:return new e.Vector3(0,0,-1)}return e.Vector3.Zero()},r.prototype.setShadowProjectionMatrix=function(t,r,i){var n=this.getScene().activeCamera;e.Matrix.PerspectiveFovLHToRef(Math.PI/2,1,n.minZ,n.maxZ,t)},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=0,e.position=this.position.asArray(),e},r}(e.Light);e.PointLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(e,r,i,n,s,o){t.call(this,e,o),this.position=r,this.direction=i,this.angle=n,this.exponent=s}return __extends(r,t),r.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},r.prototype.setShadowProjectionMatrix=function(t,r,i){var n=this.getScene().activeCamera;e.Matrix.PerspectiveFovLHToRef(this.angle,1,n.minZ,n.maxZ,t)},r.prototype.needCube=function(){return!1},r.prototype.supportsVSM=function(){return!0},r.prototype.needRefreshPerFrame=function(){return!1},r.prototype.getShadowDirection=function(e){return this.direction},r.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(this.position)),this.direction},r.prototype.computeTransformedPosition=function(){return this.parent&&this.parent.getWorldMatrix?(this.transformedPosition||(this.transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),!0):!1},r.prototype.transferToEffect=function(t,r,i){var n;this.parent&&this.parent.getWorldMatrix?(this._transformedDirection||(this._transformedDirection=e.Vector3.Zero()),this.computeTransformedPosition(),e.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection),t.setFloat4(r,this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,this.exponent),n=e.Vector3.Normalize(this._transformedDirection)):(t.setFloat4(r,this.position.x,this.position.y,this.position.z,this.exponent),n=e.Vector3.Normalize(this.direction)),t.setFloat4(i,n.x,n.y,n.z,Math.cos(.5*this.angle))},r.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},r.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.type=2,e.position=this.position.asArray(),e.direction=this.position.asArray(),e.angle=this.angle,e.exponent=this.exponent,e},r}(e.Light);e.SpotLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i,n){t.call(this,r,n),this.direction=i,this.groundColor=new e.Color3(0,0,0)}return __extends(r,t),r.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(e.Vector3.Zero())),this.direction},r.prototype.getShadowGenerator=function(){return null},r.prototype.transferToEffect=function(t,r,i){var n=e.Vector3.Normalize(this.direction);t.setFloat4(r,n.x,n.y,n.z,0),t.setColor3(i,this.groundColor.scale(this.intensity))},r.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._worldMatrix},r.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.type=3,e.direction=this.direction.asArray(),e.groundColor=this.groundColor.asArray(),e},r}(e.Light);e.HemisphericLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(e,r,i){t.call(this,e,i),this.direction=r,this.shadowOrthoScale=.5,this.autoUpdateExtends=!0,this._orthoLeft=Number.MAX_VALUE,this._orthoRight=Number.MIN_VALUE,this._orthoTop=Number.MIN_VALUE,this._orthoBottom=Number.MAX_VALUE,this.position=r.scale(-1)}return __extends(r,t),r.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},r.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(this.position)),this.direction},r.prototype.setShadowProjectionMatrix=function(t,r,i){var n=this.getScene().activeCamera;if(this.autoUpdateExtends||this._orthoLeft===Number.MAX_VALUE){var s=e.Vector3.Zero();this._orthoLeft=Number.MAX_VALUE,this._orthoRight=Number.MIN_VALUE,this._orthoTop=Number.MIN_VALUE,this._orthoBottom=Number.MAX_VALUE;for(var o=0;o<i.length;o++){var a=i[o];if(a){var h=a.getBoundingInfo();if(h)for(var c=h.boundingBox,l=0;l<c.vectorsWorld.length;l++)e.Vector3.TransformCoordinatesToRef(c.vectorsWorld[l],r,s),s.x<this._orthoLeft&&(this._orthoLeft=s.x),s.y<this._orthoBottom&&(this._orthoBottom=s.y),s.x>this._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;i<e.length;i++)s(e.data[i]);for(i=0;i<t.length;i++)s(t.data[i]);if(n._transparencyShadow)for(i=0;i<r.length;i++)s(r.data[i])},this._shadowMap.onClear=function(t){n.useBlurVarianceShadowMap||n.useVarianceShadowMap?t.clear(new e.Color4(0,0,0,0),!0,!0):t.clear(new e.Color4(1,1,1,1),!0,!0)}}return Object.defineProperty(t,"FILTER_NONE",{get:function(){return t._FILTER_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FILTER_VARIANCESHADOWMAP",{get:function(){return t._FILTER_VARIANCESHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FILTER_POISSONSAMPLING",{get:function(){return t._FILTER_POISSONSAMPLING},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FILTER_BLURVARIANCESHADOWMAP",{get:function(){return t._FILTER_BLURVARIANCESHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bias",{get:function(){return this._bias},set:function(e){this._bias=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"blurBoxOffset",{get:function(){return this._blurBoxOffset},set:function(t){var r=this;this._blurBoxOffset!==t&&(this._blurBoxOffset=t,this._boxBlurPostprocess&&this._boxBlurPostprocess.dispose(),this._boxBlurPostprocess=new e.PostProcess("DepthBoxBlur","depthBoxBlur",["screenSize","boxOffset"],[],1/this.blurScale,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define OFFSET "+t),this._boxBlurPostprocess.onApply=function(e){e.setFloat2("screenSize",r._mapSize/r.blurScale,r._mapSize/r.blurScale)})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"filter",{get:function(){return this._filter},set:function(t){this._filter!==t&&(this._filter=t,this.useVarianceShadowMap||this.useBlurVarianceShadowMap||this.usePoissonSampling?(this._shadowMap.anisotropicFilteringLevel=16,this._shadowMap.updateSamplingMode(e.Texture.BILINEAR_SAMPLINGMODE)):(this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(e.Texture.NEAREST_SAMPLINGMODE)))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useVarianceShadowMap",{get:function(){return this.filter===t.FILTER_VARIANCESHADOWMAP&&this._light.supportsVSM()},set:function(e){this.filter=e?t.FILTER_VARIANCESHADOWMAP:t.FILTER_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"usePoissonSampling",{get:function(){return this.filter===t.FILTER_POISSONSAMPLING||!this._light.supportsVSM()&&(this.filter===t.FILTER_VARIANCESHADOWMAP||this.filter===t.FILTER_BLURVARIANCESHADOWMAP)},set:function(e){this.filter=e?t.FILTER_POISSONSAMPLING:t.FILTER_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useBlurVarianceShadowMap",{get:function(){return this.filter===t.FILTER_BLURVARIANCESHADOWMAP&&this._light.supportsVSM()},set:function(e){this.filter=e?t.FILTER_BLURVARIANCESHADOWMAP:t.FILTER_NONE},enumerable:!0,configurable:!0}),t.prototype.isReady=function(t,r){var i=[];(this.useVarianceShadowMap||this.useBlurVarianceShadowMap)&&i.push("#define VSM"),this.getLight().needCube()&&i.push("#define CUBEMAP");var n=[e.VertexBuffer.PositionKind],s=t.getMesh(),o=t.getMaterial();o&&o.needAlphaTesting()&&(i.push("#define ALPHATEST"),s.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(n.push(e.VertexBuffer.UVKind),i.push("#define UV1")),s.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(n.push(e.VertexBuffer.UV2Kind),i.push("#define UV2"))),s.useBones&&s.computeBonesUsingShaders?(n.push(e.VertexBuffer.MatricesIndicesKind),n.push(e.VertexBuffer.MatricesWeightsKind),s.numBoneInfluencers>4&&(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;t<this.getShadowMap().renderList.length;t++){var r=this.getShadowMap().renderList[t];e.renderList.push(r.id)}return e},t.Parse=function(e,r){for(var i=r.getLightByID(e.lightId),n=new t(e.mapSize,i),s=0;s<e.renderList.length;s++){var o=r.getMeshByID(e.renderList[s]);n.getShadowMap().renderList.push(o)}return e.usePoissonSampling?n.usePoissonSampling=!0:e.useVarianceShadowMap?n.useVarianceShadowMap=!0:e.useBlurVarianceShadowMap&&(n.useBlurVarianceShadowMap=!0,e.blurScale&&(n.blurScale=e.blurScale),e.blurBoxOffset&&(n.blurBoxOffset=e.blurBoxOffset)),void 0!==e.bias&&(n.bias=e.bias),n.forceBackFacesOnly=e.forceBackFacesOnly,n},t._FILTER_NONE=0,t._FILTER_VARIANCESHADOWMAP=1,t._FILTER_POISSONSAMPLING=2,t._FILTER_BLURVARIANCESHADOWMAP=3,t}();e.ShadowGenerator=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e,t,r,i){return e.x>r.x+i?!1:r.x-i>t.x?!1:e.y>r.y+i?!1:r.y-i>t.y?!1:e.z>r.z+i?!1:r.z-i>t.z?!1:!0},r=function(e,t,r,i){var n=t*t-4*e*r,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||P<this.nearestDistance)&&(this.intersectionPoint?this.intersectionPoint.copyFrom(this._collisionPoint):this.intersectionPoint=this._collisionPoint.clone(),this.nearestDistance=P,this.collisionFound=!0)}}},i.prototype._collide=function(e,t,r,i,n,s,o){for(var a=i;n>a;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(){
  7. 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<this._scene.meshes.length;h++){var c=this._scene.meshes[h];c.isEnabled()&&c.checkCollisions&&c.subMeshes&&c!==o&&c._checkCollision(i)}return i.collisionFound?((0!==r.x||0!==r.y||0!==r.z)&&i._getResponse(t,r),r.length()<=a?void s.copyFrom(t):(i.retry++,void this._collideWithWorld(t,r,i,n,s,o))):void t.addToRef(r,s)},t}();e.CollisionCoordinatorLegacy=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this.compensateDistortion=!0}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return this.hResolution/(2*this.vResolution)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"aspectRatioFov",{get:function(){return 2*Math.atan(this.postProcessScaleFactor*this.vScreenSize/(2*this.eyeToScreenDistance))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"leftHMatrix",{get:function(){var t=this.hScreenSize/4-this.lensSeparationDistance/2,r=4*t/this.hScreenSize;return e.Matrix.Translation(r,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightHMatrix",{get:function(){var t=this.hScreenSize/4-this.lensSeparationDistance/2,r=4*t/this.hScreenSize;return e.Matrix.Translation(-r,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"leftPreViewMatrix",{get:function(){return e.Matrix.Translation(.5*this.interpupillaryDistance,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightPreViewMatrix",{get:function(){return e.Matrix.Translation(-.5*this.interpupillaryDistance,0,0)},enumerable:!0,configurable:!0}),t.GetDefault=function(){var e=new t;return e.hResolution=1280,e.vResolution=800,e.hScreenSize=.149759993,e.vScreenSize=.0935999975,e.vScreenCenter=.0467999987,e.eyeToScreenDistance=.0410000011,e.lensSeparationDistance=.063500002,e.interpupillaryDistance=.064000003,e.distortionK=[1,.219999999,.239999995,0],e.chromaAbCorrection=[.995999992,-.00400000019,1.01400006,0],e.postProcessScaleFactor=1.714605507808412,e.lensCenterOffset=.151976421,e},t}();e.VRCameraMetrics=t;var r=function(r){function i(t,n,s){r.call(this,t,s),this.position=n,this.upVector=e.Vector3.Up(),this.orthoLeft=null,this.orthoRight=null,this.orthoBottom=null,this.orthoTop=null,this.fov=.8,this.minZ=1,this.maxZ=1e4,this.inertia=.9,this.mode=i.PERSPECTIVE_CAMERA,this.isIntermediate=!1,this.viewport=new e.Viewport(0,0,1,1),this.layerMask=268435455,this.fovMode=i.FOVMODE_VERTICAL_FIXED,this.cameraRigMode=i.RIG_MODE_NONE,this._rigCameras=new Array,this._computedViewMatrix=e.Matrix.Identity(),this._projectionMatrix=new e.Matrix,this._postProcesses=new Array,this._postProcessesTakenIndices=[],this._activeMeshes=new e.SmartArray(256),this._globalPosition=e.Vector3.Zero(),s.addCamera(this),s.activeCamera||(s.activeCamera=this)}return __extends(i,r),Object.defineProperty(i,"PERSPECTIVE_CAMERA",{get:function(){return i._PERSPECTIVE_CAMERA},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ORTHOGRAPHIC_CAMERA",{get:function(){return i._ORTHOGRAPHIC_CAMERA},enumerable:!0,configurable:!0}),Object.defineProperty(i,"FOVMODE_VERTICAL_FIXED",{get:function(){return i._FOVMODE_VERTICAL_FIXED},enumerable:!0,configurable:!0}),Object.defineProperty(i,"FOVMODE_HORIZONTAL_FIXED",{get:function(){return i._FOVMODE_HORIZONTAL_FIXED},enumerable:!0,configurable:!0}),Object.defineProperty(i,"RIG_MODE_NONE",{get:function(){return i._RIG_MODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"RIG_MODE_STEREOSCOPIC_ANAGLYPH",{get:function(){return i._RIG_MODE_STEREOSCOPIC_ANAGLYPH},enumerable:!0,configurable:!0}),Object.defineProperty(i,"RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL",{get:function(){return i._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL},enumerable:!0,configurable:!0}),Object.defineProperty(i,"RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED",{get:function(){return i._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED},enumerable:!0,configurable:!0}),Object.defineProperty(i,"RIG_MODE_STEREOSCOPIC_OVERUNDER",{get:function(){return i._RIG_MODE_STEREOSCOPIC_OVERUNDER},enumerable:!0,configurable:!0}),Object.defineProperty(i,"RIG_MODE_VR",{get:function(){return i._RIG_MODE_VR},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"globalPosition",{get:function(){return this._globalPosition},enumerable:!0,configurable:!0}),i.prototype.getActiveMeshes=function(){return this._activeMeshes},i.prototype.isActiveMesh=function(e){return-1!==this._activeMeshes.indexOf(e)},i.prototype._initCache=function(){r.prototype._initCache.call(this),this._cache.position=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.upVector=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.mode=void 0,this._cache.minZ=void 0,this._cache.maxZ=void 0,this._cache.fov=void 0,this._cache.aspectRatio=void 0,this._cache.orthoLeft=void 0,this._cache.orthoRight=void 0,this._cache.orthoBottom=void 0,this._cache.orthoTop=void 0,this._cache.renderWidth=void 0,this._cache.renderHeight=void 0},i.prototype._updateCache=function(e){e||r.prototype._updateCache.call(this);var t=this.getEngine();this._cache.position.copyFrom(this.position),this._cache.upVector.copyFrom(this.upVector),this._cache.mode=this.mode,this._cache.minZ=this.minZ,this._cache.maxZ=this.maxZ,this._cache.fov=this.fov,this._cache.aspectRatio=t.getAspectRatio(this),this._cache.orthoLeft=this.orthoLeft,this._cache.orthoRight=this.orthoRight,this._cache.orthoBottom=this.orthoBottom,this._cache.orthoTop=this.orthoTop,this._cache.renderWidth=t.getRenderWidth(),this._cache.renderHeight=t.getRenderHeight()},i.prototype._updateFromScene=function(){this.updateCache(),this._update()},i.prototype._isSynchronized=function(){return this._isSynchronizedViewMatrix()&&this._isSynchronizedProjectionMatrix()},i.prototype._isSynchronizedViewMatrix=function(){return r.prototype._isSynchronized.call(this)?this._cache.position.equals(this.position)&&this._cache.upVector.equals(this.upVector)&&this.isSynchronizedWithParent():!1},i.prototype._isSynchronizedProjectionMatrix=function(){var e=this._cache.mode===this.mode&&this._cache.minZ===this.minZ&&this._cache.maxZ===this.maxZ;if(!e)return!1;var t=this.getEngine();return e=this.mode===i.PERSPECTIVE_CAMERA?this._cache.fov===this.fov&&this._cache.aspectRatio===t.getAspectRatio(this):this._cache.orthoLeft===this.orthoLeft&&this._cache.orthoRight===this.orthoRight&&this._cache.orthoBottom===this.orthoBottom&&this._cache.orthoTop===this.orthoTop&&this._cache.renderWidth===t.getRenderWidth()&&this._cache.renderHeight===t.getRenderHeight()},i.prototype.attachControl=function(e){},i.prototype.detachControl=function(e){},i.prototype._update=function(){this.cameraRigMode!==i.RIG_MODE_NONE&&this._updateRigCameras(),this._checkInputs()},i.prototype._checkInputs=function(){},i.prototype.attachPostProcess=function(t,r){if(void 0===r&&(r=null),!t.isReusable()&&this._postProcesses.indexOf(t)>-1)return e.Tools.Error("You're trying to reuse a post process not defined as reusable."),0;if(null==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<this._postProcessesTakenIndices.length;++i)if(!(this._postProcessesTakenIndices[i]<r)){n=this._postProcessesTakenIndices.length-1;for(var o=n;o>=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;r<t.length;r++){var s=this._postProcesses[t[r]];s===e?(delete this._postProcesses[t[r]],i=this._postProcessesTakenIndices.indexOf(t[r]),this._postProcessesTakenIndices.splice(i,1)):n.push(r)}else{var o=this._postProcesses.length;for(r=0;o>r;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;e<this._postProcessesTakenIndices.length;++e)this._postProcesses[this._postProcessesTakenIndices[e]].dispose(this)},i.prototype.setCameraRigMode=function(r,n){for(;this._rigCameras.length>0;)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<this._rigCameras.length;e++)this._rigCameras[e].minZ=this.minZ,this._rigCameras[e].maxZ=this.maxZ,this._rigCameras[e].fov=this.fov;this.cameraRigMode===i.RIG_MODE_STEREOSCOPIC_ANAGLYPH&&(this._rigCameras[0].viewport=this._rigCameras[1].viewport=this.viewport)},i.prototype.serialize=function(){var t={};return t.name=this.name,t.tags=e.Tags.GetTags(this),t.id=this.id,t.position=this.position.asArray(),t.type=e.Tools.GetConstructorName(this),this.parent&&(t.parentId=this.parent.id),t.fov=this.fov,t.minZ=this.minZ,t.maxZ=this.maxZ,t.inertia=this.inertia,e.Animation.AppendSerializedAnimations(this,t),t.ranges=this.serializeAnimationRanges(),t.layerMask=this.layerMask,t},i.Parse=function(t,r){var i,n,s=e.Vector3.FromArray(t.position),o=t.lockedTargetId?r.getLastMeshByID(t.lockedTargetId):null;if("AnaglyphArcRotateCamera"===t.type||"ArcRotateCamera"===t.type){var a=t.alpha,h=t.beta,c=t.radius;"AnaglyphArcRotateCamera"===t.type?(n=t.interaxial_distance,i=new e.AnaglyphArcRotateCamera(t.name,a,h,c,o,n,r)):i=new e.ArcRotateCamera(t.name,a,h,c,o,r)}else"AnaglyphFreeCamera"===t.type?(n=t.interaxial_distance,i=new e.AnaglyphFreeCamera(t.name,s,n,r)):"DeviceOrientationCamera"===t.type?i=new e.DeviceOrientationCamera(t.name,s,r):"FollowCamera"===t.type?(i=new e.FollowCamera(t.name,s,r),i.heightOffset=t.heightOffset,i.radius=t.radius,i.rotationOffset=t.rotationOffset,o&&(i.target=o)):i="GamepadCamera"===t.type?new e.GamepadCamera(t.name,s,r):"TouchCamera"===t.type?new e.TouchCamera(t.name,s,r):"VirtualJoysticksCamera"===t.type?new e.VirtualJoysticksCamera(t.name,s,r):"WebVRFreeCamera"===t.type?new e.WebVRFreeCamera(t.name,s,r):"VRDeviceOrientationFreeCamera"===t.type?new e.VRDeviceOrientationFreeCamera(t.name,s,r):"FreeCamera"===t.type?new e.UniversalCamera(t.name,s,r):new e.UniversalCamera(t.name,s,r);if(t.cameraRigMode){var l=t.interaxial_distance?{interaxialDistance:t.interaxial_distance}:{};i.setCameraRigMode(t.cameraRigMode,l)}if(o&&i instanceof e.FreeCamera&&(i.lockedTarget=o),i.id=t.id,e.Tags.AddTagsTo(i,t.tags),t.parentId&&(i._waitingParentId=t.parentId),t.target?i.setTarget?i.setTarget(e.Vector3.FromArray(t.target)):i.target=e.Vector3.FromArray(t.target):i.rotation=e.Vector3.FromArray(t.rotation),i.fov=t.fov,i.minZ=t.minZ,i.maxZ=t.maxZ,i.speed=t.speed,i.inertia=t.inertia,i.checkCollisions=t.checkCollisions,i.applyGravity=t.applyGravity,t.ellipsoid&&(i.ellipsoid=e.Vector3.FromArray(t.ellipsoid)),t.animations){for(var u=0;u<t.animations.length;u++){var f=t.animations[u];i.animations.push(e.Animation.Parse(f))}e.Node.ParseAnimationRanges(i,t,r)}return t.autoAnimate&&r.beginAnimation(i,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,1),t.layerMask&&!isNaN(t.layerMask)?i.layerMask=Math.abs(parseInt(t.layerMask)):i.layerMask=268435455,i},i._PERSPECTIVE_CAMERA=0,i._ORTHOGRAPHIC_CAMERA=1,i._FOVMODE_VERTICAL_FIXED=0,i._FOVMODE_HORIZONTAL_FIXED=1,i._RIG_MODE_NONE=0,i._RIG_MODE_STEREOSCOPIC_ANAGLYPH=10,i._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL=11,i._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED=12,i._RIG_MODE_STEREOSCOPIC_OVERUNDER=13,i._RIG_MODE_VR=20,i}(e.Node);e.Camera=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i,n){t.call(this,r,i,n),this.cameraDirection=new e.Vector3(0,0,0),this.cameraRotation=new e.Vector2(0,0),this.rotation=new e.Vector3(0,0,0),this.speed=2,this.noRotationConstraint=!1,this.lockedTarget=null,this._currentTarget=e.Vector3.Zero(),this._viewMatrix=e.Matrix.Zero(),this._camMatrix=e.Matrix.Zero(),this._cameraTransformMatrix=e.Matrix.Zero(),this._cameraRotationMatrix=e.Matrix.Zero(),this._referencePoint=new e.Vector3(0,0,1),this._transformedReferencePoint=e.Vector3.Zero(),this._lookAtTemp=e.Matrix.Zero(),this._tempMatrix=e.Matrix.Zero()}return __extends(r,t),r.prototype.getFrontPosition=function(e){var t=this.getTarget().subtract(this.position);return t.normalize(),t.scaleInPlace(e),this.globalPosition.add(t)},r.prototype._getLockedTargetPosition=function(){return this.lockedTarget?this.lockedTarget.position||this.lockedTarget:null},r.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.lockedTarget=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.rotation=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},r.prototype._updateCache=function(e){e||t.prototype._updateCache.call(this);var r=this._getLockedTargetPosition();r?this._cache.lockedTarget?this._cache.lockedTarget.copyFrom(r):this._cache.lockedTarget=r.clone():this._cache.lockedTarget=null,this._cache.rotation.copyFrom(this.rotation)},r.prototype._isSynchronizedViewMatrix=function(){if(!t.prototype._isSynchronizedViewMatrix.call(this))return!1;var e=this._getLockedTargetPosition();return(this._cache.lockedTarget?this._cache.lockedTarget.equals(e):!e)&&this._cache.rotation.equals(this.rotation)},r.prototype._computeLocalCameraSpeed=function(){var e=this.getEngine();return this.speed*(e.getDeltaTime()/(10*e.getFps()))},r.prototype.setTarget=function(t){this.upVector.normalize(),e.Matrix.LookAtLHToRef(this.position,t,this.upVector,this._camMatrix),this._camMatrix.invert(),this.rotation.x=Math.atan(this._camMatrix.m[6]/this._camMatrix.m[10]);var r=t.subtract(this.position);r.x>=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.Epsilon&&(this.cameraDirection.x=0),Math.abs(this.cameraDirection.y)<e.Engine.Epsilon&&(this.cameraDirection.y=0),Math.abs(this.cameraDirection.z)<e.Engine.Epsilon&&(this.cameraDirection.z=0),this.cameraDirection.scaleInPlace(this.inertia)),i&&(Math.abs(this.cameraRotation.x)<e.Engine.Epsilon&&(this.cameraRotation.x=0),Math.abs(this.cameraRotation.y)<e.Engine.Epsilon&&(this.cameraRotation.y=0),this.cameraRotation.scaleInPlace(this.inertia)),t.prototype._checkInputs.call(this)},r.prototype._getViewMatrix=function(){return this.lockedTarget?this._currentTarget.copyFrom(this._getLockedTargetPosition()):(0!==this.upVector.x||1!==this.upVector.y||0!==this.upVector.z?(e.Matrix.LookAtLHToRef(e.Vector3.Zero(),this._referencePoint,this.upVector,this._lookAtTemp),e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),this._lookAtTemp.multiplyToRef(this._cameraRotationMatrix,this._tempMatrix),this._lookAtTemp.invert(),this._tempMatrix.multiplyToRef(this._lookAtTemp,this._cameraRotationMatrix)):e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),e.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),this.position.addToRef(this._transformedReferencePoint,this._currentTarget)),e.Matrix.LookAtLHToRef(this.position,this._currentTarget,this.upVector,this._viewMatrix),this._viewMatrix},r.prototype._getVRViewMatrix=function(){return e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),e.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),e.Vector3.TransformNormalToRef(this.upVector,this._cameraRotationMatrix,this._cameraRigParams.vrActualUp),this.position.addToRef(this._transformedReferencePoint,this._currentTarget),e.Matrix.LookAtLHToRef(this.position,this._currentTarget,this._cameraRigParams.vrActualUp,this._cameraRigParams.vrWorkMatrix),this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix,this._viewMatrix),this._viewMatrix},r.prototype.createRigCamera=function(t,i){if(this.cameraRigMode!==e.Camera.RIG_MODE_NONE){var n=new r(t,this.position.clone(),this.getScene());return this.cameraRigMode===e.Camera.RIG_MODE_VR&&(n._cameraRigParams={},n._cameraRigParams.vrActualUp=new e.Vector3(0,0,0),n._getViewMatrix=n._getVRViewMatrix),n}return null},r.prototype._updateRigCameras=function(){switch(this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:var r=this._rigCameras[0],i=this._rigCameras[1];this.cameraRigMode===e.Camera.RIG_MODE_VR?(r.rotation.x=i.rotation.x=this.rotation.x,r.rotation.y=i.rotation.y=this.rotation.y,r.rotation.z=i.rotation.z=this.rotation.z,r.position.copyFrom(this.position),i.position.copyFrom(this.position)):(this._getRigCamPosition(-this._cameraRigParams.stereoHalfAngle,r.position),this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle,i.position),r.setTarget(this.getTarget()),i.setTarget(this.getTarget()))}t.prototype._updateRigCameras.call(this)},r.prototype._getRigCamPosition=function(t,r){this._rigCamTransformMatrix||(this._rigCamTransformMatrix=new e.Matrix);var i=this.getTarget();e.Matrix.Translation(-i.x,-i.y,-i.z).multiplyToRef(e.Matrix.RotationY(t),this._rigCamTransformMatrix),this._rigCamTransformMatrix=this._rigCamTransformMatrix.multiply(e.Matrix.Translation(i.x,i.y,i.z)),e.Vector3.TransformCoordinatesToRef(this.position,this._rigCamTransformMatrix,r)},r.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.speed=this.speed,this.rotation&&(e.rotation=this.rotation.asArray()),this.lockedTarget&&this.lockedTarget.id&&(e.lockedTargetId=this.lockedTarget.id),e},r}(e.Camera);e.TargetCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i,n){var s=this;t.call(this,r,i,n),this.ellipsoid=new e.Vector3(.5,1,.5),this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39],this.checkCollisions=!1,this.applyGravity=!1,this.angularSensibility=2e3,this._keys=[],this._collider=new e.Collider,this._needMoveForGravity=!1,this._oldPosition=e.Vector3.Zero(),this._diffPosition=e.Vector3.Zero(),this._newPosition=e.Vector3.Zero(),this._onCollisionPositionChange=function(t,r,i){void 0===i&&(i=null),s.getScene().workerCollisions&&r.multiplyInPlace(s._collider.radius);var n=function(t){s._newPosition.copyFrom(t),s._newPosition.subtractToRef(s._oldPosition,s._diffPosition);s.position.clone();s._diffPosition.length()>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),
  8. 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;r<this._keys.length;r++){var i=this._keys[r],n=this._computeLocalCameraSpeed();-1!==this.keysLeft.indexOf(i)?this._localDirection.copyFromFloats(-n,0,0):-1!==this.keysUp.indexOf(i)?this._localDirection.copyFromFloats(0,0,n):-1!==this.keysRight.indexOf(i)?this._localDirection.copyFromFloats(n,0,0):-1!==this.keysDown.indexOf(i)&&this._localDirection.copyFromFloats(0,0,-n),this.getViewMatrix().invertToRef(this._cameraTransformMatrix),e.Vector3.TransformNormalToRef(this._localDirection,this._cameraTransformMatrix,this._transformedDirection),this.cameraDirection.addInPlace(this._transformedDirection)}t.prototype._checkInputs.call(this)},r.prototype._decideIfNeedsToMove=function(){return this._needMoveForGravity||Math.abs(this.cameraDirection.x)>0||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;t<this._keys.length;t++){var i=this._keys[t];-1!==this.keysLeft.indexOf(i)?this.inertialAlphaOffset-=.01:-1!==this.keysUp.indexOf(i)?this.inertialBetaOffset-=.01:-1!==this.keysRight.indexOf(i)?this.inertialAlphaOffset+=.01:-1!==this.keysDown.indexOf(i)&&(this.inertialBetaOffset+=.01)}(0!==this.inertialAlphaOffset||0!==this.inertialBetaOffset||0!==this.inertialRadiusOffset)&&(this.alpha+=this.beta<=0?-this.inertialAlphaOffset:this.inertialAlphaOffset,this.beta+=this.inertialBetaOffset,this.radius-=this.inertialRadiusOffset,this.inertialAlphaOffset*=this.inertia,this.inertialBetaOffset*=this.inertia,this.inertialRadiusOffset*=this.inertia,Math.abs(this.inertialAlphaOffset)<e.Engine.Epsilon&&(this.inertialAlphaOffset=0),Math.abs(this.inertialBetaOffset)<e.Engine.Epsilon&&(this.inertialBetaOffset=0),Math.abs(this.inertialRadiusOffset)<e.Engine.Epsilon&&(this.inertialRadiusOffset=0)),(0!==this.inertialPanningX||0!==this.inertialPanningY)&&(this._localDirection||(this._localDirection=e.Vector3.Zero(),this._transformedDirection=e.Vector3.Zero()),this.inertialPanningX*=this.inertia,this.inertialPanningY*=this.inertia,Math.abs(this.inertialPanningX)<e.Engine.Epsilon&&(this.inertialPanningX=0),Math.abs(this.inertialPanningY)<e.Engine.Epsilon&&(this.inertialPanningY=0),this._localDirection.copyFromFloats(this.inertialPanningX,this.inertialPanningY,this.inertialPanningY),this._viewMatrix.invertToRef(this._cameraTransformMatrix),e.Vector3.TransformNormalToRef(this._localDirection,this._cameraTransformMatrix,this._transformedDirection),this._transformedDirection.multiplyInPlace(this.panningAxis),this.target.addInPlace(this._transformedDirection)),this._checkLimits(),r.prototype._checkInputs.call(this)}},i.prototype._checkLimits=function(){null===this.lowerBetaLimit||void 0===this.lowerBetaLimit?this.allowUpsideDown&&this.beta>Math.PI&&(this.beta=this.beta-2*Math.PI):this.beta<this.lowerBetaLimit&&(this.beta=this.lowerBetaLimit),null===this.upperBetaLimit||void 0===this.upperBetaLimit?this.allowUpsideDown&&this.beta<-Math.PI&&(this.beta=this.beta+2*Math.PI):this.beta>this.upperBetaLimit&&(this.beta=this.upperBetaLimit),this.lowerAlphaLimit&&this.alpha<this.lowerAlphaLimit&&(this.alpha=this.lowerAlphaLimit),this.upperAlphaLimit&&this.alpha>this.upperAlphaLimit&&(this.alpha=this.upperAlphaLimit),this.lowerRadiusLimit&&this.radius<this.lowerRadiusLimit&&(this.radius=this.lowerRadiusLimit),this.upperRadiusLimit&&this.radius>this.upperRadiusLimit&&(this.radius=this.upperRadiusLimit)},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;s<this._scene._activeParticleSystems.length;s++){var o=this._scene._activeParticleSystems.data[s];o.renderingGroupId===t&&0!==(i.layerMask&o.layerMask)&&(this._clearDepthBuffer(),o.emitter.position&&r&&-1===r.indexOf(o.emitter)||(this._scene._activeParticles+=o.render()))}this._scene._particlesDuration+=e.Tools.Now-n}},t.prototype._renderSprites=function(t){if(this._scene.spritesEnabled&&0!==this._scene.spriteManagers.length){for(var r=this._scene.activeCamera,i=e.Tools.Now,n=0;n<this._scene.spriteManagers.length;n++){var s=this._scene.spriteManagers[n];s.renderingGroupId===t&&0!==(r.layerMask&s.layerMask)&&(this._clearDepthBuffer(),s.render())}this._scene._spritesDuration+=e.Tools.Now-i}},t.prototype._clearDepthBuffer=function(){this._depthBufferAlreadyCleaned||(this._scene.getEngine().clear(0,!1,!0),this._depthBufferAlreadyCleaned=!0)},t.prototype._renderSpritesAndParticles=function(){this._currentRenderSprites&&this._renderSprites(this._currentIndex),this._currentRenderParticles&&this._renderParticles(this._currentIndex,this._currentActiveMeshes)},t.prototype.render=function(e,r,i,n){this._currentActiveMeshes=r,this._currentRenderParticles=i,this._currentRenderSprites=n;for(var s=0;s<t.MAX_RENDERINGGROUPS;s++){this._depthBufferAlreadyCleaned=0==s;var o=this._renderingGroups[s],a=!1;this._currentIndex=s,o?(this._clearDepthBuffer(),o.onBeforeTransparentRendering||(o.onBeforeTransparentRendering=this._renderSpritesAndParticles.bind(this)),o.render(e)||(this._renderingGroups.splice(s,1),a=!0,this._renderSpritesAndParticles())):this._renderSpritesAndParticles(),a&&s--}},t.prototype.reset=function(){this._renderingGroups.forEach(function(e,t,r){e&&e.prepare()})},t.prototype.dispatch=function(t){var r=t.getMesh(),i=r.renderingGroupId||0;this._renderingGroups[i]||(this._renderingGroups[i]=new e.RenderingGroup(i,this._scene)),this._renderingGroups[i].dispatch(t)},t.MAX_RENDERINGGROUPS=4,t}();e.RenderingManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r){this.index=t,this._opaqueSubMeshes=new e.SmartArray(256),this._transparentSubMeshes=new e.SmartArray(256),this._alphaTestSubMeshes=new e.SmartArray(256),this._scene=r}return t.prototype.render=function(t){if(t)return t(this._opaqueSubMeshes,this._alphaTestSubMeshes,this._transparentSubMeshes),!0;if(0===this._opaqueSubMeshes.length&&0===this._alphaTestSubMeshes.length&&0===this._transparentSubMeshes.length)return this.onBeforeTransparentRendering&&this.onBeforeTransparentRendering(),!1;var r,i,n=this._scene.getEngine();for(r=0;r<this._opaqueSubMeshes.length;r++)i=this._opaqueSubMeshes.data[r],i.render(!1);for(n.setAlphaTesting(!0),r=0;r<this._alphaTestSubMeshes.length;r++)i=this._alphaTestSubMeshes.data[r],i.render(!1);if(n.setAlphaTesting(!1),this.onBeforeTransparentRendering&&this.onBeforeTransparentRendering(),this._transparentSubMeshes.length){for(r=0;r<this._transparentSubMeshes.length;r++)i=this._transparentSubMeshes.data[r],i._alphaIndex=i.getMesh().alphaIndex,i._distanceToCamera=i.getBoundingInfo().boundingSphere.centerWorld.subtract(this._scene.activeCamera.globalPosition).length();var s=this._transparentSubMeshes.data.slice(0,this._transparentSubMeshes.length);for(s.sort(function(e,t){return e._alphaIndex>t._alphaIndex?1:e._alphaIndex<t._alphaIndex?-1:e._distanceToCamera<t._distanceToCamera?1:e._distanceToCamera>t._distanceToCamera?-1:0}),r=0;r<s.length;r++)i=s[r],i.render(!0);n.setAlphaMode(e.Engine.ALPHA_DISABLE)}return!0},t.prototype.prepare=function(){this._opaqueSubMeshes.reset(),this._transparentSubMeshes.reset(),this._alphaTestSubMeshes.reset()},t.prototype.dispatch=function(e){var t=e.getMaterial(),r=e.getMesh();t.needAlphaBlending()||r.visibility<1||r.hasVertexAlpha?this._transparentSubMeshes.push(e):t.needAlphaTesting()?this._alphaTestSubMeshes.push(e):this._opaqueSubMeshes.push(e)},t}();e.RenderingGroup=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(r){this.autoClear=!0,this.clearColor=new e.Color3(.2,.2,.3),this.ambientColor=new e.Color3(0,0,0),this.forceWireframe=!1,this.forcePointsCloud=!1,this.forceShowBoundingBoxes=!1,this.animationsEnabled=!0,this.constantlyUpdateMeshUnderPointer=!1,this.cameraToUseForPointers=null,this._startingPointerPosition=new e.Vector2(0,0),this._startingPointerTime=0,this.fogEnabled=!0,this.fogMode=t.FOGMODE_NONE,this.fogColor=new e.Color3(.2,.2,.3),this.fogDensity=.1,this.fogStart=0,this.fogEnd=1e3,this.shadowsEnabled=!0,this.lightsEnabled=!0,this.lights=new Array,this.cameras=new Array,this.activeCameras=new Array,this.meshes=new Array,this._geometries=new Array,this.materials=new Array,this.multiMaterials=new Array,this.defaultMaterial=new e.StandardMaterial("default material",this),this.texturesEnabled=!0,this.textures=new Array,this.particlesEnabled=!0,this.particleSystems=new Array,this.spritesEnabled=!0,this.spriteManagers=new Array,this.layers=new Array,this.skeletonsEnabled=!0,this.skeletons=new Array,this.lensFlaresEnabled=!0,this.lensFlareSystems=new Array,this.collisionsEnabled=!0,this.gravity=new e.Vector3(0,-9.807,0),this.postProcessesEnabled=!0,this.renderTargetsEnabled=!0,this.dumpNextRenderTargets=!1,this.customRenderTargets=new Array,this.importedMeshesFiles=new Array,this.probesEnabled=!0,this.reflectionProbes=new Array,this._actionManagers=new Array,this._meshesForIntersections=new e.SmartArray(256),this.proceduralTexturesEnabled=!0,this._proceduralTextures=new Array,this.soundTracks=new Array,this._audioEnabled=!0,this._headphone=!1,this._totalVertices=0,this._activeIndices=0,this._activeParticles=0,this._lastFrameDuration=0,this._evaluateActiveMeshesDuration=0,this._renderTargetsDuration=0,this._particlesDuration=0,this._renderDuration=0,this._spritesDuration=0,this._animationRatio=0,this._renderId=0,this._executeWhenReadyTimeoutId=-1,this._toBeDisposed=new e.SmartArray(256),this._onReadyCallbacks=new Array,this._pendingData=[],this._onBeforeRenderCallbacks=new Array,this._onAfterRenderCallbacks=new Array,this._activeMeshes=new e.SmartArray(256),this._processedMaterials=new e.SmartArray(256),this._renderTargets=new e.SmartArray(256),this._activeParticleSystems=new e.SmartArray(256),this._activeSkeletons=new e.SmartArray(32),this._softwareSkinnedMeshes=new e.SmartArray(32),this._activeBones=0,this._activeAnimatables=new Array,this._transformMatrix=e.Matrix.Zero(),this._edgesRenderers=new e.SmartArray(16),this._uniqueIdCounter=0,this._pickedMeshName=null,this._engine=r,r.scenes.push(this),this._renderingManager=new e.RenderingManager(this),this.postProcessManager=new e.PostProcessManager(this),this.postProcessRenderPipelineManager=new e.PostProcessRenderPipelineManager,this._boundingBoxRenderer=new e.BoundingBoxRenderer(this),e.OutlineRenderer&&(this._outlineRenderer=new e.OutlineRenderer(this)),this.attachControl(),this._debugLayer=new e.DebugLayer(this),e.SoundTrack&&(this.mainSoundTrack=new e.SoundTrack(this,{mainTrack:!0})),e.SimplificationQueue&&(this.simplificationQueue=new e.SimplificationQueue),this.workerCollisions=!1}return Object.defineProperty(t,"FOGMODE_NONE",{get:function(){return t._FOGMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FOGMODE_EXP",{get:function(){return t._FOGMODE_EXP},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FOGMODE_EXP2",{get:function(){return t._FOGMODE_EXP2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FOGMODE_LINEAR",{get:function(){return t._FOGMODE_LINEAR},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"debugLayer",{get:function(){return this._debugLayer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"workerCollisions",{get:function(){return this._workerCollisions},set:function(t){t=t&&!!Worker,this._workerCollisions=t,this.collisionCoordinator&&this.collisionCoordinator.destroy(),this.collisionCoordinator=t?new e.CollisionCoordinatorWorker:new e.CollisionCoordinatorLegacy,this.collisionCoordinator.init(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"SelectionOctree",{get:function(){return this._selectionOctree},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"meshUnderPointer",{get:function(){return this._meshUnderPointer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pointerX",{get:function(){return this._pointerX},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pointerY",{get:function(){return this._pointerY},enumerable:!0,configurable:!0}),t.prototype.getCachedMaterial=function(){return this._cachedMaterial},t.prototype.getBoundingBoxRenderer=function(){return this._boundingBoxRenderer},t.prototype.getOutlineRenderer=function(){return this._outlineRenderer},t.prototype.getEngine=function(){return this._engine},t.prototype.getTotalVertices=function(){return this._totalVertices},t.prototype.getActiveIndices=function(){return this._activeIndices},t.prototype.getActiveParticles=function(){return this._activeParticles},t.prototype.getActiveBones=function(){return this._activeBones},t.prototype.getLastFrameDuration=function(){return this._lastFrameDuration},t.prototype.getEvaluateActiveMeshesDuration=function(){return this._evaluateActiveMeshesDuration},t.prototype.getActiveMeshes=function(){return this._activeMeshes},t.prototype.getRenderTargetsDuration=function(){return this._renderTargetsDuration},t.prototype.getRenderDuration=function(){return this._renderDuration},t.prototype.getParticlesDuration=function(){return this._particlesDuration},t.prototype.getSpritesDuration=function(){return this._spritesDuration},t.prototype.getAnimationRatio=function(){return this._animationRatio},t.prototype.getRenderId=function(){return this._renderId},t.prototype.incrementRenderId=function(){this._renderId++},t.prototype._updatePointerPosition=function(e){var t=this._engine.getRenderingCanvasClientRect();this._pointerX=e.clientX-t.left,this._pointerY=e.clientY-t.top,this.cameraToUseForPointers&&(this._pointerX=this._pointerX-this.cameraToUseForPointers.viewport.x*this._engine.getRenderWidth(),this._pointerY=this._pointerY-this.cameraToUseForPointers.viewport.y*this._engine.getRenderHeight())},t.prototype.attachControl=function(){var t=this,r=function(e){return e.isPickable&&e.actionManager&&e.actionManager.hasPickTriggers};this._onPointerMove=function(e){if(t.cameraToUseForPointers||t.activeCamera){var i=t._engine.getRenderingCanvas();t._updatePointerPosition(e);var n=t.pick(t._pointerX,t._pointerY,function(e){return e.isPickable&&e.isVisible&&e.isReady()&&(t.constantlyUpdateMeshUnderPointer||null!==e.actionManager&&void 0!==e.actionManager)},!1,t.cameraToUseForPointers);n.hit&&n.pickedMesh?(t._meshUnderPointer=n.pickedMesh,t.setPointerOverMesh(n.pickedMesh),t._meshUnderPointer.actionManager&&t._meshUnderPointer.actionManager.hasPointerTriggers?i.style.cursor="pointer":i.style.cursor=""):(n=t.pickSprite(t._pointerX,t._pointerY,r,!1,t.cameraToUseForPointers),n.hit&&n.pickedSprite?i.style.cursor="pointer":(t.setPointerOverMesh(null),
  9. i.style.cursor="",t._meshUnderPointer=null)),t.onPointerMove&&t.onPointerMove(e,n)}},this._onPointerDown=function(i){if(t.cameraToUseForPointers||t.activeCamera){t._updatePointerPosition(i),t._pickedMeshName=null,t._startingPointerPosition.x=t._pointerX,t._startingPointerPosition.y=t._pointerY,t._startingPointerTime=(new Date).getTime();var n=null;t.onPointerDown||t.onPointerPick||(n=function(e){return e.isPickable&&e.isVisible&&e.isReady()&&e.actionManager&&e.actionManager.hasPointerTriggers});var s=t.pick(t._pointerX,t._pointerY,n,!1,t.cameraToUseForPointers);if(s.hit&&s.pickedMesh&&(t._pickedMeshName=s.pickedMesh.name,s.pickedMesh.actionManager)){if(s.pickedMesh.actionManager.hasPickTriggers){switch(i.button){case 0:s.pickedMesh.actionManager.processTrigger(e.ActionManager.OnLeftPickTrigger,e.ActionEvent.CreateNew(s.pickedMesh,i));break;case 1:s.pickedMesh.actionManager.processTrigger(e.ActionManager.OnCenterPickTrigger,e.ActionEvent.CreateNew(s.pickedMesh,i));break;case 2:s.pickedMesh.actionManager.processTrigger(e.ActionManager.OnRightPickTrigger,e.ActionEvent.CreateNew(s.pickedMesh,i))}s.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickDownTrigger,e.ActionEvent.CreateNew(s.pickedMesh,i))}if(s.pickedMesh.actionManager.hasSpecificTrigger(e.ActionManager.OnLongPressTrigger)){var o=t;window.setTimeout(function(){var t=o.pick(o._pointerX,o._pointerY,function(t){return t.isPickable&&t.isVisible&&t.isReady()&&t.actionManager&&t.actionManager.hasSpecificTrigger(e.ActionManager.OnLongPressTrigger)},!1,o.cameraToUseForPointers);t.hit&&t.pickedMesh&&t.pickedMesh.actionManager&&0!==o._startingPointerTime&&(new Date).getTime()-o._startingPointerTime>e.ActionManager.LongPressDelay&&Math.abs(o._startingPointerPosition.x-o._pointerX)<e.ActionManager.DragMovementThreshold&&Math.abs(o._startingPointerPosition.y-o._pointerY)<e.ActionManager.DragMovementThreshold&&(o._startingPointerTime=0,t.pickedMesh.actionManager.processTrigger(e.ActionManager.OnLongPressTrigger,e.ActionEvent.CreateNew(t.pickedMesh,i)))},e.ActionManager.LongPressDelay)}}if(t.onPointerDown&&t.onPointerDown(i,s),t.spriteManagers.length>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)<e.ActionManager.DragMovementThreshold&&Math.abs(t._startingPointerPosition.y-t._pointerY)<e.ActionManager.DragMovementThreshold&&s.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickTrigger,e.ActionEvent.CreateNew(s.pickedMesh,i)))),t.onPointerUp&&t.onPointerUp(i,s),t._startingPointerTime=0,t.spriteManagers.length>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<this._geometries.length;t++){var r=this._geometries[t];if(r.delayLoadState===e.Engine.DELAYLOADSTATE_LOADING)return!1}for(t=0;t<this.meshes.length;t++){var i=this.meshes[t];if(!i.isReady())return!1;var n=i.material;if(n&&!n.isReady(i))return!1}return!0},t.prototype.resetCachedMaterial=function(){this._cachedMaterial=null},t.prototype.registerBeforeRender=function(e){this._onBeforeRenderCallbacks.push(e)},t.prototype.unregisterBeforeRender=function(e){var t=this._onBeforeRenderCallbacks.indexOf(e);t>-1&&this._onBeforeRenderCallbacks.splice(t,1)},t.prototype.registerAfterRender=function(e){this._onAfterRenderCallbacks.push(e)},t.prototype.unregisterAfterRender=function(e){var t=this._onAfterRenderCallbacks.indexOf(e);t>-1&&this._onAfterRenderCallbacks.splice(t,1)},t.prototype._addPendingData=function(e){this._pendingData.push(e)},t.prototype._removePendingData=function(e){var t=this._pendingData.indexOf(e);-1!==t&&this._pendingData.splice(t,1)},t.prototype.getWaitingItemsCount=function(){return this._pendingData.length},t.prototype.executeWhenReady=function(e){var t=this;this._onReadyCallbacks.push(e),-1===this._executeWhenReadyTimeoutId&&(this._executeWhenReadyTimeoutId=setTimeout(function(){t._checkIsReady()},150))},t.prototype._checkIsReady=function(){var e=this;return this.isReady()?(this._onReadyCallbacks.forEach(function(e){e()}),this._onReadyCallbacks=[],void(this._executeWhenReadyTimeoutId=-1)):void(this._executeWhenReadyTimeoutId=setTimeout(function(){e._checkIsReady()},150))},t.prototype.beginAnimation=function(t,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;c<h.length;c++)this.beginAnimation(h[c],r,i,n,s,o,a);return a},t.prototype.beginDirectAnimation=function(t,r,i,n,s,o,a){void 0===o&&(o=1);var h=new e.Animatable(this,t,i,n,s,o,a,r);return h},t.prototype.getAnimatableByTarget=function(e){for(var t=0;t<this._activeAnimatables.length;t++)if(this._activeAnimatables[t].target===e)return this._activeAnimatables[t];return null},Object.defineProperty(t.prototype,"Animatables",{get:function(){return this._activeAnimatables},enumerable:!0,configurable:!0}),t.prototype.stopAnimation=function(e){var t=this.getAnimatableByTarget(e);t&&t.stop()},t.prototype._animate=function(){if(this.animationsEnabled&&0!==this._activeAnimatables.length){if(!this._animationStartDate){if(this._pendingData.length>0)return;this._animationStartDate=e.Tools.Now}for(var t=e.Tools.Now,r=t-this._animationStartDate,i=0;i<this._activeAnimatables.length;i++)this._activeAnimatables[i]._animate(r)}},t.prototype.getViewMatrix=function(){return this._viewMatrix},t.prototype.getProjectionMatrix=function(){return this._projectionMatrix},t.prototype.getTransformMatrix=function(){return this._transformMatrix},t.prototype.setTransformMatrix=function(e,t){this._viewMatrix=e,this._projectionMatrix=t,this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)},t.prototype.addMesh=function(e){e.uniqueId=this._uniqueIdCounter++;var t=this.meshes.push(e);this.collisionCoordinator.onMeshAdded(e),this.onNewMeshAdded&&this.onNewMeshAdded(e,t,this)},t.prototype.removeMesh=function(e){var t=this.meshes.indexOf(e);return-1!==t&&this.meshes.splice(t,1),this.collisionCoordinator.onMeshRemoved(e),this.onMeshRemoved&&this.onMeshRemoved(e),t},t.prototype.removeSkeleton=function(e){var t=this.skeletons.indexOf(e);return-1!==t&&this.skeletons.splice(t,1),t},t.prototype.removeLight=function(e){var t=this.lights.indexOf(e);return-1!==t&&this.lights.splice(t,1),this.onLightRemoved&&this.onLightRemoved(e),t},t.prototype.removeCamera=function(e){var t=this.cameras.indexOf(e);-1!==t&&this.cameras.splice(t,1);var r=this.activeCameras.indexOf(e);return-1!==r&&this.activeCameras.splice(r,1),this.activeCamera===e&&(this.cameras.length>0?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<this.materials.length;t++)if(this.materials[t].id===e)return this.materials[t];return null},t.prototype.getMaterialByName=function(e){for(var t=0;t<this.materials.length;t++)if(this.materials[t].name===e)return this.materials[t];return null},t.prototype.getLensFlareSystemByName=function(e){for(var t=0;t<this.lensFlareSystems.length;t++)if(this.lensFlareSystems[t].name===e)return this.lensFlareSystems[t];return null},t.prototype.getCameraByID=function(e){for(var t=0;t<this.cameras.length;t++)if(this.cameras[t].id===e)return this.cameras[t];return null},t.prototype.getCameraByUniqueID=function(e){for(var t=0;t<this.cameras.length;t++)if(this.cameras[t].uniqueId===e)return this.cameras[t];return null},t.prototype.getCameraByName=function(e){for(var t=0;t<this.cameras.length;t++)if(this.cameras[t].name===e)return this.cameras[t];return null},t.prototype.getBoneByID=function(e){for(var t=0;t<this.skeletons.length;t++)for(var r=this.skeletons[t],i=0;i<r.bones.length;i++)if(r.bones[i].id===e)return r.bones[i];return null},t.prototype.getBoneByName=function(e){for(var t=0;t<this.skeletons.length;t++)for(var r=this.skeletons[t],i=0;i<r.bones.length;i++)if(r.bones[i].name===e)return r.bones[i];return null},t.prototype.getLightByName=function(e){for(var t=0;t<this.lights.length;t++)if(this.lights[t].name===e)return this.lights[t];return null},t.prototype.getLightByID=function(e){for(var t=0;t<this.lights.length;t++)if(this.lights[t].id===e)return this.lights[t];return null},t.prototype.getLightByUniqueID=function(e){for(var t=0;t<this.lights.length;t++)if(this.lights[t].uniqueId===e)return this.lights[t];return null},t.prototype.getParticleSystemByID=function(e){for(var t=0;t<this.particleSystems.length;t++)if(this.particleSystems[t].id===e)return this.particleSystems[t];return null},t.prototype.getGeometryByID=function(e){for(var t=0;t<this._geometries.length;t++)if(this._geometries[t].id===e)return this._geometries[t];return null},t.prototype.pushGeometry=function(e,t){return!t&&this.getGeometryByID(e.id)?!1:(this._geometries.push(e),this.collisionCoordinator.onGeometryAdded(e),this.onGeometryAdded&&this.onGeometryAdded(e),!0)},t.prototype.removeGeometry=function(e){var t=this._geometries.indexOf(e);return t>-1?(this._geometries.splice(t,1),this.collisionCoordinator.onGeometryDeleted(e),this.onGeometryRemoved&&this.onGeometryRemoved(e),!0):!1},t.prototype.getGeometries=function(){return this._geometries},t.prototype.getMeshByID=function(e){for(var t=0;t<this.meshes.length;t++)if(this.meshes[t].id===e)return this.meshes[t];return null},t.prototype.getMeshByUniqueID=function(e){for(var t=0;t<this.meshes.length;t++)if(this.meshes[t].uniqueId===e)return this.meshes[t];return null},t.prototype.getLastMeshByID=function(e){for(var t=this.meshes.length-1;t>=0;t--)if(this.meshes[t].id===e)return this.meshes[t];return null},t.prototype.getLastEntryByID=function(e){var t;for(t=this.meshes.length-1;t>=0;t--)if(this.meshes[t].id===e)return this.meshes[t];for(t=this.cameras.length-1;t>=0;t--)if(this.cameras[t].id===e)return this.cameras[t];for(t=this.lights.length-1;t>=0;t--)if(this.lights[t].id===e)return this.lights[t];return null},t.prototype.getNodeByID=function(e){var t=this.getMeshByID(e);if(t)return t;var 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<this.meshes.length;t++)if(this.meshes[t].name===e)return this.meshes[t];return null},t.prototype.getSoundByName=function(t){var r;if(e.AudioEngine){for(r=0;r<this.mainSoundTrack.soundCollection.length;r++)if(this.mainSoundTrack.soundCollection[r].name===t)return this.mainSoundTrack.soundCollection[r];for(var i=0;i<this.soundTracks.length;i++)for(r=0;r<this.soundTracks[i].soundCollection.length;r++)if(this.soundTracks[i].soundCollection[r].name===t)return this.soundTracks[i].soundCollection[r]}return null},t.prototype.getLastSkeletonByID=function(e){for(var t=this.skeletons.length-1;t>=0;t--)if(this.skeletons[t].id===e)return this.skeletons[t];return null},t.prototype.getSkeletonById=function(e){for(var t=0;t<this.skeletons.length;t++)if(this.skeletons[t].id===e)return this.skeletons[t];return null},t.prototype.getSkeletonByName=function(e){for(var t=0;t<this.skeletons.length;t++)if(this.skeletons[t].name===e)return this.skeletons[t];return null},t.prototype.isActiveMesh=function(e){return-1!==this._activeMeshes.indexOf(e)},t.prototype._evaluateSubMesh=function(e,t){if(t.alwaysSelectAsActiveMesh||1===t.subMeshes.length||e.isInFrustum(this._frustumPlanes)){var r=e.getMaterial();t.showSubMeshesBoundingBox&&this._boundingBoxRenderer.renderList.push(e.getBoundingInfo().boundingBox),r&&(r.getRenderTargetTextures&&-1===this._processedMaterials.indexOf(r)&&(this._processedMaterials.push(r),this._renderTargets.concat(r.getRenderTargetTextures())),this._activeIndices+=e.indexCount,this._renderingManager.dispatch(e))}},t.prototype._evaluateActiveMeshes=function(){this.activeCamera._activeMeshes.reset(),this._activeMeshes.reset(),this._renderingManager.reset(),this._processedMaterials.reset(),this._activeParticleSystems.reset(),this._activeSkeletons.reset(),this._softwareSkinnedMeshes.reset(),this._boundingBoxRenderer.reset(),this._edgesRenderers.reset(),this._frustumPlanes?e.Frustum.GetPlanesToRef(this._transformMatrix,this._frustumPlanes):this._frustumPlanes=e.Frustum.GetPlanes(this._transformMatrix);var t,r;if(this._selectionOctree){var i=this._selectionOctree.select(this._frustumPlanes);t=i.data,r=i.length}else r=this.meshes.length,t=this.meshes;for(var n=0;r>n;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;h<this.particleSystems.length;h++){var c=this.particleSystems[h];c.isStarted()&&(!c.emitter.position||c.emitter&&c.emitter.isEnabled())&&(this._activeParticleSystems.push(c),c.animate())}e.Tools.EndPerformanceCounter("Particles",this.particleSystems.length>0)}this._particlesDuration+=e.Tools.Now-a},t.prototype._activeMesh=function(e){if(e.skeleton&&this.skeletonsEnabled&&(this._activeSkeletons.pushNoDuplicate(e.skeleton),e.computeBonesUsingShaders||this._softwareSkinnedMeshes.pushNoDuplicate(e)),(e.showBoundingBox||this.forceShowBoundingBoxes)&&this._boundingBoxRenderer.renderList.push(e.getBoundingInfo().boundingBox),e._edgesRenderer&&this._edgesRenderers.push(e._edgesRenderer),e&&e.subMeshes){var t,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;n<this._activeSkeletons.length;n++){var s=this._activeSkeletons.data[n];s.prepare()}for(var o=0;o<this._softwareSkinnedMeshes.length;o++){var a=this._softwareSkinnedMeshes.data[o];a.applySkeleton(a.skeleton)}var h=e.Tools.Now;if(this.renderTargetsEnabled&&this._renderTargets.length>0){e.Tools.StartPerformanceCounter("Render targets",this._renderTargets.length>0);for(var c=0;c<this._renderTargets.length;c++){var l=this._renderTargets.data[c];if(l._shouldRender()){this._renderId++;var u=l.activeCamera&&l.activeCamera!==this.activeCamera;l.render(u,this.dumpNextRenderTargets)}}e.Tools.EndPerformanceCounter("Render targets",this._renderTargets.length>0),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;f<this.layers.length;f++)d=this.layers[f],d.isBackground&&d.render();r.setDepthBuffer(!0)}e.Tools.StartPerformanceCounter("Main render"),this._renderingManager.render(null,null,!0,!0),e.Tools.EndPerformanceCounter("Main render"),this._boundingBoxRenderer.render();for(var m=0;m<this._edgesRenderers.length;m++)this._edgesRenderers.data[m].render();if(this.lensFlaresEnabled){e.Tools.StartPerformanceCounter("Lens flares",this.lensFlareSystems.length>0);for(var g=0;g<this.lensFlareSystems.length;g++){var _=this.lensFlareSystems[g];0!==(t.layerMask&_.layerMask)&&_.render()}e.Tools.EndPerformanceCounter("Lens flares",this.lensFlareSystems.length>0)}if(this.layers.length){for(r.setDepthBuffer(!1),f=0;f<this.layers.length;f++)d=this.layers[f],d.isBackground||d.render();r.setDepthBuffer(!0)}this._renderDuration+=e.Tools.Now-p,this.postProcessManager._finalizeFrame(t.isIntermediate),this.activeCamera._updateFromScene(),this._renderTargets.reset(),this.afterCameraRender&&this.afterCameraRender(this.activeCamera),e.Tools.EndPerformanceCounter("Rendering camera "+this.activeCamera.name)},t.prototype._processSubCameras=function(t){if(t.cameraRigMode===e.Camera.RIG_MODE_NONE)return void this._renderForCamera(t);for(var r=0;r<t._rigCameras.length;r++)this._renderForCamera(t._rigCameras[r]);this.activeCamera=t,this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix()),this.activeCamera._updateFromScene()},t.prototype._checkIntersections=function(){for(var t=0;t<this._meshesForIntersections.length;t++)for(var r=this._meshesForIntersections.data[t],i=0;i<r.actionManager.actions.length;i++){var n=r.actionManager.actions[i];if(n.trigger===e.ActionManager.OnIntersectionEnterTrigger||n.trigger===e.ActionManager.OnIntersectionExitTrigger){var s=n.getTriggerParameter(),o=s instanceof e.AbstractMesh?s:s.mesh,a=o.intersectsMesh(r,s.usePreciseIntersection),h=r._intersectionsInProgress.indexOf(o);a&&-1===h?n.trigger===e.ActionManager.OnIntersectionEnterTrigger?(n._executeCurrent(e.ActionEvent.CreateNew(r,null,o)),r._intersectionsInProgress.push(o)):n.trigger===e.ActionManager.OnIntersectionExitTrigger&&r._intersectionsInProgress.push(o):!a&&h>-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;n<this._onBeforeRenderCallbacks.length;n++)this._onBeforeRenderCallbacks[n]();var s=e.Tools.Now,o=this.getEngine(),a=this.activeCamera;if(this.renderTargetsEnabled){e.Tools.StartPerformanceCounter("Custom render targets",this.customRenderTargets.length>0);for(var h=0;h<this.customRenderTargets.length;h++){var c=this.customRenderTargets[h];if(c._shouldRender()){if(this._renderId++,this.activeCamera=c.activeCamera||this.activeCamera,!this.activeCamera)throw new Error("Active camera not set");o.setViewport(this.activeCamera.viewport),this.updateTransformMatrix(),c.render(a!==this.activeCamera,this.dumpNextRenderTargets)}}e.Tools.EndPerformanceCounter("Custom render targets",this.customRenderTargets.length>0),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;l<this._proceduralTextures.length;l++){var u=this._proceduralTextures[l];u._shouldRender()&&u.render()}e.Tools.EndPerformanceCounter("Procedural textures",this._proceduralTextures.length>0)}if(this._engine.clear(this.clearColor,this.autoClear||this.forceWireframe||this.forcePointsCloud,!0),this.shadowsEnabled)for(var f=0;f<this.lights.length;f++){var d=this.lights[f],p=d.getShadowGenerator();d.isEnabled()&&p&&-1!==p.getShadowMap().getScene().textures.indexOf(p.getShadowMap())&&this._renderTargets.push(p.getShadowMap())}if(this._depthRenderer&&this._renderTargets.push(this._depthRenderer.getDepthMap()),this.postProcessRenderPipelineManager.update(),this.activeCameras.length>0)for(var m=this._renderId,g=0;g<this.activeCameras.length;g++)this._renderId=m,g>0&&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;n<this._onAfterRenderCallbacks.length;n++)this._onAfterRenderCallbacks[n]();for(var _=0;_<this._toBeDisposed.length;_++)this._toBeDisposed.data[_].dispose(),this._toBeDisposed[_]=null;this._toBeDisposed.reset(),this.dumpNextRenderTargets&&(this.dumpNextRenderTargets=!1),e.Tools.EndPerformanceCounter("Scene rendering"),this._lastFrameDuration=e.Tools.Now-r},t.prototype._updateAudioParameters=function(){if(this.audioEnabled&&(0!==this.mainSoundTrack.soundCollection.length||1!==this.soundTracks.length)){var t,r=e.Engine.audioEngine;if(t=this.activeCameras.length>0?this.activeCameras[0]:this.activeCamera,t&&r.canUseWebAudio){r.audioContext.listener.setPosition(t.position.x,t.position.y,t.position.z);var i=e.Matrix.Invert(t.getViewMatrix()),n=e.Vector3.TransformNormal(new e.Vector3(0,0,-1),i);n.normalize(),r.audioContext.listener.setOrientation(n.x,n.y,n.z,0,1,0);var s;for(s=0;s<this.mainSoundTrack.soundCollection.length;s++){var o=this.mainSoundTrack.soundCollection[s];o.useCustomAttenuation&&o.updateDistanceFromListener()}for(s=0;s<this.soundTracks.length;s++)for(var a=0;a<this.soundTracks[s].soundCollection.length;a++)o=this.soundTracks[s].soundCollection[a],o.useCustomAttenuation&&o.updateDistanceFromListener()}}},Object.defineProperty(t.prototype,"audioEnabled",{get:function(){return this._audioEnabled},set:function(t){this._audioEnabled=t,e.AudioEngine&&(this._audioEnabled?this._enableAudio():this._disableAudio())},enumerable:!0,configurable:!0}),t.prototype._disableAudio=function(){var e;for(e=0;e<this.mainSoundTrack.soundCollection.length;e++)this.mainSoundTrack.soundCollection[e].pause();for(e=0;e<this.soundTracks.length;e++)for(var t=0;t<this.soundTracks[e].soundCollection.length;t++)this.soundTracks[e].soundCollection[t].pause()},t.prototype._enableAudio=function(){var e;for(e=0;e<this.mainSoundTrack.soundCollection.length;e++)this.mainSoundTrack.soundCollection[e].isPaused&&this.mainSoundTrack.soundCollection[e].play();for(e=0;e<this.soundTracks.length;e++)for(var t=0;t<this.soundTracks[e].soundCollection.length;t++)this.soundTracks[e].soundCollection[t].isPaused&&this.soundTracks[e].soundCollection[t].play()},Object.defineProperty(t.prototype,"headphone",{get:function(){return this._headphone},set:function(t){this._headphone=t,e.AudioEngine&&(this._headphone?this._switchAudioModeForHeadphones():this._switchAudioModeForNormalSpeakers())},enumerable:!0,configurable:!0}),t.prototype._switchAudioModeForHeadphones=function(){this.mainSoundTrack.switchPanningModelToHRTF();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].switchPanningModelToHRTF()},t.prototype._switchAudioModeForNormalSpeakers=function(){this.mainSoundTrack.switchPanningModelToEqualPower();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].switchPanningModelToEqualPower()},t.prototype.enableDepthRenderer=function(){return this._depthRenderer?this._depthRenderer:(this._depthRenderer=new e.DepthRenderer(this),this._depthRenderer)},t.prototype.disableDepthRenderer=function(){this._depthRenderer&&(this._depthRenderer.dispose(),this._depthRenderer=null)},t.prototype.freezeMaterials=function(){for(var e=0;e<this.materials.length;e++)this.materials[e].freeze()},t.prototype.unfreezeMaterials=function(){for(var e=0;e<this.materials.length;e++)this.materials[e].unfreeze()},t.prototype.dispose=function(){this.beforeRender=null,this.afterRender=null,this.skeletons=[],this._boundingBoxRenderer.dispose(),this._depthRenderer&&this._depthRenderer.dispose(),this.debugLayer.hide(),this.onDispose&&this.onDispose(),this._onBeforeRenderCallbacks=[],this._onAfterRenderCallbacks=[],this.detachControl(),e.AudioEngine&&this.disposeSounds();var t,r=this._engine.getRenderingCanvas();for(t=0;t<this.cameras.length;t++)this.cameras[t].detachControl(r);for(;this.lights.length;)this.lights[0].dispose();for(;this.meshes.length;)this.meshes[0].dispose(!0);for(;this.cameras.length;)this.cameras[0].dispose();for(;this.materials.length;)this.materials[0].dispose();for(;this.particleSystems.length;)this.particleSystems[0].dispose();for(;this.spriteManagers.length;)this.spriteManagers[0].dispose();for(;this.layers.length;)this.layers[0].dispose();for(;this.textures.length;)this.textures[0].dispose();this.postProcessManager.dispose(),this._physicsEngine&&this.disablePhysicsEngine(),t=this._engine.scenes.indexOf(this),t>-1&&this._engine.scenes.splice(t,1),this._engine.wipeCaches()},t.prototype.disposeSounds=function(){this.mainSoundTrack.dispose();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].dispose()},t.prototype.getWorldExtends=function(){for(var t=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),r=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),i=0;i<this.meshes.length;i++){var n=this.meshes[i];n.computeWorldMatrix(!0);var s=n.getBoundingInfo().boundingBox.minimumWorld,o=n.getBoundingInfo().boundingBox.maximumWorld;e.Tools.CheckExtends(s,t,r),e.Tools.CheckExtends(o,t,r)}return{min:t,max:r}},t.prototype.createOrUpdateSelectionOctree=function(t,r){void 0===t&&(t=64),void 0===r&&(r=2),this._selectionOctree||(this._selectionOctree=new e.Octree(e.Octree.CreationFuncForMeshes,t,r));var i=this.getWorldExtends();return this._selectionOctree.update(i.min,i.max,this.meshes),this._selectionOctree},t.prototype.createPickingRay=function(t,r,i,n,s){void 0===s&&(s=!1);var o=this._engine;if(!n){if(!this.activeCamera)throw new Error("Active camera not set");n=this.activeCamera}var a=n.viewport,h=a.toGlobal(o);return t=t/this._engine.getHardwareScalingLevel()-h.x,r=r/this._engine.getHardwareScalingLevel()-(this._engine.getRenderHeight()-h.y-h.height),e.Ray.CreateNew(t,r,h.width,h.height,i?i:e.Matrix.Identity(),s?e.Matrix.Identity():n.getViewMatrix(),n.getProjectionMatrix())},t.prototype.createPickingRayInCameraSpace=function(t,r,i){var n=this._engine;if(!i){if(!this.activeCamera)throw new Error("Active camera not set");i=this.activeCamera}var s=i.viewport,o=s.toGlobal(n),a=e.Matrix.Identity();return t=t/this._engine.getHardwareScalingLevel()-o.x,r=r/this._engine.getHardwareScalingLevel()-(this._engine.getRenderHeight()-o.y-o.height),e.Ray.CreateNew(t,r,o.width,o.height,a,a,i.getProjectionMatrix())},t.prototype._internalPick=function(t,r,i){for(var n=null,s=0;s<this.meshes.length;s++){var o=this.meshes[s];if(r){if(!r(o))continue}else if(!o.isEnabled()||!o.isVisible||!o.isPickable)continue;var a=o.getWorldMatrix(),h=t(a),c=o.intersects(h,i);if(c&&c.hit&&(i||null==n||!(c.distance>=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<this.spriteManagers.length;o++){var a=this.spriteManagers[o];if(a.isPickable){var h=a.intersects(t,n,r,i);if(h&&h.hit&&(i||null==s||!(h.distance>=s.distance))&&(s=h,i))break}}return s||new e.PickingInfo;
  10. },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;r<e.length;r++){var i=e[r].mesh;i._physicImpostor=e[r].impostor,i._physicsMass=t.mass/e.length,i._physicsFriction=t.friction,i._physicRestitution=t.restitution}return this._physicsEngine._registerMeshesAsCompound(e,t)},t.prototype.deleteCompoundImpostor=function(t){for(var r=0;r<t.parts.length;r++){var i=t.parts[r].mesh;i._physicImpostor=e.PhysicsEngine.NoImpostor,this._physicsEngine._unregisterMesh(i)}},t.prototype.createDefaultCameraOrLight=function(){if(0===this.lights.length&&new e.HemisphericLight("default light",e.Vector3.Up(),this),!this.activeCamera){var t=new e.FreeCamera("default camera",e.Vector3.Zero(),this),r=this.getWorldExtends(),i=r.min.add(r.max.subtract(r.min).scale(.5));t.position=new e.Vector3(i.x,i.y,r.min.z-(r.max.z-r.min.z)),t.setTarget(i),this.activeCamera=t}},t.prototype._getByTags=function(t,r,i){if(void 0===r)return t;var n=[];i=i||function(e){};for(var s in t){var o=t[s];e.Tags.MatchesQuery(o,r)&&(n.push(o),i(o))}return n},t.prototype.getMeshesByTags=function(e,t){return this._getByTags(this.meshes,e,t)},t.prototype.getCamerasByTags=function(e,t){return this._getByTags(this.cameras,e,t)},t.prototype.getLightsByTags=function(e,t){return this._getByTags(this.lights,e,t)},t.prototype.getMaterialByTags=function(e,t){return this._getByTags(this.materials,e,t).concat(this._getByTags(this.multiMaterials,e,t))},t._FOGMODE_NONE=0,t._FOGMODE_EXP=1,t._FOGMODE_EXP2=2,t._FOGMODE_LINEAR=3,t.MinDeltaTime=1,t.MaxDeltaTime=1e3,t}();e.Scene=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(r,i,n,s,o,a){if(r instanceof e.Mesh?this._engine=r.getScene().getEngine():this._engine=r,this._updatable=s,this._data=i,o||this.create(),this._kind=n,a)return void(this._strideSize=a);switch(n){case t.PositionKind:this._strideSize=3;break;case t.NormalKind:this._strideSize=3;break;case t.UVKind:case t.UV2Kind:case t.UV3Kind:case t.UV4Kind:case t.UV5Kind:case t.UV6Kind:this._strideSize=2;break;case t.ColorKind:this._strideSize=4;break;case t.MatricesIndicesKind:case t.MatricesIndicesExtraKind:this._strideSize=4;break;case t.MatricesWeightsKind:case t.MatricesWeightsExtraKind:this._strideSize=4}}return t.prototype.isUpdatable=function(){return this._updatable},t.prototype.getData=function(){return this._data},t.prototype.getBuffer=function(){return this._buffer},t.prototype.getStrideSize=function(){return this._strideSize},t.prototype.create=function(e){(e||!this._buffer)&&(e=e||this._data,this._buffer||(this._updatable?this._buffer=this._engine.createDynamicVertexBuffer(4*e.length):this._buffer=this._engine.createVertexBuffer(e)),this._updatable&&(this._engine.updateDynamicVertexBuffer(this._buffer,e),this._data=e))},t.prototype.update=function(e){this.create(e)},t.prototype.updateDirectly=function(e,t){this._buffer&&this._updatable&&(this._engine.updateDynamicVertexBuffer(this._buffer,e,t),this._data=null)},t.prototype.dispose=function(){this._buffer&&this._engine._releaseBuffer(this._buffer)&&(this._buffer=null)},Object.defineProperty(t,"PositionKind",{get:function(){return t._PositionKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"NormalKind",{get:function(){return t._NormalKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UVKind",{get:function(){return t._UVKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UV2Kind",{get:function(){return t._UV2Kind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UV3Kind",{get:function(){return t._UV3Kind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UV4Kind",{get:function(){return t._UV4Kind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UV5Kind",{get:function(){return t._UV5Kind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UV6Kind",{get:function(){return t._UV6Kind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ColorKind",{get:function(){return t._ColorKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"MatricesIndicesKind",{get:function(){return t._MatricesIndicesKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"MatricesWeightsKind",{get:function(){return t._MatricesWeightsKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"MatricesIndicesExtraKind",{get:function(){return t._MatricesIndicesExtraKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"MatricesWeightsExtraKind",{get:function(){return t._MatricesWeightsExtraKind},enumerable:!0,configurable:!0}),t._PositionKind="position",t._NormalKind="normal",t._UVKind="uv",t._UV2Kind="uv2",t._UV3Kind="uv3",t._UV4Kind="uv4",t._UV5Kind="uv5",t._UV6Kind="uv6",t._ColorKind="color",t._MatricesIndicesKind="matricesIndices",t._MatricesWeightsKind="matricesWeights",t._MatricesIndicesExtraKind="matricesIndicesExtra",t._MatricesWeightsExtraKind="matricesWeightsExtra",t}();e.VertexBuffer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(e,r){t.call(this,e,r.getScene()),r.instances.push(this),this._sourceMesh=r,this.position.copyFrom(r.position),this.rotation.copyFrom(r.rotation),this.scaling.copyFrom(r.scaling),r.rotationQuaternion&&(this.rotationQuaternion=r.rotationQuaternion.clone()),this.infiniteDistance=r.infiniteDistance,this.setPivotMatrix(r.getPivotMatrix()),this.refreshBoundingInfo(),this._syncSubMeshes()}return __extends(r,t),Object.defineProperty(r.prototype,"receiveShadows",{get:function(){return this._sourceMesh.receiveShadows},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"material",{get:function(){return this._sourceMesh.material},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"visibility",{get:function(){return this._sourceMesh.visibility},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"skeleton",{get:function(){return this._sourceMesh.skeleton},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"renderingGroupId",{get:function(){return this._sourceMesh.renderingGroupId},enumerable:!0,configurable:!0}),r.prototype.getTotalVertices=function(){return this._sourceMesh.getTotalVertices()},Object.defineProperty(r.prototype,"sourceMesh",{get:function(){return this._sourceMesh},enumerable:!0,configurable:!0}),r.prototype.getVerticesData=function(e,t){return this._sourceMesh.getVerticesData(e,t)},r.prototype.isVerticesDataPresent=function(e){return this._sourceMesh.isVerticesDataPresent(e)},r.prototype.getIndices=function(){return this._sourceMesh.getIndices()},Object.defineProperty(r.prototype,"_positions",{get:function(){return this._sourceMesh._positions},enumerable:!0,configurable:!0}),r.prototype.refreshBoundingInfo=function(){var t=this._sourceMesh.getBoundingInfo();this._boundingInfo=new e.BoundingInfo(t.minimum.clone(),t.maximum.clone()),this._updateBoundingInfo()},r.prototype._preActivate=function(){this._currentLOD&&this._currentLOD._preActivate()},r.prototype._activate=function(e){this._currentLOD&&this._currentLOD._registerInstanceForRenderId(this,e)},r.prototype.getLOD=function(e){return this._currentLOD=this.sourceMesh.getLOD(this.getScene().activeCamera,this.getBoundingInfo().boundingSphere),this._currentLOD===this.sourceMesh?this:this._currentLOD},r.prototype._syncSubMeshes=function(){if(this.releaseSubMeshes(),this._sourceMesh.subMeshes)for(var e=0;e<this._sourceMesh.subMeshes.length;e++)this._sourceMesh.subMeshes[e].clone(this,this._sourceMesh)},r.prototype._generatePointsArray=function(){return this._sourceMesh._generatePointsArray()},r.prototype.clone=function(t,r,i){var n=this._sourceMesh.createInstance(t);if(e.Tools.DeepCopy(this,n,["name"],[]),this.refreshBoundingInfo(),r&&(n.parent=r),!i)for(var s=0;s<this.getScene().meshes.length;s++){var o=this.getScene().meshes[s];o.parent===this&&o.clone(o.name,n)}return n.computeWorldMatrix(!0),n},r.prototype.dispose=function(e){var r=this._sourceMesh.instances.indexOf(this);this._sourceMesh.instances.splice(r,1),t.prototype.dispose.call(this,e)},r}(e.AbstractMesh);e.InstancedMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this.mustReturn=!1,this.visibleInstances=new Array,this.renderSelf=new Array}return e}();e._InstancesBatch=t;var r=function(r){function i(n,s,o,a,h){if(void 0===o&&(o=null),r.call(this,n,s),this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this.instances=new Array,this._LODLevels=new Array,this._onBeforeRenderCallbacks=new Array,this._onAfterRenderCallbacks=new Array,this._visibleInstances={},this._renderIdForInstances=new Array,this._batchCache=new t,this._instancesBufferSize=2048,this._sideOrientation=i._DEFAULTSIDE,this._areNormalsFrozen=!1,a){a._geometry&&a._geometry.applyToMesh(this),e.Tools.DeepCopy(a,this,["name","material","skeleton","instances"],[]),this.id=n+"."+a.id,this.material=a.material;var c;if(!h)for(c=0;c<s.meshes.length;c++){var l=s.meshes[c];if(l.parent===a){l.clone(n+"."+l.name,this,h)}}for(c=0;c<s.particleSystems.length;c++){var u=s.particleSystems[c];u.emitter===a&&u.clone(u.name,this)}this.computeWorldMatrix(!0)}null!==o&&(this.parent=o)}return __extends(i,r),Object.defineProperty(i,"FRONTSIDE",{get:function(){return i._FRONTSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BACKSIDE",{get:function(){return i._BACKSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"DOUBLESIDE",{get:function(){return i._DOUBLESIDE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"DEFAULTSIDE",{get:function(){return i._DEFAULTSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"NO_CAP",{get:function(){return i._NO_CAP},enumerable:!0,configurable:!0}),Object.defineProperty(i,"CAP_START",{get:function(){return i._CAP_START},enumerable:!0,configurable:!0}),Object.defineProperty(i,"CAP_END",{get:function(){return i._CAP_END},enumerable:!0,configurable:!0}),Object.defineProperty(i,"CAP_ALL",{get:function(){return i._CAP_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"hasLODLevels",{get:function(){return this._LODLevels.length>0},enumerable:!0,configurable:!0}),i.prototype._sortLODLevels=function(){this._LODLevels.sort(function(e,t){return e.distance<t.distance?1:e.distance>t.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;t<this._LODLevels.length;t++){var r=this._LODLevels[t];if(r.distance===e)return r.mesh}return null},i.prototype.removeLODLevel=function(e){for(var t=0;t<this._LODLevels.length;t++)this._LODLevels[t].mesh===e&&(this._LODLevels.splice(t,1),e&&(e._masterMesh=null));return this._sortLODLevels(),this},i.prototype.getLOD=function(e,t){if(!this._LODLevels||0===this._LODLevels.length)return this;var r=(t?t:this.getBoundingInfo().boundingSphere).centerWorld.subtract(e.position).length();if(this._LODLevels[this._LODLevels.length-1].distance>r)return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var i=0;i<this._LODLevels.length;i++){var n=this._LODLevels[i];if(n.distance<r)return n.mesh&&(n.mesh._preActivate(),n.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)),this.onLODLevelSelection&&this.onLODLevelSelection(r,this,n.mesh),n.mesh}return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,this),this},Object.defineProperty(i.prototype,"geometry",{get:function(){return this._geometry},enumerable:!0,configurable:!0}),i.prototype.getTotalVertices=function(){return this._geometry?this._geometry.getTotalVertices():0},i.prototype.getVerticesData=function(e,t){return this._geometry?this._geometry.getVerticesData(e,t):null},i.prototype.getVertexBuffer=function(e){return this._geometry?this._geometry.getVertexBuffer(e):void 0},i.prototype.isVerticesDataPresent=function(e){return this._geometry?this._geometry.isVerticesDataPresent(e):this._delayInfo?-1!==this._delayInfo.indexOf(e):!1},i.prototype.getVerticesDataKinds=function(){if(!this._geometry){var e=[];if(this._delayInfo)for(var t in this._delayInfo)e.push(t);return e}return this._geometry.getVerticesDataKinds()},i.prototype.getTotalIndices=function(){return this._geometry?this._geometry.getTotalIndices():0},i.prototype.getIndices=function(e){return this._geometry?this._geometry.getIndices(e):[]},Object.defineProperty(i.prototype,"isBlocked",{get:function(){return null!==this._masterMesh&&void 0!==this._masterMesh},enumerable:!0,configurable:!0}),i.prototype.isReady=function(){return this.delayLoadState===e.Engine.DELAYLOADSTATE_LOADING?!1:r.prototype.isReady.call(this)},i.prototype.isDisposed=function(){return this._isDisposed},Object.defineProperty(i.prototype,"sideOrientation",{get:function(){return this._sideOrientation},set:function(e){this._sideOrientation=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"areNormalsFrozen",{get:function(){return this._areNormalsFrozen},enumerable:!0,configurable:!0}),i.prototype.freezeNormals=function(){this._areNormalsFrozen=!0},i.prototype.unfreezeNormals=function(){this._areNormalsFrozen=!1},i.prototype._preActivate=function(){var e=this.getScene().getRenderId();this._preActivateId!==e&&(this._preActivateId=e,this._visibleInstances=null)},i.prototype._registerInstanceForRenderId=function(e,t){this._visibleInstances||(this._visibleInstances={},this._visibleInstances.defaultRenderId=t,this._visibleInstances.selfDefaultRenderId=this._renderId),this._visibleInstances[t]||(this._visibleInstances[t]=new Array),this._visibleInstances[t].push(e)},i.prototype.refreshBoundingInfo=function(){if(!this._boundingInfo.isLocked){var t=this.getVerticesData(e.VertexBuffer.PositionKind);if(t){var r=e.Tools.ExtractMinAndMax(t,0,this.getTotalVertices());this._boundingInfo=new e.BoundingInfo(r.minimum,r.maximum)}if(this.subMeshes)for(var i=0;i<this.subMeshes.length;i++)this.subMeshes[i].refreshBoundingInfo();this._updateBoundingInfo()}},i.prototype._createGlobalSubMesh=function(){var t=this.getTotalVertices();return t&&this.getIndices()?(this.releaseSubMeshes(),new e.SubMesh(0,0,t,0,this.getTotalIndices(),this)):null},i.prototype.subdivide=function(t){if(!(1>t)){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._instancesBufferSize<a;)this._instancesBufferSize*=2;(!this._worldMatricesInstancesBuffer||this._worldMatricesInstancesBuffer.capacity<this._instancesBufferSize)&&(this._worldMatricesInstancesBuffer&&n.deleteInstancesBuffer(this._worldMatricesInstancesBuffer),this._worldMatricesInstancesBuffer=n.createInstancesBuffer(this._instancesBufferSize),this._worldMatricesInstancesArray=new Float32Array(this._instancesBufferSize/4));var h=0,c=0,l=this.getWorldMatrix();if(r.renderSelf[e._id]&&(l.copyToArray(this._worldMatricesInstancesArray,h),h+=16,c++),s)for(var u=0;u<s.length;u++){var f=s[u];f.getWorldMatrix().copyToArray(this._worldMatricesInstancesArray,h),h+=16,c++}var d=i.getAttributeLocationByName("world0"),p=i.getAttributeLocationByName("world1"),m=i.getAttributeLocationByName("world2"),g=i.getAttributeLocationByName("world3"),_=[d,p,m,g];n.updateAndBindInstancesBuffer(this._worldMatricesInstancesBuffer,this._worldMatricesInstancesArray,_),this._draw(e,t,c),n.unBindInstancesBuffer(this._worldMatricesInstancesBuffer,_)},i.prototype._processRendering=function(e,t,r,i,n,s){var o=this.getScene(),a=o.getEngine();if(n)this._renderWithInstances(e,r,i,t,a);else if(i.renderSelf[e._id]&&(s&&s(!1,this.getWorldMatrix()),this._draw(e,r)),i.visibleInstances[e._id])for(var h=0;h<i.visibleInstances[e._id].length;h++){var c=i.visibleInstances[e._id][h],l=c.getWorldMatrix();s&&s(!0,l),this._draw(e,r)}},i.prototype.render=function(t,r){var i=this.getScene(),n=this._getInstancesRenderList(t._id);if(!n.mustReturn&&this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var s;for(s=0;s<this._onBeforeRenderCallbacks.length;s++)this._onBeforeRenderCallbacks[s](this);var o=i.getEngine(),a=null!==o.getCaps().instancedArrays&&null!==n.visibleInstances[t._id]&&void 0!==n.visibleInstances[t._id],h=t.getMaterial();if(h&&h.isReady(this,a)){var c=o.getDepthWrite();this.renderOutline&&(o.setDepthWrite(!1),i.getOutlineRenderer().render(t,n),o.setDepthWrite(c)),h._preBind();var l=h.getEffect(),u=i.forcePointsCloud?e.Material.PointFillMode:i.forceWireframe?e.Material.WireFrameFillMode:h.fillMode;this._bind(t,l,u);var f=this.getWorldMatrix();if(h.bind(f,this),r&&o.setAlphaMode(h.alphaMode),this._processRendering(t,l,u,n,a,function(e,t){e&&h.bindOnlyWorldMatrix(t)}),h.unbind(),this.renderOutline&&c&&(o.setDepthWrite(!0),o.setColorWrite(!1),i.getOutlineRenderer().render(t,n),o.setColorWrite(!0)),this.renderOverlay){var d=o.getAlphaMode();o.setAlphaMode(e.Engine.ALPHA_COMBINE),i.getOutlineRenderer().render(t,n,!0),o.setAlphaMode(d)}for(s=0;s<this._onAfterRenderCallbacks.length;s++)this._onAfterRenderCallbacks[s](this)}}},i.prototype.getEmittedParticleSystems=function(){for(var e=new Array,t=0;t<this.getScene().particleSystems.length;t++){var r=this.getScene().particleSystems[t];r.emitter===this&&e.push(r)}return e},i.prototype.getHierarchyEmittedParticleSystems=function(){var e=new Array,t=this.getDescendants();t.push(this);for(var r=0;r<this.getScene().particleSystems.length;r++){var i=this.getScene().particleSystems[r];-1!==t.indexOf(i.emitter)&&e.push(i)}return e},i.prototype.getChildren=function(){for(var e=[],t=0;t<this.getScene().meshes.length;t++){var r=this.getScene().meshes[t];r.parent===this&&e.push(r)}return e},i.prototype._checkDelayState=function(){var t=this,r=this,i=this.getScene();if(this._geometry)this._geometry.load(i);else if(r.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED){r.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,i._addPendingData(r);var n=-1!==this.delayLoadingFile.indexOf(".babylonbinarymeshdata");e.Tools.LoadFile(this.delayLoadingFile,function(r){r instanceof ArrayBuffer?t._delayLoadingFunction(r,t):t._delayLoadingFunction(JSON.parse(r),t),t.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,i._removePendingData(t)},function(){},i.database,n)}},i.prototype.isInFrustum=function(t){return this.delayLoadState===e.Engine.DELAYLOADSTATE_LOADING?!1:r.prototype.isInFrustum.call(this,t)?(this._checkDelayState(),!0):!1},i.prototype.setMaterialByID=function(e){var t,r=this.getScene().materials;for(t=0;t<r.length;t++)if(r[t].id===e)return void(this.material=r[t]);var i=this.getScene().multiMaterials;for(t=0;t<i.length;t++)if(i[t].id===e)return void(this.material=i[t])},i.prototype.getAnimatables=function(){var e=[];return this.material&&e.push(this.material),this.skeleton&&e.push(this.skeleton),e},i.prototype.bakeTransformIntoVertices=function(t){if(this.isVerticesDataPresent(e.VertexBuffer.PositionKind)){this._resetPointsArrayCache();var r,i=this.getVerticesData(e.VertexBuffer.PositionKind),n=[];for(r=0;r<i.length;r+=3)e.Vector3.TransformCoordinates(e.Vector3.FromArray(i,r),t).toArray(n,r);if(this.setVerticesData(e.VertexBuffer.PositionKind,n,this.getVertexBuffer(e.VertexBuffer.PositionKind).isUpdatable()),this.isVerticesDataPresent(e.VertexBuffer.NormalKind)){for(i=this.getVerticesData(e.VertexBuffer.NormalKind),n=[],r=0;r<i.length;r+=3)e.Vector3.TransformNormal(e.Vector3.FromArray(i,r),t).normalize().toArray(n,r);this.setVerticesData(e.VertexBuffer.NormalKind,n,this.getVertexBuffer(e.VertexBuffer.NormalKind).isUpdatable()),t.m[0]*t.m[5]*t.m[10]<0&&this.flipFaces()}}},i.prototype.bakeCurrentTransformIntoVertices=function(){this.bakeTransformIntoVertices(this.computeWorldMatrix(!0)),this.scaling.copyFromFloats(1,1,1),this.position.copyFromFloats(0,0,0),this.rotation.copyFromFloats(0,0,0),this.rotationQuaternion&&(this.rotationQuaternion=e.Quaternion.Identity()),this._worldMatrix=e.Matrix.Identity()},i.prototype._resetPointsArrayCache=function(){this._positions=null},i.prototype._generatePointsArray=function(){if(this._positions)return!0;this._positions=[];var t=this.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return!1;for(var r=0;r<t.length;r+=3)this._positions.push(e.Vector3.FromArray(t,r));return!0},i.prototype.clone=function(e,t,r){return new i(e,this.getScene(),t,this,r)},i.prototype.dispose=function(e){for(this._geometry&&this._geometry.releaseForMesh(this,!0),this._worldMatricesInstancesBuffer&&(this.getEngine().deleteInstancesBuffer(this._worldMatricesInstancesBuffer),this._worldMatricesInstancesBuffer=null);this.instances.length;)this.instances[0].dispose();r.prototype.dispose.call(this,e)},i.prototype.applyDisplacementMap=function(t,r,i,n){var s=this,o=this.getScene(),a=function(e){var t=document.createElement("canvas"),o=t.getContext("2d"),a=e.width,h=e.height;t.width=a,t.height=h,o.drawImage(e,0,0);var c=o.getImageData(0,0,a,h).data;s.applyDisplacementMapFromBuffer(c,a,h,r,i),n&&n(s)};e.Tools.LoadImage(t,a,function(){},o.database)},i.prototype.applyDisplacementMapFromBuffer=function(t,r,i,n,s){if(!this.isVerticesDataPresent(e.VertexBuffer.PositionKind)||!this.isVerticesDataPresent(e.VertexBuffer.NormalKind)||!this.isVerticesDataPresent(e.VertexBuffer.UVKind))return void e.Tools.Warn("Cannot call applyDisplacementMap: Given mesh is not complete. Position, Normal or UV are missing");for(var o=this.getVerticesData(e.VertexBuffer.PositionKind),a=this.getVerticesData(e.VertexBuffer.NormalKind),h=this.getVerticesData(e.VertexBuffer.UVKind),c=e.Vector3.Zero(),l=e.Vector3.Zero(),u=e.Vector2.Zero(),f=0;f<o.length;f+=3){e.Vector3.FromArrayToRef(o,f,c),e.Vector3.FromArrayToRef(a,f,l),e.Vector2.FromArrayToRef(h,f/3*2,u);var d=Math.abs(u.x)*r%r|0,p=Math.abs(u.y)*i%i|0,m=4*(d+p*r),g=t[m]/255,_=t[m+1]/255,v=t[m+2]/255,y=.3*g+.59*_+.11*v;l.normalize(),l.scaleInPlace(n+(s-n)*y),c=c.add(l),c.toArray(o,f)}e.VertexData.ComputeNormals(o,this.getIndices(),a),this.updateVerticesData(e.VertexBuffer.PositionKind,o),this.updateVerticesData(e.VertexBuffer.NormalKind,a)},i.prototype.convertToFlatShadedMesh=function(){var t,r,i=this.getVerticesDataKinds(),n=[],s=[],o=[],a=!1;for(t=0;t<i.length;t++){r=i[t];var h=this.getVertexBuffer(r);r!==e.VertexBuffer.NormalKind?(n[r]=h,s[r]=n[r].getData(),o[r]=[]):(a=h.isUpdatable(),i.splice(t,1),t--)}var c,l=this.subMeshes.slice(0),u=this.getIndices(),f=this.getTotalIndices();for(c=0;f>c;c++){var d=u[c];for(t=0;t<i.length;t++){r=i[t];for(var p=n[r].getStrideSize(),m=0;p>m;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;t<i.length;t++)r=i[t],this.setVerticesData(r,o[r],n[r].isUpdatable());this.releaseSubMeshes();for(var M=0;M<l.length;M++){var P=l[M];new e.SubMesh(P.materialIndex,P.indexStart,P.indexCount,P.indexStart,P.indexCount,this)}this.synchronizeInstances()},i.prototype.convertToUnIndexedMesh=function(){var t,r,i=this.getVerticesDataKinds(),n=[],s=[],o=[];for(t=0;t<i.length;t++){r=i[t];var a=this.getVertexBuffer(r);n[r]=a,s[r]=n[r].getData(),o[r]=[]}var h,c=this.subMeshes.slice(0),l=this.getIndices(),u=this.getTotalIndices();for(h=0;u>h;h++){var f=l[h];for(t=0;t<i.length;t++){r=i[t];for(var d=n[r].getStrideSize(),p=0;d>p;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;t<i.length;t++)r=i[t],this.setVerticesData(r,o[r],n[r].isUpdatable());this.releaseSubMeshes();for(var m=0;m<c.length;m++){var g=c[m];new e.SubMesh(g.materialIndex,g.indexStart,g.indexCount,g.indexStart,g.indexCount,this)}this._unIndexed=!0,this.synchronizeInstances()},i.prototype.flipFaces=function(t){void 0===t&&(t=!1);var r,i=e.VertexData.ExtractFromMesh(this);if(t&&this.isVerticesDataPresent(e.VertexBuffer.NormalKind))for(r=0;r<i.normals.length;r++)i.normals[r]*=-1;var n;for(r=0;r<i.indices.length;r+=3)n=i.indices[r+1],i.indices[r+1]=i.indices[r+2],i.indices[r+2]=n;i.applyToMesh(this)},i.prototype.createInstance=function(t){return new e.InstancedMesh(t,this)},i.prototype.synchronizeInstances=function(){for(var e=0;e<this.instances.length;e++){var t=this.instances[e];t._syncSubMeshes()}},i.prototype.simplify=function(t,r,i,n){void 0===r&&(r=!0),void 0===i&&(i=e.SimplificationType.QUADRATIC),this.getScene().simplificationQueue.addTask({settings:t,parallelProcessing:r,mesh:this,simplificationType:i,successCallback:n})},i.prototype.optimizeIndices=function(t){for(var r=this,i=this.getIndices(),n=this.getVerticesData(e.VertexBuffer.PositionKind),s=[],o=0;o<n.length;o+=3)s.push(e.Vector3.FromArray(n,o));var a=[];e.AsyncLoop.SyncAsyncForLoop(s.length,40,function(e){for(var t=s.length-1-e,r=s[t],i=0;t>i;++i){var n=s[i];if(r.equals(n)){a[t]=i;break}}},function(){for(var e=0;e<i.length;++e)i[e]=a[i[e]]||i[e];var n=r.subMeshes.slice(0);r.setIndices(i),r.subMeshes=n,t&&t(r)})},i.Parse=function(t,r,n){var s=new i(t.name,r);if(s.id=t.id,e.Tags.AddTagsTo(s,t.tags),s.position=e.Vector3.FromArray(t.position),t.rotationQuaternion?s.rotationQuaternion=e.Quaternion.FromArray(t.rotationQuaternion):t.rotation&&(s.rotation=e.Vector3.FromArray(t.rotation)),s.scaling=e.Vector3.FromArray(t.scaling),t.localMatrix?s.setPivotMatrix(e.Matrix.FromArray(t.localMatrix)):t.pivotMatrix&&s.setPivotMatrix(e.Matrix.FromArray(t.pivotMatrix)),s.setEnabled(t.isEnabled),s.isVisible=t.isVisible,s.infiniteDistance=t.infiniteDistance,s.showBoundingBox=t.showBoundingBox,s.showSubMeshesBoundingBox=t.showSubMeshesBoundingBox,void 0!==t.applyFog&&(s.applyFog=t.applyFog),void 0!==t.pickable&&(s.isPickable=t.pickable),void 0!==t.alphaIndex&&(s.alphaIndex=t.alphaIndex),s.receiveShadows=t.receiveShadows,s.billboardMode=t.billboardMode,void 0!==t.visibility&&(s.visibility=t.visibility),s.checkCollisions=t.checkCollisions,s._shouldGenerateFlatShading=t.useFlatShading,t.freezeWorldMatrix&&(s._waitingFreezeWorldMatrix=t.freezeWorldMatrix),t.parentId&&(s._waitingParentId=t.parentId),void 0!==t.actions&&(s._waitingActions=t.actions),s.hasVertexAlpha=t.hasVertexAlpha,t.delayLoadingFile?(s.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,s.delayLoadingFile=n+t.delayLoadingFile,s._boundingInfo=new e.BoundingInfo(e.Vector3.FromArray(t.boundingBoxMinimum),e.Vector3.FromArray(t.boundingBoxMaximum)),
  11. t._binaryInfo&&(s._binaryInfo=t._binaryInfo),s._delayInfo=[],t.hasUVs&&s._delayInfo.push(e.VertexBuffer.UVKind),t.hasUVs2&&s._delayInfo.push(e.VertexBuffer.UV2Kind),t.hasUVs3&&s._delayInfo.push(e.VertexBuffer.UV3Kind),t.hasUVs4&&s._delayInfo.push(e.VertexBuffer.UV4Kind),t.hasUVs5&&s._delayInfo.push(e.VertexBuffer.UV5Kind),t.hasUVs6&&s._delayInfo.push(e.VertexBuffer.UV6Kind),t.hasColors&&s._delayInfo.push(e.VertexBuffer.ColorKind),t.hasMatricesIndices&&s._delayInfo.push(e.VertexBuffer.MatricesIndicesKind),t.hasMatricesWeights&&s._delayInfo.push(e.VertexBuffer.MatricesWeightsKind),s._delayLoadingFunction=e.Geometry.ImportGeometry,e.SceneLoader.ForceFullSceneLoadingForIncremental&&s._checkDelayState()):e.Geometry.ImportGeometry(t,s),t.materialId?s.setMaterialByID(t.materialId):s.material=null,t.skeletonId>-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;o<t.animations.length;o++){var a=t.animations[o];s.animations.push(e.Animation.Parse(a))}e.Node.ParseAnimationRanges(s,t,r)}if(t.autoAnimate&&r.beginAnimation(s,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,1),t.layerMask&&!isNaN(t.layerMask)?s.layerMask=Math.abs(parseInt(t.layerMask)):s.layerMask=268435455,t.instances)for(var h=0;h<t.instances.length;h++){var c=t.instances[h],l=s.createInstance(c.name);if(e.Tags.AddTagsTo(l,c.tags),l.position=e.Vector3.FromArray(c.position),c.rotationQuaternion?l.rotationQuaternion=e.Quaternion.FromArray(c.rotationQuaternion):c.rotation&&(l.rotation=e.Vector3.FromArray(c.rotation)),l.scaling=e.Vector3.FromArray(c.scaling),l.checkCollisions=s.checkCollisions,t.animations){for(o=0;o<t.animations.length;o++)a=t.animations[o],l.animations.push(e.Animation.Parse(a));e.Node.ParseAnimationRanges(l,t,r)}}return s},i.CreateRibbon=function(t,r,i,n,s,o,a,h,c){return e.MeshBuilder.CreateRibbon(t,{pathArray:r,closeArray:i,closePath:n,offset:s,updatable:a,sideOrientation:h,instance:c},o)},i.CreateDisc=function(t,r,i,n,s,o){var a={radius:r,tessellation:i,sideOrientation:o,updatable:s};return e.MeshBuilder.CreateDisc(t,a,n)},i.CreateBox=function(t,r,i,n,s){var o={size:r,sideOrientation:s,updatable:n};return e.MeshBuilder.CreateBox(t,o,i)},i.CreateSphere=function(t,r,i,n,s,o){var a={segments:r,diameterX:i,diameterY:i,diameterZ:i,sideOrientation:o,updatable:s};return e.MeshBuilder.CreateSphere(t,a,n)},i.CreateCylinder=function(t,r,n,s,o,a,h,c,l){void 0!==h&&h instanceof e.Scene||(void 0!==h&&(l=c||i.DEFAULTSIDE,c=h),h=a,a=1);var u={height:r,diameterTop:n,diameterBottom:s,tessellation:o,subdivisions:a,sideOrientation:l,updatable:c};return e.MeshBuilder.CreateCylinder(t,u,h)},i.CreateTorus=function(t,r,i,n,s,o,a){var h={diameter:r,thickness:i,tessellation:n,sideOrientation:a,updatable:o};return e.MeshBuilder.CreateTorus(t,h,s)},i.CreateTorusKnot=function(t,r,i,n,s,o,a,h,c,l){var u={radius:r,tube:i,radialSegments:n,tubularSegments:s,p:o,q:a,sideOrientation:l,updatable:c};return e.MeshBuilder.CreateTorusKnot(t,u,h)},i.CreateLines=function(t,r,i,n,s){var o={points:r,updatable:n,instance:s};return e.MeshBuilder.CreateLines(t,o,i)},i.CreateDashedLines=function(t,r,i,n,s,o,a,h){var c={points:r,dashSize:i,gapSize:n,dashNb:s,updatable:a};return e.MeshBuilder.CreateDashedLines(t,c,o)},i.ExtrudeShape=function(t,r,n,s,o,a,h,c,l,u){var f={shape:r,path:n,scale:s,rotation:o,cap:0===a?0:a||i.NO_CAP,sideOrientation:l,instance:u,updatable:c};return e.MeshBuilder.ExtrudeShape(t,f,h)},i.ExtrudeShapeCustom=function(t,r,n,s,o,a,h,c,l,u,f,d){var p={shape:r,path:n,scaleFunction:s,rotationFunction:o,ribbonCloseArray:a,ribbonClosePath:h,cap:0===c?0:c||i.NO_CAP,sideOrientation:f,instance:d,updatable:u};return e.MeshBuilder.ExtrudeShapeCustom(t,p,l)},i.CreateLathe=function(t,r,i,n,s,o,a){var h={shape:r,radius:i,tessellation:n,sideOrientation:a,updatable:o};return e.MeshBuilder.CreateLathe(t,h,s)},i.CreatePlane=function(t,r,i,n,s){var o={size:r,width:r,height:r,sideOrientation:s,updatable:n};return e.MeshBuilder.CreatePlane(t,o,i)},i.CreateGround=function(t,r,i,n,s,o){var a={width:r,height:i,subdivisions:n,updatable:o};return e.MeshBuilder.CreateGround(t,a,s)},i.CreateTiledGround=function(t,r,i,n,s,o,a,h,c){var l={xmin:r,zmin:i,xmax:n,zmax:s,subdivisions:o,precision:a,updatable:c};return e.MeshBuilder.CreateTiledGround(t,l,h)},i.CreateGroundFromHeightMap=function(t,r,i,n,s,o,a,h,c,l){var u={width:i,height:n,subdivisions:s,minHeight:o,maxHeight:a,updatable:c,onReady:l};return e.MeshBuilder.CreateGroundFromHeightMap(t,r,u,h)},i.CreateTube=function(t,r,i,n,s,o,a,h,c,l){var u={path:r,radius:i,tessellation:n,radiusFunction:s,arc:1,cap:o,updatable:h,sideOrientation:c,instance:l};return e.MeshBuilder.CreateTube(t,u,a)},i.CreatePolyhedron=function(t,r,i){return e.MeshBuilder.CreatePolyhedron(t,r,i)},i.CreateIcoSphere=function(t,r,i){return e.MeshBuilder.CreateIcoSphere(t,r,i)},i.CreateDecal=function(t,r,i,n,s,o){var a={position:i,normal:n,size:s,angle:o};return e.MeshBuilder.CreateDecal(t,r,a)},i.prototype.setPositionsForCPUSkinning=function(){var t;return this._sourcePositions||(t=this.getVerticesData(e.VertexBuffer.PositionKind),this._sourcePositions=new Float32Array(t),this.getVertexBuffer(e.VertexBuffer.PositionKind).isUpdatable()||this.setVerticesData(e.VertexBuffer.PositionKind,t,!0)),this._sourcePositions},i.prototype.setNormalsForCPUSkinning=function(){var t;return this._sourceNormals||(t=this.getVerticesData(e.VertexBuffer.NormalKind),this._sourceNormals=new Float32Array(t),this.getVertexBuffer(e.VertexBuffer.NormalKind).isUpdatable()||this.setVerticesData(e.VertexBuffer.NormalKind,t,!0)),this._sourceNormals},i.prototype.applySkeleton=function(t){if(this.geometry&&this.geometry._softwareSkinningRenderId!=this.getScene().getRenderId()){if(this.geometry._softwareSkinningRenderId=this.getScene().getRenderId(),!this.isVerticesDataPresent(e.VertexBuffer.PositionKind))return this;if(!this.isVerticesDataPresent(e.VertexBuffer.NormalKind))return this;if(!this.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind))return this;if(!this.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind))return this;this._sourcePositions||this.setPositionsForCPUSkinning(),this._sourceNormals||this.setNormalsForCPUSkinning();var r=this.getVerticesData(e.VertexBuffer.PositionKind);r instanceof Float32Array||(r=new Float32Array(r));var i=this.getVerticesData(e.VertexBuffer.NormalKind);i instanceof Float32Array||(i=new Float32Array(i));for(var n,s=this.getVerticesData(e.VertexBuffer.MatricesIndicesKind),o=this.getVerticesData(e.VertexBuffer.MatricesWeightsKind),a=this.numBoneInfluencers>4,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;m<r.length;m+=3,p+=4){var g;for(n=0;4>n&&(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;o<t.length;o++)if(t[o]&&(a+=t[o].getTotalVertices(),a>65536))return e.Tools.Warn("Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices"),null}var h,c,l;for(o=0;o<t.length;o++)t[o]&&(t[o].computeWorldMatrix(!0),c=e.VertexData.ExtractFromMesh(t[o],!0),c.transform(t[o].getWorldMatrix()),h?h.merge(c):(h=c,l=t[o]));if(s||(s=new i(l.name+"_merged",l.getScene())),h.applyToMesh(s),s.material=l.material,s.checkCollisions=l.checkCollisions,r)for(o=0;o<t.length;o++)t[o]&&t[o].dispose();return s},i._FRONTSIDE=0,i._BACKSIDE=1,i._DOUBLESIDE=2,i._DEFAULTSIDE=0,i._NO_CAP=0,i._CAP_START=1,i._CAP_END=2,i._CAP_ALL=3,i}(e.AbstractMesh);e.Mesh=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,r,i,n,s,o,a){void 0===a&&(a=!0),this.materialIndex=e,this.verticesStart=t,this.verticesCount=r,this.indexStart=i,this.indexCount=n,this._renderId=0,this._mesh=s,this._renderingMesh=o||s,s.subMeshes.push(this),this._trianglePlanes=[],this._id=s.subMeshes.length-1,a&&(this.refreshBoundingInfo(),s.computeWorldMatrix(!0))}return Object.defineProperty(t.prototype,"IsGlobal",{get:function(){return 0===this.verticesStart&&this.verticesCount==this._mesh.getTotalVertices()},enumerable:!0,configurable:!0}),t.prototype.getBoundingInfo=function(){return this.IsGlobal?this._mesh.getBoundingInfo():this._boundingInfo},t.prototype.getMesh=function(){return this._mesh},t.prototype.getRenderingMesh=function(){return this._renderingMesh},t.prototype.getMaterial=function(){var t=this._renderingMesh.material;if(t&&t instanceof e.MultiMaterial){var r=t;return r.getSubMaterial(this.materialIndex)}return t?t:this._mesh.getScene().defaultMaterial},t.prototype.refreshBoundingInfo=function(){if(!this.IsGlobal){var t=this._renderingMesh.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return void(this._boundingInfo=this._mesh._boundingInfo);var r,i=this._renderingMesh.getIndices();r=0===this.indexStart&&this.indexCount===i.length?{minimum:this._renderingMesh.getBoundingInfo().minimum.clone(),maximum:this._renderingMesh.getBoundingInfo().maximum.clone()}:e.Tools.ExtractMinAndMaxIndexed(t,i,this.indexStart,this.indexCount),this._boundingInfo=new e.BoundingInfo(r.minimum,r.maximum)}},t.prototype._checkCollision=function(e){return this.getBoundingInfo()._checkCollision(e)},t.prototype.updateBoundingInfo=function(e){this.getBoundingInfo()||this.refreshBoundingInfo(),this.getBoundingInfo().update(e)},t.prototype.isInFrustum=function(e){return this.getBoundingInfo().isInFrustum(e)},t.prototype.render=function(e){this._renderingMesh.render(this,e)},t.prototype.getLinesIndexBuffer=function(e,t){if(!this._linesIndexBuffer){for(var r=[],i=this.indexStart;i<this.indexStart+this.indexCount;i+=3)r.push(e[i],e[i+1],e[i+1],e[i+2],e[i+2],e[i]);this._linesIndexBuffer=t.createIndexBuffer(r),this.linesIndexCount=r.length}return this._linesIndexBuffer},t.prototype.canIntersects=function(e){return e.intersectsBox(this.getBoundingInfo().boundingBox)},t.prototype.intersects=function(e,t,r,i){for(var n=null,s=this.indexStart;s<this.indexStart+this.indexCount;s+=3){var o=t[r[s]],a=t[r[s+1]],h=t[r[s+2]],c=e.intersectsTriangle(o,a,h);if(c){if(c.distance<0)continue;if((i||!n||c.distance<n.distance)&&(n=c,n.faceId=s/3,i))break}}return n},t.prototype.clone=function(r,i){var n=new t(this.materialIndex,this.verticesStart,this.verticesCount,this.indexStart,this.indexCount,r,i,!1);return this.IsGlobal||(n._boundingInfo=new e.BoundingInfo(this.getBoundingInfo().minimum,this.getBoundingInfo().maximum)),n},t.prototype.dispose=function(){this._linesIndexBuffer&&(this._mesh.getScene().getEngine()._releaseBuffer(this._linesIndexBuffer),this._linesIndexBuffer=null);var e=this._mesh.subMeshes.indexOf(this);this._mesh.subMeshes.splice(e,1)},t.CreateFromIndices=function(e,r,i,n,s){var o=Number.MAX_VALUE,a=-Number.MAX_VALUE;s=s||n;for(var h=s.getIndices(),c=r;r+i>c;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;a<n.length;a++){var c=n[a],l=c.length;r=l>r?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;g<n.length;g++)p=3*h._idx[g],m=g+1<n.length?3*(h._idx[g+1]-1):d.length-3,d[p]=.5*(d[p]+d[m]),d[p+1]=.5*(d[p+1]+d[m+1]),d[p+2]=.5*(d[p+2]+d[m+2]),d[m]=d[p],d[m+1]=d[p+1],d[m+2]=d[p+2];h.updateVerticesData(e.VertexBuffer.NormalKind,d,!1,!1)}return h}var _=new e.Mesh(t,i);_.sideOrientation=a;var v=e.VertexData.CreateRibbon(r);return o&&(_._idx=v._idx),_._closePath=o,_._closeArray=s,v.applyToMesh(_,c),_},t.CreateCylinder=function(t,r,i){var n=new e.Mesh(t,i),s=e.VertexData.CreateCylinder(r);return s.applyToMesh(n,r.updatable),n},t.CreateTorus=function(t,r,i){var n=new e.Mesh(t,i),s=e.VertexData.CreateTorus(r);return s.applyToMesh(n,r.updatable),n},t.CreateTorusKnot=function(t,r,i){var n=new e.Mesh(t,i),s=e.VertexData.CreateTorusKnot(r);return s.applyToMesh(n,r.updatable),n},t.CreateLines=function(t,r,i){var n=r.instance,s=r.points;if(n){var o=function(e){for(var t=0,r=0;r<s.length;r++)e[t]=s[r].x,e[t+1]=s[r].y,e[t+2]=s[r].z,t+=3};return n.updateMeshPositions(o,!1),n}var a=new e.LinesMesh(t,i),h=e.VertexData.CreateLines(r);return h.applyToMesh(a,r.updatable),a},t.CreateDashedLines=function(t,r,i){var n=r.points,s=r.instance,o=r.gapSize,a=(r.dashNb,r.dashSize);if(s){var h=function(t){var r=e.Vector3.Zero(),i=t.length/6,o=0,a=0,h=0,c=0,l=0,u=0,f=0,d=0;for(f=0;f<n.length-1;f++)n[f+1].subtractToRef(n[f],r),o+=r.length();for(h=o/i,c=s.dashSize*h/(s.dashSize+s.gapSize),f=0;f<n.length-1;f++)for(n[f+1].subtractToRef(n[f],r),a=Math.floor(r.length()/h),r.normalize(),d=0;a>d&&u<t.length;)l=h*d,t[u]=n[f].x+l*r.x,t[u+1]=n[f].y+l*r.y,t[u+2]=n[f].z+l*r.z,t[u+3]=n[f].x+(l+c)*r.x,t[u+4]=n[f].y+(l+c)*r.y,t[u+5]=n[f].z+(l+c)*r.z,u+=6,d++;for(;u<t.length;)t[u]=n[f].x,t[u+1]=n[f].y,t[u+2]=n[f].z,u+=3};return s.updateMeshPositions(h,!1),s}var c=new e.LinesMesh(t,i),l=e.VertexData.CreateDashedLines(r);return l.applyToMesh(c,r.updatable),c.dashSize=a,c.gapSize=o,c},t.ExtrudeShape=function(r,i,n){var s=i.path,o=i.shape,a=i.scale||1,h=i.rotation||0,c=0===i.cap?0:i.cap||e.Mesh.NO_CAP,l=i.updatable,u=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,f=i.instance;return t._ExtrudeShapeGeneric(r,o,s,a,h,null,null,!1,!1,c,!1,n,l,u,f)},t.ExtrudeShapeCustom=function(r,i,n){var s=i.path,o=i.shape,a=i.scaleFunction||function(){return 1},h=i.rotationFunction||function(){return 0},c=i.ribbonCloseArray||!1,l=i.ribbonClosePath||!1,u=0===i.cap?0:i.cap||e.Mesh.NO_CAP,f=i.updatable,d=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,p=i.instance;return t._ExtrudeShapeGeneric(r,o,s,null,null,a,h,c,l,u,!0,n,f,d,p)},t.CreateLathe=function(r,i,n){var s,o=i.arc<=0||i.arc>1?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;_<h.length;_++)s=new e.Vector3(Math.cos(g*v)*h[_].x*c,h[_].y,Math.sin(g*v)*h[_].x*c),y.push(s);(d==e.Mesh.CAP_END||d==e.Mesh.CAP_ALL)&&(y.push(new e.Vector3(Math.cos(g*v)*h[h.length-1].x*c,h[h.length-1].y,Math.sin(g*v)*h[h.length-1].x*c)),y.push(new e.Vector3(0,h[h.length-1].y,0))),m.push(y)}var x=t.CreateRibbon(r,{pathArray:m,closeArray:a,sideOrientation:f,updatable:u},n);return x},t.CreatePlane=function(t,r,i){var n=new e.Mesh(t,i),s=e.VertexData.CreatePlane(r);if(s.applyToMesh(n,r.updatable),r.sourcePlane){n.translate(r.sourcePlane.normal,r.sourcePlane.d);var o=Math.acos(e.Vector3.Dot(r.sourcePlane.normal,e.Axis.Z)),a=e.Vector3.Cross(e.Axis.Z,r.sourcePlane.normal);n.rotate(a,o)}return n},t.CreateGround=function(t,r,i){var n=new e.GroundMesh(t,i);n._setReady(!1),n._subdivisions=r.subdivisions||1,n._width=r.width||1,n._height=r.height||1,n._maxX=n._width/2,n._maxZ=n._height/2,n._minX=-n._maxX,n._minZ=-n._maxZ;var s=e.VertexData.CreateGround(r);return s.applyToMesh(n,r.updatable),n._setReady(!0),n},t.CreateTiledGround=function(t,r,i){var n=new e.Mesh(t,i),s=e.VertexData.CreateTiledGround(r);return s.applyToMesh(n,r.updatable),n},t.CreateGroundFromHeightMap=function(t,r,i,n){var s=i.width||10,o=i.height||10,a=i.subdivisions||1,h=i.minHeight,c=i.maxHeight||10,l=i.updatable,u=i.onReady,f=new e.GroundMesh(t,n);f._subdivisions=a,f._width=s,f._height=o,f._maxX=f._width/2,f._maxZ=f._height/2,f._minX=-f._maxX,f._minZ=-f._maxZ,f._setReady(!1);var d=function(t){var r=document.createElement("canvas"),i=r.getContext("2d"),n=t.width,d=t.height;r.width=n,r.height=d,i.drawImage(t,0,0);var p=i.getImageData(0,0,n,d).data,m=e.VertexData.CreateGroundFromHeightMap({width:s,height:o,subdivisions:a,minHeight:h,maxHeight:c,buffer:p,bufferWidth:n,bufferHeight:d});m.applyToMesh(f,l),f._setReady(!0),u&&u(f)};return e.Tools.LoadImage(r,d,function(){},n.database),f},t.CreateTube=function(r,i,n){var s=i.path,o=i.radius||1,a=i.tessellation||64,h=i.radiusFunction,c=i.cap||e.Mesh.NO_CAP,l=i.updatable,u=i.sideOrientation||e.Mesh.DEFAULTSIDE,f=i.instance;i.arc=i.arc<=0||i.arc>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;T<t.length;T++){l=y(T,m[T]),c=Array(),u=p[T];for(var A=0;s>A;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;o<t.length;o+=3){var a,h,l,u,f,d,p,m=0,g=e.Vector3.Dot(t[o].position,r)-i,_=e.Vector3.Dot(t[o+1].position,r)-i,v=e.Vector3.Dot(t[o+2].position,r)-i;switch(a=g>0,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;M<n.length;M+=3){var P=new Array;if(P.push(A(M)),P.push(A(M+1)),P.push(A(M+2)),P=b(P,new e.Vector3(1,0,0)),P=b(P,new e.Vector3(-1,0,0)),P=b(P,new e.Vector3(0,1,0)),P=b(P,new e.Vector3(0,-1,0)),P=b(P,new e.Vector3(0,0,1)),P=b(P,new e.Vector3(0,0,-1)),0!==P.length)for(var S=0;S<P.length;S++){var C=P[S];E.indices.push(T),C.position.toArray(E.positions,3*T),C.normal.toArray(E.normals,3*T),E.uvs.push(.5+C.position.x/c.x),E.uvs.push(.5+C.position.y/c.y),T++}}var I=new e.Mesh(t,r.getScene());return E.applyToMesh(I),I.position=a.clone(),I.rotation=new e.Vector3(g,p,l),I},t._ExtrudeShapeGeneric=function(t,r,i,n,s,o,a,h,c,l,u,f,d,p,m){var g,_,v=function(t,r,i,n,s,o,a,h,c,l){for(var u=i.getTangents(),f=i.getNormals(),d=i.getBinormals(),p=i.getDistances(),m=0,g=function(){return s},_=function(){return o},v=l?h:_,y=l?a:g,x=c===e.Mesh.NO_CAP||c===e.Mesh.CAP_END?0:2,E=e.Tmp.Matrix[0],T=0;T<r.length;T++){for(var A=new Array,b=v(T,p[T]),M=y(T,p[T]),P=0;P<t.length;P++){e.Matrix.RotationAxisToRef(u[T],m,E);var S=u[T].scale(t[P].z).add(f[T].scale(t[P].x)).add(d[T].scale(t[P].y)),C=A[P]?A[P]:e.Vector3.Zero();e.Vector3.TransformCoordinatesToRef(S,E,C),C.scaleInPlace(M).addInPlace(r[T]),A[P]=C}n[x]=A,m+=b,x++}var I=function(t){var r,i=Array(),n=e.Vector3.Zero();for(r=0;r<t.length;r++)n.addInPlace(t[r]);for(n.scaleInPlace(1/t.length),r=0;r<t.length;r++)i.push(n);return i};switch(c){case e.Mesh.NO_CAP:break;case e.Mesh.CAP_START:n[0]=I(n[2]),n[1]=n[2].slice(0);break;case e.Mesh.CAP_END:n[x]=n[x-1],n[x+1]=I(n[x-1]);break;case e.Mesh.CAP_ALL:n[0]=I(n[2]),n[1]=n[2].slice(0),n[x]=n[x-1],n[x+1]=I(n[x-1])}return n};if(m)return g=m.path3D.update(i),_=v(r,i,m.path3D,m.pathArray,n,s,o,a,m.cap,u),m=e.Mesh.CreateRibbon(null,_,null,null,null,null,null,null,m);g=new e.Path3D(i);var y=new Array;l=0>l||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<r.length;i++){var n=r[i];if(n.url===e&&n.noMipmap===t)return void r.splice(i,1)}},t.prototype._getFromCache=function(e,t,r){for(var i=this._scene.getEngine().getLoadedTexturesCache(),n=0;n<i.length;n++){var s=i[n];if(s.url===e&&s.noMipmap===t&&(!r||r===s.samplingMode))return s.references++,s}return null},t.prototype.delayLoad=function(){},t.prototype.clone=function(){return null},t.prototype.releaseInternalTexture=function(){this._texture&&(this._scene.getEngine().releaseInternalTexture(this._texture),delete this._texture)},t.prototype.dispose=function(){this.getScene().stopAnimation(this);var e=this._scene.textures.indexOf(this);e>=0&&this._scene.textures.splice(e,1),void 0!==this._texture&&(this.releaseInternalTexture(),this.onDispose&&this.onDispose())},t.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),
  12. 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;o<t.animations.length;o++){var a=t.animations[o];s.animations.push(e.Animation.Parse(a))}return s},r.NEAREST_SAMPLINGMODE=1,r.BILINEAR_SAMPLINGMODE=2,r.TRILINEAR_SAMPLINGMODE=3,r.EXPLICIT_MODE=0,r.SPHERICAL_MODE=1,r.PLANAR_MODE=2,r.CUBIC_MODE=3,r.PROJECTION_MODE=4,r.SKYBOX_MODE=5,r.INVCUBIC_MODE=6,r.EQUIRECTANGULAR_MODE=7,r.FIXED_EQUIRECTANGULAR_MODE=8,r.CLAMP_ADDRESSMODE=0,r.WRAP_ADDRESSMODE=1,r.MIRROR_ADDRESSMODE=2,r}(e.BaseTexture);e.Texture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i,n,s,o){if(t.call(this,i),this.coordinatesMode=e.Texture.CUBIC_MODE,this.name=r,this.url=r,this._noMipmap=s,this.hasAlpha=!1,r||o){if(this._texture=this._getFromCache(r,s),!o){n||(n=["_px.jpg","_py.jpg","_pz.jpg","_nx.jpg","_ny.jpg","_nz.jpg"]),o=[];for(var a=0;a<n.length;a++)o.push(r+n[a]);this._extensions=n}this._files=o,this._texture||(i.useDelayedTextureLoading?this.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:this._texture=i.getEngine().createCubeTexture(r,i,o,s)),this.isCube=!0,this._textureMatrix=e.Matrix.Identity()}}return __extends(r,t),r.CreateFromImages=function(e,t,i){return new r("",t,null,i,e)},r.prototype.clone=function(){var e=new r(this.url,this.getScene(),this._extensions,this._noMipmap,this._files);return e.level=this.level,e.wrapU=this.wrapU,e.wrapV=this.wrapV,e.coordinatesIndex=this.coordinatesIndex,e.coordinatesMode=this.coordinatesMode,e},r.prototype.delayLoad=function(){this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap),this._texture||(this._texture=this.getScene().getEngine().createCubeTexture(this.url,this.getScene(),this._extensions)))},r.prototype.getReflectionTextureMatrix=function(){return this._textureMatrix},r.Parse=function(t,r,i){var n=null;return!t.name&&!t.extensions||t.isRenderTarget||(n=new e.CubeTexture(i+t.name,r,t.extensions),n.name=t.name,n.hasAlpha=t.hasAlpha,n.level=t.level,n.coordinatesMode=t.coordinatesMode),n},r.prototype.serialize=function(){if(!this.name)return null;var e={};return e.name=this.name,e.hasAlpha=this.hasAlpha,e.isCube=!0,e.level=this.level,e.coordinatesMode=this.coordinatesMode,e},r}(e.BaseTexture);e.CubeTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i,n,s,o,a,h){void 0===o&&(o=!0),void 0===a&&(a=e.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===h&&(h=!1),t.call(this,null,n,!s),this.isCube=h,this.renderList=new Array,this.renderParticles=!0,this.renderSprites=!1,this.coordinatesMode=e.Texture.PROJECTION_MODE,this._currentRefreshId=-1,this._refreshRate=1,this.name=r,this.isRenderTarget=!0,this._size=i,this._generateMipMaps=s,this._doNotChangeAspectRatio=o,h?(this._texture=n.getEngine().createRenderTargetCubeTexture(i,{generateMipMaps:s}),this.coordinatesMode=e.Texture.INVCUBIC_MODE,this._textureMatrix=e.Matrix.Identity()):this._texture=n.getEngine().createRenderTargetTexture(i,{generateMipMaps:s,type:a}),this._renderingManager=new e.RenderingManager(n)}return __extends(r,t),Object.defineProperty(r,"REFRESHRATE_RENDER_ONCE",{get:function(){return r._REFRESHRATE_RENDER_ONCE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"REFRESHRATE_RENDER_ONEVERYFRAME",{get:function(){return r._REFRESHRATE_RENDER_ONEVERYFRAME},enumerable:!0,configurable:!0}),Object.defineProperty(r,"REFRESHRATE_RENDER_ONEVERYTWOFRAMES",{get:function(){return r._REFRESHRATE_RENDER_ONEVERYTWOFRAMES},enumerable:!0,configurable:!0}),r.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},Object.defineProperty(r.prototype,"refreshRate",{get:function(){return this._refreshRate},set:function(e){this._refreshRate=e,this.resetRefreshCounter()},enumerable:!0,configurable:!0}),r.prototype._shouldRender=function(){return-1===this._currentRefreshId?(this._currentRefreshId=1,!0):this.refreshRate===this._currentRefreshId?(this._currentRefreshId=1,!0):(this._currentRefreshId++,!1)},r.prototype.isReady=function(){return this.getScene().renderTargetsEnabled?t.prototype.isReady.call(this):!1},r.prototype.getRenderSize=function(){return this._size},Object.defineProperty(r.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),r.prototype.scale=function(e){var t=this._size*e;this.resize(t,this._generateMipMaps)},r.prototype.getReflectionTextureMatrix=function(){return this.isCube?this._textureMatrix:t.prototype.getReflectionTextureMatrix.call(this)},r.prototype.resize=function(e,t){this.releaseInternalTexture(),this.isCube?this._texture=this.getScene().getEngine().createRenderTargetCubeTexture(e):this._texture=this.getScene().getEngine().createRenderTargetTexture(e,t)},r.prototype.render=function(e,t){var r=this.getScene();if(this.activeCamera&&this.activeCamera!==r.activeCamera&&r.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(!0)),this._waitingRenderList){this.renderList=[];for(var i=0;i<this._waitingRenderList.length;i++){var n=this._waitingRenderList[i];this.renderList.push(r.getMeshByID(n))}delete this._waitingRenderList}if(!this.renderList||0!==this.renderList.length){this._renderingManager.reset();for(var s=this.renderList?this.renderList:r.getActiveMeshes().data,o=0;o<s.length;o++){var a=s[o];if(a){if(!a.isReady()){this.resetRefreshCounter();continue}if(a.isEnabled()&&a.isVisible&&a.subMeshes&&0!==(a.layerMask&r.activeCamera.layerMask)){a._activate(r.getRenderId());for(var h=0;h<a.subMeshes.length;h++){var c=a.subMeshes[h];r._activeIndices+=c.indexCount,this._renderingManager.dispatch(c)}}}}if(this.isCube)for(var l=0;6>l;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;r<this.renderList.length;r++)e.renderList.push(this.renderList[r].id);return e},r._REFRESHRATE_RENDER_ONCE=0,r._REFRESHRATE_RENDER_ONEVERYFRAME=1,r._REFRESHRATE_RENDER_ONEVERYTWOFRAMES=2,r}(e.Texture);e.RenderTargetTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,r,i,n,s,o,a){void 0===o&&(o=!0),void 0===a&&(a=!1),e.call(this,null,n,!o),this.isCube=a,this.isEnabled=!0,this._currentRefreshId=-1,this._refreshRate=1,this._vertexDeclaration=[2],this._vertexStrideSize=8,this._uniforms=new Array,this._samplers=new Array,this._textures=new Array,this._floats=new Array,this._floatsArrays={},this._colors3=new Array,this._colors4=new Array,this._vectors2=new Array,this._vectors3=new Array,this._matrices=new Array,this._fallbackTextureUsed=!1,n._proceduralTextures.push(this),this.name=t,this.isRenderTarget=!0,this._size=r,this._generateMipMaps=o,this.setFragment(i),this._fallbackTexture=s,a?(this._texture=n.getEngine().createRenderTargetCubeTexture(r,{generateMipMaps:o}),this.setFloat("face",0)):this._texture=n.getEngine().createRenderTargetTexture(r,o);var h=[];h.push(1,1),h.push(-1,1),h.push(-1,-1),h.push(1,-1),this._vertexBuffer=n.getEngine().createVertexBuffer(h);var c=[];c.push(0),c.push(1),c.push(2),c.push(0),c.push(2),c.push(3),this._indexBuffer=n.getEngine().createIndexBuffer(c)}return __extends(t,e),t.prototype.reset=function(){if(void 0!==this._effect){var e=this.getScene().getEngine();e._releaseEffect(this._effect)}},t.prototype.isReady=function(){var e,t=this,r=this.getScene().getEngine();return this._fragment?this._fallbackTextureUsed?!0:(e=void 0!==this._fragment.fragmentElement?{vertex:"procedural",fragmentElement:this._fragment.fragmentElement}:{vertex:"procedural",fragment:this._fragment},this._effect=r.createEffect(e,["position"],this._uniforms,this._samplers,"",null,null,function(){t.releaseInternalTexture(),t._fallbackTexture&&(t._texture=t._fallbackTexture._texture,t._texture.references++),t._fallbackTextureUsed=!0}),this._effect.isReady()):!1},t.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},t.prototype.setFragment=function(e){this._fragment=e},Object.defineProperty(t.prototype,"refreshRate",{get:function(){return this._refreshRate},set:function(e){this._refreshRate=e,this.resetRefreshCounter()},enumerable:!0,configurable:!0}),t.prototype._shouldRender=function(){return this.isEnabled&&this.isReady()&&this._texture?this._fallbackTextureUsed?!1:-1===this._currentRefreshId?(this._currentRefreshId=1,!0):this.refreshRate===this._currentRefreshId?(this._currentRefreshId=1,!0):(this._currentRefreshId++,!1):!1},t.prototype.getRenderSize=function(){return this._size},t.prototype.resize=function(e,t){this._fallbackTextureUsed||(this.releaseInternalTexture(),this._texture=this.getScene().getEngine().createRenderTargetTexture(e,t))},t.prototype._checkUniform=function(e){-1===this._uniforms.indexOf(e)&&this._uniforms.push(e)},t.prototype.setTexture=function(e,t){return-1===this._samplers.indexOf(e)&&this._samplers.push(e),this._textures[e]=t,this},t.prototype.setFloat=function(e,t){return this._checkUniform(e),this._floats[e]=t,this},t.prototype.setFloats=function(e,t){return this._checkUniform(e),this._floatsArrays[e]=t,this},t.prototype.setColor3=function(e,t){return this._checkUniform(e),this._colors3[e]=t,this},t.prototype.setColor4=function(e,t){return this._checkUniform(e),this._colors4[e]=t,this},t.prototype.setVector2=function(e,t){return this._checkUniform(e),this._vectors2[e]=t,this},t.prototype.setVector3=function(e,t){return this._checkUniform(e),this._vectors3[e]=t,this},t.prototype.setMatrix=function(e,t){return this._checkUniform(e),this._matrices[e]=t,this},t.prototype.render=function(e){var t=this.getScene(),r=t.getEngine();r.enableEffect(this._effect),r.setState(!1);for(var i in this._textures)this._effect.setTexture(i,this._textures[i]);for(i in this._floats)this._effect.setFloat(i,this._floats[i]);for(i in this._floatsArrays)this._effect.setArray(i,this._floatsArrays[i]);for(i in this._colors3)this._effect.setColor3(i,this._colors3[i]);for(i in this._colors4){var n=this._colors4[i];this._effect.setFloat4(i,n.r,n.g,n.b,n.a)}for(i in this._vectors2)this._effect.setVector2(i,this._vectors2[i]);for(i in this._vectors3)this._effect.setVector3(i,this._vectors3[i]);for(i in this._matrices)this._effect.setMatrix(i,this._matrices[i]);if(r.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,this._effect),this.isCube)for(var s=0;6>s;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;t<this._config.sampler2Ds.length;t++)this.setTexture(this._config.sampler2Ds[t].sample2Dname,new e.Texture(this._texturePath+"/"+this._config.sampler2Ds[t].textureRelativeUrl,this.getScene()))},r.prototype.updateShaderUniforms=function(){if(this._config)for(var t=0;t<this._config.uniforms.length;t++){var r=this._config.uniforms[t];switch(r.type){case"float":this.setFloat(r.name,r.value);break;case"color3":this.setColor3(r.name,new e.Color3(r.r,r.g,r.b));break;case"color4":this.setColor4(r.name,new e.Color4(r.r,r.g,r.b,r.a));break;case"vector2":this.setVector2(r.name,new e.Vector2(r.x,r.y));break;case"vector3":this.setVector3(r.name,new e.Vector3(r.x,r.y,r.z))}}this.setFloat("time",this._time)},Object.defineProperty(r.prototype,"animate",{get:function(){return this._animate},set:function(e){this._animate=e},enumerable:!0,configurable:!0}),r}(e.ProceduralTexture);e.CustomProceduralTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this._defines={},this._currentRank=32,this._maxRank=-1}return t.prototype.addFallback=function(e,t){this._defines[e]||(e<this._currentRank&&(this._currentRank=e),e>this._maxRank&&(this._maxRank=e),this._defines[e]=new Array),this._defines[e].push(t)},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<r.length;i++)t=t.replace("#define "+r[i],"");return this._mesh&&this._currentRank===this._meshRank&&(this._mesh.computeBonesUsingShaders=!1,t=t.replace("#define NUM_BONE_INFLUENCERS "+this._mesh.numBoneInfluencers,"#define NUM_BONE_INFLUENCERS 0"),e.Tools.Log("Falling back to CPU skinning for "+this._mesh.name)),this._currentRank++,t},t}();e.EffectFallbacks=t;var r=function(){function t(e,t,r,i,n,s,o,a,h){var c=this;this._isReady=!1,this._compilationError="",this._valueCache=[],this._engine=n,this.name=e,this.defines=s,this._uniformsNames=r.concat(i),this._samplers=i,this._attributesNames=t,this.onError=h,this.onCompiled=a;var l,u;e.vertexElement?(l=document.getElementById(e.vertexElement),l||(l=e.vertexElement)):l=e.vertex||e,e.fragmentElement?(u=document.getElementById(e.fragmentElement),u||(u=e.fragmentElement)):u=e.fragment||e,this._loadVertexShader(l,function(e){c._loadFragmentShader(u,function(r){c._prepareEffect(e,r,t,s,o)})})}return t.prototype.isReady=function(){return this._isReady},t.prototype.getProgram=function(){return this._program},t.prototype.getAttributesNames=function(){return this._attributesNames},t.prototype.getAttributeLocation=function(e){return this._attributes[e]},t.prototype.getAttributeLocationByName=function(e){var t=this._attributesNames.indexOf(e);return this._attributes[t]},t.prototype.getAttributesCount=function(){return this._attributes.length},t.prototype.getUniformIndex=function(e){return this._uniformsNames.indexOf(e)},t.prototype.getUniform=function(e){return this._uniforms[this._uniformsNames.indexOf(e)]},t.prototype.getSamplers=function(){return this._samplers},t.prototype.getCompilationError=function(){return this._compilationError},t.prototype._loadVertexShader=function(r,i){if(r instanceof HTMLElement){var n=e.Tools.GetDOMTextContent(r);return void i(n)}if(t.ShadersStore[r+"VertexShader"])return void i(t.ShadersStore[r+"VertexShader"]);var s;s="."===r[0]||"/"===r[0]||r.indexOf("http")>-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;a<this._samplers.length;a++){var h=this.getUniform(this._samplers[a]);null==h&&(this._samplers.splice(a,1),a--)}o.bindSamplers(this),this._isReady=!0,this.onCompiled&&this.onCompiled(this)}catch(c){if(-1!==c.message.indexOf("highp"))return t=t.replace("precision highp float","precision mediump float"),r=r.replace("precision highp float","precision mediump float"),void this._prepareEffect(t,r,i,n,s);s&&s.isMoreFallbacks?(e.Tools.Error("Unable to compile effect with current defines. Trying next fallback."),this._dumpShadersName(),n=s.reduce(n),this._prepareEffect(t,r,i,n,s)):(e.Tools.Error("Unable to compile effect: "),this._dumpShadersName(),e.Tools.Error("Defines: "+n),e.Tools.Error("Error: "+c.message),this._compilationError=c.message,this.onError&&this.onError(this,this._compilationError))}},Object.defineProperty(t.prototype,"isSupported",{get:function(){return""===this._compilationError},enumerable:!0,configurable:!0}),t.prototype._bindTexture=function(e,t){this._engine._bindTexture(this._samplers.indexOf(e),t)},t.prototype.setTexture=function(e,t){this._engine.setTexture(this._samplers.indexOf(e),t)},t.prototype.setTextureFromPostProcess=function(e,t){this._engine.setTextureFromPostProcess(this._samplers.indexOf(e),t)},t.prototype._cacheMatrix=function(t,r){this._valueCache[t]||(this._valueCache[t]=new e.Matrix);for(var i=0;16>i;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<this._keys.length;t++){var r=this._keys[t];if(this[r]!==e[r])return!1}return!0},e.prototype.cloneTo=function(e){for(var t=0;t<this._keys.length;t++){var r=this._keys[t];e[r]=this[r]}},e.prototype.reset=function(){for(var e=0;e<this._keys.length;e++){var t=this._keys[e];"number"==typeof this[t]?this[t]=0:this[t]=!1}},e.prototype.toString=function(){for(var e="",t=0;t<this._keys.length;t++){var r=this._keys[t];"number"==typeof this[r]?e+="#define "+r+" "+this[r]+"\n":this[r]&&(e+="#define "+r+"\n")}return e},e}();e.MaterialDefines=t;var r=function(){function t(r,i,n){this.name=r,this.checkReadyOnEveryCall=!1,this.checkReadyOnlyOnce=!1,this.state="",this.alpha=1,this.backFaceCulling=!0,this.sideOrientation=t.CounterClockWiseSideOrientation,this.alphaMode=e.Engine.ALPHA_COMBINE,this.disableDepthWrite=!1,this.fogEnabled=!0,this._wasPreviouslyReady=!1,this._fillMode=t.TriangleFillMode,this.pointSize=1,this.zOffset=0,this.id=r,this._scene=i,n||i.materials.push(this)}return Object.defineProperty(t,"TriangleFillMode",{get:function(){return t._TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"WireFrameFillMode",{get:function(){return t._WireFrameFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PointFillMode",{get:function(){return t._PointFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ClockWiseSideOrientation",{get:function(){return t._ClockWiseSideOrientation},enumerable:!0,configurable:!0}),Object.defineProperty(t,"CounterClockWiseSideOrientation",{get:function(){return t._CounterClockWiseSideOrientation},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"wireframe",{get:function(){return this._fillMode===t.WireFrameFillMode},set:function(e){this._fillMode=e?t.WireFrameFillMode:t.TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pointsCloud",{get:function(){return this._fillMode===t.PointFillMode},set:function(e){this._fillMode=e?t.PointFillMode:t.TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fillMode",{get:function(){return this._fillMode},set:function(e){this._fillMode=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isFrozen",{get:function(){return this.checkReadyOnlyOnce},enumerable:!0,configurable:!0}),t.prototype.freeze=function(){this.checkReadyOnlyOnce=!0},t.prototype.unfreeze=function(){this.checkReadyOnlyOnce=!1},t.prototype.isReady=function(e,t){return!0},t.prototype.getEffect=function(){return this._effect},t.prototype.getScene=function(){return this._scene},t.prototype.needAlphaBlending=function(){return this.alpha<1},t.prototype.needAlphaTesting=function(){return!1},t.prototype.getAlphaTestTexture=function(){return null},t.prototype.trackCreation=function(e,t){},t.prototype.markDirty=function(){this._wasPreviouslyReady=!1},t.prototype._preBind=function(){var e=this._scene.getEngine();e.enableEffect(this._effect),e.setState(this.backFaceCulling,this.zOffset,!1,this.sideOrientation===t.ClockWiseSideOrientation)},t.prototype.bind=function(e,t){if(this._scene._cachedMaterial=this,this.onBind&&this.onBind(this,t),this.disableDepthWrite){var r=this._scene.getEngine();this._cachedDepthWriteState=r.getDepthWrite(),
  13. r.setDepthWrite(!1)}},t.prototype.bindOnlyWorldMatrix=function(e){},t.prototype.unbind=function(){if(this.disableDepthWrite){var e=this._scene.getEngine();e.setDepthWrite(this._cachedDepthWriteState)}},t.prototype.clone=function(e){return null},t.prototype.getBindedMeshes=function(){for(var e=new Array,t=0;t<this._scene.meshes.length;t++){var r=this._scene.meshes[t];r.material===this&&e.push(r)}return e},t.prototype.dispose=function(e){this.getScene().stopAnimation(this);var t=this._scene.materials.indexOf(this);for(t>=0&&this._scene.materials.splice(t,1),e&&this._effect&&(this._scene.getEngine()._releaseEffect(this._effect),this._effect=null),t=0;t<this._scene.meshes.length;t++){var r=this._scene.meshes[t];r.material===this&&(r.material=null)}this.onDispose&&this.onDispose()},t.prototype.copyTo=function(e){e.checkReadyOnlyOnce=this.checkReadyOnlyOnce,e.checkReadyOnEveryCall=this.checkReadyOnEveryCall,e.alpha=this.alpha,e.fillMode=this.fillMode,e.backFaceCulling=this.backFaceCulling,e.fogEnabled=this.fogEnabled,e.wireframe=this.wireframe,e.zOffset=this.zOffset,e.alphaMode=this.alphaMode,e.sideOrientation=this.sideOrientation,e.disableDepthWrite=this.disableDepthWrite,e.pointSize=this.pointSize,e.pointsCloud=this.pointsCloud},t.prototype.serialize=function(){var t={};return t.name=this.name,t.alpha=this.alpha,t.id=this.id,t.tags=e.Tags.GetTags(this),t.backFaceCulling=this.backFaceCulling,t.checkReadyOnlyOnce=this.checkReadyOnlyOnce,t.disableDepthWrite=this.disableDepthWrite,t},t.ParseMultiMaterial=function(t,r){var i=new e.MultiMaterial(t.name,r);i.id=t.id,e.Tags.AddTagsTo(i,t.tags);for(var n=0;n<t.materials.length;n++){var s=t.materials[n];s?i.subMaterials.push(r.getMaterialByID(s)):i.subMaterials.push(null)}return i},t.Parse=function(t,r,i){if(!t.customType)return e.StandardMaterial.Parse(t,r,i);var n=e.Tools.Instantiate(t.customType);return n.Parse(t,r,i)},t._TriangleFillMode=0,t._WireFrameFillMode=1,t._PointFillMode=2,t._ClockWiseSideOrientation=0,t._CounterClockWiseSideOrientation=1,t}();e.Material=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=4,r=function(){function t(){this.isEnabled=!0,this.leftColor=e.Color3.White(),this.rightColor=e.Color3.Black(),this.bias=0,this.power=1}return t.prototype.clone=function(){var r=new t;return e.Tools.DeepCopy(this,r),new t},t.prototype.serialize=function(){var e={};return e.isEnabled=this.isEnabled,e.leftColor=this.leftColor,e.rightColor=this.rightColor,e.bias=this.bias,e.power=this.power,e},t.Parse=function(r){var i=new t;return i.isEnabled=r.isEnabled,i.leftColor=e.Color3.FromArray(r.leftColor),i.rightColor=e.Color3.FromArray(r.rightColor),i.bias=r.bias,i.power=r.power||1,i},t}();e.FresnelParameters=r;var i=function(e){function t(){e.call(this),this.DIFFUSE=!1,this.AMBIENT=!1,this.OPACITY=!1,this.OPACITYRGB=!1,this.REFLECTION=!1,this.EMISSIVE=!1,this.SPECULAR=!1,this.BUMP=!1,this.SPECULAROVERALPHA=!1,this.CLIPPLANE=!1,this.ALPHATEST=!1,this.ALPHAFROMDIFFUSE=!1,this.POINTSIZE=!1,this.FOG=!1,this.LIGHT0=!1,this.LIGHT1=!1,this.LIGHT2=!1,this.LIGHT3=!1,this.SPOTLIGHT0=!1,this.SPOTLIGHT1=!1,this.SPOTLIGHT2=!1,this.SPOTLIGHT3=!1,this.HEMILIGHT0=!1,this.HEMILIGHT1=!1,this.HEMILIGHT2=!1,this.HEMILIGHT3=!1,this.POINTLIGHT0=!1,this.POINTLIGHT1=!1,this.POINTLIGHT2=!1,this.POINTLIGHT3=!1,this.DIRLIGHT0=!1,this.DIRLIGHT1=!1,this.DIRLIGHT2=!1,this.DIRLIGHT3=!1,this.SPECULARTERM=!1,this.SHADOW0=!1,this.SHADOW1=!1,this.SHADOW2=!1,this.SHADOW3=!1,this.SHADOWS=!1,this.SHADOWVSM0=!1,this.SHADOWVSM1=!1,this.SHADOWVSM2=!1,this.SHADOWVSM3=!1,this.SHADOWPCF0=!1,this.SHADOWPCF1=!1,this.SHADOWPCF2=!1,this.SHADOWPCF3=!1,this.DIFFUSEFRESNEL=!1,this.OPACITYFRESNEL=!1,this.REFLECTIONFRESNEL=!1,this.EMISSIVEFRESNEL=!1,this.FRESNEL=!1,this.NORMAL=!1,this.UV1=!1,this.UV2=!1,this.VERTEXCOLOR=!1,this.VERTEXALPHA=!1,this.NUM_BONE_INFLUENCERS=0,this.BonesPerMesh=0,this.INSTANCES=!1,this.GLOSSINESS=!1,this.ROUGHNESS=!1,this.EMISSIVEASILLUMINATION=!1,this.LINKEMISSIVEWITHDIFFUSE=!1,this.REFLECTIONFRESNELFROMSPECULAR=!1,this.LIGHTMAP=!1,this.USELIGHTMAPASSHADOWMAP=!1,this.REFLECTIONMAP_3D=!1,this.REFLECTIONMAP_SPHERICAL=!1,this.REFLECTIONMAP_PLANAR=!1,this.REFLECTIONMAP_CUBIC=!1,this.REFLECTIONMAP_PROJECTION=!1,this.REFLECTIONMAP_SKYBOX=!1,this.REFLECTIONMAP_EXPLICIT=!1,this.REFLECTIONMAP_EQUIRECTANGULAR=!1,this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!1,this.INVERTCUBICMAP=!1,this.LOGARITHMICDEPTH=!1,this._keys=Object.keys(this)}return __extends(t,e),t}(e.MaterialDefines),n=function(n){function s(t,r){var s=this;n.call(this,t,r),this.ambientColor=new e.Color3(0,0,0),this.diffuseColor=new e.Color3(1,1,1),this.specularColor=new e.Color3(1,1,1),this.specularPower=64,this.emissiveColor=new e.Color3(0,0,0),this.useAlphaFromDiffuseTexture=!1,this.useEmissiveAsIllumination=!1,this.linkEmissiveWithDiffuse=!1,this.useReflectionFresnelFromSpecular=!1,this.useSpecularOverAlpha=!1,this.disableLighting=!1,this.roughness=0,this.useLightmapAsShadowmap=!1,this.useGlossinessFromSpecularMapAlpha=!1,this._renderTargets=new e.SmartArray(16),this._worldViewProjectionMatrix=e.Matrix.Zero(),this._globalAmbientColor=new e.Color3(0,0,0),this._defines=new i,this._cachedDefines=new i,this._cachedDefines.BonesPerMesh=-1,this.getRenderTargetTextures=function(){return s._renderTargets.reset(),s.reflectionTexture&&s.reflectionTexture.isRenderTarget&&s._renderTargets.push(s.reflectionTexture),s._renderTargets}}return __extends(s,n),Object.defineProperty(s.prototype,"useLogarithmicDepth",{get:function(){return this._useLogarithmicDepth},set:function(e){this._useLogarithmicDepth=e&&this.getScene().getEngine().getCaps().fragmentDepthSupported},enumerable:!0,configurable:!0}),s.prototype.needAlphaBlending=function(){return this.alpha<1||null!=this.opacityTexture||this._shouldUseAlphaFromDiffuseTexture()||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled},s.prototype.needAlphaTesting=function(){return null!=this.diffuseTexture&&this.diffuseTexture.hasAlpha},s.prototype._shouldUseAlphaFromDiffuseTexture=function(){return null!=this.diffuseTexture&&this.diffuseTexture.hasAlpha&&this.useAlphaFromDiffuseTexture},s.prototype.getAlphaTestTexture=function(){return this.diffuseTexture},s.prototype._checkCache=function(e,t,r){return t?this._defines.INSTANCES!==r?!1:t._materialDefines&&t._materialDefines.isEqual(this._defines)?!0:!1:!0},s.PrepareDefinesForLights=function(r,i,n){for(var s=0,o=!1,a=0;a<r.lights.length;a++){var h=r.lights[a];if(h.isEnabled()){if(h._excludedMeshesIds.length>0){for(var c=0;c<h._excludedMeshesIds.length;c++){var l=r.getMeshByID(h._excludedMeshesIds[c]);l&&h.excludedMeshes.push(l)}h._excludedMeshesIds=[]}if(h._includedOnlyMeshesIds.length>0){for(var u=0;u<h._includedOnlyMeshesIds.length;u++){var f=r.getMeshByID(h._includedOnlyMeshesIds[u]);f&&h.includedOnlyMeshes.push(f)}h._includedOnlyMeshesIds=[]}if(h.canAffectMesh(i)){o=!0,n["LIGHT"+s]=!0;var d;if(d=h instanceof e.SpotLight?"SPOTLIGHT"+s:h instanceof e.HemisphericLight?"HEMILIGHT"+s:h instanceof e.PointLight?"POINTLIGHT"+s:"DIRLIGHT"+s,n[d]=!0,h.specular.equalsFloats(0,0,0)||(n.SPECULARTERM=!0),r.shadowsEnabled){var p=h.getShadowGenerator();i&&i.receiveShadows&&p&&(n["SHADOW"+s]=!0,n.SHADOWS=!0,(p.useVarianceShadowMap||p.useBlurVarianceShadowMap)&&(n["SHADOWVSM"+s]=!0),p.usePoissonSampling&&(n["SHADOWPCF"+s]=!0))}if(s++,s===t)break}}}return o},s.BindLights=function(r,i,n,o){for(var a=0,h=!1,c=0;c<r.lights.length;c++){var l=r.lights[c];if(l.isEnabled()&&l.canAffectMesh(i)){if(l instanceof e.PointLight?l.transferToEffect(n,"vLightData"+a):l instanceof e.DirectionalLight?l.transferToEffect(n,"vLightData"+a):l instanceof e.SpotLight?l.transferToEffect(n,"vLightData"+a,"vLightDirection"+a):l instanceof e.HemisphericLight&&l.transferToEffect(n,"vLightData"+a,"vLightGround"+a),l.diffuse.scaleToRef(l.intensity,s._scaledDiffuse),n.setColor4("vLightDiffuse"+a,s._scaledDiffuse,l.range),o.SPECULARTERM&&(l.specular.scaleToRef(l.intensity,s._scaledSpecular),n.setColor3("vLightSpecular"+a,s._scaledSpecular)),r.shadowsEnabled){var u=l.getShadowGenerator();i.receiveShadows&&u&&(l.needCube()?h||(h=!0,n.setFloat2("depthValues",r.activeCamera.minZ,r.activeCamera.maxZ)):n.setMatrix("lightMatrix"+a,u.getTransformMatrix()),n.setTexture("shadowSampler"+a,u.getShadowMapForRendering()),n.setFloat3("shadowsInfo"+a,u.getDarkness(),u.blurScale/u.getShadowMap().getSize().width,u.bias))}if(a++,a===t)break}}},s.prototype.isReady=function(r,n){if(this.isFrozen&&this._wasPreviouslyReady)return!0;var o=this.getScene();if(!this.checkReadyOnEveryCall&&this._renderId===o.getRenderId()&&this._checkCache(o,r,n))return!0;var a=o.getEngine(),h=!1,c=!1;if(this._defines.reset(),o.texturesEnabled){if(this.diffuseTexture&&s.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;c=!0,this._defines.DIFFUSE=!0}if(this.ambientTexture&&s.AmbientTextureEnabled){if(!this.ambientTexture.isReady())return!1;c=!0,this._defines.AMBIENT=!0}if(this.opacityTexture&&s.OpacityTextureEnabled){if(!this.opacityTexture.isReady())return!1;c=!0,this._defines.OPACITY=!0,this.opacityTexture.getAlphaFromRGB&&(this._defines.OPACITYRGB=!0)}if(this.reflectionTexture&&s.ReflectionTextureEnabled){if(!this.reflectionTexture.isReady())return!1;switch(h=!0,this._defines.REFLECTION=!0,this.roughness>0&&(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;t<this.subMaterials.length;t++){var r=this.subMaterials[t];if(r&&!this.subMaterials[t].isReady(e))return!1}return!0},r.prototype.clone=function(e,t){for(var i=new r(e,this.getScene()),n=0;n<this.subMaterials.length;n++){var s=null;s=t?this.subMaterials[n].clone(e+"-"+this.subMaterials[n].name):this.subMaterials[n],i.subMaterials.push(s)}return i},r.prototype.serialize=function(){var t={};t.name=this.name,t.id=this.id,t.tags=e.Tags.GetTags(this),t.materials=[];for(var r=0;r<this.subMaterials.length;r++){var i=this.subMaterials[r];i?t.materials.push(i.id):t.materials.push(null)}return t},r}(e.Material);e.MultiMaterial=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return Object.defineProperty(t,"ForceFullSceneLoadingForIncremental",{get:function(){return t._ForceFullSceneLoadingForIncremental},set:function(e){t._ForceFullSceneLoadingForIncremental=e},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ShowLoadingScreen",{get:function(){return t._ShowLoadingScreen},set:function(e){t._ShowLoadingScreen=e},enumerable:!0,configurable:!0}),t._getPluginForFilename=function(e){var t=e.lastIndexOf("."),r=e.indexOf("?");-1===r&&(r=e.length);for(var i=e.substring(t,r).toLowerCase(),n=0;n<this._registeredPlugins.length;n++){var s=this._registeredPlugins[n];if(-1!==s.extensions.indexOf(i))return s}return this._registeredPlugins[this._registeredPlugins.length-1]},t.RegisterPlugin=function(e){e.extensions=e.extensions.toLowerCase(),t._registeredPlugins.push(e)},t.ImportMesh=function(r,i,n,s,o,a,h){if(n.substr&&"/"===n.substr(0,1))return void e.Tools.Error("Wrong sceneFilename parameter");var c={};s._addPendingData(c);var l=function(l){s.database=u;var f=t._getPluginForFilename(n),d=function(e){var t=[],a=[],l=[];try{if(!f.importMesh(r,s,e,i,t,a,l))return h&&h(s,"Unable to import meshes from "+i+n),void s._removePendingData(c)}catch(u){return h&&h(s,"Unable to import meshes from "+i+n+" (Exception: "+u+")"),void s._removePendingData(c)}o&&(s.importedMeshesFiles.push(i+n),o(t,a,l),s._removePendingData(c))};return n.substr&&"data:"===n.substr(0,5)?void d(n.substr(5)):void e.Tools.LoadFile(i+n,function(e){d(e)},a,u)};if(s.getEngine().enableOfflineSupport)var u=new e.Database(i+n,l);else l(!0)},t.Load=function(r,i,n,s,o,a){t.Append(r,i,new e.Scene(n),s,o,a)},t.Append=function(r,i,n,s,o,a){if(i.substr&&"/"===i.substr(0,1))return void e.Tools.Error("Wrong sceneFilename parameter");var h,c=this._getPluginForFilename(i.name||i),l={};n._addPendingData(l),t.ShowLoadingScreen&&n.getEngine().displayLoadingUI();var u=function(e){return n.database=h,c.load(n,e,r)?(s&&s(n),n._removePendingData(l),
  14. void(t.ShowLoadingScreen&&n.executeWhenReady(function(){n.getEngine().hideLoadingUI()}))):(a&&a(n),n._removePendingData(l),void n.getEngine().hideLoadingUI())},f=function(t){e.Tools.LoadFile(r+i,u,o,h)};return i.substr&&"data:"===i.substr(0,5)?void u(i.substr(5)):void(-1===r.indexOf("file:")?n.getEngine().enableOfflineSupport?h=new e.Database(r+i,f):f(!0):e.Tools.ReadFile(i,u,o))},t._ForceFullSceneLoadingForIncremental=!1,t._ShowLoadingScreen=!0,t._registeredPlugins=new Array,t}();e.SceneLoader=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){var r=function(t,r,i,n){for(var s=0,o=r.materials.length;o>s;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;e<this._manager.sprites.length;e++)this._manager.sprites[e]==this&&this._manager.sprites.splice(e,1)},t}();e.Sprite=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r,i,n,s){this.name=t,this.scale=new e.Vector2(1,1),this.offset=new e.Vector2(0,0),this.alphaBlendingMode=e.Engine.ALPHA_COMBINE,this._vertexDeclaration=[2],this._vertexStrideSize=8,this.texture=r?new e.Texture(r,i,!0):null,this.isBackground=void 0===n?!0:n,this.color=void 0===s?new e.Color4(1,1,1,1):s,this._scene=i,this._scene.layers.push(this);var o=[];o.push(1,1),o.push(-1,1),o.push(-1,-1),o.push(1,-1),this._vertexBuffer=i.getEngine().createVertexBuffer(o);var a=[];a.push(0),a.push(1),a.push(2),a.push(0),a.push(2),a.push(3),this._indexBuffer=i.getEngine().createIndexBuffer(a),this._effect=this._scene.getEngine().createEffect("layer",["position"],["textureMatrix","color","scale","offset"],["textureSampler"],"")}return t.prototype.render=function(){if(this._effect.isReady()&&this.texture&&this.texture.isReady()){var t=this._scene.getEngine();t.enableEffect(this._effect),t.setState(!1),this._effect.setTexture("textureSampler",this.texture),this._effect.setMatrix("textureMatrix",this.texture.getTextureMatrix()),this._effect.setFloat4("color",this.color.r,this.color.g,this.color.b,this.color.a),this._effect.setVector2("offset",this.offset),this._effect.setVector2("scale",this.scale),t.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,this._effect),t.setAlphaMode(this.alphaBlendingMode),t.draw(!0,0,6),t.setAlphaMode(e.Engine.ALPHA_DISABLE)}},t.prototype.dispose=function(){this._vertexBuffer&&(this._scene.getEngine()._releaseBuffer(this._vertexBuffer),this._vertexBuffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this.texture&&(this.texture.dispose(),this.texture=null);var e=this._scene.layers.indexOf(this);this._scene.layers.splice(e,1),this.onDispose&&this.onDispose()},t}();e.Layer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this.position=e.Vector3.Zero(),this.direction=e.Vector3.Zero(),this.color=new e.Color4(0,0,0,0),this.colorStep=new e.Color4(0,0,0,0),this.lifeTime=1,this.age=0,this.size=0,this.angle=0,this.angularSpeed=0}return t.prototype.copyTo=function(e){e.position.copyFrom(this.position),e.direction.copyFrom(this.direction),e.color.copyFrom(this.color),e.colorStep.copyFrom(this.colorStep),e.lifeTime=this.lifeTime,e.age=this.age,e.size=this.size,e.angle=this.angle,e.angularSpeed=this.angularSpeed},t}();e.Particle=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e,t){if(e===t)return e;var r=Math.random();return r*(t-e)+e},r=function(){function r(i,n,s,o){var a=this;this.name=i,this.renderingGroupId=0,this.emitter=null,this.emitRate=10,this.manualEmitCount=-1,this.updateSpeed=.01,this.targetStopDuration=0,this.disposeOnStop=!1,this.minEmitPower=1,this.maxEmitPower=1,this.minLifeTime=1,this.maxLifeTime=1,this.minSize=1,this.maxSize=1,this.minAngularSpeed=0,this.maxAngularSpeed=0,this.layerMask=268435455,this.blendMode=r.BLENDMODE_ONEONE,this.forceDepthWrite=!1,this.gravity=e.Vector3.Zero(),this.direction1=new e.Vector3(0,1,0),this.direction2=new e.Vector3(0,1,0),this.minEmitBox=new e.Vector3(-.5,-.5,-.5),this.maxEmitBox=new e.Vector3(.5,.5,.5),this.color1=new e.Color4(1,1,1,1),this.color2=new e.Color4(1,1,1,1),this.colorDead=new e.Color4(0,0,0,1),this.textureMask=new e.Color4(1,1,1,1),this.particles=new Array,this._vertexDeclaration=[3,4,4],this._vertexStrideSize=44,this._stockParticles=new Array,this._newPartsExcess=0,this._scaledColorStep=new e.Color4(0,0,0,0),this._colorDiff=new e.Color4(0,0,0,0),this._scaledDirection=e.Vector3.Zero(),this._scaledGravity=e.Vector3.Zero(),this._currentRenderId=-1,this._started=!1,this._stopped=!1,this._actualFrame=0,this.id=i,this._capacity=n,this._scene=s,this._customEffect=o,s.particleSystems.push(this),this._vertexBuffer=s.getEngine().createDynamicVertexBuffer(n*this._vertexStrideSize*4);for(var h=[],c=0,l=0;n>l;l++)h.push(c),h.push(c+1),h.push(c+2),h.push(c),h.push(c+2),h.push(c+3),c+=4;this._indexBuffer=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<e.length;t++){var r=e[t];r.age+=a._scaledUpdateSpeed,r.age>=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<this.particles.length;i++){var n=this.particles[i];this._appendParticleVertex(r++,n,0,0),this._appendParticleVertex(r++,n,1,0),this._appendParticleVertex(r++,n,1,1),this._appendParticleVertex(r++,n,0,1)}var s=this._scene.getEngine();s.updateDynamicVertexBuffer(this._vertexBuffer,this._vertices)}}},r.prototype.render=function(){var t=this._getEffect();if(!(this.emitter&&t.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this.particles.length))return 0;var i=this._scene.getEngine();i.enableEffect(t),i.setState(!1);var n=this._scene.getViewMatrix();if(t.setTexture("diffuseSampler",this.particleTexture),t.setMatrix("view",n),t.setMatrix("projection",this._scene.getProjectionMatrix()),t.setFloat4("textureMask",this.textureMask.r,this.textureMask.g,this.textureMask.b,this.textureMask.a),this._scene.clipPlane){var s=this._scene.clipPlane,o=n.clone();o.invert(),t.setMatrix("invView",o),t.setFloat4("vClipPlane",s.normal.x,s.normal.y,s.normal.z,s.d)}return i.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,t),this.blendMode===r.BLENDMODE_ONEONE?i.setAlphaMode(e.Engine.ALPHA_ONEONE):i.setAlphaMode(e.Engine.ALPHA_COMBINE),this.forceDepthWrite&&i.setDepthWrite(!0),i.draw(!0,0,6*this.particles.length),i.setAlphaMode(e.Engine.ALPHA_DISABLE),this.particles.length},r.prototype.dispose=function(){this._vertexBuffer&&(this._scene.getEngine()._releaseBuffer(this._vertexBuffer),this._vertexBuffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this.particleTexture&&(this.particleTexture.dispose(),this.particleTexture=null);var e=this._scene.particleSystems.indexOf(this);this._scene.particleSystems.splice(e,1),this.onDispose&&this.onDispose()},r.prototype.clone=function(t,i){var n=new r(t,this._capacity,this._scene);return e.Tools.DeepCopy(this,n,["particles"],["_vertexDeclaration","_vertexStrideSize"]),void 0===i&&(i=this.emitter),n.emitter=i,this.particleTexture&&(n.particleTexture=new e.Texture(this.particleTexture.url,this._scene)),n.start(),n},r.prototype.serialize=function(){var e={};return e.name=this.name,this.emitter.position?e.emitterId=this.emitter.id:e.emitter=this.emitter.asArray(),e.capacity=this.getCapacity(),this.particleTexture&&(e.textureName=this.particleTexture.name),e.minAngularSpeed=this.minAngularSpeed,e.maxAngularSpeed=this.maxAngularSpeed,e.minSize=this.minSize,e.maxSize=this.maxSize,e.minEmitPower=this.minEmitPower,e.maxEmitPower=this.maxEmitPower,e.minLifeTime=this.minLifeTime,e.maxLifeTime=this.maxLifeTime,e.emitRate=this.emitRate,e.minEmitBox=this.minEmitBox.asArray(),e.maxEmitBox=this.maxEmitBox.asArray(),e.gravity=this.gravity.asArray(),e.direction1=this.direction1.asArray(),e.direction2=this.direction2.asArray(),e.color1=this.color1.asArray(),e.color2=this.color2.asArray(),e.colorDead=this.colorDead.asArray(),e.updateSpeed=this.updateSpeed,e.targetStopDuration=this.targetStopDuration,e.textureMask=this.textureMask.asArray(),e.blendMode=this.blendMode,e},r.Parse=function(t,i,n){var s=t.name,o=new r(s,t.capacity,i);return t.textureName&&(o.particleTexture=new e.Texture(n+t.textureName,i),o.particleTexture.name=t.textureName),t.emitterId?o.emitter=i.getLastMeshByID(t.emitterId):o.emitter=e.Vector3.FromArray(t.emitter),o.minAngularSpeed=t.minAngularSpeed,o.maxAngularSpeed=t.maxAngularSpeed,o.minSize=t.minSize,o.maxSize=t.maxSize,o.minLifeTime=t.minLifeTime,o.maxLifeTime=t.maxLifeTime,o.minEmitPower=t.minEmitPower,o.maxEmitPower=t.maxEmitPower,o.emitRate=t.emitRate,o.minEmitBox=e.Vector3.FromArray(t.minEmitBox),o.maxEmitBox=e.Vector3.FromArray(t.maxEmitBox),o.gravity=e.Vector3.FromArray(t.gravity),o.direction1=e.Vector3.FromArray(t.direction1),o.direction2=e.Vector3.FromArray(t.direction2),o.color1=e.Color4.FromArray(t.color1),o.color2=e.Color4.FromArray(t.color2),o.colorDead=e.Color4.FromArray(t.colorDead),o.updateSpeed=t.updateSpeed,o.targetStopDuration=t.targetStopDuration,o.textureMask=e.Color4.FromArray(t.textureMask),o.blendMode=t.blendMode,o.start(),o},r.BLENDMODE_ONEONE=0,r.BLENDMODE_STANDARD=1,r}();e.ParticleSystem=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,r){this.name=e,this.from=t,this.to=r}return e}();e.AnimationRange=t;var r=function(){function e(e,t,r){this.frame=e,this.action=t,this.onlyOnce=r,this.isDone=!1}return e}();e.AnimationEvent=r;var i=function(){function r(e,t,i,n,s){this.name=e,this.targetProperty=t,this.framePerSecond=i,this.dataType=n,this.loopMode=s,this._offsetsCache={},this._highLimitsCache={},this._stopped=!1,this._events=new Array,this.allowMatricesInterpolation=!1,this._ranges={},this.targetPropertyPath=t.split("."),this.dataType=n,this.loopMode=void 0===s?r.ANIMATIONLOOPMODE_CYCLE:s}return r._PrepareAnimation=function(t,i,n,s,o,a,h,c){var l=void 0;if(!isNaN(parseFloat(o))&&isFinite(o)?l=r.ANIMATIONTYPE_FLOAT:o instanceof e.Quaternion?l=r.ANIMATIONTYPE_QUATERNION:o instanceof e.Vector3?l=r.ANIMATIONTYPE_VECTOR3:o instanceof e.Vector2?l=r.ANIMATIONTYPE_VECTOR2:o instanceof e.Color3&&(l=r.ANIMATIONTYPE_COLOR3),void 0==l)return null;var u=new r(t,i,n,l,h),f=[];return f.push({frame:0,value:o}),f.push({frame:s,value:a}),u.setKeys(f),void 0!==c&&u.setEasingFunction(c),u},r.CreateAndStartAnimation=function(e,t,i,n,s,o,a,h,c,l){var u=r._PrepareAnimation(e,i,n,s,o,a,h,c);return t.getScene().beginDirectAnimation(t,[u],0,s,1===u.loopMode,1,l)},r.CreateMergeAndStartAnimation=function(e,t,i,n,s,o,a,h,c,l){var u=r._PrepareAnimation(e,i,n,s,o,a,h,c);return t.animations.push(u),t.getScene().beginAnimation(t,0,s,1===u.loopMode,1,l)},r.prototype.addEvent=function(e){this._events.push(e)},r.prototype.removeEvents=function(e){for(var t=0;t<this._events.length;t++)this._events[t].frame===e&&(this._events.splice(t,1),t--)},r.prototype.createRange=function(e,r,i){this._ranges[e]||(this._ranges[e]=new t(e,r,i))},r.prototype.deleteRange=function(e,t){if(void 0===t&&(t=!0),this._ranges[e]){if(t)for(var r=this._ranges[e].from,i=this._ranges[e].to,n=this._keys.length-1;n>=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++)e<this._keys[t].frame&&(e=this._keys[t].frame);return e},r.prototype.getEasingFunction=function(){return this._easingFunction},r.prototype.setEasingFunction=function(e){this._easingFunction=e},r.prototype.floatInterpolateFunction=function(e,t,r){return e+(t-e)*r},r.prototype.quaternionInterpolateFunction=function(t,r,i){return e.Quaternion.Slerp(t,r,i)},r.prototype.vector3InterpolateFunction=function(t,r,i){return e.Vector3.Lerp(t,r,i)},r.prototype.vector2InterpolateFunction=function(t,r,i){return e.Vector2.Lerp(t,r,i)},r.prototype.color3InterpolateFunction=function(t,r,i){return e.Color3.Lerp(t,r,i)},r.prototype.matrixInterpolateFunction=function(t,r,i){return e.Matrix.Lerp(t,r,i)},r.prototype.clone=function(){var e=new r(this.name,this.targetPropertyPath.join("."),this.framePerSecond,this.dataType,this.loopMode);return this._keys&&e.setKeys(this._keys),e},r.prototype.setKeys=function(e){this._keys=e.slice(0),this._offsetsCache={},this._highLimitsCache={}},r.prototype._getKeyValue=function(e){return"function"==typeof e?e():e},r.prototype._interpolate=function(e,t,i,n,s){if(i===r.ANIMATIONLOOPMODE_CONSTANT&&t>0)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<this._keys.length;a++)if(this._keys[a+1].frame>=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;r<this.targetPropertyPath.length-1;r++)t=t[this.targetPropertyPath[r]];t[this.targetPropertyPath[this.targetPropertyPath.length-1]]=e}else this._target[this.targetPropertyPath[0]]=e;this._target.markAsDirty&&this._target.markAsDirty(this.targetProperty)},r.prototype.goToFrame=function(e){e<this._keys[0].frame?e=this._keys[0].frame:e>this._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)}(i<this._keys[0].frame||i>this._keys[this._keys.length-1].frame)&&(i=this._keys[0].frame),(n<this._keys[0].frame||n>this._keys[this._keys.length-1].frame)&&(n=this._keys[this._keys.length-1].frame);var c,l=n-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;
  15. 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.length;y++)if(_>=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<i.length;n++){var s=i[n],o={};switch(o.frame=s.frame,t){case r.ANIMATIONTYPE_FLOAT:o.values=[s.value];break;case r.ANIMATIONTYPE_QUATERNION:case r.ANIMATIONTYPE_MATRIX:case r.ANIMATIONTYPE_VECTOR3:case r.ANIMATIONTYPE_COLOR3:o.values=s.value.asArray()}e.keys.push(o)}e.ranges=[];for(var a in this._ranges){var h={};h.name=a,h.from=this._ranges[a].from,h.to=this._ranges[a].to,e.ranges.push(h)}return e},Object.defineProperty(r,"ANIMATIONTYPE_FLOAT",{get:function(){return r._ANIMATIONTYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ANIMATIONTYPE_VECTOR3",{get:function(){return r._ANIMATIONTYPE_VECTOR3},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ANIMATIONTYPE_VECTOR2",{get:function(){return r._ANIMATIONTYPE_VECTOR2},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ANIMATIONTYPE_QUATERNION",{get:function(){return r._ANIMATIONTYPE_QUATERNION},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ANIMATIONTYPE_MATRIX",{get:function(){return r._ANIMATIONTYPE_MATRIX},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ANIMATIONTYPE_COLOR3",{get:function(){return r._ANIMATIONTYPE_COLOR3},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ANIMATIONLOOPMODE_RELATIVE",{get:function(){return r._ANIMATIONLOOPMODE_RELATIVE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ANIMATIONLOOPMODE_CYCLE",{get:function(){return r._ANIMATIONLOOPMODE_CYCLE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ANIMATIONLOOPMODE_CONSTANT",{get:function(){return r._ANIMATIONLOOPMODE_CONSTANT},enumerable:!0,configurable:!0}),r.Parse=function(t){for(var i=new r(t.name,t.property,t.framePerSecond,t.dataType,t.loopBehavior),n=t.dataType,s=[],o=0;o<t.keys.length;o++){var a,h=t.keys[o];switch(n){case r.ANIMATIONTYPE_FLOAT:a=h.values[0];break;case r.ANIMATIONTYPE_QUATERNION:a=e.Quaternion.FromArray(h.values);break;case r.ANIMATIONTYPE_MATRIX:a=e.Matrix.FromArray(h.values);break;case r.ANIMATIONTYPE_COLOR3:a=e.Color3.FromArray(h.values);break;case r.ANIMATIONTYPE_VECTOR3:default:a=e.Vector3.FromArray(h.values)}s.push({frame:h.frame,value:a})}if(i.setKeys(s),t.ranges)for(var o=0;o<t.ranges.length;o++)a=t.ranges[o],i.createRange(a.name,a.from,a.to);return i},r.AppendSerializedAnimations=function(e,t){if(e.animations){t.animations=[];for(var r=0;r<e.animations.length;r++){var i=e.animations[r];t.animations.push(i.serialize())}}},r._ANIMATIONTYPE_FLOAT=0,r._ANIMATIONTYPE_VECTOR3=1,r._ANIMATIONTYPE_QUATERNION=2,r._ANIMATIONTYPE_MATRIX=3,r._ANIMATIONTYPE_COLOR3=4,r._ANIMATIONTYPE_VECTOR2=5,r._ANIMATIONLOOPMODE_RELATIVE=0,r._ANIMATIONLOOPMODE_CYCLE=1,r._ANIMATIONLOOPMODE_CONSTANT=2,r}();e.Animation=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,r,i,n,s,o,a){void 0===r&&(r=0),void 0===i&&(i=100),void 0===n&&(n=!1),void 0===s&&(s=1),this.target=t,this.fromFrame=r,this.toFrame=i,this.loopAnimation=n,this.speedRatio=s,this.onAnimationEnd=o,this._animations=new Array,this._paused=!1,this.animationStarted=!1,a&&this.appendAnimations(t,a),this._scene=e,e._activeAnimatables.push(this)}return e.prototype.getAnimations=function(){return this._animations},e.prototype.appendAnimations=function(e,t){for(var r=0;r<t.length;r++){var i=t[r];i._target=e,this._animations.push(i)}},e.prototype.getAnimationByTargetProperty=function(e){for(var t=this._animations,r=0;r<t.length;r++)if(t[r].targetProperty===e)return t[r];return null},e.prototype.reset=function(){for(var e=this._animations,t=0;t<e.length;t++)e[t].reset();this._localDelayOffset=null,this._pausedDelay=null},e.prototype.goToFrame=function(e){for(var t=this._animations,r=0;r<t.length;r++)t[r].goToFrame(e)},e.prototype.pause=function(){this._paused||(this._paused=!0)},e.prototype.restart=function(){this._paused=!1},e.prototype.stop=function(){var e=this._scene._activeAnimatables.indexOf(this);e>-1&&this._scene._activeAnimatables.splice(e,1),this.onAnimationEnd&&this.onAnimationEnd()},e.prototype._animate=function(e){if(this._paused)return this.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<i.length;t++){var n=i[t],s=n.animate(e-this._localDelayOffset,this.fromFrame,this.toFrame,this.loopAnimation,this.speedRatio);r=r||s}return this.animationStarted=r,r||(t=this._scene._activeAnimatables.indexOf(this),this._scene._activeAnimatables.splice(t,1)),!r&&this.onAnimationEnd&&this.onAnimationEnd(),r},e}();e.Animatable=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this._easingMode=e.EASINGMODE_EASEIN}return Object.defineProperty(e,"EASINGMODE_EASEIN",{get:function(){return e._EASINGMODE_EASEIN},enumerable:!0,configurable:!0}),Object.defineProperty(e,"EASINGMODE_EASEOUT",{get:function(){return e._EASINGMODE_EASEOUT},enumerable:!0,configurable:!0}),Object.defineProperty(e,"EASINGMODE_EASEINOUT",{get:function(){return e._EASINGMODE_EASEINOUT},enumerable:!0,configurable:!0}),e.prototype.setEasingMode=function(e){var t=Math.min(Math.max(e,0),2);this._easingMode=t},e.prototype.getEasingMode=function(){return this._easingMode},e.prototype.easeInCore=function(e){throw new Error("You must implement this method")},e.prototype.ease=function(t){switch(this._easingMode){case e.EASINGMODE_EASEIN:return this.easeInCore(t);case e.EASINGMODE_EASEOUT:return 1-this.easeInCore(1-t)}return t>=.5?.5*(1-this.easeInCore(2*(1-t)))+.5:.5*this.easeInCore(2*t)},e._EASINGMODE_EASEIN=0,e._EASINGMODE_EASEOUT=1,e._EASINGMODE_EASEINOUT=2,e}();e.EasingFunction=t;var 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;t<this.children.length;t++)this.children[t]._updateDifferenceMatrix()},r.prototype.markAsDirty=function(){this._currentRenderId++,this._skeleton._markAsDirty()},r.prototype.copyAnimationRange=function(t,r,i,n){void 0===n&&(n=!1),0===this.animations.length&&this.animations.push(new e.Animation(this.name,"_matrix",t.animations[0].framePerSecond,e.Animation.ANIMATIONTYPE_MATRIX,0));var s=t.animations[0].getRange(r);if(!s)return!1;for(var o,a,h=s.from,c=s.to,l=t.animations[0].getKeys(),u=t.length,f=n&&u&&this.length&&u!==this.length,d=f?this.length/u:null,p=this.animations[0].getKeys(),m=f?e.Vector3.Zero():null,g=f?new e.Quaternion:null,_=f?e.Vector3.Zero():null,v=0,y=l.length;y>v;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;e<this.bones.length;e++)this.bones[e].returnToRest()},t.prototype._getHighestAnimationFrame=function(){for(var e=0,t=0,r=this.bones.length;r>t;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;r<this.bones.length;r++){var i=this.bones[r],n=i.getParent();n?i.getLocalMatrix().multiplyToRef(n.getWorldMatrix(),i.getWorldMatrix()):t?i.getLocalMatrix().multiplyToRef(t,i.getWorldMatrix()):i.getWorldMatrix().copyFrom(i.getLocalMatrix()),i.getInvertedAbsoluteTransform().multiplyToArray(i.getWorldMatrix(),e,16*r)}this._identity.copyToArray(e,16*this.bones.length)},t.prototype.prepare=function(){if(this._isDirty){if(this.needInitialSkinMatrix)for(var t=0;t<this._meshesWithPoseMatrix.length;t++){var r=this._meshesWithPoseMatrix[t];r._bonesTransformMatrices&&r._bonesTransformMatrices.length===16*(this.bones.length+1)||(r._bonesTransformMatrices=new Float32Array(16*(this.bones.length+1)));for(var i=r.getPoseMatrix(),n=0;n<this.bones.length;n++){var s=this.bones[n];if(!s.getParent()){var o=s.getBaseMatrix();o.multiplyToRef(i,e.Tmp.Matrix[0]),s._updateDifferenceMatrix(e.Tmp.Matrix[0])}}this._computeTransformMatrices(r._bonesTransformMatrices,i)}else this._transformMatrices&&this._transformMatrices.length===16*(this.bones.length+1)||(this._transformMatrices=new Float32Array(16*(this.bones.length+1))),this._computeTransformMatrices(this._transformMatrices,null);this._isDirty=!1,this._scene._activeBones+=this.bones.length}},t.prototype.getAnimatables=function(){if(!this._animatables||this._animatables.length!==this.bones.length){this._animatables=[];for(var e=0;e<this.bones.length;e++)this._animatables.push(this.bones[e])}return this._animatables},t.prototype.clone=function(r,i){for(var n=new t(r,i||r,this._scene),s=0;s<this.bones.length;s++){var o=this.bones[s],a=null;if(o.getParent()){var h=this.bones.indexOf(o.getParent());a=n.bones[h]}var c=new e.Bone(o.name,n,a,o.getBaseMatrix().clone(),o.getRestPose().clone());e.Tools.DeepCopy(o.animations,c.animations)}return n},t.prototype.dispose=function(){this._meshesWithPoseMatrix=[],this.getScene().stopAnimation(this),this.getScene().removeSkeleton(this)},t.prototype.serialize=function(){var e={};e.name=this.name,e.id=this.id,e.bones=[],e.needInitialSkinMatrix=this.needInitialSkinMatrix;for(var t=0;t<this.bones.length;t++){var r=this.bones[t],i={parentBoneIndex:r.getParent()?this.bones.indexOf(r.getParent()):-1,name:r.name,matrix:r.getLocalMatrix().toArray(),rest:r.getRestPose().toArray()};e.bones.push(i),r.length&&(i.length=r.length),r.animations&&r.animations.length>0&&(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<r.bones.length;s++){var o=r.bones[s],a=null;o.parentBoneIndex>-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;s<r.ranges.length;s++){var l=r.ranges[s];n.createAnimationRange(l.name,l.from,l.to)}return n},t}();e.Skeleton=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r,i,n,s,o,a,h,c,l,u){void 0===a&&(a=e.Texture.NEAREST_SAMPLINGMODE),void 0===u&&(u=e.Engine.TEXTURETYPE_UNSIGNED_INT),this.name=t,this.width=-1,this.height=-1,this._reusable=!1,this._textures=new e.SmartArray(2),this._currentRenderTextureInd=0,null!=o?(this._camera=o,this._scene=o.getScene(),o.attachPostProcess(this),this._engine=this._scene.getEngine()):this._engine=h,this._renderRatio=s,this.renderTargetSamplingMode=a?a:e.Texture.NEAREST_SAMPLINGMODE,this._reusable=c||!1,this._textureType=u,this._samplers=n||[],this._samplers.push("textureSampler"),this._fragmentUrl=r,this._parameters=i||[],this.updateEffect(l)}return t.prototype.updateEffect=function(e){this._effect=this._engine.createEffect({vertex:"postprocess",fragment:this._fragmentUrl},["position"],this._parameters,this._samplers,void 0!==e?e:"")},t.prototype.isReusable=function(){return this._reusable},t.prototype.activate=function(t,r){t=t||this._camera;var i=t.getScene(),n=t.getEngine().getCaps().maxTextureSize,s=(r?r._width:this._engine.getRenderingCanvas().width)*this._renderRatio|0,o=(r?r._height:this._engine.getRenderingCanvas().height)*this._renderRatio|0;if(s=this._renderRatio.width||e.Tools.GetExponentOfTwo(s,n),o=this._renderRatio.height||e.Tools.GetExponentOfTwo(o,n),this.width!==s||this.height!==o){if(this._textures.length>0){for(var a=0;a<this._textures.length;a++)this._engine._releaseTexture(this._textures.data[a]);this._textures.reset()}this.width=s,this.height=o,this._textures.push(this._engine.createRenderTargetTexture({width:this.width,height:this.height},{generateMipMaps:!1,generateDepthBuffer:t._postProcesses.indexOf(this)===t._postProcessesTakenIndices[0],samplingMode:this.renderTargetSamplingMode,type:this._textureType})),this._reusable&&this._textures.push(this._engine.createRenderTargetTexture({width:this.width,height:this.height},{generateMipMaps:!1,generateDepthBuffer:t._postProcesses.indexOf(this)===t._postProcessesTakenIndices[0],samplingMode:this.renderTargetSamplingMode,type:this._textureType})),this.onSizeChanged&&this.onSizeChanged()}this._engine.bindFramebuffer(this._textures.data[this._currentRenderTextureInd]),this.onActivate&&this.onActivate(t),this.clearColor?this._engine.clear(this.clearColor,!0,!0):this._engine.clear(i.clearColor,i.autoClear||i.forceWireframe,!0),this._reusable&&(this._currentRenderTextureInd=(this._currentRenderTextureInd+1)%2)},Object.defineProperty(t.prototype,"isSupported",{get:function(){return this._effect.isSupported},enumerable:!0,configurable:!0}),t.prototype.apply=function(){return this._effect.isReady()?(this._engine.enableEffect(this._effect),this._engine.setState(!1),this._engine.setAlphaMode(e.Engine.ALPHA_DISABLE),this._engine.setDepthBuffer(!1),this._engine.setDepthWrite(!1),this._effect._bindTexture("textureSampler",this._textures.data[this._currentRenderTextureInd]),this.onApply&&this.onApply(this._effect),this._effect):null},t.prototype.dispose=function(e){if(e=e||this._camera,this._textures.length>0){for(var t=0;t<this._textures.length;t++)this._engine._releaseTexture(this._textures.data[t]);this._textures.reset()}if(e){e.detachPostProcess(this);var r=e._postProcesses.indexOf(this);r===e._postProcessesTakenIndices[0]&&e._postProcessesTakenIndices.length>0&&(this._camera._postProcesses[e._postProcessesTakenIndices[0]].width=-1)}},t}();e.PostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){this._vertexDeclaration=[2],this._vertexStrideSize=8,this._scene=e}return e.prototype._prepareBuffers=function(){if(!this._vertexBuffer){var e=[];e.push(1,1),e.push(-1,1),e.push(-1,-1),e.push(1,-1),this._vertexBuffer=this._scene.getEngine().createVertexBuffer(e);var t=[];t.push(0),t.push(1),t.push(2),t.push(0),t.push(2),t.push(3),this._indexBuffer=this._scene.getEngine().createIndexBuffer(t)}},e.prototype._prepareFrame=function(e){var t=this._scene.activeCamera._postProcesses,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<e.length;i++){i<e.length-1?e[i+1].activate(this._scene.activeCamera,t):t?r.bindFramebuffer(t):r.restoreDefaultFramebuffer();var n=e[i],s=n.apply();s&&(n.onBeforeRender&&n.onBeforeRender(s),this._prepareBuffers(),r.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,s),r.draw(!0,0,6),n.onAfterRender&&n.onAfterRender(s))}r.setDepthBuffer(!0),r.setDepthWrite(!0)},e.prototype._finalizeFrame=function(e,t,r,i){i=i||this._scene.activeCamera._postProcesses;var n=this._scene.activeCamera._postProcessesTakenIndices;if(0!==n.length&&this._scene.postProcessesEnabled){for(var s=this._scene.getEngine(),o=0;o<n.length&&(o<n.length-1?i[n[o+1]].activate(this._scene.activeCamera,t):t?s.bindFramebuffer(t,r):s.restoreDefaultFramebuffer(),!e);o++){var a=i[n[o]],h=a.apply();h&&(a.onBeforeRender&&a.onBeforeRender(h),this._prepareBuffers(),s.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,h),s.draw(!0,0,6),a.onAfterRender&&a.onAfterRender(h))}s.setDepthBuffer(!0),s.setDepthWrite(!0)}},e.prototype.dispose=function(){this._vertexBuffer&&(this._scene.getEngine()._releaseBuffer(this._vertexBuffer),this._vertexBuffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null)},e}();e.PostProcessManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,r,i,n,s,o){e.call(this,t,"pass",null,null,r,i,n,s,o)}return __extends(t,e),t}(e.PostProcess);e.PassPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this._currentPlugin=t||new e.OimoJSPlugin}return t.prototype._initialize=function(e){this._currentPlugin.initialize(),this._setGravity(e)},t.prototype._runOneStep=function(e){e>.1?e=.1:0>=e&&(e=1/60),this._currentPlugin.runOneStep(e)},t.prototype._setGravity=function(t){this.gravity=t||new e.Vector3(0,-9.807,0),this._currentPlugin.setGravity(this.gravity)},t.prototype._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;r<this.positions.length;r+=3)e.Vector3.FromArrayToRef(this.positions,r,n),e.Vector3.TransformCoordinatesToRef(n,t,i),this.positions[r]=i.x,this.positions[r+1]=i.y,this.positions[r+2]=i.z}if(this.normals){var s=e.Vector3.Zero();for(r=0;r<this.normals.length;r+=3)e.Vector3.FromArrayToRef(this.normals,r,s),e.Vector3.TransformNormalToRef(s,t,i),this.normals[r]=i.x,this.normals[r+1]=i.y,this.normals[r+2]=i.z}},t.prototype.merge=function(e){if(e.indices){this.indices||(this.indices=[]);for(var t=this.positions?this.positions.length/3:0,r=0;r<e.indices.length;r++)this.indices.push(e.indices[r]+t)}this.positions=this._mergeElement(this.positions,e.positions),this.normals=this._mergeElement(this.normals,e.normals),this.uvs=this._mergeElement(this.uvs,e.uvs),this.uvs2=this._mergeElement(this.uvs2,e.uvs2),this.uvs3=this._mergeElement(this.uvs3,e.uvs3),this.uvs4=this._mergeElement(this.uvs4,e.uvs4),this.uvs5=this._mergeElement(this.uvs5,e.uvs5),this.uvs6=this._mergeElement(this.uvs6,e.uvs6),this.colors=this._mergeElement(this.colors,e.colors),this.matricesIndices=this._mergeElement(this.matricesIndices,e.matricesIndices),this.matricesWeights=this._mergeElement(this.matricesWeights,e.matricesWeights),this.matricesIndicesExtra=this._mergeElement(this.matricesIndicesExtra,e.matricesIndicesExtra),this.matricesWeightsExtra=this._mergeElement(this.matricesWeightsExtra,e.matricesWeightsExtra)},t.prototype._mergeElement=function(e,t){if(!t)return e;if(!e)return t;var r=t.length+e.length,i=e instanceof Float32Array,n=t instanceof Float32Array;if(i){var s=new Float32Array(r);return s.set(e),s.set(t,e.length),s}if(n){for(var o=e.slice(0),a=0,r=t.length;r>a;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)),
  16. 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;l<i[0].length-a;l++)A.push(i[0][l]),b.push(i[0][l+a]);i=[A,b]}var M,P,S=0,C=s?1:0;h=i[0].length;var I,D;for(c=0;c<i.length;c++){for(y[c]=0,_[c]=[0],M=i[c],P=M.length,h=P>h?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;c<i.length-1;c++)R=i[c],w=i[c+1],l===h?(L=R[0],O=w[0]):(L=R[l],O=w[l]),I=O.subtract(L).length(),D=I+x[l],v[l].push(D),x[l]=D;n&&(R=i[c],w=i[0],l===h&&(O=w[0]),I=O.subtract(L).length(),D=I+x[l],x[l]=D)}var B,F;for(c=0;c<i.length;c++)for(l=0;h+C>l;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;c<i.length;c++)G=3*T[c],K=c+1<i.length?3*(T[c+1]-1):m.length-3,m[G]=.5*(m[G]+m[K]),m[G+1]=.5*(m[G+1]+m[K+1]),m[G+2]=.5*(m[G+2]+m[K+2]),m[K]=m[G],m[K+1]=m[G+1],m[K+2]=m[G+2]}t._ComputeSides(f,d,p,m,g);var Y=new t;return Y.indices=p,Y.positions=d,Y.normals=m,Y.uvs=g,s&&(Y._idx=T),Y},t.CreateBox=function(r){for(var i=[new e.Vector3(0,0,1),new e.Vector3(0,0,-1),new e.Vector3(1,0,0),new e.Vector3(-1,0,0),new e.Vector3(0,1,0),new e.Vector3(0,-1,0)],n=[],s=[],o=[],a=[],h=r.width||r.size||1,c=r.height||r.size||1,l=r.depth||r.size||1,u=0===r.sideOrientation?0:r.sideOrientation||e.Mesh.DEFAULTSIDE,f=r.faceUV||new Array(6),d=r.faceColors,p=[],m=0;6>m;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;_<i.length;_++){var v=i[_],y=new e.Vector3(v.y,v.z,v.x),x=e.Vector3.Cross(v,y),E=s.length/3;n.push(E),n.push(E+1),n.push(E+2),n.push(E),n.push(E+2),n.push(E+3);var T=v.subtract(y).subtract(x).multiply(g);s.push(T.x,T.y,T.z),o.push(v.x,v.y,v.z),a.push(f[_].z,f[_].w),d&&p.push(d[_].r,d[_].g,d[_].b,d[_].a),T=v.subtract(y).add(x).multiply(g),s.push(T.x,T.y,T.z),o.push(v.x,v.y,v.z),a.push(f[_].x,f[_].w),d&&p.push(d[_].r,d[_].g,d[_].b,d[_].a),T=v.add(y).add(x).multiply(g),s.push(T.x,T.y,T.z),o.push(v.x,v.y,v.z),a.push(f[_].x,f[_].y),d&&p.push(d[_].r,d[_].g,d[_].b,d[_].a),T=v.add(y).subtract(x).multiply(g),s.push(T.x,T.y,T.z),o.push(v.x,v.y,v.z),a.push(f[_].z,f[_].y),d&&p.push(d[_].r,d[_].g,d[_].b,d[_].a)}t._ComputeSides(u,s,n,o,a);var A=new t;if(A.indices=n,A.positions=s,A.normals=o,A.uvs=a,d){var b=u===e.Mesh.DOUBLESIDE?p.concat(p):p;A.colors=b}return A},t.CreateSphere=function(r){for(var i=r.segments||32,n=r.diameterX||r.diameter||1,s=r.diameterY||r.diameter||1,o=r.diameterZ||r.diameter||1,a=r.arc<=0||r.arc>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;s<n.length;s++)i.push(n[s].x,n[s].y,n[s].z),s>0&&(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<o.length-1;g++)o[g+1].subtractToRef(o[g],c),l+=c.length();for(f=l/s,d=i*f/(i+n),g=0;g<o.length-1;g++){o[g+1].subtractToRef(o[g],c),u=Math.floor(c.length()/f),c.normalize();for(var _=0;u>_;_++)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;n<d.h;n++)for(s=0;s<d.w;s++){var c=[a+s+n*h,a+(s+1)+n*h,a+(s+1)+(n+1)*h,a+s+(n+1)*h];p.push(c[1]),p.push(c[2]),p.push(c[3]),p.push(c[0]),p.push(c[1]),p.push(c[3])}var l=e.Vector3.Zero(),u=new e.Vector3(0,1,0);for(n=0;n<=d.h;n++)for(l.z=n*(o-r)/d.h+r,s=0;s<=d.w;s++)l.x=s*(i-t)/d.w+t,l.y=0,m.push(l.x,l.y,l.z),g.push(u.x,u.y,u.z),_.push(s/d.w,n/d.h)}var n,s,o,a,h=r.xmin,c=r.zmin,l=r.xmax,u=r.zmax,f=r.subdivisions||{w:1,h:1},d=r.precision||{w:1,h:1},p=[],m=[],g=[],_=[];f.h=f.w<1?1:f.h,f.w=f.w<1?1:f.w,d.w=d.w<1?1:d.w,d.h=d.h<1?1:d.h;var v={w:(l-h)/f.w,h:(u-c)/f.h};for(o=0;o<f.h;o++)for(a=0;a<f.w;a++)i(h+a*v.w,c+o*v.h,h+(a+1)*v.w,c+(o+1)*v.h);var y=new t;return y.indices=p,y.positions=m,y.normals=g,y.uvs=_,y},t.CreateGroundFromHeightMap=function(r){var i,n,s=[],o=[],a=[],h=[];for(i=0;i<=r.subdivisions;i++)for(n=0;n<=r.subdivisions;n++){var c=new e.Vector3(n*r.width/r.subdivisions-r.width/2,0,(r.subdivisions-i)*r.height/r.subdivisions-r.height/2),l=(c.x+r.width/2)/r.width*(r.bufferWidth-1)|0,u=(1-(c.z+r.height/2)/r.height)*(r.bufferHeight-1)|0,f=4*(l+u*r.bufferWidth),d=r.buffer[f]/255,p=r.buffer[f+1]/255,m=r.buffer[f+2]/255,g=.3*d+.59*p+.11*m;c.y=r.minHeight+(r.maxHeight-r.minHeight)*g,o.push(c.x,c.y,c.z),a.push(0,0,0),h.push(n/r.subdivisions,1-i/r.subdivisions)}for(i=0;i<r.subdivisions;i++)for(n=0;n<r.subdivisions;n++)s.push(n+1+(i+1)*(r.subdivisions+1)),s.push(n+1+i*(r.subdivisions+1)),s.push(n+i*(r.subdivisions+1)),s.push(n+(i+1)*(r.subdivisions+1)),s.push(n+1+(i+1)*(r.subdivisions+1)),s.push(n+i*(r.subdivisions+1));t.ComputeNormals(o,s,a);var _=new t;return _.indices=s,_.positions=o,_.normals=a,_.uvs=h,_},t.CreatePlane=function(r){var i=[],n=[],s=[],o=[],a=r.width||r.size||1,h=r.height||r.size||1,c=0===r.sideOrientation?0:r.sideOrientation||e.Mesh.DEFAULTSIDE,l=a/2,u=h/2;n.push(-l,-u,0),s.push(0,0,-1),o.push(0,0),n.push(l,-u,0),s.push(0,0,-1),o.push(1,0),n.push(l,u,0),s.push(0,0,-1),o.push(1,1),n.push(-l,u,0),s.push(0,0,-1),o.push(0,1),i.push(0),i.push(1),i.push(2),i.push(0),i.push(2),i.push(3),t._ComputeSides(c,n,i,s,o);var f=new t;return f.indices=i,f.positions=n,f.normals=s,f.uvs=o,f},t.CreateDisc=function(r){var i=[],n=[],s=[],o=[],a=r.radius||.5,h=r.tessellation||64,c=r.arc<=0||r.arc>1?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;I<m.vertex.length;I++)E.push(m.vertex[I][0]*f,m.vertex[I][1]*d,m.vertex[I][2]*p),b.push(0,0);for(D=0;g>D;D++)for(I=0;I<m.face[D].length-2;I++)T.push(m.face[D][0],m.face[D][I+2],m.face[D][I+1])}t.ComputeNormals(E,T,A),t._ComputeSides(x,E,T,A,b);var w=new t;return w.positions=E,w.indices=T,w.normals=A,w.uvs=b,v&&y&&(w.colors=M),w},t.CreateTorusKnot=function(r){var i,n,s=[],o=[],a=[],h=[],c=r.radius||2,l=r.tube||.5,u=r.radialSegments||32,f=r.tubularSegments||32,d=r.p||2,p=r.q||3,m=0===r.sideOrientation?0:r.sideOrientation||e.Mesh.DEFAULTSIDE,g=function(t){var r=Math.cos(t),i=Math.sin(t),n=p/d*t,s=Math.cos(n),o=c*(2+s)*.5*r,a=c*(2+s)*i*.5,h=c*Math.sin(n)*.5;return new e.Vector3(o,a,h)};for(i=0;u>=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;i<e.length;i++)r[i]=0;var _=t.length/3;for(i=0;_>i;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;i<r.length/3;i++)l=r[3*i],u=r[3*i+1],f=r[3*i+2],d=Math.sqrt(l*l+u*u+f*f),d=0===d?1:d,l/=d,u/=d,f/=d,r[3*i]=l,r[3*i+1]=u,r[3*i+2]=f},t._ComputeSides=function(t,r,i,n,s){var o,a,h=i.length,c=n.length;switch(t=t||e.Mesh.DEFAULTSIDE){case e.Mesh.FRONTSIDE:break;case e.Mesh.BACKSIDE:var l;for(o=0;h>o;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;h<a.length;++h){var c=e._SimplifyNegation(a[h].trim());if(i="true"!==c&&"false"!==c?"!"===c[0]?!r(c.substring(1)):r(c):"true"===c?!0:!1,!i){o="false";break}}if(i||"true"===o){i=!0;break}i="true"!==o&&"false"!==o?"!"===o[0]?!r(o.substring(1)):r(o):"true"===o?!0:!1}return i?"true":"false"},e._SimplifyNegation=function(e){return e=e.replace(/^[\s!]+/,function(e){return e=e.replace(/[\s]/g,function(){return""}),e.length%2?"!":""}),e=e.trim(),"!true"===e?e="false":"!false"===e&&(e="true"),e},e}();e.AndOrNotEvaluator=t}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r,i,n,s,o){this._enabled=!0,this._refCount=0,this._name=r,this._renderTexture=new e.RenderTargetTexture(r,i,t),this.setRenderList(n),this._renderTexture.onBeforeRender=s,this._renderTexture.onAfterRender=o,this._scene=t,this._renderList=n}return t.prototype._incRefCount=function(){return 0===this._refCount&&this._scene.customRenderTargets.push(this._renderTexture),++this._refCount},t.prototype._decRefCount=function(){return this._refCount--,this._refCount<=0&&this._scene.customRenderTargets.splice(this._scene.customRenderTargets.indexOf(this._renderTexture),1),this._refCount},t.prototype._update=function(){this.setRenderList(this._renderList)},t.prototype.setRenderList=function(e){this._renderTexture.renderList=e},t.prototype.getRenderTexture=function(){return this._renderTexture},t}();e.PostProcessRenderPass=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,r,i){this._engine=e,this._name=t,this._singleInstance=i||!0,this._getPostProcess=r,this._cameras=[],this._indicesForCamera=[],this._postProcesses={},this._renderPasses={},this._renderEffectAsPasses={}}return Object.defineProperty(t.prototype,"isSupported",{get:function(){for(var e in this._postProcesses)if(!this._postProcesses[e].isSupported)return!1;return!0},enumerable:!0,configurable:!0}),t.prototype._update=function(){for(var e in this._renderPasses)this._renderPasses[e]._update()},t.prototype.addPass=function(e){this._renderPasses[e._name]=e,this._linkParameters()},t.prototype.removePass=function(e){delete this._renderPasses[e._name],this._linkParameters()},t.prototype.addRenderEffectAsPass=function(e){this._renderEffectAsPasses[e._name]=e,this._linkParameters()},t.prototype.getPass=function(e){for(var t in this._renderPasses)if(t===e)return this._renderPasses[e]},t.prototype.emptyPasses=function(){this._renderPasses={},this._linkParameters()},t.prototype._attachCameras=function(t){for(var r,i=e.Tools.MakeArray(t||this._cameras),n=0;n<i.length;n++){var s=i[n],o=s.name;r=this._singleInstance?0:o,this._postProcesses[r]=this._postProcesses[r]||this._getPostProcess();var a=s.attachPostProcess(this._postProcesses[r]);this._indicesForCamera[o]||(this._indicesForCamera[o]=[]),this._indicesForCamera[o].push(a),-1===this._cameras.indexOf(s)&&(this._cameras[o]=s);for(var h in this._renderPasses)this._renderPasses[h]._incRefCount()}this._linkParameters()},t.prototype._detachCameras=function(t){for(var r=e.Tools.MakeArray(t||this._cameras),i=0;i<r.length;i++){var n=r[i],s=n.name;n.detachPostProcess(this._postProcesses[this._singleInstance?0:s],this._indicesForCamera[s]);var o=this._cameras.indexOf(s);this._indicesForCamera.splice(o,1),this._cameras.splice(o,1);for(var a in this._renderPasses)this._renderPasses[a]._decRefCount()}},t.prototype._enable=function(t){for(var r=e.Tools.MakeArray(t||this._cameras),i=0;i<r.length;i++){for(var n=r[i],s=n.name,o=0;o<this._indicesForCamera[s].length;o++)void 0===n._postProcesses[this._indicesForCamera[s][o]]&&t[i].attachPostProcess(this._postProcesses[this._singleInstance?0:s],this._indicesForCamera[s][o]);for(var a in this._renderPasses)this._renderPasses[a]._incRefCount()}},t.prototype._disable=function(t){for(var r=e.Tools.MakeArray(t||this._cameras),i=0;i<r.length;i++){var n=r[i],s=n.Name;n.detachPostProcess(this._postProcesses[this._singleInstance?0:s],this._indicesForCamera[s]);for(var o in this._renderPasses)this._renderPasses[o]._decRefCount()}},t.prototype.getPostProcess=function(e){return this._singleInstance?this._postProcesses[0]:this._postProcesses[e.name]},t.prototype._linkParameters=function(){var e=this;for(var t in this._postProcesses)this.applyParameters&&this.applyParameters(this._postProcesses[t]),this._postProcesses[t].onBeforeRender=function(t){e._linkTextures(t)}},t.prototype._linkTextures=function(e){for(var t in this._renderPasses)e.setTexture(t,this._renderPasses[t].getRenderTexture());for(var r in this._renderEffectAsPasses)e.setTextureFromPostProcess(r+"Sampler",this._renderEffectAsPasses[r].getPostProcess())},t}();e.PostProcessRenderEffect=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t){this._engine=e,this._name=t,this._renderEffects={},this._renderEffectsForIsolatedPass={},this._cameras=[]}return Object.defineProperty(t.prototype,"isSupported",{get:function(){for(var e in this._renderEffects)if(!this._renderEffects[e].isSupported)return!1;return!0},enumerable:!0,configurable:!0}),t.prototype.addEffect=function(e){this._renderEffects[e._name]=e},t.prototype._enableEffect=function(t,r){var i=this._renderEffects[t];i&&i._enable(e.Tools.MakeArray(r||this._cameras))},t.prototype._disableEffect=function(t,r){var i=this._renderEffects[t];i&&i._disable(e.Tools.MakeArray(r||this._cameras))},t.prototype._attachCameras=function(t,r){var i,n=e.Tools.MakeArray(t||this._cameras),s=[];for(i=0;i<n.length;i++){var o=n[i],a=o.name;-1===this._cameras.indexOf(o)?this._cameras[a]=o:r&&s.push(i)}for(i=0;i<s.length;i++)t.splice(s[i],1);for(var h in this._renderEffects)this._renderEffects[h]._attachCameras(n)},t.prototype._detachCameras=function(t){var r=e.Tools.MakeArray(t||this._cameras);for(var i in this._renderEffects)this._renderEffects[i]._detachCameras(r);for(var n=0;n<r.length;n++)this._cameras.splice(this._cameras.indexOf(r[n]),1);
  17. },t.prototype._enableDisplayOnlyPass=function(r,i){var n,s=this,o=e.Tools.MakeArray(i||this._cameras),a=null;for(n in this._renderEffects)if(a=this._renderEffects[n].getPass(r),null!=a)break;if(null!==a){for(n in this._renderEffects)this._renderEffects[n]._disable(o);a._name=t.PASS_SAMPLER_NAME;for(var h=0;h<o.length;h++){var c=o[h],l=c.name;this._renderEffectsForIsolatedPass[l]=this._renderEffectsForIsolatedPass[l]||new e.PostProcessRenderEffect(this._engine,t.PASS_EFFECT_NAME,function(){return new e.DisplayPassPostProcess(t.PASS_EFFECT_NAME,1,null,null,s._engine,!0)}),this._renderEffectsForIsolatedPass[l].emptyPasses(),this._renderEffectsForIsolatedPass[l].addPass(a),this._renderEffectsForIsolatedPass[l]._attachCameras(c)}}},t.prototype._disableDisplayOnlyPass=function(r){for(var i=this,n=e.Tools.MakeArray(r||this._cameras),s=0;s<n.length;s++){var o=n[s],a=o.name;this._renderEffectsForIsolatedPass[a]=this._renderEffectsForIsolatedPass[a]||new e.PostProcessRenderEffect(this._engine,t.PASS_EFFECT_NAME,function(){return new e.DisplayPassPostProcess(t.PASS_EFFECT_NAME,1,null,null,i._engine,!0)}),this._renderEffectsForIsolatedPass[a]._disable(o)}for(var h in this._renderEffects)this._renderEffects[h]._enable(n)},t.prototype._update=function(){for(var e in this._renderEffects)this._renderEffects[e]._update();for(var t=0;t<this._cameras.length;t++){var r=this._cameras[t].name;this._renderEffectsForIsolatedPass[r]&&this._renderEffectsForIsolatedPass[r]._update()}},t.prototype.dispose=function(){},t.PASS_EFFECT_NAME="passEffect",t.PASS_SAMPLER_NAME="passSampler",t}();e.PostProcessRenderPipeline=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this._renderPipelines={}}return e.prototype.addPipeline=function(e){this._renderPipelines[e._name]=e},e.prototype.attachCamerasToRenderPipeline=function(e,t,r){var i=this._renderPipelines[e];i&&i._attachCameras(t,r)},e.prototype.detachCamerasFromRenderPipeline=function(e,t){var r=this._renderPipelines[e];r&&r._detachCameras(t)},e.prototype.enableEffectInPipeline=function(e,t,r){var i=this._renderPipelines[e];i&&i._enableEffect(t,r)},e.prototype.disableEffectInPipeline=function(e,t,r){var i=this._renderPipelines[e];i&&i._disableEffect(t,r)},e.prototype.enableDisplayOnlyPassInPipeline=function(e,t,r){var i=this._renderPipelines[e];i&&i._enableDisplayOnlyPass(t,r)},e.prototype.disableDisplayOnlyPassInPipeline=function(e,t){var r=this._renderPipelines[e];r&&r._disableDisplayOnlyPass(t)},e.prototype.update=function(){for(var e in this._renderPipelines){var t=this._renderPipelines[e];t.isSupported?t._update():(t.dispose(),delete this._renderPipelines[e])}},e}();e.PostProcessRenderPipelineManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.frontColor=new e.Color3(1,1,1),this.backColor=new e.Color3(.1,.1,.1),this.showBackLines=!0,this.renderList=new e.SmartArray(32),this._scene=t}return t.prototype._prepareRessources=function(){if(!this._colorShader){this._colorShader=new e.ShaderMaterial("colorShader",this._scene,"color",{attributes:["position"],uniforms:["worldViewProjection","color"]});var t=this._scene.getEngine(),r=e.VertexData.CreateBox(1);this._vb=new e.VertexBuffer(t,r.positions,e.VertexBuffer.PositionKind,!1),this._ib=t.createIndexBuffer([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,7,1,6,2,5,3,4])}},t.prototype.reset=function(){this.renderList.reset()},t.prototype.render=function(){if(0!==this.renderList.length&&(this._prepareRessources(),this._colorShader.isReady())){var t=this._scene.getEngine();t.setDepthWrite(!1),this._colorShader._preBind();for(var r=0;r<this.renderList.length;r++){var i=this.renderList.data[r],n=i.minimum,s=i.maximum,o=s.subtract(n),a=n.add(o.scale(.5)),h=e.Matrix.Scaling(o.x,o.y,o.z).multiply(e.Matrix.Translation(a.x,a.y,a.z)).multiply(i.getWorldMatrix());t.bindBuffers(this._vb.getBuffer(),this._ib,[3],12,this._colorShader.getEffect()),this.showBackLines&&(t.setDepthFunctionToGreaterOrEqual(),this._scene.resetCachedMaterial(),this._colorShader.setColor4("color",this.backColor.toColor4()),this._colorShader.bind(h),t.draw(!1,0,24)),t.setDepthFunctionToLess(),this._scene.resetCachedMaterial(),this._colorShader.setColor4("color",this.frontColor.toColor4()),this._colorShader.bind(h),t.draw(!1,0,24)}this._colorShader.unbind(),t.setDepthFunctionToLessOrEqual(),t.setDepthWrite(!0)}},t.prototype.dispose=function(){this._colorShader&&(this._colorShader.dispose(),this._vb.dispose(),this._scene.getEngine()._releaseBuffer(this._ib))},t}();e.BoundingBoxRenderer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){this._actionManager=e}return e.prototype.isValid=function(){return!0},e.prototype._getProperty=function(e){return this._actionManager._getProperty(e)},e.prototype._getEffectiveTarget=function(e,t){return this._actionManager._getEffectiveTarget(e,t)},e}();e.Condition=t;var r=function(e){function t(r,i,n,s,o){void 0===o&&(o=t.IsEqual),e.call(this,r),this.propertyPath=n,this.value=s,this.operator=o,this._target=this._getEffectiveTarget(i,this.propertyPath),this._property=this._getProperty(this.propertyPath)}return __extends(t,e),Object.defineProperty(t,"IsEqual",{get:function(){return t._IsEqual},enumerable:!0,configurable:!0}),Object.defineProperty(t,"IsDifferent",{get:function(){return t._IsDifferent},enumerable:!0,configurable:!0}),Object.defineProperty(t,"IsGreater",{get:function(){return t._IsGreater},enumerable:!0,configurable:!0}),Object.defineProperty(t,"IsLesser",{get:function(){return t._IsLesser},enumerable:!0,configurable:!0}),t.prototype.isValid=function(){switch(this.operator){case t.IsGreater:return this._target[this._property]>this.value;case t.IsLesser:return this._target[this._property]<this.value;case t.IsEqual:case t.IsDifferent:var e;return e=this.value.equals?this.value.equals(this._target[this._property]):this.value===this._target[this._property],this.operator===t.IsEqual?e:!e}return!1},t._IsEqual=0,t._IsDifferent=1,t._IsGreater=2,t._IsLesser=3,t}(t);e.ValueCondition=r;var i=function(e){function t(t,r){e.call(this,t),this.predicate=r}return __extends(t,e),t.prototype.isValid=function(){return this.predicate()},t}(t);e.PredicateCondition=i;var n=function(e){function t(t,r,i){e.call(this,t),this.value=i,this._target=r}return __extends(t,e),t.prototype.isValid=function(){return this._target.state===this.value},t}(t);e.StateCondition=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t){this.triggerOptions=e,e.parameter?(this.trigger=e.trigger,this._triggerParameter=e.parameter):this.trigger=e,this._nextActiveAction=this,this._condition=t}return e.prototype._prepare=function(){},e.prototype.getTriggerParameter=function(){return this._triggerParameter},e.prototype._executeCurrent=function(e){if(this._nextActiveAction._condition){var t=this._nextActiveAction._condition,r=this._actionManager.getScene().getRenderId();if(t._evaluationId===r){if(!t._currentResult)return}else{if(t._evaluationId=r,!t.isValid())return void(t._currentResult=!1);t._currentResult=!0}}this._nextActiveAction.execute(e),this.skipToNextActiveAction()},e.prototype.execute=function(e){},e.prototype.skipToNextActiveAction=function(){this._nextActiveAction._child?(this._nextActiveAction._child._actionManager||(this._nextActiveAction._child._actionManager=this._actionManager),this._nextActiveAction=this._nextActiveAction._child):this._nextActiveAction=this},e.prototype.then=function(e){return this._child=e,e._actionManager=this._actionManager,e._prepare(),e},e.prototype._getProperty=function(e){return this._actionManager._getProperty(e)},e.prototype._getEffectiveTarget=function(e,t){return this._actionManager._getEffectiveTarget(e,t)},e}();e.Action=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,r,i,n,s){this.source=e,this.pointerX=t,this.pointerY=r,this.meshUnderPointer=i,this.sourceEvent=n,this.additionalData=s}return e.CreateNew=function(t,r,i){var n=t.getScene();return new e(t,n.pointerX,n.pointerY,n.meshUnderPointer,r,i)},e.CreateNewFromSprite=function(t,r,i,n){return new e(t,r.pointerX,r.pointerY,r.meshUnderPointer,i,n)},e.CreateNewFromScene=function(t,r){return new e(null,t.pointerX,t.pointerY,t.meshUnderPointer,r)},e}();e.ActionEvent=t;var r=function(){function t(e){this.actions=new Array,this._scene=e,e._actionManagers.push(this)}return Object.defineProperty(t,"NothingTrigger",{get:function(){return t._NothingTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPickTrigger",{get:function(){return t._OnPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnLeftPickTrigger",{get:function(){return t._OnLeftPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnRightPickTrigger",{get:function(){return t._OnRightPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnCenterPickTrigger",{get:function(){return t._OnCenterPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPickDownTrigger",{get:function(){return t._OnPickDownTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPickUpTrigger",{get:function(){return t._OnPickUpTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnLongPressTrigger",{get:function(){return t._OnLongPressTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPointerOverTrigger",{get:function(){return t._OnPointerOverTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPointerOutTrigger",{get:function(){return t._OnPointerOutTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnEveryFrameTrigger",{get:function(){return t._OnEveryFrameTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnIntersectionEnterTrigger",{get:function(){return t._OnIntersectionEnterTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnIntersectionExitTrigger",{get:function(){return t._OnIntersectionExitTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnKeyDownTrigger",{get:function(){return t._OnKeyDownTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnKeyUpTrigger",{get:function(){return t._OnKeyUpTrigger},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){var e=this._scene._actionManagers.indexOf(this);e>-1&&this._scene._actionManagers.splice(e,1)},t.prototype.getScene=function(){return this._scene},t.prototype.hasSpecificTriggers=function(e){for(var t=0;t<this.actions.length;t++){var r=this.actions[t];if(e.indexOf(r.trigger)>-1)return!0}return!1},t.prototype.hasSpecificTrigger=function(e){for(var t=0;t<this.actions.length;t++){var r=this.actions[t];if(r.trigger===e)return!0}return!1},Object.defineProperty(t.prototype,"hasPointerTriggers",{get:function(){for(var e=0;e<this.actions.length;e++){var r=this.actions[e];if(r.trigger>=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<this.actions.length;e++){var r=this.actions[e];if(r.trigger>=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;i<this.actions.length;i++){var n=this.actions[i];if(n.trigger===e){if(e===t.OnKeyUpTrigger||e===t.OnKeyDownTrigger){var s=n.getTriggerParameter();if(s){var o=r.sourceEvent.charCode?r.sourceEvent.charCode:r.sourceEvent.keyCode,a=String.fromCharCode(o).toLowerCase();if(a!==s.toLowerCase())continue}}n._executeCurrent(r)}}},t.prototype._getEffectiveTarget=function(e,t){for(var r=t.split("."),i=0;i<r.length-1;i++)e=e[r[i]];return e},t.prototype._getProperty=function(e){var t=e.split(".");return t[t.length-1]},t.Parse=function(r,i,n){var s=new e.ActionManager(n);null===i?n.actionManager=s:i.actionManager=s;for(var o=function(t,r){var i=Object.create(e[t].prototype);return i.constructor.apply(i,r),i},a=function(t,r,i,n){if(null===n){var s=parseFloat(r);return"true"===r||"false"===r?"true"===r:isNaN(s)?r:s}for(var o=n.split("."),a=r.split(","),h=0;h<o.length;h++)i=i[o[h]];if("boolean"==typeof i)return"true"===a[0];if("string"==typeof i)return a[0];for(var c=new Array,h=0;h<a.length;h++)c.push(parseFloat(a[h]));return i instanceof e.Vector3?e.Vector3.FromArray(c):i instanceof e.Vector4?e.Vector4.FromArray(c):i instanceof e.Color3?e.Color3.FromArray(c):i instanceof e.Color4?e.Color4.FromArray(c):parseFloat(a[0])},h=function(r,i,c,l,u){if(void 0===u&&(u=null),!r.detached){var f=new Array,d=null,p=null,m=r.combine&&r.combine.length>0;if(2===r.type?f.push(s):f.push(i),m){for(var g=new Array,_=0;_<r.combine.length;_++)h(r.combine[_],t.NothingTrigger,c,l,g);f.push(g)}else for(var v=0;v<r.properties.length;v++){var y=r.properties[v].value,x=r.properties[v].name,E=r.properties[v].targetType;"target"===x?y=d=null!==E&&"SceneProperties"===E?n:n.getNodeByName(y):"parent"===x?y=n.getNodeByName(y):"sound"===x?y=n.getSoundByName(y):"propertyPath"!==x?y=2===r.type&&"operator"===x?e.ValueCondition[y]:a(x,y,d,"value"===x?p:null):p=y,f.push(y)}if(null===u?f.push(c):f.push(null),"InterpolateValueAction"===r.name){var T=f[f.length-2];f[f.length-1]=T,f[f.length-2]=c}var A=o(r.name,f);if(A instanceof e.Condition&&null!==c){var b=new e.DoNothingAction(i,c);l?l.then(b):s.registerAction(b),l=b}null===u?A instanceof e.Condition?(c=A,A=l):(c=null,l?l.then(A):s.registerAction(A)):u.push(A);for(var v=0;v<r.children.length;v++)h(r.children[v],i,c,A,null)}},c=0;c<r.children.length;c++){var l,u=r.children[c];if(u.properties.length>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;p<u.children.length;p++)u.detached||h(u.children[p],l,null,null)}},t._NothingTrigger=0,t._OnPickTrigger=1,t._OnLeftPickTrigger=2,t._OnRightPickTrigger=3,t._OnCenterPickTrigger=4,t._OnPickDownTrigger=5,t._OnPickUpTrigger=6,t._OnLongPressTrigger=7,t._OnPointerOverTrigger=8,t._OnPointerOutTrigger=9,t._OnEveryFrameTrigger=10,t._OnIntersectionEnterTrigger=11,t._OnIntersectionExitTrigger=12,t._OnKeyDownTrigger=13,t._OnKeyUpTrigger=14,t.DragMovementThreshold=10,t.LongPressDelay=500,t}();e.ActionManager=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(e,r,i,n,s,o,a,h){void 0===s&&(s=1e3),t.call(this,e,o),this.propertyPath=i,this.value=n,this.duration=s,this.stopOtherAnimations=a,this.onInterpolationDone=h,this._target=r}return __extends(r,t),r.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath)},r.prototype.execute=function(){var t,r=this._actionManager.getScene(),i=[{frame:0,value:this._target[this._property]},{frame:100,value:this.value}];if("number"==typeof this.value)t=e.Animation.ANIMATIONTYPE_FLOAT;else if(this.value instanceof e.Color3)t=e.Animation.ANIMATIONTYPE_COLOR3;else if(this.value instanceof e.Vector3)t=e.Animation.ANIMATIONTYPE_VECTOR3;else if(this.value instanceof e.Matrix)t=e.Animation.ANIMATIONTYPE_MATRIX;else{if(!(this.value instanceof e.Quaternion))return void e.Tools.Warn("InterpolateValueAction: Unsupported type ("+typeof this.value+")");t=e.Animation.ANIMATIONTYPE_QUATERNION}var n=new e.Animation("InterpolateValueAction",this._property,100*(1e3/this.duration),t,e.Animation.ANIMATIONLOOPMODE_CONSTANT);n.setKeys(i),this.stopOtherAnimations&&r.stopAnimation(this._target),r.beginDirectAnimation(this._target,[n],0,100,!1,1,this.onInterpolationDone)},r}(e.Action);e.InterpolateValueAction=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,r,i,n){e.call(this,t,n),this.propertyPath=i,this._target=r}return __extends(t,e),t.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath)},t.prototype.execute=function(){this._target[this._property]=!this._target[this._property]},t}(e.Action);e.SwitchBooleanAction=t;var r=function(e){function t(t,r,i,n){e.call(this,t,n),this.value=i,this._target=r}return __extends(t,e),t.prototype.execute=function(){this._target.state=this.value},t}(e.Action);e.SetStateAction=r;var i=function(e){function t(t,r,i,n,s){e.call(this,t,s),this.propertyPath=i,this.value=n,this._target=r}return __extends(t,e),t.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath)},t.prototype.execute=function(){this._target[this._property]=this.value},t}(e.Action);e.SetValueAction=i;var n=function(t){function r(e,r,i,n,s){t.call(this,e,s),this.propertyPath=i,this.value=n,this._target=r}return __extends(r,t),r.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath),"number"!=typeof this._target[this._property]&&e.Tools.Warn("Warning: IncrementValueAction can only be used with number values")},r.prototype.execute=function(){this._target[this._property]+=this.value},r}(e.Action);e.IncrementValueAction=n;var s=function(e){function t(t,r,i,n,s,o){e.call(this,t,o),this.from=i,this.to=n,this.loop=s,this._target=r}return __extends(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){var e=this._actionManager.getScene();e.beginAnimation(this._target,this.from,this.to,this.loop)},t}(e.Action);e.PlayAnimationAction=s;var o=function(e){function t(t,r,i){e.call(this,t,i),this._target=r}return __extends(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){var e=this._actionManager.getScene();e.stopAnimation(this._target)},t}(e.Action);e.StopAnimationAction=o;var a=function(t){function r(r,i){void 0===r&&(r=e.ActionManager.NothingTrigger),t.call(this,r,i)}return __extends(r,t),r.prototype.execute=function(){},r}(e.Action);e.DoNothingAction=a;var h=function(e){function t(t,r,i){e.call(this,t,i),this.children=r}return __extends(t,e),t.prototype._prepare=function(){for(var e=0;e<this.children.length;e++)this.children[e]._actionManager=this._actionManager,this.children[e]._prepare()},t.prototype.execute=function(e){for(var t=0;t<this.children.length;t++)this.children[t].execute(e)},t}(e.Action);e.CombineAction=h;var c=function(e){function t(t,r,i){e.call(this,t,i),this.func=r}return __extends(t,e),t.prototype.execute=function(e){this.func(e)},t}(e.Action);e.ExecuteCodeAction=c;var l=function(t){function r(e,r,i,n){t.call(this,e,n),this._target=r,this._parent=i}return __extends(r,t),r.prototype._prepare=function(){},r.prototype.execute=function(){if(this._target.parent!==this._parent){var t=this._parent.getWorldMatrix().clone();t.invert(),this._target.position=e.Vector3.TransformCoordinates(this._target.position,t),this._target.parent=this._parent}},r}(e.Action);e.SetParentAction=l;var u=function(e){function t(t,r,i){e.call(this,t,i),this._sound=r}return __extends(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){void 0!==this._sound&&this._sound.play()},t}(e.Action);e.PlaySoundAction=u;var f=function(e){function t(t,r,i){e.call(this,t,i),this._sound=r}return __extends(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){void 0!==this._sound&&this._sound.stop()},t}(e.Action);e.StopSoundAction=f}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,r,i,n,s){this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this._totalVertices=0,this._isDisposed=!1,this.id=t,this._engine=r.getEngine(),this._meshes=[],this._scene=r,this._vertexBuffers={},this._indices=[],i?this.setAllVerticesData(i,n):(this._totalVertices=0,this._indices=[]),s&&(this.applyToMesh(s),s.computeWorldMatrix(!0))}return Object.defineProperty(t.prototype,"extend",{get:function(){return this._extend},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},t.prototype.getEngine=function(){return this._engine},t.prototype.isReady=function(){return this.delayLoadState===e.Engine.DELAYLOADSTATE_LOADED||this.delayLoadState===e.Engine.DELAYLOADSTATE_NONE},t.prototype.setAllVerticesData=function(e,t){e.applyToGeometry(this,t),this.notifyUpdate()},t.prototype.setVerticesData=function(t,r,i,n){if(this._vertexBuffers[t]&&this._vertexBuffers[t].dispose(),this._vertexBuffers[t]=new e.VertexBuffer(this._engine,r,t,i,0===this._meshes.length,n),t===e.VertexBuffer.PositionKind){n=this._vertexBuffers[t].getStrideSize(),this._totalVertices=r.length/n,this._extend=e.Tools.ExtractMinAndMax(r,0,this._totalVertices);for(var s=this._meshes,o=s.length,a=0;o>a;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;l<c.subMeshes.length;l++){var u=c.subMeshes[l];u.refreshBoundingInfo()}}}}this.notifyUpdate(t)}},t.prototype.getTotalVertices=function(){return this.isReady()?this._totalVertices:0},t.prototype.getVerticesData=function(e,t){var r=this.getVertexBuffer(e);if(!r)return null;var i=r.getData();if(t&&1!==this._meshes.length){for(var n=i.length,s=[],o=0;n>o;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;s<n.length;s++)i.indices.push(n[s]);var o,a=!1,h=!1;for(o in this._vertexBuffers){var c=this.getVerticesData(o);c instanceof Float32Array?i.set(new Float32Array(c),o):i.set(c.slice(0),o),h||(a=this.getVertexBuffer(o).isUpdatable(),h=!a)}var l=new t(r,this._scene,i,a,null);l.delayLoadState=this.delayLoadState,l.delayLoadingFile=this.delayLoadingFile,l._delayLoadingFunction=this._delayLoadingFunction;for(o in this._delayInfo)l._delayInfo=l._delayInfo||[],l._delayInfo.push(o);return l._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),l},t.prototype.serialize=function(){var t={};return t.id=this.id,e.Tags.HasTags(this)&&(t.tags=e.Tags.GetTags(this)),t},t.prototype.serializeVerticeData=function(){var t=this.serialize();return this.isVerticesDataPresent(e.VertexBuffer.PositionKind)&&(t.positions=this.getVerticesData(e.VertexBuffer.PositionKind)),this.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(t.normals=this.getVerticesData(e.VertexBuffer.NormalKind)),this.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(t.uvs=this.getVerticesData(e.VertexBuffer.UVKind)),this.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(t.uvs2=this.getVerticesData(e.VertexBuffer.UV2Kind)),this.isVerticesDataPresent(e.VertexBuffer.UV3Kind)&&(t.uvs3=this.getVerticesData(e.VertexBuffer.UV3Kind)),this.isVerticesDataPresent(e.VertexBuffer.UV4Kind)&&(t.uvs4=this.getVerticesData(e.VertexBuffer.UV4Kind)),this.isVerticesDataPresent(e.VertexBuffer.UV5Kind)&&(t.uvs5=this.getVerticesData(e.VertexBuffer.UV5Kind)),this.isVerticesDataPresent(e.VertexBuffer.UV6Kind)&&(t.uvs6=this.getVerticesData(e.VertexBuffer.UV6Kind)),this.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(t.colors=this.getVerticesData(e.VertexBuffer.ColorKind)),this.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&(t.matricesIndices=this.getVerticesData(e.VertexBuffer.MatricesIndicesKind),t.matricesIndices._isExpanded=!0),this.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)&&(t.matricesWeights=this.getVerticesData(e.VertexBuffer.MatricesWeightsKind)),t.indices=this.getIndices(),t},t.ExtractFromMesh=function(e,t){var r=e._geometry;return r?r.copy(t):null},t.RandomId=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0,r="x"===e?t:3&t|8;return r.toString(16)})},t.ImportGeometry=function(t,r){var i=r.getScene(),n=t.geometryId;if(n){var s=i.getGeometryByID(n);s&&s.applyToMesh(r)}else if(t instanceof ArrayBuffer){var o=r._binaryInfo;if(o.positionsAttrDesc&&o.positionsAttrDesc.count>0){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<o.subMeshesAttrDesc.count;x++){var E=y[5*x+0],T=y[5*x+1],A=y[5*x+2],b=y[5*x+3],M=y[5*x+4];new e.SubMesh(E,T,A,b,M,r)}}}else if(t.positions&&t.normals&&t.indices){if(r.setVerticesData(e.VertexBuffer.PositionKind,t.positions,!1),r.setVerticesData(e.VertexBuffer.NormalKind,t.normals,!1),t.uvs&&r.setVerticesData(e.VertexBuffer.UVKind,t.uvs,!1),t.uvs2&&r.setVerticesData(e.VertexBuffer.UV2Kind,t.uvs2,!1),t.uvs3&&r.setVerticesData(e.VertexBuffer.UV3Kind,t.uvs3,!1),t.uvs4&&r.setVerticesData(e.VertexBuffer.UV4Kind,t.uvs4,!1),t.uvs5&&r.setVerticesData(e.VertexBuffer.UV5Kind,t.uvs5,!1),t.uvs6&&r.setVerticesData(e.VertexBuffer.UV6Kind,t.uvs6,!1),t.colors&&r.setVerticesData(e.VertexBuffer.ColorKind,e.Color4.CheckColors4(t.colors,t.positions.length/3),!1),t.matricesIndices)if(t.matricesIndices._isExpanded)delete t.matricesIndices._isExpanded,r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,t.matricesIndices,!1);else{for(var P=[],x=0;x<t.matricesIndices.length;x++){var S=t.matricesIndices[x];P.push(255&S),P.push((65280&S)>>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<t.matricesIndicesExtra.length;x++){var S=t.matricesIndicesExtra[x];P.push(255&S),P.push((65280&S)>>8),P.push((16711680&S)>>16),P.push(S>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,P,!1);
  18. }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;C<t.subMeshes.length;C++){var I=t.subMeshes[C];new e.SubMesh(I.materialIndex,I.verticesStart,I.verticesCount,I.indexStart,I.indexCount,r)}}r._shouldGenerateFlatShading&&(r.convertToFlatShadedMesh(),delete r._shouldGenerateFlatShading),r.computeWorldMatrix(!0),i._selectionOctree&&i._selectionOctree.addMesh(r)},t.Parse=function(r,i,n){if(i.getGeometryByID(r.id))return null;var s=new t(r.id,i);return e.Tags.AddTagsTo(s,r.tags),r.delayLoadingFile?(s.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,s.delayLoadingFile=n+r.delayLoadingFile,s._boundingInfo=new e.BoundingInfo(e.Vector3.FromArray(r.boundingBoxMinimum),e.Vector3.FromArray(r.boundingBoxMaximum)),s._delayInfo=[],r.hasUVs&&s._delayInfo.push(e.VertexBuffer.UVKind),r.hasUVs2&&s._delayInfo.push(e.VertexBuffer.UV2Kind),r.hasUVs3&&s._delayInfo.push(e.VertexBuffer.UV3Kind),r.hasUVs4&&s._delayInfo.push(e.VertexBuffer.UV4Kind),r.hasUVs5&&s._delayInfo.push(e.VertexBuffer.UV5Kind),r.hasUVs6&&s._delayInfo.push(e.VertexBuffer.UV6Kind),r.hasColors&&s._delayInfo.push(e.VertexBuffer.ColorKind),r.hasMatricesIndices&&s._delayInfo.push(e.VertexBuffer.MatricesIndicesKind),r.hasMatricesWeights&&s._delayInfo.push(e.VertexBuffer.MatricesWeightsKind),s._delayLoadingFunction=e.VertexData.ImportVertexData):e.VertexData.ImportVertexData(r,s),i.pushGeometry(s,!0),s},t}();e.Geometry=t;var t;!function(t){var r;!function(r){var i=function(e){function t(t,r,i,n,s){this._beingRegenerated=!0,this._canBeRegenerated=n,e.call(this,t,r,i,!1,s),this._beingRegenerated=!1}return __extends(t,e),t.prototype.canBeRegenerated=function(){return this._canBeRegenerated},t.prototype.regenerate=function(){this._canBeRegenerated&&(this._beingRegenerated=!0,this.setAllVerticesData(this._regenerateVertexData(),!1),this._beingRegenerated=!1)},t.prototype.asNewGeometry=function(t){return e.prototype.copy.call(this,t)},t.prototype.setAllVerticesData=function(t,r){this._beingRegenerated&&e.prototype.setAllVerticesData.call(this,t,!1)},t.prototype.setVerticesData=function(t,r,i){this._beingRegenerated&&e.prototype.setVerticesData.call(this,t,r,!1)},t.prototype._regenerateVertexData=function(){throw new Error("Abstract method")},t.prototype.copy=function(e){throw new Error("Must be overriden in sub-classes.")},t.prototype.serialize=function(){var t=e.prototype.serialize.call(this);return t.canBeRegenerated=this.canBeRegenerated(),t},t}(t);r._Primitive=i;var n=function(t){function r(r,i,n,s,o,a,h,c,l){void 0===l&&(l=e.Mesh.DEFAULTSIDE),this.pathArray=n,this.closeArray=s,this.closePath=o,this.offset=a,this.side=l,t.call(this,r,i,this._regenerateVertexData(),h,c)}return __extends(r,t),r.prototype._regenerateVertexData=function(){return e.VertexData.CreateRibbon({pathArray:this.pathArray,closeArray:this.closeArray,closePath:this.closePath,offset:this.offset,sideOrientation:this.side})},r.prototype.copy=function(e){return new r(e,this.getScene(),this.pathArray,this.closeArray,this.closePath,this.offset,this.canBeRegenerated(),null,this.side)},r}(i);r.Ribbon=n;var s=function(r){function i(t,i,n,s,o,a){void 0===a&&(a=e.Mesh.DEFAULTSIDE),this.size=n,this.side=a,r.call(this,t,i,this._regenerateVertexData(),s,o)}return __extends(i,r),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateBox({size:this.size,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.size,this.canBeRegenerated(),null,this.side)},i.prototype.serialize=function(){var e=r.prototype.serialize.call(this);return e.size=this.size,e},i.Parse=function(r,i){if(i.getGeometryByID(r.id))return null;var n=new t.Primitives.Box(r.id,i,r.size,r.canBeRegenerated,null);return e.Tags.AddTagsTo(n,r.tags),i.pushGeometry(n,!0),n},i}(i);r.Box=s;var o=function(r){function i(t,i,n,s,o,a,h){void 0===h&&(h=e.Mesh.DEFAULTSIDE),this.segments=n,this.diameter=s,this.side=h,r.call(this,t,i,this._regenerateVertexData(),o,a)}return __extends(i,r),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateSphere({segments:this.segments,diameter:this.diameter,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.segments,this.diameter,this.canBeRegenerated(),null,this.side)},i.prototype.serialize=function(){var e=r.prototype.serialize.call(this);return e.segments=this.segments,e.diameter=this.diameter,e},i.Parse=function(r,i){if(i.getGeometryByID(r.id))return null;var n=new t.Primitives.Sphere(r.id,i,r.segments,r.diameter,r.canBeRegenerated,null);return e.Tags.AddTagsTo(n,r.tags),i.pushGeometry(n,!0),n},i}(i);r.Sphere=o;var a=function(t){function r(r,i,n,s,o,a,h){void 0===h&&(h=e.Mesh.DEFAULTSIDE),this.radius=n,this.tessellation=s,this.side=h,t.call(this,r,i,this._regenerateVertexData(),o,a)}return __extends(r,t),r.prototype._regenerateVertexData=function(){return e.VertexData.CreateDisc({radius:this.radius,tessellation:this.tessellation,sideOrientation:this.side})},r.prototype.copy=function(e){return new r(e,this.getScene(),this.radius,this.tessellation,this.canBeRegenerated(),null,this.side)},r}(i);r.Disc=a;var h=function(r){function i(t,i,n,s,o,a,h,c,l,u){void 0===h&&(h=1),void 0===u&&(u=e.Mesh.DEFAULTSIDE),this.height=n,this.diameterTop=s,this.diameterBottom=o,this.tessellation=a,this.subdivisions=h,this.side=u,r.call(this,t,i,this._regenerateVertexData(),c,l)}return __extends(i,r),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateCylinder({height:this.height,diameterTop:this.diameterTop,diameterBottom:this.diameterBottom,tessellation:this.tessellation,subdivisions:this.subdivisions,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.height,this.diameterTop,this.diameterBottom,this.tessellation,this.subdivisions,this.canBeRegenerated(),null,this.side)},i.prototype.serialize=function(){var e=r.prototype.serialize.call(this);return e.height=this.height,e.diameterTop=this.diameterTop,e.diameterBottom=this.diameterBottom,e.tessellation=this.tessellation,e},i.Parse=function(r,i){if(i.getGeometryByID(r.id))return null;var n=new t.Primitives.Cylinder(r.id,i,r.height,r.diameterTop,r.diameterBottom,r.tessellation,r.subdivisions,r.canBeRegenerated,null);return e.Tags.AddTagsTo(n,r.tags),i.pushGeometry(n,!0),n},i}(i);r.Cylinder=h;var c=function(r){function i(t,i,n,s,o,a,h,c){void 0===c&&(c=e.Mesh.DEFAULTSIDE),this.diameter=n,this.thickness=s,this.tessellation=o,this.side=c,r.call(this,t,i,this._regenerateVertexData(),a,h)}return __extends(i,r),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateTorus({diameter:this.diameter,thickness:this.thickness,tessellation:this.tessellation,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.diameter,this.thickness,this.tessellation,this.canBeRegenerated(),null,this.side)},i.prototype.serialize=function(){var e=r.prototype.serialize.call(this);return e.diameter=this.diameter,e.thickness=this.thickness,e.tessellation=this.tessellation,e},i.Parse=function(r,i){if(i.getGeometryByID(r.id))return null;var n=new t.Primitives.Torus(r.id,i,r.diameter,r.thickness,r.tessellation,r.canBeRegenerated,null);return e.Tags.AddTagsTo(n,r.tags),i.pushGeometry(n,!0),n},i}(i);r.Torus=c;var l=function(r){function i(e,t,i,n,s,o,a){this.width=i,this.height=n,this.subdivisions=s,r.call(this,e,t,this._regenerateVertexData(),o,a)}return __extends(i,r),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateGround({width:this.width,height:this.height,subdivisions:this.subdivisions})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.width,this.height,this.subdivisions,this.canBeRegenerated(),null)},i.prototype.serialize=function(){var e=r.prototype.serialize.call(this);return e.width=this.width,e.height=this.height,e.subdivisions=this.subdivisions,e},i.Parse=function(r,i){if(i.getGeometryByID(r.id))return null;var n=new t.Primitives.Ground(r.id,i,r.width,r.height,r.subdivisions,r.canBeRegenerated,null);return e.Tags.AddTagsTo(n,r.tags),i.pushGeometry(n,!0),n},i}(i);r.Ground=l;var u=function(t){function r(e,r,i,n,s,o,a,h,c,l){this.xmin=i,this.zmin=n,this.xmax=s,this.zmax=o,this.subdivisions=a,this.precision=h,t.call(this,e,r,this._regenerateVertexData(),c,l)}return __extends(r,t),r.prototype._regenerateVertexData=function(){return e.VertexData.CreateTiledGround({xmin:this.xmin,zmin:this.zmin,xmax:this.xmax,zmax:this.zmax,subdivisions:this.subdivisions,precision:this.precision})},r.prototype.copy=function(e){return new r(e,this.getScene(),this.xmin,this.zmin,this.xmax,this.zmax,this.subdivisions,this.precision,this.canBeRegenerated(),null)},r}(i);r.TiledGround=u;var f=function(r){function i(t,i,n,s,o,a){void 0===a&&(a=e.Mesh.DEFAULTSIDE),this.size=n,this.side=a,r.call(this,t,i,this._regenerateVertexData(),s,o)}return __extends(i,r),i.prototype._regenerateVertexData=function(){return e.VertexData.CreatePlane({size:this.size,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.size,this.canBeRegenerated(),null,this.side)},i.prototype.serialize=function(){var e=r.prototype.serialize.call(this);return e.size=this.size,e},i.Parse=function(r,i){if(i.getGeometryByID(r.id))return null;var n=new t.Primitives.Plane(r.id,i,r.size,r.canBeRegenerated,null);return e.Tags.AddTagsTo(n,r.tags),i.pushGeometry(n,!0),n},i}(i);r.Plane=f;var d=function(r){function i(t,i,n,s,o,a,h,c,l,u,f){void 0===f&&(f=e.Mesh.DEFAULTSIDE),this.radius=n,this.tube=s,this.radialSegments=o,this.tubularSegments=a,this.p=h,this.q=c,this.side=f,r.call(this,t,i,this._regenerateVertexData(),l,u)}return __extends(i,r),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateTorusKnot({radius:this.radius,tube:this.tube,radialSegments:this.radialSegments,tubularSegments:this.tubularSegments,p:this.p,q:this.q,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.radius,this.tube,this.radialSegments,this.tubularSegments,this.p,this.q,this.canBeRegenerated(),null,this.side)},i.prototype.serialize=function(){var e=r.prototype.serialize.call(this);return e.radius=this.radius,e.tube=this.tube,e.radialSegments=this.radialSegments,e.tubularSegments=this.tubularSegments,e.p=this.p,e.q=this.q,e},i.Parse=function(r,i){if(i.getGeometryByID(r.id))return null;var n=new t.Primitives.TorusKnot(r.id,i,r.radius,r.tube,r.radialSegments,r.tubularSegments,r.p,r.q,r.canBeRegenerated,null);return e.Tags.AddTagsTo(n,r.tags),i.pushGeometry(n,!0),n},i}(i);r.TorusKnot=d}(r=t.Primitives||(t.Primitives={}))}(t=e.Geometry||(e.Geometry={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i){t.call(this,r,i),this.generateOctree=!1,this._worldInverse=new e.Matrix}return __extends(r,t),Object.defineProperty(r.prototype,"subdivisions",{get:function(){return this._subdivisions},enumerable:!0,configurable:!0}),r.prototype.optimize=function(e,t){void 0===t&&(t=32),this._subdivisions=e,this.subdivide(this._subdivisions),this.createOrUpdateSubmeshesOctree(t)},r.prototype.getHeightAtCoordinates=function(e,t){if(e-=this.position.x,t-=this.position.z,e/=this.scaling.x,t/=this.scaling.z,e<this._minX||e>this._maxX||t<this._minZ||t>this._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,!(e<this._minX||e>this._maxX||t<this._minZ||t>this._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=t<s.slope.x*e+s.slope.y?s.facet1:s.facet2},r.prototype._computeHeightQuads=function(){this._heightQuads=new Array;for(var t=this.getVerticesData(e.VertexBuffer.PositionKind),r=e.Vector3.Zero(),i=e.Vector3.Zero(),n=e.Vector3.Zero(),s=e.Vector3.Zero(),o=e.Vector3.Zero(),a=e.Vector3.Zero(),h=e.Vector3.Zero(),c=e.Vector3.Zero(),l=e.Vector3.Zero(),u=0,f=0,d=0,p=0,m=0,g=0,_=0,v=0;v<this._subdivisions;v++)for(var y=0;y<this._subdivisions;y++){u=3*y,f=v*(this._subdivisions+1)*3,d=(v+1)*(this._subdivisions+1)*3,r.x=t[f+u],r.y=t[f+u+1],r.z=t[f+u+2],i.x=t[f+u+3],i.y=t[f+u+4],i.z=t[f+u+5],n.x=t[d+u],n.y=t[d+u+1],n.z=t[d+u+2],s.x=t[d+u+3],s.y=t[d+u+4],s.z=t[d+u+5],p=(s.z-r.z)/(s.x-r.x),m=r.z-p*r.x;var x=new e.Vector2(p,m);i.subtractToRef(r,o),n.subtractToRef(r,a),s.subtractToRef(r,h),e.Vector3.CrossToRef(h,a,c),e.Vector3.CrossToRef(o,h,l),c.normalize(),l.normalize(),g=-(c.x*r.x+c.y*r.y+c.z*r.z),_=-(l.x*i.x+l.y*i.y+l.z*i.z);var E=new e.Vector4(c.x,c.y,c.z,g),T=new e.Vector4(l.x,l.y,l.z,_),A={slope:x,facet1:E,facet2:T};this._heightQuads.push(A)}},r}(e.Mesh);e.GroundMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function r(r,i,n,s,o){void 0===n&&(n=null),t.call(this,r,i,n,s,o),this.color=new e.Color3(1,1,1),this.alpha=1,this._colorShader=new e.ShaderMaterial("colorShader",i,"color",{attributes:["position"],uniforms:["worldViewProjection","color"],needAlphaBlending:!0})}return __extends(r,t),Object.defineProperty(r.prototype,"material",{get:function(){return this._colorShader},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isPickable",{get:function(){return!1},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"checkCollisions",{get:function(){return!1},enumerable:!0,configurable:!0}),r.prototype._bind=function(t,r,i){var n=this.getScene().getEngine(),s=this._geometry.getIndexBuffer();n.bindBuffers(this._geometry.getVertexBuffer(e.VertexBuffer.PositionKind).getBuffer(),s,[3],12,this._colorShader.getEffect()),this._colorShader.setColor4("color",this.color.toColor4(this.alpha))},r.prototype._draw=function(e,t,r){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var i=this.getScene().getEngine();i.draw(!1,e.indexStart,e.indexCount)}},r.prototype.intersects=function(e,t){return null},r.prototype.dispose=function(e){this._colorShader.dispose(),t.prototype.dispose.call(this,e)},r.prototype.clone=function(e,t,i){return new r(e,this.getScene(),t,this,i)},r}(e.Mesh);e.LinesMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){var r=this;this._transformationMatrix=e.Matrix.Identity(),this._enabled=!1,this._labelsEnabled=!1,this._displayStatistics=!0,this._displayTree=!1,this._displayLogs=!1,this._identityMatrix=e.Matrix.Identity(),this.axisRatio=.02,this.accentColor="orange",this._scene=t,this._syncPositions=function(){var e=r._scene.getEngine(),t=e.getRenderingCanvasClientRect();r._showUI&&(r._statsDiv.style.left=t.width-410+"px",r._statsDiv.style.top=t.height-290+"px",r._statsDiv.style.width="400px",r._statsDiv.style.height="auto",r._statsSubsetDiv.style.maxHeight="240px",r._optionsDiv.style.left="0px",r._optionsDiv.style.top="10px",r._optionsDiv.style.width="200px",r._optionsDiv.style.height="auto",r._optionsSubsetDiv.style.maxHeight=t.height-225+"px",r._logDiv.style.left="0px",r._logDiv.style.top=t.height-170+"px",r._logDiv.style.width="600px",r._logDiv.style.height="160px",r._treeDiv.style.left=t.width-310+"px",r._treeDiv.style.top="10px",r._treeDiv.style.width="300px",r._treeDiv.style.height="auto",r._treeSubsetDiv.style.maxHeight=t.height-340+"px"),r._globalDiv.style.left=t.left+"px",r._globalDiv.style.top=t.top+"px",r._drawingCanvas.style.left="0px",r._drawingCanvas.style.top="0px",r._drawingCanvas.style.width=e.getRenderWidth()+"px",r._drawingCanvas.style.height=e.getRenderHeight()+"px";var i=window.devicePixelRatio||1,n=r._drawingContext,s=n.webkitBackingStorePixelRatio||n.mozBackingStorePixelRatio||n.msBackingStorePixelRatio||n.oBackingStorePixelRatio||n.backingStorePixelRatio||1;r._ratio=i/s,r._drawingCanvas.width=e.getRenderWidth()*r._ratio,r._drawingCanvas.height=e.getRenderHeight()*r._ratio},this._onCanvasClick=function(e){r._clickPosition={x:e.clientX*r._ratio,y:e.clientY*r._ratio}},this._syncUI=function(){r._showUI&&(r._displayStatistics?(r._displayStats(),r._statsDiv.style.display=""):r._statsDiv.style.display="none",r._displayLogs?r._logDiv.style.display="":r._logDiv.style.display="none",r._displayTree?(r._treeDiv.style.display="",r._needToRefreshMeshesTree&&(r._needToRefreshMeshesTree=!1,r._refreshMeshesTreeContent())):r._treeDiv.style.display="none")},this._syncData=function(){if(r._labelsEnabled||!r._showUI){r._camera.getViewMatrix().multiplyToRef(r._camera.getProjectionMatrix(),r._transformationMatrix),r._drawingContext.clearRect(0,0,r._drawingCanvas.width,r._drawingCanvas.height);var t,i,n=r._scene.getEngine(),s=r._camera.viewport,o=s.toGlobal(n),a=r._camera.getActiveMeshes();for(t=0;t<a.length;t++){var h=a.data[t],c=h.getBoundingInfo().boundingSphere.center;i=e.Vector3.Project(c,h.getWorldMatrix(),r._transformationMatrix,o),(h.renderOverlay||r.shouldDisplayAxis&&r.shouldDisplayAxis(h))&&r._renderAxis(i,h,o),(!r.shouldDisplayLabel||r.shouldDisplayLabel(h))&&r._renderLabel(h.name,i,12,function(){h.renderOverlay=!h.renderOverlay},function(){return h.renderOverlay?"red":"black"})}var l=r._scene.cameras;for(t=0;t<l.length;t++){var u=l[t];u!==r._camera&&(i=e.Vector3.Project(e.Vector3.Zero(),u.getWorldMatrix(),r._transformationMatrix,o),(!r.shouldDisplayLabel||r.shouldDisplayLabel(u))&&r._renderLabel(u.name,i,12,function(){r._camera.detachControl(n.getRenderingCanvas()),r._camera=u,r._camera.attachControl(n.getRenderingCanvas())},function(){return"purple"}))}var f=r._scene.lights;for(t=0;t<f.length;t++){var d=f[t];d.position&&(i=e.Vector3.Project(d.getAbsolutePosition(),r._identityMatrix,r._transformationMatrix,o),(!r.shouldDisplayLabel||r.shouldDisplayLabel(d))&&r._renderLabel(d.name,i,-20,function(){d.setEnabled(!d.isEnabled())},function(){return d.isEnabled()?"orange":"gray"}))}}r._clickPosition=void 0}}return t.prototype._refreshMeshesTreeContent=function(){for(;this._treeSubsetDiv.hasChildNodes();)this._treeSubsetDiv.removeChild(this._treeSubsetDiv.lastChild);var e=this._scene.meshes.slice(0,this._scene.meshes.length);e.sort(function(e,t){return e.name===t.name?0:e.name>t.name?1:-1});for(var t=0;t<e.length;t++){var r=e[t];r.isEnabled()&&this._generateAdvancedCheckBox(this._treeSubsetDiv,r.name,r.getTotalVertices()+" verts",r.isVisible,function(e,t){t.isVisible=e.checked},r)}},t.prototype._renderSingleAxis=function(e,t,r,i,n){this._drawingContext.beginPath(),this._drawingContext.moveTo(e.x,e.y),this._drawingContext.lineTo(t.x,t.y),this._drawingContext.strokeStyle=n,this._drawingContext.lineWidth=4,this._drawingContext.stroke(),this._drawingContext.font="normal 14px Segoe UI",this._drawingContext.fillStyle=n,this._drawingContext.fillText(i,r.x,r.y)},t.prototype._renderAxis=function(t,r,i){var n=r.getBoundingInfo().boundingSphere.center,s=r.getWorldMatrix(),o=e.Vector3.UnprojectFromTransform(t.add(new e.Vector3(this._drawingCanvas.width*this.axisRatio,0,0)),i.width,i.height,s,this._transformationMatrix),a=o.subtract(n).length(),h=e.Vector3.Project(n.add(new e.Vector3(a,0,0)),s,this._transformationMatrix,i),c=e.Vector3.Project(n.add(new e.Vector3(1.5*a,0,0)),s,this._transformationMatrix,i);this._renderSingleAxis(t,h,c,"x","#FF0000");var l=e.Vector3.Project(n.add(new e.Vector3(0,a,0)),s,this._transformationMatrix,i),u=e.Vector3.Project(n.add(new e.Vector3(0,1.5*a,0)),s,this._transformationMatrix,i);this._renderSingleAxis(t,l,u,"y","#00FF00");var f=e.Vector3.Project(n.add(new e.Vector3(0,0,a)),s,this._transformationMatrix,i),d=e.Vector3.Project(n.add(new e.Vector3(0,0,1.5*a)),s,this._transformationMatrix,i);this._renderSingleAxis(t,f,d,"z","#0000FF")},t.prototype._renderLabel=function(e,t,r,i,n){if(t.z>0&&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.x<e||this._clickPosition.x>e+r?!1:this._clickPosition.y<t||this._clickPosition.y>t+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;e<this._scene.meshes.length;e++){var t=this._scene.meshes[e];t.renderOverlay=!1}},t.prototype._generateheader=function(e,t){var r=document.createElement("div");r.innerHTML=t+"&nbsp;",r.style.textAlign="right",r.style.width="100%",r.style.color="white",r.style.backgroundColor="Black",r.style.padding="5px 5px 4px 0px",r.style.marginLeft="-5px",r.style.fontWeight="bold",e.appendChild(r)},t.prototype._generateTexBox=function(e,t,r){var i=document.createElement("label");i.innerHTML=t,i.style.color=r,e.appendChild(i),e.appendChild(document.createElement("br"))},t.prototype._generateAdvancedCheckBox=function(e,t,r,i,n,s){void 0===s&&(s=null);var o=document.createElement("label"),a=document.createElement("input");a.type="checkbox",a.checked=i,a.addEventListener("change",function(e){n(e.target,s)}),o.appendChild(a);var h=document.createElement("span"),c=document.createElement("span"),l=document.createElement("span");l.style.cssFloat="right",c.innerHTML=t,l.innerHTML=r,l.style.fontSize="12px",l.style.maxWidth="200px",h.appendChild(c),h.appendChild(l),o.appendChild(h),e.appendChild(o),e.appendChild(document.createElement("br"))},t.prototype._generateCheckBox=function(e,t,r,i,n){void 0===n&&(n=null);var s=document.createElement("label"),o=document.createElement("input");o.type="checkbox",o.checked=r,o.addEventListener("change",function(e){i(e.target,n)}),s.appendChild(o),s.appendChild(document.createTextNode(t)),e.appendChild(s),e.appendChild(document.createElement("br"))},t.prototype._generateButton=function(e,t,r,i){void 0===i&&(i=null);var n=document.createElement("button");n.innerHTML=t,n.style.height="24px",n.style.width="150px",n.style.marginBottom="5px",n.style.color="#444444",n.style.border="1px solid white",n.className="debugLayerButton",n.addEventListener("click",function(e){r(e.target,i)}),e.appendChild(n),e.appendChild(document.createElement("br"))},t.prototype._generateRadio=function(e,t,r,i,n,s){void 0===s&&(s=null);var o=document.createElement("label"),a=document.createElement("input");a.type="radio",a.name=r,a.checked=i,a.addEventListener("change",function(e){n(e.target,s)}),o.appendChild(a),o.appendChild(document.createTextNode(t)),e.appendChild(o),e.appendChild(document.createElement("br"))},t.prototype._generateDOMelements=function(){var t=this;if(this._globalDiv.id="DebugLayer",this._globalDiv.style.position="absolute",this._globalDiv.style.fontFamily="Segoe UI, Arial",this._globalDiv.style.fontSize="14px",this._globalDiv.style.color="white",this._drawingCanvas=document.createElement("canvas"),this._drawingCanvas.id="DebugLayerDrawingCanvas",this._drawingCanvas.style.position="absolute",this._drawingCanvas.style.pointerEvents="none",this._drawingCanvas.style.backgroundColor="transparent",this._drawingContext=this._drawingCanvas.getContext("2d"),this._globalDiv.appendChild(this._drawingCanvas),this._showUI){var r="rgba(128, 128, 128, 0.4)",i="rgb(180, 180, 180) solid 1px";this._statsDiv=document.createElement("div"),this._statsDiv.id="DebugLayerStats",this._statsDiv.style.border=i,this._statsDiv.style.position="absolute",this._statsDiv.style.background=r,this._statsDiv.style.padding="0px 0px 0px 5px",this._generateheader(this._statsDiv,"STATISTICS"),this._statsSubsetDiv=document.createElement("div"),this._statsSubsetDiv.style.paddingTop="5px",this._statsSubsetDiv.style.paddingBottom="5px",this._statsSubsetDiv.style.overflowY="auto",this._statsDiv.appendChild(this._statsSubsetDiv),this._treeDiv=document.createElement("div"),this._treeDiv.id="DebugLayerTree",this._treeDiv.style.border=i,this._treeDiv.style.position="absolute",this._treeDiv.style.background=r,this._treeDiv.style.padding="0px 0px 0px 5px",this._treeDiv.style.display="none",this._generateheader(this._treeDiv,"MESHES TREE"),this._treeSubsetDiv=document.createElement("div"),this._treeSubsetDiv.style.paddingTop="5px",this._treeSubsetDiv.style.paddingRight="5px",this._treeSubsetDiv.style.overflowY="auto",this._treeSubsetDiv.style.maxHeight="300px",this._treeDiv.appendChild(this._treeSubsetDiv),this._needToRefreshMeshesTree=!0,this._logDiv=document.createElement("div"),this._logDiv.style.border=i,this._logDiv.id="DebugLayerLogs",this._logDiv.style.position="absolute",this._logDiv.style.background=r,this._logDiv.style.padding="0px 0px 0px 5px",this._logDiv.style.display="none",this._generateheader(this._logDiv,"LOGS"),this._logSubsetDiv=document.createElement("div"),this._logSubsetDiv.style.height="127px",this._logSubsetDiv.style.paddingTop="5px",this._logSubsetDiv.style.overflowY="auto",this._logSubsetDiv.style.fontSize="12px",this._logSubsetDiv.style.fontFamily="consolas",this._logSubsetDiv.innerHTML=e.Tools.LogCache,this._logDiv.appendChild(this._logSubsetDiv),e.Tools.OnNewCacheEntry=function(e){t._logSubsetDiv.innerHTML=e+t._logSubsetDiv.innerHTML},this._optionsDiv=document.createElement("div"),this._optionsDiv.id="DebugLayerOptions",this._optionsDiv.style.border=i,this._optionsDiv.style.position="absolute",this._optionsDiv.style.background=r,this._optionsDiv.style.padding="0px 0px 0px 5px",this._optionsDiv.style.overflowY="auto",this._generateheader(this._optionsDiv,"OPTIONS"),this._optionsSubsetDiv=document.createElement("div"),this._optionsSubsetDiv.style.paddingTop="5px",this._optionsSubsetDiv.style.paddingBottom="5px",this._optionsSubsetDiv.style.overflowY="auto",this._optionsSubsetDiv.style.maxHeight="200px",this._optionsDiv.appendChild(this._optionsSubsetDiv),this._generateTexBox(this._optionsSubsetDiv,"<b>Windows:</b>",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Statistics",this._displayStatistics,function(e){t._displayStatistics=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Logs",this._displayLogs,function(e){t._displayLogs=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Meshes tree",this._displayTree,function(e){t._displayTree=e.checked,t._needToRefreshMeshesTree=!0}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>General:</b>",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Bounding boxes",this._scene.forceShowBoundingBoxes,function(e){t._scene.forceShowBoundingBoxes=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Clickable labels",this._labelsEnabled,function(e){t._labelsEnabled=e.checked,t._labelsEnabled||t._clearLabels()}),this._generateCheckBox(this._optionsSubsetDiv,"Generate user marks (F12)",e.Tools.PerformanceLogLevel===e.Tools.PerformanceUserMarkLogLevel,function(t){t.checked?e.Tools.PerformanceLogLevel=e.Tools.PerformanceUserMarkLogLevel:e.Tools.PerformanceLogLevel=e.Tools.PerformanceNoneLogLevel}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>Rendering mode:</b>",this.accentColor),this._generateRadio(this._optionsSubsetDiv,"Solid","renderMode",!this._scene.forceWireframe&&!this._scene.forcePointsCloud,function(e){e.checked&&(t._scene.forceWireframe=!1,t._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Wireframe","renderMode",this._scene.forceWireframe,function(e){e.checked&&(t._scene.forceWireframe=!0,t._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Point","renderMode",this._scene.forcePointsCloud,function(e){e.checked&&(t._scene.forceWireframe=!1,t._scene.forcePointsCloud=!0)}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>Texture channels:</b>",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Diffuse",e.StandardMaterial.DiffuseTextureEnabled,function(t){e.StandardMaterial.DiffuseTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Ambient",e.StandardMaterial.AmbientTextureEnabled,function(t){e.StandardMaterial.AmbientTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Specular",e.StandardMaterial.SpecularTextureEnabled,function(t){e.StandardMaterial.SpecularTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Emissive",e.StandardMaterial.EmissiveTextureEnabled,function(t){e.StandardMaterial.EmissiveTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Bump",e.StandardMaterial.BumpTextureEnabled,function(t){e.StandardMaterial.BumpTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Opacity",e.StandardMaterial.OpacityTextureEnabled,function(t){e.StandardMaterial.OpacityTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Reflection",e.StandardMaterial.ReflectionTextureEnabled,function(t){e.StandardMaterial.ReflectionTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fresnel",e.StandardMaterial.FresnelEnabled,function(t){e.StandardMaterial.FresnelEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lightmap",e.StandardMaterial.LightmapEnabled,function(t){
  19. e.StandardMaterial.LightmapEnabled=t.checked}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>Options:</b>",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Animations",this._scene.animationsEnabled,function(e){t._scene.animationsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Collisions",this._scene.collisionsEnabled,function(e){t._scene.collisionsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fog",this._scene.fogEnabled,function(e){t._scene.fogEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lens flares",this._scene.lensFlaresEnabled,function(e){t._scene.lensFlaresEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lights",this._scene.lightsEnabled,function(e){t._scene.lightsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Particles",this._scene.particlesEnabled,function(e){t._scene.particlesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Post-processes",this._scene.postProcessesEnabled,function(e){t._scene.postProcessesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"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,"<b>Audio:</b>",this.accentColor),this._generateRadio(this._optionsSubsetDiv,"Headphones","panningModel",this._scene.headphone,function(e){e.checked&&(t._scene.headphone=!0)}),this._generateRadio(this._optionsSubsetDiv,"Normal Speakers","panningModel",!this._scene.headphone,function(e){e.checked&&(t._scene.headphone=!1)}),this._generateCheckBox(this._optionsSubsetDiv,"Disable audio",!this._scene.audioEnabled,function(e){t._scene.audioEnabled=!e.checked})),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>Tools:</b>",this.accentColor),this._generateButton(this._optionsSubsetDiv,"Dump rendertargets",function(e){t._scene.dumpNextRenderTargets=!0}),this._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+" - <b>"+e.Tools.Format(r.getFps(),0)+" fps</b><br><br><div style='column-count: 2;-moz-column-count:2;-webkit-column-count:2'><b>Count</b><br>Total meshes: "+t.meshes.length+"<br>Total vertices: "+t.getTotalVertices()+"<br>Total materials: "+t.materials.length+"<br>Total textures: "+t.textures.length+"<br>Active meshes: "+t.getActiveMeshes().length+"<br>Active indices: "+t.getActiveIndices()+"<br>Active bones: "+t.getActiveBones()+"<br>Active particles: "+t.getActiveParticles()+"<br><b>Draw calls: "+r.drawCalls+"</b><br><br><br><b>Duration</b><br>Meshes selection:</i> "+e.Tools.Format(t.getEvaluateActiveMeshesDuration())+" ms<br>Render Targets: "+e.Tools.Format(t.getRenderTargetsDuration())+" ms<br>Particles: "+e.Tools.Format(t.getParticlesDuration())+" ms<br>Sprites: "+e.Tools.Format(t.getSpritesDuration())+" ms<br><br>Render: <b>"+e.Tools.Format(t.getRenderDuration())+" ms</b><br>Frame: "+e.Tools.Format(t.getLastFrameDuration())+" ms<br>Potential FPS: "+e.Tools.Format(1e3/t.getLastFrameDuration(),0)+"<br>Resolution: "+r.getRenderWidth()+"x"+r.getRenderHeight()+"<br></div><div style='column-count: 2;-moz-column-count:2;-webkit-column-count:2'><b>Extensions</b><br>Std derivatives: "+(r.getCaps().standardDerivatives?"Yes":"No")+"<br>Compressed textures: "+(r.getCaps().s3tc?"Yes":"No")+"<br>Hardware instances: "+(r.getCaps().instancedArrays?"Yes":"No")+"<br>Texture float: "+(r.getCaps().textureFloat?"Yes":"No")+"<br><br>32bits indices: "+(r.getCaps().uintIndices?"Yes":"No")+"<br>Fragment depth: "+(r.getCaps().fragmentDepthSupported?"Yes":"No")+"<br>High precision shaders: "+(r.getCaps().highPrecisionShaderSupported?"Yes":"No")+"<br>Draw buffers: "+(r.getCaps().drawBuffersExtension?"Yes":"No")+"<br></div><br><div style='column-count: 2;-moz-column-count:2;-webkit-column-count:2'><b>Caps.</b><br>Max textures units: "+r.getCaps().maxTexturesImageUnits+"<br>Max textures size: "+r.getCaps().maxTextureSize+"<br>Max anisotropy: "+r.getCaps().maxAnisotropy+"<br><b>Info</b><br>WebGL feature level: "+r.webGLVersion+"<br>"+i.version+"<br></div><br>"+i.renderer+"<br>",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}",
  20. 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}",
  21. 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}",
  22. 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);