babylon.js 1.0 MB

12345678910111213141516171819202122232425262728293031323334
  1. var __decorate=this&&this.__decorate||function(e,t,i,n){var r,o=arguments.length,s=3>o?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(s=(3>o?r(s):o>3?r(t,i,s):r(t,i))||s);return o>3&&s&&Object.defineProperty(t,i,s),s},__extends=this&&this.__extends||function(e,t){function i(){this.constructor=e}for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);i.prototype=t.prototype,e.prototype=new i},BABYLON;!function(e){e.ToGammaSpace=1/2.2,e.ToLinearSpace=2.2,e.Epsilon=.001;var t=function(){function e(){}return e.WithinEpsilon=function(e,t,i){void 0===i&&(i=1.401298e-45);var n=e-t;return n>=-i&&i>=n},e.ToHex=function(e){var t=e.toString(16);return 15>=e?("0"+t).toUpperCase():t.toUpperCase()},e.Sign=function(e){return e=+e,0===e||isNaN(e)?e:e>0?1:-1},e.Clamp=function(e,t,i){return void 0===t&&(t=0),void 0===i&&(i=1),Math.min(i,Math.max(t,e))},e}();e.MathTools=t;var i=function(){function i(e,t,i){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),this.r=e,this.g=t,this.b=i}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,i){return this.r===e&&this.g===t&&this.b===i},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,i){return this.r=e,this.g=t,this.b=i,this},i.prototype.toHexString=function(){var e=255*this.r|0,i=255*this.g|0,n=255*this.b|0;return"#"+t.ToHex(e)+t.ToHex(i)+t.ToHex(n)},i.prototype.toLinearSpace=function(){var e=new i;return this.toLinearSpaceToRef(e),e},i.prototype.toLinearSpaceToRef=function(t){return t.r=Math.pow(this.r,e.ToLinearSpace),t.g=Math.pow(this.g,e.ToLinearSpace),t.b=Math.pow(this.b,e.ToLinearSpace),this},i.prototype.toGammaSpace=function(){var e=new i;return this.toGammaSpaceToRef(e),e},i.prototype.toGammaSpaceToRef=function(t){return t.r=Math.pow(this.r,e.ToGammaSpace),t.g=Math.pow(this.g,e.ToGammaSpace),t.b=Math.pow(this.b,e.ToGammaSpace),this},i.FromHexString=function(e){if("#"!==e.substring(0,1)||7!==e.length)return new i(0,0,0);var t=parseInt(e.substring(1,3),16),n=parseInt(e.substring(3,5),16),r=parseInt(e.substring(5,7),16);return i.FromInts(t,n,r)},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,n){return new i(e/255,t/255,n/255)},i.Lerp=function(e,t,n){var r=e.r+(t.r-e.r)*n,o=e.g+(t.g-e.g)*n,s=e.b+(t.b-e.b)*n;return new i(r,o,s)},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 e(e,t,i,n){this.r=e,this.g=t,this.b=i,this.a=n}return e.prototype.addInPlace=function(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this.a+=e.a,this},e.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},e.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e[t+3]=this.a,this},e.prototype.add=function(t){return new e(this.r+t.r,this.g+t.g,this.b+t.b,this.a+t.a)},e.prototype.subtract=function(t){return new e(this.r-t.r,this.g-t.g,this.b-t.b,this.a-t.a)},e.prototype.subtractToRef=function(e,t){return t.r=this.r-e.r,t.g=this.g-e.g,t.b=this.b-e.b,t.a=this.a-e.a,this},e.prototype.scale=function(t){return new e(this.r*t,this.g*t,this.b*t,this.a*t)},e.prototype.scaleToRef=function(e,t){return t.r=this.r*e,t.g=this.g*e,t.b=this.b*e,t.a=this.a*e,this},e.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+" A:"+this.a+"}"},e.prototype.clone=function(){return new e(this.r,this.g,this.b,this.a)},e.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this},e.prototype.toHexString=function(){var e=255*this.r|0,i=255*this.g|0,n=255*this.b|0,r=255*this.a|0;return"#"+t.ToHex(e)+t.ToHex(i)+t.ToHex(n)+t.ToHex(r)},e.FromHexString=function(t){if("#"!==t.substring(0,1)||9!==t.length)return new e(0,0,0,0);var i=parseInt(t.substring(1,3),16),n=parseInt(t.substring(3,5),16),r=parseInt(t.substring(5,7),16),o=parseInt(t.substring(7,9),16);return e.FromInts(i,n,r,o)},e.Lerp=function(t,i,n){var r=new e(0,0,0,0);return e.LerpToRef(t,i,n,r),r},e.LerpToRef=function(e,t,i,n){n.r=e.r+(t.r-e.r)*i,n.g=e.g+(t.g-e.g)*i,n.b=e.b+(t.b-e.b)*i,n.a=e.a+(t.a-e.a)*i},e.FromArray=function(t,i){return void 0===i&&(i=0),new e(t[i],t[i+1],t[i+2],t[i+3])},e.FromInts=function(t,i,n,r){return new e(t/255,i/255,n/255,r/255)},e.CheckColors4=function(e,t){if(e.length===3*t){for(var i=[],n=0;n<e.length;n+=3){var r=n/3*4;i[r]=e[n],i[r+1]=e[n+1],i[r+2]=e[n+2],i[r+3]=1}return i}return e},e}();e.Color4=n;var r=function(){function i(e,t){this.x=e,this.y=t}return i.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}"},i.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,this},i.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},i.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this},i.prototype.copyFromFloats=function(e,t){return this.x=e,this.y=t,this},i.prototype.add=function(e){return new i(this.x+e.x,this.y+e.y)},i.prototype.addVector3=function(e){return new i(this.x+e.x,this.y+e.y)},i.prototype.subtract=function(e){return new i(this.x-e.x,this.y-e.y)},i.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this},i.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this},i.prototype.multiply=function(e){return new i(this.x*e.x,this.y*e.y)},i.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,this},i.prototype.multiplyByFloats=function(e,t){return new i(this.x*e,this.y*t)},i.prototype.divide=function(e){return new i(this.x/e.x,this.y/e.y)},i.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,this},i.prototype.negate=function(){return new i(-this.x,-this.y)},i.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this},i.prototype.scale=function(e){return new i(this.x*e,this.y*e)},i.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y},i.prototype.equalsWithEpsilon=function(i,n){return void 0===n&&(n=e.Epsilon),i&&t.WithinEpsilon(this.x,i.x,n)&&t.WithinEpsilon(this.y,i.y,n)},i.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},i.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},i.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this},i.prototype.clone=function(){return new i(this.x,this.y)},i.Zero=function(){return new i(0,0)},i.FromArray=function(e,t){return void 0===t&&(t=0),new i(e[t],e[t+1])},i.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1]},i.CatmullRom=function(e,t,n,r,o){var s=o*o,a=o*s,h=.5*(2*t.x+(-e.x+n.x)*o+(2*e.x-5*t.x+4*n.x-r.x)*s+(-e.x+3*t.x-3*n.x+r.x)*a),c=.5*(2*t.y+(-e.y+n.y)*o+(2*e.y-5*t.y+4*n.y-r.y)*s+(-e.y+3*t.y-3*n.y+r.y)*a);return new i(h,c)},i.Clamp=function(e,t,n){var r=e.x;r=r>n.x?n.x:r,r=r<t.x?t.x:r;var o=e.y;return o=o>n.y?n.y:o,o=o<t.y?t.y:o,new i(r,o)},i.Hermite=function(e,t,n,r,o){var s=o*o,a=o*s,h=2*a-3*s+1,c=-2*a+3*s,l=a-2*s+o,u=a-s,d=e.x*h+n.x*c+t.x*l+r.x*u,f=e.y*h+n.y*c+t.y*l+r.y*u;return new i(d,f)},i.Lerp=function(e,t,n){var r=e.x+(t.x-e.x)*n,o=e.y+(t.y-e.y)*n;return new i(r,o)},i.Dot=function(e,t){return e.x*t.x+e.y*t.y},i.Normalize=function(e){var t=e.clone();return t.normalize(),t},i.Minimize=function(e,t){var n=e.x<t.x?e.x:t.x,r=e.y<t.y?e.y:t.y;return new i(n,r)},i.Maximize=function(e,t){var n=e.x>t.x?e.x:t.x,r=e.y>t.y?e.y:t.y;return new i(n,r)},i.Transform=function(e,t){var n=e.x*t.m[0]+e.y*t.m[4],r=e.x*t.m[1]+e.y*t.m[5];return new i(n,r)},i.Distance=function(e,t){return Math.sqrt(i.DistanceSquared(e,t))},i.DistanceSquared=function(e,t){var i=e.x-t.x,n=e.y-t.y;return i*i+n*n},i}();e.Vector2=r;var o=function(){function i(e,t,i){this.x=e,this.y=t,this.z=i}return i.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},i.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},i.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},i.prototype.toQuaternion=function(){var e=new a(0,0,0,1),t=Math.cos(.5*(this.x+this.z)),i=Math.sin(.5*(this.x+this.z)),n=Math.cos(.5*(this.z-this.x)),r=Math.sin(.5*(this.z-this.x)),o=Math.cos(.5*this.y),s=Math.sin(.5*this.y);return e.x=n*s,e.y=-r*s,e.z=i*o,e.w=t*o,e},i.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},i.prototype.add=function(e){return new i(this.x+e.x,this.y+e.y,this.z+e.z)},i.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},i.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this},i.prototype.subtract=function(e){return new i(this.x-e.x,this.y-e.y,this.z-e.z)},i.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},i.prototype.subtractFromFloats=function(e,t,n){return new i(this.x-e,this.y-t,this.z-n)},i.prototype.subtractFromFloatsToRef=function(e,t,i,n){return n.x=this.x-e,n.y=this.y-t,n.z=this.z-i,this},i.prototype.negate=function(){return new i(-this.x,-this.y,-this.z)},i.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this},i.prototype.scale=function(e){return new i(this.x*e,this.y*e,this.z*e)},i.prototype.scaleToRef=function(e,t){t.x=this.x*e,t.y=this.y*e,t.z=this.z*e},i.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z},i.prototype.equalsWithEpsilon=function(i,n){return void 0===n&&(n=e.Epsilon),i&&t.WithinEpsilon(this.x,i.x,n)&&t.WithinEpsilon(this.y,i.y,n)&&t.WithinEpsilon(this.z,i.z,n)},i.prototype.equalsToFloats=function(e,t,i){return this.x===e&&this.y===t&&this.z===i},i.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this},i.prototype.multiply=function(e){return new i(this.x*e.x,this.y*e.y,this.z*e.z)},i.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},i.prototype.multiplyByFloats=function(e,t,n){return new i(this.x*e,this.y*t,this.z*n)},i.prototype.divide=function(e){return new i(this.x/e.x,this.y/e.y,this.z/e.z)},i.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},i.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},i.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},i.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},i.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},i.prototype.normalize=function(){var 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},i.prototype.clone=function(){return new i(this.x,this.y,this.z)},i.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},i.prototype.copyFromFloats=function(e,t,i){return this.x=e,this.y=t,this.z=i,this},i.GetClipFactor=function(e,t,n,r){var o=i.Dot(e,n)-r,s=i.Dot(t,n)-r,a=o/(o-s);return a},i.FromArray=function(e,t){return t||(t=0),new i(e[t],e[t+1],e[t+2])},i.FromFloatArray=function(e,t){return t||(t=0),new i(e[t],e[t+1],e[t+2])},i.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2]},i.FromFloatArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2]},i.FromFloatsToRef=function(e,t,i,n){n.x=e,n.y=t,n.z=i},i.Zero=function(){return new i(0,0,0)},i.Up=function(){return new i(0,1,0)},i.TransformCoordinates=function(e,t){var n=i.Zero();return i.TransformCoordinatesToRef(e,t,n),n},i.TransformCoordinatesToRef=function(e,t,i){var n=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8]+t.m[12],r=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9]+t.m[13],o=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10]+t.m[14],s=e.x*t.m[3]+e.y*t.m[7]+e.z*t.m[11]+t.m[15];i.x=n/s,i.y=r/s,i.z=o/s},i.TransformCoordinatesFromFloatsToRef=function(e,t,i,n,r){var o=e*n.m[0]+t*n.m[4]+i*n.m[8]+n.m[12],s=e*n.m[1]+t*n.m[5]+i*n.m[9]+n.m[13],a=e*n.m[2]+t*n.m[6]+i*n.m[10]+n.m[14],h=e*n.m[3]+t*n.m[7]+i*n.m[11]+n.m[15];r.x=o/h,r.y=s/h,r.z=a/h},i.TransformNormal=function(e,t){var n=i.Zero();return i.TransformNormalToRef(e,t,n),n},i.TransformNormalToRef=function(e,t,i){i.x=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8],i.y=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9],i.z=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10]},i.TransformNormalFromFloatsToRef=function(e,t,i,n,r){r.x=e*n.m[0]+t*n.m[4]+i*n.m[8],r.y=e*n.m[1]+t*n.m[5]+i*n.m[9],r.z=e*n.m[2]+t*n.m[6]+i*n.m[10]},i.CatmullRom=function(e,t,n,r,o){var s=o*o,a=o*s,h=.5*(2*t.x+(-e.x+n.x)*o+(2*e.x-5*t.x+4*n.x-r.x)*s+(-e.x+3*t.x-3*n.x+r.x)*a),c=.5*(2*t.y+(-e.y+n.y)*o+(2*e.y-5*t.y+4*n.y-r.y)*s+(-e.y+3*t.y-3*n.y+r.y)*a),l=.5*(2*t.z+(-e.z+n.z)*o+(2*e.z-5*t.z+4*n.z-r.z)*s+(-e.z+3*t.z-3*n.z+r.z)*a);return new i(h,c,l)},i.Clamp=function(e,t,n){var r=e.x;r=r>n.x?n.x:r,r=r<t.x?t.x:r;var o=e.y;o=o>n.y?n.y:o,o=o<t.y?t.y:o;var s=e.z;return s=s>n.z?n.z:s,s=s<t.z?t.z:s,new i(r,o,s)},i.Hermite=function(e,t,n,r,o){var s=o*o,a=o*s,h=2*a-3*s+1,c=-2*a+3*s,l=a-2*s+o,u=a-s,d=e.x*h+n.x*c+t.x*l+r.x*u,f=e.y*h+n.y*c+t.y*l+r.y*u,p=e.z*h+n.z*c+t.z*l+r.z*u;return new i(d,f,p)},i.Lerp=function(e,t,n){var r=e.x+(t.x-e.x)*n,o=e.y+(t.y-e.y)*n,s=e.z+(t.z-e.z)*n;return new i(r,o,s)},i.Dot=function(e,t){return e.x*t.x+e.y*t.y+e.z*t.z},i.Cross=function(e,t){var n=i.Zero();return i.CrossToRef(e,t,n),n},i.CrossToRef=function(e,t,i){i.x=e.y*t.z-e.z*t.y,i.y=e.z*t.x-e.x*t.z,i.z=e.x*t.y-e.y*t.x},i.Normalize=function(e){var t=i.Zero();return i.NormalizeToRef(e,t),t},i.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},i.Project=function(e,t,n,r){var o=r.width,s=r.height,a=r.x,c=r.y,l=h.FromValues(o/2,0,0,0,0,-s/2,0,0,0,0,1,0,a+o/2,s/2+c,0,1),u=t.multiply(n).multiply(l);return i.TransformCoordinates(e,u)},i.UnprojectFromTransform=function(e,n,r,o,s){var a=o.multiply(s);a.invert(),e.x=e.x/n*2-1,e.y=-(e.y/r*2-1);var h=i.TransformCoordinates(e,a),c=e.x*a.m[3]+e.y*a.m[7]+e.z*a.m[11]+a.m[15];return t.WithinEpsilon(c,1)&&(h=h.scale(1/c)),h},i.Unproject=function(e,n,r,o,s,a){var h=o.multiply(s).multiply(a);h.invert();var c=new i(e.x/n*2-1,-(e.y/r*2-1),e.z),l=i.TransformCoordinates(c,h),u=c.x*h.m[3]+c.y*h.m[7]+c.z*h.m[11]+h.m[15];return t.WithinEpsilon(u,1)&&(l=l.scale(1/u)),l},i.Minimize=function(e,t){var i=e.clone();return i.MinimizeInPlace(t),i},i.Maximize=function(e,t){var i=e.clone();return i.MaximizeInPlace(t),i},i.Distance=function(e,t){return Math.sqrt(i.DistanceSquared(e,t))},i.DistanceSquared=function(e,t){var i=e.x-t.x,n=e.y-t.y,r=e.z-t.z;return i*i+n*n+r*r},i.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},i.RotationFromAxis=function(e,t,n){var r=i.Zero();return i.RotationFromAxisToRef(e,t,n,r),r},i.RotationFromAxisToRef=function(n,r,o,s){var a=n.normalize(),h=o.normalize(),c=d.X,l=d.Y,u=0,f=0,p=0,m=0,_=0,g=0,v=0,y=-1,x=0,b=T.Vector3[0],E=0,A=T.Vector3[1];t.WithinEpsilon(h.z,0,e.Epsilon)?g=1:t.WithinEpsilon(h.x,0,e.Epsilon)?m=1:(v=h.z/h.x,m=-v*Math.sqrt(1/(1+v*v)),g=Math.sqrt(1/(1+v*v))),A.x=m,A.y=_,A.z=g,A.normalize(),i.CrossToRef(a,A,b),b.normalize(),i.Dot(h,b)<0&&(y=1),E=i.Dot(a,A),E=Math.min(1,Math.max(-1,E)),p=Math.acos(E)*y,i.Dot(A,c)<0&&(p=Math.PI+p,A=A.scaleInPlace(-1),x++);var P=T.Vector3[2],M=T.Vector3[3];m=0,_=0,g=0,y=-1,t.WithinEpsilon(h.z,0,e.Epsilon)?m=1:(v=A.z/A.x,m=-v*Math.sqrt(1/(1+v*v)),g=Math.sqrt(1/(1+v*v))),P.x=m,P.y=_,P.z=g,P.normalize(),i.CrossToRef(P,A,M),M.normalize(),i.CrossToRef(h,P,b),b.normalize(),i.Dot(A,b)<0&&(y=1),E=i.Dot(h,P),E=Math.min(1,Math.max(-1,E)),f=Math.acos(E)*y,i.Dot(M,l)<0&&(f=Math.PI+f,x++),y=-1,i.CrossToRef(c,A,b),b.normalize(),i.Dot(b,l)<0&&(y=1),E=i.Dot(A,c),E=Math.min(1,Math.max(-1,E)),u=-Math.acos(E)*y,0>E&&2>x&&(u=Math.PI+u),s.x=f,s.y=u,s.z=p},i}();e.Vector3=o;var s=function(){function i(e,t,i,n){this.x=e,this.y=t,this.z=i,this.w=n}return i.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"W:"+this.w+"}"},i.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},i.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},i.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this},i.prototype.add=function(e){return new i(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)},i.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},i.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this},i.prototype.subtract=function(e){return new i(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},i.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},i.prototype.subtractFromFloats=function(e,t,n,r){return new i(this.x-e,this.y-t,this.z-n,this.w-r)},i.prototype.subtractFromFloatsToRef=function(e,t,i,n,r){return r.x=this.x-e,r.y=this.y-t,r.z=this.z-i,r.w=this.w-n,this},i.prototype.negate=function(){return new i(-this.x,-this.y,-this.z,-this.w)},i.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},i.prototype.scale=function(e){return new i(this.x*e,this.y*e,this.z*e,this.w*e)},i.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},i.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},i.prototype.equalsWithEpsilon=function(i,n){return void 0===n&&(n=e.Epsilon),i&&t.WithinEpsilon(this.x,i.x,n)&&t.WithinEpsilon(this.y,i.y,n)&&t.WithinEpsilon(this.z,i.z,n)&&t.WithinEpsilon(this.w,i.w,n)},i.prototype.equalsToFloats=function(e,t,i,n){return this.x===e&&this.y===t&&this.z===i&&this.w===n},i.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this},i.prototype.multiply=function(e){return new i(this.x*e.x,this.y*e.y,this.z*e.z,this.w*e.w)},i.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},i.prototype.multiplyByFloats=function(e,t,n,r){return new i(this.x*e,this.y*t,this.z*n,this.w*r)},i.prototype.divide=function(e){return new i(this.x/e.x,this.y/e.y,this.z/e.z,this.w/e.w)},i.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},i.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},i.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},i.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},i.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},i.prototype.normalize=function(){var 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},i.prototype.clone=function(){return new i(this.x,this.y,this.z,this.w)},i.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},i.prototype.copyFromFloats=function(e,t,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,this},i.FromArray=function(e,t){return t||(t=0),new i(e[t],e[t+1],e[t+2],e[t+3])},i.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2],i.w=e[t+3]},i.FromFloatArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2],i.w=e[t+3]},i.FromFloatsToRef=function(e,t,i,n,r){r.x=e,r.y=t,r.z=i,r.w=n},i.Zero=function(){return new i(0,0,0,0)},i.Normalize=function(e){var t=i.Zero();return i.NormalizeToRef(e,t),t},i.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},i.Minimize=function(e,t){var i=e.clone();return i.MinimizeInPlace(t),i},i.Maximize=function(e,t){var i=e.clone();return i.MaximizeInPlace(t),i},i.Distance=function(e,t){return Math.sqrt(i.DistanceSquared(e,t))},i.DistanceSquared=function(e,t){var i=e.x-t.x,n=e.y-t.y,r=e.z-t.z,o=e.w-t.w;return i*i+n*n+r*r+o*o},i.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},i}();e.Vector4=s;var a=function(){function e(e,t,i,n){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),void 0===n&&(n=1),this.x=e,this.y=t,this.z=i,this.w=n}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,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,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 i=new e(0,0,0,1);return this.multiplyToRef(t,i),i},e.prototype.multiplyToRef=function(e,t){var i=this.x*e.w+this.y*e.z-this.z*e.y+this.w*e.x,n=-this.x*e.z+this.y*e.w+this.z*e.x+this.w*e.y,r=this.x*e.y-this.y*e.x+this.z*e.w+this.w*e.z,o=-this.x*e.x-this.y*e.y-this.z*e.z+this.w*e.w;return t.copyFromFloats(i,n,r,o),this},e.prototype.multiplyInPlace=function(e){return this.multiplyToRef(e,this),this},e.prototype.conjugateToRef=function(e){return e.copyFromFloats(-this.x,-this.y,-this.z,this.w),this},e.prototype.conjugateInPlace=function(){return this.x*=-1,this.y*=-1,this.z*=-1,this},e.prototype.conjugate=function(){var t=new e(-this.x,-this.y,-this.z,this.w);return t},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 i,n,r,o=this.x,s=this.y,a=this.z,h=this.w;switch(t){case"YZX":var c=o*s+a*h;if(c>.499&&(i=2*Math.atan2(o,h),n=Math.PI/2,r=0),-.499>c&&(i=-2*Math.atan2(o,h),n=-Math.PI/2,r=0),isNaN(i)){var l=o*o,u=s*s,d=a*a;i=Math.atan2(2*s*h-2*o*a,1-2*u-2*d),n=Math.asin(2*c),r=Math.atan2(2*o*h-2*s*a,1-2*l-2*d)}break;default:throw new Error("Euler order "+t+" not supported yet.")}return e.y=i,e.z=n,e.x=r,this},e.prototype.toRotationMatrix=function(e){var t=this.x*this.x,i=this.y*this.y,n=this.z*this.z,r=this.x*this.y,o=this.z*this.w,s=this.z*this.x,a=this.y*this.w,h=this.y*this.z,c=this.x*this.w;return e.m[0]=1-2*(i+n),e.m[1]=2*(r+o),e.m[2]=2*(s-a),e.m[3]=0,e.m[4]=2*(r-o),e.m[5]=1-2*(n+t),e.m[6]=2*(h+c),e.m[7]=0,e.m[8]=2*(s+a),e.m[9]=2*(h-c),e.m[10]=1-2*(i+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 i=new e;return e.FromRotationMatrixToRef(t,i),i},e.FromRotationMatrixToRef=function(e,t){var i,n=e.m,r=n[0],o=n[4],s=n[8],a=n[1],h=n[5],c=n[9],l=n[2],u=n[6],d=n[10],f=r+h+d;f>0?(i=.5/Math.sqrt(f+1),t.w=.25/i,t.x=(u-c)*i,t.y=(s-l)*i,t.z=(a-o)*i):r>h&&r>d?(i=2*Math.sqrt(1+r-h-d),t.w=(u-c)/i,t.x=.25*i,t.y=(o+a)/i,t.z=(s+l)/i):h>d?(i=2*Math.sqrt(1+h-r-d),t.w=(s-l)/i,t.x=(o+a)/i,t.y=.25*i,t.z=(c+u)/i):(i=2*Math.sqrt(1+d-r-h),t.w=(a-o)/i,t.x=(s+l)/i,t.y=(c+u)/i,t.z=.25*i)},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,i){var n=new e,r=Math.sin(i/2);return t.normalize(),n.w=Math.cos(i/2),n.x=t.x*r,n.y=t.y*r,n.z=t.z*r,n},e.FromArray=function(t,i){return i||(i=0),new e(t[i],t[i+1],t[i+2],t[i+3])},e.RotationYawPitchRoll=function(t,i,n){var r=new e;return e.RotationYawPitchRollToRef(t,i,n,r),r},e.RotationYawPitchRollToRef=function(e,t,i,n){var r=.5*i,o=.5*t,s=.5*e,a=Math.sin(r),h=Math.cos(r),c=Math.sin(o),l=Math.cos(o),u=Math.sin(s),d=Math.cos(s);n.x=d*c*h+u*l*a,n.y=u*l*h-d*c*a,n.z=d*l*a-u*c*h,n.w=d*l*h+u*c*a},e.RotationAlphaBetaGamma=function(t,i,n){var r=new e;return e.RotationAlphaBetaGammaToRef(t,i,n,r),r},e.RotationAlphaBetaGammaToRef=function(e,t,i,n){var r=.5*(i+e),o=.5*(i-e),s=.5*t;n.x=Math.cos(o)*Math.sin(s),n.y=Math.sin(o)*Math.sin(s),n.z=Math.sin(r)*Math.cos(s),n.w=Math.cos(r)*Math.cos(s)},e.Slerp=function(t,i,n){var r,o,s=n,a=t.x*i.x+t.y*i.y+t.z*i.z+t.w*i.w,h=!1;if(0>a&&(h=!0,a=-a),a>.999999)o=1-s,r=h?-s:s;else{var c=Math.acos(a),l=1/Math.sin(c);o=Math.sin((1-s)*c)*l,r=h?-Math.sin(s*c)*l:Math.sin(s*c)*l}return new e(o*t.x+r*i.x,o*t.y+r*i.y,o*t.z+r*i.z,o*t.w+r*i.w)},e}();e.Quaternion=a;var h=function(){function e(){this.m=new Float32Array(16)}return e.prototype.isIdentity=function(){return 1!==this.m[0]||1!==this.m[5]||1!==this.m[10]||1!==this.m[15]?!1:0===this.m[1]&&0===this.m[2]&&0===this.m[3]&&0===this.m[4]&&0===this.m[6]&&0===this.m[7]&&0===this.m[8]&&0===this.m[9]&&0===this.m[11]&&0===this.m[12]&&0===this.m[13]&&0===this.m[14]},e.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],i=this.m[9]*this.m[14]-this.m[10]*this.m[13],n=this.m[8]*this.m[15]-this.m[11]*this.m[12],r=this.m[8]*this.m[14]-this.m[10]*this.m[12],o=this.m[8]*this.m[13]-this.m[9]*this.m[12];return this.m[0]*(this.m[5]*e-this.m[6]*t+this.m[7]*i)-this.m[1]*(this.m[4]*e-this.m[6]*n+this.m[7]*r)+this.m[2]*(this.m[4]*t-this.m[5]*n+this.m[7]*o)-this.m[3]*(this.m[4]*i-this.m[5]*r+this.m[6]*o)},e.prototype.toArray=function(){return this.m},e.prototype.asArray=function(){return this.toArray()},e.prototype.invert=function(){return this.invertToRef(this),this},e.prototype.reset=function(){for(var e=0;16>e;e++)this.m[e]=0;return this},e.prototype.add=function(t){var i=new e;return this.addToRef(t,i),i},e.prototype.addToRef=function(e,t){for(var i=0;16>i;i++)t.m[i]=this.m[i]+e.m[i];return this},e.prototype.addToSelf=function(e){for(var t=0;16>t;t++)this.m[t]+=e.m[t];return this},e.prototype.invertToRef=function(e){var t=this.m[0],i=this.m[1],n=this.m[2],r=this.m[3],o=this.m[4],s=this.m[5],a=this.m[6],h=this.m[7],c=this.m[8],l=this.m[9],u=this.m[10],d=this.m[11],f=this.m[12],p=this.m[13],m=this.m[14],_=this.m[15],g=u*_-d*m,v=l*_-d*p,y=l*m-u*p,x=c*_-d*f,b=c*m-u*f,E=c*p-l*f,A=s*g-a*v+h*y,T=-(o*g-a*x+h*b),P=o*v-s*x+h*E,M=-(o*y-s*b+a*E),C=1/(t*A+i*T+n*P+r*M),S=a*_-h*m,R=s*_-h*p,I=s*m-a*p,D=o*_-h*f,O=o*m-a*f,w=o*p-s*f,L=a*d-h*u,B=s*d-h*l,F=s*u-a*l,V=o*d-h*c,N=o*u-a*c,z=o*l-s*c;return e.m[0]=A*C,e.m[4]=T*C,e.m[8]=P*C,e.m[12]=M*C,e.m[1]=-(i*g-n*v+r*y)*C,e.m[5]=(t*g-n*x+r*b)*C,e.m[9]=-(t*v-i*x+r*E)*C,e.m[13]=(t*y-i*b+n*E)*C,e.m[2]=(i*S-n*R+r*I)*C,e.m[6]=-(t*S-n*D+r*O)*C,e.m[10]=(t*R-i*D+r*w)*C,e.m[14]=-(t*I-i*O+n*w)*C,e.m[3]=-(i*L-n*B+r*F)*C,e.m[7]=(t*L-n*V+r*N)*C,e.m[11]=-(t*B-i*V+r*z)*C,e.m[15]=(t*F-i*N+n*z)*C,this},e.prototype.setTranslation=function(e){return this.m[12]=e.x,this.m[13]=e.y,this.m[14]=e.z,this},e.prototype.multiply=function(t){var i=new e;return this.multiplyToRef(t,i),i},e.prototype.copyFrom=function(e){for(var t=0;16>t;t++)this.m[t]=e.m[t];return this},e.prototype.copyToArray=function(e,t){void 0===t&&(t=0);for(var i=0;16>i;i++)e[t+i]=this.m[i];return this},e.prototype.multiplyToRef=function(e,t){return this.multiplyToArray(e,t.m,0),this},e.prototype.multiplyToArray=function(e,t,i){var n=this.m[0],r=this.m[1],o=this.m[2],s=this.m[3],a=this.m[4],h=this.m[5],c=this.m[6],l=this.m[7],u=this.m[8],d=this.m[9],f=this.m[10],p=this.m[11],m=this.m[12],_=this.m[13],g=this.m[14],v=this.m[15],y=e.m[0],x=e.m[1],b=e.m[2],E=e.m[3],A=e.m[4],T=e.m[5],P=e.m[6],M=e.m[7],C=e.m[8],S=e.m[9],R=e.m[10],I=e.m[11],D=e.m[12],O=e.m[13],w=e.m[14],L=e.m[15];return t[i]=n*y+r*A+o*C+s*D,t[i+1]=n*x+r*T+o*S+s*O,t[i+2]=n*b+r*P+o*R+s*w,t[i+3]=n*E+r*M+o*I+s*L,t[i+4]=a*y+h*A+c*C+l*D,t[i+5]=a*x+h*T+c*S+l*O,t[i+6]=a*b+h*P+c*R+l*w,t[i+7]=a*E+h*M+c*I+l*L,t[i+8]=u*y+d*A+f*C+p*D,t[i+9]=u*x+d*T+f*S+p*O,t[i+10]=u*b+d*P+f*R+p*w,t[i+11]=u*E+d*M+f*I+p*L,t[i+12]=m*y+_*A+g*C+v*D,t[i+13]=m*x+_*T+g*S+v*O,t[i+14]=m*b+_*P+g*R+v*w,t[i+15]=m*E+_*M+g*I+v*L,this},e.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]},e.prototype.clone=function(){return e.FromValues(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5],this.m[6],this.m[7],this.m[8],this.m[9],this.m[10],this.m[11],this.m[12],this.m[13],this.m[14],this.m[15])},e.prototype.decompose=function(i,n,r){r.x=this.m[12],r.y=this.m[13],r.z=this.m[14];var o=t.Sign(this.m[0]*this.m[1]*this.m[2]*this.m[3])<0?-1:1,s=t.Sign(this.m[4]*this.m[5]*this.m[6]*this.m[7])<0?-1:1,h=t.Sign(this.m[8]*this.m[9]*this.m[10]*this.m[11])<0?-1:1;if(i.x=o*Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]+this.m[2]*this.m[2]),i.y=s*Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]+this.m[6]*this.m[6]),i.z=h*Math.sqrt(this.m[8]*this.m[8]+this.m[9]*this.m[9]+this.m[10]*this.m[10]),0===i.x||0===i.y||0===i.z)return n.x=0,n.y=0,n.z=0,n.w=1,!1;var c=e.FromValues(this.m[0]/i.x,this.m[1]/i.x,this.m[2]/i.x,0,this.m[4]/i.y,this.m[5]/i.y,this.m[6]/i.y,0,this.m[8]/i.z,this.m[9]/i.z,this.m[10]/i.z,0,0,0,0,1);return a.FromRotationMatrixToRef(c,n),!0},e.FromArray=function(t,i){var n=new e;return i||(i=0),e.FromArrayToRef(t,i,n),n},e.FromArrayToRef=function(e,t,i){for(var n=0;16>n;n++)i.m[n]=e[n+t]},e.FromFloat32ArrayToRefScaled=function(e,t,i,n){for(var r=0;16>r;r++)n.m[r]=e[r+t]*i},e.FromValuesToRef=function(e,t,i,n,r,o,s,a,h,c,l,u,d,f,p,m,_){_.m[0]=e,_.m[1]=t,_.m[2]=i,_.m[3]=n,_.m[4]=r,_.m[5]=o,_.m[6]=s,_.m[7]=a,_.m[8]=h,_.m[9]=c,_.m[10]=l,_.m[11]=u,_.m[12]=d,_.m[13]=f,_.m[14]=p,_.m[15]=m},e.FromValues=function(t,i,n,r,o,s,a,h,c,l,u,d,f,p,m,_){var g=new e;return g.m[0]=t,g.m[1]=i,g.m[2]=n,g.m[3]=r,g.m[4]=o,g.m[5]=s,g.m[6]=a,g.m[7]=h,g.m[8]=c,g.m[9]=l,g.m[10]=u,g.m[11]=d,g.m[12]=f,g.m[13]=p,g.m[14]=m,g.m[15]=_,g},e.Compose=function(t,i,n){var r=e.FromValues(t.x,0,0,0,0,t.y,0,0,0,0,t.z,0,0,0,0,1),o=e.Identity();return i.toRotationMatrix(o),r=r.multiply(o),r.setTranslation(n),r},e.Identity=function(){return e.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},e.IdentityToRef=function(t){e.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,t)},e.Zero=function(){
  2. return e.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},e.RotationX=function(t){var i=new e;return e.RotationXToRef(t,i),i},e.Invert=function(t){var i=new e;return t.invertToRef(i),i},e.RotationXToRef=function(e,t){var i=Math.sin(e),n=Math.cos(e);t.m[0]=1,t.m[15]=1,t.m[5]=n,t.m[10]=n,t.m[9]=-i,t.m[6]=i,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},e.RotationY=function(t){var i=new e;return e.RotationYToRef(t,i),i},e.RotationYToRef=function(e,t){var i=Math.sin(e),n=Math.cos(e);t.m[5]=1,t.m[15]=1,t.m[0]=n,t.m[2]=-i,t.m[8]=i,t.m[10]=n,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},e.RotationZ=function(t){var i=new e;return e.RotationZToRef(t,i),i},e.RotationZToRef=function(e,t){var i=Math.sin(e),n=Math.cos(e);t.m[10]=1,t.m[15]=1,t.m[0]=n,t.m[1]=i,t.m[4]=-i,t.m[5]=n,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},e.RotationAxis=function(t,i){var n=e.Zero();return e.RotationAxisToRef(t,i,n),n},e.RotationAxisToRef=function(e,t,i){var n=Math.sin(-t),r=Math.cos(-t),o=1-r;e.normalize(),i.m[0]=e.x*e.x*o+r,i.m[1]=e.x*e.y*o-e.z*n,i.m[2]=e.x*e.z*o+e.y*n,i.m[3]=0,i.m[4]=e.y*e.x*o+e.z*n,i.m[5]=e.y*e.y*o+r,i.m[6]=e.y*e.z*o-e.x*n,i.m[7]=0,i.m[8]=e.z*e.x*o-e.y*n,i.m[9]=e.z*e.y*o+e.x*n,i.m[10]=e.z*e.z*o+r,i.m[11]=0,i.m[15]=1},e.RotationYawPitchRoll=function(t,i,n){var r=new e;return e.RotationYawPitchRollToRef(t,i,n,r),r},e.RotationYawPitchRollToRef=function(e,t,i,n){a.RotationYawPitchRollToRef(e,t,i,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(n)},e.Scaling=function(t,i,n){var r=e.Zero();return e.ScalingToRef(t,i,n,r),r},e.ScalingToRef=function(e,t,i,n){n.m[0]=e,n.m[1]=0,n.m[2]=0,n.m[3]=0,n.m[4]=0,n.m[5]=t,n.m[6]=0,n.m[7]=0,n.m[8]=0,n.m[9]=0,n.m[10]=i,n.m[11]=0,n.m[12]=0,n.m[13]=0,n.m[14]=0,n.m[15]=1},e.Translation=function(t,i,n){var r=e.Identity();return e.TranslationToRef(t,i,n,r),r},e.TranslationToRef=function(t,i,n,r){e.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,t,i,n,1,r)},e.Lerp=function(t,i,n){var r=new o(0,0,0),s=new a,h=new o(0,0,0);t.decompose(r,s,h);var c=new o(0,0,0),l=new a,u=new o(0,0,0);i.decompose(c,l,u);var d=o.Lerp(r,c,n),f=a.Slerp(s,l,n),p=o.Lerp(h,u,n);return e.Compose(d,f,p)},e.LookAtLH=function(t,i,n){var r=e.Zero();return e.LookAtLHToRef(t,i,n,r),r},e.LookAtLHToRef=function(t,i,n,r){i.subtractToRef(t,this._zAxis),this._zAxis.normalize(),o.CrossToRef(n,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,t),a=-o.Dot(this._yAxis,t),h=-o.Dot(this._zAxis,t);return e.FromValuesToRef(this._xAxis.x,this._yAxis.x,this._zAxis.x,0,this._xAxis.y,this._yAxis.y,this._zAxis.y,0,this._xAxis.z,this._yAxis.z,this._zAxis.z,0,s,a,h,1,r)},e.OrthoLH=function(t,i,n,r){var o=e.Zero();return e.OrthoLHToRef(t,i,n,r,o),o},e.OrthoLHToRef=function(t,i,n,r,o){var s=2/t,a=2/i,h=1/(r-n),c=n/(n-r);e.FromValuesToRef(s,0,0,0,0,a,0,0,0,0,h,0,0,0,c,1,o)},e.OrthoOffCenterLH=function(t,i,n,r,o,s){var a=e.Zero();return e.OrthoOffCenterLHToRef(t,i,n,r,o,s,a),a},e.OrthoOffCenterLHToRef=function(e,t,i,n,r,o,s){s.m[0]=2/(t-e),s.m[1]=s.m[2]=s.m[3]=0,s.m[5]=2/(n-i),s.m[4]=s.m[6]=s.m[7]=0,s.m[10]=-1/(r-o),s.m[8]=s.m[9]=s.m[11]=0,s.m[12]=(e+t)/(e-t),s.m[13]=(n+i)/(i-n),s.m[14]=r/(r-o),s.m[15]=1},e.PerspectiveLH=function(t,i,n,r){var o=e.Zero();return o.m[0]=2*n/t,o.m[1]=o.m[2]=o.m[3]=0,o.m[5]=2*n/i,o.m[4]=o.m[6]=o.m[7]=0,o.m[10]=-r/(n-r),o.m[8]=o.m[9]=0,o.m[11]=1,o.m[12]=o.m[13]=o.m[15]=0,o.m[14]=n*r/(n-r),o},e.PerspectiveFovLH=function(t,i,n,r){var o=e.Zero();return e.PerspectiveFovLHToRef(t,i,n,r,o),o},e.PerspectiveFovLHToRef=function(e,t,i,n,r,o){void 0===o&&(o=!0);var s=1/Math.tan(.5*e);o?r.m[0]=s/t:r.m[0]=s,r.m[1]=r.m[2]=r.m[3]=0,o?r.m[5]=s:r.m[5]=s*t,r.m[4]=r.m[6]=r.m[7]=0,r.m[8]=r.m[9]=0,r.m[10]=-n/(i-n),r.m[11]=1,r.m[12]=r.m[13]=r.m[15]=0,r.m[14]=i*n/(i-n)},e.GetFinalMatrix=function(t,i,n,r,o,s){var a=t.width,h=t.height,c=t.x,l=t.y,u=e.FromValues(a/2,0,0,0,0,-h/2,0,0,0,0,s-o,0,c+a/2,h/2+l,o,1);return i.multiply(n).multiply(r).multiply(u)},e.GetAsMatrix2x2=function(e){return new Float32Array([e.m[0],e.m[1],e.m[4],e.m[5]])},e.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]])},e.Transpose=function(t){var i=new e;return i.m[0]=t.m[0],i.m[1]=t.m[4],i.m[2]=t.m[8],i.m[3]=t.m[12],i.m[4]=t.m[1],i.m[5]=t.m[5],i.m[6]=t.m[9],i.m[7]=t.m[13],i.m[8]=t.m[2],i.m[9]=t.m[6],i.m[10]=t.m[10],i.m[11]=t.m[14],i.m[12]=t.m[3],i.m[13]=t.m[7],i.m[14]=t.m[11],i.m[15]=t.m[15],i},e.Reflection=function(t){var i=new e;return e.ReflectionToRef(t,i),i},e.ReflectionToRef=function(e,t){e.normalize();var i=e.normal.x,n=e.normal.y,r=e.normal.z,o=-2*i,s=-2*n,a=-2*r;t.m[0]=o*i+1,t.m[1]=s*i,t.m[2]=a*i,t.m[3]=0,t.m[4]=o*n,t.m[5]=s*n+1,t.m[6]=a*n,t.m[7]=0,t.m[8]=o*r,t.m[9]=s*r,t.m[10]=a*r+1,t.m[11]=0,t.m[12]=o*e.d,t.m[13]=s*e.d,t.m[14]=a*e.d,t.m[15]=1},e._tempQuaternion=new a,e._xAxis=o.Zero(),e._yAxis=o.Zero(),e._zAxis=o.Zero(),e}();e.Matrix=h;var c=function(){function e(e,t,i,n){this.normal=new o(e,t,i),this.d=n}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 i=h.Transpose(t),n=this.normal.x,r=this.normal.y,o=this.normal.z,s=this.d,a=n*i.m[0]+r*i.m[1]+o*i.m[2]+s*i.m[3],c=n*i.m[4]+r*i.m[5]+o*i.m[6]+s*i.m[7],l=n*i.m[8]+r*i.m[9]+o*i.m[10]+s*i.m[11],u=n*i.m[12]+r*i.m[13]+o*i.m[14]+s*i.m[15];return new e(a,c,l,u)},e.prototype.dotCoordinate=function(e){return this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z+this.d},e.prototype.copyFromPoints=function(e,t,i){var n,r=t.x-e.x,o=t.y-e.y,s=t.z-e.z,a=i.x-e.x,h=i.y-e.y,c=i.z-e.z,l=o*c-s*h,u=s*a-r*c,d=r*h-o*a,f=Math.sqrt(l*l+u*u+d*d);return n=0!==f?1/f:0,this.normal.x=l*n,this.normal.y=u*n,this.normal.z=d*n,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 i=o.Dot(this.normal,e);return t>=i},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,i,n){var r=new e(0,0,0,0);return r.copyFromPoints(t,i,n),r},e.FromPositionAndNormal=function(t,i){var n=new e(0,0,0,0);return i.normalize(),n.normal=i,n.d=-(i.x*t.x+i.y*t.y+i.z*t.z),n},e.SignedDistanceToPlaneFromPositionAndNormal=function(e,t,i){var n=-(t.x*e.x+t.y*e.y+t.z*e.z);return o.Dot(i,t)+n},e}();e.Plane=c;var l=function(){function e(e,t,i,n){this.x=e,this.y=t,this.width=i,this.height=n}return e.prototype.toGlobal=function(t,i){return new e(this.x*t,this.y*i,this.width*t,this.height*i)},e}();e.Viewport=l;var u=function(){function e(){}return e.GetPlanes=function(t){for(var i=[],n=0;6>n;n++)i.push(new c(0,0,0,0));return e.GetPlanesToRef(t,i),i},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=u,function(e){e[e.LOCAL=0]="LOCAL",e[e.WORLD=1]="WORLD"}(e.Space||(e.Space={}));var d=(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=d;var f=function(){function e(){}return e.interpolate=function(e,t,i,n,r){for(var o=1-3*n+3*t,s=3*n-6*t,a=3*t,h=e,c=0;5>c;c++){var l=h*h,u=l*h,d=o*u+s*l+a*h,f=1/(3*o*l+2*s*h+a);h-=(d-e)*f,h=Math.min(1,Math.max(0,h))}return 3*Math.pow(1-h,2)*h*i+3*(1-h)*Math.pow(h,2)*r+Math.pow(h,3)},e}();e.BezierCurve=f,function(e){e[e.CW=0]="CW",e[e.CCW=1]="CCW"}(e.Orientation||(e.Orientation={}));var p=e.Orientation,m=function(){function e(e){var t=this;this.degrees=function(){return 180*t._radians/Math.PI},this.radians=function(){return t._radians},this._radians=e,this._radians<0&&(this._radians+=2*Math.PI)}return e.BetweenTwoPoints=function(t,i){var n=i.subtract(t),r=Math.atan2(n.y,n.x);return new e(r)},e.FromRadians=function(t){return new e(t)},e.FromDegrees=function(t){return new e(t*Math.PI/180)},e}();e.Angle=m;var _=function(){function e(e,t,i){this.startPoint=e,this.midPoint=t,this.endPoint=i;var n=Math.pow(t.x,2)+Math.pow(t.y,2),o=(Math.pow(e.x,2)+Math.pow(e.y,2)-n)/2,s=(n-Math.pow(i.x,2)-Math.pow(i.y,2))/2,a=(e.x-t.x)*(t.y-i.y)-(t.x-i.x)*(e.y-t.y);this.centerPoint=new r((o*(t.y-i.y)-s*(e.y-t.y))/a,((e.x-t.x)*s-(t.x-i.x)*o)/a),this.radius=this.centerPoint.subtract(this.startPoint).length(),this.startAngle=m.BetweenTwoPoints(this.centerPoint,this.startPoint);var h=this.startAngle.degrees(),c=m.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),l=m.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();c-h>180&&(c-=360),-180>c-h&&(c+=360),l-c>180&&(l-=360),-180>l-c&&(l+=360),this.orientation=0>c-h?p.CW:p.CCW,this.angle=m.FromDegrees(this.orientation===p.CW?h-l:l-h)}return e}();e.Arc2=_;var g=function(){function e(e,t){this._points=new Array,this._length=0,this.closed=!1,this._points.push(new r(e,t))}return e.prototype.addLineTo=function(e,t){if(closed)return this;var i=new r(e,t),n=this._points[this._points.length-1];return this._points.push(i),this._length+=i.subtract(n).length(),this},e.prototype.addArcTo=function(e,t,i,n,o){if(void 0===o&&(o=36),closed)return this;var s=this._points[this._points.length-1],a=new r(e,t),h=new r(i,n),c=new _(s,a,h),l=c.angle.radians()/o;c.orientation===p.CW&&(l*=-1);for(var u=c.startAngle.radians()+l,d=0;o>d;d++){var f=Math.cos(u)*c.radius+c.centerPoint.x,m=Math.sin(u)*c.radius+c.centerPoint.y;this.addLineTo(f,m),u+=l}return this},e.prototype.close=function(){return this.closed=!0,this},e.prototype.length=function(){var e=this._length;if(!this.closed){var t=this._points[this._points.length-1],i=this._points[0];e+=i.subtract(t).length()}return e},e.prototype.getPoints=function(){return this._points},e.prototype.getPointAtLengthPosition=function(e){if(0>e||e>1)return r.Zero();for(var t=e*this.length(),i=0,n=0;n<this._points.length;n++){var o=(n+1)%this._points.length,s=this._points[n],a=this._points[o],h=a.subtract(s),c=h.length()+i;if(t>=i&&c>=t){var l=h.normalize(),u=t-i;return new r(s.x+l.x*u,s.y+l.y*u)}i=c}return r.Zero()},e.StartingAt=function(t,i){return new e(t,i)},e}();e.Path2=g;var v=function(){function i(e,t,i){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 n=0;n<e.length;n++)this._curve[n]=e[n].clone();this._raw=i||!1,this._compute(t)}return i.prototype.getCurve=function(){return this._curve},i.prototype.getTangents=function(){return this._tangents},i.prototype.getNormals=function(){return this._normals},i.prototype.getBinormals=function(){return this._binormals},i.prototype.getDistances=function(){return this._distances},i.prototype.update=function(e,t){for(var i=0;i<e.length;i++)this._curve[i].x=e[i].x,this._curve[i].y=e[i].y,this._curve[i].z=e[i].z;return this._compute(t),this},i.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 i=this._tangents[0],n=this._normalVector(this._curve[0],i,e);this._normals[0]=n,this._raw||this._normals[0].normalize(),this._binormals[0]=o.Cross(i,this._normals[0]),this._raw||this._binormals[0].normalize(),this._distances[0]=0;for(var r,s,a,h,c=1;t>c;c++)r=this._getLastNonNullVector(c),t-1>c&&(s=this._getFirstNonNullVector(c),this._tangents[c]=r.add(s),this._tangents[c].normalize()),this._distances[c]=this._distances[c-1]+r.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()},i.prototype._getFirstNonNullVector=function(e){for(var t=1,i=this._curve[e+t].subtract(this._curve[e]);0===i.length()&&e+t+1<this._curve.length;)t++,i=this._curve[e+t].subtract(this._curve[e]);return i},i.prototype._getLastNonNullVector=function(e){for(var t=1,i=this._curve[e].subtract(this._curve[e-t]);0===i.length()&&e>t+1;)t++,i=this._curve[e].subtract(this._curve[e-t]);return i},i.prototype._normalVector=function(i,n,r){var s;if(void 0===r||null===r){var a;t.WithinEpsilon(n.y,1,e.Epsilon)?t.WithinEpsilon(n.x,1,e.Epsilon)?t.WithinEpsilon(n.z,1,e.Epsilon)||(a=new o(0,0,1)):a=new o(1,0,0):a=new o(0,-1,0),s=o.Cross(n,a)}else s=o.Cross(n,r),o.CrossToRef(s,n,s);return s.normalize(),s},i}();e.Path3D=v;var y=function(){function e(e){this._length=0,this._points=e,this._length=this._computeLength(e)}return e.CreateQuadraticBezier=function(t,i,n,r){r=r>2?r:3;for(var s=new Array,a=function(e,t,i,n){var r=(1-e)*(1-e)*t+2*e*(1-e)*i+e*e*n;return r},h=0;r>=h;h++)s.push(new o(a(h/r,t.x,i.x,n.x),a(h/r,t.y,i.y,n.y),a(h/r,t.z,i.z,n.z)));return new e(s)},e.CreateCubicBezier=function(t,i,n,r,s){s=s>3?s:4;for(var a=new Array,h=function(e,t,i,n,r){var o=(1-e)*(1-e)*(1-e)*t+3*e*(1-e)*(1-e)*i+3*e*e*(1-e)*n+e*e*e*r;return o},c=0;s>=c;c++)a.push(new o(h(c/s,t.x,i.x,n.x,r.x),h(c/s,t.y,i.y,n.y,r.y),h(c/s,t.z,i.z,n.z,r.z)));return new e(a)},e.CreateHermiteSpline=function(t,i,n,r,s){for(var a=new Array,h=1/s,c=0;s>=c;c++)a.push(o.Hermite(t,i,n,r,c*h));return new e(a)},e.prototype.getPoints=function(){return this._points},e.prototype.length=function(){return this._length},e.prototype["continue"]=function(t){for(var i=this._points[this._points.length-1],n=this._points.slice(),r=t.getPoints(),o=1;o<r.length;o++)n.push(r[o].subtract(r[0]).add(i));var s=new e(n);return s},e.prototype._computeLength=function(e){for(var t=0,i=1;i<e.length;i++)t+=e[i].subtract(e[i-1]).length();return t},e}();e.Curve3=y;var x=function(){function e(){this.L00=o.Zero(),this.L1_1=o.Zero(),this.L10=o.Zero(),this.L11=o.Zero(),this.L2_2=o.Zero(),this.L2_1=o.Zero(),this.L20=o.Zero(),this.L21=o.Zero(),this.L22=o.Zero()}return e.prototype.addLight=function(e,t,i){var n=new o(t.r,t.g,t.b),r=n.scale(i);this.L00=this.L00.add(r.scale(.282095)),this.L1_1=this.L1_1.add(r.scale(.488603*e.y)),this.L10=this.L10.add(r.scale(.488603*e.z)),this.L11=this.L11.add(r.scale(.488603*e.x)),this.L2_2=this.L2_2.add(r.scale(1.092548*e.x*e.y)),this.L2_1=this.L2_1.add(r.scale(1.092548*e.y*e.z)),this.L21=this.L21.add(r.scale(1.092548*e.x*e.z)),this.L20=this.L20.add(r.scale(.315392*(3*e.z*e.z-1))),this.L22=this.L22.add(r.scale(.546274*(e.x*e.x-e.y*e.y)))},e.prototype.scale=function(e){this.L00=this.L00.scale(e),this.L1_1=this.L1_1.scale(e),this.L10=this.L10.scale(e),this.L11=this.L11.scale(e),this.L2_2=this.L2_2.scale(e),this.L2_1=this.L2_1.scale(e),this.L20=this.L20.scale(e),this.L21=this.L21.scale(e),this.L22=this.L22.scale(e)},e}();e.SphericalHarmonics=x;var b=function(){function e(){this.x=o.Zero(),this.y=o.Zero(),this.z=o.Zero(),this.xx=o.Zero(),this.yy=o.Zero(),this.zz=o.Zero(),this.xy=o.Zero(),this.yz=o.Zero(),this.zx=o.Zero()}return e.prototype.addAmbient=function(e){var t=new o(e.r,e.g,e.b);this.xx=this.xx.add(t),this.yy=this.yy.add(t),this.zz=this.zz.add(t)},e.getSphericalPolynomialFromHarmonics=function(t){var i=new e;return i.x=t.L11.scale(1.02333),i.y=t.L1_1.scale(1.02333),i.z=t.L10.scale(1.02333),i.xx=t.L00.scale(.886277).subtract(t.L20.scale(.247708)).add(t.L22.scale(.429043)),i.yy=t.L00.scale(.886277).subtract(t.L20.scale(.247708)).subtract(t.L22.scale(.429043)),i.zz=t.L00.scale(.886277).add(t.L20.scale(.495417)),i.yz=t.L2_1.scale(.858086),i.zx=t.L21.scale(.858086),i.xy=t.L2_2.scale(.858086),i},e}();e.SphericalPolynomial=b;var E=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=E;var A=function(){function e(e,t,i){void 0===e&&(e=o.Zero()),void 0===t&&(t=o.Up()),void 0===i&&(i=r.Zero()),this.position=e,this.normal=t,this.uv=i}return e.prototype.clone=function(){return new e(this.position.clone(),this.normal.clone(),this.uv.clone())},e}();e.PositionNormalTextureVertex=A;var T=function(){function e(){}return e.Color3=[i.Black(),i.Black(),i.Black()],e.Vector2=[r.Zero(),r.Zero(),r.Zero()],e.Vector3=[o.Zero(),o.Zero(),o.Zero(),o.Zero(),o.Zero(),o.Zero(),o.Zero(),o.Zero(),o.Zero()],e.Vector4=[s.Zero(),s.Zero(),s.Zero()],e.Quaternion=[new a(0,0,0,0)],e.Matrix=[h.Zero(),h.Zero(),h.Zero(),h.Zero(),h.Zero(),h.Zero(),h.Zero(),h.Zero()],e}();e.Tmp=T}(BABYLON||(BABYLON={}));var BABYLON;!function(e){function t(e,t){return function(i,n){i.__serializableMembers||(i.__serializableMembers={}),i.__serializableMembers[n]={type:e,sourceName:t}}}function i(e){return t(0,e)}function n(e){return t(1,e)}function r(e){return t(2,e)}function o(e){return t(3,e)}function s(e){return t(4,e)}function a(e){return t(5,e)}function h(e){return t(6,e)}e.serialize=i,e.serializeAsTexture=n,e.serializeAsColor3=r,e.serializeAsFresnelParameters=o,e.serializeAsVector2=s,e.serializeAsVector3=a,e.serializeAsMeshReference=h;var c=function(){function t(){}return t.Serialize=function(t,i){i||(i={}),i.tags=e.Tags.GetTags(t);for(var n in t.__serializableMembers){var r=t.__serializableMembers[n],o=r.sourceName||n,s=r.type,a=t[n];if(void 0!==a&&null!==a)switch(s){case 0:i[o]=a;break;case 1:i[o]=a.serialize();break;case 2:i[o]=a.asArray();break;case 3:i[o]=a.serialize();break;case 4:i[o]=a.asArray();break;case 5:i[o]=a.asArray();break;case 6:i[o]=a.id}}return i},t.Parse=function(t,i,n,r){var o=t();e.Tags.AddTagsTo(o,i.tags);for(var s in o.__serializableMembers){var a=o.__serializableMembers[s],h=i[a.sourceName||s],c=a.type;if(void 0!==h&&null!==h)switch(c){case 0:o[s]=h;break;case 1:o[s]=e.Texture.Parse(h,n,r);break;case 2:o[s]=e.Color3.FromArray(h);break;case 3:o[s]=e.FresnelParameters.Parse(h);break;case 4:o[s]=e.Vector2.FromArray(h);break;case 5:o[s]=e.Vector3.FromArray(h);break;case 6:o[s]=n.getLastMeshByID(h)}}return o},t.Clone=function(t,i){var n=t();e.Tags.AddTagsTo(n,i.tags);for(var r in n.__serializableMembers){var o=n.__serializableMembers[r],s=i[r],a=o.type;if(void 0!==s&&null!==s)switch(a){case 0:case 6:n[r]=s;break;case 1:case 2:case 3:case 4:case 5:n[r]=s.clone()}}return n},t}();e.SerializationHelper=c}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){void 0===e&&(e=!1),this.skipNextObervers=e}return e}();e.EventState=t;var i=function(){function e(e,t){this.callback=e,this.mask=t}return e}();e.Observer=i;var n=function(){function e(){this._observers=new Array}return e.prototype.add=function(e,t,n){if(void 0===t&&(t=-1),void 0===n&&(n=!1),!e)return null;var r=new i(e,t);return n?this._observers.unshift(r):this._observers.push(r),r},e.prototype.remove=function(e){var t=this._observers.indexOf(e);return-1!==t?(this._observers.splice(t,1),!0):!1},e.prototype.removeCallback=function(e){for(var t=0;t<this._observers.length;t++)if(this._observers[t].callback===e)return this._observers.splice(t,1),!0;return!1},e.prototype.notifyObservers=function(e,i){void 0===i&&(i=-1);for(var n=new t,r=0,o=this._observers;r<o.length;r++){var s=o[r];if(s.mask&i&&s.callback(e,n),n.skipNextObervers)break}},e.prototype.hasObservers=function(){return this._observers.length>0},e.prototype.clear=function(){this._observers=new Array},e.prototype.clone=function(){var t=new e;return t._observers=this._observers.slice(0),t},e}();e.Observable=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,i){this.idbFactory=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,this.callbackManifestChecked=i,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(){n.enableSceneOffline=!1,n.enableTexturesOffline=!1,n.callbackManifestChecked(!1)}var i=this,n=this,r=!1,o=this.currentSceneUrl+".manifest",s=new XMLHttpRequest;navigator.onLine&&(r=!0,o=o+(null==o.match(/\?/)?"?":"&")+(new Date).getTime()),s.open("GET",o,!0),s.addEventListener("load",function(){if(200===s.status||e.Tools.ValidateXHRData(s,1))try{var n=JSON.parse(s.response);i.enableSceneOffline=n.enableSceneOffline,i.enableTexturesOffline=n.enableTexturesOffline,n.version&&!isNaN(parseInt(n.version))&&(i.manifestVersionFound=n.version),i.callbackManifestChecked&&i.callbackManifestChecked(!0)}catch(r){t()}else t()},!1),s.addEventListener("error",function(e){if(r){r=!1;var n=i.currentSceneUrl+".manifest";s.open("GET",n,!0),s.send()}else t()},!1);try{s.send()}catch(a){e.Tools.Error("Error on XHR send request."),n.callbackManifestChecked(!1)}},t.prototype.openAsync=function(t,i){function n(){o.isSupported=!1,i&&i()}var r=this,o=this;if(this.idbFactory&&(this.enableSceneOffline||this.enableTexturesOffline))if(this.db)t&&t();else{this.hasReachedQuota=!1,this.isSupported=!0;var s=this.idbFactory.open("babylonjs",1);s.onerror=function(e){n()},s.onblocked=function(t){e.Tools.Error("IDB request blocked. Please reload the page."),n()},s.onsuccess=function(e){r.db=s.result,t()},s.onupgradeneeded=function(t){r.db=t.target.result;try{r.db.createObjectStore("scenes",{keyPath:"sceneUrl"}),r.db.createObjectStore("versions",{keyPath:"sceneUrl"}),r.db.createObjectStore("textures",{keyPath:"textureUrl"})}catch(i){e.Tools.Error("Error while creating object stores. Exception: "+i.message),n()}}}else this.isSupported=!1,i&&i()},t.prototype.loadImageFromDB=function(e,i){var n=this,r=t.ReturnFullUrlLocation(e),o=function(){n.hasReachedQuota||null===n.db?i.src=e:n._saveImageIntoDBAsync(r,i)};this.mustUpdateRessources?o():this._loadImageFromDBAsync(r,i,o)},t.prototype._loadImageFromDBAsync=function(t,i,n){if(this.isSupported&&null!==this.db){var r,o=this.db.transaction(["textures"]);o.onabort=function(e){i.src=t},o.oncomplete=function(o){var s;if(r){var a=window.URL||window.webkitURL;s=a.createObjectURL(r.data,{oneTimeOnly:!0}),i.onerror=function(){e.Tools.Error("Error loading image from blob URL: "+s+" switching back to web url: "+t),i.src=t},i.src=s}else n()};var s=o.objectStore("textures").get(t);s.onsuccess=function(e){r=e.target.result},s.onerror=function(n){e.Tools.Error("Error loading texture "+t+" from DB."),i.src=t}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i.src=t},t.prototype._saveImageIntoDBAsync=function(i,n){var r=this;if(this.isSupported){var o=function(){var e;if(s){var t=window.URL||window.webkitURL;try{e=t.createObjectURL(s,{oneTimeOnly:!0})}catch(i){e=t.createObjectURL(s)}}n.src=e};if(t.IsUASupportingBlobStorage){var s,a=new XMLHttpRequest;a.open("GET",i,!0),a.responseType="blob",a.addEventListener("load",function(){if(200===a.status){s=a.response;var e=r.db.transaction(["textures"],"readwrite");e.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(t){}o()},e.oncomplete=function(e){o()};var h={textureUrl:i,data:s};try{var c=e.objectStore("textures").put(h);c.onsuccess=function(e){},c.onerror=function(e){o()}}catch(l){25===l.code&&(t.IsUASupportingBlobStorage=!1),n.src=i}}else n.src=i},!1),a.addEventListener("error",function(t){e.Tools.Error("Error in XHR request in BABYLON.Database."),n.src=i},!1),a.send()}else n.src=i}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),n.src=i},t.prototype._checkVersionFromDB=function(e,t){var i=this,n=function(n){i._saveVersionIntoDBAsync(e,t)};this._loadVersionFromDBAsync(e,t,n)},t.prototype._loadVersionFromDBAsync=function(t,i,n){var r=this;if(this.isSupported){var o;try{var s=this.db.transaction(["versions"]);s.oncomplete=function(e){o?r.manifestVersionFound>o.data?(r.mustUpdateRessources=!0,n()):i(o.data):(r.mustUpdateRessources=!0,n())},s.onabort=function(e){i(-1)};var a=s.objectStore("versions").get(t);a.onsuccess=function(e){o=e.target.result},a.onerror=function(n){e.Tools.Error("Error loading version for scene "+t+" from DB."),i(-1)}}catch(h){e.Tools.Error("Error while accessing 'versions' object store (READ OP). Exception: "+h.message),i(-1)}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i(-1)},t.prototype._saveVersionIntoDBAsync=function(t,i){var n=this;if(this.isSupported&&!this.hasReachedQuota)try{var r=this.db.transaction(["versions"],"readwrite");r.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(n.hasReachedQuota=!0)}catch(t){}i(-1)},r.oncomplete=function(e){i(n.manifestVersionFound)};var o={sceneUrl:t,data:this.manifestVersionFound},s=r.objectStore("versions").put(o);s.onsuccess=function(e){},s.onerror=function(t){e.Tools.Error("Error in DB add version request in BABYLON.Database.")}}catch(a){e.Tools.Error("Error while accessing 'versions' object store (WRITE OP). Exception: "+a.message),i(-1)}else i(-1)},t.prototype.loadFileFromDB=function(e,i,n,r,o){var s=this,a=t.ReturnFullUrlLocation(e),h=function(e){s._saveFileIntoDBAsync(a,i,n)};this._checkVersionFromDB(a,function(e){-1!==e?s.mustUpdateRessources?s._saveFileIntoDBAsync(a,i,n,o):s._loadFileFromDBAsync(a,i,h,o):r()})},t.prototype._loadFileFromDBAsync=function(t,i,n,r){if(this.isSupported){var o;o=-1!==t.indexOf(".babylon")?"scenes":"textures";var s,a=this.db.transaction([o]);a.oncomplete=function(e){s?i(s.data):n()},a.onabort=function(e){n()};var h=a.objectStore(o).get(t);h.onsuccess=function(e){s=e.target.result},h.onerror=function(i){e.Tools.Error("Error loading file "+t+" from DB."),n()}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},t.prototype._saveFileIntoDBAsync=function(t,i,n,r){var o=this;if(this.isSupported){var s;s=-1!==t.indexOf(".babylon")?"scenes":"textures";var a,h=new XMLHttpRequest;h.open("GET",t,!0),r&&(h.responseType="arraybuffer"),h.onprogress=n,h.addEventListener("load",function(){if(200===h.status||e.Tools.ValidateXHRData(h,r?6:1))if(a=r?h.response:h.responseText,o.hasReachedQuota)i(a);else{var n=o.db.transaction([s],"readwrite");n.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(t){}i(a)},n.oncomplete=function(e){i(a)};var c;c="scenes"===s?{sceneUrl:t,data:a,version:o.manifestVersionFound}:{textureUrl:t,data:a};try{var l=n.objectStore(s).put(c);l.onsuccess=function(e){},l.onerror=function(t){e.Tools.Error("Error in DB add file request in BABYLON.Database.")}}catch(u){i(a)}}else i()},!1),h.addEventListener("error",function(t){e.Tools.Error("error on XHR request."),i()},!1),h.send()}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},t.IsUASupportingBlobStorage=!0,t.IDBStorageEnabled=!0,t.parseURL=function(e){var t=document.createElement("a");t.href=e;var i=e.substring(0,e.lastIndexOf("#")),n=e.substring(i.lastIndexOf("/")+1,e.length),r=e.substring(0,e.indexOf(n,0));return r},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 i=function(){function t(){}return t.GetTGAHeader=function(e){var t=0,i={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 i},t.UploadContent=function(i,n){if(n.length<19)return void e.Tools.Error("Unable to load TGA file - Not enough data to contain header");var r=18,o=t.GetTGAHeader(n);if(o.id_length+r>n.length)return void e.Tools.Error("Unable to load TGA file - Not enough data");r+=o.id_length;var s=!1,a=!1,h=!1,c=!1;switch(o.image_type){case t._TYPE_RLE_INDEXED:s=!0;case t._TYPE_INDEXED:a=!0;break;case t._TYPE_RLE_RGB:s=!0;case t._TYPE_RGB:h=!0;break;case t._TYPE_RLE_GREY:s=!0;case t._TYPE_GREY:c=!0}var l,u,d=(15&o.flags,o.pixel_size>>3),f=o.width*o.height*d;if(a&&(u=n.subarray(r,r+=o.colormap_length*(o.colormap_size>>3))),s){l=new Uint8Array(f);for(var p,m,_,g=0,v=new Uint8Array(d);f>r&&f>g;)if(p=n[r++],m=(127&p)+1,128&p){for(_=0;d>_;++_)v[_]=n[r++];for(_=0;m>_;++_)l.set(v,g+_*d);g+=d*m}else{for(m*=d,_=0;m>_;++_)l[g+_]=n[r++];g+=m}}else l=n.subarray(r,r+=a?o.width*o.height:f);var y,x,b,E,A,T;switch((o.flags&t._ORIGIN_MASK)>>t._ORIGIN_SHIFT){default:case t._ORIGIN_UL:y=0,b=1,T=o.width,x=0,E=1,A=o.height;break;case t._ORIGIN_BL:y=0,b=1,T=o.width,x=o.height-1,E=-1,A=-1;break;case t._ORIGIN_UR:y=o.width-1,b=-1,T=-1,x=0,E=1,A=o.height;break;case t._ORIGIN_BR:y=o.width-1,b=-1,T=-1,x=o.height-1,E=-1,A=-1}var P="_getImageData"+(c?"Grey":"")+o.pixel_size+"bits",M=t[P](o,u,l,x,E,A,y,b,T);i.texImage2D(i.TEXTURE_2D,0,i.RGBA,o.width,o.height,0,i.RGBA,i.UNSIGNED_BYTE,M)},t._getImageData8bits=function(e,t,i,n,r,o,s,a,h){var c,l,u,d=i,f=t,p=e.width,m=e.height,_=0,g=new Uint8Array(p*m*4);for(u=n;u!==o;u+=r)for(l=s;l!==h;l+=a,_++)c=d[_],g[4*(l+p*u)+3]=255,g[4*(l+p*u)+2]=f[3*c+0],g[4*(l+p*u)+1]=f[3*c+1],g[4*(l+p*u)+0]=f[3*c+2];return g},t._getImageData16bits=function(e,t,i,n,r,o,s,a,h){var c,l,u,d=i,f=e.width,p=e.height,m=0,_=new Uint8Array(f*p*4);for(u=n;u!==o;u+=r)for(l=s;l!==h;l+=a,m+=2)c=d[m+0]+(d[m+1]<<8),_[4*(l+f*u)+0]=(31744&c)>>7,_[4*(l+f*u)+1]=(992&c)>>2,_[4*(l+f*u)+2]=(31&c)>>3,_[4*(l+f*u)+3]=32768&c?0:255;return _},t._getImageData24bits=function(e,t,i,n,r,o,s,a,h){var c,l,u=i,d=e.width,f=e.height,p=0,m=new Uint8Array(d*f*4);for(l=n;l!==o;l+=r)for(c=s;c!==h;c+=a,p+=3)m[4*(c+d*l)+3]=255,m[4*(c+d*l)+2]=u[p+0],m[4*(c+d*l)+1]=u[p+1],m[4*(c+d*l)+0]=u[p+2];return m},t._getImageData32bits=function(e,t,i,n,r,o,s,a,h){var c,l,u=i,d=e.width,f=e.height,p=0,m=new Uint8Array(d*f*4);for(l=n;l!==o;l+=r)for(c=s;c!==h;c+=a,p+=4)m[4*(c+d*l)+2]=u[p+0],m[4*(c+d*l)+1]=u[p+1],m[4*(c+d*l)+0]=u[p+2],m[4*(c+d*l)+3]=u[p+3];return m},t._getImageDataGrey8bits=function(e,t,i,n,r,o,s,a,h){var c,l,u,d=i,f=e.width,p=e.height,m=0,_=new Uint8Array(f*p*4);for(u=n;u!==o;u+=r)for(l=s;l!==h;l+=a,m++)c=d[m],_[4*(l+f*u)+0]=c,_[4*(l+f*u)+1]=c,_[4*(l+f*u)+2]=c,_[4*(l+f*u)+3]=255;return _},t._getImageDataGrey16bits=function(e,t,i,n,r,o,s,a,h){var c,l,u=i,d=e.width,f=e.height,p=0,m=new Uint8Array(d*f*4);for(l=n;l!==o;l+=r)for(c=s;c!==h;c+=a,p+=2)m[4*(c+d*l)+0]=u[p+0],m[4*(c+d*l)+1]=u[p+0],m[4*(c+d*l)+2]=u[p+0],m[4*(c+d*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=i}(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){
  3. 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 i=(e.data||e)[t];this.pushNoDuplicate(i)}}},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;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}},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,i=function(t,i){return t?t instanceof e.Mesh?null:t instanceof e.SubMesh?t.clone(i):t.clone?t.clone():null:null},n=function(){function n(){}return n.Instantiate=function(e){for(var t=e.split("."),i=window||this,n=0,r=t.length;r>n;n++)i=i[t[n]];return"function"!=typeof i?null:i},n.SetImmediate=function(e){window.setImmediate?window.setImmediate(e):setTimeout(e,1)},n.IsExponentOfTwo=function(e){var t=1;do t*=2;while(e>t);return t===e},n.GetExponentOfTwo=function(e,t){var i=1;do i*=2;while(e>i);return i>t&&(i=t),i},n.GetFilename=function(e){var t=e.lastIndexOf("/");return 0>t?e:e.substring(t+1)},n.GetDOMTextContent=function(e){for(var t="",i=e.firstChild;i;)3===i.nodeType&&(t+=i.textContent),i=i.nextSibling;return t},n.ToDegrees=function(e){return 180*e/Math.PI},n.ToRadians=function(e){return e*Math.PI/180},n.EncodeArrayBufferTobase64=function(e){for(var t,i,n,r,o,s,a,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c="",l=0,u=new Uint8Array(e);l<u.length;)t=u[l++],i=l<u.length?u[l++]:Number.NaN,n=l<u.length?u[l++]:Number.NaN,r=t>>2,o=(3&t)<<4|i>>4,s=(15&i)<<2|n>>6,a=63&n,isNaN(i)?s=a=64:isNaN(n)&&(a=64),c+=h.charAt(r)+h.charAt(o)+h.charAt(s)+h.charAt(a);return"data:image/png;base64,"+c},n.ExtractMinAndMaxIndexed=function(t,i,n,r,o){void 0===o&&(o=null);for(var s=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),a=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),h=n;n+r>h;h++){var c=new e.Vector3(t[3*i[h]],t[3*i[h]+1],t[3*i[h]+2]);s=e.Vector3.Minimize(c,s),a=e.Vector3.Maximize(c,a)}return o&&(s.x-=s.x*o.x+o.y,s.y-=s.y*o.x+o.y,s.z-=s.z*o.x+o.y,a.x+=a.x*o.x+o.y,a.y+=a.y*o.x+o.y,a.z+=a.z*o.x+o.y),{minimum:s,maximum:a}},n.ExtractMinAndMax=function(t,i,n,r){void 0===r&&(r=null);for(var o=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),s=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),a=i;i+n>a;a++){var h=new e.Vector3(t[3*a],t[3*a+1],t[3*a+2]);o=e.Vector3.Minimize(h,o),s=e.Vector3.Maximize(h,s)}return r&&(o.x-=o.x*r.x+r.y,o.y-=o.y*r.x+r.y,o.z-=o.z*r.x+r.y,s.x+=s.x*r.x+r.y,s.y+=s.y*r.x+r.y,s.z+=s.z*r.x+r.y),{minimum:o,maximum:s}},n.MakeArray=function(e,t){return t===!0||void 0!==e&&null!=e?Array.isArray(e)?e:[e]:void 0},n.GetPointerPrefix=function(){var e="pointer";return window.PointerEvent||navigator.pointerEnabled||(e="mouse"),e},n.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)},n.RequestFullscreen=function(e){e.requestFullscreen?e.requestFullscreen():e.msRequestFullscreen?e.msRequestFullscreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.mozRequestFullScreen&&e.mozRequestFullScreen()},n.ExitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.msCancelFullScreen&&document.msCancelFullScreen()},n.CleanUrl=function(e){return e=e.replace(/#/gm,"%23")},n.LoadImage=function(t,i,r,o){t instanceof ArrayBuffer&&(t=n.EncodeArrayBufferTobase64(t)),t=n.CleanUrl(t);var s=new Image;if("data:"!==t.substr(0,5)&&n.CorsBehavior)switch(typeof n.CorsBehavior){case"function":var a=n.CorsBehavior(t);a&&(s.crossOrigin=a);break;case"string":default:s.crossOrigin=n.CorsBehavior}s.onload=function(){i(s)},s.onerror=function(e){n.Error("Error while trying to load texture: "+t),n.UseFallbackTexture?(s.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",i(s)):r()};var h=function(){s.src=t},c=function(){o.loadImageFromDB(t,s)};if("data:"!==t.substr(0,5)&&o&&o.enableTexturesOffline&&e.Database.IsUASupportingBlobStorage)o.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(d){l=URL.createObjectURL(e.FilesInput.FilesTextures[u])}s.src=l}catch(f){s.src=null}return s},n.LoadFile=function(t,i,r,o,s,a){t=n.CleanUrl(t);var h=function(){var e=new XMLHttpRequest,o=n.BaseUrl+t;e.open("GET",o,!0),s&&(e.responseType="arraybuffer"),e.onprogress=r,e.onreadystatechange=function(){if(4===e.readyState)if(200===e.status||n.ValidateXHRData(e,s?6:1))i(s?e.response:e.responseText);else{if(!a)throw new Error("Error status: "+e.status+" - Unable to load "+o);a()}},e.send(null)},c=function(){o.loadFileFromDB(t,i,r,h,s)};if(-1!==t.indexOf("file:")){var l=t.substring(5).toLowerCase();n.ReadFile(e.FilesInput.FilesToLoad[l],i,r,s)}else o&&o.enableSceneOffline?o.openAsync(c,h):h()},n.ReadFileAsDataURL=function(e,t,i){var n=new FileReader;n.onload=function(e){t(e.target.result)},n.onprogress=i,n.readAsDataURL(e)},n.ReadFile=function(e,t,i,r){var o=new FileReader;o.onerror=function(i){n.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:[]}))},o.onload=function(e){t(e.target.result)},o.onprogress=i,r?o.readAsArrayBuffer(e):o.readAsText(e)},n.FileAsURL=function(e){var t=new Blob([e]),i=window.URL||window.webkitURL,n=i.createObjectURL(t);return n},n.Format=function(e,t){return void 0===t&&(t=2),e.toFixed(t)},n.CheckExtends=function(e,t,i){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>i.x&&(i.x=e.x),e.y>i.y&&(i.y=e.y),e.z>i.z&&(i.z=e.z)},n.DeepCopy=function(e,t,n,r){for(var o in e)if(("_"!==o[0]||r&&-1!==r.indexOf(o))&&(!n||-1===n.indexOf(o))){var s=e[o],a=typeof s;if("function"!==a)if("object"===a)if(s instanceof Array){if(t[o]=[],s.length>0)if("object"==typeof s[0])for(var h=0;h<s.length;h++){var c=i(s[h],t);-1===t[o].indexOf(c)&&t[o].push(c)}else t[o]=s.slice(0)}else t[o]=i(s,t);else t[o]=s}},n.IsEmpty=function(e){for(var t in e)return!1;return!0},n.RegisterTopRootEvents=function(e){for(var t=0;t<e.length;t++){var i=e[t];window.addEventListener(i.name,i.handler,!1);try{window.parent&&window.parent.addEventListener(i.name,i.handler,!1)}catch(n){}}},n.UnregisterTopRootEvents=function(e){for(var t=0;t<e.length;t++){var i=e[t];window.removeEventListener(i.name,i.handler);try{window.parent&&window.parent.removeEventListener(i.name,i.handler)}catch(n){}}},n.DumpFramebuffer=function(e,i,n,r){for(var o=4*e,s=i/2,a=n.readPixels(0,0,e,i),h=0;s>h;h++)for(var c=0;o>c;c++){var l=c+h*o,u=i-h-1,d=c+u*o,f=a[l];a[l]=a[d],a[d]=f}t||(t=document.createElement("canvas")),t.width=e,t.height=i;var p=t.getContext("2d"),m=p.createImageData(e,i),_=m.data;_.set(a),p.putImageData(m,0,0);var g=t.toDataURL();if(r)r(g);else if("download"in document.createElement("a")){var v=window.document.createElement("a");v.href=g;var y=new Date,x=(y.getFullYear()+"-"+(y.getMonth()+1)).slice(-2)+"-"+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 b=window.open(""),E=b.document.createElement("img");E.src=g,b.document.body.appendChild(E)}},n.CreateScreenshot=function(t,i,r,o){var s,a;if(r.precision)s=Math.round(t.getRenderWidth()*r.precision),a=Math.round(s/t.getAspectRatio(i)),r={width:s,height:a};else if(r.width&&r.height)s=r.width,a=r.height;else if(r.width&&!r.height)s=r.width,a=Math.round(s/t.getAspectRatio(i)),r={width:s,height:a};else if(r.height&&!r.width)a=r.height,s=Math.round(a*t.getAspectRatio(i)),r={width:s,height:a};else{if(isNaN(r))return void n.Error("Invalid 'size' parameter !");a=r,s=r}var h=i.getScene(),c=null;h.activeCamera!==i&&(c=h.activeCamera,h.activeCamera=i);var l=new e.RenderTargetTexture("screenShot",r,h,!1,!1);l.renderList=h.meshes,l.onAfterRender=function(){n.DumpFramebuffer(s,a,t,o)},h.incrementRenderId(),l.render(!0),l.dispose(),c&&(h.activeCamera=c),i.getProjectionMatrix(!0)},n.ValidateXHRData=function(t,i){void 0===i&&(i=7);try{if(1&i){if(t.responseText&&t.responseText.length>0)return!0;if(1===i)return!1}if(2&i){var n=e.Internals.TGATools.GetTGAHeader(t.response);if(n.width&&n.height&&n.width>0&&n.height>0)return!0;if(2===i)return!1}if(4&i){var r=new Uint8Array(t.response,0,3);return 68===r[0]&&68===r[1]&&83===r[2]}}catch(o){}return!1},Object.defineProperty(n,"NoneLogLevel",{get:function(){return n._NoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(n,"MessageLogLevel",{get:function(){return n._MessageLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(n,"WarningLogLevel",{get:function(){return n._WarningLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ErrorLogLevel",{get:function(){return n._ErrorLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(n,"AllLogLevel",{get:function(){return n._MessageLogLevel|n._WarningLogLevel|n._ErrorLogLevel},enumerable:!0,configurable:!0}),n._AddLogEntry=function(e){n._LogCache=e+n._LogCache,n.OnNewCacheEntry&&n.OnNewCacheEntry(e)},n._FormatMessage=function(e){var t=function(e){return 10>e?"0"+e:""+e},i=new Date;return"["+t(i.getHours())+":"+t(i.getMinutes())+":"+t(i.getSeconds())+"]: "+e},n._LogDisabled=function(e){},n._LogEnabled=function(e){var t=n._FormatMessage(e);console.log("BJS - "+t);var i="<div style='color:white'>"+t+"</div><br>";n._AddLogEntry(i)},n._WarnDisabled=function(e){},n._WarnEnabled=function(e){var t=n._FormatMessage(e);console.warn("BJS - "+t);var i="<div style='color:orange'>"+t+"</div><br>";n._AddLogEntry(i)},n._ErrorDisabled=function(e){},n._ErrorEnabled=function(e){n.errorsCount++;var t=n._FormatMessage(e);console.error("BJS - "+t);var i="<div style='color:red'>"+t+"</div><br>";n._AddLogEntry(i)},Object.defineProperty(n,"LogCache",{get:function(){return n._LogCache},enumerable:!0,configurable:!0}),n.ClearLogCache=function(){n._LogCache="",n.errorsCount=0},Object.defineProperty(n,"LogLevels",{set:function(e){(e&n.MessageLogLevel)===n.MessageLogLevel?n.Log=n._LogEnabled:n.Log=n._LogDisabled,(e&n.WarningLogLevel)===n.WarningLogLevel?n.Warn=n._WarnEnabled:n.Warn=n._WarnDisabled,(e&n.ErrorLogLevel)===n.ErrorLogLevel?n.Error=n._ErrorEnabled:n.Error=n._ErrorDisabled},enumerable:!0,configurable:!0}),Object.defineProperty(n,"PerformanceNoneLogLevel",{get:function(){return n._PerformanceNoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(n,"PerformanceUserMarkLogLevel",{get:function(){return n._PerformanceUserMarkLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(n,"PerformanceConsoleLogLevel",{get:function(){return n._PerformanceConsoleLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(n,"PerformanceLogLevel",{set:function(e){return(e&n.PerformanceUserMarkLogLevel)===n.PerformanceUserMarkLogLevel?(n.StartPerformanceCounter=n._StartUserMark,void(n.EndPerformanceCounter=n._EndUserMark)):(e&n.PerformanceConsoleLogLevel)===n.PerformanceConsoleLogLevel?(n.StartPerformanceCounter=n._StartPerformanceConsole,void(n.EndPerformanceCounter=n._EndPerformanceConsole)):(n.StartPerformanceCounter=n._StartPerformanceCounterDisabled,void(n.EndPerformanceCounter=n._EndPerformanceCounterDisabled))},enumerable:!0,configurable:!0}),n._StartPerformanceCounterDisabled=function(e,t){},n._EndPerformanceCounterDisabled=function(e,t){},n._StartUserMark=function(e,t){void 0===t&&(t=!0),t&&n._performance.mark&&n._performance.mark(e+"-Begin")},n._EndUserMark=function(e,t){void 0===t&&(t=!0),t&&n._performance.mark&&(n._performance.mark(e+"-End"),n._performance.measure(e,e+"-Begin",e+"-End"))},n._StartPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(n._StartUserMark(e,t),console.time&&console.time(e))},n._EndPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(n._EndUserMark(e,t),console.time&&console.timeEnd(e))},Object.defineProperty(n,"Now",{get:function(){return window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},enumerable:!0,configurable:!0}),n.BaseUrl="",n.CorsBehavior="anonymous",n.UseFallbackTexture=!0,n._NoneLogLevel=0,n._MessageLogLevel=1,n._WarningLogLevel=2,n._ErrorLogLevel=4,n._LogCache="",n.errorsCount=0,n.Log=n._LogEnabled,n.Warn=n._WarnEnabled,n.Error=n._ErrorEnabled,n._PerformanceNoneLogLevel=0,n._PerformanceUserMarkLogLevel=1,n._PerformanceConsoleLogLevel=2,n._performance=window.performance,n.StartPerformanceCounter=n._StartPerformanceCounterDisabled,n.EndPerformanceCounter=n._EndPerformanceCounterDisabled,n}();e.Tools=n;var r=function(){function e(e,t,i,n){void 0===n&&(n=0),this.iterations=e,this._fn=t,this._successCallback=i,this.index=n-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,i,n,r){void 0===r&&(r=0);var o=new e(t,i,n,r);return o.executeNext(),o},e.SyncAsyncForLoop=function(t,i,n,r,o,s){void 0===s&&(s=0),e.Run(Math.ceil(t/i),function(e){o&&o()?e.breakLoop():setTimeout(function(){for(var r=0;i>r;++r){var s=e.index*i+r;if(s>=t)break;if(n(s),o&&o()){e.breakLoop();break}}e.executeNext()},s)},r)},e}();e.AsyncLoop=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(e){var t=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,i,n){this._blendFunctionParameters[0]===e&&this._blendFunctionParameters[1]===t&&this._blendFunctionParameters[2]===i&&this._blendFunctionParameters[3]===n||(this._blendFunctionParameters[0]=e,this._blendFunctionParameters[1]=t,this._blendFunctionParameters[2]=i,this._blendFunctionParameters[3]=n,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=t}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!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}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e,t,i,n){var r=e.createShader("vertex"===i?e.VERTEX_SHADER:e.FRAGMENT_SHADER);if(e.shaderSource(r,(n?n+"\n":"")+t),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(r));return r},i=function(e,t){var i=e.UNSIGNED_BYTE;return t===h.TEXTURETYPE_FLOAT&&(i=e.FLOAT),i},n=function(t,i,n){var r=n.NEAREST,o=n.NEAREST;return t===e.Texture.BILINEAR_SAMPLINGMODE?(r=n.LINEAR,o=i?n.LINEAR_MIPMAP_NEAREST:n.LINEAR):t===e.Texture.TRILINEAR_SAMPLINGMODE?(r=n.LINEAR,o=i?n.LINEAR_MIPMAP_LINEAR:n.LINEAR):t===e.Texture.NEAREST_SAMPLINGMODE&&(r=n.NEAREST,o=i?n.NEAREST_MIPMAP_LINEAR:n.NEAREST),{min:o,mag:r}},r=function(t,i,r,o,s,a,h,c,l,u,d){void 0===d&&(d=e.Texture.TRILINEAR_SAMPLINGMODE);var f=r.getEngine(),p=e.Tools.GetExponentOfTwo(o,f.getCaps().maxTextureSize),m=e.Tools.GetExponentOfTwo(s,f.getCaps().maxTextureSize);i.bindTexture(i.TEXTURE_2D,t),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,void 0===a?1:a?1:0),t._baseWidth=o,t._baseHeight=s,t._width=p,t._height=m,t.isReady=!0,l(p,m);var _=n(d,!h,i);i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,_.mag),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,_.min),h||c||i.generateMipmap(i.TEXTURE_2D),i.bindTexture(i.TEXTURE_2D,null),f.resetTextureCache(),r._removePendingData(t),u&&u()},o=function(t,i,n,r,o){var s,a=function(){n[i]=s,n._internalCount++,r._removePendingData(s),6===n._internalCount&&o(n)},h=function(){r._removePendingData(s)};s=e.Tools.LoadImage(t,a,h,r.database),r._addPendingData(s)},s=function(e,t,i,n){var r=[];r._internalCount=0;for(var s=0;6>s;s++)o(n[s],s,r,t,i)},a=function(){function e(){}return e}();e.EngineCapabilities=a;var h=function(){function o(t,i,n,r){var s=this;if(void 0===r&&(r=!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 e.Internals._DepthCullingState,this._alphaState=new e.Internals._AlphaState,this._alphaMode=o.ALPHA_DISABLE,this._loadedTexturesCache=new Array,this._maxTextureChannels=16,this._activeTexturesCache=new Array(this._maxTextureChannels),this._compiledEffects={},this._uintIndicesCurrentlySet=!1,this._renderingCanvas=t,n=n||{},n.antialias=i,void 0===n.preserveDrawingBuffer&&(n.preserveDrawingBuffer=!1),!this._gl)try{this._gl=t.getContext("webgl",n)||t.getContext("experimental-webgl",n)}catch(h){throw new Error("WebGL not supported")}if(!this._gl)throw new Error("WebGL not supported");this._onBlur=function(){s._windowIsBackground=!0},this._onFocus=function(){s._windowIsBackground=!1},window.addEventListener("blur",this._onBlur),window.addEventListener("focus",this._onFocus);var c=n.limitDeviceRatio||window.devicePixelRatio||1;this._hardwareScalingLevel=r?1/Math.min(c,window.devicePixelRatio||1):1,this.resize(),this._caps=new a,this._caps.maxTexturesImageUnits=this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS),this._caps.maxTextureSize=this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE),this._caps.maxCubemapTextureSize=this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE),this._caps.maxRenderTextureSize=this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE),this._glVersion=this._gl.getParameter(this._gl.VERSION);var l=this._gl.getExtension("WEBGL_debug_renderer_info");if(null!=l&&(this._glRenderer=this._gl.getParameter(l.UNMASKED_RENDERER_WEBGL),this._glVendor=this._gl.getParameter(l.UNMASKED_VENDOR_WEBGL)),this._glVendor||(this._glVendor="Unknown vendor"),this._glRenderer||(this._glRenderer="Unknown renderer"),this._caps.standardDerivatives=null!==this._gl.getExtension("OES_standard_derivatives"),this._caps.s3tc=this._gl.getExtension("WEBGL_compressed_texture_s3tc"),this._caps.textureFloat=null!==this._gl.getExtension("OES_texture_float"),this._caps.textureAnisotropicFilterExtension=this._gl.getExtension("EXT_texture_filter_anisotropic")||this._gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this._gl.getExtension("MOZ_EXT_texture_filter_anisotropic"),this._caps.maxAnisotropy=this._caps.textureAnisotropicFilterExtension?this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT):0,this._caps.instancedArrays=this._gl.getExtension("ANGLE_instanced_arrays"),this._caps.uintIndices=null!==this._gl.getExtension("OES_element_index_uint"),this._caps.fragmentDepthSupported=null!==this._gl.getExtension("EXT_frag_depth"),this._caps.highPrecisionShaderSupported=!0,this._caps.drawBuffersExtension=this._gl.getExtension("WEBGL_draw_buffers"),this._caps.textureFloatLinearFiltering=this._gl.getExtension("OES_texture_float_linear"),this._caps.textureLOD=this._gl.getExtension("EXT_shader_texture_lod"),this._gl.getShaderPrecisionFormat){var u=this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER,this._gl.HIGH_FLOAT);this._caps.highPrecisionShaderSupported=0!==u.precision}this.setDepthBuffer(!0),this.setDepthFunctionToLessOrEqual(),this.setDepthWrite(!0),this._onFullscreenChange=function(){void 0!==document.fullscreen?s.isFullscreen=document.fullscreen:void 0!==document.mozFullScreen?s.isFullscreen=document.mozFullScreen:void 0!==document.webkitIsFullScreen?s.isFullscreen=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(s.isFullscreen=document.msIsFullScreen),s.isFullscreen&&s._pointerLockRequested&&(t.requestPointerLock=t.requestPointerLock||t.msRequestPointerLock||t.mozRequestPointerLock||t.webkitRequestPointerLock,t.requestPointerLock&&t.requestPointerLock())},document.addEventListener("fullscreenchange",this._onFullscreenChange,!1),document.addEventListener("mozfullscreenchange",this._onFullscreenChange,!1),document.addEventListener("webkitfullscreenchange",this._onFullscreenChange,!1),document.addEventListener("msfullscreenchange",this._onFullscreenChange,!1),this._onPointerLockChange=function(){s.isPointerLock=document.mozPointerLockElement===t||document.webkitPointerLockElement===t||document.msPointerLockElement===t||document.pointerLockElement===t},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&&!o.audioEngine&&(o.audioEngine=new e.AudioEngine),this._loadingScreen=new e.DefaultLoadingScreen(this._renderingCanvas),e.Tools.Log("Babylon.js engine (v"+o.Version+") launched")}return Object.defineProperty(o,"ALPHA_DISABLE",{get:function(){return o._ALPHA_DISABLE},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_ONEONE",{get:function(){return o._ALPHA_ONEONE},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_ADD",{get:function(){return o._ALPHA_ADD},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_COMBINE",{get:function(){return o._ALPHA_COMBINE},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_SUBTRACT",{get:function(){return o._ALPHA_SUBTRACT},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_MULTIPLY",{get:function(){return o._ALPHA_MULTIPLY},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_MAXIMIZED",{get:function(){return o._ALPHA_MAXIMIZED},enumerable:!0,configurable:!0}),Object.defineProperty(o,"DELAYLOADSTATE_NONE",{get:function(){return o._DELAYLOADSTATE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(o,"DELAYLOADSTATE_LOADED",{get:function(){return o._DELAYLOADSTATE_LOADED},enumerable:!0,configurable:!0}),Object.defineProperty(o,"DELAYLOADSTATE_LOADING",{get:function(){return o._DELAYLOADSTATE_LOADING},enumerable:!0,configurable:!0}),Object.defineProperty(o,"DELAYLOADSTATE_NOTLOADED",{get:function(){return o._DELAYLOADSTATE_NOTLOADED},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTUREFORMAT_ALPHA",{get:function(){return o._TEXTUREFORMAT_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTUREFORMAT_LUMINANCE",{
  4. get:function(){return o._TEXTUREFORMAT_LUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTUREFORMAT_LUMINANCE_ALPHA",{get:function(){return o._TEXTUREFORMAT_LUMINANCE_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTUREFORMAT_RGB",{get:function(){return o._TEXTUREFORMAT_RGB},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTUREFORMAT_RGBA",{get:function(){return o._TEXTUREFORMAT_RGBA},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTURETYPE_UNSIGNED_INT",{get:function(){return o._TEXTURETYPE_UNSIGNED_INT},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTURETYPE_FLOAT",{get:function(){return o._TEXTURETYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(o,"Version",{get:function(){return"2.4.0-alpha"},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"webGLVersion",{get:function(){return this._webGLVersion},enumerable:!0,configurable:!0}),o.prototype._prepareWorkingCanvas=function(){this._workingCanvas||(this._workingCanvas=document.createElement("canvas"),this._workingContext=this._workingCanvas.getContext("2d"))},o.prototype.resetTextureCache=function(){for(var e=0;e<this._maxTextureChannels;e++)this._activeTexturesCache[e]=null},o.prototype.getGlInfo=function(){return{vendor:this._glVendor,renderer:this._glRenderer,version:this._glVersion}},o.prototype.getAspectRatio=function(e,t){void 0===t&&(t=!1);var i=e.viewport;return this.getRenderWidth(t)*i.width/(this.getRenderHeight(t)*i.height)},o.prototype.getRenderWidth=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget._width:this._renderingCanvas.width},o.prototype.getRenderHeight=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget._height:this._renderingCanvas.height},o.prototype.getRenderingCanvas=function(){return this._renderingCanvas},o.prototype.getRenderingCanvasClientRect=function(){return this._renderingCanvas.getBoundingClientRect()},o.prototype.setHardwareScalingLevel=function(e){this._hardwareScalingLevel=e,this.resize()},o.prototype.getHardwareScalingLevel=function(){return this._hardwareScalingLevel},o.prototype.getLoadedTexturesCache=function(){return this._loadedTexturesCache},o.prototype.getCaps=function(){return this._caps},Object.defineProperty(o.prototype,"drawCalls",{get:function(){return this._drawCalls},enumerable:!0,configurable:!0}),o.prototype.resetDrawCalls=function(){this._drawCalls=0},o.prototype.setDepthFunctionToGreater=function(){this._depthCullingState.depthFunc=this._gl.GREATER},o.prototype.setDepthFunctionToGreaterOrEqual=function(){this._depthCullingState.depthFunc=this._gl.GEQUAL},o.prototype.setDepthFunctionToLess=function(){this._depthCullingState.depthFunc=this._gl.LESS},o.prototype.setDepthFunctionToLessOrEqual=function(){this._depthCullingState.depthFunc=this._gl.LEQUAL},o.prototype.stopRenderLoop=function(e){if(!e)return void(this._activeRenderLoops=[]);var t=this._activeRenderLoops.indexOf(e);t>=0&&this._activeRenderLoops.splice(t,1)},o.prototype._renderLoop=function(){var t=!0;if(!this.renderEvenInBackground&&this._windowIsBackground&&(t=!1),t){this.beginFrame();for(var i=0;i<this._activeRenderLoops.length;i++){var n=this._activeRenderLoops[i];n()}this.endFrame()}this._activeRenderLoops.length>0?e.Tools.QueueNewFrame(this._bindedRenderFunction):this._renderingQueueLaunched=!1},o.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)))},o.prototype.switchFullscreen=function(t){this.isFullscreen?e.Tools.ExitFullscreen():(this._pointerLockRequested=t,e.Tools.RequestFullscreen(this._renderingCanvas))},o.prototype.clear=function(e,t,i){this.applyStates(),t&&this._gl.clearColor(e.r,e.g,e.b,void 0!==e.a?e.a:1),i&&this._depthCullingState.depthMask&&this._gl.clearDepth(1);var n=0;t&&(n|=this._gl.COLOR_BUFFER_BIT),i&&this._depthCullingState.depthMask&&(n|=this._gl.DEPTH_BUFFER_BIT),this._gl.clear(n)},o.prototype.setViewport=function(e,t,i){var n=t||(navigator.isCocoonJS?window.innerWidth:this._renderingCanvas.width),r=i||(navigator.isCocoonJS?window.innerHeight:this._renderingCanvas.height),o=e.x||0,s=e.y||0;this._cachedViewport=e,this._gl.viewport(o*n,s*r,n*e.width,r*e.height)},o.prototype.setDirectViewport=function(e,t,i,n){this._cachedViewport=null,this._gl.viewport(e,t,i,n)},o.prototype.beginFrame=function(){this._measureFps()},o.prototype.endFrame=function(){},o.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 i=0;i<this.scenes.length;i++){var n=this.scenes[i];n.debugLayer.isVisible()&&n.debugLayer._syncPositions()}},o.prototype.setSize=function(e,t){this._renderingCanvas.width=e,this._renderingCanvas.height=t;for(var i=0;i<this.scenes.length;i++)for(var n=this.scenes[i],r=0;r<n.cameras.length;r++){var o=n.cameras[r];o._currentRenderId=0}},o.prototype.bindFramebuffer=function(e,t){this._currentRenderTarget=e;var i=this._gl;i.bindFramebuffer(i.FRAMEBUFFER,e._framebuffer),e.isCube?i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_CUBE_MAP_POSITIVE_X+t,e,0):i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,e,0),this._gl.viewport(0,0,e._width,e._height),this.wipeCaches()},o.prototype.unBindFramebuffer=function(e,t){if(void 0===t&&(t=!1),this._currentRenderTarget=null,e.generateMipMaps&&!t){var i=this._gl;i.bindTexture(i.TEXTURE_2D,e),i.generateMipmap(i.TEXTURE_2D),i.bindTexture(i.TEXTURE_2D,null)}this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,null)},o.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)}},o.prototype.flushFramebuffer=function(){this._gl.flush()},o.prototype.restoreDefaultFramebuffer=function(){this._currentRenderTarget=null,this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,null),this.setViewport(this._cachedViewport),this.wipeCaches()},o.prototype._resetVertexBufferBinding=function(){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,null),this._cachedVertexBuffers=null},o.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},o.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},o.prototype.updateDynamicVertexBuffer=function(e,t,i){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e),void 0===i&&(i=0),t instanceof Float32Array?this._gl.bufferSubData(this._gl.ARRAY_BUFFER,i,t):this._gl.bufferSubData(this._gl.ARRAY_BUFFER,i,new Float32Array(t)),this._resetVertexBufferBinding()},o.prototype._resetIndexBufferBinding=function(){this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,null),this._cachedIndexBuffer=null},o.prototype.createIndexBuffer=function(e){var t=this._gl.createBuffer();this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,t);var i,n=!1;if(this._caps.uintIndices){for(var r=0;r<e.length;r++)if(e[r]>65535){n=!0;break}i=n?new Uint32Array(e):new Uint16Array(e)}else i=new Uint16Array(e);return this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,i,this._gl.STATIC_DRAW),this._resetIndexBufferBinding(),t.references=1,t.is32Bits=n,t},o.prototype.bindBuffers=function(e,t,i,n,r){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==r){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=r,this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e);for(var o=0,s=0;s<i.length;s++){var a=r.getAttributeLocation(s);a>=0&&this._gl.vertexAttribPointer(a,i[s],this._gl.FLOAT,!1,n,o),o+=4*i[s]}}this._cachedIndexBuffer!==t&&(this._cachedIndexBuffer=t,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,t),this._uintIndicesCurrentlySet=t.is32Bits)},o.prototype.bindMultiBuffers=function(e,t,i){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==i){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=i;for(var n=i.getAttributesNames(),r=0;r<n.length;r++){var o=i.getAttributeLocation(r);if(o>=0){var s=e[n[r]];if(!s)continue;var a=s.getStrideSize();this._gl.bindBuffer(this._gl.ARRAY_BUFFER,s.getBuffer()),this._gl.vertexAttribPointer(o,a,this._gl.FLOAT,!1,4*a,0)}}}null!=t&&this._cachedIndexBuffer!==t&&(this._cachedIndexBuffer=t,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,t),this._uintIndicesCurrentlySet=t.is32Bits)},o.prototype._releaseBuffer=function(e){return e.references--,0===e.references?(this._gl.deleteBuffer(e),!0):!1},o.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},o.prototype.deleteInstancesBuffer=function(e){this._gl.deleteBuffer(e)},o.prototype.updateAndBindInstancesBuffer=function(e,t,i){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e),this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,t);for(var n=0;4>n;n++){var r=i[n];this._gl.enableVertexAttribArray(r),this._gl.vertexAttribPointer(r,4,this._gl.FLOAT,!1,64,16*n),this._caps.instancedArrays.vertexAttribDivisorANGLE(r,1)}},o.prototype.unBindInstancesBuffer=function(e,t){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e);for(var i=0;4>i;i++){var n=t[i];this._gl.disableVertexAttribArray(n),this._caps.instancedArrays.vertexAttribDivisorANGLE(n,0)}},o.prototype.applyStates=function(){this._depthCullingState.apply(this._gl),this._alphaState.apply(this._gl)},o.prototype.draw=function(e,t,i,n){this.applyStates(),this._drawCalls++;var r=this._uintIndicesCurrentlySet?this._gl.UNSIGNED_INT:this._gl.UNSIGNED_SHORT,o=this._uintIndicesCurrentlySet?4:2;return n?void this._caps.instancedArrays.drawElementsInstancedANGLE(e?this._gl.TRIANGLES:this._gl.LINES,i,r,t*o,n):void this._gl.drawElements(e?this._gl.TRIANGLES:this._gl.LINES,i,r,t*o)},o.prototype.drawPointClouds=function(e,t,i){return this.applyStates(),this._drawCalls++,i?void this._caps.instancedArrays.drawArraysInstancedANGLE(this._gl.POINTS,e,t,i):void this._gl.drawArrays(this._gl.POINTS,e,t)},o.prototype.drawUnIndexed=function(e,t,i,n){return this.applyStates(),this._drawCalls++,n?void this._caps.instancedArrays.drawArraysInstancedANGLE(e?this._gl.TRIANGLES:this._gl.LINES,t,i,n):void this._gl.drawArrays(e?this._gl.TRIANGLES:this._gl.LINES,t,i)},o.prototype._releaseEffect=function(e){this._compiledEffects[e._key]&&(delete this._compiledEffects[e._key],e.getProgram()&&this._gl.deleteProgram(e.getProgram()))},o.prototype.createEffect=function(t,i,n,r,o,s,a,h){var c=t.vertexElement||t.vertex||t,l=t.fragmentElement||t.fragment||t,u=c+"+"+l+"@"+o;if(this._compiledEffects[u])return this._compiledEffects[u];var d=new e.Effect(t,i,n,r,this,o,s,a,h);return d._key=u,this._compiledEffects[u]=d,d},o.prototype.createEffectForParticles=function(e,t,i,n,r,o,s){return void 0===t&&(t=[]),void 0===i&&(i=[]),void 0===n&&(n=""),this.createEffect({vertex:"particles",fragmentElement:e},["position","color","options"],["view","projection"].concat(t),["diffuseSampler"].concat(i),n,r,o,s)},o.prototype.createShaderProgram=function(e,i,n){var r=t(this._gl,e,"vertex",n),o=t(this._gl,i,"fragment",n),s=this._gl.createProgram();this._gl.attachShader(s,r),this._gl.attachShader(s,o),this._gl.linkProgram(s);var a=this._gl.getProgramParameter(s,this._gl.LINK_STATUS);if(!a){var h=this._gl.getProgramInfoLog(s);if(h)throw new Error(h)}return this._gl.deleteShader(r),this._gl.deleteShader(o),s},o.prototype.getUniforms=function(e,t){for(var i=[],n=0;n<t.length;n++)i.push(this._gl.getUniformLocation(e,t[n]));return i},o.prototype.getAttributes=function(e,t){for(var i=[],n=0;n<t.length;n++)try{i.push(this._gl.getAttribLocation(e,t[n]))}catch(r){i.push(-1)}return i},o.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){var i=+t;i>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[i]||(this._vertexAttribArrays[i]=!1,this._gl.disableVertexAttribArray(i))}for(var n=e.getAttributesCount(),r=0;n>r;r++){var o=e.getAttributeLocation(r);o>=0&&(this._vertexAttribArrays[o]=!0,this._gl.enableVertexAttribArray(o))}this._currentEffect=e,e.onBind&&e.onBind(e)},o.prototype.setArray=function(e,t){e&&this._gl.uniform1fv(e,t)},o.prototype.setArray2=function(e,t){e&&t.length%2===0&&this._gl.uniform2fv(e,t)},o.prototype.setArray3=function(e,t){e&&t.length%3===0&&this._gl.uniform3fv(e,t)},o.prototype.setArray4=function(e,t){e&&t.length%4===0&&this._gl.uniform4fv(e,t)},o.prototype.setMatrices=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t)},o.prototype.setMatrix=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t.toArray())},o.prototype.setMatrix3x3=function(e,t){e&&this._gl.uniformMatrix3fv(e,!1,t)},o.prototype.setMatrix2x2=function(e,t){e&&this._gl.uniformMatrix2fv(e,!1,t)},o.prototype.setFloat=function(e,t){e&&this._gl.uniform1f(e,t)},o.prototype.setFloat2=function(e,t,i){e&&this._gl.uniform2f(e,t,i)},o.prototype.setFloat3=function(e,t,i,n){e&&this._gl.uniform3f(e,t,i,n)},o.prototype.setBool=function(e,t){e&&this._gl.uniform1i(e,t)},o.prototype.setFloat4=function(e,t,i,n,r){e&&this._gl.uniform4f(e,t,i,n,r)},o.prototype.setColor3=function(e,t){e&&this._gl.uniform3f(e,t.r,t.g,t.b)},o.prototype.setColor4=function(e,t,i){e&&this._gl.uniform4f(e,t.r,t.g,t.b,i)},o.prototype.setState=function(e,t,i,n){void 0===t&&(t=0),void 0===n&&(n=!1);var r=n?this._gl.FRONT:this._gl.BACK,o=n?this._gl.BACK:this._gl.FRONT,s=this.cullBackFaces?r:o;(this._depthCullingState.cull!==e||i||this._depthCullingState.cullFace!==s)&&(e?(this._depthCullingState.cullFace=s,this._depthCullingState.cull=!0):this._depthCullingState.cull=!1),this._depthCullingState.zOffset=t},o.prototype.setDepthBuffer=function(e){this._depthCullingState.depthTest=e},o.prototype.getDepthWrite=function(){return this._depthCullingState.depthMask},o.prototype.setDepthWrite=function(e){this._depthCullingState.depthMask=e},o.prototype.setColorWrite=function(e){this._gl.colorMask(e,e,e,e)},o.prototype.setAlphaMode=function(e){if(this._alphaMode!==e){switch(e){case o.ALPHA_DISABLE:this.setDepthWrite(!0),this._alphaState.alphaBlend=!1;break;case o.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 o.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 o.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 o.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 o.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 o.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}},o.prototype.getAlphaMode=function(){return this._alphaMode},o.prototype.setAlphaTesting=function(e){this._alphaTest=e},o.prototype.getAlphaTesting=function(){return this._alphaTest},o.prototype.wipeCaches=function(){this.resetTextureCache(),this._currentEffect=null,this._depthCullingState.reset(),this._alphaState.reset(),this._cachedVertexBuffers=null,this._cachedIndexBuffer=null,this._cachedEffectForVertexBuffers=null},o.prototype.setSamplingMode=function(t,i){var n=this._gl;n.bindTexture(n.TEXTURE_2D,t);var r=n.NEAREST,o=n.NEAREST;i===e.Texture.BILINEAR_SAMPLINGMODE?(r=n.LINEAR,o=n.LINEAR):i===e.Texture.TRILINEAR_SAMPLINGMODE&&(r=n.LINEAR,o=n.LINEAR_MIPMAP_LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,r),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,o),n.bindTexture(n.TEXTURE_2D,null),t.samplingMode=i},o.prototype.createTexture=function(t,i,n,o,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,d=this._gl.createTexture(),f=!1;if("data:"===t.substr(0,5)&&(f=!0),f){var p=t;f=p.split(":"),t=p,u=f[1].substr(f[1].length-4,4).toLowerCase()}else u=t.substr(t.length-4,4).toLowerCase();var m=this.getCaps().s3tc&&".dds"===u,_=".tga"===u;o._addPendingData(d),d.url=t,d.noMipmap=i,d.references=1,d.samplingMode=s,this._loadedTexturesCache.push(d);var g,v=function(){o._removePendingData(d),h&&h()};if(_)g=function(t){var h=new Uint8Array(t),c=e.Internals.TGATools.GetTGAHeader(h);r(d,l._gl,o,c.width,c.height,n,i,!1,function(){e.Internals.TGATools.UploadContent(l._gl,h)},a,s)},f instanceof Array?g(c):e.Tools.LoadFile(t,function(e){g(e)},v,o.database,!0);else if(m)g=function(t){var h=e.Internals.DDSTools.GetDDSInfo(t),c=(h.isRGB||h.isLuminance||h.mipmapCount>1)&&!i&&h.width>>h.mipmapCount-1===1;r(d,l._gl,o,h.width,h.height,n,!c,h.isFourCC,function(){e.Internals.DDSTools.UploadDDSLevels(l._gl,l.getCaps().s3tc,t,h,c,1)},a,s)},f instanceof Array?g(c):e.Tools.LoadFile(t,function(e){g(e)},v,o.database,!0);else{var y=function(t){r(d,l._gl,o,t.width,t.height,n,i,!1,function(i,n){var r=t.width===i&&t.height===n;r||(l._prepareWorkingCanvas(),l._workingCanvas.width=i,l._workingCanvas.height=n,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,i,n),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,r?t:l._workingCanvas)},a,s)};f instanceof Array?e.Tools.LoadImage(c,y,v,o.database):e.Tools.LoadImage(t,y,v,o.database)}return d},o.prototype._getInternalFormat=function(e){var t=this._gl.RGBA;switch(e){case o.TEXTUREFORMAT_ALPHA:t=this._gl.ALPHA;break;case o.TEXTUREFORMAT_LUMINANCE:t=this._gl.LUMINANCE;break;case o.TEXTUREFORMAT_LUMINANCE_ALPHA:t=this._gl.LUMINANCE_ALPHA;break;case o.TEXTUREFORMAT_RGB:t=this._gl.RGB;break;case o.TEXTUREFORMAT_RGBA:t=this._gl.RGBA}return t},o.prototype.updateRawTexture=function(e,t,i,n,r){void 0===r&&(r=null);var o=this._getInternalFormat(i);this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,void 0===n?1:n?1:0),r?this._gl.compressedTexImage2D(this._gl.TEXTURE_2D,0,this.getCaps().s3tc[r],e._width,e._height,0,t):this._gl.texImage2D(this._gl.TEXTURE_2D,0,o,e._width,e._height,0,o,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},o.prototype.createRawTexture=function(e,t,i,r,o,s,a,h){void 0===h&&(h=null);var c=this._gl.createTexture();c._baseWidth=t,c._baseHeight=i,c._width=t,c._height=i,c.references=1,this.updateRawTexture(c,e,r,s,h),this._gl.bindTexture(this._gl.TEXTURE_2D,c);var l=n(a,o,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},o.prototype.createDynamicTexture=function(t,i,n,r,o){void 0===o&&(o=!0);var s=this._gl.createTexture();return s._baseWidth=t,s._baseHeight=i,o&&(t=e.Tools.GetExponentOfTwo(t,this._caps.maxTextureSize),i=e.Tools.GetExponentOfTwo(i,this._caps.maxTextureSize)),this.resetTextureCache(),s._width=t,s._height=i,s.isReady=!1,s.generateMipMaps=n,s.references=1,s.samplingMode=r,this.updateTextureSamplingMode(r,s),this._loadedTexturesCache.push(s),s},o.prototype.updateTextureSamplingMode=function(e,t){var i=n(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,i.mag),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_MIN_FILTER,i.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,i.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,i.min),this._gl.bindTexture(this._gl.TEXTURE_2D,null))},o.prototype.updateDynamicTexture=function(e,t,i){this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,i?1:0),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this.resetTextureCache(),e.isReady=!0},o.prototype.updateVideoTexture=function(e,t,i){if(!e._isDisabled){this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,i?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(n){e._isDisabled=!0}}},o.prototype.createRenderTargetTexture=function(t,r){var s=!1,a=!0,h=o.TEXTURETYPE_UNSIGNED_INT,c=e.Texture.TRILINEAR_SAMPLINGMODE;void 0!==r&&(s=void 0===r.generateMipMaps?r:r.generateMipMaps,a=void 0===r.generateDepthBuffer?!0:r.generateDepthBuffer,h=void 0===r.type?h:r.type,void 0!==r.samplingMode&&(c=r.samplingMode),h===o.TEXTURETYPE_FLOAT&&(c=e.Texture.NEAREST_SAMPLINGMODE));var l=this._gl,u=l.createTexture();l.bindTexture(l.TEXTURE_2D,u);var d=t.width||t,f=t.height||t,p=n(c,s,l);h!==o.TEXTURETYPE_FLOAT||this._caps.textureFloat||(h=o.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,d,f,0,l.RGBA,i(l,h),null);var m;a&&(m=l.createRenderbuffer(),l.bindRenderbuffer(l.RENDERBUFFER,m),l.renderbufferStorage(l.RENDERBUFFER,l.DEPTH_COMPONENT16,d,f));var _=l.createFramebuffer();return l.bindFramebuffer(l.FRAMEBUFFER,_),a&&l.framebufferRenderbuffer(l.FRAMEBUFFER,l.DEPTH_ATTACHMENT,l.RENDERBUFFER,m),s&&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=_,a&&(u._depthBuffer=m),u._width=d,u._height=f,u.isReady=!0,u.generateMipMaps=s,u.references=1,u.samplingMode=c,this.resetTextureCache(),this._loadedTexturesCache.push(u),u},o.prototype.createRenderTargetCubeTexture=function(t,i){var r=this._gl,o=r.createTexture(),s=!0,a=e.Texture.TRILINEAR_SAMPLINGMODE;void 0!==i&&(s=void 0===i.generateMipMaps?i:i.generateMipMaps,void 0!==i.samplingMode&&(a=i.samplingMode)),o.isCube=!0,o.references=1,o.generateMipMaps=s,o.references=1,o.samplingMode=a;var h=n(a,s,r);r.bindTexture(r.TEXTURE_CUBE_MAP,o);for(var c=0;6>c;c++)r.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+c,0,r.RGBA,t,t,0,r.RGBA,r.UNSIGNED_BYTE,null);r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_MAG_FILTER,h.mag),r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_MIN_FILTER,h.min),r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE);var l=r.createRenderbuffer();r.bindRenderbuffer(r.RENDERBUFFER,l),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT16,t,t);var u=r.createFramebuffer();return r.bindFramebuffer(r.FRAMEBUFFER,u),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,l),o.generateMipMaps&&(r.bindTexture(r.TEXTURE_CUBE_MAP,o),r.generateMipmap(r.TEXTURE_CUBE_MAP)),r.bindTexture(r.TEXTURE_CUBE_MAP,null),r.bindRenderbuffer(r.RENDERBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),o._framebuffer=u,o._depthBuffer=l,this.resetTextureCache(),o._width=t,o._height=t,o.isReady=!0,o},o.prototype.createCubeTexture=function(t,i,n,r){var o=this,a=this._gl,h=a.createTexture();h.isCube=!0,h.url=t,h.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 i=e.Internals.DDSTools.GetDDSInfo(t),n=(i.isRGB||i.isLuminance||i.mipmapCount>1)&&!r;a.bindTexture(a.TEXTURE_CUBE_MAP,h),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,1),e.Internals.DDSTools.UploadDDSLevels(o._gl,o.getCaps().s3tc,t,i,n,6),r||i.isFourCC||1!==i.mipmapCount||a.generateMipmap(a.TEXTURE_CUBE_MAP),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MIN_FILTER,n?a.LINEAR_MIPMAP_LINEAR:a.LINEAR),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.bindTexture(a.TEXTURE_CUBE_MAP,null),o.resetTextureCache(),h._width=i.width,h._height=i.height,h.isReady=!0},null,null,!0):s(t,i,function(t){var i=e.Tools.GetExponentOfTwo(t[0].width,o._caps.maxCubemapTextureSize),n=i;o._prepareWorkingCanvas(),o._workingCanvas.width=i,o._workingCanvas.height=n;var s=[a.TEXTURE_CUBE_MAP_POSITIVE_X,a.TEXTURE_CUBE_MAP_POSITIVE_Y,a.TEXTURE_CUBE_MAP_POSITIVE_Z,a.TEXTURE_CUBE_MAP_NEGATIVE_X,a.TEXTURE_CUBE_MAP_NEGATIVE_Y,a.TEXTURE_CUBE_MAP_NEGATIVE_Z];a.bindTexture(a.TEXTURE_CUBE_MAP,h),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,0);for(var c=0;c<s.length;c++)o._workingContext.drawImage(t[c],0,0,t[c].width,t[c].height,0,0,i,n),a.texImage2D(s[c],0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,o._workingCanvas);r||a.generateMipmap(a.TEXTURE_CUBE_MAP),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MIN_FILTER,r?a.LINEAR:a.LINEAR_MIPMAP_LINEAR),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.bindTexture(a.TEXTURE_CUBE_MAP,null),o.resetTextureCache(),h._width=i,h._height=n,h.isReady=!0},n),h},o.prototype.createRawCubeTexture=function(t,i,n,r,s,a,h,c){var l=this,u=this._gl,d=u.createTexture();i._addPendingData(d),d.isCube=!0,d.references=1,d.url=t;var f=this._getInternalFormat(r),p=u.UNSIGNED_BYTE;s===o.TEXTURETYPE_FLOAT&&(p=u.FLOAT);var m=n,_=m,g=e.Tools.IsExponentOfTwo(m)&&e.Tools.IsExponentOfTwo(_);d._width=m,d._height=_;var v=function(){i._removePendingData(d)},y=function(e){var t=h(e),n=[u.TEXTURE_CUBE_MAP_POSITIVE_X,u.TEXTURE_CUBE_MAP_POSITIVE_Y,u.TEXTURE_CUBE_MAP_POSITIVE_Z,u.TEXTURE_CUBE_MAP_NEGATIVE_X,u.TEXTURE_CUBE_MAP_NEGATIVE_Y,u.TEXTURE_CUBE_MAP_NEGATIVE_Z];if(u.bindTexture(u.TEXTURE_CUBE_MAP,d),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,0),!a&&g)if(c){var r=[];r.push(t[0]),r.push(t[3]),r.push(t[1]),r.push(t[4]),r.push(t[2]),r.push(t[5]);for(var o=c(r),s=0;s<o.length;s++){var v=m>>s;u.texImage2D(n[0],s,f,v,v,0,f,p,o[s][0]),u.texImage2D(n[1],s,f,v,v,0,f,p,o[s][2]),u.texImage2D(n[2],s,f,v,v,0,f,p,o[s][4]),u.texImage2D(n[3],s,f,v,v,0,f,p,o[s][1]),u.texImage2D(n[4],s,f,v,v,0,f,p,o[s][3]),u.texImage2D(n[5],s,f,v,v,0,f,p,o[s][5])}}else{for(var y=0;y<n.length;y++){var x=t[y];u.texImage2D(n[y],0,f,m,_,0,f,p,x)}u.generateMipmap(u.TEXTURE_CUBE_MAP)}else a=!0;p!=u.FLOAT||l._caps.textureFloatLinearFiltering?(u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MAG_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MIN_FILTER,a?u.LINEAR:u.LINEAR_MIPMAP_LINEAR)):(u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MIN_FILTER,u.NEAREST)),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.bindTexture(u.TEXTURE_CUBE_MAP,null),d.isReady=!0,l.resetTextureCache(),i._removePendingData(d)};return e.Tools.LoadFile(t,function(e){y(e)},v,i.database,!0),d},o.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 i=this._loadedTexturesCache.indexOf(e);-1!==i&&this._loadedTexturesCache.splice(i,1)},o.prototype.bindSamplers=function(e){this._gl.useProgram(e.getProgram());for(var t=e.getSamplers(),i=0;i<t.length;i++){var n=e.getUniform(t[i]);this._gl.uniform1i(n,i)}this._currentEffect=null},o.prototype._bindTexture=function(e,t){this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,t),this._activeTexturesCache[e]=null},o.prototype.setTextureFromPostProcess=function(e,t){this._bindTexture(e,t._textures.data[t._currentRenderTextureInd])},o.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},o.prototype.setTexture=function(t,i){if(!(0>t)){if(!i||!i.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 n=!1;if(i instanceof e.VideoTexture)this._gl.activeTexture(this._gl["TEXTURE"+t]),n=!0,i.update();else if(i.delayLoadState===o.DELAYLOADSTATE_NOTLOADED)return void i.delayLoad();if(this._activeTexturesCache[t]!==i){this._activeTexturesCache[t]=i;var r=i.getInternalTexture();if(n||this._gl.activeTexture(this._gl["TEXTURE"+t]),r.isCube){if(this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,r),r._cachedCoordinatesMode!==i.coordinatesMode){r._cachedCoordinatesMode=i.coordinatesMode;var s=i.coordinatesMode!==e.Texture.CUBIC_MODE&&i.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,i);
  5. }else{if(this._gl.bindTexture(this._gl.TEXTURE_2D,r),r._cachedWrapU!==i.wrapU)switch(r._cachedWrapU=i.wrapU,i.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(r._cachedWrapV!==i.wrapV)switch(r._cachedWrapV=i.wrapV,i.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,i)}}}},o.prototype._setAnisotropicLevel=function(t,i){var n=this._caps.textureAnisotropicFilterExtension,r=i.anisotropicFilteringLevel;i.getInternalTexture().samplingMode===e.Texture.NEAREST_SAMPLINGMODE&&(r=1),n&&i._cachedAnisotropicFilteringLevel!==r&&(this._gl.texParameterf(t,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(r,this._caps.maxAnisotropy)),i._cachedAnisotropicFilteringLevel=r)},o.prototype.readPixels=function(e,t,i,n){var r=new Uint8Array(n*i*4);return this._gl.readPixels(e,t,i,n,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r),r},o.prototype.releaseInternalTexture=function(e){if(e&&(e.references--,0===e.references)){var t=this.getLoadedTexturesCache(),i=t.indexOf(e);i>-1&&t.splice(i,1),this._releaseTexture(e)}},o.prototype.dispose=function(){for(this.hideLoadingUI(),this.stopRenderLoop();this.scenes.length;)this.scenes[0].dispose();o.audioEngine.dispose();for(var e in this._compiledEffects)this._gl.deleteProgram(this._compiledEffects[e]._program);for(var t in this._vertexAttribArrays){var i=+t;i>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[i]||this._gl.disableVertexAttribArray(i)}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)},o.prototype.displayLoadingUI=function(){this._loadingScreen.displayLoadingUI()},o.prototype.hideLoadingUI=function(){this._loadingScreen.hideLoadingUI()},Object.defineProperty(o.prototype,"loadingScreen",{get:function(){return this._loadingScreen},set:function(e){this._loadingScreen=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"loadingUIText",{set:function(e){this._loadingScreen.loadingUIText=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"loadingUIBackgroundColor",{set:function(e){this._loadingScreen.loadingUIBackgroundColor=e},enumerable:!0,configurable:!0}),o.prototype.getFps=function(){return this.fps},o.prototype.getDeltaTime=function(){return this.deltaTime},o.prototype._measureFps=function(){this.previousFramesDuration.push(e.Tools.Now);var t=this.previousFramesDuration.length;if(t>=2&&(this.deltaTime=this.previousFramesDuration[t-1]-this.previousFramesDuration[t-2]),t>=this.fpsRange){t>this.fpsRange&&(this.previousFramesDuration.splice(0,1),t=this.previousFramesDuration.length);for(var i=0,n=0;t-1>n;n++)i+=this.previousFramesDuration[n+1]-this.previousFramesDuration[n];this.fps=1e3/(i/(t-1))}},o.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(i){return!1}},o._ALPHA_DISABLE=0,o._ALPHA_ADD=1,o._ALPHA_COMBINE=2,o._ALPHA_SUBTRACT=3,o._ALPHA_MULTIPLY=4,o._ALPHA_MAXIMIZED=5,o._ALPHA_ONEONE=6,o._DELAYLOADSTATE_NONE=0,o._DELAYLOADSTATE_LOADED=1,o._DELAYLOADSTATE_LOADING=2,o._DELAYLOADSTATE_NOTLOADED=4,o._TEXTUREFORMAT_ALPHA=0,o._TEXTUREFORMAT_LUMINANCE=1,o._TEXTUREFORMAT_LUMINANCE_ALPHA=2,o._TEXTUREFORMAT_RGB=4,o._TEXTUREFORMAT_RGBA=5,o._TEXTURETYPE_UNSIGNED_INT=0,o._TEXTURETYPE_FLOAT=1,o.CollisionsEpsilon=.001,o.CodeRepository="src/",o.ShadersRepository="src/Shaders/",o}();e.Engine=h}(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 Object.defineProperty(t.prototype,"parent",{get:function(){return this._parentNode},set:function(e){if(this._parentNode!==e){if(this._parentNode){var t=this._parentNode._children.indexOf(this);-1!==t&&this._parentNode._children.splice(t,1)}this._parentNode=e,this._parentNode&&(this._parentNode._children||(this._parentNode._children=new Array),this._parentNode._children.push(this))}},enumerable:!0,configurable:!0}),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,i){if(void 0===t&&(t=!1),this._children)for(var n=0;n<this._children.length;n++){var r=this._children[n];i&&!i(r)||e.push(r),t||r._getDescendants(e,!1,i)}},t.prototype.getDescendants=function(e,t){var i=[];return this._getDescendants(i,e,t),i},t.prototype.getChildren=function(e){return this.getDescendants(!0,e)},t.prototype.getChildMeshes=function(t,i){var n=[];return this._getDescendants(n,t,function(t){return(!i||i(t))&&t instanceof e.AbstractMesh}),n},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 i=this.animations[t];if(i.name===e)return i}return null},t.prototype.createAnimationRange=function(t,i,n){if(!this._ranges[t]){this._ranges[t]=new e.AnimationRange(t,i,n);for(var r=0,o=this.animations.length;o>r;r++)this.animations[r]&&this.animations[r].createRange(t,i,n)}},t.prototype.deleteAnimationRange=function(e,t){void 0===t&&(t=!0);for(var i=0,n=this.animations.length;n>i;i++)this.animations[i]&&this.animations[i].deleteRange(e,t);this._ranges[e]=void 0},t.prototype.getAnimationRange=function(e){return this._ranges[e]},t.prototype.beginAnimation=function(e,t,i,n){var r=this.getAnimationRange(e);return r?void this._scene.beginAnimation(this,r.from,r.to,t,i,n):null},t.prototype.serializeAnimationRanges=function(){var e=[];for(var t in this._ranges){var i={};i.name=t,i.from=this._ranges[t].from,i.to=this._ranges[t].to,e.push(i)}return e},t.prototype.dispose=function(){this.parent=null},t.ParseAnimationRanges=function(e,t,i){if(t.ranges)for(var n=0;n<t.ranges.length;n++){var r=t.ranges[n];e.createAnimationRange(r.name,r.from,r.to)}},__decorate([e.serialize()],t.prototype,"name",void 0),__decorate([e.serialize()],t.prototype,"id",void 0),__decorate([e.serialize()],t.prototype,"uniqueId",void 0),__decorate([e.serialize()],t.prototype,"state",void 0),t}();e.Node=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i,n,r,o,s,a){this._engine=e,this._canvas=i,this._currentScene=t,this._sceneLoadedCallback=n,this._progressCallback=r,this._additionnalRenderLoopLogicCallback=o,this._textureLoadingCallback=s,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 i=0;i<this._filesToLoad.length;i++)switch(this._filesToLoad[i].type){case"image/jpeg":case"image/png":case"image/bmp":t.FilesTextures[this._filesToLoad[i].name.toLowerCase()]=this._filesToLoad[i];break;case"image/targa":case"image/vnd.ms-dds":case"audio/wav":case"audio/x-wav":case"audio/mp3":case"audio/mpeg":case"audio/mpeg3":case"audio/x-mpeg-3":case"audio/ogg":t.FilesToLoad[this._filesToLoad[i].name.toLowerCase()]=this._filesToLoad[i];break;default:-1!==this._filesToLoad[i].name.indexOf(".mtl")?t.FilesToLoad[this._filesToLoad[i].name.toLowerCase()]=this._filesToLoad[i]:-1===this._filesToLoad[i].name.indexOf(".babylon")&&-1===this._filesToLoad[i].name.indexOf(".stl")&&-1===this._filesToLoad[i].name.indexOf(".obj")||-1!==this._filesToLoad[i].name.indexOf(".manifest")||-1!==this._filesToLoad[i].name.indexOf(".incremental")||-1!==this._filesToLoad[i].name.indexOf(".babylonmeshdata")||-1!==this._filesToLoad[i].name.indexOf(".babylongeometrydata")||-1!==this._filesToLoad[i].name.indexOf(".babylonbinarymeshdata")||-1!==this._filesToLoad[i].name.indexOf(".binary.babylon")||(this._sceneFileToLoad=this._filesToLoad[i])}this.reload()}},t.prototype.reload=function(){var t=this,i=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){i._currentScene=e,i._currentScene.executeWhenReady(function(){i._currentScene.activeCamera&&0!==i._currentScene.lights.length||i._currentScene.createDefaultCameraOrLight(),i._currentScene.activeCamera.attachControl(i._canvas),i._sceneLoadedCallback&&i._sceneLoadedCallback(t._sceneFileToLoad,i._currentScene),i._engine.runRenderLoop(function(){i.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,i){this.bu=e,this.bv=t,this.distance=i,this.faceId=0,this.subMeshId=0}return e}();e.IntersectionInfo=t;var i=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,i){if(void 0===t&&(t=!1),void 0===i&&(i=!0),!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(e.VertexBuffer.NormalKind))return null;var n,r=this.pickedMesh.getIndices();if(i){var o=this.pickedMesh.getVerticesData(e.VertexBuffer.NormalKind),s=e.Vector3.FromArray(o,3*r[3*this.faceId]),a=e.Vector3.FromArray(o,3*r[3*this.faceId+1]),h=e.Vector3.FromArray(o,3*r[3*this.faceId+2]);s=s.scale(this.bu),a=a.scale(this.bv),h=h.scale(1-this.bu-this.bv),n=new e.Vector3(s.x+a.x+h.x,s.y+a.y+h.y,s.z+a.z+h.z)}else{var c=this.pickedMesh.getVerticesData(e.VertexBuffer.PositionKind),l=e.Vector3.FromArray(c,3*r[3*this.faceId]),u=e.Vector3.FromArray(c,3*r[3*this.faceId+1]),d=e.Vector3.FromArray(c,3*r[3*this.faceId+2]),f=l.subtract(u),p=d.subtract(u);n=e.Vector3.Cross(f,p)}return t&&(n=e.Vector3.TransformNormal(n,this.pickedMesh.getWorldMatrix())),e.Vector3.Normalize(n)},t.prototype.getTextureCoordinates=function(){if(!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(e.VertexBuffer.UVKind))return null;var t=this.pickedMesh.getIndices(),i=this.pickedMesh.getVerticesData(e.VertexBuffer.UVKind),n=e.Vector2.FromArray(i,2*t[3*this.faceId]),r=e.Vector2.FromArray(i,2*t[3*this.faceId+1]),o=e.Vector2.FromArray(i,2*t[3*this.faceId+2]);return n=n.scale(1-this.bu-this.bv),r=r.scale(this.bu),o=o.scale(this.bv),new e.Vector2(n.x+r.x+o.x,n.y+r.y+o.y)},t}();e.PickingInfo=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){this.minimum=t,this.maximum=i,this._tempRadiusVector=e.Vector3.Zero();var n=e.Vector3.Distance(t,i);this.center=e.Vector3.Lerp(t,i,.5),this.radius=.5*n,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 i=this.centerWorld.x-t.x,n=this.centerWorld.y-t.y,r=this.centerWorld.z-t.z,o=Math.sqrt(i*i+n*n+r*r);return!(Math.abs(this.radiusWorld-o)<e.Epsilon)},t.Intersects=function(e,t){var i=e.centerWorld.x-t.centerWorld.x,n=e.centerWorld.y-t.centerWorld.y,r=e.centerWorld.z-t.centerWorld.z,o=Math.sqrt(i*i+n*n+r*r);return!(e.radiusWorld+t.radiusWorld<o)},t}();e.BoundingSphere=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){this.minimum=t,this.maximum=i,this.vectors=new Array,this.vectorsWorld=new Array,this.vectors.push(this.minimum.clone()),this.vectors.push(this.maximum.clone()),this.vectors.push(this.minimum.clone()),this.vectors[2].x=this.maximum.x,this.vectors.push(this.minimum.clone()),this.vectors[3].y=this.maximum.y,this.vectors.push(this.minimum.clone()),this.vectors[4].z=this.maximum.z,this.vectors.push(this.maximum.clone()),this.vectors[5].z=this.minimum.z,this.vectors.push(this.maximum.clone()),this.vectors[6].x=this.minimum.x,this.vectors.push(this.maximum.clone()),this.vectors[7].y=this.minimum.y,this.center=this.maximum.add(this.minimum).scale(.5),this.extendSize=this.maximum.subtract(this.minimum).scale(.5),this.directions=[e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero()];for(var n=0;n<this.vectors.length;n++)this.vectorsWorld[n]=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.setWorldMatrix=function(e){return this._worldMatrix.copyFrom(e),this},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 i=0;i<this.vectors.length;i++){var n=this.vectorsWorld[i];e.Vector3.TransformCoordinatesToRef(this.vectors[i],t,n),n.x<this.minimumWorld.x&&(this.minimumWorld.x=n.x),n.y<this.minimumWorld.y&&(this.minimumWorld.y=n.y),n.z<this.minimumWorld.z&&(this.minimumWorld.z=n.z),n.x>this.maximumWorld.x&&(this.maximumWorld.x=n.x),n.y>this.maximumWorld.y&&(this.maximumWorld.y=n.y),n.z>this.maximumWorld.z&&(this.maximumWorld.z=n.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 i=-e.Epsilon;return this.maximumWorld.x-t.x<i||i>t.x-this.minimumWorld.x?!1:this.maximumWorld.y-t.y<i||i>t.y-this.minimumWorld.y?!1:!(this.maximumWorld.z-t.z<i||i>t.z-this.minimumWorld.z)},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)},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)},t.IntersectsSphere=function(t,i,n,r){var o=e.Vector3.Clamp(n,t,i),s=e.Vector3.DistanceSquared(n,o);return r*r>=s},t.IsCompletelyInFrustum=function(e,t){for(var i=0;6>i;i++)for(var n=0;8>n;n++)if(t[i].dotCoordinate(e[n])<0)return!1;return!0},t.IsInFrustum=function(e,t){for(var i=0;6>i;i++){for(var n=8,r=0;8>r&&t[i].dotCoordinate(e[r])<0;r++)--n;if(0===n)return!1}return!0},t}();e.BoundingBox=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t,i){var n=e.Vector3.Dot(i.center,t),r=Math.abs(e.Vector3.Dot(i.directions[0],t))*i.extendSize.x,o=Math.abs(e.Vector3.Dot(i.directions[1],t))*i.extendSize.y,s=Math.abs(e.Vector3.Dot(i.directions[2],t))*i.extendSize.z,a=r+o+s;return{min:n-a,max:n+a}},i=function(e,t,i,n){return!(e>n||i>t)},n=function(e,n,r){var o=t(e,n),s=t(e,r);return i(o.min,o.max,s.min,s.max)},r=function(){function t(t,i){this.minimum=t,this.maximum=i,this._isLocked=!1,this.boundingBox=new e.BoundingBox(t,i),this.boundingSphere=new e.BoundingSphere(t,i)}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):!1},t.prototype.intersects=function(t,i){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(!i)return!0;var r=this.boundingBox,o=t.boundingBox;return n(r.directions[0],r,o)&&n(r.directions[1],r,o)&&n(r.directions[2],r,o)&&n(o.directions[0],r,o)&&n(o.directions[1],r,o)&&n(o.directions[2],r,o)&&n(e.Vector3.Cross(r.directions[0],o.directions[0]),r,o)&&n(e.Vector3.Cross(r.directions[0],o.directions[1]),r,o)&&n(e.Vector3.Cross(r.directions[0],o.directions[2]),r,o)&&n(e.Vector3.Cross(r.directions[1],o.directions[0]),r,o)&&n(e.Vector3.Cross(r.directions[1],o.directions[1]),r,o)&&n(e.Vector3.Cross(r.directions[1],o.directions[2]),r,o)&&n(e.Vector3.Cross(r.directions[2],o.directions[0]),r,o)&&n(e.Vector3.Cross(r.directions[2],o.directions[1]),r,o)?!!n(e.Vector3.Cross(r.directions[2],o.directions[2]),r,o):!1},t}();e.BoundingInfo=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i){void 0===i&&(i=Number.MAX_VALUE),this.origin=e,this.direction=t,this.length=i}return t.prototype.intersectsBoxMinMax=function(e,t){var i,n,r,o,s=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(i=1/this.direction.x,n=(e.x-this.origin.x)*i,r=(t.x-this.origin.x)*i,r===-(1/0)&&(r=1/0),n>r&&(o=n,n=r,r=o),s=Math.max(n,s),a=Math.min(r,a),s>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(i=1/this.direction.y,n=(e.y-this.origin.y)*i,r=(t.y-this.origin.y)*i,r===-(1/0)&&(r=1/0),n>r&&(o=n,n=r,r=o),s=Math.max(n,s),a=Math.min(r,a),s>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(i=1/this.direction.z,n=(e.z-this.origin.z)*i,r=(t.z-this.origin.z)*i,r===-(1/0)&&(r=1/0),n>r&&(o=n,n=r,r=o),s=Math.max(n,s),a=Math.min(r,a),s>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,i=e.center.y-this.origin.y,n=e.center.z-this.origin.z,r=t*t+i*i+n*n,o=e.radius*e.radius;if(o>=r)return!0;var s=t*this.direction.x+i*this.direction.y+n*this.direction.z;if(0>s)return!1;var a=r-s*s;return o>=a},t.prototype.intersectsTriangle=function(t,i,n){this._edge1||(this._edge1=e.Vector3.Zero(),this._edge2=e.Vector3.Zero(),this._pvec=e.Vector3.Zero(),this._tvec=e.Vector3.Zero(),this._qvec=e.Vector3.Zero()),i.subtractToRef(t,this._edge1),n.subtractToRef(t,this._edge2),e.Vector3.CrossToRef(this.direction,this._edge2,this._pvec);var r=e.Vector3.Dot(this._edge1,this._pvec);if(0===r)return null;var o=1/r;this.origin.subtractToRef(t,this._tvec);var s=e.Vector3.Dot(this._tvec,this._pvec)*o;if(0>s||s>1)return null;e.Vector3.CrossToRef(this._tvec,this._edge1,this._qvec);var a=e.Vector3.Dot(this.direction,this._qvec)*o;if(0>a||s+a>1)return null;var h=e.Vector3.Dot(this._edge2,this._qvec)*o;return h>this.length?null:new e.IntersectionInfo(s,a,h)},t.prototype.intersectsPlane=function(t){var i,n=e.Vector3.Dot(t.normal,this.direction);if(Math.abs(n)<9.99999997475243e-7)return null;var r=e.Vector3.Dot(t.normal,this.origin);return i=(-t.d-r)/n,0>i?-9.99999997475243e-7>i?null:0:i},t.prototype.intersectionSegment=function(i,n,r){var o,s,a,h,c=this.origin.add(this.direction.multiplyByFloats(t.rayl,t.rayl,t.rayl)),l=n.subtract(i),u=c.subtract(this.origin),d=i.subtract(this.origin),f=e.Vector3.Dot(l,l),p=e.Vector3.Dot(l,u),m=e.Vector3.Dot(u,u),_=e.Vector3.Dot(l,d),g=e.Vector3.Dot(u,d),v=f*m-p*p,y=v,x=v;v<t.smallnum?(s=0,y=1,h=g,x=m):(s=p*g-m*_,h=f*g-p*_,0>s?(s=0,h=g,x=m):s>y&&(s=y,h=g+p,x=m)),0>h?(h=0,0>-_?s=0:-_>f?s=y:(s=-_,y=f)):h>x&&(h=x,0>-_+p?s=0:-_+p>f?s=y:(s=-_+p,y=f)),o=Math.abs(s)<t.smallnum?0:s/y,a=Math.abs(h)<t.smallnum?0:h/x;var b=d.add(l.multiplyByFloats(o,o,o)).subtract(u.multiplyByFloats(a,a,a)),E=a>0&&a<=this.length&&b.lengthSquared()<r*r;return E?a:-1},t.CreateNew=function(i,n,r,o,s,a,h){var c=e.Vector3.Unproject(new e.Vector3(i,n,0),r,o,s,a,h),l=e.Vector3.Unproject(new e.Vector3(i,n,1),r,o,s,a,h),u=l.subtract(c);return u.normalize(),new t(c,u)},t.CreateNewFromTo=function(i,n,r){void 0===r&&(r=e.Matrix.Identity());var o=n.subtract(i),s=Math.sqrt(o.x*o.x+o.y*o.y+o.z*o.z);return o.normalize(),t.Transform(new t(i,o,s),r)},t.Transform=function(i,n){var r=e.Vector3.TransformCoordinates(i.origin,n),o=e.Vector3.TransformNormal(i.direction,n);return o.normalize(),new t(r,o,i.length)},t.smallnum=1e-8,t.rayl=1e9,t}();e.Ray=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(n,r){var o=this;t.call(this,n,r),this.onCollideObservable=new e.Observable,this.onCollisionPositionChangeObservable=new e.Observable,this.onAfterWorldMatrixUpdateObservable=new e.Observable,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=i.BILLBOARDMODE_NONE,this.visibility=1,this.alphaIndex=Number.MAX_VALUE,this.infiniteDistance=!1,this.isVisible=!0,this.isPickable=!0,this.showBoundingBox=!1,this.showSubMeshesBoundingBox=!1,this.onDispose=null,this.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._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._isWorldMatrixFrozen=!1,this._unIndexed=!1,this._onCollisionPositionChange=function(t,i,n){void 0===n&&(n=null),o.getScene().workerCollisions&&i.multiplyInPlace(o._collider.radius),i.subtractToRef(o._oldPositionForCollisions,o._diffPositionForCollisions),o._diffPositionForCollisions.length()>e.Engine.CollisionsEpsilon&&o.position.addInPlace(o._diffPositionForCollisions),n&&o.onCollideObservable.notifyObservers(n),o.onCollisionPositionChangeObservable.notifyObservers(o.position)},r.addMesh(this)}return __extends(i,t),Object.defineProperty(i,"BILLBOARDMODE_NONE",{get:function(){return i._BILLBOARDMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_X",{get:function(){return i._BILLBOARDMODE_X},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Y",{get:function(){return i._BILLBOARDMODE_Y},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Z",{get:function(){return i._BILLBOARDMODE_Z},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_ALL",{get:function(){return i._BILLBOARDMODE_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onCollide",{set:function(e){this._onCollideObserver&&this.onCollideObservable.remove(this._onCollideObserver),this._onCollideObserver=this.onCollideObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onCollisionPositionChange",{set:function(e){this._onCollisionPositionChangeObserver&&this.onCollisionPositionChangeObservable.remove(this._onCollisionPositionChangeObserver),this._onCollisionPositionChangeObserver=this.onCollisionPositionChangeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.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}),i.prototype.toString=function(t){var i="Name: "+this.name+", isInstance: "+(this instanceof e.InstancedMesh?"YES":"NO");return i+=", # of submeshes: "+(this.subMeshes?this.subMeshes.length:0),this._skeleton&&(i+=", skeleton: "+this._skeleton.name),t&&(i+=", billboard mode: "+["NONE","X","Y",null,"Z",null,null,"ALL"][this.billboardMode],i+=", freeze wrld mat: "+(this._isWorldMatrixFrozen||this._waitingFreezeWorldMatrix?"YES":"NO")),i},Object.defineProperty(i.prototype,"rotation",{get:function(){return this._rotation},set:function(e){this._rotation=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"scaling",{get:function(){return this._scaling},set:function(e){this._scaling=e,this.physicsImpostor&&this.physicsImpostor.forceUpdate()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"rotationQuaternion",{get:function(){return this._rotationQuaternion},set:function(e){this._rotationQuaternion=e,e&&this.rotation.length()&&this.rotation.copyFromFloats(0,0,0)},enumerable:!0,configurable:!0}),i.prototype.updatePoseMatrix=function(e){this._poseMatrix.copyFrom(e)},i.prototype.getPoseMatrix=function(){return this._poseMatrix},i.prototype.disableEdgesRendering=function(){void 0!==this._edgesRenderer&&(this._edgesRenderer.dispose(),this._edgesRenderer=void 0)},i.prototype.enableEdgesRendering=function(t,i){void 0===t&&(t=.95),void 0===i&&(i=!1),this.disableEdgesRendering(),this._edgesRenderer=new e.EdgesRenderer(this,t,i)},Object.defineProperty(i.prototype,"isBlocked",{get:function(){return!1},enumerable:!0,configurable:!0}),i.prototype.getLOD=function(e){return this},i.prototype.getTotalVertices=function(){return 0},i.prototype.getIndices=function(){return null},i.prototype.getVerticesData=function(e){return null},i.prototype.isVerticesDataPresent=function(e){return!1},i.prototype.getBoundingInfo=function(){return this._masterMesh?this._masterMesh.getBoundingInfo():(this._boundingInfo||this._updateBoundingInfo(),this._boundingInfo)},Object.defineProperty(i.prototype,"useBones",{get:function(){return this.skeleton&&this.getScene().skeletonsEnabled&&this.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&this.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)},enumerable:!0,configurable:!0}),i.prototype._preActivate=function(){},i.prototype._preActivateForIntermediateRendering=function(e){},i.prototype._activate=function(e){this._renderId=e},i.prototype.getWorldMatrix=function(){return this._masterMesh?this._masterMesh.getWorldMatrix():(this._currentRenderId!==this.getScene().getRenderId()&&this.computeWorldMatrix(),this._worldMatrix)},Object.defineProperty(i.prototype,"worldMatrixFromCache",{get:function(){return this._worldMatrix},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"absolutePosition",{get:function(){return this._absolutePosition},enumerable:!0,configurable:!0}),i.prototype.freezeWorldMatrix=function(){this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0),this._isWorldMatrixFrozen=!0},i.prototype.unfreezeWorldMatrix=function(){this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0)},Object.defineProperty(i.prototype,"isWorldMatrixFrozen",{get:function(){return this._isWorldMatrixFrozen},enumerable:!0,configurable:!0}),i.prototype.rotate=function(t,i,n){
  6. t.normalize(),this.rotationQuaternion||(this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation=e.Vector3.Zero());var r;if(n&&n!==e.Space.LOCAL){if(this.parent){var o=this.parent.getWorldMatrix().clone();o.invert(),t=e.Vector3.TransformNormal(t,o)}r=e.Quaternion.RotationAxis(t,i),this.rotationQuaternion=r.multiply(this.rotationQuaternion)}else r=e.Quaternion.RotationAxis(t,i),this.rotationQuaternion=this.rotationQuaternion.multiply(r)},i.prototype.translate=function(t,i,n){var r=t.scale(i);if(n&&n!==e.Space.LOCAL)this.setAbsolutePosition(this.getAbsolutePosition().add(r));else{var o=this.getPositionExpressedInLocalSpace().add(r);this.setPositionWithLocalVector(o)}},i.prototype.getAbsolutePosition=function(){return this.computeWorldMatrix(),this._absolutePosition},i.prototype.setAbsolutePosition=function(t){if(t){var i,n,r;if(void 0===t.x){if(arguments.length<3)return;i=arguments[0],n=arguments[1],r=arguments[2]}else i=t.x,n=t.y,r=t.z;if(this.parent){var o=this.parent.getWorldMatrix().clone();o.invert();var s=new e.Vector3(i,n,r);this.position=e.Vector3.TransformCoordinates(s,o)}else this.position.x=i,this.position.y=n,this.position.z=r}},i.prototype.movePOV=function(e,t,i){this.position.addInPlace(this.calcMovePOV(e,t,i))},i.prototype.calcMovePOV=function(t,i,n){var r=new e.Matrix,o=this.rotationQuaternion?this.rotationQuaternion:e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z);o.toRotationMatrix(r);var s=e.Vector3.Zero(),a=this.definedFacingForward?-1:1;return e.Vector3.TransformCoordinatesFromFloatsToRef(t*a,i,n*a,r,s),s},i.prototype.rotatePOV=function(e,t,i){this.rotation.addInPlace(this.calcRotatePOV(e,t,i))},i.prototype.calcRotatePOV=function(t,i,n){var r=this.definedFacingForward?1:-1;return new e.Vector3(t*r,i,n*r)},i.prototype.setPivotMatrix=function(e){this._pivotMatrix=e,this._cache.pivotMatrixUpdated=!0},i.prototype.getPivotMatrix=function(){return this._pivotMatrix},i.prototype._isSynchronized=function(){if(this._isDirty)return!1;if(this.billboardMode!==this._cache.billboardMode||this.billboardMode!==i.BILLBOARDMODE_NONE)return!1;if(this._cache.pivotMatrixUpdated)return!1;if(this.infiniteDistance)return!1;if(!this._cache.position.equals(this.position))return!1;if(this.rotationQuaternion){if(!this._cache.rotationQuaternion.equals(this.rotationQuaternion))return!1}else if(!this._cache.rotation.equals(this.rotation))return!1;return!!this._cache.scaling.equals(this.scaling)},i.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},i.prototype.markAsDirty=function(e){"rotation"===e&&(this.rotationQuaternion=null),this._currentRenderId=Number.MAX_VALUE,this._isDirty=!0},i.prototype._updateBoundingInfo=function(){this._boundingInfo=this._boundingInfo||new e.BoundingInfo(this.absolutePosition,this.absolutePosition),this._boundingInfo.update(this.worldMatrixFromCache),this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)},i.prototype._updateSubMeshesBoundingInfo=function(e){if(this.subMeshes)for(var t=0;t<this.subMeshes.length;t++){var i=this.subMeshes[t];i.IsGlobal||i.updateBoundingInfo(e)}},i.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){var n=this.rotation.length();n&&(this.rotationQuaternion.multiplyInPlace(e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z)),this.rotation.copyFromFloats(0,0,0))}if(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 r=this.getScene().activeCamera;if(r){var o=r.getWorldMatrix(),s=new e.Vector3(o.m[12],o.m[13],o.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!==i.BILLBOARDMODE_NONE&&this.getScene().activeCamera){e.Tmp.Vector3[0].copyFrom(this.position);var a=e.Tmp.Vector3[0];if(this.parent&&this.parent.getWorldMatrix){this._markSyncedWithParent();var h;this._meshToBoneReferal?(this.parent.getWorldMatrix().multiplyToRef(this._meshToBoneReferal.getWorldMatrix(),e.Tmp.Matrix[6]),h=e.Tmp.Matrix[6]):h=this.parent.getWorldMatrix(),e.Vector3.TransformCoordinatesToRef(a,h,e.Tmp.Vector3[1]),a=e.Tmp.Vector3[1]}var c=this.getScene().activeCamera.globalPosition.clone();this.parent&&this.parent.position&&(a.addInPlace(this.parent.position),e.Matrix.TranslationToRef(a.x,a.y,a.z,e.Tmp.Matrix[2])),(this.billboardMode&i.BILLBOARDMODE_ALL)!==i.BILLBOARDMODE_ALL&&(this.billboardMode&i.BILLBOARDMODE_X&&(c.x=a.x+e.Epsilon),this.billboardMode&i.BILLBOARDMODE_Y&&(c.y=a.y+e.Epsilon),this.billboardMode&i.BILLBOARDMODE_Z&&(c.z=a.z+e.Epsilon)),e.Matrix.LookAtLHToRef(a,c,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])}return e.Tmp.Matrix[5].multiplyToRef(e.Tmp.Matrix[2],this._localWorld),this.parent&&this.parent.getWorldMatrix&&this.billboardMode===i.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]),this.onAfterWorldMatrixUpdateObservable.notifyObservers(this),this._poseMatrix||(this._poseMatrix=e.Matrix.Invert(this._worldMatrix)),this._worldMatrix},i.prototype.registerAfterWorldMatrixUpdate=function(e){this.onAfterWorldMatrixUpdateObservable.add(e)},i.prototype.unregisterAfterWorldMatrixUpdate=function(e){this.onAfterWorldMatrixUpdateObservable.removeCallback(e)},i.prototype.setPositionWithLocalVector=function(t){this.computeWorldMatrix(),this.position=e.Vector3.TransformNormal(t,this._localWorld)},i.prototype.getPositionExpressedInLocalSpace=function(){this.computeWorldMatrix();var t=this._localWorld.clone();return t.invert(),e.Vector3.TransformNormal(this.position,t)},i.prototype.locallyTranslate=function(t){this.computeWorldMatrix(!0),this.position=e.Vector3.TransformCoordinates(t,this._localWorld)},i.prototype.lookAt=function(t,i,n,r){i=i||0,n=n||0,r=r||0;var o=t.subtract(this.position),s=-Math.atan2(o.z,o.x)-Math.PI/2,a=Math.sqrt(o.x*o.x+o.z*o.z),h=Math.atan2(o.y,a);this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(s+i,h+n,r)},i.prototype.attachToBone=function(e,t){this._meshToBoneReferal=t,this.parent=e,e.getWorldMatrix().determinant()<0&&(this.scalingDeterminant*=-1)},i.prototype.detachFromBone=function(){this.parent.getWorldMatrix().determinant()<0&&(this.scalingDeterminant*=-1),this._meshToBoneReferal=null,this.parent=null},i.prototype.isInFrustum=function(e){return this._boundingInfo.isInFrustum(e)},i.prototype.isCompletelyInFrustum=function(t){t||(t=this.getScene().activeCamera);var i=t.getViewMatrix().multiply(t.getProjectionMatrix());return!!this._boundingInfo.isCompletelyInFrustum(e.Frustum.GetPlanes(i))},i.prototype.intersectsMesh=function(e,t){return this._boundingInfo&&e._boundingInfo?this._boundingInfo.intersects(e._boundingInfo,t):!1},i.prototype.intersectsPoint=function(e){return this._boundingInfo?this._boundingInfo.intersectsPoint(e):!1},i.prototype.setPhysicsState=function(t,i){return t.impostor&&(i=t,t=t.impostor),this.physicsImpostor=new e.PhysicsImpostor(this,t,i,this.getScene()),this.physicsImpostor.physicsBody},i.prototype.getPhysicsImpostor=function(){return this.physicsImpostor},i.prototype.getPhysicsMass=function(){return this.physicsImpostor.getParam("mass")},i.prototype.getPhysicsFriction=function(){return this.physicsImpostor.getParam("friction")},i.prototype.getPhysicsRestitution=function(){return this.physicsImpostor.getParam("resitution")},i.prototype.getPositionInCameraSpace=function(t){return t||(t=this.getScene().activeCamera),e.Vector3.TransformCoordinates(this.absolutePosition,t.getViewMatrix())},i.prototype.getDistanceToCamera=function(e){return e||(e=this.getScene().activeCamera),this.absolutePosition.subtract(e.position).length()},i.prototype.applyImpulse=function(e,t){this.physicsImpostor&&this.physicsImpostor.applyImpulse(e,t)},i.prototype.setPhysicsLinkWith=function(t,i,n,r){this.physicsImpostor&&t.physicsImpostor&&this.physicsImpostor.createJoint(t.physicsImpostor,e.PhysicsJoint.HingeJoint,{mainPivot:i,connectedPivot:n,nativeParams:r})},i.prototype.updatePhysicsBodyPosition=function(){e.Tools.Warn("updatePhysicsBodyPosition() is deprecated, please use updatePhysicsBody()"),this.updatePhysicsBody()},i.prototype.updatePhysicsBody=function(){},Object.defineProperty(i.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}),i.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)},i.prototype.createOrUpdateSubmeshesOctree=function(t,i){void 0===t&&(t=64),void 0===i&&(i=2),this._submeshesOctree||(this._submeshesOctree=new e.Octree(e.Octree.CreationFuncForSubMeshes,t,i)),this.computeWorldMatrix(!0);var n=this.getBoundingInfo().boundingBox;return this._submeshesOctree.update(n.minimumWorld,n.maximumWorld,this.subMeshes),this._submeshesOctree},i.prototype._collideForSubMesh=function(t,i,n){if(this._generatePointsArray(),!t._lastColliderWorldVertices||!t._lastColliderTransformMatrix.equals(i)){t._lastColliderTransformMatrix=i.clone(),t._lastColliderWorldVertices=[],t._trianglePlanes=[];for(var r=t.verticesStart,o=t.verticesStart+t.verticesCount,s=r;o>s;s++)t._lastColliderWorldVertices.push(e.Vector3.TransformCoordinates(this._positions[s],i))}n._collide(t._trianglePlanes,t._lastColliderWorldVertices,this.getIndices(),t.indexStart,t.indexStart+t.indexCount,t.verticesStart,!!t.getMaterial()),n.collisionFound&&(n.collidedMesh=this)},i.prototype._processCollisionsForSubMeshes=function(e,t){var i,n;if(this._submeshesOctree&&this.useOctreeForCollisions){var r=e.velocityWorldLength+Math.max(e.radius.x,e.radius.y,e.radius.z),o=this._submeshesOctree.intersects(e.basePointWorld,r);n=o.length,i=o.data}else i=this.subMeshes,n=i.length;for(var s=0;n>s;s++){var a=i[s];n>1&&!a._checkCollision(e)||this._collideForSubMesh(a,t,e)}},i.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))},i.prototype._generatePointsArray=function(){return!1},i.prototype.intersects=function(t,i){var n=new e.PickingInfo;if(!(this.subMeshes&&this._boundingInfo&&t.intersectsSphere(this._boundingInfo.boundingSphere)&&t.intersectsBox(this._boundingInfo.boundingBox)))return n;if(!this._generatePointsArray())return n;var r,o,s=null;if(this._submeshesOctree&&this.useOctreeForPicking){var a=e.Ray.Transform(t,this.getWorldMatrix()),h=this._submeshesOctree.intersectsRay(a);o=h.length,r=h.data}else r=this.subMeshes,o=r.length;for(var c=0;o>c;c++){var l=r[c];if(!(o>1)||l.canIntersects(t)){var u=l.intersects(t,this._positions,this.getIndices(),i);if(u&&(i||!s||u.distance<s.distance)&&(s=u,s.subMeshId=c,i))break}}if(s){var d=this.getWorldMatrix(),f=e.Vector3.TransformCoordinates(t.origin,d),p=t.direction.clone();p=p.scale(s.distance);var m=e.Vector3.TransformNormal(p,d),_=f.add(m);return n.hit=!0,n.distance=e.Vector3.Distance(f,_),n.pickedPoint=_,n.pickedMesh=this,n.bu=s.bu,n.bv=s.bv,n.faceId=s.faceId,n.subMeshId=s.subMeshId,n}return n},i.prototype.clone=function(e,t,i){return null},i.prototype.releaseSubMeshes=function(){if(this.subMeshes)for(;this.subMeshes.length;)this.subMeshes[0].dispose();else this.subMeshes=new Array},i.prototype.dispose=function(e){var i,n=this;for(this.actionManager&&(this.actionManager.dispose(),this.actionManager=null),this.skeleton=null,this.getScene().stopAnimation(this),this.physicsImpostor&&this.physicsImpostor.dispose(),i=0;i<this._intersectionsInProgress.length;i++){var r=this._intersectionsInProgress[i],o=r._intersectionsInProgress.indexOf(this);r._intersectionsInProgress.splice(o,1)}this._intersectionsInProgress=[];var s=this.getScene().lights;if(s.forEach(function(e){var t=e.includedOnlyMeshes.indexOf(n);-1!==t&&e.includedOnlyMeshes.splice(t,1),t=e.excludedMeshes.indexOf(n),-1!==t&&e.excludedMeshes.splice(t,1)}),this._edgesRenderer&&(this._edgesRenderer.dispose(),this._edgesRenderer=null),this.releaseSubMeshes(),this.getScene().removeMesh(this),e){var a=this.getChildMeshes(!0);for(i=0;i<a.length;i++){var h=a[i];h.parent=null,h.computeWorldMatrix(!0)}}else{for(i=0;i<this.getScene().particleSystems.length;i++)this.getScene().particleSystems[i].emitter===this&&(this.getScene().particleSystems[i].dispose(),i--);var c=this.getDescendants(!0);for(i=0;i<c.length;i++)c[i].dispose()}t.prototype.dispose.call(this),this.onAfterWorldMatrixUpdateObservable.clear(),this._isDisposed=!0,this.onDispose&&this.onDispose()},i._BILLBOARDMODE_NONE=0,i._BILLBOARDMODE_X=1,i._BILLBOARDMODE_Y=2,i._BILLBOARDMODE_Z=4,i._BILLBOARDMODE_ALL=7,i}(e.Node);e.AbstractMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n){t.call(this,i,n),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.radius=1e-5,this._excludedMeshesIds=new Array,this._includedOnlyMeshesIds=new Array,n.addLight(this)}return __extends(i,t),i.prototype.toString=function(e){var t="Name: "+this.name;if(t+=", type: "+["Point","Directional","Spot","Hemispheric"][this.getTypeID()],this.animations)for(var i=0;i<this.animations.length;i++)t+=", animation[0]: "+this.animations[i].toString(e);return t},i.prototype.getShadowGenerator=function(){return this._shadowGenerator},i.prototype.getAbsolutePosition=function(){return e.Vector3.Zero()},i.prototype.transferToEffect=function(e,t,i){},i.prototype._getWorldMatrix=function(){return e.Matrix.Identity()},i.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):!0},i.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},i.prototype.dispose=function(){this._shadowGenerator&&(this._shadowGenerator.dispose(),this._shadowGenerator=null),this.getScene().stopAnimation(this),this.getScene().removeLight(this),t.prototype.dispose.call(this)},i.prototype.getTypeID=function(){return 0},i.prototype.clone=function(t){return e.SerializationHelper.Clone(i.GetConstructorFromName(this.getTypeID(),t,this.getScene()),this)},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.type=this.getTypeID(),this.parent&&(t.parentId=this.parent.id),this.excludedMeshes.length>0&&(t.excludedMeshesIds=[],this.excludedMeshes.forEach(function(e){t.excludedMeshesIds.push(e.id)})),this.includedOnlyMeshes.length>0&&(t.includedOnlyMeshesIds=[],this.includedOnlyMeshes.forEach(function(e){t.includedOnlyMeshesIds.push(e.id)})),e.Animation.AppendSerializedAnimations(this,t),t.ranges=this.serializeAnimationRanges(),t},i.GetConstructorFromName=function(t,i,n){switch(t){case 0:return function(){return new e.PointLight(i,e.Vector3.Zero(),n)};case 1:return function(){return new e.DirectionalLight(i,e.Vector3.Zero(),n)};case 2:return function(){return new e.SpotLight(i,e.Vector3.Zero(),e.Vector3.Zero(),0,0,n)};case 3:return function(){return new e.HemisphericLight(i,e.Vector3.Zero(),n)}}},i.Parse=function(t,n){var r=e.SerializationHelper.Parse(i.GetConstructorFromName(t.type,t.name,n),t,n);if(t.excludedMeshesIds&&(r._excludedMeshesIds=t.excludedMeshesIds),t.includedOnlyMeshesIds&&(r._includedOnlyMeshesIds=t.includedOnlyMeshesIds),t.parentId&&(r._waitingParentId=t.parentId),t.animations){for(var o=0;o<t.animations.length;o++){var s=t.animations[o];r.animations.push(e.Animation.Parse(s))}e.Node.ParseAnimationRanges(r,t,n)}return t.autoAnimate&&n.beginAnimation(r,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,t.autoAnimateSpeed||1),r},__decorate([e.serializeAsColor3()],i.prototype,"diffuse",void 0),__decorate([e.serializeAsColor3()],i.prototype,"specular",void 0),__decorate([e.serialize()],i.prototype,"intensity",void 0),__decorate([e.serialize()],i.prototype,"range",void 0),__decorate([e.serialize()],i.prototype,"includeOnlyWithLayerMask",void 0),__decorate([e.serialize()],i.prototype,"excludeWithLayerMask",void 0),__decorate([e.serialize()],i.prototype,"radius",void 0),i}(e.Node);e.Light=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,n){t.call(this,e,n),this.position=i}return __extends(i,t),i.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},i.prototype.computeTransformedPosition=function(){return this.parent&&this.parent.getWorldMatrix?(this.transformedPosition||(this.transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.getAbsolutePosition(),this.parent.getWorldMatrix(),this.transformedPosition),!0):!1},i.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)},i.prototype.needCube=function(){return!0},i.prototype.supportsVSM=function(){return!1},i.prototype.needRefreshPerFrame=function(){return!1},i.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()},i.prototype.setShadowProjectionMatrix=function(t,i,n){var r=this.getScene().activeCamera;e.Matrix.PerspectiveFovLHToRef(Math.PI/2,1,r.minZ,r.maxZ,t)},i.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},i.prototype.getTypeID=function(){return 0},__decorate([e.serializeAsVector3()],i.prototype,"position",void 0),i}(e.Light);e.PointLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,n,r,o,s){t.call(this,e,s),this.position=i,this.direction=n,this.angle=r,this.exponent=o}return __extends(i,t),i.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},i.prototype.setShadowProjectionMatrix=function(t,i,n){var r=this.getScene().activeCamera;e.Matrix.PerspectiveFovLHToRef(this.angle,1,r.minZ,r.maxZ,t)},i.prototype.needCube=function(){return!1},i.prototype.supportsVSM=function(){return!0},i.prototype.needRefreshPerFrame=function(){return!1},i.prototype.getShadowDirection=function(e){return this.direction},i.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(this.position)),this.direction},i.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},i.prototype.transferToEffect=function(t,i,n){var r;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(i,this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,this.exponent),r=e.Vector3.Normalize(this._transformedDirection)):(t.setFloat4(i,this.position.x,this.position.y,this.position.z,this.exponent),r=e.Vector3.Normalize(this.direction)),t.setFloat4(n,r.x,r.y,r.z,Math.cos(.5*this.angle))},i.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},i.prototype.getTypeID=function(){return 2},__decorate([e.serializeAsVector3()],i.prototype,"position",void 0),__decorate([e.serializeAsVector3()],i.prototype,"direction",void 0),__decorate([e.serialize()],i.prototype,"angle",void 0),__decorate([e.serialize()],i.prototype,"exponent",void 0),i}(e.Light);e.SpotLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r){t.call(this,i,r),this.groundColor=new e.Color3(0,0,0),this.direction=n}return __extends(i,t),i.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(e.Vector3.Zero())),this.direction},i.prototype.getShadowGenerator=function(){return null},i.prototype.transferToEffect=function(t,i,n){var r=e.Vector3.Normalize(this.direction);t.setFloat4(i,r.x,r.y,r.z,0),t.setColor3(n,this.groundColor.scale(this.intensity))},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._worldMatrix},i.prototype.getTypeID=function(){return 3},__decorate([e.serializeAsColor3()],i.prototype,"groundColor",void 0),__decorate([e.serializeAsVector3()],i.prototype,"direction",void 0),i}(e.Light);e.HemisphericLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,n){t.call(this,e,n),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=i.scale(-1),this.direction=i}return __extends(i,t),i.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},i.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(this.position)),this.direction},i.prototype.setShadowProjectionMatrix=function(t,i,n){var r=this.getScene().activeCamera;if(this.autoUpdateExtends||this._orthoLeft===Number.MAX_VALUE){var o=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 s=0;s<n.length;s++){var a=n[s];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],i,o),o.x<this._orthoLeft&&(this._orthoLeft=o.x),o.y<this._orthoBottom&&(this._orthoBottom=o.y),o.x>this._orthoRight&&(this._orthoRight=o.x),o.y>this._orthoTop&&(this._orthoTop=o.y)}}}var u=this._orthoRight-this._orthoLeft,d=this._orthoTop-this._orthoBottom;e.Matrix.OrthoOffCenterLHToRef(this._orthoLeft-u*this.shadowOrthoScale,this._orthoRight+u*this.shadowOrthoScale,this._orthoBottom-d*this.shadowOrthoScale,this._orthoTop+d*this.shadowOrthoScale,-r.maxZ,r.maxZ,t)},i.prototype.supportsVSM=function(){return!0},i.prototype.needRefreshPerFrame=function(){return!0},i.prototype.needCube=function(){return!1},i.prototype.getShadowDirection=function(e){return this.direction},i.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},i.prototype.transferToEffect=function(t,i){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(i,this._transformedDirection.x,this._transformedDirection.y,this._transformedDirection.z,1)):void t.setFloat4(i,this.direction.x,this.direction.y,this.direction.z,1)},i.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},i.prototype.getTypeID=function(){return 1},__decorate([e.serializeAsVector3()],i.prototype,"position",void 0),__decorate([e.serializeAsVector3()],i.prototype,"direction",void 0),__decorate([e.serialize()],i.prototype,"shadowOrthoScale",void 0),__decorate([e.serialize()],i.prototype,"autoUpdateExtends",void 0),i}(e.Light);e.DirectionalLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(i,n){var r=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=n,this._scene=n.getScene(),this._mapSize=i,n._shadowGenerator=this,this._shadowMap=new e.RenderTargetTexture(n.name+"_shadowMap",i,this._scene,!1,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT,n.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){r._currentFaceIndex=e},this._shadowMap.onAfterUnbind=function(){r.useBlurVarianceShadowMap&&(r._shadowMap2||(r._shadowMap2=new e.RenderTargetTexture(n.name+"_shadowMap",i,r._scene,!1),r._shadowMap2.wrapU=e.Texture.CLAMP_ADDRESSMODE,r._shadowMap2.wrapV=e.Texture.CLAMP_ADDRESSMODE,r._shadowMap2.updateSamplingMode(e.Texture.TRILINEAR_SAMPLINGMODE),r._downSamplePostprocess=new e.PassPostProcess("downScale",1/r.blurScale,null,e.Texture.BILINEAR_SAMPLINGMODE,r._scene.getEngine()),r._downSamplePostprocess.onApply=function(e){e.setTexture("textureSampler",r._shadowMap)},r.blurBoxOffset=1),r._scene.postProcessManager.directRender([r._downSamplePostprocess,r._boxBlurPostprocess],r._shadowMap2.getInternalTexture()))};var o=function(t){var i=t.getRenderingMesh(),n=r._scene,o=n.getEngine();o.setState(t.getMaterial().backFaceCulling);var s=i._getInstancesRenderList(t._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[t._id]&&void 0!==s.visibleInstances[t._id];if(r.isReady(t,a)){o.enableEffect(r._effect),i._bind(t,r._effect,e.Material.TriangleFillMode);var h=t.getMaterial();if(r._effect.setMatrix("viewProjection",r.getTransformMatrix()),r._effect.setVector3("lightPosition",r.getLight().position),r.getLight().needCube()&&r._effect.setFloat2("depthValues",n.activeCamera.minZ,n.activeCamera.maxZ),h&&h.needAlphaTesting()){var c=h.getAlphaTestTexture();r._effect.setTexture("diffuseSampler",c),r._effect.setMatrix("diffuseMatrix",c.getTextureMatrix())}i.useBones&&i.computeBonesUsingShaders&&r._effect.setMatrices("mBones",i.skeleton.getTransformMatrices(i)),r.forceBackFacesOnly&&o.setState(!0,0,!1,!0),i._processRendering(t,r._effect,e.Material.TriangleFillMode,s,a,function(e,t){return r._effect.setMatrix("world",t)}),r.forceBackFacesOnly&&o.setState(!0,0,!1,!1)}else r._shadowMap.resetRefreshCounter()}};this._shadowMap.customRenderFunction=function(e,t,i){var n;for(n=0;n<e.length;n++)o(e.data[n]);for(n=0;n<t.length;n++)o(t.data[n]);if(r._transparencyShadow)for(n=0;n<i.length;n++)o(i.data[n])},this._shadowMap.onClear=function(t){r.useBlurVarianceShadowMap||r.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 i=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",i._mapSize/i.blurScale,i._mapSize/i.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",{
  7. 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,i){var n=[];(this.useVarianceShadowMap||this.useBlurVarianceShadowMap)&&n.push("#define VSM"),this.getLight().needCube()&&n.push("#define CUBEMAP");var r=[e.VertexBuffer.PositionKind],o=t.getMesh(),s=t.getMaterial();s&&s.needAlphaTesting()&&(n.push("#define ALPHATEST"),o.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(r.push(e.VertexBuffer.UVKind),n.push("#define UV1")),o.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(r.push(e.VertexBuffer.UV2Kind),n.push("#define UV2"))),o.useBones&&o.computeBonesUsingShaders?(r.push(e.VertexBuffer.MatricesIndicesKind),r.push(e.VertexBuffer.MatricesWeightsKind),o.numBoneInfluencers>4&&(r.push(e.VertexBuffer.MatricesIndicesExtraKind),r.push(e.VertexBuffer.MatricesWeightsExtraKind)),n.push("#define NUM_BONE_INFLUENCERS "+o.numBoneInfluencers),n.push("#define BonesPerMesh "+(o.skeleton.bones.length+1))):n.push("#define NUM_BONE_INFLUENCERS 0"),i&&(n.push("#define INSTANCES"),r.push("world0"),r.push("world1"),r.push("world2"),r.push("world3"));var a=n.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("shadowMap",r,["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 i=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()&&(i=this._light.transformedPosition),!this._light.needRefreshPerFrame()&&this._cachedPosition&&this._cachedDirection&&i.equals(this._cachedPosition)&&this._lightDirection.equals(this._cachedDirection)||(this._cachedPosition=i.clone(),this._cachedDirection=this._lightDirection.clone(),e.Matrix.LookAtLHToRef(i,i.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 i=255*t,n=i-Math.floor(i);return new e.Vector2(t-n/255,n)},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 i=this.getShadowMap().renderList[t];e.renderList.push(i.id)}return e},t.Parse=function(e,i){for(var n=i.getLightByID(e.lightId),r=new t(e.mapSize,n),o=0;o<e.renderList.length;o++){var s=i.getMeshByID(e.renderList[o]);r.getShadowMap().renderList.push(s)}return e.usePoissonSampling?r.usePoissonSampling=!0:e.useVarianceShadowMap?r.useVarianceShadowMap=!0:e.useBlurVarianceShadowMap&&(r.useBlurVarianceShadowMap=!0,e.blurScale&&(r.blurScale=e.blurScale),e.blurBoxOffset&&(r.blurBoxOffset=e.blurBoxOffset)),void 0!==e.bias&&(r.bias=e.bias),r.forceBackFacesOnly=e.forceBackFacesOnly,r},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,i,n){return e.x>i.x+n?!1:i.x-n>t.x?!1:e.y>i.y+n?!1:i.y-n>t.y?!1:e.z>i.z+n?!1:!(i.z-n>t.z)},i=function(e,t,i,n){var r=t*t-4*e*i,o={root:0,found:!1};if(0>r)return o;var s=Math.sqrt(r),a=(-t-s)/(2*e),h=(-t+s)/(2*e);if(a>h){var c=h;h=a,a=c}return a>0&&n>a?(o.root=a,o.found=!0,o):h>0&&n>h?(o.root=h,o.found=!0,o):o},n=function(){function n(){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 n.prototype._initialize=function(t,i,n){this.velocity=i,e.Vector3.NormalizeToRef(i,this.normalizedVelocity),this.basePoint=t,t.multiplyToRef(this.radius,this.basePointWorld),i.multiplyToRef(this.radius,this.velocityWorld),this.velocityWorldLength=this.velocityWorld.length(),this.epsilon=n,this.collisionFound=!1},n.prototype._checkPointInTriangle=function(t,i,n,r,o){i.subtractToRef(t,this._tempVector),n.subtractToRef(t,this._tempVector2),e.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var s=e.Vector3.Dot(this._tempVector4,o);return 0>s?!1:(r.subtractToRef(t,this._tempVector3),e.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),s=e.Vector3.Dot(this._tempVector4,o),0>s?!1:(e.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),s=e.Vector3.Dot(this._tempVector4,o),s>=0))},n.prototype._canDoCollision=function(i,n,r,o){var s=e.Vector3.Distance(this.basePointWorld,i),a=Math.max(this.radius.x,this.radius.y,this.radius.z);return s>this.velocityWorldLength+a+n?!1:!!t(r,o,this.basePointWorld,this.velocityWorldLength+a)},n.prototype._testTriangle=function(t,n,r,o,s,a){var h,c=!1;n||(n=[]),n[t]||(n[t]=new e.Plane(0,0,0,0),n[t].copyFromPoints(r,o,s));var l=n[t];if(a||l.isFrontFacingTo(this.normalizedVelocity,0)){var u=l.signedDistanceTo(this.basePoint),d=e.Vector3.Dot(l.normal,this.velocity);if(0==d){if(Math.abs(u)>=1)return;c=!0,h=0}else{h=(-1-u)/d;var f=(1-u)/d;if(h>f){var p=f;f=h,h=p}if(h>1||0>f)return;0>h&&(h=0),h>1&&(h=1)}this._collisionPoint.copyFromFloats(0,0,0);var m=!1,_=1;if(c||(this.basePoint.subtractToRef(l.normal,this._planeIntersectionPoint),this.velocity.scaleToRef(h,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,r,o,s,l.normal)&&(m=!0,_=h,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!m){var g=this.velocity.lengthSquared(),v=g;this.basePoint.subtractToRef(r,this._tempVector);var y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=i(v,y,x,_);b.found&&(_=b.root,m=!0,this._collisionPoint.copyFrom(r)),this.basePoint.subtractToRef(o,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=i(v,y,x,_),b.found&&(_=b.root,m=!0,this._collisionPoint.copyFrom(o)),this.basePoint.subtractToRef(s,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=i(v,y,x,_),b.found&&(_=b.root,m=!0,this._collisionPoint.copyFrom(s)),o.subtractToRef(r,this._edge),r.subtractToRef(this.basePoint,this._baseToVertex);var E=this._edge.lengthSquared(),A=e.Vector3.Dot(this._edge,this.velocity),T=e.Vector3.Dot(this._edge,this._baseToVertex);if(v=E*-g+A*A,y=E*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*A*T,x=E*(1-this._baseToVertex.lengthSquared())+T*T,b=i(v,y,x,_),b.found){var P=(A*b.root-T)/E;P>=0&&1>=P&&(_=b.root,m=!0,this._edge.scaleInPlace(P),r.addToRef(this._edge,this._collisionPoint))}s.subtractToRef(o,this._edge),o.subtractToRef(this.basePoint,this._baseToVertex),E=this._edge.lengthSquared(),A=e.Vector3.Dot(this._edge,this.velocity),T=e.Vector3.Dot(this._edge,this._baseToVertex),v=E*-g+A*A,y=E*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*A*T,x=E*(1-this._baseToVertex.lengthSquared())+T*T,b=i(v,y,x,_),b.found&&(P=(A*b.root-T)/E,P>=0&&1>=P&&(_=b.root,m=!0,this._edge.scaleInPlace(P),o.addToRef(this._edge,this._collisionPoint))),r.subtractToRef(s,this._edge),s.subtractToRef(this.basePoint,this._baseToVertex),E=this._edge.lengthSquared(),A=e.Vector3.Dot(this._edge,this.velocity),T=e.Vector3.Dot(this._edge,this._baseToVertex),v=E*-g+A*A,y=E*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*A*T,x=E*(1-this._baseToVertex.lengthSquared())+T*T,b=i(v,y,x,_),b.found&&(P=(A*b.root-T)/E,P>=0&&1>=P&&(_=b.root,m=!0,this._edge.scaleInPlace(P),s.addToRef(this._edge,this._collisionPoint)))}if(m){var M=_*this.velocity.length();(!this.collisionFound||M<this.nearestDistance)&&(this.intersectionPoint?this.intersectionPoint.copyFrom(this._collisionPoint):this.intersectionPoint=this._collisionPoint.clone(),this.nearestDistance=M,this.collisionFound=!0)}}},n.prototype._collide=function(e,t,i,n,r,o,s){for(var a=n;r>a;a+=3){var h=t[i[a]-o],c=t[i[a+1]-o],l=t[i[a+2]-o];this._testTriangle(a,e,l,c,h,s)}},n.prototype._getResponse=function(t,i){t.addToRef(i,this._destinationPoint),i.scaleInPlace(this.nearestDistance/i.length()),this.basePoint.addToRef(i,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,i)},n}();e.Collider=n}(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 i=e.WorkerReplyType,n=function(){function n(){var r=this;this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this.onMeshUpdated=function(e){r._addUpdateMeshesList[e.uniqueId]=n.SerializeMesh(e)},this.onGeometryUpdated=function(e){r._addUpdateGeometriesList[e.id]=n.SerializeGeometry(e)},this._afterRender=function(){if(r._init&&!(0==r._toRemoveGeometryArray.length&&0==r._toRemoveMeshesArray.length&&0==Object.keys(r._addUpdateGeometriesList).length&&0==Object.keys(r._addUpdateMeshesList).length||r._runningUpdated>4)){++r._runningUpdated;var e={updatedMeshes:r._addUpdateMeshesList,updatedGeometries:r._addUpdateGeometriesList,removedGeometries:r._toRemoveGeometryArray,removedMeshes:r._toRemoveMeshesArray},i={payload:e,taskType:t.UPDATE},n=[];for(var o in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(o)&&(n.push(i.payload.updatedGeometries[o].indices.buffer),n.push(i.payload.updatedGeometries[o].normals.buffer),n.push(i.payload.updatedGeometries[o].positions.buffer));r._worker.postMessage(i,n),r._addUpdateMeshesList={},r._addUpdateGeometriesList={},r._toRemoveGeometryArray=[],r._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(n){var o=n.data;if(o.error!=i.SUCCESS)return void e.Tools.Warn("error returned from worker!");switch(o.taskType){case t.INIT:r._init=!0,r._scene.meshes.forEach(function(e){r.onMeshAdded(e)}),r._scene.getGeometries().forEach(function(e){r.onGeometryAdded(e)});break;case t.UPDATE:r._runningUpdated--;break;case t.COLLIDE:r._runningCollisionTask=!1;var s=o.payload;if(!r._collisionsCallbackArray[s.collisionId])return;r._collisionsCallbackArray[s.collisionId](s.collisionId,e.Vector3.FromArray(s.newPosition),r._scene.getMeshByUniqueID(s.collidedMeshUniqueId)),r._collisionsCallbackArray[s.collisionId]=void 0}},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,this._runningCollisionTask=!1,this._addUpdateMeshesList={},this._addUpdateGeometriesList={},this._toRemoveGeometryArray=[],this._toRemoveMeshesArray=[]}return n.prototype.getNewPosition=function(e,i,n,r,o,s,a){if(this._init&&!this._collisionsCallbackArray[a]&&!this._collisionsCallbackArray[a+1e5]){e.divideToRef(n.radius,this._scaledPosition),i.divideToRef(n.radius,this._scaledVelocity),this._collisionsCallbackArray[a]=s;var h={collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:n.radius.asArray()},collisionId:a,excludedMeshUniqueId:o?o.uniqueId:null,maximumRetry:r},c={payload:h,taskType:t.COLLIDE};this._worker.postMessage(c)}},n.prototype.init=function(i){this._scene=i,this._scene.registerAfterRender(this._afterRender);var n=e.WorkerIncluded?e.Engine.CodeRepository+"Collisions/babylon.collisionWorker.js":URL.createObjectURL(new Blob([e.CollisionWorker],{type:"application/javascript"}));this._worker=new Worker(n),this._worker.onmessage=this._onMessageFromWorker;var r={payload:{},taskType:t.INIT};this._worker.postMessage(r)},n.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},n.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},n.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},n.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},n.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},n.SerializeMesh=function(t){var i=[];t.subMeshes&&(i=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 n=null;return t instanceof e.Mesh?n=t.geometry?t.geometry.id:null:t instanceof e.InstancedMesh&&(n=t.sourceMesh&&t.sourceMesh.geometry?t.sourceMesh.geometry.id:null),{uniqueId:t.uniqueId,id:t.id,name:t.name,geometryId:n,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:i,checkCollisions:t.checkCollisions}},n.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()||[])}},n}();e.CollisionCoordinatorWorker=n;var r=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,i,n,r,o,s){e.divideToRef(i.radius,this._scaledPosition),t.divideToRef(i.radius,this._scaledVelocity),i.collidedMesh=null,i.retry=0,i.initialVelocity=this._scaledVelocity,i.initialPosition=this._scaledPosition,this._collideWithWorld(this._scaledPosition,this._scaledVelocity,i,n,this._finalPosition,r),this._finalPosition.multiplyInPlace(i.radius),o(s,this._finalPosition,i.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,i,n,r,o,s){void 0===s&&(s=null);var a=10*e.Engine.CollisionsEpsilon;if(n.retry>=r)return void o.copyFrom(t);n._initialize(t,i,a);for(var h=0;h<this._scene.meshes.length;h++){var c=this._scene.meshes[h];c.isEnabled()&&c.checkCollisions&&c.subMeshes&&c!==s&&c._checkCollision(n)}return n.collisionFound?(0===i.x&&0===i.y&&0===i.z||n._getResponse(t,i),i.length()<=a?void o.copyFrom(t):(n.retry++,void this._collideWithWorld(t,i,n,r,o,s))):void t.addToRef(i,o)},t}();e.CollisionCoordinatorLegacy=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(n,r,o){t.call(this,n,o),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(),o.addCamera(this),o.activeCamera||(o.activeCamera=this),this.position=r}return __extends(i,t),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}),i.prototype.toString=function(e){var t="Name: "+this.name;if(t+=", type: "+this.getTypeName(),this.animations)for(var i=0;i<this.animations.length;i++)t+=", animation[0]: "+this.animations[i].toString(e);return t},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(){t.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||t.prototype._updateCache.call(this);var i=this.getEngine();this._cache.position.copyFrom(this.position),this._cache.upVector.copyFrom(this.upVector),this._cache.mode=this.mode,this._cache.minZ=this.minZ,this._cache.maxZ=this.maxZ,this._cache.fov=this.fov,this._cache.aspectRatio=i.getAspectRatio(this),this._cache.orthoLeft=this.orthoLeft,this._cache.orthoRight=this.orthoRight,this._cache.orthoBottom=this.orthoBottom,this._cache.orthoTop=this.orthoTop,this._cache.renderWidth=i.getRenderWidth(),this._cache.renderHeight=i.getRenderHeight()},i.prototype._updateFromScene=function(){this.updateCache(),this._update()},i.prototype._isSynchronized=function(){return this._isSynchronizedViewMatrix()&&this._isSynchronizedProjectionMatrix()},i.prototype._isSynchronizedViewMatrix=function(){return t.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,t){},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,i){if(void 0===i&&(i=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==i||0>i)return this._postProcesses.push(t),this._postProcessesTakenIndices.push(this._postProcesses.length-1),this._postProcesses.length-1;var n,r,o=0;if(this._postProcesses[i]){for(r=this._postProcesses.length-1,n=r;n>=i+1;--n)this._postProcesses[n+1]=this._postProcesses[n];o=1}for(n=0;n<this._postProcessesTakenIndices.length;++n)if(!(this._postProcessesTakenIndices[n]<i)){r=this._postProcessesTakenIndices.length-1;for(var s=r;s>=n;--s)this._postProcessesTakenIndices[s+1]=this._postProcessesTakenIndices[s]+o;this._postProcessesTakenIndices[n]=i;break}o||-1!==this._postProcessesTakenIndices.indexOf(i)||this._postProcessesTakenIndices.push(i);var a=i+o;return this._postProcesses[a]=t,a},i.prototype.detachPostProcess=function(e,t){void 0===t&&(t=null);var i,n,r=[];if(t)for(t=t instanceof Array?t:[t],i=0;i<t.length;i++){var o=this._postProcesses[t[i]];o===e?(delete this._postProcesses[t[i]],n=this._postProcessesTakenIndices.indexOf(t[i]),this._postProcessesTakenIndices.splice(n,1)):r.push(i)}else{var s=this._postProcesses.length;for(i=0;s>i;i++)this._postProcesses[i]===e&&(delete this._postProcesses[i],n=this._postProcessesTakenIndices.indexOf(i),this._postProcessesTakenIndices.splice(n,1))}return r},i.prototype.getWorldMatrix=function(){this._worldMatrix||(this._worldMatrix=e.Matrix.Identity());var t=this.getViewMatrix();return t.invertToRef(this._worldMatrix),this._worldMatrix},i.prototype._getViewMatrix=function(){return e.Matrix.Identity()},i.prototype.getViewMatrix=function(t){return this._computedViewMatrix=this._computeViewMatrix(t),!t&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this.parent&&this.parent.getWorldMatrix?(this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._computedViewMatrix.invertToRef(this._worldMatrix),this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(),this._computedViewMatrix),this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12],this._computedViewMatrix.m[13],this._computedViewMatrix.m[14]),this._computedViewMatrix.invert(),this._markSyncedWithParent()):this._globalPosition.copyFrom(this.position),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix)},i.prototype._computeViewMatrix=function(e){return!e&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this._computedViewMatrix=this._getViewMatrix(),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix)},i.prototype.getProjectionMatrix=function(t){if(!t&&this._isSynchronizedProjectionMatrix())return this._projectionMatrix;var n=this.getEngine();if(this.mode===i.PERSPECTIVE_CAMERA)return this.minZ<=0&&(this.minZ=.1),e.Matrix.PerspectiveFovLHToRef(this.fov,n.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode===i.FOVMODE_VERTICAL_FIXED),this._projectionMatrix;var r=n.getRenderWidth()/2,o=n.getRenderHeight()/2;return e.Matrix.OrthoOffCenterLHToRef(this.orthoLeft||-r,this.orthoRight||r,this.orthoBottom||-o,this.orthoTop||o,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);t.prototype.dispose.call(this)},i.prototype.setCameraRigMode=function(t,n){for(;this._rigCameras.length>0;)this._rigCameras.pop().dispose();switch(this.cameraRigMode=t,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 r=new Array;switch(this.cameraRigMode){case i.RIG_MODE_STEREOSCOPIC_ANAGLYPH:r.push(new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[0])),this._rigCameras[0].isIntermediate=!0,r.push(new e.AnaglyphPostProcess(this.name+"_anaglyph",1,this._rigCameras[1])),r[1].onApply=function(e){e.setTextureFromPostProcess("leftSampler",r[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,s=this.cameraRigMode===i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED?1:0,a=1-s;r.push(new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[s])),this._rigCameras[s].isIntermediate=!0,r.push(new e.StereoscopicInterlacePostProcess(this.name+"_stereoInterlace",this._rigCameras[a],r[0],o));break;case i.RIG_MODE_VR: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 h=n.vrCameraMetrics||e.VRCameraMetrics.GetDefault();this._rigCameras[0]._cameraRigParams.vrMetrics=h,this._rigCameras[0].viewport=new e.Viewport(0,0,.5,1),this._rigCameras[0]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[0]._cameraRigParams.vrHMatrix=h.leftHMatrix,this._rigCameras[0]._cameraRigParams.vrPreViewMatrix=h.leftPreViewMatrix,this._rigCameras[0].getProjectionMatrix=this._rigCameras[0]._getVRProjectionMatrix,h.compensateDistortion&&r.push(new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Left",this._rigCameras[0],!1,h)),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=h.rightHMatrix,this._rigCameras[1]._cameraRigParams.vrPreViewMatrix=h.rightPreViewMatrix,this._rigCameras[1].getProjectionMatrix=this._rigCameras[1]._getVRProjectionMatrix,h.compensateDistortion&&r.push(new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Right",this._rigCameras[1],!0,h))}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,i){this._cameraRigParams[t]=i,"interaxialDistance"===t&&(this._cameraRigParams.stereoHalfAngle=e.Tools.ToRadians(i/.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=e.SerializationHelper.Serialize(this);return t.type=this.getTypeName(),this.parent&&(t.parentId=this.parent.id),this.inputs&&this.inputs.serialize(t),e.Animation.AppendSerializedAnimations(this,t),t.ranges=this.serializeAnimationRanges(),t},i.prototype.getTypeName=function(){return"Camera"},i.prototype.clone=function(t){return e.SerializationHelper.Clone(i.GetConstructorFromName(this.getTypeName(),t,this.getScene(),this.interaxialDistance,this.isStereoscopicSideBySide),this)},i.GetConstructorFromName=function(t,i,n,r,o){switch(void 0===r&&(r=0),void 0===o&&(o=!0),t){case"ArcRotateCamera":return function(){return new e.ArcRotateCamera(i,0,0,1,e.Vector3.Zero(),n)};case"DeviceOrientationCamera":return function(){return new e.DeviceOrientationCamera(i,e.Vector3.Zero(),n)};case"FollowCamera":return function(){return new e.FollowCamera(i,e.Vector3.Zero(),n)};case"ArcFollowCamera":return function(){return new e.ArcFollowCamera(i,0,0,1,null,n)};case"GamepadCamera":return function(){return new e.GamepadCamera(i,e.Vector3.Zero(),n)};case"TouchCamera":return function(){return new e.TouchCamera(i,e.Vector3.Zero(),n)};case"VirtualJoysticksCamera":return function(){return new e.VirtualJoysticksCamera(i,e.Vector3.Zero(),n)};case"WebVRFreeCamera":return function(){return new e.WebVRFreeCamera(i,e.Vector3.Zero(),n)};case"VRDeviceOrientationFreeCamera":return function(){return new e.VRDeviceOrientationFreeCamera(i,e.Vector3.Zero(),n)};case"AnaglyphArcRotateCamera":return function(){return new e.AnaglyphArcRotateCamera(i,0,0,1,e.Vector3.Zero(),r,n)};case"AnaglyphFreeCamera":return function(){return new e.AnaglyphFreeCamera(i,e.Vector3.Zero(),r,n)};case"AnaglyphGamepadCamera":return function(){return new e.AnaglyphGamepadCamera(i,e.Vector3.Zero(),r,n);
  8. };case"AnaglyphUniversalCamera":return function(){return new e.AnaglyphUniversalCamera(i,e.Vector3.Zero(),r,n)};case"StereoscopicArcRotateCamera":return function(){return new e.StereoscopicArcRotateCamera(i,0,0,1,e.Vector3.Zero(),r,o,n)};case"StereoscopicFreeCamera":return function(){return new e.StereoscopicFreeCamera(i,e.Vector3.Zero(),r,o,n)};case"StereoscopicGamepadCamera":return function(){return new e.StereoscopicGamepadCamera(i,e.Vector3.Zero(),r,o,n)};case"StereoscopicUniversalCamera":return function(){return new e.StereoscopicUniversalCamera(i,e.Vector3.Zero(),r,o,n)};case"FreeCamera":return function(){return new e.UniversalCamera(i,e.Vector3.Zero(),n)};default:return function(){return new e.UniversalCamera(i,e.Vector3.Zero(),n)}}},i.Parse=function(t,n){var r=t.type,o=i.GetConstructorFromName(r,t.name,n,t.interaxial_distance,t.isStereoscopicSideBySide),s=e.SerializationHelper.Parse(o,t,n);if(t.parentId&&(s._waitingParentId=t.parentId),s.inputs&&s.inputs.parse(t),t.target&&s.setTarget&&s.setTarget(e.Vector3.FromArray(t.target)),t.cameraRigMode){var a=t.interaxial_distance?{interaxialDistance:t.interaxial_distance}:{};s.setCameraRigMode(t.cameraRigMode,a)}if(t.animations){for(var h=0;h<t.animations.length;h++){var c=t.animations[h];s.animations.push(e.Animation.Parse(c))}e.Node.ParseAnimationRanges(s,t,n)}return t.autoAnimate&&n.beginAnimation(s,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,t.autoAnimateSpeed||1),s},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.ForceAttachControlToAlwaysPreventDefault=!1,__decorate([e.serializeAsVector3()],i.prototype,"position",void 0),__decorate([e.serializeAsVector3()],i.prototype,"upVector",void 0),__decorate([e.serialize()],i.prototype,"orthoLeft",void 0),__decorate([e.serialize()],i.prototype,"orthoRight",void 0),__decorate([e.serialize()],i.prototype,"orthoBottom",void 0),__decorate([e.serialize()],i.prototype,"orthoTop",void 0),__decorate([e.serialize()],i.prototype,"fov",void 0),__decorate([e.serialize()],i.prototype,"minZ",void 0),__decorate([e.serialize()],i.prototype,"maxZ",void 0),__decorate([e.serialize()],i.prototype,"inertia",void 0),__decorate([e.serialize()],i.prototype,"mode",void 0),__decorate([e.serialize()],i.prototype,"layerMask",void 0),__decorate([e.serialize()],i.prototype,"fovMode",void 0),__decorate([e.serialize()],i.prototype,"cameraRigMode",void 0),__decorate([e.serialize()],i.prototype,"interaxialDistance",void 0),__decorate([e.serialize()],i.prototype,"isStereoscopicSideBySide",void 0),i}(e.Node);e.Camera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){e.CameraInputTypes={};var t=function(){function t(e){this.attached={},this.camera=e,this.checkInputs=function(){}}return t.prototype.add=function(t){var i=t.getSimpleName();return this.attached[i]?void e.Tools.Warn("camera input of type "+i+" already exists on camera"):(this.attached[i]=t,t.camera=this.camera,t.checkInputs&&(this.checkInputs=this._addCheckInputs(t.checkInputs.bind(t))),void(this.attachedElement&&t.attachControl(this.attachedElement)))},t.prototype.remove=function(e){for(var t in this.attached){var i=this.attached[t];i===e&&(i.detachControl(this.attachedElement),delete this.attached[t],this.rebuildInputCheck())}},t.prototype.removeByType=function(e){for(var t in this.attached){var i=this.attached[t];i.getTypeName()===e&&(i.detachControl(this.attachedElement),delete this.attached[t],this.rebuildInputCheck())}},t.prototype._addCheckInputs=function(e){var t=this.checkInputs;return function(){t(),e()}},t.prototype.attachInput=function(e){e.attachControl(this.attachedElement,this.noPreventDefault)},t.prototype.attachElement=function(t,i){if(!this.attachedElement){i=e.Camera.ForceAttachControlToAlwaysPreventDefault?!1:i,this.attachedElement=t,this.noPreventDefault=i;for(var n in this.attached){this.attached[n];this.attached[n].attachControl(t,i)}}},t.prototype.detachElement=function(e){if(this.attachedElement===e){for(var t in this.attached){this.attached[t];this.attached[t].detachControl(e)}this.attachedElement=null}},t.prototype.rebuildInputCheck=function(){this.checkInputs=function(){};for(var e in this.attached){var t=this.attached[e];t.checkInputs&&(this.checkInputs=this._addCheckInputs(t.checkInputs.bind(t)))}},t.prototype.clear=function(){this.attachedElement&&this.detachElement(this.attachedElement),this.attached={},this.attachedElement=null,this.checkInputs=function(){}},t.prototype.serialize=function(t){var i={};for(var n in this.attached){var r=this.attached[n],o=e.SerializationHelper.Serialize(r);i[r.getTypeName()]=o}t.inputsmgr=i},t.prototype.parse=function(t){var i=t.inputsmgr;if(i){this.clear();for(var n in i){var r=e.CameraInputTypes[n];if(r){var o=i[n],s=e.SerializationHelper.Parse(function(){return new r},o,null);this.add(s)}}}else for(var n in this.attached){var r=e.CameraInputTypes[this.attached[n].getTypeName()];if(r){var s=e.SerializationHelper.Parse(function(){return new r},t,null);this.remove(this.attached[n]),this.add(s)}}},t}();e.CameraInputsManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this.angularSensibility=2e3}return t.prototype.attachControl=function(t,i){var n=this;if(!this._pointerInput){var r=this.camera,o=this.camera.getEngine();this._pointerInput=function(t,s){var a=t.event;if(t.type===e.PointerEventTypes.POINTERDOWN){try{a.srcElement.setPointerCapture(a.pointerId)}catch(h){}n.previousPosition={x:a.clientX,y:a.clientY},i||a.preventDefault()}else if(t.type===e.PointerEventTypes.POINTERUP){try{a.srcElement.releasePointerCapture(a.pointerId)}catch(h){}n.previousPosition=null,i||a.preventDefault()}else if(t.type===e.PointerEventTypes.POINTERMOVE){if(!n.previousPosition&&!o.isPointerLock)return;var c,l;o.isPointerLock?(c=a.movementX||a.mozMovementX||a.webkitMovementX||a.msMovementX||0,l=a.movementY||a.mozMovementY||a.webkitMovementY||a.msMovementY||0):(c=a.clientX-n.previousPosition.x,l=a.clientY-n.previousPosition.y),r.cameraRotation.y+=c/n.angularSensibility,r.cameraRotation.x+=l/n.angularSensibility,n.previousPosition={x:a.clientX,y:a.clientY},i||a.preventDefault()}}}this._observer=this.camera.getScene().onPointerObservable.add(this._pointerInput,e.PointerEventTypes.POINTERDOWN|e.PointerEventTypes.POINTERUP|e.PointerEventTypes.POINTERMOVE)},t.prototype.detachControl=function(e){this._observer&&e&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._observer=null,this.previousPosition=null)},t.prototype.getTypeName=function(){return"FreeCameraMouseInput"},t.prototype.getSimpleName=function(){return"mouse"},__decorate([e.serialize()],t.prototype,"angularSensibility",void 0),t}();e.FreeCameraMouseInput=t,e.CameraInputTypes.FreeCameraMouseInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this._keys=[],this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39]}return t.prototype.attachControl=function(t,i){var n=this;this._onKeyDown||(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),i||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),i||e.preventDefault()}},e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]))},t.prototype.detachControl=function(t){this._onKeyDown&&(e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]),this._keys=[],this._onKeyDown=null,this._onKeyUp=null)},t.prototype.checkInputs=function(){if(this._onKeyDown)for(var t=this.camera,i=0;i<this._keys.length;i++){var n=this._keys[i],r=t._computeLocalCameraSpeed();-1!==this.keysLeft.indexOf(n)?t._localDirection.copyFromFloats(-r,0,0):-1!==this.keysUp.indexOf(n)?t._localDirection.copyFromFloats(0,0,r):-1!==this.keysRight.indexOf(n)?t._localDirection.copyFromFloats(r,0,0):-1!==this.keysDown.indexOf(n)&&t._localDirection.copyFromFloats(0,0,-r),t.getViewMatrix().invertToRef(t._cameraTransformMatrix),e.Vector3.TransformNormalToRef(t._localDirection,t._cameraTransformMatrix,t._transformedDirection),t.cameraDirection.addInPlace(t._transformedDirection)}},t.prototype.getTypeName=function(){return"FreeCameraKeyboardMoveInput"},t.prototype._onLostFocus=function(e){this._keys=[]},t.prototype.getSimpleName=function(){return"keyboard"},__decorate([e.serialize()],t.prototype,"keysUp",void 0),__decorate([e.serialize()],t.prototype,"keysDown",void 0),__decorate([e.serialize()],t.prototype,"keysLeft",void 0),__decorate([e.serialize()],t.prototype,"keysRight",void 0),t}();e.FreeCameraKeyboardMoveInput=t,e.CameraInputTypes.FreeCameraKeyboardMoveInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this._offsetX=null,this._offsetY=null,this._pointerCount=0,this._pointerPressed=[],this.touchAngularSensibility=2e5,this.touchMoveSensibility=250}return t.prototype.attachControl=function(t,i){var n,r=this;void 0===this._pointerInput&&(this._onLostFocus=function(e){r._offsetX=null,r._offsetY=null},this._pointerInput=function(t,o){var s=t.event;if(t.type===e.PointerEventTypes.POINTERDOWN){if("mouse"===s.pointerType)return;if(i||s.preventDefault(),r._pointerPressed.push(s.pointerId),1!==r._pointerPressed.length)return;n={x:s.clientX,y:s.clientY}}else if(t.type===e.PointerEventTypes.POINTERUP){if("mouse"===s.pointerType)return;i||s.preventDefault();var a=r._pointerPressed.indexOf(s.pointerId);if(-1===a)return;if(r._pointerPressed.splice(a,1),0!=a)return;n=null,r._offsetX=null,r._offsetY=null}else if(t.type===e.PointerEventTypes.POINTERMOVE){if("mouse"===s.pointerType)return;if(i||s.preventDefault(),!n)return;var a=r._pointerPressed.indexOf(s.pointerId);if(0!=a)return;r._offsetX=s.clientX-n.x,r._offsetY=-(s.clientY-n.y)}}),this._observer=this.camera.getScene().onPointerObservable.add(this._pointerInput,e.PointerEventTypes.POINTERDOWN|e.PointerEventTypes.POINTERUP|e.PointerEventTypes.POINTERMOVE),t.addEventListener("blur",this._onLostFocus)},t.prototype.detachControl=function(e){this._pointerInput&&e&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._observer=null,e.removeEventListener("blur",this._onLostFocus),this._onLostFocus=null,this._pointerPressed=[],this._offsetX=null,this._offsetY=null,this._pointerCount=0)},t.prototype.checkInputs=function(){if(this._offsetX){var t=this.camera;if(t.cameraRotation.y+=this._offsetX/this.touchAngularSensibility,this._pointerPressed.length>1)t.cameraRotation.x+=-this._offsetY/this.touchAngularSensibility;else{var i=t._computeLocalCameraSpeed(),n=new e.Vector3(0,0,i*this._offsetY/this.touchMoveSensibility);e.Matrix.RotationYawPitchRollToRef(t.rotation.y,t.rotation.x,0,t._cameraRotationMatrix),t.cameraDirection.addInPlace(e.Vector3.TransformCoordinates(n,t._cameraRotationMatrix))}}},t.prototype.getTypeName=function(){return"FreeCameraTouchInput"},t.prototype.getSimpleName=function(){return"touch"},__decorate([e.serialize()],t.prototype,"touchAngularSensibility",void 0),__decorate([e.serialize()],t.prototype,"touchMoveSensibility",void 0),t}();e.FreeCameraTouchInput=t,e.CameraInputTypes.FreeCameraTouchInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this._offsetX=null,this._offsetY=null,this._orientationGamma=0,this._orientationBeta=0,this._initialOrientationGamma=0,this._initialOrientationBeta=0,this.angularSensibility=1e4,this.moveSensibility=50,this._resetOrientationGamma=this.resetOrientationGamma.bind(this),this._orientationChanged=this.orientationChanged.bind(this)}return t.prototype.attachControl=function(e,t){window.addEventListener("resize",this._resetOrientationGamma,!1),window.addEventListener("deviceorientation",this._orientationChanged)},t.prototype.resetOrientationGamma=function(){this._initialOrientationGamma=null},t.prototype.orientationChanged=function(e){this._initialOrientationGamma||(this._initialOrientationGamma=e.gamma,this._initialOrientationBeta=e.beta),this._orientationGamma=e.gamma,this._orientationBeta=e.beta,this._offsetY=this._initialOrientationBeta-this._orientationBeta,this._offsetX=this._initialOrientationGamma-this._orientationGamma},t.prototype.detachControl=function(e){window.removeEventListener("resize",this._resetOrientationGamma),window.removeEventListener("deviceorientation",this._orientationChanged),this._orientationGamma=0,this._orientationBeta=0,this._initialOrientationGamma=0,this._initialOrientationBeta=0,this._offsetX=null,this._offsetY=null},t.prototype.checkInputs=function(){if(this._offsetX){var t=this.camera;t.cameraRotation.y-=this._offsetX/this.angularSensibility;var i=t._computeLocalCameraSpeed(),n=new e.Vector3(0,0,i*this._offsetY/this.moveSensibility);e.Matrix.RotationYawPitchRollToRef(t.rotation.y,t.rotation.x,0,t._cameraRotationMatrix),t.cameraDirection.addInPlace(e.Vector3.TransformCoordinates(n,t._cameraRotationMatrix))}},t.prototype.getTypeName=function(){return"FreeCameraDeviceOrientationInput"},t.prototype.getSimpleName=function(){return"deviceOrientation"},__decorate([e.serialize()],t.prototype,"angularSensibility",void 0),__decorate([e.serialize()],t.prototype,"moveSensibility",void 0),t}();e.FreeCameraDeviceOrientationInput=t,e.CameraInputTypes.FreeCameraDeviceOrientationInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this.alphaCorrection=1,this.betaCorrection=1,this.gammaCorrection=1,this._alpha=0,this._beta=0,this._gamma=0,this._dirty=!1,this._deviceOrientationHandler=this._onOrientationEvent.bind(this)}return e.prototype.attachControl=function(e,t){window.addEventListener("deviceorientation",this._deviceOrientationHandler)},e.prototype._onOrientationEvent=function(e){this.camera;this._alpha=0|+e.alpha,this._beta=0|+e.beta,this._gamma=0|+e.gamma,this._dirty=!0},e.prototype.checkInputs=function(){if(this._dirty){this._dirty=!1;var e=this._gamma;e=0>e?90+e:270-e,this.camera.rotation.x=this.gammaCorrection*e/180*Math.PI,this.camera.rotation.y=this.alphaCorrection*-this._alpha/180*Math.PI,this.camera.rotation.z=this.betaCorrection*this._beta/180*Math.PI}},e.prototype.detachControl=function(e){window.removeEventListener("deviceorientation",this._deviceOrientationHandler)},e.prototype.getTypeName=function(){return"FreeCameraVRDeviceOrientationInput"},e.prototype.getSimpleName=function(){return"VRDeviceOrientation"},e}();e.FreeCameraVRDeviceOrientationInput=t,e.CameraInputTypes.FreeCameraVRDeviceOrientationInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this.gamepadAngularSensibility=200,this.gamepadMoveSensibility=40}return t.prototype.attachControl=function(t,i){var n=this;this._gamepads=new e.Gamepads(function(e){n._onNewGameConnected(e)})},t.prototype.detachControl=function(e){this._gamepads&&this._gamepads.dispose(),this.gamepad=null},t.prototype.checkInputs=function(){if(this.gamepad){var t=this.camera,i=this.gamepad.leftStick,n=i.x/this.gamepadMoveSensibility,r=i.y/this.gamepadMoveSensibility;i.x=Math.abs(n)>.005?0+n:0,i.y=Math.abs(r)>.005?0+r:0;var o=this.gamepad.rightStick,s=o.x/this.gamepadAngularSensibility,a=o.y/this.gamepadAngularSensibility;o.x=Math.abs(s)>.001?0+s:0,o.y=Math.abs(a)>.001?0+a:0;var h=e.Matrix.RotationYawPitchRoll(t.rotation.y,t.rotation.x,0),c=50*t._computeLocalCameraSpeed(),l=e.Vector3.TransformCoordinates(new e.Vector3(i.x*c,0,-i.y*c),h);t.cameraDirection=t.cameraDirection.add(l),t.cameraRotation=t.cameraRotation.add(new e.Vector2(o.y,o.x))}},t.prototype._onNewGameConnected=function(e){0===e.index&&(this.gamepad=e)},t.prototype.getTypeName=function(){return"FreeCameraGamepadInput"},t.prototype.getSimpleName=function(){return"gamepad"},__decorate([e.serialize()],t.prototype,"gamepadAngularSensibility",void 0),__decorate([e.serialize()],t.prototype,"gamepadMoveSensibility",void 0),t}();e.FreeCameraGamepadInput=t,e.CameraInputTypes.FreeCameraGamepadInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.prototype.getLeftJoystick=function(){return this._leftjoystick},t.prototype.getRightJoystick=function(){return this._rightjoystick},t.prototype.checkInputs=function(){if(this._leftjoystick){var t=this.camera,i=50*t._computeLocalCameraSpeed(),n=e.Matrix.RotationYawPitchRoll(t.rotation.y,t.rotation.x,0),r=e.Vector3.TransformCoordinates(new e.Vector3(this._leftjoystick.deltaPosition.x*i,this._leftjoystick.deltaPosition.y*i,this._leftjoystick.deltaPosition.z*i),n);t.cameraDirection=t.cameraDirection.add(r),t.cameraRotation=t.cameraRotation.addVector3(this._rightjoystick.deltaPosition),this._leftjoystick.pressed||(this._leftjoystick.deltaPosition=this._leftjoystick.deltaPosition.scale(.9)),this._rightjoystick.pressed||(this._rightjoystick.deltaPosition=this._rightjoystick.deltaPosition.scale(.9))}},t.prototype.attachControl=function(t,i){this._leftjoystick=new e.VirtualJoystick(!0),this._leftjoystick.setAxisForUpDown(e.JoystickAxis.Z),this._leftjoystick.setAxisForLeftRight(e.JoystickAxis.X),this._leftjoystick.setJoystickSensibility(.15),this._rightjoystick=new e.VirtualJoystick(!1),this._rightjoystick.setAxisForUpDown(e.JoystickAxis.X),this._rightjoystick.setAxisForLeftRight(e.JoystickAxis.Y),this._rightjoystick.reverseUpDown=!0,this._rightjoystick.setJoystickSensibility(.05),this._rightjoystick.setJoystickColor("yellow")},t.prototype.detachControl=function(e){this._leftjoystick.releaseCanvas(),this._rightjoystick.releaseCanvas()},t.prototype.getTypeName=function(){return"FreeCameraVirtualJoystickInput"},t.prototype.getSimpleName=function(){return"virtualJoystick"},t}();e.FreeCameraVirtualJoystickInput=t,e.CameraInputTypes.FreeCameraVirtualJoystickInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this._keys=[],this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39]}return t.prototype.attachControl=function(t,i){var n=this;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),e.preventDefault&&(i||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),e.preventDefault&&(i||e.preventDefault())}},this._onLostFocus=function(){n._keys=[]},e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}])},t.prototype.detachControl=function(t){e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]),this._keys=[],this._onKeyDown=null,this._onKeyUp=null,this._onLostFocus=null},t.prototype.checkInputs=function(){if(this._onKeyDown)for(var e=this.camera,t=0;t<this._keys.length;t++){var i=this._keys[t];-1!==this.keysLeft.indexOf(i)?e.inertialAlphaOffset-=.01:-1!==this.keysUp.indexOf(i)?e.inertialBetaOffset-=.01:-1!==this.keysRight.indexOf(i)?e.inertialAlphaOffset+=.01:-1!==this.keysDown.indexOf(i)&&(e.inertialBetaOffset+=.01)}},t.prototype.getTypeName=function(){return"ArcRotateCameraKeyboardMoveInput"},t.prototype.getSimpleName=function(){return"keyboard"},__decorate([e.serialize()],t.prototype,"keysUp",void 0),__decorate([e.serialize()],t.prototype,"keysDown",void 0),__decorate([e.serialize()],t.prototype,"keysLeft",void 0),__decorate([e.serialize()],t.prototype,"keysRight",void 0),t}();e.ArcRotateCameraKeyboardMoveInput=t,e.CameraInputTypes.ArcRotateCameraKeyboardMoveInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this.wheelPrecision=3}return t.prototype.attachControl=function(t,i){var n=this;this._wheel=function(t,r){if(t.type===e.PointerEventTypes.POINTERWHEEL){var o=t.event,s=0;o.wheelDelta?s=o.wheelDelta/(40*n.wheelPrecision):o.detail&&(s=-o.detail/n.wheelPrecision),s&&(n.camera.inertialRadiusOffset+=s),o.preventDefault&&(i||o.preventDefault())}},this._observer=this.camera.getScene().onPointerObservable.add(this._wheel,e.PointerEventTypes.POINTERWHEEL)},t.prototype.detachControl=function(e){this._observer&&e&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._observer=null,this._wheel=null)},t.prototype.getTypeName=function(){return"ArcRotateCameraMouseWheelInput"},t.prototype.getSimpleName=function(){return"mousewheel"},__decorate([e.serialize()],t.prototype,"wheelPrecision",void 0),t}();e.ArcRotateCameraMouseWheelInput=t,e.CameraInputTypes.ArcRotateCameraMouseWheelInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=(e.Tools.GetPointerPrefix(),function(){function t(){this.angularSensibilityX=1e3,this.angularSensibilityY=1e3,this.pinchPrecision=6,this.panningSensibility=50,this._isRightClick=!1,this._isCtrlPushed=!1,this.pinchInwards=!0}return t.prototype.attachControl=function(t,i){var n,r=this,o=this.camera.getEngine(),s=new e.SmartCollection,a=0;this._pointerInput=function(t,o){var h=t.event;if(t.type===e.PointerEventTypes.POINTERDOWN){try{h.srcElement.setPointerCapture(h.pointerId)}catch(c){}r._isRightClick=2===h.button,s.add(h.pointerId,{x:h.clientX,y:h.clientY,type:h.pointerType}),n=s.item(h.pointerId),i||h.preventDefault()}else if(t.type===e.PointerEventTypes.POINTERUP){try{h.srcElement.releasePointerCapture(h.pointerId)}catch(c){}n=null,a=0,s.empty(),i||h.preventDefault()}else if(t.type===e.PointerEventTypes.POINTERMOVE)switch(i||h.preventDefault(),s.count){case 1:if(0!==r.panningSensibility&&(r._isCtrlPushed&&r.camera._useCtrlForPanning||!r.camera._useCtrlForPanning&&r._isRightClick))r.camera.inertialPanningX+=-(h.clientX-n.x)/r.panningSensibility,r.camera.inertialPanningY+=(h.clientY-n.y)/r.panningSensibility;else{var l=h.clientX-n.x,u=h.clientY-n.y;r.camera.inertialAlphaOffset-=l/r.angularSensibilityX,r.camera.inertialBetaOffset-=u/r.angularSensibilityY}n.x=h.clientX,n.y=h.clientY;break;case 2:s.item(h.pointerId).x=h.clientX,s.item(h.pointerId).y=h.clientY;var d=r.pinchInwards?1:-1,f=s.getItemByIndex(0).x-s.getItemByIndex(1).x,p=s.getItemByIndex(0).y-s.getItemByIndex(1).y,m=f*f+p*p;if(0===a)return void(a=m);m!==a&&(r.camera.inertialRadiusOffset+=(m-a)/(r.pinchPrecision*((r.angularSensibilityX+r.angularSensibilityY)/2)*d),a=m);break;default:s.item(h.pointerId)&&(s.item(h.pointerId).x=h.clientX,s.item(h.pointerId).y=h.clientY)}},this._observer=this.camera.getScene().onPointerObservable.add(this._pointerInput,e.PointerEventTypes.POINTERDOWN|e.PointerEventTypes.POINTERUP|e.PointerEventTypes.POINTERMOVE),this._onContextMenu=function(e){e.preventDefault()},this.camera._useCtrlForPanning||t.addEventListener("contextmenu",this._onContextMenu,!1),this._onLostFocus=function(){s.empty(),a=0,n=null},this._onKeyDown=function(e){r._isCtrlPushed=e.ctrlKey},this._onKeyUp=function(e){r._isCtrlPushed=e.ctrlKey},this._onMouseMove=function(e){if(o.isPointerLock){var t=e.movementX||e.mozMovementX||e.webkitMovementX||e.msMovementX||0,n=e.movementY||e.mozMovementY||e.webkitMovementY||e.msMovementY||0;r.camera.inertialAlphaOffset-=t/r.angularSensibilityX,r.camera.inertialBetaOffset-=n/r.angularSensibilityY,i||e.preventDefault()}},this._onGestureStart=function(e){void 0!==window.MSGesture&&(r._MSGestureHandler||(r._MSGestureHandler=new MSGesture,r._MSGestureHandler.target=t),r._MSGestureHandler.addPointer(e.pointerId))},this._onGesture=function(e){r.camera.radius*=e.scale,e.preventDefault&&(i||(e.stopPropagation(),e.preventDefault()))},t.addEventListener("mousemove",this._onMouseMove,!1),t.addEventListener("MSPointerDown",this._onGestureStart,!1),t.addEventListener("MSGestureChange",this._onGesture,!1),e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}])},t.prototype.detachControl=function(t){t&&this._observer&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._observer=null,t.removeEventListener("contextmenu",this._onContextMenu),t.removeEventListener("mousemove",this._onMouseMove),t.removeEventListener("MSPointerDown",this._onGestureStart),t.removeEventListener("MSGestureChange",this._onGesture),this._isRightClick=!1,this._isCtrlPushed=!1,this.pinchInwards=!0,this._onKeyDown=null,this._onKeyUp=null,this._onMouseMove=null,this._onGestureStart=null,this._onGesture=null,this._MSGestureHandler=null,this._onLostFocus=null,this._onContextMenu=null),e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}])},t.prototype.getTypeName=function(){return"ArcRotateCameraPointersInput"},t.prototype.getSimpleName=function(){return"pointers"},__decorate([e.serialize()],t.prototype,"angularSensibilityX",void 0),__decorate([e.serialize()],t.prototype,"angularSensibilityY",void 0),__decorate([e.serialize()],t.prototype,"pinchPrecision",void 0),__decorate([e.serialize()],t.prototype,"panningSensibility",void 0),t}());e.ArcRotateCameraPointersInput=t,e.CameraInputTypes.ArcRotateCameraPointersInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this.gamepadRotationSensibility=80,this.gamepadMoveSensibility=40}return t.prototype.attachControl=function(t,i){var n=this;this._gamepads=new e.Gamepads(function(e){n._onNewGameConnected(e)})},t.prototype.detachControl=function(e){this._gamepads&&this._gamepads.dispose(),this.gamepad=null},t.prototype.checkInputs=function(){if(this.gamepad){var e=this.camera,t=this.gamepad.rightStick;if(0!=t.x){var i=t.x/this.gamepadRotationSensibility;0!=i&&Math.abs(i)>.005&&(e.inertialAlphaOffset+=i)}if(0!=t.y){var n=t.y/this.gamepadRotationSensibility;0!=n&&Math.abs(n)>.005&&(e.inertialBetaOffset+=n)}var r=this.gamepad.leftStick;if(0!=r.y){var o=r.y/this.gamepadMoveSensibility;0!=o&&Math.abs(o)>.005&&(this.camera.inertialRadiusOffset-=o)}}},t.prototype._onNewGameConnected=function(e){0===e.index&&(this.gamepad=e)},t.prototype.getTypeName=function(){return"ArcRotateCameraGamepadInput"},t.prototype.getSimpleName=function(){return"gamepad"},__decorate([e.serialize()],t.prototype,"gamepadRotationSensibility",void 0),__decorate([e.serialize()],t.prototype,"gamepadMoveSensibility",void 0),t}();e.ArcRotateCameraGamepadInput=t,e.CameraInputTypes.ArcRotateCameraGamepadInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this.alphaCorrection=1,this.betaCorrection=1,this.gammaCorrection=1,this._alpha=0,this._beta=0,this._gamma=0,this._dirty=!1,this._deviceOrientationHandler=this._onOrientationEvent.bind(this)}return e.prototype.attachControl=function(e,t){this.camera.attachControl(e,t),window.addEventListener("deviceorientation",this._deviceOrientationHandler)},e.prototype._onOrientationEvent=function(e){this.camera;this._alpha=0|+e.alpha,this._beta=0|+e.beta,this._gamma=0|+e.gamma,this._dirty=!0},e.prototype.checkInputs=function(){this._dirty&&(this._dirty=!1,this._gamma<0&&(this._gamma=180+this._gamma),this.camera.alpha=-this._alpha/180*Math.PI%Math.PI*2,this.camera.beta=this._gamma/180*Math.PI)},e.prototype.detachControl=function(e){window.removeEventListener("deviceorientation",this._deviceOrientationHandler)},e.prototype.getTypeName=function(){return"ArcRotateCameraVRDeviceOrientationInput"},e.prototype.getSimpleName=function(){return"VRDeviceOrientation"},e}();e.ArcRotateCameraVRDeviceOrientationInput=t,e.CameraInputTypes.ArcRotateCameraVRDeviceOrientationInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r){t.call(this,i,n,r),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(i,t),i.prototype.getFrontPosition=function(e){var t=this.getTarget().subtract(this.position);return t.normalize(),t.scaleInPlace(e),this.globalPosition.add(t)},i.prototype._getLockedTargetPosition=function(){return this.lockedTarget?this.lockedTarget.position||this.lockedTarget:null},i.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)},i.prototype._updateCache=function(e){e||t.prototype._updateCache.call(this);var i=this._getLockedTargetPosition();i?this._cache.lockedTarget?this._cache.lockedTarget.copyFrom(i):this._cache.lockedTarget=i.clone():this._cache.lockedTarget=null,this._cache.rotation.copyFrom(this.rotation)},i.prototype._isSynchronizedViewMatrix=function(){if(!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)},i.prototype._computeLocalCameraSpeed=function(){var e=this.getEngine();return this.speed*(e.getDeltaTime()/(10*e.getFps()))},i.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 i=t.subtract(this.position);i.x>=0?this.rotation.y=-Math.atan(i.z/i.x)+Math.PI/2:this.rotation.y=-Math.atan(i.z/i.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)},i.prototype.getTarget=function(){return this._currentTarget},i.prototype._decideIfNeedsToMove=function(){return Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},i.prototype._updatePosition=function(){this.position.addInPlace(this.cameraDirection)},i.prototype._checkInputs=function(){var i=this._decideIfNeedsToMove(),n=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(i&&this._updatePosition(),n&&(this.rotation.x+=this.cameraRotation.x,this.rotation.y+=this.cameraRotation.y,!this.noRotationConstraint)){var r=Math.PI/2*.95;this.rotation.x>r&&(this.rotation.x=r),this.rotation.x<-r&&(this.rotation.x=-r)}i&&(Math.abs(this.cameraDirection.x)<e.Epsilon&&(this.cameraDirection.x=0),Math.abs(this.cameraDirection.y)<e.Epsilon&&(this.cameraDirection.y=0),Math.abs(this.cameraDirection.z)<e.Epsilon&&(this.cameraDirection.z=0),this.cameraDirection.scaleInPlace(this.inertia)),n&&(Math.abs(this.cameraRotation.x)<e.Epsilon&&(this.cameraRotation.x=0),Math.abs(this.cameraRotation.y)<e.Epsilon&&(this.cameraRotation.y=0),this.cameraRotation.scaleInPlace(this.inertia)),t.prototype._checkInputs.call(this)},i.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),
  9. 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},i.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},i.prototype.createRigCamera=function(t,n){if(this.cameraRigMode!==e.Camera.RIG_MODE_NONE){var r=new i(t,this.position.clone(),this.getScene());return this.cameraRigMode===e.Camera.RIG_MODE_VR&&(r._cameraRigParams={},r._cameraRigParams.vrActualUp=new e.Vector3(0,0,0),r._getViewMatrix=r._getVRViewMatrix),r}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 i=this._rigCameras[0],n=this._rigCameras[1];this.cameraRigMode===e.Camera.RIG_MODE_VR?(i.rotation.x=n.rotation.x=this.rotation.x,i.rotation.y=n.rotation.y=this.rotation.y,i.rotation.z=n.rotation.z=this.rotation.z,i.position.copyFrom(this.position),n.position.copyFrom(this.position)):(this._getRigCamPosition(-this._cameraRigParams.stereoHalfAngle,i.position),this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle,n.position),i.setTarget(this.getTarget()),n.setTarget(this.getTarget()))}t.prototype._updateRigCameras.call(this)},i.prototype._getRigCamPosition=function(t,i){this._rigCamTransformMatrix||(this._rigCamTransformMatrix=new e.Matrix);var n=this.getTarget();e.Matrix.Translation(-n.x,-n.y,-n.z).multiplyToRef(e.Matrix.RotationY(t),this._rigCamTransformMatrix),this._rigCamTransformMatrix=this._rigCamTransformMatrix.multiply(e.Matrix.Translation(n.x,n.y,n.z)),e.Vector3.TransformCoordinatesToRef(this.position,this._rigCamTransformMatrix,i)},i.prototype.getTypeName=function(){return"TargetCamera"},__decorate([e.serializeAsVector3()],i.prototype,"rotation",void 0),__decorate([e.serialize()],i.prototype,"speed",void 0),__decorate([e.serializeAsMeshReference("lockedTargetId")],i.prototype,"lockedTarget",void 0),i}(e.Camera);e.TargetCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r){var o=this;t.call(this,i,n,r),this.ellipsoid=new e.Vector3(.5,1,.5),this.checkCollisions=!1,this.applyGravity=!1,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,i,n){void 0===n&&(n=null),o.getScene().workerCollisions&&i.multiplyInPlace(o._collider.radius);var r=function(t){o._newPosition.copyFrom(t),o._newPosition.subtractToRef(o._oldPosition,o._diffPosition);o.position.clone();o._diffPosition.length()>e.Engine.CollisionsEpsilon&&(o.position.addInPlace(o._diffPosition),o.onCollide&&n&&o.onCollide(n))};r(i)},this.inputs=new e.FreeCameraInputsManager(this),this.inputs.addKeyboard().addMouse()}return __extends(i,t),Object.defineProperty(i.prototype,"angularSensibility",{get:function(){var e=this.inputs.attached.mouse;return e?e.angularSensibility:void 0},set:function(e){var t=this.inputs.attached.mouse;t&&(t.angularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysUp",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysUp:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysUp=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysDown",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysDown:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysDown=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysLeft",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysLeft:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysLeft=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysRight",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysRight:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysRight=e)},enumerable:!0,configurable:!0}),i.prototype.attachControl=function(e,t){this.inputs.attachElement(e,t)},i.prototype.detachControl=function(t){this.inputs.detachElement(t),this.cameraDirection=new e.Vector3(0,0,0),this.cameraRotation=new e.Vector2(0,0)},i.prototype._collideWithWorld=function(t){var i;i=this.parent?e.Vector3.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position,i.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._collider.radius=this.ellipsoid;var n=t;this.applyGravity&&(n=t.add(this.getScene().gravity)),this.getScene().collisionCoordinator.getNewPosition(this._oldPosition,n,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId)},i.prototype._checkInputs=function(){this._localDirection||(this._localDirection=e.Vector3.Zero(),this._transformedDirection=e.Vector3.Zero()),this.inputs.checkInputs(),t.prototype._checkInputs.call(this)},i.prototype._decideIfNeedsToMove=function(){return this._needMoveForGravity||Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},i.prototype._updatePosition=function(){this.checkCollisions&&this.getScene().collisionsEnabled?this._collideWithWorld(this.cameraDirection):this.position.addInPlace(this.cameraDirection)},i.prototype.dispose=function(){this.inputs.clear(),t.prototype.dispose.call(this)},i.prototype.getTypeName=function(){return"FreeCamera"},__decorate([e.serializeAsVector3()],i.prototype,"ellipsoid",void 0),__decorate([e.serialize()],i.prototype,"checkCollisions",void 0),__decorate([e.serialize()],i.prototype,"applyGravity",void 0),i}(e.TargetCamera);e.FreeCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e){t.call(this,e)}return __extends(i,t),i.prototype.addKeyboard=function(){return this.add(new e.FreeCameraKeyboardMoveInput),this},i.prototype.addMouse=function(){return this.add(new e.FreeCameraMouseInput),this},i.prototype.addGamepad=function(){return this.add(new e.FreeCameraGamepadInput),this},i.prototype.addDeviceOrientation=function(){return this.add(new e.FreeCameraDeviceOrientationInput),this},i.prototype.addVRDeviceOrientation=function(){return this.add(new e.FreeCameraVRDeviceOrientationInput),this},i.prototype.addTouch=function(){return this.add(new e.FreeCameraTouchInput),this},i.prototype.addVirtualJoystick=function(){return this.add(new e.FreeCameraVirtualJoystickInput),this},i}(e.CameraInputsManager);e.FreeCameraInputsManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,n,r){t.call(this,e,i,n),this.radius=12,this.rotationOffset=0,this.heightOffset=4,this.cameraAcceleration=.05,this.maxCameraSpeed=20,this.target=r}return __extends(i,t),i.prototype.getRadians=function(e){return e*Math.PI/180},i.prototype.follow=function(t){if(t){var i;if(t.rotationQuaternion){var n=new e.Matrix;t.rotationQuaternion.toRotationMatrix(n),i=Math.atan2(n.m[8],n.m[10])}else i=t.rotation.y;var r=this.getRadians(this.rotationOffset)+i,o=t.position.x+Math.sin(r)*this.radius,s=t.position.z+Math.cos(r)*this.radius,a=o-this.position.x,h=t.position.y+this.heightOffset-this.position.y,c=s-this.position.z,l=a*this.cameraAcceleration*2,u=h*this.cameraAcceleration,d=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),(d>this.maxCameraSpeed||d<-this.maxCameraSpeed)&&(d=1>d?-this.maxCameraSpeed:this.maxCameraSpeed),this.position=new e.Vector3(this.position.x+l,this.position.y+u,this.position.z+d),this.setTarget(t.position)}},i.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.follow(this.target)},i.prototype.getTypeName=function(){return"FollowCamera"},__decorate([e.serialize()],i.prototype,"radius",void 0),__decorate([e.serialize()],i.prototype,"rotationOffset",void 0),__decorate([e.serialize()],i.prototype,"heightOffset",void 0),__decorate([e.serialize()],i.prototype,"cameraAcceleration",void 0),__decorate([e.serialize()],i.prototype,"maxCameraSpeed",void 0),__decorate([e.serializeAsMeshReference("lockedTargetId")],i.prototype,"target",void 0),i}(e.TargetCamera);e.FollowCamera=t;var i=function(t){function i(i,n,r,o,s,a){t.call(this,i,e.Vector3.Zero(),a),this.alpha=n,this.beta=r,this.radius=o,this.target=s,this._cartesianCoordinates=e.Vector3.Zero(),this.follow()}return __extends(i,t),i.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)},i.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.follow()},i.prototype.getTypeName=function(){return"ArcFollowCamera"},i}(e.TargetCamera);e.ArcFollowCamera=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n){e.call(this,t,i,n),this.inputs.addTouch()}return __extends(t,e),Object.defineProperty(t.prototype,"touchAngularSensibility",{get:function(){var e=this.inputs.attached.touch;return e?e.touchAngularSensibility:void 0},set:function(e){var t=this.inputs.attached.touch;t&&(t.touchAngularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"touchMoveSensibility",{get:function(){var e=this.inputs.attached.touch;return e?e.touchMoveSensibility:void 0},set:function(e){var t=this.inputs.attached.touch;t&&(t.touchMoveSensibility=e)},enumerable:!0,configurable:!0}),t.prototype.getTypeName=function(){return"TouchCamera"},t}(e.FreeCamera);e.TouchCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s,a){var h=this;t.call(this,i,e.Vector3.Zero(),a),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.inertialPanningX=0,this.inertialPanningY=0,this.zoomOnFactor=1,this.targetScreenOffset=e.Vector2.Zero(),this.allowUpsideDown=!0,this._viewMatrix=new e.Matrix,this.panningAxis=new e.Vector3(1,1,0),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,i,n){void 0===n&&(n=null),h.getScene().workerCollisions&&h.checkCollisions&&i.multiplyInPlace(h._collider.radius),n?(h.setPosition(i),h.onCollide&&h.onCollide(n)):h._previousPosition.copyFrom(h.position);var r=Math.cos(h.alpha),o=Math.sin(h.alpha),s=Math.cos(h.beta),a=Math.sin(h.beta);0===a&&(a=1e-4);var c=h._getTargetPosition();c.addToRef(new e.Vector3(h.radius*r*a,h.radius*s,h.radius*o*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},s?this.target=s:this.target=e.Vector3.Zero(),this.alpha=n,this.beta=r,this.radius=o,this.getViewMatrix(),this.inputs=new e.ArcRotateCameraInputsManager(this),this.inputs.addKeyboard().addMouseWheel().addPointers().addGamepad()}return __extends(i,t),Object.defineProperty(i.prototype,"angularSensibilityX",{get:function(){var e=this.inputs.attached.pointers;return e?e.angularSensibilityX:void 0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.angularSensibilityX=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"angularSensibilityY",{get:function(){var e=this.inputs.attached.pointers;return e?e.angularSensibilityY:void 0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.angularSensibilityY=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"pinchPrecision",{get:function(){var e=this.inputs.attached.pointers;return e?e.pinchPrecision:void 0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.pinchPrecision=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"panningSensibility",{get:function(){var e=this.inputs.attached.pointers;return e?e.panningSensibility:void 0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.panningSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysUp",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysUp:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysUp=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysDown",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysDown:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysDown=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysLeft",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysLeft:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysLeft=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysRight",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysRight:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysRight=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"wheelPrecision",{get:function(){var e=this.inputs.attached.mousewheel;return e?e.wheelPrecision:void 0},set:function(e){var t=this.inputs.attached.mousewheel;t&&(t.wheelPrecision=e)},enumerable:!0,configurable:!0}),i.prototype._initCache=function(){t.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||t.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._getTargetPosition=function(){return this.target.getAbsolutePosition?this.target.getAbsolutePosition():this.target},i.prototype._isSynchronizedViewMatrix=function(){return t.prototype._isSynchronizedViewMatrix.call(this)?this._cache.target.equals(this.target)&&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(e,t,i){var n=this;void 0===i&&(i=!0),this._useCtrlForPanning=i,this.inputs.attachElement(e,t),this._reset=function(){n.inertialAlphaOffset=0,n.inertialBetaOffset=0,n.inertialRadiusOffset=0}},i.prototype.detachControl=function(e){this.inputs.detachElement(e),this._reset&&this._reset()},i.prototype._checkInputs=function(){this._collisionTriggered||(this.inputs.checkInputs(),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.Epsilon&&(this.inertialAlphaOffset=0),Math.abs(this.inertialBetaOffset)<e.Epsilon&&(this.inertialBetaOffset=0),Math.abs(this.inertialRadiusOffset)<e.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.Epsilon&&(this.inertialPanningX=0),Math.abs(this.inertialPanningY)<e.Epsilon&&(this.inertialPanningY=0),this._localDirection.copyFromFloats(this.inertialPanningX,this.inertialPanningY,this.inertialPanningY),this._localDirection.multiplyInPlace(this.panningAxis),this._viewMatrix.invertToRef(this._cameraTransformMatrix),e.Vector3.TransformNormalToRef(this._localDirection,this._cameraTransformMatrix,this._transformedDirection),this.panningAxis.y||(this._transformedDirection.y=0),this.target.addInPlace(this._transformedDirection)),this._checkLimits(),t.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.rebuildAnglesAndRadius=function(){var e=this.position.subtract(this._getTargetPosition());this.radius=e.length(),this.alpha=Math.acos(e.x/Math.sqrt(Math.pow(e.x,2)+Math.pow(e.z,2))),e.z<0&&(this.alpha=2*Math.PI-this.alpha),this.beta=Math.acos(e.y/this.radius),this._checkLimits()},i.prototype.setPosition=function(e){this.position.equals(e)||(this.position=e,this.rebuildAnglesAndRadius())},i.prototype.setTarget=function(e){this._getTargetPosition().equals(e)||(this.target=e,this.rebuildAnglesAndRadius())},i.prototype._getViewMatrix=function(){var t=Math.cos(this.alpha),i=Math.sin(this.alpha),n=Math.cos(this.beta),r=Math.sin(this.beta);0===r&&(r=1e-4);var o=this._getTargetPosition();if(o.addToRef(new e.Vector3(this.radius*t*r,this.radius*n,this.radius*i*r),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 s=this.upVector;this.allowUpsideDown&&this.beta<0&&(s=s.clone(),s=s.negate()),e.Matrix.LookAtLHToRef(this.position,o,s,this._viewMatrix),this._viewMatrix.m[12]+=this.targetScreenOffset.x,this._viewMatrix.m[13]+=this.targetScreenOffset.y}return this._viewMatrix},i.prototype.zoomOn=function(t,i){void 0===i&&(i=!1),t=t||this.getScene().meshes;var n=e.Mesh.MinMax(t),r=e.Vector3.Distance(n.min,n.max);this.radius=r*this.zoomOnFactor,this.focusOn({min:n.min,max:n.max,distance:r},i)},i.prototype.focusOn=function(t,i){void 0===i&&(i=!1);var n,r;void 0===t.min?(n=t||this.getScene().meshes,n=e.Mesh.MinMax(n),r=e.Vector3.Distance(n.min,n.max)):(n=t,r=t.distance),this.target=e.Mesh.Center(n),i||(this.maxZ=2*r)},i.prototype.createRigCamera=function(t,n){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._cameraRigParams.stereoHalfAngle*(0===n?1:-1),o=new i(t,this.alpha+r,this.beta,this.radius,this.target,this.getScene());return o._cameraRigParams={},o}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 i=this._rigCameras[0],n=this._rigCameras[1];i.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle,n.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle,i.beta=n.beta=this.beta,i.radius=n.radius=this.radius}t.prototype._updateRigCameras.call(this)},i.prototype.dispose=function(){this.inputs.clear(),t.prototype.dispose.call(this)},i.prototype.getTypeName=function(){return"ArcRotateCamera"},__decorate([e.serialize()],i.prototype,"alpha",void 0),__decorate([e.serialize()],i.prototype,"beta",void 0),__decorate([e.serialize()],i.prototype,"radius",void 0),__decorate([e.serializeAsVector3()],i.prototype,"target",void 0),__decorate([e.serialize()],i.prototype,"inertialAlphaOffset",void 0),__decorate([e.serialize()],i.prototype,"inertialBetaOffset",void 0),__decorate([e.serialize()],i.prototype,"inertialRadiusOffset",void 0),__decorate([e.serialize()],i.prototype,"lowerAlphaLimit",void 0),__decorate([e.serialize()],i.prototype,"upperAlphaLimit",void 0),__decorate([e.serialize()],i.prototype,"lowerBetaLimit",void 0),__decorate([e.serialize()],i.prototype,"upperBetaLimit",void 0),__decorate([e.serialize()],i.prototype,"lowerRadiusLimit",void 0),__decorate([e.serialize()],i.prototype,"upperRadiusLimit",void 0),__decorate([e.serialize()],i.prototype,"inertialPanningX",void 0),__decorate([e.serialize()],i.prototype,"inertialPanningY",void 0),__decorate([e.serialize()],i.prototype,"zoomOnFactor",void 0),__decorate([e.serialize()],i.prototype,"allowUpsideDown",void 0),i}(e.TargetCamera);e.ArcRotateCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e){t.call(this,e)}return __extends(i,t),i.prototype.addMouseWheel=function(){return this.add(new e.ArcRotateCameraMouseWheelInput),this},i.prototype.addPointers=function(){return this.add(new e.ArcRotateCameraPointersInput),this},i.prototype.addKeyboard=function(){return this.add(new e.ArcRotateCameraKeyboardMoveInput),this},i.prototype.addGamepad=function(){return this.add(new e.ArcRotateCameraGamepadInput),this},i.prototype.addVRDeviceOrientation=function(){return this.add(new e.ArcRotateCameraVRDeviceOrientationInput),this},i}(e.CameraInputsManager);e.ArcRotateCameraInputsManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e){this._renderingGroups=new Array,this._scene=e}return t.prototype._renderParticles=function(t,i){if(0!==this._scene._activeParticleSystems.length){for(var n=this._scene.activeCamera,r=e.Tools.Now,o=0;o<this._scene._activeParticleSystems.length;o++){var s=this._scene._activeParticleSystems.data[o];s.renderingGroupId===t&&0!==(n.layerMask&s.layerMask)&&(this._clearDepthBuffer(),s.emitter.position&&i&&-1===i.indexOf(s.emitter)||(this._scene._activeParticles+=s.render()))}this._scene._particlesDuration+=e.Tools.Now-r}},t.prototype._renderSprites=function(t){if(this._scene.spritesEnabled&&0!==this._scene.spriteManagers.length){for(var i=this._scene.activeCamera,n=e.Tools.Now,r=0;r<this._scene.spriteManagers.length;r++){var o=this._scene.spriteManagers[r];o.renderingGroupId===t&&0!==(i.layerMask&o.layerMask)&&(this._clearDepthBuffer(),o.render())}this._scene._spritesDuration+=e.Tools.Now-n}},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,i,n,r){this._currentActiveMeshes=i,this._currentRenderParticles=n,this._currentRenderSprites=r;for(var o=0;o<t.MAX_RENDERINGGROUPS;o++){this._depthBufferAlreadyCleaned=0==o;var s=this._renderingGroups[o],a=!1;this._currentIndex=o,s?(this._clearDepthBuffer(),s.onBeforeTransparentRendering||(s.onBeforeTransparentRendering=this._renderSpritesAndParticles.bind(this)),s.render(e)||(this._renderingGroups.splice(o,1),a=!0,this._renderSpritesAndParticles())):this._renderSpritesAndParticles(),a&&o--}},t.prototype.reset=function(){this._renderingGroups.forEach(function(e,t,i){e&&e.prepare()})},t.prototype.dispatch=function(t){var i=t.getMesh(),n=i.renderingGroupId||0;this._renderingGroups[n]||(this._renderingGroups[n]=new e.RenderingGroup(n,this._scene)),this._renderingGroups[n].dispatch(t)},t.MAX_RENDERINGGROUPS=4,t}();e.RenderingManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){this.index=t,this._opaqueSubMeshes=new e.SmartArray(256),this._transparentSubMeshes=new e.SmartArray(256),this._alphaTestSubMeshes=new e.SmartArray(256),this._scene=i}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 i,n,r=this._scene.getEngine();for(i=0;i<this._opaqueSubMeshes.length;i++)n=this._opaqueSubMeshes.data[i],n.render(!1);for(r.setAlphaTesting(!0),i=0;i<this._alphaTestSubMeshes.length;i++)n=this._alphaTestSubMeshes.data[i],n.render(!1);if(r.setAlphaTesting(!1),this.onBeforeTransparentRendering&&this.onBeforeTransparentRendering(),this._transparentSubMeshes.length){for(i=0;i<this._transparentSubMeshes.length;i++)n=this._transparentSubMeshes.data[i],n._alphaIndex=n.getMesh().alphaIndex,n._distanceToCamera=n.getBoundingInfo().boundingSphere.centerWorld.subtract(this._scene.activeCamera.globalPosition).length();var o=this._transparentSubMeshes.data.slice(0,this._transparentSubMeshes.length);for(o.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}),i=0;i<o.length;i++)n=o[i],n.render(!0);r.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(),i=e.getMesh();t.needAlphaBlending()||i.visibility<1||i.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 e(){}return Object.defineProperty(e,"POINTERDOWN",{get:function(){return e._POINTERDOWN},enumerable:!0,configurable:!0}),Object.defineProperty(e,"POINTERUP",{get:function(){return e._POINTERUP},enumerable:!0,configurable:!0}),Object.defineProperty(e,"POINTERMOVE",{get:function(){return e._POINTERMOVE},enumerable:!0,configurable:!0}),Object.defineProperty(e,"POINTERWHEEL",{get:function(){return e._POINTERWHEEL},enumerable:!0,configurable:!0}),Object.defineProperty(e,"POINTERPICK",{get:function(){return e._POINTERPICK},enumerable:!0,configurable:!0}),e._POINTERDOWN=1,e._POINTERUP=2,e._POINTERMOVE=4,e._POINTERWHEEL=8,e._POINTERPICK=16,e}();e.PointerEventTypes=t;var i=function(){function e(e,t,i){this.type=e,this.event=t,this.pickInfo=i}return e}();e.PointerInfo=i;var n=function(){function n(t){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.onDisposeObservable=new e.Observable,this.onBeforeRenderObservable=new e.Observable,this.onAfterRenderObservable=new e.Observable,this.onReadyObservable=new e.Observable,this.onBeforeCameraRenderObservable=new e.Observable,this.onAfterCameraRenderObservable=new e.Observable,this.onNewCameraAddedObservable=new e.Observable,this.onCameraRemovedObservable=new e.Observable,this.onNewLightAddedObservable=new e.Observable,this.onLightRemovedObservable=new e.Observable,this.onNewGeometryAddedObservable=new e.Observable,this.onGeometryRemovedObservable=new e.Observable,this.onNewMeshAddedObservable=new e.Observable,this.onMeshRemovedObservable=new e.Observable,this.animations=[],this.onPointerObservable=new e.Observable,this.cameraToUseForPointers=null,this._startingPointerPosition=new e.Vector2(0,0),this._startingPointerTime=0,this.fogEnabled=!0,this.fogMode=n.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._intermediateRendering=!1,this._toBeDisposed=new e.SmartArray(256),this._pendingData=[],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._engine=t,t.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)),
  10. 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(n,"FOGMODE_NONE",{get:function(){return n._FOGMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"FOGMODE_EXP",{get:function(){return n._FOGMODE_EXP},enumerable:!0,configurable:!0}),Object.defineProperty(n,"FOGMODE_EXP2",{get:function(){return n._FOGMODE_EXP2},enumerable:!0,configurable:!0}),Object.defineProperty(n,"FOGMODE_LINEAR",{get:function(){return n._FOGMODE_LINEAR},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"beforeRender",{set:function(e){this._onBeforeRenderObserver&&this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver),this._onBeforeRenderObserver=this.onBeforeRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"afterRender",{set:function(e){this._onAfterRenderObserver&&this.onAfterRenderObservable.remove(this._onAfterRenderObserver),this._onAfterRenderObserver=this.onAfterRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"beforeCameraRender",{set:function(e){this._onBeforeCameraRenderObserver&&this.onBeforeCameraRenderObservable.remove(this._onBeforeCameraRenderObserver),this._onBeforeCameraRenderObserver=this.onBeforeCameraRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"afterCameraRender",{set:function(e){this._onAfterCameraRenderObserver&&this.onAfterCameraRenderObservable.remove(this._onAfterCameraRenderObserver),this._onAfterCameraRenderObserver=this.onAfterCameraRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"debugLayer",{get:function(){return this._debugLayer},enumerable:!0,configurable:!0}),Object.defineProperty(n.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(n.prototype,"SelectionOctree",{get:function(){return this._selectionOctree},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"meshUnderPointer",{get:function(){return this._pointerOverMesh},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"pointerX",{get:function(){return this._pointerX},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"pointerY",{get:function(){return this._pointerY},enumerable:!0,configurable:!0}),n.prototype.getCachedMaterial=function(){return this._cachedMaterial},n.prototype.getBoundingBoxRenderer=function(){return this._boundingBoxRenderer},n.prototype.getOutlineRenderer=function(){return this._outlineRenderer},n.prototype.getEngine=function(){return this._engine},n.prototype.getTotalVertices=function(){return this._totalVertices},n.prototype.getActiveIndices=function(){return this._activeIndices},n.prototype.getActiveParticles=function(){return this._activeParticles},n.prototype.getActiveBones=function(){return this._activeBones},n.prototype.getLastFrameDuration=function(){return this._lastFrameDuration},n.prototype.getEvaluateActiveMeshesDuration=function(){return this._evaluateActiveMeshesDuration},n.prototype.getActiveMeshes=function(){return this._activeMeshes},n.prototype.getRenderTargetsDuration=function(){return this._renderTargetsDuration},n.prototype.getRenderDuration=function(){return this._renderDuration},n.prototype.getParticlesDuration=function(){return this._particlesDuration},n.prototype.getSpritesDuration=function(){return this._spritesDuration},n.prototype.getAnimationRatio=function(){return this._animationRatio},n.prototype.getRenderId=function(){return this._renderId},n.prototype.incrementRenderId=function(){this._renderId++},n.prototype._updatePointerPosition=function(e){var t=this._engine.getRenderingCanvasClientRect();this._pointerX=e.clientX-t.left,this._pointerY=e.clientY-t.top,this._unTranslatedPointerX=this._pointerX,this._unTranslatedPointerY=this._pointerY,this.cameraToUseForPointers&&(this._pointerX=this._pointerX-this.cameraToUseForPointers.viewport.x*this._engine.getRenderWidth(),this._pointerY=this._pointerY-this.cameraToUseForPointers.viewport.y*this._engine.getRenderHeight())},n.prototype.attachControl=function(n,r,o){var s=this;void 0===n&&(n=!0),void 0===r&&(r=!0),void 0===o&&(o=!0);var a=function(e){return e.isPickable&&e.actionManager&&e.actionManager.hasPointerTriggers};this._onPointerMove=function(e){if(s.cameraToUseForPointers||s.activeCamera){var n=s._engine.getRenderingCanvas();s._updatePointerPosition(e),s.pointerMovePredicate||(s.pointerMovePredicate=function(e){return e.isPickable&&e.isVisible&&e.isReady()&&(s.constantlyUpdateMeshUnderPointer||null!==e.actionManager&&void 0!==e.actionManager)});var r=s.pick(s._unTranslatedPointerX,s._unTranslatedPointerY,s.pointerMovePredicate,!1,s.cameraToUseForPointers);if(r.hit&&r.pickedMesh?(s.setPointerOverSprite(null),s.setPointerOverMesh(r.pickedMesh),s._pointerOverMesh.actionManager&&s._pointerOverMesh.actionManager.hasPointerTriggers?n.style.cursor="pointer":n.style.cursor=""):(s.setPointerOverMesh(null),r=s.pickSprite(s._unTranslatedPointerX,s._unTranslatedPointerY,a,!1,s.cameraToUseForPointers),r.hit&&r.pickedSprite?(n.style.cursor="pointer",s.setPointerOverSprite(r.pickedSprite)):(s.setPointerOverSprite(null),n.style.cursor="")),s.onPointerMove&&s.onPointerMove(e,r),s.onPointerObservable.hasObservers()){var o="mousewheel"===e.type?t.POINTERWHEEL:t.POINTERMOVE,h=new i(o,e,r);s.onPointerObservable.notifyObservers(h,o)}}},this._onPointerDown=function(n){if(s.cameraToUseForPointers||s.activeCamera){s._updatePointerPosition(n),s._startingPointerPosition.x=s._pointerX,s._startingPointerPosition.y=s._pointerY,s._startingPointerTime=(new Date).getTime(),s.pointerDownPredicate||(s.pointerDownPredicate=function(e){return e.isPickable&&e.isVisible&&e.isReady()&&(!e.actionManager||e.actionManager.hasPointerTriggers)}),s._pickedDownMesh=null;var r=s.pick(s._unTranslatedPointerX,s._unTranslatedPointerY,s.pointerDownPredicate,!1,s.cameraToUseForPointers);if(r.hit&&r.pickedMesh&&r.pickedMesh.actionManager){if(s._pickedDownMesh=r.pickedMesh,r.pickedMesh.actionManager.hasPickTriggers){switch(n.button){case 0:r.pickedMesh.actionManager.processTrigger(e.ActionManager.OnLeftPickTrigger,e.ActionEvent.CreateNew(r.pickedMesh,n));break;case 1:r.pickedMesh.actionManager.processTrigger(e.ActionManager.OnCenterPickTrigger,e.ActionEvent.CreateNew(r.pickedMesh,n));break;case 2:r.pickedMesh.actionManager.processTrigger(e.ActionManager.OnRightPickTrigger,e.ActionEvent.CreateNew(r.pickedMesh,n))}r.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickDownTrigger,e.ActionEvent.CreateNew(r.pickedMesh,n))}if(r.pickedMesh.actionManager.hasSpecificTrigger(e.ActionManager.OnLongPressTrigger)){var o=s;window.setTimeout(function(){var t=o.pick(o._unTranslatedPointerX,o._unTranslatedPointerY,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,n)))},e.ActionManager.LongPressDelay)}}if(s.onPointerDown&&s.onPointerDown(n,r),s.onPointerObservable.hasObservers()){var h=t.POINTERDOWN,c=new i(h,n,r);s.onPointerObservable.notifyObservers(c,h)}if(s._pickedDownSprite=null,s.spriteManagers.length>0&&(r=s.pickSprite(s._unTranslatedPointerX,s._unTranslatedPointerY,a,!1,s.cameraToUseForPointers),r.hit&&r.pickedSprite&&r.pickedSprite.actionManager)){switch(s._pickedDownSprite=r.pickedSprite,n.button){case 0:r.pickedSprite.actionManager.processTrigger(e.ActionManager.OnLeftPickTrigger,e.ActionEvent.CreateNewFromSprite(r.pickedSprite,s,n));break;case 1:r.pickedSprite.actionManager.processTrigger(e.ActionManager.OnCenterPickTrigger,e.ActionEvent.CreateNewFromSprite(r.pickedSprite,s,n));break;case 2:r.pickedSprite.actionManager.processTrigger(e.ActionManager.OnRightPickTrigger,e.ActionEvent.CreateNewFromSprite(r.pickedSprite,s,n))}r.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickDownTrigger,e.ActionEvent.CreateNewFromSprite(r.pickedSprite,s,n))}}},this._onPointerUp=function(n){if(s.cameraToUseForPointers||s.activeCamera){s._updatePointerPosition(n),s.pointerUpPredicate||(s.pointerUpPredicate=function(t){return t.isPickable&&t.isVisible&&t.isReady()&&(!t.actionManager||t.actionManager.hasPickTriggers||t.actionManager.hasSpecificTrigger(e.ActionManager.OnLongPressTrigger))});var r=s.pick(s._unTranslatedPointerX,s._unTranslatedPointerY,s.pointerUpPredicate,!1,s.cameraToUseForPointers);if(r.hit&&r.pickedMesh){if(null!=s._pickedDownMesh&&r.pickedMesh==s._pickedDownMesh&&(s.onPointerPick&&s.onPointerPick(n,r),s.onPointerObservable.hasObservers())){var o=t.POINTERPICK,h=new i(o,n,r);s.onPointerObservable.notifyObservers(h,o)}r.pickedMesh.actionManager&&(r.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNew(r.pickedMesh,n)),Math.abs(s._startingPointerPosition.x-s._pointerX)<e.ActionManager.DragMovementThreshold&&Math.abs(s._startingPointerPosition.y-s._pointerY)<e.ActionManager.DragMovementThreshold&&r.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickTrigger,e.ActionEvent.CreateNew(r.pickedMesh,n)))}if(s._pickedDownMesh&&s._pickedDownMesh!==r.pickedMesh&&s._pickedDownMesh.actionManager.processTrigger(e.ActionManager.OnPickOutTrigger,e.ActionEvent.CreateNew(s._pickedDownMesh,n)),s.onPointerUp&&s.onPointerUp(n,r),s.onPointerObservable.hasObservers()){var o=t.POINTERUP,h=new i(o,n,r);s.onPointerObservable.notifyObservers(h,o)}s._startingPointerTime=0,s.spriteManagers.length>0&&(r=s.pickSprite(s._unTranslatedPointerX,s._unTranslatedPointerY,a,!1,s.cameraToUseForPointers),r.hit&&r.pickedSprite&&r.pickedSprite.actionManager&&(r.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNewFromSprite(r.pickedSprite,s,n)),Math.abs(s._startingPointerPosition.x-s._pointerX)<e.ActionManager.DragMovementThreshold&&Math.abs(s._startingPointerPosition.y-s._pointerY)<e.ActionManager.DragMovementThreshold&&r.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickTrigger,e.ActionEvent.CreateNewFromSprite(r.pickedSprite,s,n))),s._pickedDownSprite&&s._pickedDownSprite!==r.pickedSprite&&s._pickedDownSprite.actionManager.processTrigger(e.ActionManager.OnPickOutTrigger,e.ActionEvent.CreateNewFromSprite(s._pickedDownSprite,s,n)))}},this._onKeyDown=function(t){s.actionManager&&s.actionManager.processTrigger(e.ActionManager.OnKeyDownTrigger,e.ActionEvent.CreateNewFromScene(s,t))},this._onKeyUp=function(t){s.actionManager&&s.actionManager.processTrigger(e.ActionManager.OnKeyUpTrigger,e.ActionEvent.CreateNewFromScene(s,t))};var h=e.Tools.GetPointerPrefix();o&&(this._engine.getRenderingCanvas().addEventListener(h+"move",this._onPointerMove,!1),this._engine.getRenderingCanvas().addEventListener("mousewheel",this._onPointerMove,!1),this._engine.getRenderingCanvas().addEventListener("DOMMouseScroll",this._onPointerMove,!1)),r&&this._engine.getRenderingCanvas().addEventListener(h+"down",this._onPointerDown,!1),n&&this._engine.getRenderingCanvas().addEventListener(h+"up",this._onPointerUp,!1),e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp}])},n.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}])},n.prototype.isReady=function(){if(this._pendingData.length>0)return!1;var t;for(t=0;t<this._geometries.length;t++){var i=this._geometries[t];if(i.delayLoadState===e.Engine.DELAYLOADSTATE_LOADING)return!1}for(t=0;t<this.meshes.length;t++){var n=this.meshes[t];if(!n.isReady())return!1;var r=n.material;if(r&&!r.isReady(n))return!1}return!0},n.prototype.resetCachedMaterial=function(){this._cachedMaterial=null},n.prototype.registerBeforeRender=function(e){this.onBeforeRenderObservable.add(e)},n.prototype.unregisterBeforeRender=function(e){this.onBeforeRenderObservable.removeCallback(e)},n.prototype.registerAfterRender=function(e){this.onAfterRenderObservable.add(e)},n.prototype.unregisterAfterRender=function(e){this.onAfterRenderObservable.removeCallback(e)},n.prototype._addPendingData=function(e){this._pendingData.push(e)},n.prototype._removePendingData=function(e){var t=this._pendingData.indexOf(e);-1!==t&&this._pendingData.splice(t,1)},n.prototype.getWaitingItemsCount=function(){return this._pendingData.length},n.prototype.executeWhenReady=function(e){var t=this;this.onReadyObservable.add(e),-1===this._executeWhenReadyTimeoutId&&(this._executeWhenReadyTimeoutId=setTimeout(function(){t._checkIsReady()},150))},n.prototype._checkIsReady=function(){var e=this;return this.isReady()?(this.onReadyObservable.notifyObservers(this),this.onReadyObservable.clear(),void(this._executeWhenReadyTimeoutId=-1)):void(this._executeWhenReadyTimeoutId=setTimeout(function(){e._checkIsReady()},150))},n.prototype.beginAnimation=function(t,i,n,r,o,s,a){if(void 0===o&&(o=1),this.stopAnimation(t),a||(a=new e.Animatable(this,t,i,n,r,o,s)),t.animations&&a.appendAnimations(t,t.animations),t.getAnimatables)for(var h=t.getAnimatables(),c=0;c<h.length;c++)this.beginAnimation(h[c],i,n,r,o,s,a);return a.reset(),a},n.prototype.beginDirectAnimation=function(t,i,n,r,o,s,a){void 0===s&&(s=1);var h=new e.Animatable(this,t,n,r,o,s,a,i);return h},n.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(n.prototype,"Animatables",{get:function(){return this._activeAnimatables},enumerable:!0,configurable:!0}),n.prototype.stopAnimation=function(e){var t=this.getAnimatableByTarget(e);t&&t.stop()},n.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,i=t-this._animationStartDate,n=0;n<this._activeAnimatables.length;n++)this._activeAnimatables[n]._animate(i)}},n.prototype.getViewMatrix=function(){return this._viewMatrix},n.prototype.getProjectionMatrix=function(){return this._projectionMatrix},n.prototype.getTransformMatrix=function(){return this._transformMatrix},n.prototype.setTransformMatrix=function(e,t){this._viewMatrix=e,this._projectionMatrix=t,this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)},n.prototype.addMesh=function(e){e.uniqueId=this._uniqueIdCounter++;this.meshes.push(e);this.collisionCoordinator.onMeshAdded(e),this.onNewMeshAddedObservable.notifyObservers(e)},n.prototype.removeMesh=function(e){var t=this.meshes.indexOf(e);return-1!==t&&this.meshes.splice(t,1),this.collisionCoordinator.onMeshRemoved(e),this.onMeshRemovedObservable.notifyObservers(e),t},n.prototype.removeSkeleton=function(e){var t=this.skeletons.indexOf(e);return-1!==t&&this.skeletons.splice(t,1),t},n.prototype.removeLight=function(e){var t=this.lights.indexOf(e);return-1!==t&&this.lights.splice(t,1),this.onLightRemovedObservable.notifyObservers(e),t},n.prototype.removeCamera=function(e){var t=this.cameras.indexOf(e);-1!==t&&this.cameras.splice(t,1);var i=this.activeCameras.indexOf(e);return-1!==i&&this.activeCameras.splice(i,1),this.activeCamera===e&&(this.cameras.length>0?this.activeCamera=this.cameras[0]:this.activeCamera=null),this.onCameraRemovedObservable.notifyObservers(e),t},n.prototype.addLight=function(e){e.uniqueId=this._uniqueIdCounter++;this.lights.push(e);this.onNewLightAddedObservable.notifyObservers(e)},n.prototype.addCamera=function(e){e.uniqueId=this._uniqueIdCounter++;this.cameras.push(e);this.onNewCameraAddedObservable.notifyObservers(e)},n.prototype.swithActiveCamera=function(e,t){void 0===t&&(t=!0);var i=this._engine.getRenderingCanvas();this.activeCamera.detachControl(i),this.activeCamera=e,t&&e.attachControl(i)},n.prototype.setActiveCameraByID=function(e){var t=this.getCameraByID(e);return t?(this.activeCamera=t,t):null},n.prototype.setActiveCameraByName=function(e){var t=this.getCameraByName(e);return t?(this.activeCamera=t,t):null},n.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},n.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},n.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},n.prototype.getLensFlareSystemByID=function(e){for(var t=0;t<this.lensFlareSystems.length;t++)if(this.lensFlareSystems[t].id===e)return this.lensFlareSystems[t];return null},n.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},n.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},n.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},n.prototype.getBoneByID=function(e){for(var t=0;t<this.skeletons.length;t++)for(var i=this.skeletons[t],n=0;n<i.bones.length;n++)if(i.bones[n].id===e)return i.bones[n];return null},n.prototype.getBoneByName=function(e){for(var t=0;t<this.skeletons.length;t++)for(var i=this.skeletons[t],n=0;n<i.bones.length;n++)if(i.bones[n].name===e)return i.bones[n];return null},n.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},n.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},n.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},n.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},n.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},n.prototype.pushGeometry=function(e,t){return!t&&this.getGeometryByID(e.id)?!1:(this._geometries.push(e),this.collisionCoordinator.onGeometryAdded(e),this.onNewGeometryAddedObservable.notifyObservers(e),!0)},n.prototype.removeGeometry=function(e){var t=this._geometries.indexOf(e);return t>-1?(this._geometries.splice(t,1),this.collisionCoordinator.onGeometryDeleted(e),this.onGeometryRemovedObservable.notifyObservers(e),!0):!1},n.prototype.getGeometries=function(){return this._geometries},n.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},n.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},n.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},n.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},n.prototype.getNodeByID=function(e){var t=this.getMeshByID(e);if(t)return t;var i=this.getLightByID(e);if(i)return i;var n=this.getCameraByID(e);if(n)return n;var r=this.getBoneByID(e);return r},n.prototype.getNodeByName=function(e){var t=this.getMeshByName(e);if(t)return t;var i=this.getLightByName(e);if(i)return i;var n=this.getCameraByName(e);if(n)return n;var r=this.getBoneByName(e);return r},n.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},n.prototype.getSoundByName=function(t){var i;if(e.AudioEngine){for(i=0;i<this.mainSoundTrack.soundCollection.length;i++)if(this.mainSoundTrack.soundCollection[i].name===t)return this.mainSoundTrack.soundCollection[i];for(var n=0;n<this.soundTracks.length;n++)for(i=0;i<this.soundTracks[n].soundCollection.length;i++)if(this.soundTracks[n].soundCollection[i].name===t)return this.soundTracks[n].soundCollection[i]}return null},n.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},n.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},n.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},n.prototype.isActiveMesh=function(e){return-1!==this._activeMeshes.indexOf(e)},n.prototype._evaluateSubMesh=function(e,t){if(t.alwaysSelectAsActiveMesh||1===t.subMeshes.length||e.isInFrustum(this._frustumPlanes)){var i=e.getMaterial();t.showSubMeshesBoundingBox&&this._boundingBoxRenderer.renderList.push(e.getBoundingInfo().boundingBox),i&&(i.getRenderTargetTextures&&-1===this._processedMaterials.indexOf(i)&&(this._processedMaterials.push(i),this._renderTargets.concatWithNoDuplicate(i.getRenderTargetTextures())),this._activeIndices+=e.indexCount,this._renderingManager.dispatch(e))}},n.prototype._isInIntermediateRendering=function(){return this._intermediateRendering},n.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,i;if(this._selectionOctree){var n=this._selectionOctree.select(this._frustumPlanes);t=n.data,i=n.length}else i=this.meshes.length,t=this.meshes;for(var r=0;i>r;r++){var o=t[r];if(!o.isBlocked&&(this._totalVertices+=o.getTotalVertices(),o.isReady()&&o.isEnabled())){o.computeWorldMatrix(),o.actionManager&&o.actionManager.hasSpecificTriggers([e.ActionManager.OnIntersectionEnterTrigger,e.ActionManager.OnIntersectionExitTrigger])&&this._meshesForIntersections.pushNoDuplicate(o);var s=o.getLOD(this.activeCamera);s&&(o._preActivate(),(o.alwaysSelectAsActiveMesh||o.isVisible&&o.visibility>0&&0!==(o.layerMask&this.activeCamera.layerMask)&&o.isInFrustum(this._frustumPlanes))&&(this._activeMeshes.push(o),this.activeCamera._activeMeshes.push(o),o._activate(this._renderId),this._activeMesh(s)))}}var a=e.Tools.Now;if(this.particlesEnabled){e.Tools.StartPerformanceCounter("Particles",this.particleSystems.length>0);for(var h=0;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},n.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,i;if(e._submeshesOctree&&e.useOctreeForRenderingSelection){var n=e._submeshesOctree.select(this._frustumPlanes);t=n.length,i=n.data}else i=e.subMeshes,t=i.length;for(var r=0;t>r;r++){var o=i[r];this._evaluateSubMesh(o,e)}}},n.prototype.updateTransformMatrix=function(e){this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(e))},n.prototype._renderForCamera=function(t){var i=this._engine;if(this.activeCamera=t,!this.activeCamera)throw new Error("Active camera not set");e.Tools.StartPerformanceCounter("Rendering camera "+this.activeCamera.name),i.setViewport(this.activeCamera.viewport),this.resetCachedMaterial(),this._renderId++,this.updateTransformMatrix(),this.onBeforeCameraRenderObservable.notifyObservers(this.activeCamera);var n=e.Tools.Now;e.Tools.StartPerformanceCounter("Active meshes evaluation"),this._evaluateActiveMeshes(),this._evaluateActiveMeshesDuration+=e.Tools.Now-n,e.Tools.EndPerformanceCounter("Active meshes evaluation");for(var r=0;r<this._activeSkeletons.length;r++){var o=this._activeSkeletons.data[r];o.prepare()}for(var s=0;s<this._softwareSkinnedMeshes.length;s++){var a=this._softwareSkinnedMeshes.data[s];a.applySkeleton(a.skeleton)}var h=e.Tools.Now;if(this.renderTargetsEnabled&&this._renderTargets.length>0){this._intermediateRendering=!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._intermediateRendering=!1,this._renderId++,i.restoreDefaultFramebuffer()}this._renderTargetsDuration+=e.Tools.Now-h,this.postProcessManager._prepareFrame();var d,f,p=e.Tools.Now;if(this.layers.length){for(i.setDepthBuffer(!1),d=0;d<this.layers.length;d++)f=this.layers[d],f.isBackground&&f.render();i.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 _=0;_<this.lensFlareSystems.length;_++){var g=this.lensFlareSystems[_];0!==(t.layerMask&g.layerMask)&&g.render()}e.Tools.EndPerformanceCounter("Lens flares",this.lensFlareSystems.length>0)}if(this.layers.length){for(i.setDepthBuffer(!1),d=0;d<this.layers.length;d++)f=this.layers[d],f.isBackground||f.render();i.setDepthBuffer(!0)}this._renderDuration+=e.Tools.Now-p,this.postProcessManager._finalizeFrame(t.isIntermediate),this.activeCamera._updateFromScene(),this._renderTargets.reset(),this.onAfterCameraRenderObservable.notifyObservers(this.activeCamera),e.Tools.EndPerformanceCounter("Rendering camera "+this.activeCamera.name)},n.prototype._processSubCameras=function(t){if(t.cameraRigMode===e.Camera.RIG_MODE_NONE)return void this._renderForCamera(t);for(var i=0;i<t._rigCameras.length;i++)this._renderForCamera(t._rigCameras[i]);this.activeCamera=t,this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix()),this.activeCamera._updateFromScene()},n.prototype._checkIntersections=function(){for(var t=0;t<this._meshesForIntersections.length;t++)for(var i=this._meshesForIntersections.data[t],n=0;n<i.actionManager.actions.length;n++){var r=i.actionManager.actions[n];if(r.trigger===e.ActionManager.OnIntersectionEnterTrigger||r.trigger===e.ActionManager.OnIntersectionExitTrigger){var o=r.getTriggerParameter(),s=o instanceof e.AbstractMesh?o:o.mesh,a=s.intersectsMesh(i,o.usePreciseIntersection),h=i._intersectionsInProgress.indexOf(s);a&&-1===h?r.trigger===e.ActionManager.OnIntersectionEnterTrigger?(r._executeCurrent(e.ActionEvent.CreateNew(i,null,s)),i._intersectionsInProgress.push(s)):r.trigger===e.ActionManager.OnIntersectionExitTrigger&&i._intersectionsInProgress.push(s):!a&&h>-1&&(r.trigger===e.ActionManager.OnIntersectionExitTrigger&&r._executeCurrent(e.ActionEvent.CreateNew(i,null,s)),i.actionManager.hasSpecificTrigger(e.ActionManager.OnIntersectionExitTrigger)&&r.trigger!==e.ActionManager.OnIntersectionExitTrigger||i._intersectionsInProgress.splice(h,1))}}},n.prototype.render=function(){var t=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(n.MinDeltaTime,Math.min(this._engine.getDeltaTime(),n.MaxDeltaTime));this._animationRatio=.06*i,this._animate(),this._physicsEngine&&(e.Tools.StartPerformanceCounter("Physics"),this._physicsEngine._step(i/1e3),e.Tools.EndPerformanceCounter("Physics")),this.onBeforeRenderObservable.notifyObservers(this);var r=e.Tools.Now,o=this.getEngine(),s=this.activeCamera;if(this.renderTargetsEnabled){e.Tools.StartPerformanceCounter("Custom render targets",this.customRenderTargets.length>0);for(var a=0;a<this.customRenderTargets.length;a++){var h=this.customRenderTargets[a];if(h._shouldRender()){if(this._renderId++,this.activeCamera=h.activeCamera||this.activeCamera,!this.activeCamera)throw new Error("Active camera not set");o.setViewport(this.activeCamera.viewport),this.updateTransformMatrix(),h.render(s!==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-r,this.activeCamera=s,this.proceduralTexturesEnabled){e.Tools.StartPerformanceCounter("Procedural textures",this._proceduralTextures.length>0);for(var c=0;c<this._proceduralTextures.length;c++){var l=this._proceduralTextures[c];l._shouldRender()&&l.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 u=0;u<this.lights.length;u++){var d=this.lights[u],f=d.getShadowGenerator();d.isEnabled()&&f&&-1!==f.getShadowMap().getScene().textures.indexOf(f.getShadowMap())&&this._renderTargets.push(f.getShadowMap());
  11. }if(this._depthRenderer&&this._renderTargets.push(this._depthRenderer.getDepthMap()),this.postProcessRenderPipelineManager.update(),this.activeCameras.length>0)for(var p=this._renderId,m=0;m<this.activeCameras.length;m++)this._renderId=p,m>0&&this._engine.clear(0,!1,!0),this._processSubCameras(this.activeCameras[m]);else{if(!this.activeCamera)throw new Error("No camera defined");this._processSubCameras(this.activeCamera)}this._checkIntersections(),e.AudioEngine&&this._updateAudioParameters(),this.afterRender&&this.afterRender(),this.onAfterRenderObservable.notifyObservers(this);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-t},n.prototype._updateAudioParameters=function(){if(this.audioEnabled&&(0!==this.mainSoundTrack.soundCollection.length||1!==this.soundTracks.length)){var t,i=e.Engine.audioEngine;if(t=this.activeCameras.length>0?this.activeCameras[0]:this.activeCamera,t&&i.canUseWebAudio){i.audioContext.listener.setPosition(t.position.x,t.position.y,t.position.z);var n=e.Matrix.Invert(t.getViewMatrix()),r=e.Vector3.TransformNormal(new e.Vector3(0,0,-1),n);r.normalize(),i.audioContext.listener.setOrientation(r.x,r.y,r.z,0,1,0);var o;for(o=0;o<this.mainSoundTrack.soundCollection.length;o++){var s=this.mainSoundTrack.soundCollection[o];s.useCustomAttenuation&&s.updateDistanceFromListener()}for(o=0;o<this.soundTracks.length;o++)for(var a=0;a<this.soundTracks[o].soundCollection.length;a++)s=this.soundTracks[o].soundCollection[a],s.useCustomAttenuation&&s.updateDistanceFromListener()}}},Object.defineProperty(n.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}),n.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()},n.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(n.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}),n.prototype._switchAudioModeForHeadphones=function(){this.mainSoundTrack.switchPanningModelToHRTF();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].switchPanningModelToHRTF()},n.prototype._switchAudioModeForNormalSpeakers=function(){this.mainSoundTrack.switchPanningModelToEqualPower();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].switchPanningModelToEqualPower()},n.prototype.enableDepthRenderer=function(){return this._depthRenderer?this._depthRenderer:(this._depthRenderer=new e.DepthRenderer(this),this._depthRenderer)},n.prototype.disableDepthRenderer=function(){this._depthRenderer&&(this._depthRenderer.dispose(),this._depthRenderer=null)},n.prototype.freezeMaterials=function(){for(var e=0;e<this.materials.length;e++)this.materials[e].freeze()},n.prototype.unfreezeMaterials=function(){for(var e=0;e<this.materials.length;e++)this.materials[e].unfreeze()},n.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.onBeforeRenderObservable.clear(),this.onAfterRenderObservable.clear(),this.detachControl(),e.AudioEngine&&this.disposeSounds();var t,i=this._engine.getRenderingCanvas();for(t=0;t<this.cameras.length;t++)this.cameras[t].detachControl(i);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()},n.prototype.disposeSounds=function(){this.mainSoundTrack.dispose();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].dispose()},n.prototype.getWorldExtends=function(){for(var t=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),i=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),n=0;n<this.meshes.length;n++){var r=this.meshes[n];r.computeWorldMatrix(!0);var o=r.getBoundingInfo().boundingBox.minimumWorld,s=r.getBoundingInfo().boundingBox.maximumWorld;e.Tools.CheckExtends(o,t,i),e.Tools.CheckExtends(s,t,i)}return{min:t,max:i}},n.prototype.createOrUpdateSelectionOctree=function(t,i){void 0===t&&(t=64),void 0===i&&(i=2),this._selectionOctree||(this._selectionOctree=new e.Octree(e.Octree.CreationFuncForMeshes,t,i));var n=this.getWorldExtends();return this._selectionOctree.update(n.min,n.max,this.meshes),this._selectionOctree},n.prototype.createPickingRay=function(t,i,n,r,o){void 0===o&&(o=!1);var s=this._engine;if(!r){if(!this.activeCamera)throw new Error("Active camera not set");r=this.activeCamera}var a=r.viewport,h=a.toGlobal(s.getRenderWidth(),s.getRenderHeight());return t=t/this._engine.getHardwareScalingLevel()-h.x,i=i/this._engine.getHardwareScalingLevel()-(this._engine.getRenderHeight()-h.y-h.height),e.Ray.CreateNew(t,i,h.width,h.height,n?n:e.Matrix.Identity(),o?e.Matrix.Identity():r.getViewMatrix(),r.getProjectionMatrix())},n.prototype.createPickingRayInCameraSpace=function(t,i,n){var r=this._engine;if(!n){if(!this.activeCamera)throw new Error("Active camera not set");n=this.activeCamera}var o=n.viewport,s=o.toGlobal(r.getRenderWidth(),r.getRenderHeight()),a=e.Matrix.Identity();return t=t/this._engine.getHardwareScalingLevel()-s.x,i=i/this._engine.getHardwareScalingLevel()-(this._engine.getRenderHeight()-s.y-s.height),e.Ray.CreateNew(t,i,s.width,s.height,a,a,n.getProjectionMatrix())},n.prototype._internalPick=function(t,i,n){for(var r=null,o=0;o<this.meshes.length;o++){var s=this.meshes[o];if(i){if(!i(s))continue}else if(!s.isEnabled()||!s.isVisible||!s.isPickable)continue;var a=s.getWorldMatrix(),h=t(a),c=s.intersects(h,n);if(c&&c.hit&&(n||null==r||!(c.distance>=r.distance))&&(r=c,n))break}return r||new e.PickingInfo},n.prototype._internalPickSprites=function(t,i,n,r){var o=null;if(r=r||this.activeCamera,this.spriteManagers.length>0)for(var s=0;s<this.spriteManagers.length;s++){var a=this.spriteManagers[s];if(a.isPickable){var h=a.intersects(t,r,i,n);if(h&&h.hit&&(n||null==o||!(h.distance>=o.distance))&&(o=h,n))break}}return o||new e.PickingInfo},n.prototype.pick=function(e,t,i,n,r){var o=this;return this._internalPick(function(i){return o.createPickingRay(e,t,i,r)},i,n)},n.prototype.pickSprite=function(e,t,i,n,r){return this._internalPickSprites(this.createPickingRayInCameraSpace(e,t,r),i,n,r)},n.prototype.pickWithRay=function(t,i,n){var r=this;return this._internalPick(function(i){return r._pickWithRayInverseMatrix||(r._pickWithRayInverseMatrix=e.Matrix.Identity()),i.invertToRef(r._pickWithRayInverseMatrix),e.Ray.Transform(t,r._pickWithRayInverseMatrix)},i,n)},n.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)))},n.prototype.getPointerOverMesh=function(){return this._pointerOverMesh},n.prototype.setPointerOverSprite=function(t){this._pointerOverSprite!==t&&(this._pointerOverSprite&&this._pointerOverSprite.actionManager&&this._pointerOverSprite.actionManager.processTrigger(e.ActionManager.OnPointerOutTrigger,e.ActionEvent.CreateNewFromSprite(this._pointerOverSprite,this)),this._pointerOverSprite=t,this._pointerOverSprite&&this._pointerOverSprite.actionManager&&this._pointerOverSprite.actionManager.processTrigger(e.ActionManager.OnPointerOverTrigger,e.ActionEvent.CreateNewFromSprite(this._pointerOverSprite,this)))},n.prototype.getPointerOverSprite=function(){return this._pointerOverSprite},n.prototype.getPhysicsEngine=function(){return this._physicsEngine},n.prototype.enablePhysics=function(t,i){if(this._physicsEngine)return!0;try{return this._physicsEngine=new e.PhysicsEngine(t,i),!0}catch(n){return e.Tools.Error(n.message),!1}},n.prototype.disablePhysicsEngine=function(){this._physicsEngine&&(this._physicsEngine.dispose(),this._physicsEngine=void 0)},n.prototype.isPhysicsEnabled=function(){return void 0!==this._physicsEngine},n.prototype.setGravity=function(t){e.Tools.Warn("Deprecated, please use 'scene.getPhysicsEngine().setGravity()'"),this._physicsEngine&&this._physicsEngine.setGravity(t)},n.prototype.createCompoundImpostor=function(t,i){e.Tools.Warn("Scene.createCompoundImpostor is deprecated. Please use PhysicsImpostor parent/child"),t.parts&&(i=t,t=t.parts);var n=t[0].mesh;n.physicsImpostor=new e.PhysicsImpostor(n,t[0].impostor,i,this);for(var r=1;r<t.length;r++){var o=t[r].mesh;o.parent!==n&&(o.position=o.position.subtract(n.position),o.parent=n),o.physicsImpostor=new e.PhysicsImpostor(o,t[r].impostor,i,this)}n.physicsImpostor.forceUpdate()},n.prototype.deleteCompoundImpostor=function(e){var t=e.parts[0].mesh;t.physicsImpostor.dispose(),t.physicsImpostor=null},n.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),i=this.getWorldExtends(),n=i.min.add(i.max.subtract(i.min).scale(.5));t.position=new e.Vector3(n.x,n.y,i.min.z-(i.max.z-i.min.z)),t.setTarget(n),this.activeCamera=t}},n.prototype._getByTags=function(t,i,n){if(void 0===i)return t;var r=[];n=n||function(e){};for(var o in t){var s=t[o];e.Tags.MatchesQuery(s,i)&&(r.push(s),n(s))}return r},n.prototype.getMeshesByTags=function(e,t){return this._getByTags(this.meshes,e,t)},n.prototype.getCamerasByTags=function(e,t){return this._getByTags(this.cameras,e,t)},n.prototype.getLightsByTags=function(e,t){return this._getByTags(this.lights,e,t)},n.prototype.getMaterialByTags=function(e,t){return this._getByTags(this.materials,e,t).concat(this._getByTags(this.multiMaterials,e,t))},n._FOGMODE_NONE=0,n._FOGMODE_EXP=1,n._FOGMODE_EXP2=2,n._FOGMODE_LINEAR=3,n.MinDeltaTime=1,n.MaxDeltaTime=1e3,n}();e.Scene=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(i,n,r,o,s,a){if(i instanceof e.Mesh?this._engine=i.getScene().getEngine():this._engine=i,this._updatable=o,this._data=n,s||this.create(),this._kind=r,a)return void(this._strideSize=a);switch(r){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 i(e,i){t.call(this,e,i.getScene()),i.instances.push(this),this._sourceMesh=i,this.position.copyFrom(i.position),this.rotation.copyFrom(i.rotation),this.scaling.copyFrom(i.scaling),i.rotationQuaternion&&(this.rotationQuaternion=i.rotationQuaternion.clone()),this.infiniteDistance=i.infiniteDistance,this.setPivotMatrix(i.getPivotMatrix()),this.refreshBoundingInfo(),this._syncSubMeshes()}return __extends(i,t),Object.defineProperty(i.prototype,"receiveShadows",{get:function(){return this._sourceMesh.receiveShadows},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"material",{get:function(){return this._sourceMesh.material},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"visibility",{get:function(){return this._sourceMesh.visibility},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"skeleton",{get:function(){return this._sourceMesh.skeleton},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"renderingGroupId",{get:function(){return this._sourceMesh.renderingGroupId},enumerable:!0,configurable:!0}),i.prototype.getTotalVertices=function(){return this._sourceMesh.getTotalVertices()},Object.defineProperty(i.prototype,"sourceMesh",{get:function(){return this._sourceMesh},enumerable:!0,configurable:!0}),i.prototype.getVerticesData=function(e,t){return this._sourceMesh.getVerticesData(e,t)},i.prototype.isVerticesDataPresent=function(e){return this._sourceMesh.isVerticesDataPresent(e)},i.prototype.getIndices=function(){return this._sourceMesh.getIndices()},Object.defineProperty(i.prototype,"_positions",{get:function(){return this._sourceMesh._positions},enumerable:!0,configurable:!0}),i.prototype.refreshBoundingInfo=function(){var t=this._sourceMesh.getBoundingInfo();this._boundingInfo=new e.BoundingInfo(t.minimum.clone(),t.maximum.clone()),this._updateBoundingInfo()},i.prototype._preActivate=function(){this._currentLOD&&this._currentLOD._preActivate()},i.prototype._activate=function(e){this._currentLOD&&this._currentLOD._registerInstanceForRenderId(this,e)},i.prototype.getLOD=function(e){return this._currentLOD=this.sourceMesh.getLOD(this.getScene().activeCamera,this.getBoundingInfo().boundingSphere),this._currentLOD===this.sourceMesh?this:this._currentLOD},i.prototype._syncSubMeshes=function(){if(this.releaseSubMeshes(),this._sourceMesh.subMeshes)for(var e=0;e<this._sourceMesh.subMeshes.length;e++)this._sourceMesh.subMeshes[e].clone(this,this._sourceMesh)},i.prototype._generatePointsArray=function(){return this._sourceMesh._generatePointsArray()},i.prototype.clone=function(t,i,n){var r=this._sourceMesh.createInstance(t);if(e.Tools.DeepCopy(this,r,["name"],[]),this.refreshBoundingInfo(),i&&(r.parent=i),!n)for(var o=0;o<this.getScene().meshes.length;o++){var s=this.getScene().meshes[o];s.parent===this&&s.clone(s.name,r)}return r.computeWorldMatrix(!0),r},i.prototype.dispose=function(e){var i=this._sourceMesh.instances.indexOf(this);this._sourceMesh.instances.splice(i,1),t.prototype.dispose.call(this,e)},i}(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 i=function(i){function n(r,o,s,a,h,c){if(void 0===s&&(s=null),void 0===c&&(c=!0),i.call(this,r,o),this.onBeforeRenderObservable=new e.Observable,this.onAfterRenderObservable=new e.Observable,this.onBeforeDrawObservable=new e.Observable,this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this.instances=new Array,this._LODLevels=new Array,this._visibleInstances={},this._renderIdForInstances=new Array,this._batchCache=new t,this._instancesBufferSize=2048,this._sideOrientation=n._DEFAULTSIDE,this._areNormalsFrozen=!1,a){a._geometry&&a._geometry.applyToMesh(this),e.Tools.DeepCopy(a,this,["name","material","skeleton","instances"],["_poseMatrix"]),this.setPivotMatrix(a.getPivotMatrix()),this.id=r+"."+a.id,this.material=a.material;var l;if(!h)for(l=0;l<o.meshes.length;l++){var u=o.meshes[l];if(u.parent===a){u.clone(r+"."+u.name,this,h)}}var d=this.getScene().getPhysicsEngine();if(c&&d){var f=d.getImpostorForPhysicsObject(a);f&&(this.physicsImpostor=f.clone(this))}for(l=0;l<o.particleSystems.length;l++){var p=o.particleSystems[l];p.emitter===a&&p.clone(p.name,this)}this.computeWorldMatrix(!0)}null!==s&&(this.parent=s)}return __extends(n,i),Object.defineProperty(n,"FRONTSIDE",{get:function(){return n._FRONTSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"BACKSIDE",{get:function(){return n._BACKSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"DOUBLESIDE",{get:function(){return n._DOUBLESIDE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"DEFAULTSIDE",{get:function(){return n._DEFAULTSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"NO_CAP",{get:function(){return n._NO_CAP},enumerable:!0,configurable:!0}),Object.defineProperty(n,"CAP_START",{get:function(){return n._CAP_START},enumerable:!0,configurable:!0}),Object.defineProperty(n,"CAP_END",{get:function(){return n._CAP_END},enumerable:!0,configurable:!0}),Object.defineProperty(n,"CAP_ALL",{get:function(){return n._CAP_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onBeforeDraw",{set:function(e){this._onBeforeDrawObserver&&this.onBeforeDrawObservable.remove(this._onBeforeDrawObserver),this._onBeforeDrawObserver=this.onBeforeDrawObservable.add(e)},enumerable:!0,configurable:!0}),n.prototype.toString=function(t){var n=i.prototype.toString.call(this,t);if(n+=", n vertices: "+this.getTotalVertices(),n+=", parent: "+(this._waitingParentId?this._waitingParentId:this.parent?this.parent.name:"NONE"),this.animations)for(var r=0;r<this.animations.length;r++)n+=", animation[0]: "+this.animations[r].toString(t);return t&&(n+=", flat shading: "+(this._geometry?this.getVerticesData(e.VertexBuffer.PositionKind).length/3===this.getIndices().length?"YES":"NO":"UNKNOWN")),n},Object.defineProperty(n.prototype,"hasLODLevels",{get:function(){return this._LODLevels.length>0},enumerable:!0,configurable:!0}),n.prototype._sortLODLevels=function(){this._LODLevels.sort(function(e,t){return e.distance<t.distance?1:e.distance>t.distance?-1:0})},n.prototype.addLODLevel=function(t,i){if(i&&i._masterMesh)return e.Tools.Warn("You cannot use a mesh as LOD level twice"),this;var n=new e.Internals.MeshLODLevel(t,i);return this._LODLevels.push(n),i&&(i._masterMesh=this),this._sortLODLevels(),this},n.prototype.getLODLevelAtDistance=function(e){for(var t=0;t<this._LODLevels.length;t++){var i=this._LODLevels[t];if(i.distance===e)return i.mesh}return null},n.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},n.prototype.getLOD=function(e,t){if(!this._LODLevels||0===this._LODLevels.length)return this;var i=(t?t:this.getBoundingInfo().boundingSphere).centerWorld.subtract(e.globalPosition).length();if(this._LODLevels[this._LODLevels.length-1].distance>i)return this.onLODLevelSelection&&this.onLODLevelSelection(i,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var n=0;n<this._LODLevels.length;n++){var r=this._LODLevels[n];if(r.distance<i)return r.mesh&&(r.mesh._preActivate(),r.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)),this.onLODLevelSelection&&this.onLODLevelSelection(i,this,r.mesh),r.mesh}return this.onLODLevelSelection&&this.onLODLevelSelection(i,this,this),this},Object.defineProperty(n.prototype,"geometry",{get:function(){return this._geometry},enumerable:!0,configurable:!0}),n.prototype.getTotalVertices=function(){return this._geometry?this._geometry.getTotalVertices():0},n.prototype.getVerticesData=function(e,t){return this._geometry?this._geometry.getVerticesData(e,t):null},n.prototype.getVertexBuffer=function(e){return this._geometry?this._geometry.getVertexBuffer(e):void 0},n.prototype.isVerticesDataPresent=function(e){return this._geometry?this._geometry.isVerticesDataPresent(e):this._delayInfo?-1!==this._delayInfo.indexOf(e):!1},n.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()},n.prototype.getTotalIndices=function(){return this._geometry?this._geometry.getTotalIndices():0},n.prototype.getIndices=function(e){return this._geometry?this._geometry.getIndices(e):[]},Object.defineProperty(n.prototype,"isBlocked",{get:function(){return null!==this._masterMesh&&void 0!==this._masterMesh},enumerable:!0,configurable:!0}),n.prototype.isReady=function(){return this.delayLoadState===e.Engine.DELAYLOADSTATE_LOADING?!1:i.prototype.isReady.call(this)},n.prototype.isDisposed=function(){return this._isDisposed},Object.defineProperty(n.prototype,"sideOrientation",{get:function(){return this._sideOrientation},set:function(e){this._sideOrientation=e},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"areNormalsFrozen",{get:function(){return this._areNormalsFrozen},enumerable:!0,configurable:!0}),n.prototype.freezeNormals=function(){this._areNormalsFrozen=!0},n.prototype.unfreezeNormals=function(){this._areNormalsFrozen=!1},n.prototype._preActivate=function(){var e=this.getScene().getRenderId();this._preActivateId!==e&&(this._preActivateId=e,this._visibleInstances=null)},n.prototype._preActivateForIntermediateRendering=function(e){this._visibleInstances&&(this._visibleInstances.intermediateDefaultRenderId=e)},n.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)},n.prototype.refreshBoundingInfo=function(){if(!this._boundingInfo.isLocked){var t=this.getVerticesData(e.VertexBuffer.PositionKind);if(t){var i=e.Tools.ExtractMinAndMax(t,0,this.getTotalVertices());this._boundingInfo=new e.BoundingInfo(i.minimum,i.maximum)}if(this.subMeshes)for(var n=0;n<this.subMeshes.length;n++)this.subMeshes[n].refreshBoundingInfo();this._updateBoundingInfo()}},n.prototype._createGlobalSubMesh=function(){var t=this.getTotalVertices();return t&&this.getIndices()?(this.releaseSubMeshes(),new e.SubMesh(0,0,t,0,this.getTotalIndices(),this)):null},n.prototype.subdivide=function(t){if(!(1>t)){for(var i=this.getTotalIndices(),n=i/t|0,r=0;n%3!==0;)n++;this.releaseSubMeshes();for(var o=0;t>o&&!(r>=i);o++)e.SubMesh.CreateFromIndices(0,r,Math.min(n,i-r),this),r+=n;this.synchronizeInstances()}},n.prototype.setVerticesData=function(t,i,n,r){if(this._geometry)this._geometry.setVerticesData(t,i,n,r);else{var o=new e.VertexData;o.set(i,t);var s=this.getScene();new e.Geometry(e.Geometry.RandomId(),s,o,n,this)}},n.prototype.updateVerticesData=function(e,t,i,n){this._geometry&&(n?(this.makeGeometryUnique(),this.updateVerticesData(e,t,i,!1)):this._geometry.updateVerticesData(e,t,i))},n.prototype.updateVerticesDataDirectly=function(t,i,n,r){e.Tools.Warn("Mesh.updateVerticesDataDirectly deprecated since 2.3."),this._geometry&&(r?(this.makeGeometryUnique(),this.updateVerticesDataDirectly(t,i,n,!1)):this._geometry.updateVerticesDataDirectly(t,i,n))},n.prototype.updateMeshPositions=function(t,i){void 0===i&&(i=!0);var n=this.getVerticesData(e.VertexBuffer.PositionKind);if(t(n),this.updateVerticesData(e.VertexBuffer.PositionKind,n,!1,!1),i){var r=this.getIndices(),o=this.getVerticesData(e.VertexBuffer.NormalKind);e.VertexData.ComputeNormals(n,r,o),this.updateVerticesData(e.VertexBuffer.NormalKind,o,!1,!1)}},n.prototype.makeGeometryUnique=function(){if(this._geometry){var t=this._geometry.copy(e.Geometry.RandomId());t.applyToMesh(this)}},n.prototype.setIndices=function(t,i){if(this._geometry)this._geometry.setIndices(t,i);else{var n=new e.VertexData;n.indices=t;var r=this.getScene();new e.Geometry(e.Geometry.RandomId(),r,n,!1,this)}},n.prototype._bind=function(t,i,n){var r,o=this.getScene().getEngine();if(this._unIndexed)r=null;else switch(n){case e.Material.PointFillMode:r=null;break;case e.Material.WireFrameFillMode:r=t.getLinesIndexBuffer(this.getIndices(),o);break;default:case e.Material.TriangleFillMode:r=this._unIndexed?null:this._geometry.getIndexBuffer()}o.bindMultiBuffers(this._geometry.getVertexBuffers(),r,i)},n.prototype._draw=function(t,i,n){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){this.onBeforeDrawObservable.notifyObservers(this);var r=this.getScene().getEngine();switch(i){case e.Material.PointFillMode:r.drawPointClouds(t.verticesStart,t.verticesCount,n);break;case e.Material.WireFrameFillMode:this._unIndexed?r.drawUnIndexed(!1,t.verticesStart,t.verticesCount,n):r.draw(!1,0,t.linesIndexCount,n);break;default:this._unIndexed?r.drawUnIndexed(!0,t.verticesStart,t.verticesCount,n):r.draw(!0,t.indexStart,t.indexCount,n)}}},n.prototype.registerBeforeRender=function(e){this.onBeforeRenderObservable.add(e)},n.prototype.unregisterBeforeRender=function(e){this.onBeforeRenderObservable.removeCallback(e)},n.prototype.registerAfterRender=function(e){this.onAfterRenderObservable.add(e)},n.prototype.unregisterAfterRender=function(e){this.onAfterRenderObservable.removeCallback(e)},n.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 i=t.getRenderId(),n=t._isInIntermediateRendering()?this._visibleInstances.intermediateDefaultRenderId:this._visibleInstances.defaultRenderId;this._batchCache.visibleInstances[e]=this._visibleInstances[i];var r=this._renderId;if(!this._batchCache.visibleInstances[e]&&n&&(this._batchCache.visibleInstances[e]=this._visibleInstances[n],i=Math.max(n,i),r=Math.max(this._visibleInstances.selfDefaultRenderId,i)),this._batchCache.visibleInstances[e]&&this._batchCache.visibleInstances[e].length){if(this._renderIdForInstances[e]===i)return this._batchCache.mustReturn=!0,this._batchCache;i!==r&&(this._batchCache.renderSelf[e]=!1)}this._renderIdForInstances[e]=i}return this._batchCache},n.prototype._renderWithInstances=function(e,t,i,n,r){for(var o=i.visibleInstances[e._id],s=o.length+1,a=16*s*4;this._instancesBufferSize<a;)this._instancesBufferSize*=2;(!this._worldMatricesInstancesBuffer||this._worldMatricesInstancesBuffer.capacity<this._instancesBufferSize)&&(this._worldMatricesInstancesBuffer&&r.deleteInstancesBuffer(this._worldMatricesInstancesBuffer),this._worldMatricesInstancesBuffer=r.createInstancesBuffer(this._instancesBufferSize),this._worldMatricesInstancesArray=new Float32Array(this._instancesBufferSize/4));var h=0,c=0,l=this.getWorldMatrix();if(i.renderSelf[e._id]&&(l.copyToArray(this._worldMatricesInstancesArray,h),h+=16,c++),o)for(var u=0;u<o.length;u++){var d=o[u];d.getWorldMatrix().copyToArray(this._worldMatricesInstancesArray,h),h+=16,c++}var f=n.getAttributeLocationByName("world0"),p=n.getAttributeLocationByName("world1"),m=n.getAttributeLocationByName("world2"),_=n.getAttributeLocationByName("world3"),g=[f,p,m,_];r.updateAndBindInstancesBuffer(this._worldMatricesInstancesBuffer,this._worldMatricesInstancesArray,g),this._draw(e,t,c),r.unBindInstancesBuffer(this._worldMatricesInstancesBuffer,g)},n.prototype._processRendering=function(e,t,i,n,r,o){var s=this.getScene(),a=s.getEngine();if(r)this._renderWithInstances(e,i,n,t,a);else if(n.renderSelf[e._id]&&(o&&o(!1,this.getWorldMatrix()),this._draw(e,i)),n.visibleInstances[e._id])for(var h=0;h<n.visibleInstances[e._id].length;h++){var c=n.visibleInstances[e._id][h],l=c.getWorldMatrix();o&&o(!0,l),this._draw(e,i)}},n.prototype.render=function(t,i){var n=this.getScene(),r=this._getInstancesRenderList(t._id);if(!r.mustReturn&&this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){this.onBeforeRenderObservable.notifyObservers(this);var o=n.getEngine(),s=null!==o.getCaps().instancedArrays&&null!==r.visibleInstances[t._id]&&void 0!==r.visibleInstances[t._id],a=t.getMaterial();if(a&&a.isReady(this,s)){var h=o.getDepthWrite();this.renderOutline&&(o.setDepthWrite(!1),n.getOutlineRenderer().render(t,r),o.setDepthWrite(h)),a._preBind();var c=a.getEffect(),l=n.forcePointsCloud?e.Material.PointFillMode:n.forceWireframe?e.Material.WireFrameFillMode:a.fillMode;this._bind(t,c,l);var u=this.getWorldMatrix();if(a.bind(u,this),i&&o.setAlphaMode(a.alphaMode),this._processRendering(t,c,l,r,s,function(e,t){e&&a.bindOnlyWorldMatrix(t)}),a.unbind(),this.renderOutline&&h&&(o.setDepthWrite(!0),o.setColorWrite(!1),n.getOutlineRenderer().render(t,r),o.setColorWrite(!0)),this.renderOverlay){var d=o.getAlphaMode();o.setAlphaMode(e.Engine.ALPHA_COMBINE),n.getOutlineRenderer().render(t,r,!0),o.setAlphaMode(d)}this.onAfterRenderObservable.notifyObservers(this)}}},n.prototype.getEmittedParticleSystems=function(){for(var e=new Array,t=0;t<this.getScene().particleSystems.length;t++){var i=this.getScene().particleSystems[t];i.emitter===this&&e.push(i)}return e;
  12. },n.prototype.getHierarchyEmittedParticleSystems=function(){var e=new Array,t=this.getDescendants();t.push(this);for(var i=0;i<this.getScene().particleSystems.length;i++){var n=this.getScene().particleSystems[i];-1!==t.indexOf(n.emitter)&&e.push(n)}return e},n.prototype._checkDelayState=function(){var t=this,i=this,n=this.getScene();if(this._geometry)this._geometry.load(n);else if(i.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED){i.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,n._addPendingData(i);var r=-1!==this.delayLoadingFile.indexOf(".babylonbinarymeshdata");e.Tools.LoadFile(this.delayLoadingFile,function(i){i instanceof ArrayBuffer?t._delayLoadingFunction(i,t):t._delayLoadingFunction(JSON.parse(i),t),t.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,n._removePendingData(t)},function(){},n.database,r)}},n.prototype.isInFrustum=function(t){return this.delayLoadState===e.Engine.DELAYLOADSTATE_LOADING?!1:i.prototype.isInFrustum.call(this,t)?(this._checkDelayState(),!0):!1},n.prototype.setMaterialByID=function(e){var t,i=this.getScene().materials;for(t=0;t<i.length;t++)if(i[t].id===e)return void(this.material=i[t]);var n=this.getScene().multiMaterials;for(t=0;t<n.length;t++)if(n[t].id===e)return void(this.material=n[t])},n.prototype.getAnimatables=function(){var e=[];return this.material&&e.push(this.material),this.skeleton&&e.push(this.skeleton),e},n.prototype.bakeTransformIntoVertices=function(t){if(this.isVerticesDataPresent(e.VertexBuffer.PositionKind)){this._resetPointsArrayCache();var i,n=this.getVerticesData(e.VertexBuffer.PositionKind),r=[];for(i=0;i<n.length;i+=3)e.Vector3.TransformCoordinates(e.Vector3.FromArray(n,i),t).toArray(r,i);if(this.setVerticesData(e.VertexBuffer.PositionKind,r,this.getVertexBuffer(e.VertexBuffer.PositionKind).isUpdatable()),this.isVerticesDataPresent(e.VertexBuffer.NormalKind)){for(n=this.getVerticesData(e.VertexBuffer.NormalKind),r=[],i=0;i<n.length;i+=3)e.Vector3.TransformNormal(e.Vector3.FromArray(n,i),t).normalize().toArray(r,i);this.setVerticesData(e.VertexBuffer.NormalKind,r,this.getVertexBuffer(e.VertexBuffer.NormalKind).isUpdatable()),t.m[0]*t.m[5]*t.m[10]<0&&this.flipFaces()}}},n.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()},n.prototype._resetPointsArrayCache=function(){this._positions=null},n.prototype._generatePointsArray=function(){if(this._positions)return!0;this._positions=[];var t=this.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return!1;for(var i=0;i<t.length;i+=3)this._positions.push(e.Vector3.FromArray(t,i));return!0},n.prototype.clone=function(e,t,i,r){return void 0===r&&(r=!0),new n(e,this.getScene(),t,this,i,r)},n.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();i.prototype.dispose.call(this,e)},n.prototype.applyDisplacementMap=function(t,i,n,r){var o=this,s=this.getScene(),a=function(e){var t=document.createElement("canvas"),s=t.getContext("2d"),a=e.width,h=e.height;t.width=a,t.height=h,s.drawImage(e,0,0);var c=s.getImageData(0,0,a,h).data;o.applyDisplacementMapFromBuffer(c,a,h,i,n),r&&r(o)};e.Tools.LoadImage(t,a,function(){},s.database)},n.prototype.applyDisplacementMapFromBuffer=function(t,i,n,r,o){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 s=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(),d=0;d<s.length;d+=3){e.Vector3.FromArrayToRef(s,d,c),e.Vector3.FromArrayToRef(a,d,l),e.Vector2.FromArrayToRef(h,d/3*2,u);var f=Math.abs(u.x)*i%i|0,p=Math.abs(u.y)*n%n|0,m=4*(f+p*i),_=t[m]/255,g=t[m+1]/255,v=t[m+2]/255,y=.3*_+.59*g+.11*v;l.normalize(),l.scaleInPlace(r+(o-r)*y),c=c.add(l),c.toArray(s,d)}e.VertexData.ComputeNormals(s,this.getIndices(),a),this.updateVerticesData(e.VertexBuffer.PositionKind,s),this.updateVerticesData(e.VertexBuffer.NormalKind,a)},n.prototype.convertToFlatShadedMesh=function(){var t,i,n=this.getVerticesDataKinds(),r=[],o=[],s=[],a=!1;for(t=0;t<n.length;t++){i=n[t];var h=this.getVertexBuffer(i);i!==e.VertexBuffer.NormalKind?(r[i]=h,o[i]=r[i].getData(),s[i]=[]):(a=h.isUpdatable(),n.splice(t,1),t--)}var c,l=this.subMeshes.slice(0),u=this.getIndices(),d=this.getTotalIndices();for(c=0;d>c;c++){var f=u[c];for(t=0;t<n.length;t++){i=n[t];for(var p=r[i].getStrideSize(),m=0;p>m;m++)s[i].push(o[i][f*p+m])}}var _=[],g=s[e.VertexBuffer.PositionKind];for(c=0;d>c;c+=3){u[c]=c,u[c+1]=c+1,u[c+2]=c+2;for(var v=e.Vector3.FromArray(g,3*c),y=e.Vector3.FromArray(g,3*(c+1)),x=e.Vector3.FromArray(g,3*(c+2)),b=v.subtract(y),E=x.subtract(y),A=e.Vector3.Normalize(e.Vector3.Cross(b,E)),T=0;3>T;T++)_.push(A.x),_.push(A.y),_.push(A.z)}for(this.setIndices(u),this.setVerticesData(e.VertexBuffer.NormalKind,_,a),t=0;t<n.length;t++)i=n[t],this.setVerticesData(i,s[i],r[i].isUpdatable());this.releaseSubMeshes();for(var P=0;P<l.length;P++){var M=l[P];new e.SubMesh(M.materialIndex,M.indexStart,M.indexCount,M.indexStart,M.indexCount,this)}this.synchronizeInstances()},n.prototype.convertToUnIndexedMesh=function(){var t,i,n=this.getVerticesDataKinds(),r=[],o=[],s=[];for(t=0;t<n.length;t++){i=n[t];var a=this.getVertexBuffer(i);r[i]=a,o[i]=r[i].getData(),s[i]=[]}var h,c=this.subMeshes.slice(0),l=this.getIndices(),u=this.getTotalIndices();for(h=0;u>h;h++){var d=l[h];for(t=0;t<n.length;t++){i=n[t];for(var f=r[i].getStrideSize(),p=0;f>p;p++)s[i].push(o[i][d*f+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<n.length;t++)i=n[t],this.setVerticesData(i,s[i],r[i].isUpdatable());this.releaseSubMeshes();for(var m=0;m<c.length;m++){var _=c[m];new e.SubMesh(_.materialIndex,_.indexStart,_.indexCount,_.indexStart,_.indexCount,this)}this._unIndexed=!0,this.synchronizeInstances()},n.prototype.flipFaces=function(t){void 0===t&&(t=!1);var i,n=e.VertexData.ExtractFromMesh(this);if(t&&this.isVerticesDataPresent(e.VertexBuffer.NormalKind))for(i=0;i<n.normals.length;i++)n.normals[i]*=-1;var r;for(i=0;i<n.indices.length;i+=3)r=n.indices[i+1],n.indices[i+1]=n.indices[i+2],n.indices[i+2]=r;n.applyToMesh(this)},n.prototype.createInstance=function(t){return new e.InstancedMesh(t,this)},n.prototype.synchronizeInstances=function(){for(var e=0;e<this.instances.length;e++){var t=this.instances[e];t._syncSubMeshes()}},n.prototype.simplify=function(t,i,n,r){void 0===i&&(i=!0),void 0===n&&(n=e.SimplificationType.QUADRATIC),this.getScene().simplificationQueue.addTask({settings:t,parallelProcessing:i,mesh:this,simplificationType:n,successCallback:r})},n.prototype.optimizeIndices=function(t){for(var i=this,n=this.getIndices(),r=this.getVerticesData(e.VertexBuffer.PositionKind),o=[],s=0;s<r.length;s+=3)o.push(e.Vector3.FromArray(r,s));var a=[];e.AsyncLoop.SyncAsyncForLoop(o.length,40,function(e){for(var t=o.length-1-e,i=o[t],n=0;t>n;++n){var r=o[n];if(i.equals(r)){a[t]=n;break}}},function(){for(var e=0;e<n.length;++e)n[e]=a[n[e]]||n[e];var r=i.subMeshes.slice(0);i.setIndices(n),i.subMeshes=r,t&&t(i)})},n.Parse=function(t,i,r){var o=new n(t.name,i);if(o.id=t.id,e.Tags.AddTagsTo(o,t.tags),o.position=e.Vector3.FromArray(t.position),t.rotationQuaternion?o.rotationQuaternion=e.Quaternion.FromArray(t.rotationQuaternion):t.rotation&&(o.rotation=e.Vector3.FromArray(t.rotation)),o.scaling=e.Vector3.FromArray(t.scaling),t.localMatrix?o.setPivotMatrix(e.Matrix.FromArray(t.localMatrix)):t.pivotMatrix&&o.setPivotMatrix(e.Matrix.FromArray(t.pivotMatrix)),o.setEnabled(t.isEnabled),o.isVisible=t.isVisible,o.infiniteDistance=t.infiniteDistance,o.showBoundingBox=t.showBoundingBox,o.showSubMeshesBoundingBox=t.showSubMeshesBoundingBox,void 0!==t.applyFog&&(o.applyFog=t.applyFog),void 0!==t.pickable&&(o.isPickable=t.pickable),void 0!==t.alphaIndex&&(o.alphaIndex=t.alphaIndex),o.receiveShadows=t.receiveShadows,o.billboardMode=t.billboardMode,void 0!==t.visibility&&(o.visibility=t.visibility),o.checkCollisions=t.checkCollisions,o._shouldGenerateFlatShading=t.useFlatShading,t.freezeWorldMatrix&&(o._waitingFreezeWorldMatrix=t.freezeWorldMatrix),t.parentId&&(o._waitingParentId=t.parentId),void 0!==t.actions&&(o._waitingActions=t.actions),o.hasVertexAlpha=t.hasVertexAlpha,t.delayLoadingFile?(o.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,o.delayLoadingFile=r+t.delayLoadingFile,o._boundingInfo=new e.BoundingInfo(e.Vector3.FromArray(t.boundingBoxMinimum),e.Vector3.FromArray(t.boundingBoxMaximum)),t._binaryInfo&&(o._binaryInfo=t._binaryInfo),o._delayInfo=[],t.hasUVs&&o._delayInfo.push(e.VertexBuffer.UVKind),t.hasUVs2&&o._delayInfo.push(e.VertexBuffer.UV2Kind),t.hasUVs3&&o._delayInfo.push(e.VertexBuffer.UV3Kind),t.hasUVs4&&o._delayInfo.push(e.VertexBuffer.UV4Kind),t.hasUVs5&&o._delayInfo.push(e.VertexBuffer.UV5Kind),t.hasUVs6&&o._delayInfo.push(e.VertexBuffer.UV6Kind),t.hasColors&&o._delayInfo.push(e.VertexBuffer.ColorKind),t.hasMatricesIndices&&o._delayInfo.push(e.VertexBuffer.MatricesIndicesKind),t.hasMatricesWeights&&o._delayInfo.push(e.VertexBuffer.MatricesWeightsKind),o._delayLoadingFunction=e.Geometry.ImportGeometry,e.SceneLoader.ForceFullSceneLoadingForIncremental&&o._checkDelayState()):e.Geometry.ImportGeometry(t,o),t.materialId?o.setMaterialByID(t.materialId):o.material=null,t.skeletonId>-1&&(o.skeleton=i.getLastSkeletonByID(t.skeletonId),t.numBoneInfluencers&&(o.numBoneInfluencers=t.numBoneInfluencers)),t.animations){for(var s=0;s<t.animations.length;s++){var a=t.animations[s];o.animations.push(e.Animation.Parse(a))}e.Node.ParseAnimationRanges(o,t,i)}if(t.autoAnimate&&i.beginAnimation(o,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,t.autoAnimateSpeed||1),t.layerMask&&!isNaN(t.layerMask)?o.layerMask=Math.abs(parseInt(t.layerMask)):o.layerMask=268435455,t.physicsImpostor&&(o.physicsImpostor=new e.PhysicsImpostor(o,t.physicsImpostor,{mass:t.physicsMass,friction:t.physicsFriction,restitution:t.physicsRestitution},i)),t.instances)for(var h=0;h<t.instances.length;h++){var c=t.instances[h],l=o.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=o.checkCollisions,t.animations){for(s=0;s<t.animations.length;s++)a=t.animations[s],l.animations.push(e.Animation.Parse(a));e.Node.ParseAnimationRanges(l,t,i)}}return o},n.CreateRibbon=function(t,i,n,r,o,s,a,h,c){return e.MeshBuilder.CreateRibbon(t,{pathArray:i,closeArray:n,closePath:r,offset:o,updatable:a,sideOrientation:h,instance:c},s)},n.CreateDisc=function(t,i,n,r,o,s){var a={radius:i,tessellation:n,sideOrientation:s,updatable:o};return e.MeshBuilder.CreateDisc(t,a,r)},n.CreateBox=function(t,i,n,r,o){var s={size:i,sideOrientation:o,updatable:r};return e.MeshBuilder.CreateBox(t,s,n)},n.CreateSphere=function(t,i,n,r,o,s){var a={segments:i,diameterX:n,diameterY:n,diameterZ:n,sideOrientation:s,updatable:o};return e.MeshBuilder.CreateSphere(t,a,r)},n.CreateCylinder=function(t,i,r,o,s,a,h,c,l){void 0!==h&&h instanceof e.Scene||(void 0!==h&&(l=c||n.DEFAULTSIDE,c=h),h=a,a=1);var u={height:i,diameterTop:r,diameterBottom:o,tessellation:s,subdivisions:a,sideOrientation:l,updatable:c};return e.MeshBuilder.CreateCylinder(t,u,h)},n.CreateTorus=function(t,i,n,r,o,s,a){var h={diameter:i,thickness:n,tessellation:r,sideOrientation:a,updatable:s};return e.MeshBuilder.CreateTorus(t,h,o)},n.CreateTorusKnot=function(t,i,n,r,o,s,a,h,c,l){var u={radius:i,tube:n,radialSegments:r,tubularSegments:o,p:s,q:a,sideOrientation:l,updatable:c};return e.MeshBuilder.CreateTorusKnot(t,u,h)},n.CreateLines=function(t,i,n,r,o){var s={points:i,updatable:r,instance:o};return e.MeshBuilder.CreateLines(t,s,n)},n.CreateDashedLines=function(t,i,n,r,o,s,a,h){var c={points:i,dashSize:n,gapSize:r,dashNb:o,updatable:a};return e.MeshBuilder.CreateDashedLines(t,c,s)},n.ExtrudeShape=function(t,i,r,o,s,a,h,c,l,u){var d={shape:i,path:r,scale:o,rotation:s,cap:0===a?0:a||n.NO_CAP,sideOrientation:l,instance:u,updatable:c};return e.MeshBuilder.ExtrudeShape(t,d,h)},n.ExtrudeShapeCustom=function(t,i,r,o,s,a,h,c,l,u,d,f){var p={shape:i,path:r,scaleFunction:o,rotationFunction:s,ribbonCloseArray:a,ribbonClosePath:h,cap:0===c?0:c||n.NO_CAP,sideOrientation:d,instance:f,updatable:u};return e.MeshBuilder.ExtrudeShapeCustom(t,p,l)},n.CreateLathe=function(t,i,n,r,o,s,a){var h={shape:i,radius:n,tessellation:r,sideOrientation:a,updatable:s};return e.MeshBuilder.CreateLathe(t,h,o)},n.CreatePlane=function(t,i,n,r,o){var s={size:i,width:i,height:i,sideOrientation:o,updatable:r};return e.MeshBuilder.CreatePlane(t,s,n)},n.CreateGround=function(t,i,n,r,o,s){var a={width:i,height:n,subdivisions:r,updatable:s};return e.MeshBuilder.CreateGround(t,a,o)},n.CreateTiledGround=function(t,i,n,r,o,s,a,h,c){var l={xmin:i,zmin:n,xmax:r,zmax:o,subdivisions:s,precision:a,updatable:c};return e.MeshBuilder.CreateTiledGround(t,l,h)},n.CreateGroundFromHeightMap=function(t,i,n,r,o,s,a,h,c,l){var u={width:n,height:r,subdivisions:o,minHeight:s,maxHeight:a,updatable:c,onReady:l};return e.MeshBuilder.CreateGroundFromHeightMap(t,i,u,h)},n.CreateTube=function(t,i,n,r,o,s,a,h,c,l){var u={path:i,radius:n,tessellation:r,radiusFunction:o,arc:1,cap:s,updatable:h,sideOrientation:c,instance:l};return e.MeshBuilder.CreateTube(t,u,a)},n.CreatePolyhedron=function(t,i,n){return e.MeshBuilder.CreatePolyhedron(t,i,n)},n.CreateIcoSphere=function(t,i,n){return e.MeshBuilder.CreateIcoSphere(t,i,n)},n.CreateDecal=function(t,i,n,r,o,s){var a={position:n,normal:r,size:o,angle:s};return e.MeshBuilder.CreateDecal(t,i,a)},n.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},n.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},n.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 i=this.getVerticesData(e.VertexBuffer.PositionKind);i instanceof Float32Array||(i=new Float32Array(i));var n=this.getVerticesData(e.VertexBuffer.NormalKind);n instanceof Float32Array||(n=new Float32Array(n));for(var r,o=this.getVerticesData(e.VertexBuffer.MatricesIndicesKind),s=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(),d=new e.Matrix,f=new e.Matrix,p=0,m=0;m<i.length;m+=3,p+=4){var _;for(r=0;4>r&&(_=s[p+r],_>0);r++)e.Matrix.FromFloat32ArrayToRefScaled(l,16*o[p+r],_,f),d.addToSelf(f);if(a)for(r=0;4>r&&(_=c[p+r],_>0);r++)e.Matrix.FromFloat32ArrayToRefScaled(l,16*h[p+r],_,f),d.addToSelf(f);e.Vector3.TransformCoordinatesFromFloatsToRef(this._sourcePositions[m],this._sourcePositions[m+1],this._sourcePositions[m+2],d,u),u.toArray(i,m),e.Vector3.TransformNormalFromFloatsToRef(this._sourceNormals[m],this._sourceNormals[m+1],this._sourceNormals[m+2],d,u),u.toArray(n,m),d.reset()}return this.updateVerticesData(e.VertexBuffer.PositionKind,i),this.updateVerticesData(e.VertexBuffer.NormalKind,n),this}},n.MinMax=function(e){var t=null,i=null;for(var n in e){var r=e[n],o=r.getBoundingInfo().boundingBox;t?(t.MinimizeInPlace(o.minimumWorld),i.MaximizeInPlace(o.maximumWorld)):(t=o.minimumWorld,i=o.maximumWorld)}return{min:t,max:i}},n.Center=function(t){var i=void 0!==t.min?t:n.MinMax(t);return e.Vector3.Center(i.min,i.max)},n.MergeMeshes=function(t,i,r,o){void 0===i&&(i=!0);var s;if(!r){var a=0;for(s=0;s<t.length;s++)if(t[s]&&(a+=t[s].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(s=0;s<t.length;s++)t[s]&&(t[s].computeWorldMatrix(!0),c=e.VertexData.ExtractFromMesh(t[s],!0),c.transform(t[s].getWorldMatrix()),h?h.merge(c):(h=c,l=t[s]));if(o||(o=new n(l.name+"_merged",l.getScene())),h.applyToMesh(o),o.material=l.material,o.checkCollisions=l.checkCollisions,i)for(s=0;s<t.length;s++)t[s]&&t[s].dispose();return o},n._FRONTSIDE=0,n._BACKSIDE=1,n._DOUBLESIDE=2,n._DEFAULTSIDE=0,n._NO_CAP=0,n._CAP_START=1,n._CAP_END=2,n._CAP_ALL=3,n}(e.AbstractMesh);e.Mesh=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i,n,r,o,s,a){void 0===a&&(a=!0),this.materialIndex=e,this.verticesStart=t,this.verticesCount=i,this.indexStart=n,this.indexCount=r,this._renderId=0,this._mesh=o,this._renderingMesh=s||o,o.subMeshes.push(this),this._trianglePlanes=[],this._id=o.subMeshes.length-1,a&&(this.refreshBoundingInfo(),o.computeWorldMatrix(!0))}return 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 i=t;return i.getSubMaterial(this.materialIndex)}return t?t:this._mesh.getScene().defaultMaterial},t.prototype.refreshBoundingInfo=function(){if(this._lastColliderWorldVertices=null,!this.IsGlobal){var t=this._renderingMesh.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return void(this._boundingInfo=this._mesh._boundingInfo);var i,n=this._renderingMesh.getIndices();i=0===this.indexStart&&this.indexCount===n.length?{minimum:this._renderingMesh.getBoundingInfo().minimum.clone(),maximum:this._renderingMesh.getBoundingInfo().maximum.clone()}:e.Tools.ExtractMinAndMaxIndexed(t,n,this.indexStart,this.indexCount,this._renderingMesh.geometry.boundingBias),this._boundingInfo=new e.BoundingInfo(i.minimum,i.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 i=[],n=this.indexStart;n<this.indexStart+this.indexCount;n+=3)i.push(e[n],e[n+1],e[n+1],e[n+2],e[n+2],e[n]);this._linesIndexBuffer=t.createIndexBuffer(i),this.linesIndexCount=i.length}return this._linesIndexBuffer},t.prototype.canIntersects=function(e){return e.intersectsBox(this.getBoundingInfo().boundingBox)},t.prototype.intersects=function(t,i,n,r){var o=null;if(this._mesh instanceof e.LinesMesh)for(var s=this._mesh,a=this.indexStart;a<this.indexStart+this.indexCount;a+=2){var h=i[n[a]],c=i[n[a+1]],l=t.intersectionSegment(h,c,s.intersectionThreshold);if(!(0>l)&&(r||!o||l<o.distance)&&(o=new e.IntersectionInfo(null,null,l),r))break}else for(var a=this.indexStart;a<this.indexStart+this.indexCount;a+=3){var h=i[n[a]],c=i[n[a+1]],u=i[n[a+2]],d=t.intersectsTriangle(h,c,u);if(d){if(d.distance<0)continue;if((r||!o||d.distance<o.distance)&&(o=d,o.faceId=a/3,r))break}}return o},t.prototype.clone=function(i,n){var r=new t(this.materialIndex,this.verticesStart,this.verticesCount,this.indexStart,this.indexCount,i,n,!1);return this.IsGlobal||(r._boundingInfo=new e.BoundingInfo(this.getBoundingInfo().minimum,this.getBoundingInfo().maximum)),r},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,i,n,r,o){var s=Number.MAX_VALUE,a=-Number.MAX_VALUE;o=o||r;for(var h=o.getIndices(),c=i;i+n>c;c++){var l=h[c];s>l&&(s=l),l>a&&(a=l)}return new t(e,s,a-s+1,i,n,r,o)},t}();e.SubMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.CreateBox=function(t,i,n){var r=new e.Mesh(t,n),o=e.VertexData.CreateBox(i);return o.applyToMesh(r,i.updatable),r},t.CreateSphere=function(t,i,n){var r=new e.Mesh(t,n),o=e.VertexData.CreateSphere(i);return o.applyToMesh(r,i.updatable),r},t.CreateDisc=function(t,i,n){var r=new e.Mesh(t,n),o=e.VertexData.CreateDisc(i);return o.applyToMesh(r,i.updatable),r},t.CreateIcoSphere=function(t,i,n){var r=new e.Mesh(t,n),o=e.VertexData.CreateIcoSphere(i);return o.applyToMesh(r,i.updatable),r},t.CreateRibbon=function(t,i,n){var r=i.pathArray,o=i.closeArray,s=i.closePath,a=(i.offset,i.sideOrientation),h=i.instance,c=i.updatable;if(h){var l=function(t){for(var i=r[0].length,n=0,o=h.sideOrientation===e.Mesh.DOUBLESIDE?2:1,s=1;o>=s;s++)for(var a=0;a<r.length;a++){var c=r[a],l=c.length;i=l>i?i:l;for(var u=0;i>u;)t[n]=c[u].x,t[n+1]=c[u].y,t[n+2]=c[u].z,u++,n+=3;h._closePath&&(t[n]=c[0].x,t[n+1]=c[0].y,t[n+2]=c[0].z,n+=3)}},u=h.getVerticesData(e.VertexBuffer.PositionKind);if(l(u),h.updateVerticesData(e.VertexBuffer.PositionKind,u,!1,!1),!h.areNormalsFrozen){var d=h.getIndices(),f=h.getVerticesData(e.VertexBuffer.NormalKind);if(e.VertexData.ComputeNormals(u,d,f),h._closePath)for(var p=0,m=0,_=0;_<r.length;_++)p=3*h._idx[_],m=_+1<r.length?3*(h._idx[_+1]-1):f.length-3,f[p]=.5*(f[p]+f[m]),f[p+1]=.5*(f[p+1]+f[m+1]),f[p+2]=.5*(f[p+2]+f[m+2]),f[m]=f[p],f[m+1]=f[p+1],f[m+2]=f[p+2];h.updateVerticesData(e.VertexBuffer.NormalKind,f,!1,!1)}return h}var g=new e.Mesh(t,n);g.sideOrientation=a;var v=e.VertexData.CreateRibbon(i);return s&&(g._idx=v._idx),g._closePath=s,g._closeArray=o,v.applyToMesh(g,c),g},t.CreateCylinder=function(t,i,n){var r=new e.Mesh(t,n),o=e.VertexData.CreateCylinder(i);return o.applyToMesh(r,i.updatable),r},t.CreateTorus=function(t,i,n){var r=new e.Mesh(t,n),o=e.VertexData.CreateTorus(i);return o.applyToMesh(r,i.updatable),r},t.CreateTorusKnot=function(t,i,n){var r=new e.Mesh(t,n),o=e.VertexData.CreateTorusKnot(i);return o.applyToMesh(r,i.updatable),r},t.CreateLineSystem=function(t,i,n){var r=i.instance,o=i.lines;if(r){var s=function(e){for(var t=0,i=0;i<o.length;i++)for(var n=o[i],r=0;r<n.length;r++)e[t]=n[r].x,e[t+1]=n[r].y,e[t+2]=n[r].z,t+=3};return r.updateMeshPositions(s,!1),r}var a=new e.LinesMesh(t,n),h=e.VertexData.CreateLineSystem(i);return h.applyToMesh(a,i.updatable),a},t.CreateLines=function(e,i,n){var r=t.CreateLineSystem(e,{lines:[i.points],updatable:i.updatable,instance:i.instance},n);return r},t.CreateDashedLines=function(t,i,n){var r=i.points,o=i.instance,s=i.gapSize,a=(i.dashNb,i.dashSize);if(o){var h=function(t){var i=e.Vector3.Zero(),n=t.length/6,s=0,a=0,h=0,c=0,l=0,u=0,d=0,f=0;for(d=0;d<r.length-1;d++)r[d+1].subtractToRef(r[d],i),s+=i.length();for(h=s/n,c=o.dashSize*h/(o.dashSize+o.gapSize),d=0;d<r.length-1;d++)for(r[d+1].subtractToRef(r[d],i),a=Math.floor(i.length()/h),i.normalize(),f=0;a>f&&u<t.length;)l=h*f,t[u]=r[d].x+l*i.x,t[u+1]=r[d].y+l*i.y,t[u+2]=r[d].z+l*i.z,t[u+3]=r[d].x+(l+c)*i.x,t[u+4]=r[d].y+(l+c)*i.y,t[u+5]=r[d].z+(l+c)*i.z,u+=6,f++;for(;u<t.length;)t[u]=r[d].x,t[u+1]=r[d].y,t[u+2]=r[d].z,u+=3};return o.updateMeshPositions(h,!1),o}var c=new e.LinesMesh(t,n),l=e.VertexData.CreateDashedLines(i);return l.applyToMesh(c,i.updatable),c.dashSize=a,c.gapSize=s,c},t.ExtrudeShape=function(i,n,r){var o=n.path,s=n.shape,a=n.scale||1,h=n.rotation||0,c=0===n.cap?0:n.cap||e.Mesh.NO_CAP,l=n.updatable,u=0===n.sideOrientation?0:n.sideOrientation||e.Mesh.DEFAULTSIDE,d=n.instance;return t._ExtrudeShapeGeneric(i,s,o,a,h,null,null,!1,!1,c,!1,r,l,u,d)},t.ExtrudeShapeCustom=function(i,n,r){var o=n.path,s=n.shape,a=n.scaleFunction||function(){return 1},h=n.rotationFunction||function(){return 0},c=n.ribbonCloseArray||!1,l=n.ribbonClosePath||!1,u=0===n.cap?0:n.cap||e.Mesh.NO_CAP,d=n.updatable,f=0===n.sideOrientation?0:n.sideOrientation||e.Mesh.DEFAULTSIDE,p=n.instance;return t._ExtrudeShapeGeneric(i,s,o,null,null,a,h,c,l,u,!0,r,d,f,p)},t.CreateLathe=function(i,n,r){var o,s=n.arc<=0||n.arc>1?1:n.arc||1,a=void 0===n.closed?!0:n.closed,h=n.shape,c=n.radius||1,l=n.tessellation||64,u=n.updatable,d=0===n.sideOrientation?0:n.sideOrientation||e.Mesh.DEFAULTSIDE,f=n.cap||e.Mesh.NO_CAP,p=2*Math.PI,m=new Array,_=0,g=0,v=p/l*s,y=new Array;for(_=0;l>=_;_++){var y=[];for(f!=e.Mesh.CAP_START&&f!=e.Mesh.CAP_ALL||(y.push(new e.Vector3(0,h[0].y,0)),y.push(new e.Vector3(Math.cos(_*v)*h[0].x*c,h[0].y,Math.sin(_*v)*h[0].x*c))),g=0;g<h.length;g++)o=new e.Vector3(Math.cos(_*v)*h[g].x*c,h[g].y,Math.sin(_*v)*h[g].x*c),y.push(o);f!=e.Mesh.CAP_END&&f!=e.Mesh.CAP_ALL||(y.push(new e.Vector3(Math.cos(_*v)*h[h.length-1].x*c,h[h.length-1].y,Math.sin(_*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(i,{pathArray:m,closeArray:a,sideOrientation:d,updatable:u},r);return x},t.CreatePlane=function(t,i,n){var r=new e.Mesh(t,n),o=e.VertexData.CreatePlane(i);if(o.applyToMesh(r,i.updatable),i.sourcePlane){r.translate(i.sourcePlane.normal,i.sourcePlane.d);var s=Math.acos(e.Vector3.Dot(i.sourcePlane.normal,e.Axis.Z)),a=e.Vector3.Cross(e.Axis.Z,i.sourcePlane.normal);r.rotate(a,s)}return r},t.CreateGround=function(t,i,n){var r=new e.GroundMesh(t,n);r._setReady(!1),r._subdivisions=i.subdivisions||1,r._width=i.width||1,r._height=i.height||1,r._maxX=r._width/2,r._maxZ=r._height/2,r._minX=-r._maxX,r._minZ=-r._maxZ;var o=e.VertexData.CreateGround(i);return o.applyToMesh(r,i.updatable),r._setReady(!0),r},t.CreateTiledGround=function(t,i,n){var r=new e.Mesh(t,n),o=e.VertexData.CreateTiledGround(i);return o.applyToMesh(r,i.updatable),r},t.CreateGroundFromHeightMap=function(t,i,n,r){var o=n.width||10,s=n.height||10,a=n.subdivisions||1,h=n.minHeight,c=n.maxHeight||10,l=n.updatable,u=n.onReady,d=new e.GroundMesh(t,r);d._subdivisions=a,d._width=o,d._height=s,d._maxX=d._width/2,d._maxZ=d._height/2,d._minX=-d._maxX,d._minZ=-d._maxZ,d._setReady(!1);var f=function(t){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,f=t.height;i.width=r,i.height=f,n.drawImage(t,0,0);var p=n.getImageData(0,0,r,f).data,m=e.VertexData.CreateGroundFromHeightMap({width:o,height:s,subdivisions:a,minHeight:h,maxHeight:c,buffer:p,bufferWidth:r,bufferHeight:f});m.applyToMesh(d,l),d._setReady(!0),u&&u(d)};return e.Tools.LoadImage(i,f,function(){},r.database),d},t.CreateTube=function(i,n,r){var o=n.path,s=n.radius||1,a=n.tessellation||64,h=n.radiusFunction,c=n.cap||e.Mesh.NO_CAP,l=n.updatable,u=n.sideOrientation||e.Mesh.DEFAULTSIDE,d=n.instance;n.arc=n.arc<=0||n.arc>1?1:n.arc||1;var f,p,m=function(t,i,n,r,o,s,a,h){for(var c,l,u,d,f=i.getTangents(),p=i.getNormals(),m=i.getDistances(),_=2*Math.PI,g=_/o*h,v=function(){return r},y=s||v,x=e.Tmp.Matrix[0],b=a===e.Mesh._NO_CAP||a===e.Mesh.CAP_END?0:2,E=0;E<t.length;E++){l=y(E,m[E]),c=Array(),u=p[E];for(var A=0;o>A;A++)e.Matrix.RotationAxisToRef(f[E],g*A,x),d=c[A]?c[A]:e.Vector3.Zero(),e.Vector3.TransformCoordinatesToRef(u,x,d),d.scaleInPlace(l).addInPlace(t[E]),c[A]=d;n[b]=c,b++}var T=function(e,i){for(var n=Array(),r=0;e>r;r++)n.push(t[i]);return n};switch(a){case e.Mesh.NO_CAP:break;case e.Mesh.CAP_START:n[0]=T(o,0),n[1]=n[2].slice(0);break;case e.Mesh.CAP_END:n[b]=n[b-1].slice(0),n[b+1]=T(o,t.length-1);break;case e.Mesh.CAP_ALL:n[0]=T(o,0),n[1]=n[2].slice(0),n[b]=n[b-1].slice(0),n[b+1]=T(o,t.length-1)}return n};if(d){var _=n.arc||d.arc;return f=d.path3D.update(o),p=m(o,f,d.pathArray,s,d.tessellation,h,d.cap,_),d=t.CreateRibbon(null,{pathArray:p,instance:d}),d.path3D=f,d.pathArray=p,d.arc=_,d}f=new e.Path3D(o);var g=new Array;c=0>c||c>3?0:c,p=m(o,f,g,s,a,h,c,n.arc);var v=t.CreateRibbon(i,{pathArray:p,closePath:!0,closeArray:!1,updatable:l,sideOrientation:u},r);return v.pathArray=p,v.path3D=f,v.tessellation=a,v.cap=c,v.arc=n.arc,v},t.CreatePolyhedron=function(t,i,n){var r=new e.Mesh(t,n),o=e.VertexData.CreatePolyhedron(i);return o.applyToMesh(r,i.updatable),r},t.CreateDecal=function(t,i,n){var r=i.getIndices(),o=i.getVerticesData(e.VertexBuffer.PositionKind),s=i.getVerticesData(e.VertexBuffer.NormalKind),a=n.position||e.Vector3.Zero(),h=n.normal||e.Vector3.Up(),c=n.size||new e.Vector3(1,1,1),l=n.angle||0;if(!h){var u=new e.Vector3(0,0,1),d=i.getScene().activeCamera,f=e.Vector3.TransformCoordinates(u,d.getWorldMatrix());h=d.globalPosition.subtract(f)}var p=-Math.atan2(h.z,h.x)-Math.PI/2,m=Math.sqrt(h.x*h.x+h.z*h.z),_=Math.atan2(h.y,m),g=e.Matrix.RotationYawPitchRoll(p,_,l).multiply(e.Matrix.Translation(a.x,a.y,a.z)),v=e.Matrix.Invert(g),y=i.getWorldMatrix(),x=y.multiply(v),b=new e.VertexData;b.indices=[],b.positions=[],b.normals=[],b.uvs=[];for(var E=0,A=function(t){var i=r[t],n=new e.PositionNormalVertex;return n.position=new e.Vector3(o[3*i],o[3*i+1],o[3*i+2]),n.position=e.Vector3.TransformCoordinates(n.position,x),n.normal=new e.Vector3(s[3*i],s[3*i+1],s[3*i+2]),n},T=function(t,i){if(0===t.length)return t;for(var n=.5*Math.abs(e.Vector3.Dot(c,i)),r=function(t,r){var o=e.Vector3.GetClipFactor(t.position,r.position,i,n);return new e.PositionNormalVertex(e.Vector3.Lerp(t.position,r.position,o),e.Vector3.Lerp(t.normal,r.normal,o))},o=new Array,s=0;s<t.length;s+=3){var a,h,l,u,d,f,p,m=0,_=e.Vector3.Dot(t[s].position,i)-n,g=e.Vector3.Dot(t[s+1].position,i)-n,v=e.Vector3.Dot(t[s+2].position,i)-n;switch(a=_>0,h=g>0,l=v>0,m=(a?1:0)+(h?1:0)+(l?1:0)){case 0:o.push(t[s]),o.push(t[s+1]),o.push(t[s+2]);break;case 1:if(a&&(u=t[s+1],d=t[s+2],f=r(t[s],u),p=r(t[s],d)),h){u=t[s],d=t[s+2],f=r(t[s+1],u),p=r(t[s+1],d),o.push(f),o.push(d.clone()),o.push(u.clone()),o.push(d.clone()),o.push(f.clone()),o.push(p);break}l&&(u=t[s],d=t[s+1],f=r(t[s+2],u),p=r(t[s+2],d)),o.push(u.clone()),o.push(d.clone()),o.push(f),o.push(p),o.push(f.clone()),o.push(d.clone());break;case 2:a||(u=t[s].clone(),d=r(u,t[s+1]),f=r(u,t[s+2]),o.push(u),o.push(d),o.push(f)),h||(u=t[s+1].clone(),d=r(u,t[s+2]),f=r(u,t[s]),o.push(u),o.push(d),o.push(f)),l||(u=t[s+2].clone(),d=r(u,t[s]),f=r(u,t[s+1]),o.push(u),o.push(d),o.push(f));break;case 3:}}return o},P=0;P<r.length;P+=3){var M=new Array;if(M.push(A(P)),M.push(A(P+1)),M.push(A(P+2)),M=T(M,new e.Vector3(1,0,0)),M=T(M,new e.Vector3(-1,0,0)),M=T(M,new e.Vector3(0,1,0)),M=T(M,new e.Vector3(0,-1,0)),M=T(M,new e.Vector3(0,0,1)),M=T(M,new e.Vector3(0,0,-1)),0!==M.length)for(var C=0;C<M.length;C++){var S=M[C];b.indices.push(E),S.position.toArray(b.positions,3*E),S.normal.toArray(b.normals,3*E),b.uvs.push(.5+S.position.x/c.x),
  13. b.uvs.push(.5+S.position.y/c.y),E++}}var R=new e.Mesh(t,i.getScene());return b.applyToMesh(R),R.position=a.clone(),R.rotation=new e.Vector3(_,p,l),R},t._ExtrudeShapeGeneric=function(t,i,n,r,o,s,a,h,c,l,u,d,f,p,m){var _,g,v=function(t,i,n,r,o,s,a,h,c,l){for(var u=n.getTangents(),d=n.getNormals(),f=n.getBinormals(),p=n.getDistances(),m=0,_=function(){return o},g=function(){return s},v=l?h:g,y=l?a:_,x=c===e.Mesh.NO_CAP||c===e.Mesh.CAP_END?0:2,b=e.Tmp.Matrix[0],E=0;E<i.length;E++){for(var A=new Array,T=v(E,p[E]),P=y(E,p[E]),M=0;M<t.length;M++){e.Matrix.RotationAxisToRef(u[E],m,b);var C=u[E].scale(t[M].z).add(d[E].scale(t[M].x)).add(f[E].scale(t[M].y)),S=A[M]?A[M]:e.Vector3.Zero();e.Vector3.TransformCoordinatesToRef(C,b,S),S.scaleInPlace(P).addInPlace(i[E]),A[M]=S}r[x]=A,m+=T,x++}var R=function(t){var i,n=Array(),r=e.Vector3.Zero();for(i=0;i<t.length;i++)r.addInPlace(t[i]);for(r.scaleInPlace(1/t.length),i=0;i<t.length;i++)n.push(r);return n};switch(c){case e.Mesh.NO_CAP:break;case e.Mesh.CAP_START:r[0]=R(r[2]),r[1]=r[2].slice(0);break;case e.Mesh.CAP_END:r[x]=r[x-1],r[x+1]=R(r[x-1]);break;case e.Mesh.CAP_ALL:r[0]=R(r[2]),r[1]=r[2].slice(0),r[x]=r[x-1],r[x+1]=R(r[x-1])}return r};if(m)return _=m.path3D.update(n),g=v(i,n,m.path3D,m.pathArray,r,o,s,a,m.cap,u),m=e.Mesh.CreateRibbon(null,g,null,null,null,null,null,null,m);_=new e.Path3D(n);var y=new Array;l=0>l||l>3?0:l,g=v(i,n,_,y,r,o,s,a,l,u);var x=e.Mesh.CreateRibbon(t,g,h,c,0,d,f,p);return x.pathArray=g,x.path3D=_,x.cap=l,x},t}();e.MeshBuilder=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.hasAlpha=!1,this.getAlphaFromRGB=!1,this.level=1,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.isCube=!1,this.isRenderTarget=!1,this.animations=new Array,this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,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?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 i=this._scene.getEngine().getLoadedTexturesCache(),n=0;n<i.length;n++){var r=i[n];if(r.url===e&&r.noMipmap===t)return void i.splice(n,1)}},t.prototype._getFromCache=function(e,t,i){for(var n=this._scene.getEngine().getLoadedTexturesCache(),r=0;r<n.length;r++){var o=n[r];if(o.url===e&&o.noMipmap===t&&(!i||i===o.samplingMode))return o.references++,o}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(){if(!this.name)return null;var t=e.SerializationHelper.Serialize(this);return e.Animation.AppendSerializedAnimations(this,t),t},__decorate([e.serialize()],t.prototype,"name",void 0),__decorate([e.serialize()],t.prototype,"hasAlpha",void 0),__decorate([e.serialize()],t.prototype,"getAlphaFromRGB",void 0),__decorate([e.serialize()],t.prototype,"level",void 0),__decorate([e.serialize()],t.prototype,"coordinatesIndex",void 0),__decorate([e.serialize()],t.prototype,"coordinatesMode",void 0),__decorate([e.serialize()],t.prototype,"wrapU",void 0),__decorate([e.serialize()],t.prototype,"wrapV",void 0),__decorate([e.serialize()],t.prototype,"anisotropicFilteringLevel",void 0),__decorate([e.serialize()],t.prototype,"isCube",void 0),__decorate([e.serialize()],t.prototype,"isRenderTarget",void 0),t}();e.BaseTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(n,r,o,s,a,h,c,l,u){void 0===a&&(a=i.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=null),void 0===c&&(c=null),void 0===l&&(l=null),void 0===u&&(u=!1),t.call(this,r),this.uOffset=0,this.vOffset=0,this.uScale=1,this.vScale=1,this.uAng=0,this.vAng=0,this.wAng=0,this.name=n,this.url=n,this._noMipmap=o,this._invertY=s,this._samplingMode=a,this._buffer=l,this._deleteBuffer=u,n&&(this._texture=this._getFromCache(n,o,a),this._texture?e.Tools.SetImmediate(function(){h&&h()}):r.useDelayedTextureLoading?(this.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,this._delayedOnLoad=h,this._delayedOnError=c):(this._texture=r.getEngine().createTexture(n,o,s,r,this._samplingMode,h,c,this._buffer),u&&delete this._buffer))}return __extends(i,t),i.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,this._delayedOnLoad,this._delayedOnError,this._buffer),this._deleteBuffer&&delete this._buffer))},i.prototype.updateSamplingMode=function(e){this._texture&&this.getScene().getEngine().updateTextureSamplingMode(e,this._texture)},i.prototype._prepareRowForTextureGeneration=function(t,i,n,r){t*=this.uScale,i*=this.vScale,t-=.5*this.uScale,i-=.5*this.vScale,n-=.5,e.Vector3.TransformCoordinatesFromFloatsToRef(t,i,n,this._rowGenerationMatrix,r),r.x+=.5*this.uScale+this.uOffset,r.y+=.5*this.vScale+this.vOffset,r.z+=.5},i.prototype.getTextureMatrix=function(){return this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.uAng===this._cachedUAng&&this.vAng===this._cachedVAng&&this.wAng===this._cachedWAng?this._cachedTextureMatrix:(this._cachedUOffset=this.uOffset,this._cachedVOffset=this.vOffset,this._cachedUScale=this.uScale,this._cachedVScale=this.vScale,this._cachedUAng=this.uAng,this._cachedVAng=this.vAng,this._cachedWAng=this.wAng,this._cachedTextureMatrix||(this._cachedTextureMatrix=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)},i.prototype.getReflectionTextureMatrix=function(){if(this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.coordinatesMode===this._cachedCoordinatesMode)return this._cachedTextureMatrix;switch(this._cachedTextureMatrix||(this._cachedTextureMatrix=e.Matrix.Zero(),this._projectionModeMatrix=e.Matrix.Zero()),this._cachedCoordinatesMode=this.coordinatesMode,this.coordinatesMode){case i.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 i.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},i.prototype.clone=function(){var t=this;return e.SerializationHelper.Clone(function(){return new i(t._texture.url,t.getScene(),t._noMipmap,t._invertY,t._samplingMode)},this)},i.CreateFromBase64String=function(e,t,n,r,o,s,a,h){return void 0===s&&(s=i.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=null),void 0===h&&(h=null),new i("data:"+t,n,r,o,s,a,h,e)},i.Parse=function(t,n,r){if(t.isCube)return e.CubeTexture.Parse(t,n,r);if(!t.name&&!t.isRenderTarget)return null;var o=e.SerializationHelper.Parse(function(){if(t.mirrorPlane){var o=new e.MirrorTexture(t.name,t.renderTargetSize,n);return o._waitingRenderList=t.renderList,o.mirrorPlane=e.Plane.FromArray(t.mirrorPlane),o}if(t.isRenderTarget){var s=new e.RenderTargetTexture(t.name,t.renderTargetSize,n);return s._waitingRenderList=t.renderList,s}var a;return a=t.base64String?i.CreateFromBase64String(t.base64String,t.name,n):new i(r+t.name,n)},t,n);if(t.animations)for(var s=0;s<t.animations.length;s++){var a=t.animations[s];o.animations.push(e.Animation.Parse(a))}return o},i.NEAREST_SAMPLINGMODE=1,i.BILINEAR_SAMPLINGMODE=2,i.TRILINEAR_SAMPLINGMODE=3,i.EXPLICIT_MODE=0,i.SPHERICAL_MODE=1,i.PLANAR_MODE=2,i.CUBIC_MODE=3,i.PROJECTION_MODE=4,i.SKYBOX_MODE=5,i.INVCUBIC_MODE=6,i.EQUIRECTANGULAR_MODE=7,i.FIXED_EQUIRECTANGULAR_MODE=8,i.CLAMP_ADDRESSMODE=0,i.WRAP_ADDRESSMODE=1,i.MIRROR_ADDRESSMODE=2,__decorate([e.serialize()],i.prototype,"url",void 0),__decorate([e.serialize()],i.prototype,"uOffset",void 0),__decorate([e.serialize()],i.prototype,"vOffset",void 0),__decorate([e.serialize()],i.prototype,"uScale",void 0),__decorate([e.serialize()],i.prototype,"vScale",void 0),__decorate([e.serialize()],i.prototype,"uAng",void 0),__decorate([e.serialize()],i.prototype,"vAng",void 0),__decorate([e.serialize()],i.prototype,"wAng",void 0),i}(e.BaseTexture);e.Texture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s){if(t.call(this,n),this.coordinatesMode=e.Texture.CUBIC_MODE,this.name=i,this.url=i,this._noMipmap=o,this.hasAlpha=!1,i||s){if(this._texture=this._getFromCache(i,o),!s){r||(r=["_px.jpg","_py.jpg","_pz.jpg","_nx.jpg","_ny.jpg","_nz.jpg"]),s=[];for(var a=0;a<r.length;a++)s.push(i+r[a]);this._extensions=r}this._files=s,this._texture||(n.useDelayedTextureLoading?this.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:this._texture=n.getEngine().createCubeTexture(i,n,s,o)),this.isCube=!0,this._textureMatrix=e.Matrix.Identity()}}return __extends(i,t),i.CreateFromImages=function(e,t,n){return new i("",t,null,n,e)},i.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)))},i.prototype.getReflectionTextureMatrix=function(){return this._textureMatrix},i.Parse=function(t,i,n){var r=e.SerializationHelper.Parse(function(){return new e.CubeTexture(n+t.name,i,t.extensions)},t,i);if(t.animations)for(var o=0;o<t.animations.length;o++){var s=t.animations[o];r.animations.push(e.Animation.Parse(s))}return r},i.prototype.clone=function(){var t=this;return e.SerializationHelper.Clone(function(){return new i(t.url,t.getScene(),t._extensions,t._noMipmap,t._files)},this)},i}(e.BaseTexture);e.CubeTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s,a,h){void 0===s&&(s=!0),void 0===a&&(a=e.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===h&&(h=!1),t.call(this,null,r,!o),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=i,this.isRenderTarget=!0,this._size=n,this._generateMipMaps=o,this._doNotChangeAspectRatio=s,h?(this._texture=r.getEngine().createRenderTargetCubeTexture(n,{generateMipMaps:o}),this.coordinatesMode=e.Texture.INVCUBIC_MODE,this._textureMatrix=e.Matrix.Identity()):this._texture=r.getEngine().createRenderTargetTexture(n,{generateMipMaps:o,type:a}),this._renderingManager=new e.RenderingManager(r)}return __extends(i,t),Object.defineProperty(i,"REFRESHRATE_RENDER_ONCE",{get:function(){return i._REFRESHRATE_RENDER_ONCE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"REFRESHRATE_RENDER_ONEVERYFRAME",{get:function(){return i._REFRESHRATE_RENDER_ONEVERYFRAME},enumerable:!0,configurable:!0}),Object.defineProperty(i,"REFRESHRATE_RENDER_ONEVERYTWOFRAMES",{get:function(){return i._REFRESHRATE_RENDER_ONEVERYTWOFRAMES},enumerable:!0,configurable:!0}),i.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},Object.defineProperty(i.prototype,"refreshRate",{get:function(){return this._refreshRate},set:function(e){this._refreshRate=e,this.resetRefreshCounter()},enumerable:!0,configurable:!0}),i.prototype._shouldRender=function(){return-1===this._currentRefreshId?(this._currentRefreshId=1,!0):this.refreshRate===this._currentRefreshId?(this._currentRefreshId=1,!0):(this._currentRefreshId++,!1)},i.prototype.isReady=function(){return this.getScene().renderTargetsEnabled?t.prototype.isReady.call(this):!1},i.prototype.getRenderSize=function(){return this._size},Object.defineProperty(i.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),i.prototype.scale=function(e){var t=this._size*e;this.resize(t,this._generateMipMaps)},i.prototype.getReflectionTextureMatrix=function(){return this.isCube?this._textureMatrix:t.prototype.getReflectionTextureMatrix.call(this)},i.prototype.resize=function(e,t){this.releaseInternalTexture(),this.isCube?this._texture=this.getScene().getEngine().createRenderTargetCubeTexture(e):this._texture=this.getScene().getEngine().createRenderTargetTexture(e,t)},i.prototype.render=function(e,t){var i=this.getScene();if(this.activeCamera&&this.activeCamera!==i.activeCamera&&i.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(!0)),this._waitingRenderList){this.renderList=[];for(var n=0;n<this._waitingRenderList.length;n++){var r=this._waitingRenderList[n];this.renderList.push(i.getMeshByID(r))}delete this._waitingRenderList}if(!this.renderList||0!==this.renderList.length){this._renderingManager.reset();for(var o=this.renderList?this.renderList:i.getActiveMeshes().data,s=i.getRenderId(),a=0;a<o.length;a++){var h=o[a];if(h){if(!h.isReady()){this.resetRefreshCounter();continue}if(h._preActivateForIntermediateRendering(s),h.isEnabled()&&h.isVisible&&h.subMeshes&&0!==(h.layerMask&i.activeCamera.layerMask)){h._activate(s);for(var c=0;c<h.subMeshes.length;c++){var l=h.subMeshes[c];i._activeIndices+=l.indexCount,this._renderingManager.dispatch(l)}}}}if(this.isCube)for(var u=0;6>u;u++)this.renderToTarget(u,o,e,t),i.incrementRenderId(),i.resetCachedMaterial();else this.renderToTarget(0,o,e,t);this.onAfterUnbind&&this.onAfterUnbind(),this.activeCamera&&this.activeCamera!==i.activeCamera&&i.setTransformMatrix(i.activeCamera.getViewMatrix(),i.activeCamera.getProjectionMatrix(!0)),i.resetCachedMaterial()}},i.prototype.renderToTarget=function(t,i,n,r){var o=this.getScene(),s=o.getEngine();n&&o.postProcessManager._prepareFrame(this._texture)||(this.isCube?s.bindFramebuffer(this._texture,t):s.bindFramebuffer(this._texture)),this.onBeforeRender&&this.onBeforeRender(t),this.onClear?this.onClear(s):s.clear(o.clearColor,!0,!0),this._doNotChangeAspectRatio||o.updateTransformMatrix(!0),this._renderingManager.render(this.customRenderFunction,i,this.renderParticles,this.renderSprites),n&&o.postProcessManager._finalizeFrame(!1,this._texture,t),this._doNotChangeAspectRatio||o.updateTransformMatrix(!0),this.onAfterRender&&this.onAfterRender(t),r&&e.Tools.DumpFramebuffer(this._size,this._size,s),this.isCube&&5!==t||(this.isCube&&5===t&&s.generateMipMapsForCubemap(this._texture),s.unBindFramebuffer(this._texture,this.isCube))},i.prototype.clone=function(){var e=this.getSize(),t=new i(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},i.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);e.renderTargetSize=this.getRenderSize(),e.renderList=[];for(var i=0;i<this.renderList.length;i++)e.renderList.push(this.renderList[i].id);return e},i._REFRESHRATE_RENDER_ONCE=0,i._REFRESHRATE_RENDER_ONEVERYFRAME=1,i._REFRESHRATE_RENDER_ONEVERYTWOFRAMES=2,i}(e.Texture);e.RenderTargetTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n,r,o,s,a){void 0===s&&(s=!0),void 0===a&&(a=!1),e.call(this,null,r,!s),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,r._proceduralTextures.push(this),this.name=t,this.isRenderTarget=!0,this._size=i,this._generateMipMaps=s,this.setFragment(n),this._fallbackTexture=o,a?(this._texture=r.getEngine().createRenderTargetCubeTexture(i,{generateMipMaps:s}),this.setFloat("face",0)):this._texture=r.getEngine().createRenderTargetTexture(i,s);var h=[];h.push(1,1),h.push(-1,1),h.push(-1,-1),h.push(1,-1),this._vertexBuffer=r.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=r.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,i=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=i.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(),i=t.getEngine();i.enableEffect(this._effect),i.setState(!1);for(var n in this._textures)this._effect.setTexture(n,this._textures[n]);for(n in this._floats)this._effect.setFloat(n,this._floats[n]);for(n in this._floatsArrays)this._effect.setArray(n,this._floatsArrays[n]);for(n in this._colors3)this._effect.setColor3(n,this._colors3[n]);for(n in this._colors4){var r=this._colors4[n];this._effect.setFloat4(n,r.r,r.g,r.b,r.a)}for(n in this._vectors2)this._effect.setVector2(n,this._vectors2[n]);for(n in this._vectors3)this._effect.setVector3(n,this._vectors3[n]);for(n in this._matrices)this._effect.setMatrix(n,this._matrices[n]);if(i.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,this._effect),this.isCube)for(var o=0;6>o;o++)i.bindFramebuffer(this._texture,o),this._effect.setFloat("face",o),i.clear(t.clearColor,!0,!0),i.draw(!0,0,6),5===o&&i.generateMipMapsForCubemap(this._texture);else i.bindFramebuffer(this._texture),i.clear(t.clearColor,!0,!0),i.draw(!0,0,6);i.unBindFramebuffer(this._texture,this.isCube),this.onGenerated&&this.onGenerated()},t.prototype.clone=function(){var e=this.getSize(),i=new t(this.name,e.width,this._fragment,this.getScene(),this._fallbackTexture,this._generateMipMaps);return i.hasAlpha=this.hasAlpha,i.level=this.level,i.coordinatesMode=this.coordinatesMode,i},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 i(i,n,r,o){var s=this;t.call(this,i,n,r,o,!0),this.mirrorPlane=new e.Plane(0,1,0,1),this._transformMatrix=e.Matrix.Zero(),this._mirrorMatrix=e.Matrix.Zero(),this.onBeforeRender=function(){e.Matrix.ReflectionToRef(s.mirrorPlane,s._mirrorMatrix),s._savedViewMatrix=r.getViewMatrix(),s._mirrorMatrix.multiplyToRef(s._savedViewMatrix,s._transformMatrix),r.setTransformMatrix(s._transformMatrix,r.getProjectionMatrix()),r.clipPlane=s.mirrorPlane,r.getEngine().cullBackFaces=!1,r._mirroredCameraPosition=e.Vector3.TransformCoordinates(r.activeCamera.position,s._mirrorMatrix)},this.onAfterRender=function(){r.setTransformMatrix(s._savedViewMatrix,r.getProjectionMatrix()),r.getEngine().cullBackFaces=!0,r._mirroredCameraPosition=null,delete r.clipPlane}}return __extends(i,t),i.prototype.clone=function(){var e=this.getSize(),t=new i(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},i.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);return e.mirrorPlane=this.mirrorPlane.asArray(),e},i}(e.RenderTargetTexture);e.MirrorTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o){var s=this;t.call(this,i,n,r,o,!0),this.refractionPlane=new e.Plane(0,1,0,1),this.depth=2,this.onBeforeRender=function(){r.clipPlane=s.refractionPlane},this.onAfterRender=function(){delete r.clipPlane}}return __extends(i,t),i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.refractionPlane=this.refractionPlane.clone(),t.renderList=this.renderList.slice(0),t.depth=this.depth,t},i.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);return e.mirrorPlane=this.refractionPlane.asArray(),e.depth=this.depth,e},i}(e.RenderTargetTexture);e.RefractionTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s){void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,r,!o),this.name=i,this.wrapU=e.Texture.CLAMP_ADDRESSMODE,this.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._generateMipMaps=o,n.getContext?(this._canvas=n,this._texture=r.getEngine().createDynamicTexture(n.width,n.height,o,s)):(this._canvas=document.createElement("canvas"),n.width?this._texture=r.getEngine().createDynamicTexture(n.width,n.height,o,s):this._texture=r.getEngine().createDynamicTexture(n,n,o,s));var a=this.getSize();this._canvas.width=a.width,this._canvas.height=a.height,this._context=this._canvas.getContext("2d")}return __extends(i,t),Object.defineProperty(i.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),i.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)},i.prototype.getContext=function(){return this._context},i.prototype.clear=function(){var e=this.getSize();this._context.fillRect(0,0,e.width,e.height)},i.prototype.update=function(e){this.getScene().getEngine().updateDynamicTexture(this._texture,this._canvas,void 0===e?!0:e)},i.prototype.drawText=function(e,t,i,n,r,o,s,a){void 0===a&&(a=!0);var h=this.getSize();if(o&&(this._context.fillStyle=o,this._context.fillRect(0,0,h.width,h.height)),this._context.font=n,null===t){var c=this._context.measureText(e);t=(h.width-c.width)/2}this._context.fillStyle=r,this._context.fillText(e,t,i),a&&this.update(s)},i.prototype.clone=function(){var e=this.getSize(),t=new i(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},i}(e.Texture);e.DynamicTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s,a){var h=this;void 0===o&&(o=!1),void 0===s&&(s=!1),void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,r,!o,s),this._autoLaunch=!0;var c;this.name=i,n instanceof HTMLVideoElement?this.video=n:(c=n,this.video=document.createElement("video"),this.video.autoplay=!1,this.video.loop=!0),this._generateMipMaps=o,this._samplingMode=a,e.Tools.IsExponentOfTwo(this.video.videoWidth)&&e.Tools.IsExponentOfTwo(this.video.videoHeight)?(this.wrapU=e.Texture.WRAP_ADDRESSMODE,this.wrapV=e.Texture.WRAP_ADDRESSMODE):(this.wrapU=e.Texture.CLAMP_ADDRESSMODE,this.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._generateMipMaps=!1),c?(this.video.addEventListener("canplaythrough",function(){h._createTexture()}),c.forEach(function(e){var t=document.createElement("source");t.src=e,h.video.appendChild(t)})):this._createTexture(),this._lastUpdate=e.Tools.Now}return __extends(i,t),i.prototype._createTexture=function(){this._texture=this.getScene().getEngine().createDynamicTexture(this.video.videoWidth,this.video.videoHeight,this._generateMipMaps,this._samplingMode,!1),this._texture.isReady=!0},i.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)},i}(e.Texture);e.VideoTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,n,r,o,s){t.call(this,e,n,null,r,o,s),this._animate=!0,this._time=0,this._texturePath=i,this.loadJson(i),this.refreshRate=1}return __extends(i,t),i.prototype.loadJson=function(t){function i(){e.Tools.Log("No config file found in "+t+" trying to use ShadersStore or DOM element");try{r.setFragment(r._texturePath)}catch(i){e.Tools.Error("No json or ShaderStore or DOM element found for CustomProceduralTexture")}}var n=this,r=this,o=t+"/config.json",s=new XMLHttpRequest;s.open("GET",o,!0),s.addEventListener("load",function(){if(200===s.status||e.Tools.ValidateXHRData(s,1))try{n._config=JSON.parse(s.response),n.updateShaderUniforms(),n.updateTextures(),n.setFragment(n._texturePath+"/custom"),n._animate=n._config.animate,n.refreshRate=n._config.refreshrate}catch(t){i()}else i()},!1),s.addEventListener("error",function(){i()},!1);try{s.send()}catch(a){e.Tools.Error("CustomProceduralTexture: Error on XHR send request.")}},i.prototype.isReady=function(){if(!t.prototype.isReady.call(this))return!1;for(var e in this._textures){var i=this._textures[e];if(!i.isReady())return!1}return!0},i.prototype.render=function(e){this._animate&&(this._time+=.03*this.getScene().getAnimationRatio(),this.updateShaderUniforms()),t.prototype.render.call(this,e)},i.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()))},i.prototype.updateShaderUniforms=function(){if(this._config)for(var t=0;t<this._config.uniforms.length;t++){var i=this._config.uniforms[t];switch(i.type){case"float":this.setFloat(i.name,i.value);break;case"color3":this.setColor3(i.name,new e.Color3(i.r,i.g,i.b));break;case"color4":this.setColor4(i.name,new e.Color4(i.r,i.g,i.b,i.a));break;case"vector2":this.setVector2(i.name,new e.Vector2(i.x,i.y));break;case"vector3":this.setVector3(i.name,new e.Vector3(i.x,i.y,i.z))}}this.setFloat("time",this._time)},Object.defineProperty(i.prototype,"animate",{get:function(){return this._animate},set:function(e){this._animate=e},enumerable:!0,configurable:!0}),i}(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 i=this._defines[this._currentRank],n=0;n<i.length;n++)t=t.replace("#define "+i[n],"");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 i=function(){function t(e,t,i,n,r,o,s,a,h){var c=this;this._isReady=!1,this._compilationError="",this._valueCache=[],this._engine=r,this.name=e,this.defines=o,this._uniformsNames=i.concat(n),this._samplers=n,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,
  14. this._loadVertexShader(l,function(e){c._processIncludes(e,function(e){c._loadFragmentShader(u,function(i){c._processIncludes(i,function(i){c._prepareEffect(e,i,t,o,s)})})})})}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(i,n){if(i instanceof HTMLElement){var r=e.Tools.GetDOMTextContent(i);return void n(r)}if(t.ShadersStore[i+"VertexShader"])return void n(t.ShadersStore[i+"VertexShader"]);var o;o="."===i[0]||"/"===i[0]||i.indexOf("http")>-1?i:e.Engine.ShadersRepository+i,e.Tools.LoadFile(o+".vertex.fx",n)},t.prototype._loadFragmentShader=function(i,n){if(i instanceof HTMLElement){var r=e.Tools.GetDOMTextContent(i);return void n(r)}if(t.ShadersStore[i+"PixelShader"])return void n(t.ShadersStore[i+"PixelShader"]);if(t.ShadersStore[i+"FragmentShader"])return void n(t.ShadersStore[i+"FragmentShader"]);var o;o="."===i[0]||"/"===i[0]||i.indexOf("http")>-1?i:e.Engine.ShadersRepository+i,e.Tools.LoadFile(o+".fragment.fx",n)},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._processIncludes=function(i,n){for(var r=this,o=/#include<(.+)>(\((.*)\))*(\[(.*)\])*/g,s=o.exec(i),a=new String(i);null!=s;){var h=s[1];if(!t.IncludesShadersStore[h]){var c=e.Engine.ShadersRepository+"ShadersInclude/"+h+".fx";return void e.Tools.LoadFile(c,function(e){t.IncludesShadersStore[h]=e,r._processIncludes(a,n)})}var l=t.IncludesShadersStore[h];if(s[2])for(var u=s[3].split(","),d=0;d<u.length;d+=2){var f=new RegExp(u[d],"g"),p=u[d+1];l=l.replace(f,p)}s[4]&&(l=l.replace(/\{X\}/g,s[5])),a=a.replace(s[0],l),s=o.exec(i)}n(a)},t.prototype._processPrecision=function(e){return-1===e.indexOf("precision highp float")?e=this._engine.getCaps().highPrecisionShaderSupported?"precision highp float;\n"+e:"precision mediump float;\n"+e:this._engine.getCaps().highPrecisionShaderSupported||(e=e.replace("precision highp float","precision mediump float")),e},t.prototype._prepareEffect=function(t,i,n,r,o){try{var s=this._engine;t=this._processPrecision(t),i=this._processPrecision(i),this._program=s.createShaderProgram(t,i,r),this._uniforms=s.getUniforms(this._program,this._uniformsNames),this._attributes=s.getAttributes(this._program,n);for(var a=0;a<this._samplers.length;a++){var h=this.getUniform(this._samplers[a]);null==h&&(this._samplers.splice(a,1),a--)}s.bindSamplers(this),this._isReady=!0,this.onCompiled&&this.onCompiled(this)}catch(c){if(-1!==c.message.indexOf("highp"))return t=t.replace("precision highp float","precision mediump float"),i=i.replace("precision highp float","precision mediump float"),void this._prepareEffect(t,i,n,r,o);o&&o.isMoreFallbacks?(e.Tools.Error("Unable to compile effect with current defines. Trying next fallback."),this._dumpShadersName(),r=o.reduce(r),this._prepareEffect(t,i,n,r,o)):(e.Tools.Error("Unable to compile effect: "),this._dumpShadersName(),e.Tools.Error("Defines: "+r),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,i){this._valueCache[t]||(this._valueCache[t]=new e.Matrix);for(var n=0;16>n;n++)this._valueCache[t].m[n]=i.m[n]},t.prototype._cacheFloat2=function(e,t,i){return this._valueCache[e]?(this._valueCache[e][0]=t,void(this._valueCache[e][1]=i)):void(this._valueCache[e]=[t,i])},t.prototype._cacheFloat3=function(e,t,i,n){return this._valueCache[e]?(this._valueCache[e][0]=t,this._valueCache[e][1]=i,void(this._valueCache[e][2]=n)):void(this._valueCache[e]=[t,i,n])},t.prototype._cacheFloat4=function(e,t,i,n,r){return this._valueCache[e]?(this._valueCache[e][0]=t,this._valueCache[e][1]=i,this._valueCache[e][2]=n,void(this._valueCache[e][3]=r)):void(this._valueCache[e]=[t,i,n,r])},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,i){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===i?this:(this._cacheFloat2(e,t,i),this._engine.setFloat2(this.getUniform(e),t,i),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,i,n){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===i&&this._valueCache[e][2]===n?this:(this._cacheFloat3(e,t,i,n),this._engine.setFloat3(this.getUniform(e),t,i,n),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,i,n,r){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===i&&this._valueCache[e][2]===n&&this._valueCache[e][3]===r?this:(this._cacheFloat4(e,t,i,n,r),this._engine.setFloat4(this.getUniform(e),t,i,n,r),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,i){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]===i?this:(this._cacheFloat4(e,t.r,t.g,t.b,i),this._engine.setColor4(this.getUniform(e),t,i),this)},t.ShadersStore={},t.IncludesShadersStore={},t}();e.Effect=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=4,i=function(){function i(){}return i.PrepareDefinesForLights=function(i,n,r){for(var o=0,s=!1,a=0;a<i.lights.length;a++){var h=i.lights[a];if(h.isEnabled()){if(h._excludedMeshesIds.length>0){for(var c=0;c<h._excludedMeshesIds.length;c++){var l=i.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 d=i.getMeshByID(h._includedOnlyMeshesIds[u]);d&&h.includedOnlyMeshes.push(d)}h._includedOnlyMeshesIds=[]}if(h.canAffectMesh(n)){s=!0,r["LIGHT"+o]=!0;var f;if(f=h instanceof e.SpotLight?"SPOTLIGHT"+o:h instanceof e.HemisphericLight?"HEMILIGHT"+o:h instanceof e.PointLight?"POINTLIGHT"+o:"DIRLIGHT"+o,r[f]=!0,h.specular.equalsFloats(0,0,0)||void 0===r.SPECULARTERM||(r.SPECULARTERM=!0),i.shadowsEnabled){var p=h.getShadowGenerator();n&&n.receiveShadows&&p&&(r["SHADOW"+o]=!0,r.SHADOWS=!0,(p.useVarianceShadowMap||p.useBlurVarianceShadowMap)&&(r["SHADOWVSM"+o]=!0),p.usePoissonSampling&&(r["SHADOWPCF"+o]=!0))}if(o++,o===t)break}}}return s},i.HandleFallbacksForShadows=function(e,i){for(var n=0;t>n;n++)e["LIGHT"+n]&&(n>0&&i.addFallback(n,"LIGHT"+n),e["SHADOW"+n]&&i.addFallback(0,"SHADOW"+n),e["SHADOWPCF"+n]&&i.addFallback(0,"SHADOWPCF"+n),e["SHADOWVSM"+n]&&i.addFallback(0,"SHADOWVSM"+n))},i.PrepareAttributesForBones=function(t,i,n,r){n.NUM_BONE_INFLUENCERS>0&&(r.addCPUSkinningFallback(0,i),t.push(e.VertexBuffer.MatricesIndicesKind),t.push(e.VertexBuffer.MatricesWeightsKind),n.NUM_BONE_INFLUENCERS>4&&(t.push(e.VertexBuffer.MatricesIndicesExtraKind),t.push(e.VertexBuffer.MatricesWeightsExtraKind)))},i.PrepareAttributesForInstances=function(e,t){t.INSTANCES&&(e.push("world0"),e.push("world1"),e.push("world2"),e.push("world3"))},i.BindLightShadow=function(e,t,i,n,r,o){var s=e.getShadowGenerator();return i.receiveShadows&&s&&(e.needCube()?o||(o=!0,r.setFloat2("depthValues",t.activeCamera.minZ,t.activeCamera.maxZ)):r.setMatrix("lightMatrix"+n,s.getTransformMatrix()),r.setTexture("shadowSampler"+n,s.getShadowMapForRendering()),r.setFloat3("shadowsInfo"+n,s.getDarkness(),s.blurScale/s.getShadowMap().getSize().width,s.bias)),o},i.BindLightProperties=function(t,i,n){t instanceof e.PointLight?t.transferToEffect(i,"vLightData"+n):t instanceof e.DirectionalLight?t.transferToEffect(i,"vLightData"+n):t instanceof e.SpotLight?t.transferToEffect(i,"vLightData"+n,"vLightDirection"+n):t instanceof e.HemisphericLight&&t.transferToEffect(i,"vLightData"+n,"vLightGround"+n)},i.BindLights=function(n,r,o,s){for(var a=0,h=!1,c=0;c<n.lights.length;c++){var l=n.lights[c];if(l.isEnabled()&&l.canAffectMesh(r)&&(i.BindLightProperties(l,o,a),l.diffuse.scaleToRef(l.intensity,e.Tmp.Color3[0]),o.setColor4("vLightDiffuse"+a,e.Tmp.Color3[0],l.range),s.SPECULARTERM&&(l.specular.scaleToRef(l.intensity,e.Tmp.Color3[1]),o.setColor3("vLightSpecular"+a,e.Tmp.Color3[1])),n.shadowsEnabled&&(h=this.BindLightShadow(l,n,r,a,o,h)),a++,a===t))break}},i.BindFogParameters=function(t,i,n){t.fogEnabled&&i.applyFog&&t.fogMode!==e.Scene.FOGMODE_NONE&&(n.setFloat4("vFogInfos",t.fogMode,t.fogStart,t.fogEnd,t.fogDensity),n.setColor3("vFogColor",t.fogColor))},i.BindBonesParameters=function(e,t){e&&e.useBones&&e.computeBonesUsingShaders&&t.setMatrices("mBones",e.skeleton.getTransformMatrices(e))},i.BindLogDepth=function(e,t,i){e.LOGARITHMICDEPTH&&t.setFloat("logarithmicDepthConstant",2/(Math.log(i.activeCamera.maxZ+1)/Math.LN2))},i.BindClipPlane=function(e,t){if(t.clipPlane){var i=t.clipPlane;e.setFloat4("vClipPlane",i.normal.x,i.normal.y,i.normal.z,i.d)}},i}();e.MaterialHelper=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=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 i=new t;return e.Tools.DeepCopy(this,i),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(i){var n=new t;return n.isEnabled=i.isEnabled,n.leftColor=e.Color3.FromArray(i.leftColor),n.rightColor=e.Color3.FromArray(i.rightColor),n.bias=i.bias,n.power=i.power||1,n},t}();e.FresnelParameters=t}(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 i=this._keys[t];if(this[i]!==e[i])return!1}return!0},e.prototype.cloneTo=function(e){for(var t=0;t<this._keys.length;t++){var i=this._keys[t];e[i]=this[i]}},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 i=this._keys[t];"number"==typeof this[i]?e+="#define "+i+" "+this[i]+"\n":this[i]&&(e+="#define "+i+"\n")}return e},e}();e.MaterialDefines=t;var i=function(){function t(i,n,r){this.name=i,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.pointSize=1,this.zOffset=0,this._wasPreviouslyReady=!1,this._fillMode=t.TriangleFillMode,this.id=i,this._scene=n,r||n.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}),t.prototype.toString=function(e){var t="Name: "+this.name;return t},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 i=this._scene.getEngine();this._cachedDepthWriteState=i.getDepthWrite(),i.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 i=this._scene.meshes[t];i.material===this&&e.push(i)}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 i=this._scene.meshes[t];i.material===this&&(i.material=null)}this.onDispose&&this.onDispose()},t.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},t.ParseMultiMaterial=function(t,i){var n=new e.MultiMaterial(t.name,i);n.id=t.id,e.Tags.AddTagsTo(n,t.tags);for(var r=0;r<t.materials.length;r++){var o=t.materials[r];o?n.subMaterials.push(i.getMaterialByID(o)):n.subMaterials.push(null)}return n},t.Parse=function(t,i,n){if(!t.customType)return e.StandardMaterial.Parse(t,i,n);var r=e.Tools.Instantiate(t.customType);return r.Parse(t,i,n)},t._TriangleFillMode=0,t._WireFrameFillMode=1,t._PointFillMode=2,t._ClockWiseSideOrientation=0,t._CounterClockWiseSideOrientation=1,__decorate([e.serialize()],t.prototype,"id",void 0),__decorate([e.serialize()],t.prototype,"checkReadyOnEveryCall",void 0),__decorate([e.serialize()],t.prototype,"checkReadyOnlyOnce",void 0),__decorate([e.serialize()],t.prototype,"state",void 0),__decorate([e.serialize()],t.prototype,"alpha",void 0),__decorate([e.serialize()],t.prototype,"backFaceCulling",void 0),__decorate([e.serialize()],t.prototype,"sideOrientation",void 0),__decorate([e.serialize()],t.prototype,"alphaMode",void 0),__decorate([e.serialize()],t.prototype,"disableDepthWrite",void 0),__decorate([e.serialize()],t.prototype,"fogEnabled",void 0),__decorate([e.serialize()],t.prototype,"pointSize",void 0),__decorate([e.serialize()],t.prototype,"zOffset",void 0),__decorate([e.serialize()],t.prototype,"wireframe",null),__decorate([e.serialize()],t.prototype,"pointsCloud",null),__decorate([e.serialize()],t.prototype,"fillMode",null),t}();e.Material=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=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.PARALLAX=!1,this.PARALLAXOCCLUSION=!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.REFRACTIONFRESNEL=!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.REFRACTION=!1,this.REFRACTIONMAP_3D=!1,this.REFLECTIONOVERALPHA=!1,this._keys=Object.keys(this)}return __extends(t,e),t}(e.MaterialDefines),i=function(i){function n(n,r){var o=this;i.call(this,n,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.emissiveColor=new e.Color3(0,0,0),this.specularPower=64,this.useAlphaFromDiffuseTexture=!1,this.useEmissiveAsIllumination=!1,this.linkEmissiveWithDiffuse=!1,this.useReflectionFresnelFromSpecular=!1,this.useSpecularOverAlpha=!1,this.useReflectionOverAlpha=!1,this.disableLighting=!1,this.useParallax=!1,this.useParallaxOcclusion=!1,this.parallaxScaleBias=.05,this.roughness=0,this.indexOfRefraction=.98,this.invertRefractionY=!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 t,this._cachedDefines=new t,this._cachedDefines.BonesPerMesh=-1,this.getRenderTargetTextures=function(){return o._renderTargets.reset(),o.reflectionTexture&&o.reflectionTexture.isRenderTarget&&o._renderTargets.push(o.reflectionTexture),o.refractionTexture&&o.refractionTexture.isRenderTarget&&o._renderTargets.push(o.refractionTexture),o._renderTargets}}return __extends(n,i),Object.defineProperty(n.prototype,"useLogarithmicDepth",{get:function(){return this._useLogarithmicDepth},set:function(e){this._useLogarithmicDepth=e&&this.getScene().getEngine().getCaps().fragmentDepthSupported},enumerable:!0,configurable:!0}),n.prototype.needAlphaBlending=function(){return this.alpha<1||null!=this.opacityTexture||this._shouldUseAlphaFromDiffuseTexture()||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled},n.prototype.needAlphaTesting=function(){return null!=this.diffuseTexture&&this.diffuseTexture.hasAlpha},n.prototype._shouldUseAlphaFromDiffuseTexture=function(){return null!=this.diffuseTexture&&this.diffuseTexture.hasAlpha&&this.useAlphaFromDiffuseTexture},n.prototype.getAlphaTestTexture=function(){return this.diffuseTexture},n.prototype._checkCache=function(e,t,i){return t?this._defines.INSTANCES!==i?!1:!(!t._materialDefines||!t._materialDefines.isEqual(this._defines)):!0},n.prototype.isReady=function(i,r){if(this.isFrozen&&this._wasPreviouslyReady)return!0;var o=this.getScene();if(!this.checkReadyOnEveryCall&&this._renderId===o.getRenderId()&&this._checkCache(o,i,r))return!0;var s=o.getEngine(),a=!1,h=!1;if(this._defines.reset(),o.texturesEnabled){if(this.diffuseTexture&&n.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;h=!0,this._defines.DIFFUSE=!0}if(this.ambientTexture&&n.AmbientTextureEnabled){if(!this.ambientTexture.isReady())return!1;h=!0,this._defines.AMBIENT=!0}if(this.opacityTexture&&n.OpacityTextureEnabled){if(!this.opacityTexture.isReady())return!1;h=!0,this._defines.OPACITY=!0,this.opacityTexture.getAlphaFromRGB&&(this._defines.OPACITYRGB=!0)}if(this.reflectionTexture&&n.ReflectionTextureEnabled){if(!this.reflectionTexture.isReady())return!1;switch(a=!0,this._defines.REFLECTION=!0,this.roughness>0&&(this._defines.ROUGHNESS=!0),this.useReflectionOverAlpha&&(this._defines.REFLECTIONOVERALPHA=!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&&n.EmissiveTextureEnabled){if(!this.emissiveTexture.isReady())return!1;h=!0,this._defines.EMISSIVE=!0}if(this.lightmapTexture&&n.LightmapTextureEnabled){if(!this.lightmapTexture.isReady())return!1;h=!0,this._defines.LIGHTMAP=!0,this._defines.USELIGHTMAPASSHADOWMAP=this.useLightmapAsShadowmap}if(this.specularTexture&&n.SpecularTextureEnabled){if(!this.specularTexture.isReady())return!1;h=!0,this._defines.SPECULAR=!0,this._defines.GLOSSINESS=this.useGlossinessFromSpecularMapAlpha}if(o.getEngine().getCaps().standardDerivatives&&this.bumpTexture&&n.BumpTextureEnabled){if(!this.bumpTexture.isReady())return!1;h=!0,this._defines.BUMP=!0,this.useParallax&&(this._defines.PARALLAX=!0,this.useParallaxOcclusion&&(this._defines.PARALLAXOCCLUSION=!0))}if(this.refractionTexture&&n.RefractionTextureEnabled){if(!this.refractionTexture.isReady())return!1;h=!0,this._defines.REFRACTION=!0,this._defines.REFRACTIONMAP_3D=this.refractionTexture.isCube}}if(o.clipPlane&&(this._defines.CLIPPLANE=!0),s.getAlphaTesting()&&(this._defines.ALPHATEST=!0),this._shouldUseAlphaFromDiffuseTexture()&&(this._defines.ALPHAFROMDIFFUSE=!0),this.useEmissiveAsIllumination&&(this._defines.EMISSIVEASILLUMINATION=!0),this.linkEmissiveWithDiffuse&&(this._defines.LINKEMISSIVEWITHDIFFUSE=!0),this.useLogarithmicDepth&&(this._defines.LOGARITHMICDEPTH=!0),(this.pointsCloud||o.forcePointsCloud)&&(this._defines.POINTSIZE=!0),o.fogEnabled&&i&&i.applyFog&&o.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(this._defines.FOG=!0),o.lightsEnabled&&!this.disableLighting&&(a=e.MaterialHelper.PrepareDefinesForLights(o,i,this._defines)),n.FresnelEnabled&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled||this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled||this.refractionFresnelParameters&&this.refractionFresnelParameters.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.useReflectionFresnelFromSpecular&&(this._defines.REFLECTIONFRESNELFROMSPECULAR=!0)),this.refractionFresnelParameters&&this.refractionFresnelParameters.isEnabled&&(this._defines.REFRACTIONFRESNEL=!0),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._defines.EMISSIVEFRESNEL=!0),a=!0,this._defines.FRESNEL=!0),this._defines.SPECULARTERM&&this.useSpecularOverAlpha&&(this._defines.SPECULAROVERALPHA=!0),i&&(a&&i.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(this._defines.NORMAL=!0),h&&(i.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(this._defines.UV1=!0),i.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(this._defines.UV2=!0)),i.useVertexColors&&i.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(this._defines.VERTEXCOLOR=!0,i.hasVertexAlpha&&(this._defines.VERTEXALPHA=!0)),i.useBones&&i.computeBonesUsingShaders&&(this._defines.NUM_BONE_INFLUENCERS=i.numBoneInfluencers,this._defines.BonesPerMesh=i.skeleton.bones.length+1),r&&(this._defines.INSTANCES=!0)),!this._defines.isEqual(this._cachedDefines)){this._defines.cloneTo(this._cachedDefines),o.resetCachedMaterial();var c=new e.EffectFallbacks;this._defines.REFLECTION&&c.addFallback(0,"REFLECTION"),this._defines.SPECULAR&&c.addFallback(0,"SPECULAR"),this._defines.BUMP&&c.addFallback(0,"BUMP"),this._defines.PARALLAX&&c.addFallback(1,"PARALLAX"),this._defines.PARALLAXOCCLUSION&&c.addFallback(0,"PARALLAXOCCLUSION"),this._defines.SPECULAROVERALPHA&&c.addFallback(0,"SPECULAROVERALPHA"),this._defines.FOG&&c.addFallback(1,"FOG"),this._defines.POINTSIZE&&c.addFallback(0,"POINTSIZE"),this._defines.LOGARITHMICDEPTH&&c.addFallback(0,"LOGARITHMICDEPTH"),e.MaterialHelper.HandleFallbacksForShadows(this._defines,c),this._defines.SPECULARTERM&&c.addFallback(0,"SPECULARTERM"),this._defines.DIFFUSEFRESNEL&&c.addFallback(1,"DIFFUSEFRESNEL"),this._defines.OPACITYFRESNEL&&c.addFallback(2,"OPACITYFRESNEL"),this._defines.REFLECTIONFRESNEL&&c.addFallback(3,"REFLECTIONFRESNEL"),this._defines.EMISSIVEFRESNEL&&c.addFallback(4,"EMISSIVEFRESNEL"),this._defines.FRESNEL&&c.addFallback(4,"FRESNEL");var l=[e.VertexBuffer.PositionKind];this._defines.NORMAL&&l.push(e.VertexBuffer.NormalKind),this._defines.UV1&&l.push(e.VertexBuffer.UVKind),this._defines.UV2&&l.push(e.VertexBuffer.UV2Kind),this._defines.VERTEXCOLOR&&l.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(l,i,this._defines,c),e.MaterialHelper.PrepareAttributesForInstances(l,this._defines);var u="default";o.getEngine().getCaps().standardDerivatives||(u="legacydefault");var d=this._defines.toString();this._effect=o.getEngine().createEffect(u,l,["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","vRefractionInfos","mBones","vClipPlane","diffuseMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","specularMatrix","bumpMatrix","lightmapMatrix","refractionMatrix","shadowsInfo0","shadowsInfo1","shadowsInfo2","shadowsInfo3","depthValues","diffuseLeftColor","diffuseRightColor","opacityParts","reflectionLeftColor","reflectionRightColor","emissiveLeftColor","emissiveRightColor","refractionLeftColor","refractionRightColor","logarithmicDepthConstant"],["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","lightmapSampler","refractionCubeSampler","refraction2DSampler","shadowSampler0","shadowSampler1","shadowSampler2","shadowSampler3"],d,c,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=o.getRenderId(),this._wasPreviouslyReady=!0,i&&(i._materialDefines||(i._materialDefines=new t),this._defines.cloneTo(i._materialDefines)),!0):!1},n.prototype.unbind=function(){this.reflectionTexture&&this.reflectionTexture.isRenderTarget&&this._effect.setTexture("reflection2DSampler",null),this.refractionTexture&&this.refractionTexture.isRenderTarget&&this._effect.setTexture("refraction2DSampler",null),i.prototype.unbind.call(this)},n.prototype.bindOnlyWorldMatrix=function(e){this._effect.setMatrix("world",e)},n.prototype.bind=function(t,r){var o=this.getScene();if(this.bindOnlyWorldMatrix(t),e.MaterialHelper.BindBonesParameters(r,this._effect),o.getCachedMaterial()!==this){if(this._effect.setMatrix("viewProjection",o.getTransformMatrix()),n.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),
  15. 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.refractionFresnelParameters&&this.refractionFresnelParameters.isEnabled&&(this._effect.setColor4("refractionLeftColor",this.refractionFresnelParameters.leftColor,this.refractionFresnelParameters.power),this._effect.setColor4("refractionRightColor",this.refractionFresnelParameters.rightColor,this.refractionFresnelParameters.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))),o.texturesEnabled&&(this.diffuseTexture&&n.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&&n.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&&n.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&&n.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&&n.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&&n.LightmapTextureEnabled&&(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&&n.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&&o.getEngine().getCaps().standardDerivatives&&n.BumpTextureEnabled&&(this._effect.setTexture("bumpSampler",this.bumpTexture),this._effect.setFloat3("vBumpInfos",this.bumpTexture.coordinatesIndex,1/this.bumpTexture.level,this.parallaxScaleBias),this._effect.setMatrix("bumpMatrix",this.bumpTexture.getTextureMatrix())),this.refractionTexture&&n.RefractionTextureEnabled)){var s=1;this.refractionTexture.isCube?this._effect.setTexture("refractionCubeSampler",this.refractionTexture):(this._effect.setTexture("refraction2DSampler",this.refractionTexture),this._effect.setMatrix("refractionMatrix",this.refractionTexture.getReflectionTextureMatrix()),this.refractionTexture.depth&&(s=this.refractionTexture.depth)),this._effect.setFloat4("vRefractionInfos",this.refractionTexture.level,this.indexOfRefraction,s,this.invertRefractionY?-1:1)}e.MaterialHelper.BindClipPlane(this._effect,o),this.pointsCloud&&this._effect.setFloat("pointSize",this.pointSize),o.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor),this._effect.setVector3("vEyePosition",o._mirroredCameraPosition?o._mirroredCameraPosition:o.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)}o.getCachedMaterial()===this&&this.isFrozen||(this._effect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*r.visibility),o.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(o,r,this._effect,this._defines),(o.fogEnabled&&r.applyFog&&o.fogMode!==e.Scene.FOGMODE_NONE||this.reflectionTexture||this.refractionTexture)&&this._effect.setMatrix("view",o.getViewMatrix()),e.MaterialHelper.BindFogParameters(o,r,this._effect),e.MaterialHelper.BindLogDepth(this._defines,this._effect,o)),i.prototype.bind.call(this,t,r)},n.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),this.lightmapTexture&&this.lightmapTexture.animations&&this.lightmapTexture.animations.length>0&&e.push(this.lightmapTexture),this.refractionTexture&&this.refractionTexture.animations&&this.refractionTexture.animations.length>0&&e.push(this.refractionTexture),e},n.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(),this.lightmapTexture&&this.lightmapTexture.dispose(),this.refractionTexture&&this.refractionTexture.dispose(),i.prototype.dispose.call(this,e)},n.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new n(t,i.getScene())},this)},n.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},n.Parse=function(t,i,r){return e.SerializationHelper.Parse(function(){return new n(t.name,i)},t,i,r)},n.DiffuseTextureEnabled=!0,n.AmbientTextureEnabled=!0,n.OpacityTextureEnabled=!0,n.ReflectionTextureEnabled=!0,n.EmissiveTextureEnabled=!0,n.SpecularTextureEnabled=!0,n.BumpTextureEnabled=!0,n.FresnelEnabled=!0,n.LightmapTextureEnabled=!0,n.RefractionTextureEnabled=!0,__decorate([e.serializeAsTexture()],n.prototype,"diffuseTexture",void 0),__decorate([e.serializeAsTexture()],n.prototype,"ambientTexture",void 0),__decorate([e.serializeAsTexture()],n.prototype,"opacityTexture",void 0),__decorate([e.serializeAsTexture()],n.prototype,"reflectionTexture",void 0),__decorate([e.serializeAsTexture()],n.prototype,"emissiveTexture",void 0),__decorate([e.serializeAsTexture()],n.prototype,"specularTexture",void 0),__decorate([e.serializeAsTexture()],n.prototype,"bumpTexture",void 0),__decorate([e.serializeAsTexture()],n.prototype,"lightmapTexture",void 0),__decorate([e.serializeAsTexture()],n.prototype,"refractionTexture",void 0),__decorate([e.serializeAsColor3("ambient")],n.prototype,"ambientColor",void 0),__decorate([e.serializeAsColor3("diffuse")],n.prototype,"diffuseColor",void 0),__decorate([e.serializeAsColor3("specular")],n.prototype,"specularColor",void 0),__decorate([e.serializeAsColor3("emissive")],n.prototype,"emissiveColor",void 0),__decorate([e.serialize()],n.prototype,"specularPower",void 0),__decorate([e.serialize()],n.prototype,"useAlphaFromDiffuseTexture",void 0),__decorate([e.serialize()],n.prototype,"useEmissiveAsIllumination",void 0),__decorate([e.serialize()],n.prototype,"linkEmissiveWithDiffuse",void 0),__decorate([e.serialize()],n.prototype,"useReflectionFresnelFromSpecular",void 0),__decorate([e.serialize()],n.prototype,"useSpecularOverAlpha",void 0),__decorate([e.serialize()],n.prototype,"useReflectionOverAlpha",void 0),__decorate([e.serialize()],n.prototype,"disableLighting",void 0),__decorate([e.serialize()],n.prototype,"useParallax",void 0),__decorate([e.serialize()],n.prototype,"useParallaxOcclusion",void 0),__decorate([e.serialize()],n.prototype,"parallaxScaleBias",void 0),__decorate([e.serialize()],n.prototype,"roughness",void 0),__decorate([e.serialize()],n.prototype,"indexOfRefraction",void 0),__decorate([e.serialize()],n.prototype,"invertRefractionY",void 0),__decorate([e.serialize()],n.prototype,"useLightmapAsShadowmap",void 0),__decorate([e.serializeAsFresnelParameters()],n.prototype,"diffuseFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters()],n.prototype,"opacityFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters()],n.prototype,"reflectionFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters()],n.prototype,"refractionFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters()],n.prototype,"emissiveFresnelParameters",void 0),__decorate([e.serialize()],n.prototype,"useGlossinessFromSpecularMapAlpha",void 0),__decorate([e.serialize()],n.prototype,"useLogarithmicDepth",null),n}(e.Material);e.StandardMaterial=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i){t.call(this,e,i,!0),this.subMaterials=new Array,i.multiMaterials.push(this)}return __extends(i,t),i.prototype.getSubMaterial=function(e){return 0>e||e>=this.subMaterials.length?this.getScene().defaultMaterial:this.subMaterials[e]},i.prototype.isReady=function(e){for(var t=0;t<this.subMaterials.length;t++){var i=this.subMaterials[t];if(i&&!this.subMaterials[t].isReady(e))return!1}return!0},i.prototype.clone=function(e,t){for(var n=new i(e,this.getScene()),r=0;r<this.subMaterials.length;r++){var o=null;o=t?this.subMaterials[r].clone(e+"-"+this.subMaterials[r].name):this.subMaterials[r],n.subMaterials.push(o)}return n},i.prototype.serialize=function(){var t={};t.name=this.name,t.id=this.id,t.tags=e.Tags.GetTags(this),t.materials=[];for(var i=0;i<this.subMaterials.length;i++){var n=this.subMaterials[i];n?t.materials.push(n.id):t.materials.push(null)}return t},i}(e.Material);e.MultiMaterial=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return Object.defineProperty(t,"NO_LOGGING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(t,"MINIMAL_LOGGING",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(t,"SUMMARY_LOGGING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"DETAILED_LOGGING",{get:function(){return 3},enumerable:!0,configurable:!0}),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}),Object.defineProperty(t,"loggingLevel",{get:function(){return t._loggingLevel},set:function(e){t._loggingLevel=e},enumerable:!0,configurable:!0}),t._getPluginForFilename=function(e){var t=e.lastIndexOf("."),i=e.indexOf("?");-1===i&&(i=e.length);for(var n=e.substring(t,i).toLowerCase(),r=0;r<this._registeredPlugins.length;r++){var o=this._registeredPlugins[r];if(-1!==o.extensions.indexOf(n))return o}return this._registeredPlugins[this._registeredPlugins.length-1]},t.GetPluginForExtension=function(e){for(var t=0;t<this._registeredPlugins.length;t++){var i=this._registeredPlugins[t];if(-1!==i.extensions.indexOf(e))return i}return null},t.RegisterPlugin=function(e){e.extensions=e.extensions.toLowerCase(),t._registeredPlugins.push(e)},t.ImportMesh=function(i,n,r,o,s,a,h){if(r.substr&&"/"===r.substr(0,1))return void e.Tools.Error("Wrong sceneFilename parameter");var c={};o._addPendingData(c);var l=function(l){o.database=u;var d=t._getPluginForFilename(r),f=function(e){var t=[],a=[],l=[];try{if(d.importMesh){var u=d;if(!u.importMesh(i,o,e,n,t,a,l))return h&&h(o,"Unable to import meshes from "+n+r),void o._removePendingData(c);s&&(o.importedMeshesFiles.push(n+r),s(t,a,l),o._removePendingData(c))}else{var f=d;f.importMeshAsync(i,o,e,n,function(e,t,i){s&&(o.importedMeshesFiles.push(n+r),s(e,t,i),o._removePendingData(c))},function(){h&&h(o,"Unable to import meshes from "+n+r),o._removePendingData(c)})}}catch(p){h&&h(o,"Unable to import meshes from "+n+r+" (Exception: "+p+")"),o._removePendingData(c)}};return r.substr&&"data:"===r.substr(0,5)?void f(r.substr(5)):void e.Tools.LoadFile(n+r,function(e){f(e)},a,u)};if(!o.getEngine().enableOfflineSupport||r.substr&&"data:"===r.substr(0,5))l(!0);else var u=new e.Database(n+r,l)},t.Load=function(i,n,r,o,s,a){t.Append(i,n,new e.Scene(r),o,s,a)},t.Append=function(i,n,r,o,s,a){if(n.substr&&"/"===n.substr(0,1))return void e.Tools.Error("Wrong sceneFilename parameter");var h,c=this._getPluginForFilename(n.name||n),l={};r._addPendingData(l),t.ShowLoadingScreen&&r.getEngine().displayLoadingUI();var u=function(e){if(r.database=h,c.load){var n=c;if(!n.load(r,e,i))return a&&a(r),r._removePendingData(l),void r.getEngine().hideLoadingUI();o&&o(r),r._removePendingData(l)}else{var s=c;s.loadAsync(r,e,i,function(){o&&o(r)},function(){a&&a(r),r._removePendingData(l),r.getEngine().hideLoadingUI()})}t.ShowLoadingScreen&&r.executeWhenReady(function(){r.getEngine().hideLoadingUI()})},d=function(t){e.Tools.LoadFile(i+n,u,s,h)};return n.substr&&"data:"===n.substr(0,5)?void u(n.substr(5)):void(-1===i.indexOf("file:")?r.getEngine().enableOfflineSupport?h=new e.Database(i+n,d):d(!0):e.Tools.ReadFile(n,u,s))},t._ForceFullSceneLoadingForIncremental=!1,t._ShowLoadingScreen=!0,t._loggingLevel=t.NO_LOGGING,t._registeredPlugins=new Array,t}();e.SceneLoader=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){var i=function(t,i,n,r){for(var o=0,s=i.materials.length;s>o;o++){var a=i.materials[o];if(a.id===t)return e.Material.Parse(a,n,r)}return null},n=function(e,t,i){t=t instanceof Array?t:[t];for(var n in t)if(e.name===t[n])return i.push(e.id),!0;return e.parentId&&-1!==i.indexOf(e.parentId)?(i.push(e.id),!0):!1},r=function(e,t){return e+" of "+(t?t.file+" from "+t.name+" version: "+t.version+", exporter version: "+t.exporter_version:"unknown")};e.SceneLoader.RegisterPlugin({extensions:".babylon",importMesh:function(t,o,s,a,h,c,l){var u="importMesh has failed JSON parse";try{var d=JSON.parse(s);u="";var f,p,m=e.SceneLoader.loggingLevel===e.SceneLoader.DETAILED_LOGGING,_=[],g=[],v=[];for(f=0,p=d.meshes.length;p>f;f++){var y=d.meshes[f];if(!t||n(y,t,v)){if(t instanceof Array&&delete t[t.indexOf(y.name)],y.geometryId&&d.geometries){var x=!1;["boxes","spheres","cylinders","toruses","grounds","planes","torusKnots","vertexData"].forEach(function(t){!x&&d.geometries[t]&&d.geometries[t]instanceof Array&&d.geometries[t].forEach(function(i){if(i.id===y.geometryId){switch(t){case"boxes":e.Geometry.Primitives.Box.Parse(i,o);break;case"spheres":e.Geometry.Primitives.Sphere.Parse(i,o);break;case"cylinders":e.Geometry.Primitives.Cylinder.Parse(i,o);break;case"toruses":e.Geometry.Primitives.Torus.Parse(i,o);break;case"grounds":e.Geometry.Primitives.Ground.Parse(i,o);break;case"planes":e.Geometry.Primitives.Plane.Parse(i,o);break;case"torusKnots":e.Geometry.Primitives.TorusKnot.Parse(i,o);break;case"vertexData":e.Geometry.Parse(i,o,a)}x=!0}})}),x||e.Tools.Warn("Geometry not found for mesh "+y.id)}if(y.materialId){var b=-1!==g.indexOf(y.materialId);if(!b&&d.multiMaterials)for(var E=0,A=d.multiMaterials.length;A>E;E++){var T=d.multiMaterials[E];if(T.id===y.materialId){for(var P=0,M=T.materials.length;M>P;P++){var C=T.materials[P];g.push(C);var S=i(C,d,o,a);u+="\n Material "+S.toString(m)}g.push(T.id);var R=e.Material.ParseMultiMaterial(T,o);b=!0,u+="\n Multi-Material "+R.toString(m);break}}if(!b){g.push(y.materialId);var S=i(y.materialId,d,o,a);S?u+="\n Material "+S.toString(m):e.Tools.Warn("Material not found for mesh "+y.id)}}if(y.skeletonId>-1&&o.skeletons){var I=_.indexOf(y.skeletonId)>-1;if(!I)for(var D=0,O=d.skeletons.length;O>D;D++){var w=d.skeletons[D];if(w.id===y.skeletonId){var L=e.Skeleton.Parse(w,o);l.push(L),_.push(w.id),u+="\n Skeleton "+L.toString(m)}}}var B=e.Mesh.Parse(y,o,a);h.push(B),u+="\n Mesh "+B.toString(m)}}var F;for(f=0,p=o.meshes.length;p>f;f++)F=o.meshes[f],F._waitingParentId&&(F.parent=o.getLastEntryByID(F._waitingParentId),F._waitingParentId=void 0);for(f=0,p=o.meshes.length;p>f;f++)F=o.meshes[f],F._waitingFreezeWorldMatrix?(F.freezeWorldMatrix(),F._waitingFreezeWorldMatrix=void 0):F.computeWorldMatrix(!0);if(d.particleSystems)for(f=0,p=d.particleSystems.length;p>f;f++){var V=d.particleSystems[f];-1!==v.indexOf(V.emitterId)&&c.push(e.ParticleSystem.Parse(V,o,a))}return!0}catch(N){throw e.Tools.Log(r("importMesh",d.producer)+u),u=null,N}finally{null!==u&&e.SceneLoader.loggingLevel!==e.SceneLoader.NO_LOGGING&&e.Tools.Log(r("importMesh",d.producer)+(e.SceneLoader.loggingLevel!==e.SceneLoader.MINIMAL_LOGGING?u:""))}},load:function(t,i,n){var o="importScene has failed JSON parse";try{var s=JSON.parse(i);o="";var a=e.SceneLoader.loggingLevel===e.SceneLoader.DETAILED_LOGGING;if(t.useDelayedTextureLoading=s.useDelayedTextureLoading&&!e.SceneLoader.ForceFullSceneLoadingForIncremental,t.autoClear=s.autoClear,t.clearColor=e.Color3.FromArray(s.clearColor),t.ambientColor=e.Color3.FromArray(s.ambientColor),s.gravity&&(t.gravity=e.Vector3.FromArray(s.gravity)),s.fogMode&&0!==s.fogMode)switch(t.fogMode=s.fogMode,t.fogColor=e.Color3.FromArray(s.fogColor),t.fogStart=s.fogStart,t.fogEnd=s.fogEnd,t.fogDensity=s.fogDensity,o+=" Fog mode for scene: ",t.fogMode){case 1:o+="exp\n";break;case 2:o+="exp2\n";break;case 3:o+="linear\n"}if(s.physicsEnabled){var h;"cannon"===s.physicsEngine?h=new e.CannonJSPlugin:"oimo"===s.physicsEngine&&(h=new e.OimoJSPlugin),o=" Physics engine "+(s.physicsEngine?s.physicsEngine:"oimo")+" enabled\n";var c=s.physicsGravity?e.Vector3.FromArray(s.physicsGravity):null;t.enablePhysics(c,h)}void 0!=s.collisionsEnabled&&(t.collisionsEnabled=s.collisionsEnabled),t.workerCollisions=!!s.workerCollisions;var l,u;for(l=0,u=s.lights.length;u>l;l++){var d=s.lights[l],f=e.Light.Parse(d,t);o+=0===l?"\n Lights:":"",o+="\n "+f.toString(a)}if(s.animations)for(l=0,u=s.animations.length;u>l;l++){var p=s.animations[l],m=e.Animation.Parse(p);t.animations.push(m),o+=0===l?"\n Animations:":"",o+="\n "+m.toString(a)}if(s.materials)for(l=0,u=s.materials.length;u>l;l++){var _=s.materials[l],g=e.Material.Parse(_,t,n);o+=0===l?"\n Materials:":"",o+="\n "+g.toString(a)}if(s.multiMaterials)for(l=0,u=s.multiMaterials.length;u>l;l++){var v=s.multiMaterials[l],y=e.Material.ParseMultiMaterial(v,t);o+=0===l?"\n MultiMaterials:":"",o+="\n "+y.toString(a)}if(s.skeletons)for(l=0,u=s.skeletons.length;u>l;l++){var x=s.skeletons[l],b=e.Skeleton.Parse(x,t);o+=0===l?"\n Skeletons:":"",o+="\n "+b.toString(a)}var E=s.geometries;if(E){var A=E.boxes;if(A)for(l=0,u=A.length;u>l;l++){var T=A[l];e.Geometry.Primitives.Box.Parse(T,t)}var P=E.spheres;if(P)for(l=0,u=P.length;u>l;l++){var M=P[l];e.Geometry.Primitives.Sphere.Parse(M,t)}var C=E.cylinders;if(C)for(l=0,u=C.length;u>l;l++){var S=C[l];e.Geometry.Primitives.Cylinder.Parse(S,t)}var R=E.toruses;if(R)for(l=0,u=R.length;u>l;l++){var I=R[l];e.Geometry.Primitives.Torus.Parse(I,t)}var D=E.grounds;if(D)for(l=0,u=D.length;u>l;l++){var O=D[l];e.Geometry.Primitives.Ground.Parse(O,t)}var w=E.planes;if(w)for(l=0,u=w.length;u>l;l++){var L=w[l];e.Geometry.Primitives.Plane.Parse(L,t)}var B=E.torusKnots;if(B)for(l=0,u=B.length;u>l;l++){var F=B[l];e.Geometry.Primitives.TorusKnot.Parse(F,t)}var V=E.vertexData;if(V)for(l=0,u=V.length;u>l;l++){var N=V[l];e.Geometry.Parse(N,t,n)}}for(l=0,u=s.meshes.length;u>l;l++){var z=s.meshes[l],U=e.Mesh.Parse(z,t,n);o+=0===l?"\n Meshes:":"",o+="\n "+U.toString(a)}for(l=0,u=s.cameras.length;u>l;l++){var k=s.cameras[l],G=e.Camera.Parse(k,t);o+=0===l?"\n Cameras:":"",o+="\n "+G.toString(a)}for(s.activeCameraID&&t.setActiveCameraByID(s.activeCameraID),l=0,u=t.cameras.length;u>l;l++){var G=t.cameras[l];G._waitingParentId&&(G.parent=t.getLastEntryByID(G._waitingParentId),G._waitingParentId=void 0)}for(l=0,u=t.lights.length;u>l;l++){var f=t.lights[l];f._waitingParentId&&(f.parent=t.getLastEntryByID(f._waitingParentId),f._waitingParentId=void 0)}var W,Y=[];if(e.AudioEngine&&s.sounds)for(l=0,u=s.sounds.length;u>l;l++){var H=s.sounds[l];if(e.Engine.audioEngine.canUseWebAudio)H.url||(H.url=H.name),Y[H.url]?e.Sound.Parse(H,t,n,Y[H.url]):(W=e.Sound.Parse(H,t,n),Y[H.url]=W);else{new e.Sound(H.name,null,t)}}for(Y=[],l=0,u=t.meshes.length;u>l;l++){var U=t.meshes[l];U._waitingParentId&&(U.parent=t.getLastEntryByID(U._waitingParentId),U._waitingParentId=void 0),U._waitingActions&&(e.ActionManager.Parse(U._waitingActions,U,t),U._waitingActions=void 0)}for(l=0,u=t.meshes.length;u>l;l++){var X=t.meshes[l];X._waitingFreezeWorldMatrix?(X.freezeWorldMatrix(),X._waitingFreezeWorldMatrix=void 0):X.computeWorldMatrix(!0)}if(s.particleSystems)for(l=0,u=s.particleSystems.length;u>l;l++){var j=s.particleSystems[l];e.ParticleSystem.Parse(j,t,n)}if(s.lensFlareSystems)for(l=0,u=s.lensFlareSystems.length;u>l;l++){var K=s.lensFlareSystems[l];e.LensFlareSystem.Parse(K,t,n)}if(s.shadowGenerators)for(l=0,u=s.shadowGenerators.length;u>l;l++){var Z=s.shadowGenerators[l];e.ShadowGenerator.Parse(Z,t)}return s.actions&&e.ActionManager.Parse(s.actions,null,t),!0}catch(q){throw e.Tools.Log(r("importScene",s.producer)+o),o=null,q}finally{null!==o&&e.SceneLoader.loggingLevel!==e.SceneLoader.NO_LOGGING&&e.Tools.Log(r("importScene",s.producer)+(e.SceneLoader.loggingLevel!==e.SceneLoader.MINIMAL_LOGGING?o:""))}}})}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,n,r,o,s,a){void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE),this.name=t,this.cellSize=r,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=n,this._spriteTexture=new e.Texture(i,o,!0,!1,a),this._spriteTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._spriteTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._epsilon=void 0===s?.01:s,this._scene=o,this._scene.spriteManagers.push(this),this._vertexBuffer=o.getEngine().createDynamicVertexBuffer(n*this._vertexStrideSize*4);for(var h=[],c=0,l=0;n>l;l++)h.push(c),h.push(c+1),h.push(c+2),h.push(c),h.push(c+2),h.push(c+3),c+=4;this._indexBuffer=o.getEngine().createIndexBuffer(h),this._vertices=new Float32Array(n*this._vertexStrideSize),this._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 Object.defineProperty(t.prototype,"texture",{get:function(){return this._spriteTexture},set:function(e){this._spriteTexture=e},enumerable:!0,configurable:!0}),t.prototype._appendSpriteVertex=function(e,t,i,n,r){var o=16*e;0===i?i=this._epsilon:1===i&&(i=1-this._epsilon),0===n?n=this._epsilon:1===n&&(n=1-this._epsilon),this._vertices[o]=t.position.x,this._vertices[o+1]=t.position.y,this._vertices[o+2]=t.position.z,this._vertices[o+3]=t.angle,this._vertices[o+4]=t.width,this._vertices[o+5]=t.height,this._vertices[o+6]=i,this._vertices[o+7]=n,this._vertices[o+8]=t.invertU?1:0,this._vertices[o+9]=t.invertV?1:0;var s=t.cellIndex/r>>0;this._vertices[o+10]=t.cellIndex-s*r,this._vertices[o+11]=s,this._vertices[o+12]=t.color.r,this._vertices[o+13]=t.color.g,this._vertices[o+14]=t.color.b,this._vertices[o+15]=t.color.a},t.prototype.intersects=function(t,i,n,r){for(var o,s=Math.min(this._capacity,this.sprites.length),a=e.Vector3.Zero(),h=e.Vector3.Zero(),c=Number.MAX_VALUE,l=e.Vector3.Zero(),u=i.getViewMatrix(),d=0;s>d;d++){var f=this.sprites[d];if(f){if(n){if(!n(f))continue}else if(!f.isPickable)continue;if(e.Vector3.TransformCoordinatesToRef(f.position,u,l),a.copyFromFloats(l.x-f.width/2,l.y-f.height/2,l.z),h.copyFromFloats(l.x+f.width/2,l.y+f.height/2,l.z),t.intersectsBoxMinMax(a,h)){var p=e.Vector3.Distance(l,t.origin);if(c>p&&(c=p,o=f,r))break}}}if(o){var m=new e.PickingInfo;return m.hit=!0,m.pickedSprite=o,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(),i=this._spriteTexture.getBaseSize(),n=t.getDeltaTime(),r=Math.min(this._capacity,this.sprites.length),o=i.width/this.cellSize,s=0,a=0;r>a;a++){var h=this.sprites[a];h&&(h._animate(n),this._appendSpriteVertex(s++,h,0,0,o),this._appendSpriteVertex(s++,h,1,0,o),this._appendSpriteVertex(s++,h,1,1,o),this._appendSpriteVertex(s++,h,0,1,o))}t.updateDynamicVertexBuffer(this._vertexBuffer,this._vertices);var c=this._effectBase;this._scene.fogEnabled&&this._scene.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(c=this._effectFog),t.enableEffect(c);var l=this._scene.getViewMatrix();c.setTexture("diffuseSampler",this._spriteTexture),c.setMatrix("view",l),c.setMatrix("projection",this._scene.getProjectionMatrix()),c.setFloat2("textureInfos",this.cellSize/i.width,this.cellSize/i.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*r),t.setColorWrite(!0),c.setBool("alphaTest",!1),t.setAlphaMode(e.Engine.ALPHA_COMBINE),t.draw(!0,0,6*r),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,i){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=i,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,i,n){this._fromIndex=e,this._toIndex=t,this._loopAnimation=i,this._delay=n,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,i,n,r,o){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=i?new e.Texture(i,n,!0):null,this.isBackground=void 0===r?!0:r,this.color=void 0===o?new e.Color4(1,1,1,1):o,this._scene=n,this._scene.layers.push(this);var s=[];s.push(1,1),s.push(-1,1),s.push(-1,-1),s.push(1,-1),this._vertexBuffer=n.getEngine().createVertexBuffer(s);var a=[];a.push(0),a.push(1),a.push(2),a.push(0),a.push(2),a.push(3),this._indexBuffer=n.getEngine().createIndexBuffer(a),this._effect=this._scene.getEngine().createEffect("layer",["position"],["textureMatrix","color","scale","offset"],["textureSampler"],""),this._alphaTestEffect=this._scene.getEngine().createEffect("layer",["position"],["textureMatrix","color","scale","offset"],["textureSampler"],"#define ALPHATEST")}return t.prototype.render=function(){var t=this.alphaTest?this._alphaTestEffect:this._effect;if(t.isReady()&&this.texture&&this.texture.isReady()){var i=this._scene.getEngine();this.onBeforeRender&&this.onBeforeRender(),i.enableEffect(t),i.setState(!1),t.setTexture("textureSampler",this.texture),t.setMatrix("textureMatrix",this.texture.getTextureMatrix()),t.setFloat4("color",this.color.r,this.color.g,this.color.b,this.color.a),t.setVector2("offset",this.offset),t.setVector2("scale",this.scale),i.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,t),this._alphaTestEffect?i.draw(!0,0,6):(i.setAlphaMode(this.alphaBlendingMode),i.draw(!0,0,6),i.setAlphaMode(e.Engine.ALPHA_DISABLE)),this.onAfterRender&&this.onAfterRender()}},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 i=Math.random();return i*(t-e)+e},i=function(){function i(n,r,o,s){var a=this;this.name=n,this.animations=[],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,
  16. this.minSize=1,this.maxSize=1,this.minAngularSpeed=0,this.maxAngularSpeed=0,this.layerMask=268435455,this.blendMode=i.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=n,this._capacity=r,this._scene=o,this._customEffect=s,o.particleSystems.push(this),this._vertexBuffer=o.getEngine().createDynamicVertexBuffer(r*this._vertexStrideSize*4);for(var h=[],c=0,l=0;r>l;l++)h.push(c),h.push(c+1),h.push(c+2),h.push(c),h.push(c+2),h.push(c+3),c+=4;this._indexBuffer=o.getEngine().createIndexBuffer(h),this._vertices=new Float32Array(r*this._vertexStrideSize),this.startDirectionFunction=function(i,n,r,o){var s=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(s*i,h*i,c*i,n,r)},this.startPositionFunction=function(i,n,r){var o=t(a.minEmitBox.x,a.maxEmitBox.x),s=t(a.minEmitBox.y,a.maxEmitBox.y),h=t(a.minEmitBox.z,a.maxEmitBox.z);e.Vector3.TransformCoordinatesFromFloatsToRef(o,s,h,i,n)},this.updateFunction=function(e){for(var t=0;t<e.length;t++){var i=e[t];i.age+=a._scaledUpdateSpeed,i.age>=i.lifeTime?(a.recycleParticle(i),t--):(i.colorStep.scaleToRef(a._scaledUpdateSpeed,a._scaledColorStep),i.color.addInPlace(a._scaledColorStep),i.color.a<0&&(i.color.a=0),i.angle+=i.angularSpeed*a._scaledUpdateSpeed,i.direction.scaleToRef(a._scaledUpdateSpeed,a._scaledDirection),i.position.addInPlace(a._scaledDirection),a.gravity.scaleToRef(a._scaledUpdateSpeed,a._scaledGravity),i.direction.addInPlace(a._scaledGravity))}}}return i.prototype.recycleParticle=function(e){var t=this.particles.pop();t!==e&&(t.copyTo(e),this._stockParticles.push(t))},i.prototype.getCapacity=function(){return this._capacity},i.prototype.isAlive=function(){return this._alive},i.prototype.isStarted=function(){return this._started},i.prototype.start=function(){this._started=!0,this._stopped=!1,this._actualFrame=0},i.prototype.stop=function(){this._stopped=!0},i.prototype._appendParticleVertex=function(e,t,i,n){var r=11*e;this._vertices[r]=t.position.x,this._vertices[r+1]=t.position.y,this._vertices[r+2]=t.position.z,this._vertices[r+3]=t.color.r,this._vertices[r+4]=t.color.g,this._vertices[r+5]=t.color.b,this._vertices[r+6]=t.color.a,this._vertices[r+7]=t.angle,this._vertices[r+8]=t.size,this._vertices[r+9]=i,this._vertices[r+10]=n},i.prototype._update=function(i){this._alive=this.particles.length>0,this.updateFunction(this.particles);var n;n=this.emitter.position?this.emitter.getWorldMatrix():e.Matrix.Translation(this.emitter.x,this.emitter.y,this.emitter.z);for(var r,o=0;i>o&&this.particles.length!==this._capacity;o++){0!==this._stockParticles.length?(r=this._stockParticles.pop(),r.age=0):r=new e.Particle,this.particles.push(r);var s=t(this.minEmitPower,this.maxEmitPower);this.startDirectionFunction(s,n,r.direction,r),r.lifeTime=t(this.minLifeTime,this.maxLifeTime),r.size=t(this.minSize,this.maxSize),r.angularSpeed=t(this.minAngularSpeed,this.maxAngularSpeed),this.startPositionFunction(n,r.position,r);var a=t(0,1);e.Color4.LerpToRef(this.color1,this.color2,a,r.color),this.colorDead.subtractToRef(r.color,this._colorDiff),this._colorDiff.scaleToRef(1/r.lifeTime,r.colorStep)}},i.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},i.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 i=0,n=0;n<this.particles.length;n++){var r=this.particles[n];this._appendParticleVertex(i++,r,0,0),this._appendParticleVertex(i++,r,1,0),this._appendParticleVertex(i++,r,1,1),this._appendParticleVertex(i++,r,0,1)}var o=this._scene.getEngine();o.updateDynamicVertexBuffer(this._vertexBuffer,this._vertices)}}},i.prototype.render=function(){var t=this._getEffect();if(!(this.emitter&&t.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this.particles.length))return 0;var n=this._scene.getEngine();n.enableEffect(t),n.setState(!1);var r=this._scene.getViewMatrix();if(t.setTexture("diffuseSampler",this.particleTexture),t.setMatrix("view",r),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 o=this._scene.clipPlane,s=r.clone();s.invert(),t.setMatrix("invView",s),t.setFloat4("vClipPlane",o.normal.x,o.normal.y,o.normal.z,o.d)}return n.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,t),this.blendMode===i.BLENDMODE_ONEONE?n.setAlphaMode(e.Engine.ALPHA_ONEONE):n.setAlphaMode(e.Engine.ALPHA_COMBINE),this.forceDepthWrite&&n.setDepthWrite(!0),n.draw(!0,0,6*this.particles.length),n.setAlphaMode(e.Engine.ALPHA_DISABLE),this.particles.length},i.prototype.dispose=function(){this._vertexBuffer&&(this._scene.getEngine()._releaseBuffer(this._vertexBuffer),this._vertexBuffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this.particleTexture&&(this.particleTexture.dispose(),this.particleTexture=null);var e=this._scene.particleSystems.indexOf(this);this._scene.particleSystems.splice(e,1),this.onDispose&&this.onDispose()},i.prototype.clone=function(t,n){var r=new i(t,this._capacity,this._scene);return e.Tools.DeepCopy(this,r,["particles"],["_vertexDeclaration","_vertexStrideSize"]),void 0===n&&(n=this.emitter),r.emitter=n,this.particleTexture&&(r.particleTexture=new e.Texture(this.particleTexture.url,this._scene)),r.start(),r},i.prototype.serialize=function(){var t={};return t.name=this.name,t.id=this.id,this.emitter.position?t.emitterId=this.emitter.id:t.emitter=this.emitter.asArray(),t.capacity=this.getCapacity(),this.particleTexture&&(t.textureName=this.particleTexture.name),e.Animation.AppendSerializedAnimations(this,t),t.minAngularSpeed=this.minAngularSpeed,t.maxAngularSpeed=this.maxAngularSpeed,t.minSize=this.minSize,t.maxSize=this.maxSize,t.minEmitPower=this.minEmitPower,t.maxEmitPower=this.maxEmitPower,t.minLifeTime=this.minLifeTime,t.maxLifeTime=this.maxLifeTime,t.emitRate=this.emitRate,t.minEmitBox=this.minEmitBox.asArray(),t.maxEmitBox=this.maxEmitBox.asArray(),t.gravity=this.gravity.asArray(),t.direction1=this.direction1.asArray(),t.direction2=this.direction2.asArray(),t.color1=this.color1.asArray(),t.color2=this.color2.asArray(),t.colorDead=this.colorDead.asArray(),t.updateSpeed=this.updateSpeed,t.targetStopDuration=this.targetStopDuration,t.textureMask=this.textureMask.asArray(),t.blendMode=this.blendMode,t},i.Parse=function(t,n,r){var o=t.name,s=new i(o,t.capacity,n);if(t.id&&(s.id=t.id),t.textureName&&(s.particleTexture=new e.Texture(r+t.textureName,n),s.particleTexture.name=t.textureName),t.emitterId?s.emitter=n.getLastMeshByID(t.emitterId):s.emitter=e.Vector3.FromArray(t.emitter),t.animations)for(var a=0;a<t.animations.length;a++){var h=t.animations[a];s.animations.push(e.Animation.Parse(h))}return t.autoAnimate&&n.beginAnimation(s,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,t.autoAnimateSpeed||1),s.minAngularSpeed=t.minAngularSpeed,s.maxAngularSpeed=t.maxAngularSpeed,s.minSize=t.minSize,s.maxSize=t.maxSize,s.minLifeTime=t.minLifeTime,s.maxLifeTime=t.maxLifeTime,s.minEmitPower=t.minEmitPower,s.maxEmitPower=t.maxEmitPower,s.emitRate=t.emitRate,s.minEmitBox=e.Vector3.FromArray(t.minEmitBox),s.maxEmitBox=e.Vector3.FromArray(t.maxEmitBox),s.gravity=e.Vector3.FromArray(t.gravity),s.direction1=e.Vector3.FromArray(t.direction1),s.direction2=e.Vector3.FromArray(t.direction2),s.color1=e.Color4.FromArray(t.color1),s.color2=e.Color4.FromArray(t.color2),s.colorDead=e.Color4.FromArray(t.colorDead),s.updateSpeed=t.updateSpeed,s.targetStopDuration=t.targetStopDuration,s.textureMask=e.Color4.FromArray(t.textureMask),s.blendMode=t.blendMode,s.start(),s},i.BLENDMODE_ONEONE=0,i.BLENDMODE_STANDARD=1,i}();e.ParticleSystem=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,i){this.name=e,this.from=t,this.to=i}return e.prototype.clone=function(){return new e(this.name,this.from,this.to)},e}();e.AnimationRange=t;var i=function(){function e(e,t,i){this.frame=e,this.action=t,this.onlyOnce=i,this.isDone=!1}return e}();e.AnimationEvent=i;var n=function(){function t(e){this.path=e,this._onchange=new Array,this.value=0,this.animations=new Array}return t.prototype.getPoint=function(){var t=this.path.getPointAtLengthPosition(this.value);return new e.Vector3(t.x,0,t.y)},t.prototype.moveAhead=function(e){return void 0===e&&(e=.002),this.move(e),this},t.prototype.moveBack=function(e){return void 0===e&&(e=.002),this.move(-e),this},t.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},t.prototype.ensureLimits=function(){for(;this.value>1;)this.value-=1;for(;this.value<0;)this.value+=1;return this},t.prototype.markAsDirty=function(e){return this.ensureLimits(),this.raiseOnChange(),this},t.prototype.raiseOnChange=function(){var e=this;return this._onchange.forEach(function(t){return t(e)}),this},t.prototype.onchange=function(e){return this._onchange.push(e),this},t}();e.PathCursor=n;var r=function(){function i(e,t,n,r,o,s){this.name=e,this.targetProperty=t,this.framePerSecond=n,this.dataType=r,this.loopMode=o,this.enableBlending=s,this._offsetsCache={},this._highLimitsCache={},this._stopped=!1,this._blendingFactor=0,this._events=new Array,this.allowMatricesInterpolation=!1,this.blendingSpeed=.01,this._ranges={},this.targetPropertyPath=t.split("."),this.dataType=r,this.loopMode=void 0===o?i.ANIMATIONLOOPMODE_CYCLE:o}return i._PrepareAnimation=function(t,n,r,o,s,a,h,c){var l=void 0;if(!isNaN(parseFloat(s))&&isFinite(s)?l=i.ANIMATIONTYPE_FLOAT:s instanceof e.Quaternion?l=i.ANIMATIONTYPE_QUATERNION:s instanceof e.Vector3?l=i.ANIMATIONTYPE_VECTOR3:s instanceof e.Vector2?l=i.ANIMATIONTYPE_VECTOR2:s instanceof e.Color3&&(l=i.ANIMATIONTYPE_COLOR3),void 0==l)return null;var u=new i(t,n,r,l,h),d=[];return d.push({frame:0,value:s}),d.push({frame:o,value:a}),u.setKeys(d),void 0!==c&&u.setEasingFunction(c),u},i.CreateAndStartAnimation=function(e,t,n,r,o,s,a,h,c,l){var u=i._PrepareAnimation(e,n,r,o,s,a,h,c);return t.getScene().beginDirectAnimation(t,[u],0,o,1===u.loopMode,1,l)},i.CreateMergeAndStartAnimation=function(e,t,n,r,o,s,a,h,c,l){var u=i._PrepareAnimation(e,n,r,o,s,a,h,c);return t.animations.push(u),t.getScene().beginAnimation(t,0,o,1===u.loopMode,1,l)},i.prototype.toString=function(e){var t="Name: "+this.name+", property: "+this.targetProperty;if(t+=", datatype: "+["Float","Vector3","Quaternion","Matrix","Color3","Vector2"][this.dataType],t+=", nKeys: "+(this._keys?this._keys.length:"none"),t+=", nRanges: "+(this._ranges?Object.keys(this._ranges).length:"none"),e){t+=", Ranges: {";var i=!0;for(var n in this._ranges)i||(i=!1),t+=n;t+="}"}return t},i.prototype.addEvent=function(e){this._events.push(e)},i.prototype.removeEvents=function(e){for(var t=0;t<this._events.length;t++)this._events[t].frame===e&&(this._events.splice(t,1),t--)},i.prototype.createRange=function(e,i,n){this._ranges[e]||(this._ranges[e]=new t(e,i,n))},i.prototype.deleteRange=function(e,t){if(void 0===t&&(t=!0),this._ranges[e]){if(t)for(var i=this._ranges[e].from,n=this._ranges[e].to,r=this._keys.length-1;r>=0;r--)this._keys[r].frame>=i&&this._keys[r].frame<=n&&this._keys.splice(r,1);this._ranges[e]=void 0}},i.prototype.getRange=function(e){return this._ranges[e]},i.prototype.reset=function(){this._offsetsCache={},this._highLimitsCache={},this.currentFrame=0,this._blendingFactor=0,this._originalBlendValue=null},i.prototype.isStopped=function(){return this._stopped},i.prototype.getKeys=function(){return this._keys},i.prototype.getHighestFrame=function(){for(var e=0,t=0,i=this._keys.length;i>t;t++)e<this._keys[t].frame&&(e=this._keys[t].frame);return e},i.prototype.getEasingFunction=function(){return this._easingFunction},i.prototype.setEasingFunction=function(e){this._easingFunction=e},i.prototype.floatInterpolateFunction=function(e,t,i){return e+(t-e)*i},i.prototype.quaternionInterpolateFunction=function(t,i,n){return e.Quaternion.Slerp(t,i,n)},i.prototype.vector3InterpolateFunction=function(t,i,n){return e.Vector3.Lerp(t,i,n)},i.prototype.vector2InterpolateFunction=function(t,i,n){return e.Vector2.Lerp(t,i,n)},i.prototype.color3InterpolateFunction=function(t,i,n){return e.Color3.Lerp(t,i,n)},i.prototype.matrixInterpolateFunction=function(t,i,n){return e.Matrix.Lerp(t,i,n)},i.prototype.clone=function(){var e=new i(this.name,this.targetPropertyPath.join("."),this.framePerSecond,this.dataType,this.loopMode);if(this._keys&&e.setKeys(this._keys),this._ranges){e._ranges={};for(var t in this._ranges)e._ranges[t]=this._ranges[t].clone()}return e},i.prototype.setKeys=function(e){this._keys=e.slice(0),this._offsetsCache={},this._highLimitsCache={}},i.prototype._getKeyValue=function(e){return"function"==typeof e?e():e},i.prototype._interpolate=function(e,t,n,r,o){if(n===i.ANIMATIONLOOPMODE_CONSTANT&&t>0)return o.clone?o.clone():o;this.currentFrame=e;var s=Math.max(0,Math.min(this._keys.length-1,Math.floor(this._keys.length*(e-this._keys[0].frame)/(this._keys[this._keys.length-1].frame-this._keys[0].frame))-1));if(this._keys[s].frame>=e)for(;s-1>=0&&this._keys[s].frame>=e;)s--;for(var a=s;a<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 i.ANIMATIONTYPE_FLOAT:switch(n){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:return this.floatInterpolateFunction(h,c,l);case i.ANIMATIONLOOPMODE_RELATIVE:return r*t+this.floatInterpolateFunction(h,c,l)}break;case i.ANIMATIONTYPE_QUATERNION:var u=null;switch(n){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:u=this.quaternionInterpolateFunction(h,c,l);break;case i.ANIMATIONLOOPMODE_RELATIVE:u=this.quaternionInterpolateFunction(h,c,l).add(r.scale(t))}return u;case i.ANIMATIONTYPE_VECTOR3:switch(n){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:return this.vector3InterpolateFunction(h,c,l);case i.ANIMATIONLOOPMODE_RELATIVE:return this.vector3InterpolateFunction(h,c,l).add(r.scale(t))}case i.ANIMATIONTYPE_VECTOR2:switch(n){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:return this.vector2InterpolateFunction(h,c,l);case i.ANIMATIONLOOPMODE_RELATIVE:return this.vector2InterpolateFunction(h,c,l).add(r.scale(t))}case i.ANIMATIONTYPE_COLOR3:switch(n){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:return this.color3InterpolateFunction(h,c,l);case i.ANIMATIONLOOPMODE_RELATIVE:return this.color3InterpolateFunction(h,c,l).add(r.scale(t))}case i.ANIMATIONTYPE_MATRIX:switch(n){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:if(this.allowMatricesInterpolation)return this.matrixInterpolateFunction(h,c,l);case i.ANIMATIONLOOPMODE_RELATIVE:return h}}break}return this._getKeyValue(this._keys[this._keys.length-1].value)},i.prototype.setValue=function(e,t){void 0===t&&(t=!1);var i,n;if(this.targetPropertyPath.length>1){for(var r=this._target[this.targetPropertyPath[0]],o=1;o<this.targetPropertyPath.length-1;o++)r=r[this.targetPropertyPath[o]];i=this.targetPropertyPath[this.targetPropertyPath.length-1],n=r}else i=this.targetPropertyPath[0],n=this._target;this.enableBlending&&this._blendingFactor<=1?(this._originalBlendValue||(this._originalBlendValue=n[i]),this._originalBlendValue.prototype?this._originalBlendValue.prototype.Lerp?n[i]=this._originalBlendValue.prototype.Lerp(e,this._originalBlendValue,this._blendingFactor):n[i]=e:n[i]=this._originalBlendValue*(1-this._blendingFactor)+this._blendingFactor*e,this._blendingFactor+=this.blendingSpeed):n[i]=e,this._target.markAsDirty&&this._target.markAsDirty(this.targetProperty)},i.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)},i.prototype.animate=function(t,n,r,o,s,a){if(void 0===a&&(a=!1),!this.targetPropertyPath||this.targetPropertyPath.length<1)return this._stopped=!0,!1;var h=!0;if(0!==this._keys[0].frame){var c={frame:0,value:this._keys[0].value};this._keys.splice(0,0,c)}(n<this._keys[0].frame||n>this._keys[this._keys.length-1].frame)&&(n=this._keys[0].frame),(r<this._keys[0].frame||r>this._keys[this._keys.length-1].frame)&&(r=this._keys[this._keys.length-1].frame);var l,u=r-n,d=t*(this.framePerSecond*s)/1e3,f=0;if(d>u&&!o)h=!1,f=this._getKeyValue(this._keys[this._keys.length-1].value);else if(this.loopMode!==i.ANIMATIONLOOPMODE_CYCLE){var p=r.toString()+n.toString();if(!this._offsetsCache[p]){var m=this._interpolate(n,0,i.ANIMATIONLOOPMODE_CYCLE),_=this._interpolate(r,0,i.ANIMATIONLOOPMODE_CYCLE);switch(this.dataType){case i.ANIMATIONTYPE_FLOAT:this._offsetsCache[p]=_-m;break;case i.ANIMATIONTYPE_QUATERNION:this._offsetsCache[p]=_.subtract(m);break;case i.ANIMATIONTYPE_VECTOR3:this._offsetsCache[p]=_.subtract(m);case i.ANIMATIONTYPE_VECTOR2:this._offsetsCache[p]=_.subtract(m);case i.ANIMATIONTYPE_COLOR3:this._offsetsCache[p]=_.subtract(m)}this._highLimitsCache[p]=_}f=this._highLimitsCache[p],l=this._offsetsCache[p]}if(void 0===l)switch(this.dataType){case i.ANIMATIONTYPE_FLOAT:l=0;break;case i.ANIMATIONTYPE_QUATERNION:l=new e.Quaternion(0,0,0,0);break;case i.ANIMATIONTYPE_VECTOR3:l=e.Vector3.Zero();break;case i.ANIMATIONTYPE_VECTOR2:l=e.Vector2.Zero();break;case i.ANIMATIONTYPE_COLOR3:l=e.Color3.Black()}var g=d/u>>0,v=h?n+d%u:r,y=this._interpolate(v,g,this.loopMode,l,f);this.setValue(y);for(var x=0;x<this._events.length;x++)if(v>=this._events[x].frame){var b=this._events[x];b.isDone||(b.onlyOnce&&(this._events.splice(x,1),x--),b.isDone=!0,b.action())}else this._events[x].isDone&&!this._events[x].onlyOnce&&(this._events[x].isDone=!1);return h||(this._stopped=!0),h},i.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 n=this.getKeys(),r=0;r<n.length;r++){var o=n[r],s={};switch(s.frame=o.frame,t){case i.ANIMATIONTYPE_FLOAT:s.values=[o.value];break;case i.ANIMATIONTYPE_QUATERNION:case i.ANIMATIONTYPE_MATRIX:case i.ANIMATIONTYPE_VECTOR3:case i.ANIMATIONTYPE_COLOR3:s.values=o.value.asArray()}e.keys.push(s)}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(i,"ANIMATIONTYPE_FLOAT",{get:function(){return i._ANIMATIONTYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONTYPE_VECTOR3",{get:function(){return i._ANIMATIONTYPE_VECTOR3},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONTYPE_VECTOR2",{get:function(){return i._ANIMATIONTYPE_VECTOR2},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONTYPE_QUATERNION",{get:function(){return i._ANIMATIONTYPE_QUATERNION},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONTYPE_MATRIX",{get:function(){return i._ANIMATIONTYPE_MATRIX},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONTYPE_COLOR3",{get:function(){return i._ANIMATIONTYPE_COLOR3},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONLOOPMODE_RELATIVE",{get:function(){return i._ANIMATIONLOOPMODE_RELATIVE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONLOOPMODE_CYCLE",{get:function(){return i._ANIMATIONLOOPMODE_CYCLE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONLOOPMODE_CONSTANT",{get:function(){return i._ANIMATIONLOOPMODE_CONSTANT},enumerable:!0,configurable:!0}),i.Parse=function(t){for(var n=new i(t.name,t.property,t.framePerSecond,t.dataType,t.loopBehavior),r=t.dataType,o=[],s=0;s<t.keys.length;s++){var a,h=t.keys[s];switch(r){case i.ANIMATIONTYPE_FLOAT:a=h.values[0];break;case i.ANIMATIONTYPE_QUATERNION:a=e.Quaternion.FromArray(h.values);break;case i.ANIMATIONTYPE_MATRIX:a=e.Matrix.FromArray(h.values);break;case i.ANIMATIONTYPE_COLOR3:a=e.Color3.FromArray(h.values);break;case i.ANIMATIONTYPE_VECTOR3:default:a=e.Vector3.FromArray(h.values)}o.push({frame:h.frame,value:a})}if(n.setKeys(o),t.ranges)for(var s=0;s<t.ranges.length;s++)a=t.ranges[s],n.createRange(a.name,a.from,a.to);return n},i.AppendSerializedAnimations=function(e,t){if(e.animations){t.animations=[];for(var i=0;i<e.animations.length;i++){var n=e.animations[i];t.animations.push(n.serialize())}}},i._ANIMATIONTYPE_FLOAT=0,i._ANIMATIONTYPE_VECTOR3=1,i._ANIMATIONTYPE_QUATERNION=2,i._ANIMATIONTYPE_MATRIX=3,i._ANIMATIONTYPE_COLOR3=4,i._ANIMATIONTYPE_VECTOR2=5,i._ANIMATIONLOOPMODE_RELATIVE=0,i._ANIMATIONLOOPMODE_CYCLE=1,i._ANIMATIONLOOPMODE_CONSTANT=2,i}();e.Animation=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,i,n,r,o,s,a){void 0===i&&(i=0),void 0===n&&(n=100),void 0===r&&(r=!1),void 0===o&&(o=1),this.target=t,this.fromFrame=i,this.toFrame=n,this.loopAnimation=r,this.speedRatio=o,this.onAnimationEnd=s,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 i=0;i<t.length;i++){var n=t[i];n._target=e,this._animations.push(n)}},e.prototype.getAnimationByTargetProperty=function(e){for(var t=this._animations,i=0;i<t.length;i++)if(t[i].targetProperty===e)return t[i];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.enableBlending=function(e){for(var t=this._animations,i=0;i<t.length;i++)t[i].enableBlending=!0,t[i].blendingSpeed=e},e.prototype.disableBlending=function(){for(var e=this._animations,t=0;t<e.length;t++)e[t].enableBlending=!1},e.prototype.goToFrame=function(e){for(var t=this._animations,i=0;i<t.length;i++)t[i].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);if(e>-1){this._scene._activeAnimatables.splice(e,1);for(var t=this._animations,e=0;e<t.length;e++)t[e].reset();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,i=!1,n=this._animations;for(t=0;t<n.length;t++){var r=n[t],o=r.animate(e-this._localDelayOffset,this.fromFrame,this.toFrame,this.loopAnimation,this.speedRatio);i=i||o}return this.animationStarted=i,i||(t=this._scene._activeAnimatables.indexOf(this),this._scene._activeAnimatables.splice(t,1)),!i&&this.onAnimationEnd&&(this.onAnimationEnd(),this.onAnimationEnd=null),i},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 i=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=i;var n=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=n;var r=function(e){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=2),e.call(this),this.bounces=t,this.bounciness=i}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.bounces),i=this.bounciness;1>=i&&(i=1.001);var n=Math.pow(i,t),r=1-i,o=(1-n)/r+.5*n,s=e*o,a=Math.log(-s*(1-i)+1)/Math.log(i),h=Math.floor(a),c=h+1,l=(1-Math.pow(i,h))/(r*o),u=(1-Math.pow(i,c))/(r*o),d=.5*(l+u),f=e-d,p=d-l;return-Math.pow(1/i,t-h)/(p*p)*(f-p)*(f+p)},t}(t);e.BounceEase=r;var o=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e},t}(t);e.CubicEase=o;var s=function(e){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=3),e.call(this),this.oscillations=t,this.springiness=i}return __extends(t,e),t.prototype.easeInCore=function(e){var t,i=Math.max(0,this.oscillations),n=Math.max(0,this.springiness);return t=0==n?e:(Math.exp(n*e)-1)/(Math.exp(n)-1),t*Math.sin((6.283185307179586*i+1.5707963267948966)*e)},t}(t);e.ElasticEase=s;var a=function(e){function t(t){void 0===t&&(t=2),e.call(this),this.exponent=t}return __extends(t,e),t.prototype.easeInCore=function(e){return this.exponent<=0?e:(Math.exp(this.exponent*e)-1)/(Math.exp(this.exponent)-1)},t}(t);e.ExponentialEase=a;var h=function(e){function t(t){void 0===t&&(t=2),e.call(this),this.power=t}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.power);return Math.pow(e,t)},t}(t);e.PowerEase=h;var c=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e},t}(t);e.QuadraticEase=c;var l=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e},t}(t);e.QuarticEase=l;var u=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e*e},t}(t);e.QuinticEase=u;var d=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=d;var f=function(t){function i(e,i,n,r){void 0===e&&(e=0),void 0===i&&(i=0),void 0===n&&(n=1),void 0===r&&(r=1),t.call(this),this.x1=e,this.y1=i,this.x2=n,this.y2=r}return __extends(i,t),i.prototype.easeInCore=function(t){return e.BezierCurve.interpolate(t,this.x1,this.y1,this.x2,this.y2)},i}(t);e.BezierCurveEase=f}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s){t.call(this,i,n.getScene()),this.name=i,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=n,this._matrix=o,this._baseMatrix=o,this._restPose=s?s:o.clone(),n.bones.push(this),r?(this._parent=r,r.children.push(this)):this._parent=null,this._updateDifferenceMatrix()}return __extends(i,t),i.prototype.getParent=function(){return this._parent},i.prototype.getLocalMatrix=function(){return this._matrix},i.prototype.getBaseMatrix=function(){return this._baseMatrix},i.prototype.getRestPose=function(){return this._restPose},i.prototype.returnToRest=function(){this.updateMatrix(this._restPose.clone())},i.prototype.getWorldMatrix=function(){return this._worldTransform},i.prototype.getInvertedAbsoluteTransform=function(){return this._invertedAbsoluteTransform},i.prototype.getAbsoluteTransform=function(){return this._absoluteTransform},i.prototype.updateMatrix=function(e){this._baseMatrix=e.clone(),this._matrix=e.clone(),this._skeleton._markAsDirty(),this._updateDifferenceMatrix()},i.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()},i.prototype.markAsDirty=function(){this._currentRenderId++,this._skeleton._markAsDirty()},i.prototype.copyAnimationRange=function(t,i,n,r){void 0===r&&(r=!1),0===this.animations.length&&(this.animations.push(new e.Animation(this.name,"_matrix",t.animations[0].framePerSecond,e.Animation.ANIMATIONTYPE_MATRIX,0)),this.animations[0].setKeys([]));var o=t.animations[0].getRange(i);if(!o)return!1;for(var s,a,h=o.from,c=o.to,l=t.animations[0].getKeys(),u=t.length,d=r&&u&&this.length&&u!==this.length,f=d?this.length/u:null,p=this.animations[0].getKeys(),m=d?e.Vector3.Zero():null,_=d?new e.Quaternion:null,g=d?e.Vector3.Zero():null,v=0,y=l.length;y>v;v++)s=l[v],s.frame>=h&&s.frame<=c&&(d?(s.value.decompose(m,_,g),g.scaleInPlace(f),a=e.Matrix.Compose(m,_,g)):a=s.value,p.push({frame:s.frame+n,value:a}));return this.animations[0].createRange(i,h+n,c+n),!0},i}(e.Node);e.Bone=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,n){this.name=t,this.id=i,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=n,n.skeletons.push(this),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.toString=function(e){var t="Name: "+this.name+", nBones: "+this.bones.length;if(t+=", nAnimationRanges: "+(this._ranges?Object.keys(this._ranges).length:"none"),
  17. e){t+=", Ranges: {";var i=!0;for(var n in this._ranges)i||(i=!1),t+=n;t+="}"}return t},t.prototype.getBoneIndexByName=function(e){for(var t=0,i=this.bones.length;i>t;t++)if(this.bones[t].name===e)return t;return-1},t.prototype.createAnimationRange=function(t,i,n){if(!this._ranges[t]){this._ranges[t]=new e.AnimationRange(t,i,n);for(var r=0,o=this.bones.length;o>r;r++)this.bones[r].animations[0]&&this.bones[r].animations[0].createRange(t,i,n)}},t.prototype.deleteAnimationRange=function(e,t){void 0===t&&(t=!0);for(var i=0,n=this.bones.length;n>i;i++)this.bones[i].animations[0]&&this.bones[i].animations[0].deleteRange(e,t);this._ranges[e]=void 0},t.prototype.getAnimationRange=function(e){return this._ranges[e]},t.prototype.getAnimationRanges=function(){var e,t=[],i=0;for(e in this._ranges)t[i]=this._ranges[e],i++;return t},t.prototype.copyAnimationRange=function(t,i,n){if(void 0===n&&(n=!1),this._ranges[i]||!t.getAnimationRange(i))return!1;for(var r=!0,o=this._getHighestAnimationFrame()+1,s={},a=t.bones,h=0,c=a.length;c>h;h++)s[a[h].name]=a[h];this.bones.length!==a.length&&(e.Tools.Warn("copyAnimationRange: this rig has "+this.bones.length+" bones, while source as "+a.length),r=!1);for(var h=0,c=this.bones.length;c>h;h++){var l=this.bones[h].name,u=s[l];u?r=r&&this.bones[h].copyAnimationRange(u,i,o,n):(e.Tools.Warn("copyAnimationRange: not same rig, missing source bone "+l),r=!1)}var d=t.getAnimationRange(i);return this._ranges[i]=new e.AnimationRange(i,d.from+o,d.to+o),r},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,i=this.bones.length;i>t;t++)if(this.bones[t].animations[0]){var n=this.bones[t].animations[0].getHighestFrame();n>e&&(e=n)}return e},t.prototype.beginAnimation=function(e,t,i,n){var r=this.getAnimationRange(e);return r?void this._scene.beginAnimation(this,r.from,r.to,t,i,n):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 i=0;i<this.bones.length;i++){var n=this.bones[i],r=n.getParent();r?n.getLocalMatrix().multiplyToRef(r.getWorldMatrix(),n.getWorldMatrix()):t?n.getLocalMatrix().multiplyToRef(t,n.getWorldMatrix()):n.getWorldMatrix().copyFrom(n.getLocalMatrix()),n.getInvertedAbsoluteTransform().multiplyToArray(n.getWorldMatrix(),e,16*i)}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 i=this._meshesWithPoseMatrix[t];i._bonesTransformMatrices&&i._bonesTransformMatrices.length===16*(this.bones.length+1)||(i._bonesTransformMatrices=new Float32Array(16*(this.bones.length+1)));for(var n=i.getPoseMatrix(),r=0;r<this.bones.length;r++){var o=this.bones[r];if(!o.getParent()){var s=o.getBaseMatrix();s.multiplyToRef(n,e.Tmp.Matrix[0]),o._updateDifferenceMatrix(e.Tmp.Matrix[0])}}this._computeTransformMatrices(i._bonesTransformMatrices,n)}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(i,n){var r=new t(i,n||i,this._scene);r.needInitialSkinMatrix=this.needInitialSkinMatrix;for(var o=0;o<this.bones.length;o++){var s=this.bones[o],a=null;if(s.getParent()){var h=this.bones.indexOf(s.getParent());a=r.bones[h]}var c=new e.Bone(s.name,r,a,s.getBaseMatrix().clone(),s.getRestPose().clone());e.Tools.DeepCopy(s.animations,c.animations)}if(this._ranges){r._ranges={};for(var l in this._ranges)r._ranges[l]=this._ranges[l].clone()}return this._isDirty=!0,r},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 i=this.bones[t],n={parentBoneIndex:i.getParent()?this.bones.indexOf(i.getParent()):-1,name:i.name,matrix:i.getLocalMatrix().toArray(),rest:i.getRestPose().toArray()};e.bones.push(n),i.length&&(n.length=i.length),i.animations&&i.animations.length>0&&(n.animation=i.animations[0].serialize()),e.ranges=[];for(var r in this._ranges){var o={};o.name=r,o.from=this._ranges[r].from,o.to=this._ranges[r].to,e.ranges.push(o)}}return e},t.Parse=function(i,n){var r=new t(i.name,i.id,n);r.needInitialSkinMatrix=i.needInitialSkinMatrix;for(var o=0;o<i.bones.length;o++){var s=i.bones[o],a=null;s.parentBoneIndex>-1&&(a=r.bones[s.parentBoneIndex]);var h=s.rest?e.Matrix.FromArray(s.rest):null,c=new e.Bone(s.name,r,a,e.Matrix.FromArray(s.matrix),h);s.length&&(c.length=s.length),s.animation&&c.animations.push(e.Animation.Parse(s.animation))}if(i.ranges)for(var o=0;o<i.ranges.length;o++){var l=i.ranges[o];r.createAnimationRange(l.name,l.from,l.to)}return r},t}();e.Skeleton=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,n,r,o,s,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!=s?(this._camera=s,this._scene=s.getScene(),s.attachPostProcess(this),this._engine=this._scene.getEngine()):this._engine=h,this._renderRatio=o,this.renderTargetSamplingMode=a?a:e.Texture.NEAREST_SAMPLINGMODE,this._reusable=c||!1,this._textureType=u,this._samplers=r||[],this._samplers.push("textureSampler"),this._fragmentUrl=i,this._parameters=n||[],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,i){t=t||this._camera;var n=t.getScene(),r=t.getEngine().getCaps().maxTextureSize,o=(i?i._width:this._engine.getRenderingCanvas().width)*this._renderRatio|0,s=(i?i._height:this._engine.getRenderingCanvas().height)*this._renderRatio|0;if(o=this._renderRatio.width||e.Tools.GetExponentOfTwo(o,r),s=this._renderRatio.height||e.Tools.GetExponentOfTwo(s,r),this.width!==o||this.height!==s){if(this._textures.length>0){for(var a=0;a<this._textures.length;a++)this._engine._releaseTexture(this._textures.data[a]);this._textures.reset()}this.width=o,this.height=s,this._textures.push(this._engine.createRenderTargetTexture({width:this.width,height:this.height},{generateMipMaps:!1,generateDepthBuffer: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(n.clearColor,n.autoClear||n.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 i=e._postProcesses.indexOf(this);i===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,i=this._scene.activeCamera._postProcessesTakenIndices;return 0!==i.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 i=this._scene.getEngine(),n=0;n<e.length;n++){n<e.length-1?e[n+1].activate(this._scene.activeCamera,t):t?i.bindFramebuffer(t):i.restoreDefaultFramebuffer();var r=e[n],o=r.apply();o&&(r.onBeforeRender&&r.onBeforeRender(o),this._prepareBuffers(),i.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,o),i.draw(!0,0,6),r.onAfterRender&&r.onAfterRender(o))}i.setDepthBuffer(!0),i.setDepthWrite(!0)},e.prototype._finalizeFrame=function(e,t,i,n){n=n||this._scene.activeCamera._postProcesses;var r=this._scene.activeCamera._postProcessesTakenIndices;if(0!==r.length&&this._scene.postProcessesEnabled){for(var o=this._scene.getEngine(),s=0;s<r.length&&(s<r.length-1?n[r[s+1]].activate(this._scene.activeCamera,t):t?o.bindFramebuffer(t,i):o.restoreDefaultFramebuffer(),!e);s++){var a=n[r[s]],h=a.apply();h&&(a.onBeforeRender&&a.onBeforeRender(h),this._prepareBuffers(),o.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,h),o.draw(!0,0,6),a.onAfterRender&&a.onAfterRender(h))}o.setDepthBuffer(!0),o.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,i,n,r,o,s){e.call(this,t,"pass",null,null,i,n,r,o,s)}return __extends(t,e),t}(e.PostProcess);e.PassPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t){this.type=e,this.jointData=t,t.nativeParams=t.nativeParams||{}}return Object.defineProperty(e.prototype,"physicsJoint",{get:function(){return this._physicsJoint},set:function(e){this._physicsJoint,this._physicsJoint=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"physicsPlugin",{set:function(e){this._physicsPlugin=e},enumerable:!0,configurable:!0}),e.prototype.executeNativeFunction=function(e){e(this._physicsPlugin.world,this._physicsJoint)},e.DistanceJoint=0,e.HingeJoint=1,e.BallAndSocketJoint=2,e.WheelJoint=3,e.SliderJoint=4,e.PrismaticJoint=5,e.UniversalJoint=6,e.Hinge2Joint=e.WheelJoint,e.PointToPointJoint=8,e.SpringJoint=9,e}();e.PhysicsJoint=t;var i=function(e){function i(i){e.call(this,t.DistanceJoint,i)}return __extends(i,e),i.prototype.updateDistance=function(e,t){this._physicsPlugin.updateDistanceJoint(this,e,t)},i}(t);e.DistanceJoint=i;var n=function(e){function i(i){e.call(this,t.HingeJoint,i)}return __extends(i,e),i.prototype.setMotor=function(e,t){this._physicsPlugin.setMotor(this,e,t)},i.prototype.setLimit=function(e,t){this._physicsPlugin.setLimit(this,e,t)},i}(t);e.HingeJoint=n;var r=function(e){function i(i){e.call(this,t.Hinge2Joint,i)}return __extends(i,e),i.prototype.setMotor=function(e,t,i){void 0===i&&(i=0),this._physicsPlugin.setMotor(this,e,t,i)},i.prototype.setLimit=function(e,t,i){void 0===i&&(i=0),this._physicsPlugin.setLimit(this,e,t,i)},i}(t);e.Hinge2Joint=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,n,r){var o=this;return void 0===n&&(n={mass:0}),this.object=t,this.type=i,this._options=n,this._scene=r,this._bodyUpdateRequired=!1,this._onBeforePhysicsStepCallbacks=new Array,this._onAfterPhysicsStepCallbacks=new Array,this._onPhysicsCollideCallbacks=[],this._deltaPosition=e.Vector3.Zero(),this._tmpPositionWithDelta=e.Vector3.Zero(),this._tmpRotationWithDelta=new e.Quaternion,this.beforeStep=function(){o.object.position.subtractToRef(o._deltaPosition,o._tmpPositionWithDelta),o._deltaRotationConjugated?o.object.rotationQuaternion.multiplyToRef(o._deltaRotationConjugated,o._tmpRotationWithDelta):o._tmpRotationWithDelta.copyFrom(o.object.rotationQuaternion),o._physicsEngine.getPhysicsPlugin().setPhysicsBodyTransformation(o,o._tmpPositionWithDelta,o._tmpRotationWithDelta),o._onBeforePhysicsStepCallbacks.forEach(function(e){e(o)})},this.afterStep=function(){o._onAfterPhysicsStepCallbacks.forEach(function(e){e(o)}),o._physicsEngine.getPhysicsPlugin().setTransformationFromPhysicsBody(o),o.object.position.addInPlace(o._deltaPosition),o._deltaRotation&&o.object.rotationQuaternion.multiplyInPlace(o._deltaRotation)},this.onCollide=function(e){var t=o._physicsEngine.getImpostorWithPhysicsBody(e.body);t&&o._onPhysicsCollideCallbacks.filter(function(e){return-1!==e.otherImpostors.indexOf(t)}).forEach(function(e){e.callback(o,t)})},this.object?(!this._scene&&t.getScene&&(this._scene=t.getScene()),this._physicsEngine=this._scene.getPhysicsEngine(),void(this._physicsEngine?(this.object.rotationQuaternion||(this.object.rotation?this.object.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(this.object.rotation.y,this.object.rotation.x,this.object.rotation.z):this.object.rotationQuaternion=new e.Quaternion),this._options.mass=void 0===n.mass?0:n.mass,this._options.friction=void 0===n.friction?.2:n.friction,this._options.restitution=void 0===n.restitution?.2:n.restitution,this._joints=[],this.object.parent||this._init()):e.Tools.Error("Physics not enabled. Please use scene.enablePhysics(...) before creating impostors."))):void e.Tools.Error("No object was provided. A physics object is obligatory")}return t.prototype._init=function(){this._physicsEngine.removeImpostor(this),this.physicsBody=null,this._parent=this._parent||this._getPhysicsParent(),this.parent||this._physicsEngine.addImpostor(this)},t.prototype._getPhysicsParent=function(){if(this.object.parent instanceof e.AbstractMesh){var t=this.object.parent;return t.physicsImpostor}},t.prototype.isBodyInitRequired=function(){return this._bodyUpdateRequired||!this._physicsBody&&!this._parent},t.prototype.setScalingUpdated=function(e){this.forceUpdate()},t.prototype.forceUpdate=function(){this._init(),this.parent&&this.parent.forceUpdate()},Object.defineProperty(t.prototype,"physicsBody",{get:function(){return this._parent?this._parent.physicsBody:this._physicsBody},set:function(e){this._physicsBody&&this._physicsEngine.getPhysicsPlugin().removePhysicsBody(this),this._physicsBody=e,this.resetUpdateFlags()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),t.prototype.resetUpdateFlags=function(){this._bodyUpdateRequired=!1},t.prototype.getObjectExtendSize=function(){return this.object.getBoundingInfo?(this.object.computeWorldMatrix&&this.object.computeWorldMatrix(!0),this.object.getBoundingInfo().boundingBox.extendSize.scale(2).multiply(this.object.scaling)):t.DEFAULT_OBJECT_SIZE},t.prototype.getObjectCenter=function(){return this.object.getBoundingInfo?this.object.getBoundingInfo().boundingBox.center:this.object.position},t.prototype.getParam=function(e){return this._options[e]},t.prototype.setParam=function(e,t){this._options[e]=t,this._bodyUpdateRequired=!0},t.prototype.setMass=function(e){this.getParam("mass")!==e&&this.setParam("mass",e),this._physicsEngine.getPhysicsPlugin().setBodyMass(this,e)},t.prototype.getLinearVelocity=function(){return this._physicsEngine.getPhysicsPlugin().getLinearVelocity(this)},t.prototype.setLinearVelocity=function(e){this._physicsEngine.getPhysicsPlugin().setLinearVelocity(this,e)},t.prototype.getAngularVelocity=function(){return this._physicsEngine.getPhysicsPlugin().getAngularVelocity(this)},t.prototype.setAngularVelocity=function(e){this._physicsEngine.getPhysicsPlugin().setAngularVelocity(this,e)},t.prototype.executeNativeFunction=function(e){e(this._physicsEngine.getPhysicsPlugin().world,this.physicsBody)},t.prototype.registerBeforePhysicsStep=function(e){this._onBeforePhysicsStepCallbacks.push(e)},t.prototype.unregisterBeforePhysicsStep=function(t){var i=this._onBeforePhysicsStepCallbacks.indexOf(t);i>-1?this._onBeforePhysicsStepCallbacks.splice(i,1):e.Tools.Warn("Function to remove was not found")},t.prototype.registerAfterPhysicsStep=function(e){this._onAfterPhysicsStepCallbacks.push(e)},t.prototype.unregisterAfterPhysicsStep=function(t){var i=this._onAfterPhysicsStepCallbacks.indexOf(t);i>-1?this._onAfterPhysicsStepCallbacks.splice(i,1):e.Tools.Warn("Function to remove was not found")},t.prototype.registerOnPhysicsCollide=function(e,t){var i=e instanceof Array?e:[e];this._onPhysicsCollideCallbacks.push({callback:t,otherImpostors:i})},t.prototype.unregisterOnPhysicsCollide=function(t,i){var n=t instanceof Array?t:[t],r=this._onPhysicsCollideCallbacks.indexOf({callback:i,otherImpostors:n});r>-1?this._onPhysicsCollideCallbacks.splice(r,1):e.Tools.Warn("Function to remove was not found")},t.prototype.applyForce=function(e,t){this._physicsEngine.getPhysicsPlugin().applyForce(this,e,t)},t.prototype.applyImpulse=function(e,t){this._physicsEngine.getPhysicsPlugin().applyImpulse(this,e,t)},t.prototype.createJoint=function(t,i,n){var r=new e.PhysicsJoint(i,n);this.addJoint(t,r)},t.prototype.addJoint=function(e,t){this._joints.push({otherImpostor:e,joint:t}),this._physicsEngine.addJoint(this,e,t)},t.prototype.sleep=function(){this._physicsEngine.getPhysicsPlugin().sleepBody(this)},t.prototype.wakeUp=function(){this._physicsEngine.getPhysicsPlugin().wakeUpBody(this)},t.prototype.clone=function(e){return e?new t(e,this.type,this._options,this._scene):null},t.prototype.dispose=function(){this.physicsBody=null,this.parent&&this.parent.forceUpdate()},t.prototype.setDeltaPosition=function(e){this._deltaPosition.copyFrom(e)},t.prototype.setDeltaRotation=function(t){this._deltaRotation||(this._deltaRotation=new e.Quaternion),this._deltaRotation.copyFrom(t),this._deltaRotationConjugated=this._deltaRotation.conjugate()},t.DEFAULT_OBJECT_SIZE=new e.Vector3(1,1,1),t.NoImpostor=0,t.SphereImpostor=1,t.BoxImpostor=2,t.PlaneImpostor=3,t.MeshImpostor=4,t.CylinderImpostor=7,t.ParticleImpostor=8,t.HeightmapImpostor=9,t}();e.PhysicsImpostor=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){if(void 0===i&&(i=new e.CannonJSPlugin),this._physicsPlugin=i,this._impostors=[],this._joints=[],!this._physicsPlugin.isSupported())throw new Error("Physics Engine "+this._physicsPlugin.name+" cannot be found. Please make sure it is included.");t=t||new e.Vector3(0,-9.807,0),this.setGravity(t),this.setTimeStep()}return t.prototype.setGravity=function(e){this.gravity=e,this._physicsPlugin.setGravity(this.gravity)},t.prototype.setTimeStep=function(e){void 0===e&&(e=1/60),this._physicsPlugin.setTimeStep(e)},t.prototype.dispose=function(){this._impostors.forEach(function(e){e.dispose()}),this._physicsPlugin.dispose()},t.prototype.getPhysicsPluginName=function(){return this._physicsPlugin.name},t.prototype.addImpostor=function(e){e.uniqueId=this._impostors.push(e),e.parent||this._physicsPlugin.generatePhysicsBody(e)},t.prototype.removeImpostor=function(e){var t=this._impostors.indexOf(e);if(t>-1){var i=this._impostors.splice(t,1);i.length&&(i[0].physicsBody=null)}},t.prototype.addJoint=function(e,t,i){var n={mainImpostor:e,connectedImpostor:t,joint:i};i.physicsPlugin=this._physicsPlugin,this._joints.push(n),this._physicsPlugin.generateJoint(n)},t.prototype.removeJoint=function(e,t,i){var n=this._joints.filter(function(n){return n.connectedImpostor===t&&n.joint===i&&n.mainImpostor===e});n.length&&this._physicsPlugin.removeJoint(n[0])},t.prototype._step=function(e){var t=this;this._impostors.forEach(function(e){e.isBodyInitRequired()&&t._physicsPlugin.generatePhysicsBody(e)}),e>.1?e=.1:0>=e&&(e=1/60),this._physicsPlugin.executeStep(e,this._impostors)},t.prototype.getPhysicsPlugin=function(){return this._physicsPlugin},t.prototype.getImpostorForPhysicsObject=function(e){for(var t=0;t<this._impostors.length;++t)if(this._impostors[t].object===e)return this._impostors[t]},t.prototype.getImpostorWithPhysicsBody=function(e){for(var t=0;t<this._impostors.length;++t)if(this._impostors[t].physicsBody===e)return this._impostors[t]},t.NoImpostor=e.PhysicsImpostor.NoImpostor,t.SphereImpostor=e.PhysicsImpostor.SphereImpostor,t.BoxImpostor=e.PhysicsImpostor.BoxImpostor,t.PlaneImpostor=e.PhysicsImpostor.PlaneImpostor,t.MeshImpostor=e.PhysicsImpostor.MeshImpostor,t.CylinderImpostor=e.PhysicsImpostor.CylinderImpostor,t.HeightmapImpostor=e.PhysicsImpostor.HeightmapImpostor,t.CapsuleImpostor=-1,t.ConeImpostor=-1,t.ConvexHullImpostor=-1,t.Epsilon=.001,t}();e.PhysicsEngine=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.prototype.set=function(t,i){switch(i){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,i){this._update(e)},t.prototype.updateGeometry=function(e,t,i){this._update(e)},t.prototype._applyTo=function(t,i){this.positions&&t.setVerticesData(e.VertexBuffer.PositionKind,this.positions,i),this.normals&&t.setVerticesData(e.VertexBuffer.NormalKind,this.normals,i),this.uvs&&t.setVerticesData(e.VertexBuffer.UVKind,this.uvs,i),this.uvs2&&t.setVerticesData(e.VertexBuffer.UV2Kind,this.uvs2,i),this.uvs3&&t.setVerticesData(e.VertexBuffer.UV3Kind,this.uvs3,i),this.uvs4&&t.setVerticesData(e.VertexBuffer.UV4Kind,this.uvs4,i),this.uvs5&&t.setVerticesData(e.VertexBuffer.UV5Kind,this.uvs5,i),this.uvs6&&t.setVerticesData(e.VertexBuffer.UV6Kind,this.uvs6,i),this.colors&&t.setVerticesData(e.VertexBuffer.ColorKind,this.colors,i),this.matricesIndices&&t.setVerticesData(e.VertexBuffer.MatricesIndicesKind,this.matricesIndices,i),this.matricesWeights&&t.setVerticesData(e.VertexBuffer.MatricesWeightsKind,this.matricesWeights,i),this.matricesIndicesExtra&&t.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,this.matricesIndicesExtra,i),this.matricesWeightsExtra&&t.setVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,this.matricesWeightsExtra,i),this.indices&&t.setIndices(this.indices)},t.prototype._update=function(t,i,n){this.positions&&t.updateVerticesData(e.VertexBuffer.PositionKind,this.positions,i,n),this.normals&&t.updateVerticesData(e.VertexBuffer.NormalKind,this.normals,i,n),this.uvs&&t.updateVerticesData(e.VertexBuffer.UVKind,this.uvs,i,n),this.uvs2&&t.updateVerticesData(e.VertexBuffer.UV2Kind,this.uvs2,i,n),this.uvs3&&t.updateVerticesData(e.VertexBuffer.UV3Kind,this.uvs3,i,n),this.uvs4&&t.updateVerticesData(e.VertexBuffer.UV4Kind,this.uvs4,i,n),this.uvs5&&t.updateVerticesData(e.VertexBuffer.UV5Kind,this.uvs5,i,n),this.uvs6&&t.updateVerticesData(e.VertexBuffer.UV6Kind,this.uvs6,i,n),this.colors&&t.updateVerticesData(e.VertexBuffer.ColorKind,this.colors,i,n),this.matricesIndices&&t.updateVerticesData(e.VertexBuffer.MatricesIndicesKind,this.matricesIndices,i,n),this.matricesWeights&&t.updateVerticesData(e.VertexBuffer.MatricesWeightsKind,this.matricesWeights,i,n),this.matricesIndicesExtra&&t.updateVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,this.matricesIndicesExtra,i,n),this.matricesWeightsExtra&&t.updateVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,this.matricesWeightsExtra,i,n),this.indices&&t.setIndices(this.indices)},t.prototype.transform=function(t){var i,n=e.Vector3.Zero();if(this.positions){var r=e.Vector3.Zero();for(i=0;i<this.positions.length;i+=3)e.Vector3.FromArrayToRef(this.positions,i,r),e.Vector3.TransformCoordinatesToRef(r,t,n),this.positions[i]=n.x,this.positions[i+1]=n.y,this.positions[i+2]=n.z}if(this.normals){var o=e.Vector3.Zero();for(i=0;i<this.normals.length;i+=3)e.Vector3.FromArrayToRef(this.normals,i,o),e.Vector3.TransformNormalToRef(o,t,n),this.normals[i]=n.x,this.normals[i+1]=n.y,this.normals[i+2]=n.z}},t.prototype.merge=function(e){if(e.indices){this.indices||(this.indices=[]);for(var t=this.positions?this.positions.length/3:0,i=0;i<e.indices.length;i++)this.indices.push(e.indices[i]+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 i=t.length+e.length,n=e instanceof Float32Array,r=t instanceof Float32Array;if(n){var o=new Float32Array(i);return o.set(e),o.set(t,e.length),o}if(r){for(var s=e.slice(0),a=0,i=t.length;i>a;a++)s.push(t[a]);return s}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,i){return t._ExtractFrom(e,i)},t.ExtractFromGeometry=function(e,i){return t._ExtractFrom(e,i)},t._ExtractFrom=function(i,n){var r=new t;return i.isVerticesDataPresent(e.VertexBuffer.PositionKind)&&(r.positions=i.getVerticesData(e.VertexBuffer.PositionKind,n)),i.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(r.normals=i.getVerticesData(e.VertexBuffer.NormalKind,n)),i.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(r.uvs=i.getVerticesData(e.VertexBuffer.UVKind,n)),i.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(r.uvs2=i.getVerticesData(e.VertexBuffer.UV2Kind,n)),i.isVerticesDataPresent(e.VertexBuffer.UV3Kind)&&(r.uvs3=i.getVerticesData(e.VertexBuffer.UV3Kind,n)),i.isVerticesDataPresent(e.VertexBuffer.UV4Kind)&&(r.uvs4=i.getVerticesData(e.VertexBuffer.UV4Kind,n)),i.isVerticesDataPresent(e.VertexBuffer.UV5Kind)&&(r.uvs5=i.getVerticesData(e.VertexBuffer.UV5Kind,n)),i.isVerticesDataPresent(e.VertexBuffer.UV6Kind)&&(r.uvs6=i.getVerticesData(e.VertexBuffer.UV6Kind,n)),i.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(r.colors=i.getVerticesData(e.VertexBuffer.ColorKind,n)),i.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&(r.matricesIndices=i.getVerticesData(e.VertexBuffer.MatricesIndicesKind,n)),i.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)&&(r.matricesWeights=i.getVerticesData(e.VertexBuffer.MatricesWeightsKind,n)),i.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesExtraKind)&&(r.matricesIndicesExtra=i.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,n)),i.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsExtraKind)&&(r.matricesWeightsExtra=i.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,n)),r.indices=i.getIndices(n),r},t.CreateRibbon=function(i){var n=i.pathArray,r=i.closeArray||!1,o=i.closePath||!1,s=Math.floor(n[0].length/2),a=i.offset||s;a=a>s?s:Math.floor(a);var h,c,l,u,d=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,f=[],p=[],m=[],_=[],g=[],v=[],y=[],x=[],b=[],E=[];if(n.length<2){var A=[],T=[];for(l=0;l<n[0].length-a;l++)A.push(n[0][l]),T.push(n[0][l+a]);n=[A,T]}var P,M,C=0,S=o?1:0;h=n[0].length;var R,I;for(c=0;c<n.length;c++){for(y[c]=0,g[c]=[0],P=n[c],M=P.length,h=M>h?h:M,u=0;M>u;)f.push(P[u].x,P[u].y,P[u].z),u>0&&(R=P[u].subtract(P[u-1]).length(),I=R+y[c],g[c].push(I),y[c]=I),u++;o&&(u--,f.push(P[0].x,P[0].y,P[0].z),R=P[u].subtract(P[0]).length(),I=R+y[c],g[c].push(I),y[c]=I),b[c]=M+S,E[c]=C,C+=M+S}var D,O,w,L;for(l=0;h+S>l;l++){for(x[l]=0,v[l]=[0],c=0;c<n.length-1;c++)D=n[c],O=n[c+1],l===h?(w=D[0],L=O[0]):(w=D[l],L=O[l]),R=L.subtract(w).length(),I=R+x[l],v[l].push(I),x[l]=I;r&&(D=n[c],O=n[0],l===h&&(L=O[0]),R=L.subtract(w).length(),I=R+x[l],x[l]=I)}var B,F;for(c=0;c<n.length;c++)for(l=0;h+S>l;l++)B=g[c][l]/y[c],F=v[l][c]/x[l],_.push(B,F);c=0;for(var V=0,N=b[c]-1,z=b[c+1]-1,U=z>N?N:z,k=E[1]-E[0],G=r?b.length:b.length-1;U>=V&&G>c;)p.push(V,V+k,V+1),p.push(V+k+1,V+1,V+k),V+=1,V===U&&(c++,c===b.length-1?(k=E[0]-E[c],N=b[c]-1,z=b[0]-1):(k=E[c+1]-E[c],N=b[c]-1,z=b[c+1]-1),V=E[c],U=z>N?N+V:z+V);if(t.ComputeNormals(f,p,m),o){var W=0,Y=0;for(c=0;c<n.length;c++)W=3*E[c],Y=c+1<n.length?3*(E[c+1]-1):m.length-3,m[W]=.5*(m[W]+m[Y]),m[W+1]=.5*(m[W+1]+m[Y+1]),m[W+2]=.5*(m[W+2]+m[Y+2]),m[Y]=m[W],m[Y+1]=m[W+1],m[Y+2]=m[W+2]}t._ComputeSides(d,f,p,m,_);var H=new t;return H.indices=p,H.positions=f,H.normals=m,H.uvs=_,o&&(H._idx=E),H},t.CreateBox=function(i){for(var n=[new e.Vector3(0,0,1),new e.Vector3(0,0,-1),new e.Vector3(1,0,0),new e.Vector3(-1,0,0),new e.Vector3(0,1,0),new e.Vector3(0,-1,0)],r=[],o=[],s=[],a=[],h=i.width||i.size||1,c=i.height||i.size||1,l=i.depth||i.size||1,u=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,d=i.faceUV||new Array(6),f=i.faceColors,p=[],m=0;6>m;m++)void 0===d[m]&&(d[m]=new e.Vector4(0,0,1,1)),f&&void 0===f[m]&&(f[m]=new e.Color4(1,1,1,1));for(var _=new e.Vector3(h/2,c/2,l/2),g=0;g<n.length;g++){var v=n[g],y=new e.Vector3(v.y,v.z,v.x),x=e.Vector3.Cross(v,y),b=o.length/3;
  18. r.push(b),r.push(b+1),r.push(b+2),r.push(b),r.push(b+2),r.push(b+3);var E=v.subtract(y).subtract(x).multiply(_);o.push(E.x,E.y,E.z),s.push(v.x,v.y,v.z),a.push(d[g].z,d[g].w),f&&p.push(f[g].r,f[g].g,f[g].b,f[g].a),E=v.subtract(y).add(x).multiply(_),o.push(E.x,E.y,E.z),s.push(v.x,v.y,v.z),a.push(d[g].x,d[g].w),f&&p.push(f[g].r,f[g].g,f[g].b,f[g].a),E=v.add(y).add(x).multiply(_),o.push(E.x,E.y,E.z),s.push(v.x,v.y,v.z),a.push(d[g].x,d[g].y),f&&p.push(f[g].r,f[g].g,f[g].b,f[g].a),E=v.add(y).subtract(x).multiply(_),o.push(E.x,E.y,E.z),s.push(v.x,v.y,v.z),a.push(d[g].z,d[g].y),f&&p.push(f[g].r,f[g].g,f[g].b,f[g].a)}t._ComputeSides(u,o,r,s,a);var A=new t;if(A.indices=r,A.positions=o,A.normals=s,A.uvs=a,f){var T=u===e.Mesh.DOUBLESIDE?p.concat(p):p;A.colors=T}return A},t.CreateSphere=function(i){for(var n=i.segments||32,r=i.diameterX||i.diameter||1,o=i.diameterY||i.diameter||1,s=i.diameterZ||i.diameter||1,a=i.arc<=0||i.arc>1?1:i.arc||1,h=i.slice<=0?1:i.slice||1,c=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,l=new e.Vector3(r/2,o/2,s/2),u=2+n,d=2*u,f=[],p=[],m=[],_=[],g=0;u>=g;g++){for(var v=g/u,y=v*Math.PI*h,x=0;d>=x;x++){var b=x/d,E=b*Math.PI*2*a,A=e.Matrix.RotationZ(-y),T=e.Matrix.RotationY(E),P=e.Vector3.TransformCoordinates(e.Vector3.Up(),A),M=e.Vector3.TransformCoordinates(P,T),C=M.multiply(l),S=M.divide(l).normalize();p.push(C.x,C.y,C.z),m.push(S.x,S.y,S.z),_.push(b,v)}if(g>0)for(var R=p.length/3,I=R-2*(d+1);R>I+d+2;I++)f.push(I),f.push(I+1),f.push(I+d+1),f.push(I+d+1),f.push(I+1),f.push(I+d+2)}t._ComputeSides(c,p,f,m,_);var D=new t;return D.indices=f,D.positions=p,D.normals=m,D.uvs=_,D},t.CreateCylinder=function(i){var n,r=i.height||2,o=0===i.diameterTop?0:i.diameterTop||i.diameter||1,s=i.diameterBottom||i.diameter||1,a=i.tessellation||24,h=i.subdivisions||1,c=i.hasRings,l=i.enclose,u=i.arc<=0||i.arc>1?1:i.arc||1,d=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,f=i.faceUV||new Array(3),p=i.faceColors,m=1!==u&&l?2:0,_=c?h:1,g=2+(1+m)*_;for(n=0;g>n;n++)p&&void 0===p[n]&&(p[n]=new e.Color4(1,1,1,1));for(n=0;g>n;n++)f&&void 0===f[n]&&(f[n]=new e.Vector4(0,0,1,1));var v,y,x,b,E,A,T=[],P=[],M=[],C=[],S=[],R=2*Math.PI*u/a,I=(s-o)/2/r,D=e.Vector3.Zero(),O=e.Vector3.Zero(),w=e.Vector3.Zero(),L=e.Vector3.Zero(),B=e.Vector3.Zero(),F=e.Axis.Y,V=1,N=1,z=0,U=0;for(b=0;h>=b;b++)for(y=b/h,x=(y*(o-s)+s)/2,V=c&&0!==b&&b!==h?2:1,A=0;V>A;A++){for(c&&(N+=A),l&&(N+=2*A),E=0;a>=E;E++)v=E*R,D.x=Math.cos(-v)*x,D.y=-r/2+y*r,D.z=Math.sin(-v)*x,0===o&&b===h?(O.x=M[M.length-3*(a+1)],O.y=M[M.length-3*(a+1)+1],O.z=M[M.length-3*(a+1)+2]):(O.x=D.x,O.z=D.z,O.y=Math.sqrt(O.x*O.x+O.z*O.z)*I,O.normalize()),0===E&&(w.copyFrom(D),L.copyFrom(O)),P.push(D.x,D.y,D.z),M.push(O.x,O.y,O.z),U=c?z!==N?f[N].y:f[N].w:f[N].y+(f[N].w-f[N].y)*y,C.push(f[N].x+(f[N].z-f[N].x)*E/a,U),p&&S.push(p[N].r,p[N].g,p[N].b,p[N].a);1!==u&&l&&(P.push(D.x,D.y,D.z),P.push(0,D.y,0),P.push(0,D.y,0),P.push(w.x,w.y,w.z),e.Vector3.CrossToRef(F,O,B),B.normalize(),M.push(B.x,B.y,B.z,B.x,B.y,B.z),e.Vector3.CrossToRef(L,F,B),B.normalize(),M.push(B.x,B.y,B.z,B.x,B.y,B.z),U=c?z!==N?f[N+1].y:f[N+1].w:f[N+1].y+(f[N+1].w-f[N+1].y)*y,C.push(f[N+1].x,U),C.push(f[N+1].z,U),U=c?z!==N?f[N+2].y:f[N+2].w:f[N+2].y+(f[N+2].w-f[N+2].y)*y,C.push(f[N+2].x,U),C.push(f[N+2].z,U),p&&(S.push(p[N+1].r,p[N+1].g,p[N+1].b,p[N+1].a),S.push(p[N+1].r,p[N+1].g,p[N+1].b,p[N+1].a),S.push(p[N+2].r,p[N+2].g,p[N+2].b,p[N+2].a),S.push(p[N+2].r,p[N+2].g,p[N+2].b,p[N+2].a))),z!==N&&(z=N)}var N,k=1!==u&&l?a+4:a;for(b=0,N=0;h>N;N++){for(E=0;a>E;E++){var G=b*(k+1)+E,W=(b+1)*(k+1)+E,Y=b*(k+1)+(E+1),H=(b+1)*(k+1)+(E+1);T.push(G,W,Y),T.push(H,Y,W)}1!==u&&l&&(T.push(G+2,W+2,Y+2),T.push(H+2,Y+2,W+2),T.push(G+4,W+4,Y+4),T.push(H+4,Y+4,W+4)),b=c?b+2:b+1}var X=function(t){var i=t?o/2:s/2;if(0!==i){var n,h,c,l,d=t?f[g-1]:f[0];p&&(l=t?p[g-1]:p[0]);var m=P.length/3,_=t?r/2:-r/2,v=new e.Vector3(0,_,0);P.push(v.x,v.y,v.z),M.push(0,t?1:-1,0),C.push(d.x+.5*(d.z-d.x),d.y+.5*(d.w-d.y)),p&&S.push(l.r,l.g,l.b,l.a);var y=new e.Vector2(.5,.5);for(c=0;a>=c;c++){n=2*Math.PI*c*u/a;var x=Math.cos(-n),b=Math.sin(-n);h=new e.Vector3(x*i,_,b*i);var E=new e.Vector2(x*y.x+.5,b*y.y+.5);P.push(h.x,h.y,h.z),M.push(0,t?1:-1,0),C.push(d.x+(d.z-d.x)*E.x,d.y+(d.w-d.y)*E.y),p&&S.push(l.r,l.g,l.b,l.a)}for(c=0;a>c;c++)t?(T.push(m),T.push(m+(c+2)),T.push(m+(c+1))):(T.push(m),T.push(m+(c+1)),T.push(m+(c+2)))}};X(!1),X(!0),t._ComputeSides(d,P,T,M,C);var j=new t;return j.indices=T,j.positions=P,j.normals=M,j.uvs=C,p&&(j.colors=S),j},t.CreateTorus=function(i){for(var n=[],r=[],o=[],s=[],a=i.diameter||1,h=i.thickness||.5,c=i.tessellation||16,l=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,u=c+1,d=0;c>=d;d++)for(var f=d/c,p=d*Math.PI*2/c-Math.PI/2,m=e.Matrix.Translation(a/2,0,0).multiply(e.Matrix.RotationY(p)),_=0;c>=_;_++){var g=1-_/c,v=_*Math.PI*2/c+Math.PI,y=Math.cos(v),x=Math.sin(v),b=new e.Vector3(y,x,0),E=b.scale(h/2),A=new e.Vector2(f,g);E=e.Vector3.TransformCoordinates(E,m),b=e.Vector3.TransformNormal(b,m),r.push(E.x,E.y,E.z),o.push(b.x,b.y,b.z),s.push(A.x,A.y);var T=(d+1)%u,P=(_+1)%u;n.push(d*u+_),n.push(d*u+P),n.push(T*u+_),n.push(d*u+P),n.push(T*u+P),n.push(T*u+_)}t._ComputeSides(l,r,n,o,s);var M=new t;return M.indices=n,M.positions=r,M.normals=o,M.uvs=s,M},t.CreateLineSystem=function(e){for(var i=[],n=[],r=e.lines,o=0,s=0;s<r.length;s++)for(var a=r[s],h=0;h<a.length;h++)n.push(a[h].x,a[h].y,a[h].z),h>0&&(i.push(o-1),i.push(o)),o++;var c=new t;return c.indices=i,c.positions=n,c},t.CreateDashedLines=function(i){var n=i.dashSize||3,r=i.gapSize||1,o=i.dashNb||200,s=i.points,a=new Array,h=new Array,c=e.Vector3.Zero(),l=0,u=0,d=0,f=0,p=0,m=0,_=0;for(_=0;_<s.length-1;_++)s[_+1].subtractToRef(s[_],c),l+=c.length();for(d=l/o,f=n*d/(n+r),_=0;_<s.length-1;_++){s[_+1].subtractToRef(s[_],c),u=Math.floor(c.length()/d),c.normalize();for(var g=0;u>g;g++)p=d*g,a.push(s[_].x+p*c.x,s[_].y+p*c.y,s[_].z+p*c.z),a.push(s[_].x+(p+f)*c.x,s[_].y+(p+f)*c.y,s[_].z+(p+f)*c.z),h.push(m,m+1),m+=2}var v=new t;return v.positions=a,v.indices=h,v},t.CreateGround=function(i){var n,r,o=[],s=[],a=[],h=[],c=i.width||1,l=i.height||1,u=i.subdivisions||1;for(n=0;u>=n;n++)for(r=0;u>=r;r++){var d=new e.Vector3(r*c/u-c/2,0,(u-n)*l/u-l/2),f=new e.Vector3(0,1,0);s.push(d.x,d.y,d.z),a.push(f.x,f.y,f.z),h.push(r/u,1-n/u)}for(n=0;u>n;n++)for(r=0;u>r;r++)o.push(r+1+(n+1)*(u+1)),o.push(r+1+n*(u+1)),o.push(r+n*(u+1)),o.push(r+(n+1)*(u+1)),o.push(r+1+(n+1)*(u+1)),o.push(r+n*(u+1));var p=new t;return p.indices=o,p.positions=s,p.normals=a,p.uvs=h,p},t.CreateTiledGround=function(i){function n(t,i,n,s){var a=m.length/3,h=f.w+1;for(r=0;r<f.h;r++)for(o=0;o<f.w;o++){var c=[a+o+r*h,a+(o+1)+r*h,a+(o+1)+(r+1)*h,a+o+(r+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(r=0;r<=f.h;r++)for(l.z=r*(s-i)/f.h+i,o=0;o<=f.w;o++)l.x=o*(n-t)/f.w+t,l.y=0,m.push(l.x,l.y,l.z),_.push(u.x,u.y,u.z),g.push(o/f.w,r/f.h)}var r,o,s,a,h=i.xmin,c=i.zmin,l=i.xmax,u=i.zmax,d=i.subdivisions||{w:1,h:1},f=i.precision||{w:1,h:1},p=[],m=[],_=[],g=[];d.h=d.w<1?1:d.h,d.w=d.w<1?1:d.w,f.w=f.w<1?1:f.w,f.h=f.h<1?1:f.h;var v={w:(l-h)/d.w,h:(u-c)/d.h};for(s=0;s<d.h;s++)for(a=0;a<d.w;a++)n(h+a*v.w,c+s*v.h,h+(a+1)*v.w,c+(s+1)*v.h);var y=new t;return y.indices=p,y.positions=m,y.normals=_,y.uvs=g,y},t.CreateGroundFromHeightMap=function(i){var n,r,o=[],s=[],a=[],h=[];for(n=0;n<=i.subdivisions;n++)for(r=0;r<=i.subdivisions;r++){var c=new e.Vector3(r*i.width/i.subdivisions-i.width/2,0,(i.subdivisions-n)*i.height/i.subdivisions-i.height/2),l=(c.x+i.width/2)/i.width*(i.bufferWidth-1)|0,u=(1-(c.z+i.height/2)/i.height)*(i.bufferHeight-1)|0,d=4*(l+u*i.bufferWidth),f=i.buffer[d]/255,p=i.buffer[d+1]/255,m=i.buffer[d+2]/255,_=.3*f+.59*p+.11*m;c.y=i.minHeight+(i.maxHeight-i.minHeight)*_,s.push(c.x,c.y,c.z),a.push(0,0,0),h.push(r/i.subdivisions,1-n/i.subdivisions)}for(n=0;n<i.subdivisions;n++)for(r=0;r<i.subdivisions;r++)o.push(r+1+(n+1)*(i.subdivisions+1)),o.push(r+1+n*(i.subdivisions+1)),o.push(r+n*(i.subdivisions+1)),o.push(r+(n+1)*(i.subdivisions+1)),o.push(r+1+(n+1)*(i.subdivisions+1)),o.push(r+n*(i.subdivisions+1));t.ComputeNormals(s,o,a);var g=new t;return g.indices=o,g.positions=s,g.normals=a,g.uvs=h,g},t.CreatePlane=function(i){var n=[],r=[],o=[],s=[],a=i.width||i.size||1,h=i.height||i.size||1,c=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,l=a/2,u=h/2;r.push(-l,-u,0),o.push(0,0,-1),s.push(0,0),r.push(l,-u,0),o.push(0,0,-1),s.push(1,0),r.push(l,u,0),o.push(0,0,-1),s.push(1,1),r.push(-l,u,0),o.push(0,0,-1),s.push(0,1),n.push(0),n.push(1),n.push(2),n.push(0),n.push(2),n.push(3),t._ComputeSides(c,r,n,o,s);var d=new t;return d.indices=n,d.positions=r,d.normals=o,d.uvs=s,d},t.CreateDisc=function(i){var n=[],r=[],o=[],s=[],a=i.radius||.5,h=i.tessellation||64,c=i.arc<=0||i.arc>1?1:i.arc||1,l=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE;n.push(0,0,0),s.push(.5,.5);for(var u=2*Math.PI*c,d=u/h,f=0;u>f;f+=d){var p=Math.cos(f),m=Math.sin(f),_=(p+1)/2,g=(1-m)/2;n.push(a*p,a*m,0),s.push(_,g)}1===c&&(n.push(n[3],n[4],n[5]),s.push(s[2],s[3]));for(var v=n.length/3,y=1;v-1>y;y++)r.push(y+1,0,y);t.ComputeNormals(n,r,o),t._ComputeSides(l,n,r,o,s);var x=new t;return x.indices=r,x.positions=n,x.normals=o,x.uvs=s,x},t.CreateIcoSphere=function(i){var n,r=i.sideOrientation||e.Mesh.DEFAULTSIDE,o=i.radius||1,s=void 0===i.flat?!0:i.flat,a=i.subdivisions||4,h=i.radiusX||o,c=i.radiusY||o,l=i.radiusZ||o,u=(1+Math.sqrt(5))/2,d=[-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],f=[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],_=138/1024,g=239/1024,v=60/1024,y=26/1024,x=-40/1024,b=20/1024,E=[0,0,0,0,1,0,0,1,1,0,0,0,1,1,0,0,1,1,1,0],A=[],T=[],P=[],M=[],C=0,S=new Array(3),R=new Array(3);for(n=0;3>n;n++)S[n]=e.Vector3.Zero(),R[n]=e.Vector2.Zero();for(var I=0;20>I;I++){for(n=0;3>n;n++){var D=f[3*I+n];S[n].copyFromFloats(d[3*p[D]],d[3*p[D]+1],d[3*p[D]+2]),S[n].normalize().scaleInPlace(o),R[n].copyFromFloats(m[2*D]*_+v+E[I]*x,m[2*D+1]*g+y+E[I]*b)}for(var O=function(t,i,n,r){var o=e.Vector3.Lerp(S[0],S[2],i/a),u=e.Vector3.Lerp(S[1],S[2],i/a),d=a===i?S[2]:e.Vector3.Lerp(o,u,t/(a-i));d.normalize();var f;if(s){var p=e.Vector3.Lerp(S[0],S[2],r/a),m=e.Vector3.Lerp(S[1],S[2],r/a);f=e.Vector3.Lerp(p,m,n/(a-r))}else f=new e.Vector3(d.x,d.y,d.z);f.x/=h,f.y/=c,f.z/=l,f.normalize();var _=e.Vector2.Lerp(R[0],R[2],i/a),g=e.Vector2.Lerp(R[1],R[2],i/a),v=a===i?R[2]:e.Vector2.Lerp(_,g,t/(a-i));T.push(d.x*h,d.y*c,d.z*l),P.push(f.x,f.y,f.z),M.push(v.x,v.y),A.push(C),C++},w=0;a>w;w++)for(var L=0;a>L+w;L++)O(L,w,L+1/3,w+1/3),O(L+1,w,L+1/3,w+1/3),O(L,w+1,L+1/3,w+1/3),a>L+w+1&&(O(L+1,w,L+2/3,w+2/3),O(L+1,w+1,L+2/3,w+2/3),O(L,w+1,L+2/3,w+2/3))}t._ComputeSides(r,T,A,P,M);var B=new t;return B.indices=A,B.positions=T,B.normals=P,B.uvs=M,B},t.CreatePolyhedron=function(i){var n=[];n[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]]},n[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]]},n[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]]},n[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]]},n[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]]},n[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]]},n[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]]},n[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]]},n[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]]},n[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]]},n[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]]},n[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]]},n[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]]},n[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]]},n[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 r,o,s,a,h,c,l=i.type<0||i.type>=n.length?0:i.type||0,u=i.size,d=i.sizeX||u||1,f=i.sizeY||u||1,p=i.sizeZ||u||1,m=i.custom||n[l],_=m.face.length,g=i.faceUV||new Array(_),v=i.faceColors,y=void 0===i.flat?!0:i.flat,x=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,b=[],E=[],A=[],T=[],P=[],M=0,C=0,S=[],R=0,I=0;if(y)for(I=0;_>I;I++)v&&void 0===v[I]&&(v[I]=new e.Color4(1,1,1,1)),g&&void 0===g[I]&&(g[I]=new e.Vector4(0,0,1,1));if(y)for(I=0;_>I;I++){var D=m.face[I].length;for(s=2*Math.PI/D,a=.5*Math.tan(s/2),h=.5,R=0;D>R;R++)b.push(m.vertex[m.face[I][R]][0]*d,m.vertex[m.face[I][R]][1]*f,m.vertex[m.face[I][R]][2]*p),S.push(M),M++,r=g[I].x+(g[I].z-g[I].x)*(.5+a),o=g[I].y+(g[I].w-g[I].y)*(h-.5),T.push(r,o),c=a*Math.cos(s)-h*Math.sin(s),h=a*Math.sin(s)+h*Math.cos(s),a=c,v&&P.push(v[I].r,v[I].g,v[I].b,v[I].a);for(R=0;D-2>R;R++)E.push(S[0+C],S[R+2+C],S[R+1+C]);C+=D}else{for(R=0;R<m.vertex.length;R++)b.push(m.vertex[R][0]*d,m.vertex[R][1]*f,m.vertex[R][2]*p),T.push(0,0);for(I=0;_>I;I++)for(R=0;R<m.face[I].length-2;R++)E.push(m.face[I][0],m.face[I][R+2],m.face[I][R+1])}t.ComputeNormals(b,E,A),t._ComputeSides(x,b,E,A,T);var O=new t;return O.positions=b,O.indices=E,O.normals=A,O.uvs=T,v&&y&&(O.colors=P),O},t.CreateTorusKnot=function(i){var n,r,o=[],s=[],a=[],h=[],c=i.radius||2,l=i.tube||.5,u=i.radialSegments||32,d=i.tubularSegments||32,f=i.p||2,p=i.q||3,m=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,_=function(t){var i=Math.cos(t),n=Math.sin(t),r=p/f*t,o=Math.cos(r),s=c*(2+o)*.5*i,a=c*(2+o)*n*.5,h=c*Math.sin(r)*.5;return new e.Vector3(s,a,h)};for(n=0;u>=n;n++){var g=n%u,v=g/u*2*f*Math.PI,y=_(v),x=_(v+.01),b=x.subtract(y),E=x.add(y),A=e.Vector3.Cross(b,E);for(E=e.Vector3.Cross(A,b),A.normalize(),E.normalize(),r=0;d>r;r++){var T=r%d,P=T/d*2*Math.PI,M=-l*Math.cos(P),C=l*Math.sin(P);s.push(y.x+M*E.x+C*A.x),s.push(y.y+M*E.y+C*A.y),s.push(y.z+M*E.z+C*A.z),h.push(n/u),h.push(r/d)}}for(n=0;u>n;n++)for(r=0;d>r;r++){var S=(r+1)%d,R=n*d+r,I=(n+1)*d+r,D=(n+1)*d+S,O=n*d+S;o.push(O),o.push(I),o.push(R),o.push(O),o.push(D),o.push(I)}t.ComputeNormals(s,o,a),t._ComputeSides(m,s,o,a,h);var w=new t;return w.indices=o,w.positions=s,w.normals=a,w.uvs=h,w},t.ComputeNormals=function(e,t,i){var n=0,r=0,o=0,s=0,a=0,h=0,c=0,l=0,u=0,d=0,f=0,p=0,m=0,_=0;for(n=0;n<e.length;n++)i[n]=0;var g=t.length/3;for(n=0;g>n;n++)p=t[3*n],m=t[3*n+1],_=t[3*n+2],r=e[3*p]-e[3*m],o=e[3*p+1]-e[3*m+1],s=e[3*p+2]-e[3*m+2],a=e[3*_]-e[3*m],h=e[3*_+1]-e[3*m+1],c=e[3*_+2]-e[3*m+2],l=o*c-s*h,u=s*a-r*c,d=r*h-o*a,f=Math.sqrt(l*l+u*u+d*d),f=0===f?1:f,l/=f,u/=f,d/=f,i[3*p]+=l,i[3*p+1]+=u,i[3*p+2]+=d,i[3*m]+=l,i[3*m+1]+=u,i[3*m+2]+=d,i[3*_]+=l,i[3*_+1]+=u,i[3*_+2]+=d;for(n=0;n<i.length/3;n++)l=i[3*n],u=i[3*n+1],d=i[3*n+2],f=Math.sqrt(l*l+u*u+d*d),f=0===f?1:f,l/=f,u/=f,d/=f,i[3*n]=l,i[3*n+1]=u,i[3*n+2]=d},t._ComputeSides=function(t,i,n,r,o){var s,a,h=n.length,c=r.length;switch(t=t||e.Mesh.DEFAULTSIDE){case e.Mesh.FRONTSIDE:break;case e.Mesh.BACKSIDE:var l;for(s=0;h>s;s+=3)l=n[s],n[s]=n[s+2],n[s+2]=l;for(a=0;c>a;a++)r[a]=-r[a];break;case e.Mesh.DOUBLESIDE:for(var u=i.length,d=u/3,f=0;u>f;f++)i[u+f]=i[f];for(s=0;h>s;s+=3)n[s+h]=n[s+2]+d,n[s+1+h]=n[s+1]+d,n[s+2+h]=n[s]+d;for(a=0;c>a;a++)r[c+a]=-r[a];for(var p=o.length,m=0;p>m;m++)o[m+p]=o[m]}},t.ImportVertexData=function(i,n){var r=new t,o=i.positions;o&&r.set(o,e.VertexBuffer.PositionKind);var s=i.normals;s&&r.set(s,e.VertexBuffer.NormalKind);var a=i.uvs;a&&r.set(a,e.VertexBuffer.UVKind);var h=i.uv2s;h&&r.set(h,e.VertexBuffer.UV2Kind);var c=i.uv3s;c&&r.set(c,e.VertexBuffer.UV3Kind);var l=i.uv4s;l&&r.set(l,e.VertexBuffer.UV4Kind);var u=i.uv5s;u&&r.set(u,e.VertexBuffer.UV5Kind);var d=i.uv6s;d&&r.set(d,e.VertexBuffer.UV6Kind);var f=i.colors;f&&r.set(e.Color4.CheckColors4(f,o.length/3),e.VertexBuffer.ColorKind);var p=i.matricesIndices;p&&r.set(p,e.VertexBuffer.MatricesIndicesKind);var m=i.matricesWeights;m&&r.set(m,e.VertexBuffer.MatricesWeightsKind);var _=i.indices;_&&(r.indices=_),n.setAllVerticesData(r,i.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(i){return t.AddTagsTo(e,i)},e.removeTags=function(i){return t.RemoveTagsFrom(e,i)},e.matchesTagsQuery=function(i){return t.MatchesQuery(e,i)}},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 i=[];for(var n in e._tags)e._tags.hasOwnProperty(n)&&e._tags[n]===!0&&i.push(n);return i.join(" ")}return e._tags},t.AddTagsTo=function(e,i){if(i&&"string"==typeof i){var n=i.split(" ");for(var r in n)t._AddTagTo(e,n[r])}},t._AddTagTo=function(e,i){i=i.trim(),""!==i&&"true"!==i&&"false"!==i&&(i.match(/[\s]/)||i.match(/^([!]|([|]|[&]){2})/)||(t.EnableFor(e),e._tags[i]=!0))},t.RemoveTagsFrom=function(e,i){if(t.HasTags(e)){var n=i.split(" ");for(var r in n)t._RemoveTagFrom(e,n[r])}},t._RemoveTagFrom=function(e,t){delete e._tags[t]},t.MatchesQuery=function(i,n){return void 0===n?!0:""===n?t.HasTags(i):e.Internals.AndOrNotEvaluator.Eval(n,function(e){return t.HasTags(i)&&i._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,i){return t=t.match(/\([^\(\)]*\)/g)?t.replace(/\([^\(\)]*\)/g,function(t){return t=t.slice(1,t.length-1),e._HandleParenthesisContent(t,i)}):e._HandleParenthesisContent(t,i),"true"===t?!0:"false"===t?!1:e.Eval(t,i)},e._HandleParenthesisContent=function(t,i){i=i||function(e){return"true"===e};var n,r=t.split("||");for(var o in r){var s=e._SimplifyNegation(r[o].trim()),a=s.split("&&");if(a.length>1)for(var h=0;h<a.length;++h){var c=e._SimplifyNegation(a[h].trim());if(n="true"!==c&&"false"!==c?"!"===c[0]?!i(c.substring(1)):i(c):"true"===c,!n){s="false";break}}if(n||"true"===s){n=!0;break}n="true"!==s&&"false"!==s?"!"===s[0]?!i(s.substring(1)):i(s):"true"===s}return n?"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,i,n,r,o,s){this._enabled=!0,this._refCount=0,this._name=i,this._renderTexture=new e.RenderTargetTexture(i,n,t),this.setRenderList(r),this._renderTexture.onBeforeRender=o,this._renderTexture.onAfterRender=s,this._scene=t,this._renderList=r}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,i,n){this._engine=e,this._name=t,this._singleInstance=n||!0,this._getPostProcess=i,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 i,n=e.Tools.MakeArray(t||this._cameras),r=0;r<n.length;r++){var o=n[r],s=o.name;i=this._singleInstance?0:s,this._postProcesses[i]=this._postProcesses[i]||this._getPostProcess();var a=o.attachPostProcess(this._postProcesses[i]);this._indicesForCamera[s]||(this._indicesForCamera[s]=[]),this._indicesForCamera[s].push(a),-1===this._cameras.indexOf(o)&&(this._cameras[s]=o);for(var h in this._renderPasses)this._renderPasses[h]._incRefCount()}this._linkParameters()},t.prototype._detachCameras=function(t){for(var i=e.Tools.MakeArray(t||this._cameras),n=0;n<i.length;n++){var r=i[n],o=r.name;r.detachPostProcess(this._postProcesses[this._singleInstance?0:o],this._indicesForCamera[o]);var s=this._cameras.indexOf(o);this._indicesForCamera.splice(s,1),this._cameras.splice(s,1);for(var a in this._renderPasses)this._renderPasses[a]._decRefCount()}},t.prototype._enable=function(t){for(var i=e.Tools.MakeArray(t||this._cameras),n=0;n<i.length;n++){for(var r=i[n],o=r.name,s=0;s<this._indicesForCamera[o].length;s++)void 0===r._postProcesses[this._indicesForCamera[o][s]]&&t[n].attachPostProcess(this._postProcesses[this._singleInstance?0:o],this._indicesForCamera[o][s]);for(var a in this._renderPasses)this._renderPasses[a]._incRefCount()}},t.prototype._disable=function(t){for(var i=e.Tools.MakeArray(t||this._cameras),n=0;n<i.length;n++){var r=i[n],o=r.Name;r.detachPostProcess(this._postProcesses[this._singleInstance?0:o],this._indicesForCamera[o]);for(var s in this._renderPasses)this._renderPasses[s]._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 i in this._renderEffectAsPasses)e.setTextureFromPostProcess(i+"Sampler",this._renderEffectAsPasses[i].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,i){var n=this._renderEffects[t];n&&n._enable(e.Tools.MakeArray(i||this._cameras))},t.prototype._disableEffect=function(t,i){var n=this._renderEffects[t];n&&n._disable(e.Tools.MakeArray(i||this._cameras))},t.prototype._attachCameras=function(t,i){var n,r=e.Tools.MakeArray(t||this._cameras),o=[];for(n=0;n<r.length;n++){var s=r[n],a=s.name;-1===this._cameras.indexOf(s)?this._cameras[a]=s:i&&o.push(n)}for(n=0;n<o.length;n++)t.splice(o[n],1);for(var h in this._renderEffects)this._renderEffects[h]._attachCameras(r)},t.prototype._detachCameras=function(t){var i=e.Tools.MakeArray(t||this._cameras);for(var n in this._renderEffects)this._renderEffects[n]._detachCameras(i);for(var r=0;r<i.length;r++)this._cameras.splice(this._cameras.indexOf(i[r]),1)},t.prototype._enableDisplayOnlyPass=function(i,n){var r,o=this,s=e.Tools.MakeArray(n||this._cameras),a=null;for(r in this._renderEffects)if(a=this._renderEffects[r].getPass(i),null!=a)break;if(null!==a){for(r in this._renderEffects)this._renderEffects[r]._disable(s);a._name=t.PASS_SAMPLER_NAME;for(var h=0;h<s.length;h++){var c=s[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,o._engine,!0)}),this._renderEffectsForIsolatedPass[l].emptyPasses(),this._renderEffectsForIsolatedPass[l].addPass(a),this._renderEffectsForIsolatedPass[l]._attachCameras(c)}}},t.prototype._disableDisplayOnlyPass=function(i){for(var n=this,r=e.Tools.MakeArray(i||this._cameras),o=0;o<r.length;o++){var s=r[o],a=s.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,n._engine,!0)}),this._renderEffectsForIsolatedPass[a]._disable(s)}for(var h in this._renderEffects)this._renderEffects[h]._enable(r)},t.prototype._update=function(){for(var e in this._renderEffects)this._renderEffects[e]._update();for(var t=0;t<this._cameras.length;t++){var i=this._cameras[t].name;this._renderEffectsForIsolatedPass[i]&&this._renderEffectsForIsolatedPass[i]._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,i){var n=this._renderPipelines[e];n&&n._attachCameras(t,i)},e.prototype.detachCamerasFromRenderPipeline=function(e,t){var i=this._renderPipelines[e];i&&i._detachCameras(t)},e.prototype.enableEffectInPipeline=function(e,t,i){var n=this._renderPipelines[e];n&&n._enableEffect(t,i)},e.prototype.disableEffectInPipeline=function(e,t,i){var n=this._renderPipelines[e];n&&n._disableEffect(t,i)},e.prototype.enableDisplayOnlyPassInPipeline=function(e,t,i){var n=this._renderPipelines[e];n&&n._enableDisplayOnlyPass(t,i)},e.prototype.disableDisplayOnlyPassInPipeline=function(e,t){var i=this._renderPipelines[e];i&&i._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),
  19. 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(),i=e.VertexData.CreateBox(1);this._vb=new e.VertexBuffer(t,i.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 i=0;i<this.renderList.length;i++){var n=this.renderList.data[i],r=n.minimum,o=n.maximum,s=o.subtract(r),a=r.add(s.scale(.5)),h=e.Matrix.Scaling(s.x,s.y,s.z).multiply(e.Matrix.Translation(a.x,a.y,a.z)).multiply(n.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 i=function(e){function t(i,n,r,o,s){void 0===s&&(s=t.IsEqual),e.call(this,i),this.propertyPath=r,this.value=o,this.operator=s,this._target=this._getEffectiveTarget(n,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=i;var n=function(e){function t(t,i){e.call(this,t),this.predicate=i}return __extends(t,e),t.prototype.isValid=function(){return this.predicate()},t}(t);e.PredicateCondition=n;var r=function(e){function t(t,i,n){e.call(this,t),this.value=n,this._target=i}return __extends(t,e),t.prototype.isValid=function(){return this._target.state===this.value},t}(t);e.StateCondition=r}(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,i=this._actionManager.getScene().getRenderId();if(t._evaluationId===i){if(!t._currentResult)return}else{if(t._evaluationId=i,!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,i,n,r,o){this.source=e,this.pointerX=t,this.pointerY=i,this.meshUnderPointer=n,this.sourceEvent=r,this.additionalData=o}return e.CreateNew=function(t,i,n){var r=t.getScene();return new e(t,r.pointerX,r.pointerY,r.meshUnderPointer,i,n)},e.CreateNewFromSprite=function(t,i,n,r){return new e(t,i.pointerX,i.pointerY,i.meshUnderPointer,n,r)},e.CreateNewFromScene=function(t,i){return new e(null,t.pointerX,t.pointerY,t.meshUnderPointer,i)},e}();e.ActionEvent=t;var i=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,"OnPickOutTrigger",{get:function(){return t._OnPickOutTrigger},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 i=this.actions[t];if(e.indexOf(i.trigger)>-1)return!0}return!1},t.prototype.hasSpecificTrigger=function(e){for(var t=0;t<this.actions.length;t++){var i=this.actions[t];if(i.trigger===e)return!0}return!1},Object.defineProperty(t.prototype,"hasPointerTriggers",{get:function(){for(var e=0;e<this.actions.length;e++){var i=this.actions[e];if(i.trigger>=t._OnPickTrigger&&i.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 i=this.actions[e];if(i.trigger>=t._OnPickTrigger&&i.trigger<=t._OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),t.prototype.registerAction=function(i){return i.trigger===t.OnEveryFrameTrigger&&this.getScene().actionManager!==this?(e.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager"),null):(this.actions.push(i),i._actionManager=this,i._prepare(),i)},t.prototype.processTrigger=function(e,i){for(var n=0;n<this.actions.length;n++){var r=this.actions[n];if(r.trigger===e){if(e===t.OnKeyUpTrigger||e===t.OnKeyDownTrigger){var o=r.getTriggerParameter();if(o){var s=i.sourceEvent.charCode?i.sourceEvent.charCode:i.sourceEvent.keyCode,a=String.fromCharCode(s).toLowerCase();if(a!==o.toLowerCase())continue}}r._executeCurrent(i)}}},t.prototype._getEffectiveTarget=function(e,t){for(var i=t.split("."),n=0;n<i.length-1;n++)e=e[i[n]];return e},t.prototype._getProperty=function(e){var t=e.split(".");return t[t.length-1]},t.Parse=function(i,n,r){var o=new e.ActionManager(r);null===n?r.actionManager=o:n.actionManager=o;for(var s=function(t,i){var n=Object.create(e[t].prototype);return n.constructor.apply(n,i),n},a=function(t,i,n,r){if(null===r){var o=parseFloat(i);return"true"===i||"false"===i?"true"===i:isNaN(o)?i:o}for(var s=r.split("."),a=i.split(","),h=0;h<s.length;h++)n=n[s[h]];if("boolean"==typeof n)return"true"===a[0];if("string"==typeof n)return a[0];for(var c=new Array,h=0;h<a.length;h++)c.push(parseFloat(a[h]));return n instanceof e.Vector3?e.Vector3.FromArray(c):n instanceof e.Vector4?e.Vector4.FromArray(c):n instanceof e.Color3?e.Color3.FromArray(c):n instanceof e.Color4?e.Color4.FromArray(c):parseFloat(a[0])},h=function(i,n,c,l,u){if(void 0===u&&(u=null),!i.detached){var d=new Array,f=null,p=null,m=i.combine&&i.combine.length>0;if(2===i.type?d.push(o):d.push(n),m){for(var _=new Array,g=0;g<i.combine.length;g++)h(i.combine[g],t.NothingTrigger,c,l,_);d.push(_)}else for(var v=0;v<i.properties.length;v++){var y=i.properties[v].value,x=i.properties[v].name,b=i.properties[v].targetType;"target"===x?y=f=null!==b&&"SceneProperties"===b?r:r.getNodeByName(y):"parent"===x?y=r.getNodeByName(y):"sound"===x?y=r.getSoundByName(y):"propertyPath"!==x?y=2===i.type&&"operator"===x?e.ValueCondition[y]:a(x,y,f,"value"===x?p:null):p=y,d.push(y)}if(null===u?d.push(c):d.push(null),"InterpolateValueAction"===i.name){var E=d[d.length-2];d[d.length-1]=E,d[d.length-2]=c}var A=s(i.name,d);if(A instanceof e.Condition&&null!==c){var T=new e.DoNothingAction(n,c);l?l.then(T):o.registerAction(T),l=T}null===u?A instanceof e.Condition?(c=A,A=l):(c=null,l?l.then(A):o.registerAction(A)):u.push(A);for(var v=0;v<i.children.length;v++)h(i.children[v],n,c,A,null)}},c=0;c<i.children.length;c++){var l,u=i.children[c];if(u.properties.length>0){var d=u.properties[0].value,f=null===u.properties[0].targetType?d:r.getMeshByName(d);l={trigger:e.ActionManager[u.name],parameter:f}}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._OnPickOutTrigger=15,t.DragMovementThreshold=10,t.LongPressDelay=500,t}();e.ActionManager=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,n,r,o,s,a,h){void 0===o&&(o=1e3),t.call(this,e,s),this.propertyPath=n,this.value=r,this.duration=o,this.stopOtherAnimations=a,this.onInterpolationDone=h,this._target=i}return __extends(i,t),i.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath)},i.prototype.execute=function(){var t,i=this._actionManager.getScene(),n=[{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 r=new e.Animation("InterpolateValueAction",this._property,100*(1e3/this.duration),t,e.Animation.ANIMATIONLOOPMODE_CONSTANT);r.setKeys(n),this.stopOtherAnimations&&i.stopAnimation(this._target),i.beginDirectAnimation(this._target,[r],0,100,!1,1,this.onInterpolationDone)},i}(e.Action);e.InterpolateValueAction=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n,r){e.call(this,t,r),this.propertyPath=n,this._target=i}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 i=function(e){function t(t,i,n,r){e.call(this,t,r),this.value=n,this._target=i}return __extends(t,e),t.prototype.execute=function(){this._target.state=this.value},t}(e.Action);e.SetStateAction=i;var n=function(e){function t(t,i,n,r,o){e.call(this,t,o),this.propertyPath=n,this.value=r,this._target=i}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=n;var r=function(t){function i(e,i,n,r,o){t.call(this,e,o),this.propertyPath=n,this.value=r,this._target=i}return __extends(i,t),i.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")},i.prototype.execute=function(){this._target[this._property]+=this.value},i}(e.Action);e.IncrementValueAction=r;var o=function(e){function t(t,i,n,r,o,s){e.call(this,t,s),this.from=n,this.to=r,this.loop=o,this._target=i}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=o;var s=function(e){function t(t,i,n){e.call(this,t,n),this._target=i}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=s;var a=function(t){function i(i,n){void 0===i&&(i=e.ActionManager.NothingTrigger),t.call(this,i,n)}return __extends(i,t),i.prototype.execute=function(){},i}(e.Action);e.DoNothingAction=a;var h=function(e){function t(t,i,n){e.call(this,t,n),this.children=i}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,i,n){e.call(this,t,n),this.func=i}return __extends(t,e),t.prototype.execute=function(e){this.func(e)},t}(e.Action);e.ExecuteCodeAction=c;var l=function(t){function i(e,i,n,r){t.call(this,e,r),this._target=i,this._parent=n}return __extends(i,t),i.prototype._prepare=function(){},i.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}},i}(e.Action);e.SetParentAction=l;var u=function(e){function t(t,i,n){e.call(this,t,n),this._sound=i}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 d=function(e){function t(t,i,n){e.call(this,t,n),this._sound=i}return __extends(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){void 0!==this._sound&&this._sound.stop()},t}(e.Action);e.StopSoundAction=d}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,n,r,o){this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this._totalVertices=0,this._isDisposed=!1,this.id=t,this._engine=i.getEngine(),this._meshes=[],this._scene=i,this._vertexBuffers={},this._indices=[],n?this.setAllVerticesData(n,r):(this._totalVertices=0,this._indices=[]),o&&(o instanceof e.LinesMesh&&(this.boundingBias=new e.Vector2(0,o.intersectionThreshold),this.updateExtend()),this.applyToMesh(o),o.computeWorldMatrix(!0))}return Object.defineProperty(t.prototype,"boundingBias",{get:function(){return this._boundingBias},set:function(e){this._boundingBias&&this._boundingBias.equals(e)||(this._boundingBias=e.clone(),this.updateExtend())},enumerable:!0,configurable:!0}),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,i,n,r){if(this._vertexBuffers[t]&&this._vertexBuffers[t].dispose(),this._vertexBuffers[t]=new e.VertexBuffer(this._engine,i,t,n,0===this._meshes.length,r),t===e.VertexBuffer.PositionKind){r=this._vertexBuffers[t].getStrideSize(),this._totalVertices=i.length/r,this.updateExtend(i);for(var o=this._meshes,s=o.length,a=0;s>a;a++){var h=o[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,i){var n=this.getVertexBuffer(e);n&&(n.updateDirectly(t,i),this.notifyUpdate(e))},t.prototype.updateVerticesData=function(t,i,n){var r=this.getVertexBuffer(t);if(r){if(r.update(i),t===e.VertexBuffer.PositionKind){var o=r.getStrideSize();this._totalVertices=i.length/o,n&&this.updateExtend(i);for(var s=this._meshes,a=s.length,h=0;a>h;h++){var c=s[h];if(c._resetPointsArrayCache(),n){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 i=this.getVertexBuffer(e);if(!i)return null;var n=i.getData();if(t&&1!==this._meshes.length){for(var r=n.length,o=[],s=0;r>s;s++)o.push(n[s]);return o}return n},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 i=this._meshes,n=i.length,r=0;n>r;r++)i[r]._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 i=t.length,n=[],r=0;i>r;r++)n.push(t[r]);return n}return t},t.prototype.getIndexBuffer=function(){return this.isReady()?this._indexBuffer:null},t.prototype.releaseForMesh=function(e,t){var i=this._meshes,n=i.indexOf(e);if(-1!==n){for(var r in this._vertexBuffers)this._vertexBuffers[r].dispose();this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer)&&(this._indexBuffer=null),i.splice(n,1),e._geometry=null,0===i.length&&t&&this.dispose()}},t.prototype.applyToMesh=function(e){if(e._geometry!==this){var t=e._geometry;t&&t.releaseForMesh(e);var i=this._meshes;e._geometry=this,this._scene.pushGeometry(this),i.push(e),this.isReady()?this._applyToMesh(e):e._boundingInfo=this._boundingInfo}},t.prototype.updateExtend=function(t){void 0===t&&(t=null),t||(t=this._vertexBuffers[e.VertexBuffer.PositionKind].getData()),this._extend=e.Tools.ExtractMinAndMax(t,0,this._totalVertices,this.boundingBias)},t.prototype._applyToMesh=function(t){var i=this._meshes.length;for(var n in this._vertexBuffers)1===i&&this._vertexBuffers[n].create(),this._vertexBuffers[n]._buffer.references=i,n===e.VertexBuffer.PositionKind&&(t._resetPointsArrayCache(),this._extend||this.updateExtend(this._vertexBuffers[n].getData()),t._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),t._createGlobalSubMesh(),t._updateBoundingInfo());1===i&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),this._indexBuffer&&(this._indexBuffer.references=i)},t.prototype.notifyUpdate=function(e){this.onGeometryUpdated&&this.onGeometryUpdated(this,e)},t.prototype.load=function(t,i){var n=this;if(this.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADING){if(this.isReady())return void(i&&i());this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,t._addPendingData(this),e.Tools.LoadFile(this.delayLoadingFile,function(r){n._delayLoadingFunction(JSON.parse(r),n),n.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,n._delayInfo=[],t._removePendingData(n);for(var o=n._meshes,s=o.length,a=0;s>a;a++)n._applyToMesh(o[a]);i&&i()},function(){},t.database)}},t.prototype.isDisposed=function(){return this._isDisposed},t.prototype.dispose=function(){var t,i=this._meshes,n=i.length;for(t=0;n>t;t++)this.releaseForMesh(i[t]);this._meshes=[];for(var r in this._vertexBuffers)this._vertexBuffers[r].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(i){var n=new e.VertexData;n.indices=[];for(var r=this.getIndices(),o=0;o<r.length;o++)n.indices.push(r[o]);var s,a=!1,h=!1;for(s in this._vertexBuffers){var c=this.getVerticesData(s);c instanceof Float32Array?n.set(new Float32Array(c),s):n.set(c.slice(0),s),h||(a=this.getVertexBuffer(s).isUpdatable(),h=!a)}var l=new t(i,this._scene,n,a,null);l.delayLoadState=this.delayLoadState,l.delayLoadingFile=this.delayLoadingFile,l._delayLoadingFunction=this._delayLoadingFunction;for(s in this._delayInfo)l._delayInfo=l._delayInfo||[],l._delayInfo.push(s);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 i=e._geometry;return i?i.copy(t):null},t.RandomId=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0,i="x"===e?t:3&t|8;return i.toString(16)})},t.ImportGeometry=function(t,i){var n=i.getScene(),r=t.geometryId;if(r){var o=n.getGeometryByID(r);o&&o.applyToMesh(i)}else if(t instanceof ArrayBuffer){var s=i._binaryInfo;if(s.positionsAttrDesc&&s.positionsAttrDesc.count>0){var a=new Float32Array(t,s.positionsAttrDesc.offset,s.positionsAttrDesc.count);i.setVerticesData(e.VertexBuffer.PositionKind,a,!1)}if(s.normalsAttrDesc&&s.normalsAttrDesc.count>0){var h=new Float32Array(t,s.normalsAttrDesc.offset,s.normalsAttrDesc.count);i.setVerticesData(e.VertexBuffer.NormalKind,h,!1)}if(s.uvsAttrDesc&&s.uvsAttrDesc.count>0){var c=new Float32Array(t,s.uvsAttrDesc.offset,s.uvsAttrDesc.count);i.setVerticesData(e.VertexBuffer.UVKind,c,!1)}if(s.uvs2AttrDesc&&s.uvs2AttrDesc.count>0){var l=new Float32Array(t,s.uvs2AttrDesc.offset,s.uvs2AttrDesc.count);i.setVerticesData(e.VertexBuffer.UV2Kind,l,!1)}if(s.uvs3AttrDesc&&s.uvs3AttrDesc.count>0){var u=new Float32Array(t,s.uvs3AttrDesc.offset,s.uvs3AttrDesc.count);i.setVerticesData(e.VertexBuffer.UV3Kind,u,!1)}if(s.uvs4AttrDesc&&s.uvs4AttrDesc.count>0){var d=new Float32Array(t,s.uvs4AttrDesc.offset,s.uvs4AttrDesc.count);i.setVerticesData(e.VertexBuffer.UV4Kind,d,!1)}if(s.uvs5AttrDesc&&s.uvs5AttrDesc.count>0){var f=new Float32Array(t,s.uvs5AttrDesc.offset,s.uvs5AttrDesc.count);i.setVerticesData(e.VertexBuffer.UV5Kind,f,!1)}if(s.uvs6AttrDesc&&s.uvs6AttrDesc.count>0){var p=new Float32Array(t,s.uvs6AttrDesc.offset,s.uvs6AttrDesc.count);i.setVerticesData(e.VertexBuffer.UV6Kind,p,!1)}if(s.colorsAttrDesc&&s.colorsAttrDesc.count>0){var m=new Float32Array(t,s.colorsAttrDesc.offset,s.colorsAttrDesc.count);i.setVerticesData(e.VertexBuffer.ColorKind,m,!1,s.colorsAttrDesc.stride)}if(s.matricesIndicesAttrDesc&&s.matricesIndicesAttrDesc.count>0){var _=new Int32Array(t,s.matricesIndicesAttrDesc.offset,s.matricesIndicesAttrDesc.count);i.setVerticesData(e.VertexBuffer.MatricesIndicesKind,_,!1)}if(s.matricesWeightsAttrDesc&&s.matricesWeightsAttrDesc.count>0){var g=new Float32Array(t,s.matricesWeightsAttrDesc.offset,s.matricesWeightsAttrDesc.count);i.setVerticesData(e.VertexBuffer.MatricesWeightsKind,g,!1)}if(s.indicesAttrDesc&&s.indicesAttrDesc.count>0){var v=new Int32Array(t,s.indicesAttrDesc.offset,s.indicesAttrDesc.count);i.setIndices(v)}if(s.subMeshesAttrDesc&&s.subMeshesAttrDesc.count>0){var y=new Int32Array(t,s.subMeshesAttrDesc.offset,5*s.subMeshesAttrDesc.count);i.subMeshes=[];for(var x=0;x<s.subMeshesAttrDesc.count;x++){var b=y[5*x+0],E=y[5*x+1],A=y[5*x+2],T=y[5*x+3],P=y[5*x+4];new e.SubMesh(b,E,A,T,P,i)}}}else if(t.positions&&t.normals&&t.indices){if(i.setVerticesData(e.VertexBuffer.PositionKind,t.positions,!1),i.setVerticesData(e.VertexBuffer.NormalKind,t.normals,!1),t.uvs&&i.setVerticesData(e.VertexBuffer.UVKind,t.uvs,!1),t.uvs2&&i.setVerticesData(e.VertexBuffer.UV2Kind,t.uvs2,!1),t.uvs3&&i.setVerticesData(e.VertexBuffer.UV3Kind,t.uvs3,!1),t.uvs4&&i.setVerticesData(e.VertexBuffer.UV4Kind,t.uvs4,!1),t.uvs5&&i.setVerticesData(e.VertexBuffer.UV5Kind,t.uvs5,!1),t.uvs6&&i.setVerticesData(e.VertexBuffer.UV6Kind,t.uvs6,!1),t.colors&&i.setVerticesData(e.VertexBuffer.ColorKind,e.Color4.CheckColors4(t.colors,t.positions.length/3),!1),t.matricesIndices)if(t.matricesIndices._isExpanded)delete t.matricesIndices._isExpanded,i.setVerticesData(e.VertexBuffer.MatricesIndicesKind,t.matricesIndices,!1);else{for(var M=[],x=0;x<t.matricesIndices.length;x++){var C=t.matricesIndices[x];M.push(255&C),M.push((65280&C)>>8),M.push((16711680&C)>>16),M.push(C>>24)}i.setVerticesData(e.VertexBuffer.MatricesIndicesKind,M,!1)}if(t.matricesIndicesExtra)if(t.matricesIndicesExtra._isExpanded)delete t.matricesIndices._isExpanded,i.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,t.matricesIndicesExtra,!1);else{for(var M=[],x=0;x<t.matricesIndicesExtra.length;x++){var C=t.matricesIndicesExtra[x];M.push(255&C),M.push((65280&C)>>8),M.push((16711680&C)>>16),M.push(C>>24)}i.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,M,!1)}t.matricesWeights&&i.setVerticesData(e.VertexBuffer.MatricesWeightsKind,t.matricesWeights,!1),t.matricesWeightsExtra&&i.setVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,t.matricesWeightsExtra,!1),i.setIndices(t.indices)}if(t.subMeshes){i.subMeshes=[];for(var S=0;S<t.subMeshes.length;S++){var R=t.subMeshes[S];new e.SubMesh(R.materialIndex,R.verticesStart,R.verticesCount,R.indexStart,R.indexCount,i)}}i._shouldGenerateFlatShading&&(i.convertToFlatShadedMesh(),delete i._shouldGenerateFlatShading),i.computeWorldMatrix(!0),n._selectionOctree&&n._selectionOctree.addMesh(i)},t.Parse=function(i,n,r){if(n.getGeometryByID(i.id))return null;var o=new t(i.id,n);return e.Tags.AddTagsTo(o,i.tags),i.delayLoadingFile?(o.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,o.delayLoadingFile=r+i.delayLoadingFile,o._boundingInfo=new e.BoundingInfo(e.Vector3.FromArray(i.boundingBoxMinimum),e.Vector3.FromArray(i.boundingBoxMaximum)),o._delayInfo=[],i.hasUVs&&o._delayInfo.push(e.VertexBuffer.UVKind),i.hasUVs2&&o._delayInfo.push(e.VertexBuffer.UV2Kind),i.hasUVs3&&o._delayInfo.push(e.VertexBuffer.UV3Kind),i.hasUVs4&&o._delayInfo.push(e.VertexBuffer.UV4Kind),i.hasUVs5&&o._delayInfo.push(e.VertexBuffer.UV5Kind),i.hasUVs6&&o._delayInfo.push(e.VertexBuffer.UV6Kind),i.hasColors&&o._delayInfo.push(e.VertexBuffer.ColorKind),i.hasMatricesIndices&&o._delayInfo.push(e.VertexBuffer.MatricesIndicesKind),i.hasMatricesWeights&&o._delayInfo.push(e.VertexBuffer.MatricesWeightsKind),o._delayLoadingFunction=e.VertexData.ImportVertexData):e.VertexData.ImportVertexData(i,o),n.pushGeometry(o,!0),o},t}();e.Geometry=t;var t;!function(t){var i;!function(i){var n=function(e){function t(t,i,n,r){e.call(this,t,i,null,!1,r),this._canBeRegenerated=n,this._beingRegenerated=!0,this.regenerate(),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,i){this._beingRegenerated&&e.prototype.setAllVerticesData.call(this,t,!1);
  20. },t.prototype.setVerticesData=function(t,i,n){this._beingRegenerated&&e.prototype.setVerticesData.call(this,t,i,!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);i._Primitive=n;var r=function(t){function i(i,n,r,o,s,a,h,c,l){void 0===l&&(l=e.Mesh.DEFAULTSIDE),t.call(this,i,n,h,c),this.pathArray=r,this.closeArray=o,this.closePath=s,this.offset=a,this.side=l}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateRibbon({pathArray:this.pathArray,closeArray:this.closeArray,closePath:this.closePath,offset:this.offset,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.pathArray,this.closeArray,this.closePath,this.offset,this.canBeRegenerated(),null,this.side)},i}(n);i.Ribbon=r;var o=function(i){function n(t,n,r,o,s,a){void 0===a&&(a=e.Mesh.DEFAULTSIDE),i.call(this,t,n,o,s),this.size=r,this.side=a}return __extends(n,i),n.prototype._regenerateVertexData=function(){return e.VertexData.CreateBox({size:this.size,sideOrientation:this.side})},n.prototype.copy=function(e){return new n(e,this.getScene(),this.size,this.canBeRegenerated(),null,this.side)},n.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.size=this.size,e},n.Parse=function(i,n){if(n.getGeometryByID(i.id))return null;var r=new t.Primitives.Box(i.id,n,i.size,i.canBeRegenerated,null);return e.Tags.AddTagsTo(r,i.tags),n.pushGeometry(r,!0),r},n}(n);i.Box=o;var s=function(i){function n(t,n,r,o,s,a,h){void 0===h&&(h=e.Mesh.DEFAULTSIDE),i.call(this,t,n,s,a),this.segments=r,this.diameter=o,this.side=h}return __extends(n,i),n.prototype._regenerateVertexData=function(){return e.VertexData.CreateSphere({segments:this.segments,diameter:this.diameter,sideOrientation:this.side})},n.prototype.copy=function(e){return new n(e,this.getScene(),this.segments,this.diameter,this.canBeRegenerated(),null,this.side)},n.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.segments=this.segments,e.diameter=this.diameter,e},n.Parse=function(i,n){if(n.getGeometryByID(i.id))return null;var r=new t.Primitives.Sphere(i.id,n,i.segments,i.diameter,i.canBeRegenerated,null);return e.Tags.AddTagsTo(r,i.tags),n.pushGeometry(r,!0),r},n}(n);i.Sphere=s;var a=function(t){function i(i,n,r,o,s,a,h){void 0===h&&(h=e.Mesh.DEFAULTSIDE),t.call(this,i,n,s,a),this.radius=r,this.tessellation=o,this.side=h}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateDisc({radius:this.radius,tessellation:this.tessellation,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.radius,this.tessellation,this.canBeRegenerated(),null,this.side)},i}(n);i.Disc=a;var h=function(i){function n(t,n,r,o,s,a,h,c,l,u){void 0===h&&(h=1),void 0===u&&(u=e.Mesh.DEFAULTSIDE),i.call(this,t,n,c,l),this.height=r,this.diameterTop=o,this.diameterBottom=s,this.tessellation=a,this.subdivisions=h,this.side=u}return __extends(n,i),n.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})},n.prototype.copy=function(e){return new n(e,this.getScene(),this.height,this.diameterTop,this.diameterBottom,this.tessellation,this.subdivisions,this.canBeRegenerated(),null,this.side)},n.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.height=this.height,e.diameterTop=this.diameterTop,e.diameterBottom=this.diameterBottom,e.tessellation=this.tessellation,e},n.Parse=function(i,n){if(n.getGeometryByID(i.id))return null;var r=new t.Primitives.Cylinder(i.id,n,i.height,i.diameterTop,i.diameterBottom,i.tessellation,i.subdivisions,i.canBeRegenerated,null);return e.Tags.AddTagsTo(r,i.tags),n.pushGeometry(r,!0),r},n}(n);i.Cylinder=h;var c=function(i){function n(t,n,r,o,s,a,h,c){void 0===c&&(c=e.Mesh.DEFAULTSIDE),i.call(this,t,n,a,h),this.diameter=r,this.thickness=o,this.tessellation=s,this.side=c}return __extends(n,i),n.prototype._regenerateVertexData=function(){return e.VertexData.CreateTorus({diameter:this.diameter,thickness:this.thickness,tessellation:this.tessellation,sideOrientation:this.side})},n.prototype.copy=function(e){return new n(e,this.getScene(),this.diameter,this.thickness,this.tessellation,this.canBeRegenerated(),null,this.side)},n.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.diameter=this.diameter,e.thickness=this.thickness,e.tessellation=this.tessellation,e},n.Parse=function(i,n){if(n.getGeometryByID(i.id))return null;var r=new t.Primitives.Torus(i.id,n,i.diameter,i.thickness,i.tessellation,i.canBeRegenerated,null);return e.Tags.AddTagsTo(r,i.tags),n.pushGeometry(r,!0),r},n}(n);i.Torus=c;var l=function(i){function n(e,t,n,r,o,s,a){i.call(this,e,t,s,a),this.width=n,this.height=r,this.subdivisions=o}return __extends(n,i),n.prototype._regenerateVertexData=function(){return e.VertexData.CreateGround({width:this.width,height:this.height,subdivisions:this.subdivisions})},n.prototype.copy=function(e){return new n(e,this.getScene(),this.width,this.height,this.subdivisions,this.canBeRegenerated(),null)},n.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.width=this.width,e.height=this.height,e.subdivisions=this.subdivisions,e},n.Parse=function(i,n){if(n.getGeometryByID(i.id))return null;var r=new t.Primitives.Ground(i.id,n,i.width,i.height,i.subdivisions,i.canBeRegenerated,null);return e.Tags.AddTagsTo(r,i.tags),n.pushGeometry(r,!0),r},n}(n);i.Ground=l;var u=function(t){function i(e,i,n,r,o,s,a,h,c,l){t.call(this,e,i,c,l),this.xmin=n,this.zmin=r,this.xmax=o,this.zmax=s,this.subdivisions=a,this.precision=h}return __extends(i,t),i.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})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.xmin,this.zmin,this.xmax,this.zmax,this.subdivisions,this.precision,this.canBeRegenerated(),null)},i}(n);i.TiledGround=u;var d=function(i){function n(t,n,r,o,s,a){void 0===a&&(a=e.Mesh.DEFAULTSIDE),i.call(this,t,n,o,s),this.size=r,this.side=a}return __extends(n,i),n.prototype._regenerateVertexData=function(){return e.VertexData.CreatePlane({size:this.size,sideOrientation:this.side})},n.prototype.copy=function(e){return new n(e,this.getScene(),this.size,this.canBeRegenerated(),null,this.side)},n.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.size=this.size,e},n.Parse=function(i,n){if(n.getGeometryByID(i.id))return null;var r=new t.Primitives.Plane(i.id,n,i.size,i.canBeRegenerated,null);return e.Tags.AddTagsTo(r,i.tags),n.pushGeometry(r,!0),r},n}(n);i.Plane=d;var f=function(i){function n(t,n,r,o,s,a,h,c,l,u,d){void 0===d&&(d=e.Mesh.DEFAULTSIDE),i.call(this,t,n,l,u),this.radius=r,this.tube=o,this.radialSegments=s,this.tubularSegments=a,this.p=h,this.q=c,this.side=d}return __extends(n,i),n.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})},n.prototype.copy=function(e){return new n(e,this.getScene(),this.radius,this.tube,this.radialSegments,this.tubularSegments,this.p,this.q,this.canBeRegenerated(),null,this.side)},n.prototype.serialize=function(){var e=i.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},n.Parse=function(i,n){if(n.getGeometryByID(i.id))return null;var r=new t.Primitives.TorusKnot(i.id,n,i.radius,i.tube,i.radialSegments,i.tubularSegments,i.p,i.q,i.canBeRegenerated,null);return e.Tags.AddTagsTo(r,i.tags),n.pushGeometry(r,!0),r},n}(n);i.TorusKnot=f}(i=t.Primitives||(t.Primitives={}))}(t=e.Geometry||(e.Geometry={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n){t.call(this,i,n),this.generateOctree=!1,this._worldInverse=new e.Matrix}return __extends(i,t),Object.defineProperty(i.prototype,"subdivisions",{get:function(){return this._subdivisions},enumerable:!0,configurable:!0}),i.prototype.optimize=function(e,t){void 0===t&&(t=32),this._subdivisions=e,this.subdivide(this._subdivisions),this.createOrUpdateSubmeshesOctree(t)},i.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._initHeightQuads(),this._computeHeightQuads());var i=this._getFacetAt(e,t),n=-(i.x*e+i.z*t+i.w)/i.y;return n*this.scaling.y+this.position.y},i.prototype.getNormalAtCoordinates=function(t,i){var n=new e.Vector3(0,1,0);return this.getNormalAtCoordinatesToRef(t,i,n),n},i.prototype.getNormalAtCoordinatesToRef=function(e,t,i){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._initHeightQuads(),this._computeHeightQuads());var n=this._getFacetAt(e,t);i.x=n.x,i.y=n.y,i.z=n.z}},i.prototype.updateCoordinateHeights=function(){this._heightQuads&&0!=this._heightQuads.length||this._initHeightQuads(),this._computeHeightQuads()},i.prototype._getFacetAt=function(e,t){var i,n=Math.floor((e+this._maxX)*this._subdivisions/this._width),r=Math.floor(-(t+this._maxZ)*this._subdivisions/this._height+this._subdivisions),o=this._heightQuads[r*this._subdivisions+n];return i=t<o.slope.x*e+o.slope.y?o.facet1:o.facet2},i.prototype._initHeightQuads=function(){this._heightQuads=new Array;for(var t=0;t<this._subdivisions;t++)for(var i=0;i<this._subdivisions;i++){var n={slope:e.Vector2.Zero(),facet1:new e.Vector4(0,0,0,0),facet2:new e.Vector4(0,0,0,0)};this._heightQuads[t*this._subdivisions+i]=n}},i.prototype._computeHeightQuads=function(){for(var t=this.getVerticesData(e.VertexBuffer.PositionKind),i=e.Tmp.Vector3[0],n=e.Tmp.Vector3[1],r=e.Tmp.Vector3[2],o=e.Tmp.Vector3[3],s=e.Tmp.Vector3[4],a=e.Tmp.Vector3[5],h=e.Tmp.Vector3[6],c=e.Tmp.Vector3[7],l=e.Tmp.Vector3[8],u=0,d=0,f=0,p=0,m=0,_=0,g=0,v=0;v<this._subdivisions;v++)for(var y=0;y<this._subdivisions;y++){u=3*y,d=v*(this._subdivisions+1)*3,f=(v+1)*(this._subdivisions+1)*3,i.x=t[d+u],i.y=t[d+u+1],i.z=t[d+u+2],n.x=t[d+u+3],n.y=t[d+u+4],n.z=t[d+u+5],r.x=t[f+u],r.y=t[f+u+1],r.z=t[f+u+2],o.x=t[f+u+3],o.y=t[f+u+4],o.z=t[f+u+5],p=(o.z-i.z)/(o.x-i.x),m=i.z-p*i.x,n.subtractToRef(i,s),r.subtractToRef(i,a),o.subtractToRef(i,h),e.Vector3.CrossToRef(h,a,c),e.Vector3.CrossToRef(s,h,l),c.normalize(),l.normalize(),_=-(c.x*i.x+c.y*i.y+c.z*i.z),g=-(l.x*n.x+l.y*n.y+l.z*n.z);var x=this._heightQuads[v*this._subdivisions+y];x.slope.copyFromFloats(p,m),x.facet1.copyFromFloats(c.x,c.y,c.z,_),x.facet2.copyFromFloats(l.x,l.y,l.z,g)}},i}(e.Mesh);e.GroundMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s){void 0===r&&(r=null),t.call(this,i,n,r,o,s),this.color=new e.Color3(1,1,1),this.alpha=1,this._intersectionThreshold=.1,this._colorShader=new e.ShaderMaterial("colorShader",n,"color",{attributes:["position"],uniforms:["worldViewProjection","color"],needAlphaBlending:!0})}return __extends(i,t),Object.defineProperty(i.prototype,"intersectionThreshold",{get:function(){return this._intersectionThreshold},set:function(t){this._intersectionThreshold!==t&&(this._intersectionThreshold=t,this.geometry&&(this.geometry.boundingBias=new e.Vector2(0,t)))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"material",{get:function(){return this._colorShader},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isPickable",{get:function(){return!0},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"checkCollisions",{get:function(){return!1},enumerable:!0,configurable:!0}),i.prototype._bind=function(t,i,n){var r=this.getScene().getEngine(),o=this._geometry.getIndexBuffer();r.bindBuffers(this._geometry.getVertexBuffer(e.VertexBuffer.PositionKind).getBuffer(),o,[3],12,this._colorShader.getEffect()),this._colorShader.setColor4("color",this.color.toColor4(this.alpha))},i.prototype._draw=function(e,t,i){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var n=this.getScene().getEngine();n.draw(!1,e.indexStart,e.indexCount)}},i.prototype.dispose=function(e){this._colorShader.dispose(),t.prototype.dispose.call(this,e)},i.prototype.clone=function(e,t,n){return new i(e,this.getScene(),t,this,n)},i}(e.Mesh);e.LinesMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){var i=this;this._transformationMatrix=e.Matrix.Identity(),this._enabled=!1,this._labelsEnabled=!1,this._displayStatistics=!0,this._displayTree=!1,this._displayLogs=!1,this._skeletonViewers=new Array,this._identityMatrix=e.Matrix.Identity(),this.axisRatio=.02,this.accentColor="orange",this._scene=t,this._syncPositions=function(){var e=i._scene.getEngine(),t=e.getRenderingCanvasClientRect();i._showUI&&(i._statsDiv.style.left=t.width-410+"px",i._statsDiv.style.top=t.height-290+"px",i._statsDiv.style.width="400px",i._statsDiv.style.height="auto",i._statsSubsetDiv.style.maxHeight="240px",i._optionsDiv.style.left="0px",i._optionsDiv.style.top="10px",i._optionsDiv.style.width="200px",i._optionsDiv.style.height="auto",i._optionsSubsetDiv.style.maxHeight=t.height-225+"px",i._logDiv.style.left="0px",i._logDiv.style.top=t.height-170+"px",i._logDiv.style.width="600px",i._logDiv.style.height="160px",i._treeDiv.style.left=t.width-310+"px",i._treeDiv.style.top="10px",i._treeDiv.style.width="300px",i._treeDiv.style.height="auto",i._treeSubsetDiv.style.maxHeight=t.height-340+"px"),i._globalDiv.style.left=t.left+"px",i._globalDiv.style.top=t.top+"px",i._drawingCanvas.style.left="0px",i._drawingCanvas.style.top="0px",i._drawingCanvas.style.width=e.getRenderWidth()+"px",i._drawingCanvas.style.height=e.getRenderHeight()+"px";var n=window.devicePixelRatio||1,r=i._drawingContext,o=r.webkitBackingStorePixelRatio||r.mozBackingStorePixelRatio||r.msBackingStorePixelRatio||r.oBackingStorePixelRatio||r.backingStorePixelRatio||1;i._ratio=n/o,i._drawingCanvas.width=e.getRenderWidth()*i._ratio,i._drawingCanvas.height=e.getRenderHeight()*i._ratio},this._onCanvasClick=function(e){i._clickPosition={x:e.clientX*i._ratio,y:e.clientY*i._ratio}},this._syncUI=function(){i._showUI&&(i._displayStatistics?(i._displayStats(),i._statsDiv.style.display=""):i._statsDiv.style.display="none",i._displayLogs?i._logDiv.style.display="":i._logDiv.style.display="none",i._displayTree?(i._treeDiv.style.display="",i._needToRefreshMeshesTree&&(i._needToRefreshMeshesTree=!1,i._refreshMeshesTreeContent())):i._treeDiv.style.display="none")},this._syncData=function(){if(i._labelsEnabled||!i._showUI){i._camera.getViewMatrix().multiplyToRef(i._camera.getProjectionMatrix(),i._transformationMatrix),i._drawingContext.clearRect(0,0,i._drawingCanvas.width,i._drawingCanvas.height);var t,n,r=i._scene.getEngine(),o=i._camera.viewport,s=o.toGlobal(r.getRenderWidth(),r.getRenderHeight()),a=i._camera.getActiveMeshes();for(t=0;t<a.length;t++){var h=a.data[t],c=h.getBoundingInfo().boundingSphere.center;n=e.Vector3.Project(c,h.getWorldMatrix(),i._transformationMatrix,s),(h.renderOverlay||i.shouldDisplayAxis&&i.shouldDisplayAxis(h))&&i._renderAxis(n,h,s),i.shouldDisplayLabel&&!i.shouldDisplayLabel(h)||i._renderLabel(h.name,n,12,function(){h.renderOverlay=!h.renderOverlay},function(){return h.renderOverlay?"red":"black"})}var l=i._scene.cameras;for(t=0;t<l.length;t++){var u=l[t];u!==i._camera&&(n=e.Vector3.Project(e.Vector3.Zero(),u.getWorldMatrix(),i._transformationMatrix,s),i.shouldDisplayLabel&&!i.shouldDisplayLabel(u)||i._renderLabel(u.name,n,12,function(){i._camera.detachControl(r.getRenderingCanvas()),i._camera=u,i._camera.attachControl(r.getRenderingCanvas())},function(){return"purple"}))}var d=i._scene.lights;for(t=0;t<d.length;t++){var f=d[t];f.position&&(n=e.Vector3.Project(f.getAbsolutePosition(),i._identityMatrix,i._transformationMatrix,s),i.shouldDisplayLabel&&!i.shouldDisplayLabel(f)||i._renderLabel(f.name,n,-20,function(){f.setEnabled(!f.isEnabled())},function(){return f.isEnabled()?"orange":"gray"}))}}i._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 i=e[t];i.isEnabled()&&this._generateAdvancedCheckBox(this._treeSubsetDiv,i.name,i.getTotalVertices()+" verts",i.isVisible,function(e,t){t.isVisible=e.checked},i)}},t.prototype._renderSingleAxis=function(e,t,i,n,r){this._drawingContext.beginPath(),this._drawingContext.moveTo(e.x,e.y),this._drawingContext.lineTo(t.x,t.y),this._drawingContext.strokeStyle=r,this._drawingContext.lineWidth=4,this._drawingContext.stroke(),this._drawingContext.font="normal 14px Segoe UI",this._drawingContext.fillStyle=r,this._drawingContext.fillText(n,i.x,i.y)},t.prototype._renderAxis=function(t,i,n){var r=i.getBoundingInfo().boundingSphere.center,o=i.getWorldMatrix(),s=e.Vector3.UnprojectFromTransform(t.add(new e.Vector3(this._drawingCanvas.width*this.axisRatio,0,0)),n.width,n.height,o,this._transformationMatrix),a=s.subtract(r).length(),h=e.Vector3.Project(r.add(new e.Vector3(a,0,0)),o,this._transformationMatrix,n),c=e.Vector3.Project(r.add(new e.Vector3(1.5*a,0,0)),o,this._transformationMatrix,n);this._renderSingleAxis(t,h,c,"x","#FF0000");var l=e.Vector3.Project(r.add(new e.Vector3(0,a,0)),o,this._transformationMatrix,n),u=e.Vector3.Project(r.add(new e.Vector3(0,1.5*a,0)),o,this._transformationMatrix,n);this._renderSingleAxis(t,l,u,"y","#00FF00");var d=e.Vector3.Project(r.add(new e.Vector3(0,0,a)),o,this._transformationMatrix,n),f=e.Vector3.Project(r.add(new e.Vector3(0,0,1.5*a)),o,this._transformationMatrix,n);this._renderSingleAxis(t,d,f,"z","#0000FF")},t.prototype._renderLabel=function(e,t,i,n,r){if(t.z>0&&t.z<1){this._drawingContext.font="normal 12px Segoe UI";var o=this._drawingContext.measureText(e),s=t.x-o.width/2,a=t.y,h=this._drawingCanvas.getBoundingClientRect();this._showUI&&this._isClickInsideRect(h.left*this._ratio+s-5,h.top*this._ratio+a-i-12,o.width+10,17)&&n(),this._drawingContext.beginPath(),this._drawingContext.rect(s-5,a-i-12,o.width+10,17),this._drawingContext.fillStyle=r(),this._drawingContext.globalAlpha=.5,this._drawingContext.fill(),this._drawingContext.globalAlpha=1,this._drawingContext.strokeStyle="#FFFFFF",this._drawingContext.lineWidth=1,this._drawingContext.stroke(),this._drawingContext.fillStyle="#FFFFFF",this._drawingContext.fillText(e,s,a-i),this._drawingContext.beginPath(),this._drawingContext.arc(t.x,a,5,0,2*Math.PI,!1),this._drawingContext.fill()}},t.prototype._isClickInsideRect=function(e,t,i,n){return this._clickPosition?this._clickPosition.x<e||this._clickPosition.x>e+i?!1:!(this._clickPosition.y<t||this._clickPosition.y>t+n):!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.LightmapTextureEnabled=!0,e.StandardMaterial.RefractionTextureEnabled=!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),this._clearSkeletonViewers()}},t.prototype._clearSkeletonViewers=function(){for(var e=0;e<this._skeletonViewers.length;e++)this._skeletonViewers[e].dispose();this._skeletonViewers=[]},t.prototype.show=function(e,t,i){if(void 0===e&&(e=!0),void 0===t&&(t=null),void 0===i&&(i=null),!this._enabled){this._enabled=!0,t?this._camera=t:this._camera=this._scene.activeCamera,this._showUI=e;var n=this._scene.getEngine();this._globalDiv=document.createElement("div"),this._rootElement=i||document.body,this._rootElement.appendChild(this._globalDiv),this._generateDOMelements(),n.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 i=document.createElement("div");i.innerHTML=t+"&nbsp;",i.style.textAlign="right",i.style.width="100%",i.style.color="white",i.style.backgroundColor="Black",i.style.padding="5px 5px 4px 0px",i.style.marginLeft="-5px",i.style.fontWeight="bold",e.appendChild(i)},t.prototype._generateTexBox=function(e,t,i){var n=document.createElement("label");n.style.display="inline",n.innerHTML=t,n.style.color=i,e.appendChild(n),e.appendChild(document.createElement("br"))},t.prototype._generateAdvancedCheckBox=function(e,t,i,n,r,o){void 0===o&&(o=null);var s=document.createElement("label");s.style.display="inline";var a=document.createElement("input");a.type="checkbox",a.checked=n,a.style.display="inline",a.style.margin="0px 5px 0px 0px",a.style.verticalAlign="sub",a.addEventListener("change",function(e){r(e.target,o)}),s.appendChild(a);var h=document.createElement("span"),c=document.createElement("span"),l=document.createElement("span");l.style.cssFloat="right",c.innerHTML=t,l.innerHTML=i,l.style.fontSize="12px",l.style.maxWidth="200px",h.appendChild(c),h.appendChild(l),s.appendChild(h),e.appendChild(s),e.appendChild(document.createElement("br"))},t.prototype._generateCheckBox=function(e,t,i,n,r){void 0===r&&(r=null);var o=document.createElement("label");o.style.display="inline";var s=document.createElement("input");s.type="checkbox",s.checked=i,s.style.display="inline",s.style.margin="0px 5px 0px 0px",s.style.verticalAlign="sub",s.addEventListener("change",function(e){n(e.target,r)}),o.appendChild(s),o.appendChild(document.createTextNode(t)),e.appendChild(o),e.appendChild(document.createElement("br"))},t.prototype._generateButton=function(e,t,i,n){void 0===n&&(n=null);var r=document.createElement("button");r.innerHTML=t,r.style.height="24px",r.style.width="150px",r.style.marginBottom="5px",r.style.color="#444444",r.style.border="1px solid white",r.className="debugLayerButton",r.addEventListener("click",function(e){i(e.target,n)}),e.appendChild(r),e.appendChild(document.createElement("br"))},t.prototype._generateRadio=function(e,t,i,n,r,o){void 0===o&&(o=null);var s=document.createElement("label");s.style.display="inline";var a=document.createElement("input");a.type="radio",a.name=i,a.checked=n,a.style.display="inline",a.style.margin="0px 5px 0px 0px",a.style.verticalAlign="sub",a.addEventListener("change",function(e){r(e.target,o)}),s.appendChild(a),s.appendChild(document.createTextNode(t)),e.appendChild(s),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 i="rgba(128, 128, 128, 0.4)",n="rgb(180, 180, 180) solid 1px";this._statsDiv=document.createElement("div"),this._statsDiv.id="DebugLayerStats",this._statsDiv.style.border=n,this._statsDiv.style.position="absolute",this._statsDiv.style.background=i,this._statsDiv.style.padding="0px 0px 0px 5px",this._generateheader(this._statsDiv,"STATISTICS"),this._statsSubsetDiv=document.createElement("div"),this._statsSubsetDiv.style.paddingTop="5px",this._statsSubsetDiv.style.paddingBottom="5px",this._statsSubsetDiv.style.overflowY="auto",this._statsDiv.appendChild(this._statsSubsetDiv),this._treeDiv=document.createElement("div"),this._treeDiv.id="DebugLayerTree",this._treeDiv.style.border=n,this._treeDiv.style.position="absolute",this._treeDiv.style.background=i,this._treeDiv.style.padding="0px 0px 0px 5px",this._treeDiv.style.display="none",this._generateheader(this._treeDiv,"MESHES TREE"),this._treeSubsetDiv=document.createElement("div"),this._treeSubsetDiv.style.paddingTop="5px",this._treeSubsetDiv.style.paddingRight="5px",this._treeSubsetDiv.style.overflowY="auto",this._treeSubsetDiv.style.maxHeight="300px",this._treeDiv.appendChild(this._treeSubsetDiv),this._needToRefreshMeshesTree=!0,this._logDiv=document.createElement("div"),this._logDiv.style.border=n,this._logDiv.id="DebugLayerLogs",this._logDiv.style.position="absolute",this._logDiv.style.background=i,this._logDiv.style.padding="0px 0px 0px 5px",this._logDiv.style.display="none",this._generateheader(this._logDiv,"LOGS"),this._logSubsetDiv=document.createElement("div"),this._logSubsetDiv.style.height="127px",this._logSubsetDiv.style.paddingTop="5px",this._logSubsetDiv.style.overflowY="auto",this._logSubsetDiv.style.fontSize="12px",this._logSubsetDiv.style.fontFamily="consolas",this._logSubsetDiv.innerHTML=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=n,this._optionsDiv.style.position="absolute",this._optionsDiv.style.background=i,this._optionsDiv.style.padding="0px 0px 0px 5px",this._optionsDiv.style.overflowY="auto",this._generateheader(this._optionsDiv,"OPTIONS"),this._optionsSubsetDiv=document.createElement("div"),this._optionsSubsetDiv.style.paddingTop="5px",this._optionsSubsetDiv.style.paddingBottom="5px",this._optionsSubsetDiv.style.overflowY="auto",this._optionsSubsetDiv.style.maxHeight="200px",this._optionsDiv.appendChild(this._optionsSubsetDiv),this._generateTexBox(this._optionsSubsetDiv,"<b>Windows:</b>",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Statistics",this._displayStatistics,function(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,"Refraction",e.StandardMaterial.RefractionTextureEnabled,function(t){e.StandardMaterial.RefractionTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lightmap",e.StandardMaterial.LightmapTextureEnabled,function(t){e.StandardMaterial.LightmapTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fresnel",e.StandardMaterial.FresnelEnabled,function(t){e.StandardMaterial.FresnelEnabled=t.checked}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<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){
  21. 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>Viewers:</b>",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Skeletons",!1,function(i){if(!i.checked)return void t._clearSkeletonViewers();for(var n=0;n<t._scene.meshes.length;n++){var r=t._scene.meshes[n];if(r.skeleton){for(var o=!1,s=0;s<t._skeletonViewers.length;s++)if(t._skeletonViewers[s].skeleton===r.skeleton){o=!0;break}if(o)continue;var a=new e.Debug.SkeletonViewer(r.skeleton,r,t._scene);a.isEnabled=!0,t._skeletonViewers.push(a)}}}),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(i){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,i=t.getEngine(),n=i.getGlInfo();this._statsSubsetDiv.innerHTML="Babylon.js v"+e.Engine.Version+" - <b>"+e.Tools.Format(i.getFps(),0)+" fps</b><br><br><div style='column-count: 2;-moz-column-count:2;-webkit-column-count:2'><b>Count</b><br>Total meshes: "+t.meshes.length+"<br>Total lights: "+t.lights.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: "+i.drawCalls+"</b><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: "+i.getRenderWidth()+"x"+i.getRenderHeight()+"<br><br></div><div style='column-count: 2;-moz-column-count:2;-webkit-column-count:2'><b>Extensions</b><br>Std derivatives: "+(i.getCaps().standardDerivatives?"Yes":"No")+"<br>Compressed textures: "+(i.getCaps().s3tc?"Yes":"No")+"<br>Hardware instances: "+(i.getCaps().instancedArrays?"Yes":"No")+"<br>Texture float: "+(i.getCaps().textureFloat?"Yes":"No")+"<br><br>32bits indices: "+(i.getCaps().uintIndices?"Yes":"No")+"<br>Fragment depth: "+(i.getCaps().fragmentDepthSupported?"Yes":"No")+"<br>High precision shaders: "+(i.getCaps().highPrecisionShaderSupported?"Yes":"No")+"<br>Draw buffers: "+(i.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: "+i.getCaps().maxTexturesImageUnits+"<br>Max textures size: "+i.getCaps().maxTextureSize+"<br>Max anisotropy: "+i.getCaps().maxAnisotropy+"<br><b>Info</b><br>WebGL feature level: "+i.webGLVersion+"<br>"+n.version+"<br></div><br>"+n.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,i){var n=this;void 0===t&&(t=""),void 0===i&&(i="black"),this._renderingCanvas=e,this._loadingText=t,this._loadingDivBackgroundColor=i,this._resizeLoadingUI=function(){var e=n._renderingCanvas.getBoundingClientRect();n._loadingDiv.style.position="absolute",n._loadingDiv.style.left=e.left+"px",n._loadingDiv.style.top=e.top+"px",n._loadingDiv.style.width=e.width+"px",n._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 i=360,n=function(){i+=360,t.style.transform="rotateZ("+i+"deg)",t.style.webkitTransform="rotateZ("+i+"deg)"};t.addEventListener("transitionend",n),t.addEventListener("webkitTransitionEnd",n),this._loadingDiv.appendChild(t);var r=new Image;r.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=",r.style.position="absolute",r.style.left="50%",r.style.top="50%",r.style.marginLeft="-50px",r.style.marginTop="-50px",this._loadingDiv.appendChild(r),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={}));var BABYLON;!function(e){var t=function(){function t(){this._audioContext=null,this._audioContextInitialized=!1,this.canUseWebAudio=!1,this.WarnedWebAudioUnsupported=!1,this.unlocked=!1,"undefined"==typeof window.AudioContext&&"undefined"==typeof window.webkitAudioContext||(window.AudioContext=window.AudioContext||window.webkitAudioContext,this.canUseWebAudio=!0),/iPad|iPhone|iPod/.test(navigator.platform)?this._unlockiOSaudio():this.unlocked=!0}return Object.defineProperty(t.prototype,"audioContext",{get:function(){return this._audioContextInitialized||this._initializeAudioContext(),this._audioContext},enumerable:!0,configurable:!0}),t.prototype._unlockiOSaudio=function(){var e=this,t=function(){var i=e.audioContext.createBuffer(1,1,22050),n=e.audioContext.createBufferSource();n.buffer=i,n.connect(e.audioContext.destination),n.start(0),setTimeout(function(){n.playbackState!==n.PLAYING_STATE&&n.playbackState!==n.FINISHED_STATE||(e.unlocked=!0,window.removeEventListener("touchend",t,!1),e.onAudioUnlocked&&e.onAudioUnlocked())},0)};window.addEventListener("touchend",t,!1)},t.prototype._initializeAudioContext=function(){try{this.canUseWebAudio&&(this._audioContext=new AudioContext,this.masterGain=this._audioContext.createGain(),this.masterGain.gain.value=1,this.masterGain.connect(this._audioContext.destination),this._audioContextInitialized=!0)}catch(t){this.canUseWebAudio=!1,e.Tools.Error("Web Audio: "+t.message)}},t.prototype.dispose=function(){this.canUseWebAudio&&this._audioContextInitialized&&(this._connectedAnalyser&&(this._connectedAnalyser.stopDebugCanvas(),this._connectedAnalyser.dispose(),this.masterGain.disconnect(),this.masterGain.connect(this._audioContext.destination),this._connectedAnalyser=null),this.masterGain.gain.value=1),this.WarnedWebAudioUnsupported=!1},t.prototype.getGlobalVolume=function(){return this.canUseWebAudio&&this._audioContextInitialized?this.masterGain.gain.value:-1},t.prototype.setGlobalVolume=function(e){this.canUseWebAudio&&this._audioContextInitialized&&(this.masterGain.gain.value=e)},t.prototype.connectToAnalyser=function(e){this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas(),this.canUseWebAudio&&this._audioContextInitialized&&(this._connectedAnalyser=e,this.masterGain.disconnect(),this._connectedAnalyser.connectAudioNodes(this.masterGain,this._audioContext.destination))},t}();e.AudioEngine=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,n,r,o){var s=this;this.autoplay=!1,this.loop=!1,this.useCustomAttenuation=!1,this.spatialSound=!1,this.refDistance=1,this.rolloffFactor=1,this.maxDistance=100,this.distanceModel="linear",this._panningModel="equalpower",this._playbackRate=1,this._streaming=!1,this._startTime=0,this._startOffset=0,this._position=e.Vector3.Zero(),this._localDirection=new e.Vector3(1,0,0),this._volume=1,this._isLoaded=!1,this._isReadyToPlay=!1,this.isPlaying=!1,this.isPaused=!1,this._isDirectional=!1,this._coneInnerAngle=360,this._coneOuterAngle=360,this._coneOuterGain=0,this._isOutputConnected=!1,this.name=t,this._scene=n,this._readyToPlayCallback=r,this._customAttenuationFunction=function(e,t,i,n,r){return i>t?e*(1-t/i):0},o&&(this.autoplay=o.autoplay||!1,this.loop=o.loop||!1,void 0!==o.volume&&(this._volume=o.volume),this.spatialSound=o.spatialSound||!1,this.maxDistance=o.maxDistance||100,this.useCustomAttenuation=o.useCustomAttenuation||!1,this.rolloffFactor=o.rolloffFactor||1,this.refDistance=o.refDistance||1,this.distanceModel=o.distanceModel||"linear",this._playbackRate=o.playbackRate||1,this._streaming=o.streaming||!1),e.Engine.audioEngine.canUseWebAudio?(this._soundGain=e.Engine.audioEngine.audioContext.createGain(),this._soundGain.gain.value=this._volume,this._inputAudioNode=this._soundGain,this._ouputAudioNode=this._soundGain,this.spatialSound&&this._createSpatialParameters(),this._scene.mainSoundTrack.AddSound(this),i&&("string"==typeof i?this._streaming?(this._htmlAudioElement=new Audio(i),this._htmlAudioElement.controls=!1,this._htmlAudioElement.loop=this.loop,this._htmlAudioElement.crossOrigin="anonymous",this._htmlAudioElement.preload="auto",this._htmlAudioElement.addEventListener("canplaythrough",function(){s._isReadyToPlay=!0,s.autoplay&&s.play(),s._readyToPlayCallback&&s._readyToPlayCallback()}),document.body.appendChild(this._htmlAudioElement)):e.Tools.LoadFile(i,function(e){s._soundLoaded(e)},null,this._scene.database,!0):i instanceof ArrayBuffer?i.byteLength>0&&this._soundLoaded(i):e.Tools.Error("Parameter must be a URL to the sound or an ArrayBuffer of the sound."))):(this._scene.mainSoundTrack.AddSound(this),e.Engine.audioEngine.WarnedWebAudioUnsupported||(e.Tools.Error("Web Audio is not supported by your browser."),e.Engine.audioEngine.WarnedWebAudioUnsupported=!0),this._readyToPlayCallback&&window.setTimeout(function(){s._readyToPlayCallback()},1e3))}return t.prototype.dispose=function(){e.Engine.audioEngine.canUseWebAudio&&this._isReadyToPlay&&(this.isPlaying&&this.stop(),this._isReadyToPlay=!1,-1===this.soundTrackId?this._scene.mainSoundTrack.RemoveSound(this):this._scene.soundTracks[this.soundTrackId].RemoveSound(this),this._soundGain&&(this._soundGain.disconnect(),this._soundGain=null),this._soundPanner&&(this._soundPanner.disconnect(),this._soundPanner=null),this._soundSource&&(this._soundSource.disconnect(),this._soundSource=null),this._audioBuffer=null,this._htmlAudioElement&&(this._htmlAudioElement.pause(),this._htmlAudioElement.src="",document.body.removeChild(this._htmlAudioElement)),this._connectedMesh&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._connectedMesh=null))},t.prototype._soundLoaded=function(t){var i=this;this._isLoaded=!0,e.Engine.audioEngine.audioContext.decodeAudioData(t,function(e){i._audioBuffer=e,i._isReadyToPlay=!0,i.autoplay&&i.play(),i._readyToPlayCallback&&i._readyToPlayCallback()},function(){e.Tools.Error("Error while decoding audio data for: "+i.name)})},t.prototype.setAudioBuffer=function(t){e.Engine.audioEngine.canUseWebAudio&&(this._audioBuffer=t,this._isReadyToPlay=!0)},t.prototype.updateOptions=function(e){e&&(this.loop=e.loop||this.loop,this.maxDistance=e.maxDistance||this.maxDistance,this.useCustomAttenuation=e.useCustomAttenuation||this.useCustomAttenuation,this.rolloffFactor=e.rolloffFactor||this.rolloffFactor,this.refDistance=e.refDistance||this.refDistance,this.distanceModel=e.distanceModel||this.distanceModel,this._playbackRate=e.playbackRate||this._playbackRate,this._updateSpatialParameters(),this.isPlaying&&(this._streaming?this._htmlAudioElement.playbackRate=this._playbackRate:this._soundSource.playbackRate.value=this._playbackRate))},t.prototype._createSpatialParameters=function(){e.Engine.audioEngine.canUseWebAudio&&(this._scene.headphone&&(this._panningModel="HRTF"),this._soundPanner=e.Engine.audioEngine.audioContext.createPanner(),this._updateSpatialParameters(),this._soundPanner.connect(this._ouputAudioNode),this._inputAudioNode=this._soundPanner)},t.prototype._updateSpatialParameters=function(){this.spatialSound&&(this.useCustomAttenuation?(this._soundPanner.distanceModel="linear",this._soundPanner.maxDistance=Number.MAX_VALUE,this._soundPanner.refDistance=1,this._soundPanner.rolloffFactor=1,this._soundPanner.panningModel=this._panningModel):(this._soundPanner.distanceModel=this.distanceModel,this._soundPanner.maxDistance=this.maxDistance,this._soundPanner.refDistance=this.refDistance,this._soundPanner.rolloffFactor=this.rolloffFactor,this._soundPanner.panningModel=this._panningModel))},t.prototype.switchPanningModelToHRTF=function(){this._panningModel="HRTF",this._switchPanningModel()},t.prototype.switchPanningModelToEqualPower=function(){this._panningModel="equalpower",this._switchPanningModel()},t.prototype._switchPanningModel=function(){e.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&(this._soundPanner.panningModel=this._panningModel)},t.prototype.connectToSoundTrackAudioNode=function(t){e.Engine.audioEngine.canUseWebAudio&&(this._isOutputConnected&&this._ouputAudioNode.disconnect(),this._ouputAudioNode.connect(t),this._isOutputConnected=!0)},t.prototype.setDirectionalCone=function(t,i,n){return t>i?void e.Tools.Error("setDirectionalCone(): outer angle of the cone must be superior or equal to the inner angle."):(this._coneInnerAngle=t,this._coneOuterAngle=i,this._coneOuterGain=n,this._isDirectional=!0,void(this.isPlaying&&this.loop&&(this.stop(),this.play())))},t.prototype.setPosition=function(t){this._position=t,e.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z)},t.prototype.setLocalDirectionToMesh=function(t){this._localDirection=t,e.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.isPlaying&&this._updateDirection()},t.prototype._updateDirection=function(){var t=this._connectedMesh.getWorldMatrix(),i=e.Vector3.TransformNormal(this._localDirection,t);i.normalize(),this._soundPanner.setOrientation(i.x,i.y,i.z)},t.prototype.updateDistanceFromListener=function(){if(e.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.useCustomAttenuation){var t=this._connectedMesh.getDistanceToCamera(this._scene.activeCamera);this._soundGain.gain.value=this._customAttenuationFunction(this._volume,t,this.maxDistance,this.refDistance,this.rolloffFactor)}},t.prototype.setAttenuationFunction=function(e){this._customAttenuationFunction=e},t.prototype.play=function(t){var i=this;if(this._isReadyToPlay&&this._scene.audioEnabled)try{this._startOffset<0&&(t=-this._startOffset,this._startOffset=0);var n=t?e.Engine.audioEngine.audioContext.currentTime+t:e.Engine.audioEngine.audioContext.currentTime;this._soundSource&&this._streamingSource||this.spatialSound&&(this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z),this._isDirectional&&(this._soundPanner.coneInnerAngle=this._coneInnerAngle,this._soundPanner.coneOuterAngle=this._coneOuterAngle,this._soundPanner.coneOuterGain=this._coneOuterGain,this._connectedMesh?this._updateDirection():this._soundPanner.setOrientation(this._localDirection.x,this._localDirection.y,this._localDirection.z))),this._streaming?(this._streamingSource||(this._streamingSource=e.Engine.audioEngine.audioContext.createMediaElementSource(this._htmlAudioElement),this._htmlAudioElement.onended=function(){i._onended()},this._htmlAudioElement.playbackRate=this._playbackRate),this._streamingSource.disconnect(),this._streamingSource.connect(this._inputAudioNode),this._htmlAudioElement.play()):(this._soundSource=e.Engine.audioEngine.audioContext.createBufferSource(),this._soundSource.buffer=this._audioBuffer,this._soundSource.connect(this._inputAudioNode),this._soundSource.loop=this.loop,this._soundSource.playbackRate.value=this._playbackRate,this._soundSource.onended=function(){i._onended()},this._soundSource.start(n,this.isPaused?this._startOffset%this._soundSource.buffer.duration:0)),this._startTime=n,this.isPlaying=!0,this.isPaused=!1}catch(r){e.Tools.Error("Error while trying to play audio: "+this.name+", "+r.message)}},t.prototype._onended=function(){this.isPlaying=!1,this.onended&&this.onended()},t.prototype.stop=function(t){if(this.isPlaying){if(this._streaming)this._htmlAudioElement.pause(),this._htmlAudioElement.currentTime>0&&(this._htmlAudioElement.currentTime=0);else{var i=t?e.Engine.audioEngine.audioContext.currentTime+t:e.Engine.audioEngine.audioContext.currentTime;this._soundSource.stop(i),this.isPaused||(this._startOffset=0)}this.isPlaying=!1}},t.prototype.pause=function(){this.isPlaying&&(this.isPaused=!0,this._streaming?this._htmlAudioElement.pause():(this.stop(0),this._startOffset+=e.Engine.audioEngine.audioContext.currentTime-this._startTime))},t.prototype.setVolume=function(t,i){e.Engine.audioEngine.canUseWebAudio&&(i?(this._soundGain.gain.cancelScheduledValues(e.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.setValueAtTime(this._soundGain.gain.value,e.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.linearRampToValueAtTime(t,e.Engine.audioEngine.audioContext.currentTime+i)):this._soundGain.gain.value=t),this._volume=t},t.prototype.setPlaybackRate=function(e){this._playbackRate=e,this.isPlaying&&(this._streaming?this._htmlAudioElement.playbackRate=this._playbackRate:this._soundSource.playbackRate.value=this._playbackRate)},t.prototype.getVolume=function(){return this._volume},t.prototype.attachToMesh=function(e){var t=this;this._connectedMesh&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._registerFunc=null),this._connectedMesh=e,this.spatialSound||(this.spatialSound=!0,this._createSpatialParameters(),this.isPlaying&&this.loop&&(this.stop(),this.play())),this._onRegisterAfterWorldMatrixUpdate(this._connectedMesh),this._registerFunc=function(e){return t._onRegisterAfterWorldMatrixUpdate(e)},e.registerAfterWorldMatrixUpdate(this._registerFunc)},t.prototype._onRegisterAfterWorldMatrixUpdate=function(t){this.setPosition(t.getBoundingInfo().boundingSphere.centerWorld),e.Engine.audioEngine.canUseWebAudio&&this._isDirectional&&this.isPlaying&&this._updateDirection()},t.prototype.clone=function(){var e=this;if(this._streaming)return null;var i=function(){e._isReadyToPlay?(r._audioBuffer=e.getAudioBuffer(),r._isReadyToPlay=!0,r.autoplay&&r.play()):window.setTimeout(i,300)},n={autoplay:this.autoplay,loop:this.loop,volume:this._volume,spatialSound:this.spatialSound,maxDistance:this.maxDistance,useCustomAttenuation:this.useCustomAttenuation,rolloffFactor:this.rolloffFactor,refDistance:this.refDistance,distanceModel:this.distanceModel},r=new t(this.name+"_cloned",new ArrayBuffer(0),this._scene,null,n);return this.useCustomAttenuation&&r.setAttenuationFunction(this._customAttenuationFunction),r.setPosition(this._position),r.setPlaybackRate(this._playbackRate),i(),r},t.prototype.getAudioBuffer=function(){return this._audioBuffer},t.Parse=function(i,n,r,o){var s,a=i.name;s=i.url?r+i.url:r+a;var h,c={autoplay:i.autoplay,loop:i.loop,volume:i.volume,spatialSound:i.spatialSound,maxDistance:i.maxDistance,rolloffFactor:i.rolloffFactor,refDistance:i.refDistance,distanceModel:i.distanceModel,playbackRate:i.playbackRate};if(o){var l=function(){o._isReadyToPlay?(h._audioBuffer=o.getAudioBuffer(),h._isReadyToPlay=!0,h.autoplay&&h.play()):window.setTimeout(l,300)};h=new t(a,new ArrayBuffer(0),n,null,c),l()}else h=new t(a,s,n,function(){n._removePendingData(h)},c),n._addPendingData(h);if(i.position){var u=e.Vector3.FromArray(i.position);h.setPosition(u)}if(i.isDirectional&&(h.setDirectionalCone(i.coneInnerAngle||360,i.coneOuterAngle||360,i.coneOuterGain||0),i.localDirectionToMesh)){var d=e.Vector3.FromArray(i.localDirectionToMesh);h.setLocalDirectionToMesh(d)}if(i.connectedMeshId){var f=n.getMeshByID(i.connectedMeshId);f&&h.attachToMesh(f)}return h},t}();e.Sound=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t){this.id=-1,this._isMainTrack=!1,this._isInitialized=!1,this._scene=e,this.soundCollection=new Array,this._options=t,this._isMainTrack||(this._scene.soundTracks.push(this),this.id=this._scene.soundTracks.length-1)}return t.prototype._initializeSoundTrackAudioGraph=function(){e.Engine.audioEngine.canUseWebAudio&&(this._outputAudioNode=e.Engine.audioEngine.audioContext.createGain(),this._outputAudioNode.connect(e.Engine.audioEngine.masterGain),this._options&&(this._options.volume&&(this._outputAudioNode.gain.value=this._options.volume),this._options.mainTrack&&(this._isMainTrack=this._options.mainTrack)),this._isInitialized=!0)},t.prototype.dispose=function(){if(e.Engine.audioEngine.canUseWebAudio){for(this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas();this.soundCollection.length;)this.soundCollection[0].dispose();this._outputAudioNode&&this._outputAudioNode.disconnect(),this._outputAudioNode=null}},t.prototype.AddSound=function(t){this._isInitialized||this._initializeSoundTrackAudioGraph(),e.Engine.audioEngine.canUseWebAudio&&t.connectToSoundTrackAudioNode(this._outputAudioNode),t.soundTrackId&&(-1===t.soundTrackId?this._scene.mainSoundTrack.RemoveSound(t):this._scene.soundTracks[t.soundTrackId].RemoveSound(t)),this.soundCollection.push(t),t.soundTrackId=this.id},t.prototype.RemoveSound=function(e){var t=this.soundCollection.indexOf(e);-1!==t&&this.soundCollection.splice(t,1)},t.prototype.setVolume=function(t){e.Engine.audioEngine.canUseWebAudio&&(this._outputAudioNode.gain.value=t)},t.prototype.switchPanningModelToHRTF=function(){if(e.Engine.audioEngine.canUseWebAudio)for(var t=0;t<this.soundCollection.length;t++)this.soundCollection[t].switchPanningModelToHRTF()},t.prototype.switchPanningModelToEqualPower=function(){if(e.Engine.audioEngine.canUseWebAudio)for(var t=0;t<this.soundCollection.length;t++)this.soundCollection[t].switchPanningModelToEqualPower()},t.prototype.connectToAnalyser=function(t){this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas(),this._connectedAnalyser=t,e.Engine.audioEngine.canUseWebAudio&&(this._outputAudioNode.disconnect(),this._connectedAnalyser.connectAudioNodes(this._outputAudioNode,e.Engine.audioEngine.masterGain))},t}();e.SoundTrack=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){}return e.TransformCoordinatesToRefSIMD=function(e,t,i){var n=SIMD.float32x4.loadXYZ(e._data,0),r=SIMD.float32x4.load(t.m,0),o=SIMD.float32x4.load(t.m,4),s=SIMD.float32x4.load(t.m,8),a=SIMD.float32x4.load(t.m,12),h=SIMD.float32x4.add(SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(n,0,0,0,0),r),SIMD.float32x4.mul(SIMD.float32x4.swizzle(n,1,1,1,1),o)),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(n,2,2,2,2),s),a));h=SIMD.float32x4.div(h,SIMD.float32x4.swizzle(h,3,3,3,3)),SIMD.float32x4.storeXYZ(i._data,0,h)},e.TransformCoordinatesFromFloatsToRefSIMD=function(e,t,i,n,r){var o=SIMD.float32x4.splat(e),s=SIMD.float32x4.splat(t),a=SIMD.float32x4.splat(i),h=SIMD.float32x4.load(n.m,0),c=SIMD.float32x4.load(n.m,4),l=SIMD.float32x4.load(n.m,8),u=SIMD.float32x4.load(n.m,12),d=SIMD.float32x4.add(SIMD.float32x4.add(SIMD.float32x4.mul(o,h),SIMD.float32x4.mul(s,c)),SIMD.float32x4.add(SIMD.float32x4.mul(a,l),u));d=SIMD.float32x4.div(d,SIMD.float32x4.swizzle(d,3,3,3,3)),SIMD.float32x4.storeXYZ(r._data,0,d)},e}();e.SIMDVector3=t;var i=function(){function e(){}return e.prototype.multiplyToArraySIMD=function(e,t,i){void 0===i&&(i=0);var n=this.m,r=e.m,o=SIMD.float32x4.load(r,0),s=SIMD.float32x4.load(r,4),a=SIMD.float32x4.load(r,8),h=SIMD.float32x4.load(r,12),c=SIMD.float32x4.load(n,0);SIMD.float32x4.store(t,i+0,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(c,0,0,0,0),o),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(c,1,1,1,1),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(c,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(c,3,3,3,3),h)))));var l=SIMD.float32x4.load(n,4);SIMD.float32x4.store(t,i+4,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,0,0,0,0),o),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,1,1,1,1),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,3,3,3,3),h)))));var u=SIMD.float32x4.load(n,8);SIMD.float32x4.store(t,i+8,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,0,0,0,0),o),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,1,1,1,1),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,3,3,3,3),h)))));
  22. var d=SIMD.float32x4.load(n,12);SIMD.float32x4.store(t,i+12,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,0,0,0,0),o),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,1,1,1,1),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,3,3,3,3),h)))))},e.prototype.invertToRefSIMD=function(e){var t,i,n,r,o,s,a,h,c,l,u=this.m,d=e.m,f=SIMD.float32x4.load(u,0),p=SIMD.float32x4.load(u,4),m=SIMD.float32x4.load(u,8),_=SIMD.float32x4.load(u,12);return o=SIMD.float32x4.shuffle(f,p,0,1,4,5),i=SIMD.float32x4.shuffle(m,_,0,1,4,5),t=SIMD.float32x4.shuffle(o,i,0,2,4,6),i=SIMD.float32x4.shuffle(i,o,1,3,5,7),o=SIMD.float32x4.shuffle(f,p,2,3,6,7),r=SIMD.float32x4.shuffle(m,_,2,3,6,7),n=SIMD.float32x4.shuffle(o,r,0,2,4,6),r=SIMD.float32x4.shuffle(r,o,1,3,5,7),o=SIMD.float32x4.mul(n,r),o=SIMD.float32x4.swizzle(o,1,0,3,2),s=SIMD.float32x4.mul(i,o),a=SIMD.float32x4.mul(t,o),o=SIMD.float32x4.swizzle(o,2,3,0,1),s=SIMD.float32x4.sub(SIMD.float32x4.mul(i,o),s),a=SIMD.float32x4.sub(SIMD.float32x4.mul(t,o),a),a=SIMD.float32x4.swizzle(a,2,3,0,1),o=SIMD.float32x4.mul(i,n),o=SIMD.float32x4.swizzle(o,1,0,3,2),s=SIMD.float32x4.add(SIMD.float32x4.mul(r,o),s),c=SIMD.float32x4.mul(t,o),o=SIMD.float32x4.swizzle(o,2,3,0,1),s=SIMD.float32x4.sub(s,SIMD.float32x4.mul(r,o)),c=SIMD.float32x4.sub(SIMD.float32x4.mul(t,o),c),c=SIMD.float32x4.swizzle(c,2,3,0,1),o=SIMD.float32x4.mul(SIMD.float32x4.swizzle(i,2,3,0,1),r),o=SIMD.float32x4.swizzle(o,1,0,3,2),n=SIMD.float32x4.swizzle(n,2,3,0,1),s=SIMD.float32x4.add(SIMD.float32x4.mul(n,o),s),h=SIMD.float32x4.mul(t,o),o=SIMD.float32x4.swizzle(o,2,3,0,1),s=SIMD.float32x4.sub(s,SIMD.float32x4.mul(n,o)),h=SIMD.float32x4.sub(SIMD.float32x4.mul(t,o),h),h=SIMD.float32x4.swizzle(h,2,3,0,1),o=SIMD.float32x4.mul(t,i),o=SIMD.float32x4.swizzle(o,1,0,3,2),h=SIMD.float32x4.add(SIMD.float32x4.mul(r,o),h),c=SIMD.float32x4.sub(SIMD.float32x4.mul(n,o),c),o=SIMD.float32x4.swizzle(o,2,3,0,1),h=SIMD.float32x4.sub(SIMD.float32x4.mul(r,o),h),c=SIMD.float32x4.sub(c,SIMD.float32x4.mul(n,o)),o=SIMD.float32x4.mul(t,r),o=SIMD.float32x4.swizzle(o,1,0,3,2),a=SIMD.float32x4.sub(a,SIMD.float32x4.mul(n,o)),h=SIMD.float32x4.add(SIMD.float32x4.mul(i,o),h),o=SIMD.float32x4.swizzle(o,2,3,0,1),a=SIMD.float32x4.add(SIMD.float32x4.mul(n,o),a),h=SIMD.float32x4.sub(h,SIMD.float32x4.mul(i,o)),o=SIMD.float32x4.mul(t,n),o=SIMD.float32x4.swizzle(o,1,0,3,2),a=SIMD.float32x4.add(SIMD.float32x4.mul(r,o),a),c=SIMD.float32x4.sub(c,SIMD.float32x4.mul(i,o)),o=SIMD.float32x4.swizzle(o,2,3,0,1),a=SIMD.float32x4.sub(a,SIMD.float32x4.mul(r,o)),c=SIMD.float32x4.add(SIMD.float32x4.mul(i,o),c),l=SIMD.float32x4.mul(t,s),l=SIMD.float32x4.add(SIMD.float32x4.swizzle(l,2,3,0,1),l),l=SIMD.float32x4.add(SIMD.float32x4.swizzle(l,1,0,3,2),l),o=SIMD.float32x4.reciprocalApproximation(l),l=SIMD.float32x4.sub(SIMD.float32x4.add(o,o),SIMD.float32x4.mul(l,SIMD.float32x4.mul(o,o))),l=SIMD.float32x4.swizzle(l,0,0,0,0),s=SIMD.float32x4.mul(l,s),a=SIMD.float32x4.mul(l,a),h=SIMD.float32x4.mul(l,h),c=SIMD.float32x4.mul(l,c),SIMD.float32x4.store(d,0,s),SIMD.float32x4.store(d,4,a),SIMD.float32x4.store(d,8,h),SIMD.float32x4.store(d,12,c),this},e.LookAtLHToRefSIMD=function(e,t,i,n){var r=n.m,o=SIMD.float32x4(t.x,t.y,t.z,0),s=SIMD.float32x4(e.x,e.y,e.z,0),a=SIMD.float32x4(i.x,i.y,i.z,0),h=SIMD.float32x4.sub(o,s),c=SIMD.float32x4.mul(h,h);c=SIMD.float32x4.add(c,SIMD.float32x4.add(SIMD.float32x4.swizzle(c,1,2,0,3),SIMD.float32x4.swizzle(c,2,0,1,3))),h=SIMD.float32x4.mul(h,SIMD.float32x4.reciprocalSqrtApproximation(c)),c=SIMD.float32x4.mul(a,a),c=SIMD.float32x4.add(c,SIMD.float32x4.add(SIMD.float32x4.swizzle(c,1,2,0,3),SIMD.float32x4.swizzle(c,2,0,1,3))),a=SIMD.float32x4.mul(a,SIMD.float32x4.reciprocalSqrtApproximation(c));var l=SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(h,1,2,0,3),SIMD.float32x4.swizzle(a,2,0,1,3)),SIMD.float32x4.mul(SIMD.float32x4.swizzle(h,2,0,1,3),SIMD.float32x4.swizzle(a,1,2,0,3)));c=SIMD.float32x4.mul(l,l),c=SIMD.float32x4.add(c,SIMD.float32x4.add(SIMD.float32x4.swizzle(c,1,2,0,3),SIMD.float32x4.swizzle(c,2,0,1,3))),l=SIMD.float32x4.mul(l,SIMD.float32x4.reciprocalSqrtApproximation(c));var u=SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,1,2,0,3),SIMD.float32x4.swizzle(h,2,0,1,3)),SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,2,0,1,3),SIMD.float32x4.swizzle(h,1,2,0,3)));c=SIMD.float32x4.mul(l,l),c=SIMD.float32x4.add(c,SIMD.float32x4.add(SIMD.float32x4.swizzle(c,1,2,0,3),SIMD.float32x4.swizzle(c,2,0,1,3))),l=SIMD.float32x4.mul(l,SIMD.float32x4.reciprocalSqrtApproximation(c));var d=SIMD.float32x4.splat(0);l=SIMD.float32x4.neg(l);var f=SIMD.float32x4.shuffle(l,u,0,1,4,5),p=SIMD.float32x4.shuffle(h,d,0,1,4,5),m=SIMD.float32x4.shuffle(f,p,0,2,4,6),_=SIMD.float32x4.shuffle(f,p,1,3,5,7);f=SIMD.float32x4.shuffle(l,u,2,3,6,7),p=SIMD.float32x4.shuffle(h,d,2,3,6,7);var g=SIMD.float32x4.shuffle(f,p,0,2,4,6),v=SIMD.float32x4(0,0,0,1),y=SIMD.float32x4(1,0,0,0),x=SIMD.float32x4(0,1,0,0),b=SIMD.float32x4(0,0,1,0),E=SIMD.float32x4.neg(s);E=SIMD.float32x4.withW(E,1),SIMD.float32x4.store(r,0,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(y,0,0,0,0),m),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(y,1,1,1,1),_),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(y,2,2,2,2),g),SIMD.float32x4.mul(SIMD.float32x4.swizzle(y,3,3,3,3),v))))),SIMD.float32x4.store(r,4,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(x,0,0,0,0),m),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(x,1,1,1,1),_),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(x,2,2,2,2),g),SIMD.float32x4.mul(SIMD.float32x4.swizzle(x,3,3,3,3),v))))),SIMD.float32x4.store(r,8,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(b,0,0,0,0),m),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(b,1,1,1,1),_),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(b,2,2,2,2),g),SIMD.float32x4.mul(SIMD.float32x4.swizzle(b,3,3,3,3),v))))),SIMD.float32x4.store(r,12,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(E,0,0,0,0),m),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(E,1,1,1,1),_),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(E,2,2,2,2),g),SIMD.float32x4.mul(SIMD.float32x4.swizzle(E,3,3,3,3),v)))))},e}();e.SIMDMatrix=i;var n=e.Matrix.prototype.multiplyToArray,r=e.Matrix.prototype.invertToRef,o=e.Matrix.LookAtLHToRef,s=e.Vector3.TransformCoordinatesToRef,a=e.Vector3.TransformCoordinatesFromFloatsToRef,h=function(){function h(){}return Object.defineProperty(h,"IsEnabled",{get:function(){return h._isEnabled},enumerable:!0,configurable:!0}),h.DisableSIMD=function(){e.Matrix.prototype.multiplyToArray=n,e.Matrix.prototype.invertToRef=r,e.Matrix.LookAtLHToRef=o,e.Vector3.TransformCoordinatesToRef=s,e.Vector3.TransformCoordinatesFromFloatsToRef=a,h._isEnabled=!1},h.EnableSIMD=function(){void 0!==window.SIMD&&(e.Matrix.prototype.multiplyToArray=i.prototype.multiplyToArraySIMD,e.Matrix.prototype.invertToRef=i.prototype.invertToRefSIMD,e.Matrix.LookAtLHToRef=i.LookAtLHToRefSIMD,e.Vector3.TransformCoordinatesToRef=t.TransformCoordinatesToRefSIMD,e.Vector3.TransformCoordinatesFromFloatsToRef=t.TransformCoordinatesFromFloatsToRefSIMD,Object.defineProperty(e.Vector3.prototype,"x",{get:function(){return this._data[0]},set:function(e){this._data||(this._data=new Float32Array(3)),this._data[0]=e}}),Object.defineProperty(e.Vector3.prototype,"y",{get:function(){return this._data[1]},set:function(e){this._data[1]=e}}),Object.defineProperty(e.Vector3.prototype,"z",{get:function(){return this._data[2]},set:function(e){this._data[2]=e}}),h._isEnabled=!0)},h._isEnabled=!1,h}();e.SIMDHelper=h}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o){t.call(this,i,n),this._textures={},this._floats={},this._floatsArrays={},this._colors3={},this._colors4={},this._vectors2={},this._vectors3={},this._vectors4={},this._matrices={},this._matrices3x3={},this._matrices2x2={},this._cachedWorldViewMatrix=new e.Matrix,this._shaderPath=r,o.needAlphaBlending=o.needAlphaBlending||!1,o.needAlphaTesting=o.needAlphaTesting||!1,o.attributes=o.attributes||["position","normal","uv"],o.uniforms=o.uniforms||["worldViewProjection"],o.samplers=o.samplers||[],o.defines=o.defines||[],this._options=o}return __extends(i,t),i.prototype.needAlphaBlending=function(){return this._options.needAlphaBlending},i.prototype.needAlphaTesting=function(){return this._options.needAlphaTesting},i.prototype._checkUniform=function(e){-1===this._options.uniforms.indexOf(e)&&this._options.uniforms.push(e)},i.prototype.setTexture=function(e,t){return-1===this._options.samplers.indexOf(e)&&this._options.samplers.push(e),this._textures[e]=t,this},i.prototype.setFloat=function(e,t){return this._checkUniform(e),this._floats[e]=t,this},i.prototype.setFloats=function(e,t){return this._checkUniform(e),this._floatsArrays[e]=t,this},i.prototype.setColor3=function(e,t){return this._checkUniform(e),this._colors3[e]=t,this},i.prototype.setColor4=function(e,t){return this._checkUniform(e),this._colors4[e]=t,this},i.prototype.setVector2=function(e,t){return this._checkUniform(e),this._vectors2[e]=t,this},i.prototype.setVector3=function(e,t){return this._checkUniform(e),this._vectors3[e]=t,this},i.prototype.setVector4=function(e,t){return this._checkUniform(e),this._vectors4[e]=t,this},i.prototype.setMatrix=function(e,t){return this._checkUniform(e),this._matrices[e]=t,this},i.prototype.setMatrix3x3=function(e,t){return this._checkUniform(e),this._matrices3x3[e]=t,this},i.prototype.setMatrix2x2=function(e,t){return this._checkUniform(e),this._matrices2x2[e]=t,this},i.prototype.isReady=function(t,i){var n=this.getScene(),r=n.getEngine();if(!this.checkReadyOnEveryCall&&this._renderId===n.getRenderId())return!0;var o=[],s=new e.EffectFallbacks;i&&o.push("#define INSTANCES");for(var a=0;a<this._options.defines.length;a++)o.push(this._options.defines[a]);t&&t.useBones&&t.computeBonesUsingShaders&&(o.push("#define NUM_BONE_INFLUENCERS "+t.numBoneInfluencers),o.push("#define BonesPerMesh "+(t.skeleton.bones.length+1)),s.addCPUSkinningFallback(0,t)),r.getAlphaTesting()&&o.push("#define ALPHATEST");var h=this._effect,c=o.join("\n");return this._effect=r.createEffect(this._shaderPath,this._options.attributes,this._options.uniforms,this._options.samplers,c,s,this.onCompiled,this.onError),this._effect.isReady()?(h!==this._effect&&n.resetCachedMaterial(),this._renderId=n.getRenderId(),!0):!1},i.prototype.bindOnlyWorldMatrix=function(e){var t=this.getScene();-1!==this._options.uniforms.indexOf("world")&&this._effect.setMatrix("world",e),-1!==this._options.uniforms.indexOf("worldView")&&(e.multiplyToRef(t.getViewMatrix(),this._cachedWorldViewMatrix),this._effect.setMatrix("worldView",this._cachedWorldViewMatrix)),-1!==this._options.uniforms.indexOf("worldViewProjection")&&this._effect.setMatrix("worldViewProjection",e.multiply(t.getTransformMatrix()))},i.prototype.bind=function(e,i){if(this.bindOnlyWorldMatrix(e),this.getScene().getCachedMaterial()!==this){-1!==this._options.uniforms.indexOf("view")&&this._effect.setMatrix("view",this.getScene().getViewMatrix()),-1!==this._options.uniforms.indexOf("projection")&&this._effect.setMatrix("projection",this.getScene().getProjectionMatrix()),-1!==this._options.uniforms.indexOf("viewProjection")&&this._effect.setMatrix("viewProjection",this.getScene().getTransformMatrix()),i&&i.useBones&&i.computeBonesUsingShaders&&this._effect.setMatrices("mBones",i.skeleton.getTransformMatrices(i));for(var n in this._textures)this._effect.setTexture(n,this._textures[n]);for(n in this._floats)this._effect.setFloat(n,this._floats[n]);for(n in this._floatsArrays)this._effect.setArray(n,this._floatsArrays[n]);for(n in this._colors3)this._effect.setColor3(n,this._colors3[n]);for(n in this._colors4){var r=this._colors4[n];this._effect.setFloat4(n,r.r,r.g,r.b,r.a)}for(n in this._vectors2)this._effect.setVector2(n,this._vectors2[n]);for(n in this._vectors3)this._effect.setVector3(n,this._vectors3[n]);for(n in this._vectors4)this._effect.setVector4(n,this._vectors4[n]);for(n in this._matrices)this._effect.setMatrix(n,this._matrices[n]);for(n in this._matrices3x3)this._effect.setMatrix3x3(n,this._matrices3x3[n]);for(n in this._matrices2x2)this._effect.setMatrix2x2(n,this._matrices2x2[n])}t.prototype.bind.call(this,e,i)},i.prototype.clone=function(e){var t=new i(e,this.getScene(),this._shaderPath,this._options);return t},i.prototype.dispose=function(e){for(var i in this._textures)this._textures[i].dispose();this._textures={},t.prototype.dispose.call(this,e)},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);t.customType="BABYLON.ShaderMaterial",t.options=this._options,t.shaderPath=this._shaderPath,t.textures={};for(var i in this._textures)t.textures[i]=this._textures[i].serialize();t.floats={};for(i in this._floats)t.floats[i]=this._floats[i];t.floatArrays={};for(i in this._floatsArrays)t.floatArrays[i]=this._floatsArrays[i];t.colors3={};for(i in this._colors3)t.colors3[i]=this._colors3[i].asArray();t.colors4={};for(i in this._colors4)t.colors4[i]=this._colors4[i].asArray();t.vectors2={};for(i in this._vectors2)t.vectors2[i]=this._vectors2[i].asArray();t.vectors3={};for(i in this._vectors3)t.vectors3[i]=this._vectors3[i].asArray();t.vectors4={};for(i in this._vectors4)t.vectors4[i]=this._vectors4[i].asArray();t.matrices={};for(i in this._matrices)t.matrices[i]=this._matrices[i].asArray();t.matrices3x3={};for(i in this._matrices3x3)t.matrices3x3[i]=this._matrices3x3[i];t.matrices2x2={};for(i in this._matrices2x2)t.matrices2x2[i]=this._matrices2x2[i];return t},i.Parse=function(t,n,r){var o=e.SerializationHelper.Parse(function(){return new i(t.name,n,t.shaderPath,t.options)},t,n,r);for(var s in t.textures)o.setTexture(s,e.Texture.Parse(t.textures[s],n,r));for(s in t.floats)o.setFloat(s,t.floats[s]);for(s in t.floatsArrays)o.setFloats(s,t.floatsArrays[s]);for(s in t.colors3)o.setColor3(s,e.Color3.FromArray(t.colors3[s]));for(s in t.colors4)o.setColor4(s,e.Color4.FromArray(t.colors4[s]));for(s in t.vectors2)o.setVector2(s,e.Vector2.FromArray(t.vectors2[s]));for(s in t.vectors3)o.setVector3(s,e.Vector3.FromArray(t.vectors3[s]));for(s in t.vectors4)o.setVector4(s,e.Vector4.FromArray(t.vectors4[s]));for(s in t.matrices)o.setMatrix(s,e.Matrix.FromArray(t.matrices[s]));for(s in t.matrices3x3)o.setMatrix3x3(s,t.matrices3x3[s]);for(s in t.matrices2x2)o.setMatrix2x2(s,t.matrices2x2[s]);return o},i}(e.Material);e.ShaderMaterial=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){function i(e){return e.charCodeAt(0)+(e.charCodeAt(1)<<8)+(e.charCodeAt(2)<<16)+(e.charCodeAt(3)<<24)}function n(e){return String.fromCharCode(255&e,e>>8&255,e>>16&255,e>>24&255)}var r=542327876,o=131072,s=512,a=4,h=64,c=131072,l=i("DXT1"),u=i("DXT3"),d=i("DXT5"),f=31,p=0,m=1,_=2,g=3,v=4,y=7,x=20,b=21,E=22,A=28,T=function(){function t(){}return t.GetDDSInfo=function(e){var t=new Int32Array(e,0,f),i=1;return t[_]&o&&(i=Math.max(1,t[y])),{width:t[v],height:t[g],mipmapCount:i,isFourCC:(t[x]&a)===a,isRGB:(t[x]&h)===h,isLuminance:(t[x]&c)===c,isCube:(t[A]&s)===s}},t.GetRGBAArrayBuffer=function(e,t,i,n,r){for(var o=new Uint8Array(n),s=new Uint8Array(r),a=0,h=t-1;h>=0;h--)for(var c=0;e>c;c++){var l=i+4*(c+h*e);o[a+2]=s[l],o[a+1]=s[l+1],o[a]=s[l+2],o[a+3]=s[l+3],a+=4}return o},t.GetRGBArrayBuffer=function(e,t,i,n,r){for(var o=new Uint8Array(n),s=new Uint8Array(r),a=0,h=t-1;h>=0;h--)for(var c=0;e>c;c++){var l=i+3*(c+h*e);o[a+2]=s[l],o[a+1]=s[l+1],o[a]=s[l+2],a+=3}return o},t.GetLuminanceArrayBuffer=function(e,t,i,n,r){for(var o=new Uint8Array(n),s=new Uint8Array(r),a=0,h=t-1;h>=0;h--)for(var c=0;e>c;c++){var l=i+(c+h*e);o[a]=s[l],a++}return o},t.UploadDDSLevels=function(i,s,a,h,c,x){var A,T,P,M,C,S,R,I,D,O,w=new Int32Array(a,0,f);if(w[p]!=r)return void e.Tools.Error("Invalid magic number in DDS header");if(!h.isFourCC&&!h.isRGB&&!h.isLuminance)return void e.Tools.Error("Unsupported format, must contain a FourCC, RGB or LUMINANCE code");if(h.isFourCC)switch(A=w[b]){case l:T=8,P=s.COMPRESSED_RGBA_S3TC_DXT1_EXT;break;case u:T=16,P=s.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case d:T=16,P=s.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;default:return void console.error("Unsupported FourCC code:",n(A))}D=1,w[_]&o&&c!==!1&&(D=Math.max(1,w[y]));for(var L=w[E],B=0;x>B;B++){var F=1===x?i.TEXTURE_2D:i.TEXTURE_CUBE_MAP_POSITIVE_X+B;for(M=w[v],C=w[g],R=w[m]+4,O=0;D>O;++O){if(h.isRGB)24===L?(S=M*C*3,I=t.GetRGBArrayBuffer(M,C,R,S,a),i.texImage2D(F,O,i.RGB,M,C,0,i.RGB,i.UNSIGNED_BYTE,I)):(S=M*C*4,I=t.GetRGBAArrayBuffer(M,C,R,S,a),i.texImage2D(F,O,i.RGBA,M,C,0,i.RGBA,i.UNSIGNED_BYTE,I));else if(h.isLuminance){var V=i.getParameter(i.UNPACK_ALIGNMENT),N=M,z=Math.floor((M+V-1)/V)*V;S=z*(C-1)+N,I=t.GetLuminanceArrayBuffer(M,C,R,S,a),i.texImage2D(F,O,i.LUMINANCE,M,C,0,i.LUMINANCE,i.UNSIGNED_BYTE,I)}else S=Math.max(4,M)/4*Math.max(4,C)/4*T,I=new Uint8Array(a,R,S),i.compressedTexImage2D(F,O,P,M,C,0,I);R+=S,M*=.5,C*=.5,M=Math.max(1,M),C=Math.max(1,C)}}},t}();t.DDSTools=T}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){return void 0===t&&(t=!0),void 0===i&&(i=10),this._useDeltaForWorldStep=t,this.name="CannonJSPlugin",this._physicsMaterials=[],this._fixedTimeStep=1/60,this._currentCollisionGroup=2,this._minus90X=new e.Quaternion(-.7071067811865475,0,0,.7071067811865475),this._plus90X=new e.Quaternion(.7071067811865475,0,0,.7071067811865475),this._tmpPosition=e.Vector3.Zero(),this._tmpQuaternion=new e.Quaternion,this._tmpDeltaPosition=e.Vector3.Zero(),this._tmpDeltaRotation=new e.Quaternion,this._tmpUnityRotation=new e.Quaternion,this.isSupported()?(this.world=new CANNON.World,this.world.broadphase=new CANNON.NaiveBroadphase,void(this.world.solver.iterations=i)):void e.Tools.Error("CannonJS is not available. Please make sure you included the js file.")}return t.prototype.setGravity=function(e){this.world.gravity.copy(e)},t.prototype.setTimeStep=function(e){this._fixedTimeStep=e},t.prototype.executeStep=function(e,t){this.world.step(this._fixedTimeStep,this._useDeltaForWorldStep?1e3*e:0,3)},t.prototype.applyImpulse=function(e,t,i){var n=new CANNON.Vec3(i.x,i.y,i.z),r=new CANNON.Vec3(t.x,t.y,t.z);e.physicsBody.applyImpulse(r,n)},t.prototype.applyForce=function(e,t,i){var n=new CANNON.Vec3(i.x,i.y,i.z),r=new CANNON.Vec3(t.x,t.y,t.z);e.physicsBody.applyImpulse(r,n)},t.prototype.generatePhysicsBody=function(e){if(e.parent)return void(e.physicsBody&&(this.removePhysicsBody(e),e.forceUpdate()));if(e.isBodyInitRequired()){var t=this._createShape(e),i=e.physicsBody;i&&this.removePhysicsBody(e);var n=this._addMaterial("mat-"+e.uniqueId,e.getParam("friction"),e.getParam("restitution")),r={mass:e.getParam("mass"),material:n},o=e.getParam("nativeOptions");for(var s in o)o.hasOwnProperty(s)&&(r[s]=o[s]);e.physicsBody=new CANNON.Body(r),e.physicsBody.addEventListener("collide",e.onCollide),this.world.addEventListener("preStep",e.beforeStep),this.world.addEventListener("postStep",e.afterStep),e.physicsBody.addShape(t),this.world.add(e.physicsBody),i&&["force","torque","velocity","angularVelocity"].forEach(function(t){e.physicsBody[t].copy(i[t])}),this._processChildMeshes(e)}this._updatePhysicsBodyTransformation(e)},t.prototype._processChildMeshes=function(t){var i=this,n=t.object.getChildMeshes?t.object.getChildMeshes():[];if(n.length){var r=function(e,n){var o=n.getPhysicsImpostor();if(o){var s=o.parent;if(s!==t){var e=n.position;o.physicsBody&&(i.removePhysicsBody(o),o.physicsBody=null),o.parent=t,o.resetUpdateFlags(),t.physicsBody.addShape(i._createShape(o),new CANNON.Vec3(e.x,e.y,e.z)),t.physicsBody.mass+=o.getParam("mass")}}n.getChildMeshes().forEach(r.bind(i,n.position))};n.forEach(r.bind(this,e.Vector3.Zero()))}},t.prototype.removePhysicsBody=function(e){e.physicsBody.removeEventListener("collide",e.onCollide),this.world.removeEventListener("preStep",e.beforeStep),this.world.removeEventListener("postStep",e.afterStep),this.world.remove(e.physicsBody)},t.prototype.generateJoint=function(t){var i=t.mainImpostor.physicsBody,n=t.connectedImpostor.physicsBody;if(i&&n){var r,o=t.joint.jointData,s={pivotA:o.mainPivot?(new CANNON.Vec3).copy(o.mainPivot):null,pivotB:o.connectedPivot?(new CANNON.Vec3).copy(o.connectedPivot):null,axisA:o.mainAxis?(new CANNON.Vec3).copy(o.mainAxis):null,axisB:o.connectedAxis?(new CANNON.Vec3).copy(o.connectedAxis):null,maxForce:o.nativeParams.maxForce,collideConnected:!!o.collision};switch(t.joint.type){case e.PhysicsJoint.HingeJoint:case e.PhysicsJoint.Hinge2Joint:r=new CANNON.HingeConstraint(i,n,s);break;case e.PhysicsJoint.DistanceJoint:r=new CANNON.DistanceConstraint(i,n,o.maxDistance||2);break;case e.PhysicsJoint.SpringJoint:var a=o;r=new CANNON.Spring(i,n,{restLength:a.length,stiffness:a.stiffness,damping:a.damping,localAnchorA:s.pivotA,localAnchorB:s.pivotB});break;case e.PhysicsJoint.PointToPointJoint:case e.PhysicsJoint.BallAndSocketJoint:default:r=new CANNON.PointToPointConstraint(i,s.pivotA,n,s.pivotA,s.maxForce)}r.collideConnected=!!o.collision,t.joint.physicsJoint=r,t.joint.type!==e.PhysicsJoint.SpringJoint?this.world.addConstraint(r):t.mainImpostor.registerAfterPhysicsStep(function(){r.applyForce()})}},t.prototype.removeJoint=function(e){},t.prototype._addMaterial=function(e,t,i){var n,r;for(n=0;n<this._physicsMaterials.length;n++)if(r=this._physicsMaterials[n],r.friction===t&&r.restitution===i)return r;var o=new CANNON.Material("mat");return o.friction=t,o.restitution=i,this._physicsMaterials.push(o),o},t.prototype._checkWithEpsilon=function(t){return t<e.PhysicsEngine.Epsilon?e.PhysicsEngine.Epsilon:t},t.prototype._createShape=function(t){var i,n=t.object,r=t.getObjectExtendSize();switch(t.type){case e.PhysicsEngine.SphereImpostor:var o=r.x,s=r.y,a=r.z;i=new CANNON.Sphere(Math.max(this._checkWithEpsilon(o),this._checkWithEpsilon(s),this._checkWithEpsilon(a))/2);break;case e.PhysicsImpostor.CylinderImpostor:i=new CANNON.Cylinder(this._checkWithEpsilon(r.x)/2,this._checkWithEpsilon(r.x)/2,this._checkWithEpsilon(r.y),16);break;case e.PhysicsImpostor.BoxImpostor:var h=r.scale(.5);i=new CANNON.Box(new CANNON.Vec3(this._checkWithEpsilon(h.x),this._checkWithEpsilon(h.y),this._checkWithEpsilon(h.z)));break;case e.PhysicsImpostor.PlaneImpostor:e.Tools.Warn("Attention, PlaneImposter might not behave as you expect. Consider using BoxImposter instead"),i=new CANNON.Plane;break;case e.PhysicsImpostor.MeshImpostor:var c=n.getVerticesData?n.getVerticesData(e.VertexBuffer.PositionKind):[],l=n.getIndices?n.getIndices():[];e.Tools.Warn("MeshImpostor only collides against spheres."),i=new CANNON.Trimesh(c,l);break;case e.PhysicsImpostor.HeightmapImpostor:i=this._createHeightmap(n);break;case e.PhysicsImpostor.ParticleImpostor:i=new CANNON.Particle}return i},t.prototype._createHeightmap=function(t,i){for(var n=t.getVerticesData(e.VertexBuffer.PositionKind),r=[],o=i||~~(Math.sqrt(n.length/3)-1),s=Math.min(t.getBoundingInfo().boundingBox.extendSize.x,t.getBoundingInfo().boundingBox.extendSize.z),a=2*s/o,h=t.getBoundingInfo().boundingBox.extendSize.y,c=0;c<n.length;c+=3){var l=Math.round(n[c+0]/a+o/2),u=Math.round(-1*(n[c+2]/a-o/2)),d=n[c+1]+h;r[l]||(r[l]=[]),r[l][u]||(r[l][u]=d),r[l][u]=Math.max(d,r[l][u])}for(var l=0;o>=l;++l){if(!r[l]){for(var f=1;!r[(l+f)%o];)f++;r[l]=r[(l+f)%o].slice()}for(var u=0;o>=u;++u)if(!r[l][u]){for(var p,f=1;void 0===p;)p=r[l][(u+f++)%o];r[l][u]=p}}var m=new CANNON.Heightfield(r,{elementSize:a});return m.minY=h,m},t.prototype._updatePhysicsBodyTransformation=function(t){var i=t.object;i.computeWorldMatrix&&i.computeWorldMatrix(!0);var n=t.getObjectCenter();t.getObjectExtendSize();this._tmpDeltaPosition.copyFrom(i.position.subtract(n)),this._tmpPosition.copyFrom(n);var r=i.rotationQuaternion;if(t.type!==e.PhysicsImpostor.PlaneImpostor&&t.type!==e.PhysicsImpostor.HeightmapImpostor&&t.type!==e.PhysicsImpostor.CylinderImpostor||(r=r.multiply(this._minus90X),t.setDeltaRotation(this._plus90X)),t.type===e.PhysicsEngine.HeightmapImpostor){var o=i,s=o.rotationQuaternion;o.rotationQuaternion=this._tmpUnityRotation,o.computeWorldMatrix(!0);var a=n.clone(),h=o.getPivotMatrix()||e.Matrix.Translation(0,0,0);o.rotationQuaternion=s;var c=e.Matrix.Translation(o.getBoundingInfo().boundingBox.extendSize.x,0,-o.getBoundingInfo().boundingBox.extendSize.z);o.setPivotMatrix(c),o.computeWorldMatrix(!0);var l=o.getBoundingInfo().boundingBox.center.subtract(n).subtract(o.position).negate();this._tmpPosition.copyFromFloats(l.x,l.y-o.getBoundingInfo().boundingBox.extendSize.y,l.z),this._tmpDeltaPosition.copyFrom(o.getBoundingInfo().boundingBox.center.subtract(a)),this._tmpDeltaPosition.y+=o.getBoundingInfo().boundingBox.extendSize.y,o.setPivotMatrix(h),o.computeWorldMatrix(!0)}else t.type===e.PhysicsEngine.MeshImpostor&&(this._tmpDeltaPosition.copyFromFloats(0,0,0),this._tmpPosition.copyFrom(i.position));t.setDeltaPosition(this._tmpDeltaPosition),t.physicsBody.position.copy(this._tmpPosition),t.physicsBody.quaternion.copy(r)},t.prototype.setTransformationFromPhysicsBody=function(e){e.object.position.copyFrom(e.physicsBody.position),e.object.rotationQuaternion.copyFrom(e.physicsBody.quaternion)},t.prototype.setPhysicsBodyTransformation=function(e,t,i){e.physicsBody.position.copy(t),e.physicsBody.quaternion.copy(i)},t.prototype.isSupported=function(){return void 0!==window.CANNON},t.prototype.setLinearVelocity=function(e,t){e.physicsBody.velocity.copy(t)},t.prototype.setAngularVelocity=function(e,t){e.physicsBody.angularVelocity.copy(t)},t.prototype.getLinearVelocity=function(t){var i=t.physicsBody.velocity;return i?new e.Vector3(i.x,i.y,i.z):null},t.prototype.getAngularVelocity=function(t){var i=t.physicsBody.angularVelocity;return i?new e.Vector3(i.x,i.y,i.z):null},t.prototype.setBodyMass=function(e,t){e.physicsBody.mass=t,e.physicsBody.updateMassProperties()},t.prototype.sleepBody=function(e){e.physicsBody.sleep()},t.prototype.wakeUpBody=function(e){e.physicsBody.wakeUp()},t.prototype.updateDistanceJoint=function(e,t,i){e.physicsJoint.distance=t},t.prototype.enableMotor=function(e,t){t||e.physicsJoint.enableMotor()},t.prototype.disableMotor=function(e,t){t||e.physicsJoint.disableMotor()},t.prototype.setMotor=function(e,t,i,n){n||(e.physicsJoint.enableMotor(),e.physicsJoint.setMotorSpeed(t),i&&this.setLimit(e,i))},t.prototype.setLimit=function(e,t,i){e.physicsJoint.motorEquation.maxForce=t,e.physicsJoint.motorEquation.minForce=void 0===i?-t:i},t.prototype.dispose=function(){},t}();e.CannonJSPlugin=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.name="OimoJSPlugin",this._tmpImpostorsArray=[],this._tmpPositionVector=e.Vector3.Zero(),this.world=new OIMO.World(1/60,2,t,!0),this.world.clear(),this.world.isNoStat=!0}return t.prototype.setGravity=function(e){this.world.gravity.copy(e)},t.prototype.setTimeStep=function(e){this.world.timeStep=e},t.prototype.executeStep=function(e,t){var i=this;t.forEach(function(e){e.beforeStep()}),this.world.step(),t.forEach(function(e){e.afterStep(),i._tmpImpostorsArray[e.uniqueId]=e});for(var n=this.world.contacts;null!==n;)if(!n.touching||n.body1.sleeping||n.body2.sleeping){var r=this._tmpImpostorsArray[+n.body1.name],o=this._tmpImpostorsArray[+n.body2.name];r&&o?(r.onCollide({body:o.physicsBody}),o.onCollide({body:r.physicsBody}),n=n.next):n=n.next}else n=n.next},t.prototype.applyImpulse=function(e,t,i){var n=e.physicsBody.massInfo.mass;e.physicsBody.applyImpulse(i.scale(OIMO.INV_SCALE),t.scale(OIMO.INV_SCALE*n))},t.prototype.applyForce=function(t,i,n){e.Tools.Warn("Oimo doesn't support applying force. Using impule instead."),this.applyImpulse(t,i,n)},t.prototype.generatePhysicsBody=function(t){function i(e){e.getChildMeshes&&e.getChildMeshes().forEach(function(e){e.physicsImpostor&&(s.push(e.physicsImpostor),e.physicsImpostor._init())})}function n(t){return Math.max(t,e.PhysicsEngine.Epsilon)}var r=this;if(t.parent)return void(t.physicsBody&&(this.removePhysicsBody(t),t.forceUpdate()));if(t.isBodyInitRequired()){var o={name:t.uniqueId,config:[t.getParam("mass")||1,t.getParam("friction"),t.getParam("restitution")],size:[],type:[],pos:[],rot:[],move:0!==t.getParam("mass"),world:this.world},s=[t];i(t.object),s.forEach(function(i){var s=i.object.rotationQuaternion,a=(new OIMO.Euler).setFromQuaternion({x:t.object.rotationQuaternion.x,y:t.object.rotationQuaternion.y,z:t.object.rotationQuaternion.z,s:t.object.rotationQuaternion.w}),h=i.getObjectExtendSize();if(i===t){var c=t.getObjectCenter();t.object.position.subtractToRef(c,r._tmpPositionVector),o.pos.push(c.x),o.pos.push(c.y),o.pos.push(c.z),o.rot.push(a.x/(OIMO.degtorad||OIMO.TO_RAD)),o.rot.push(a.y/(OIMO.degtorad||OIMO.TO_RAD)),o.rot.push(a.z/(OIMO.degtorad||OIMO.TO_RAD))}else o.pos.push(i.object.position.x),o.pos.push(i.object.position.y),o.pos.push(i.object.position.z),o.rot.push(0),o.rot.push(0),o.rot.push(0);switch(i.type){case e.PhysicsImpostor.ParticleImpostor:e.Tools.Warn("No Particle support in Oimo.js. using SphereImpostor instead");case e.PhysicsImpostor.SphereImpostor:var l=h.x,u=h.y,d=h.z,f=Math.max(n(l),n(u),n(d))/2;o.type.push("sphere"),o.size.push(f),o.size.push(f),o.size.push(f);break;case e.PhysicsImpostor.CylinderImpostor:var p=n(h.x)/2,m=n(h.y);o.type.push("cylinder"),o.size.push(p),o.size.push(m),o.size.push(m);break;case e.PhysicsImpostor.PlaneImpostor:case e.PhysicsImpostor.BoxImpostor:default:var p=n(h.x),m=n(h.y),_=n(h.z);o.type.push("box"),o.size.push(p),o.size.push(m),o.size.push(_)}i.object.rotationQuaternion=s}),t.physicsBody=new OIMO.Body(o).body}else this._tmpPositionVector.copyFromFloats(0,0,0);t.setDeltaPosition(this._tmpPositionVector)},t.prototype.removePhysicsBody=function(e){this.world.removeRigidBody(e.physicsBody)},t.prototype.generateJoint=function(t){var i=t.mainImpostor.physicsBody,n=t.connectedImpostor.physicsBody;if(i&&n){var r,o=t.joint.jointData,s=o.nativeParams||{},a={body1:i,body2:n,axe1:s.axe1||(o.mainAxis?o.mainAxis.asArray():null),axe2:s.axe2||(o.connectedAxis?o.connectedAxis.asArray():null),pos1:s.pos1||(o.mainPivot?o.mainPivot.asArray():null),pos2:s.pos2||(o.connectedPivot?o.connectedPivot.asArray():null),min:s.min,max:s.max,collision:s.collision||o.collision,spring:s.spring,world:this.world};switch(t.joint.type){case e.PhysicsJoint.BallAndSocketJoint:r="jointBall";break;case e.PhysicsJoint.SpringJoint:e.Tools.Warn("Oimo.js doesn't support Spring Constraint. Simulating using DistanceJoint instead");var h=o;a.min=h.length||a.min,a.max=Math.max(a.min,a.max);case e.PhysicsJoint.DistanceJoint:r="jointDistance",a.max=o.maxDistance;break;case e.PhysicsJoint.PrismaticJoint:r="jointPrisme";break;case e.PhysicsJoint.SliderJoint:r="jointSlide";break;case e.PhysicsJoint.WheelJoint:r="jointWheel";break;case e.PhysicsJoint.HingeJoint:default:r="jointHinge"}a.type=r,t.joint.physicsJoint=new OIMO.Link(a).joint}},t.prototype.removeJoint=function(e){e.joint.physicsJoint.dispose()},t.prototype.isSupported=function(){return void 0!==OIMO},t.prototype.setTransformationFromPhysicsBody=function(e){if(!e.physicsBody.sleeping){if(e.physicsBody.shapes.next){var t=this._getLastShape(e.physicsBody);e.object.position.x=t.position.x*OIMO.WORLD_SCALE,e.object.position.y=t.position.y*OIMO.WORLD_SCALE,e.object.position.z=t.position.z*OIMO.WORLD_SCALE}else e.object.position.copyFrom(e.physicsBody.getPosition());e.object.rotationQuaternion.copyFrom(e.physicsBody.getQuaternion())}},t.prototype.setPhysicsBodyTransformation=function(e,t,i){var n=e.physicsBody;n.position.init(t.x*OIMO.INV_SCALE,t.y*OIMO.INV_SCALE,t.z*OIMO.INV_SCALE),n.orientation.init(i.w,i.x,i.y,i.z),n.syncShapes(),n.awake()},t.prototype._getLastShape=function(e){for(var t=e.shapes;t.next;)t=t.next;return t},t.prototype.setLinearVelocity=function(e,t){e.physicsBody.linearVelocity.init(t.x,t.y,t.z)},t.prototype.setAngularVelocity=function(e,t){e.physicsBody.angularVelocity.init(t.x,t.y,t.z);
  23. },t.prototype.getLinearVelocity=function(t){var i=t.physicsBody.linearVelocity;return i?new e.Vector3(i.x,i.y,i.z):null},t.prototype.getAngularVelocity=function(t){var i=t.physicsBody.angularVelocity;return i?new e.Vector3(i.x,i.y,i.z):null},t.prototype.setBodyMass=function(e,t){var i=0===t;e.physicsBody.shapes.density=i?1:t,e.physicsBody.setupMass(i?2:1)},t.prototype.sleepBody=function(e){e.physicsBody.sleep()},t.prototype.wakeUpBody=function(e){e.physicsBody.awake()},t.prototype.updateDistanceJoint=function(e,t,i){e.physicsJoint.limitMotoe.upperLimit=t,void 0!==i&&(e.physicsJoint.limitMotoe.lowerLimit=i)},t.prototype.setMotor=function(e,t,i,n){var r=n?e.physicsJoint.rotationalLimitMotor2:e.physicsJoint.rotationalLimitMotor1||e.physicsJoint.limitMotor;r&&r.setMotor(t,i)},t.prototype.setLimit=function(e,t,i,n){var r=n?e.physicsJoint.rotationalLimitMotor2:e.physicsJoint.rotationalLimitMotor1||e.physicsJoint.limitMotor;r&&r.setLimit(t,void 0===i?-t:i)},t.prototype.dispose=function(){this.world.clear()},t}();e.OimoJSPlugin=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n,r,o,s){e.call(this,t,"displayPass",["passSampler"],["passSampler"],i,n,r,o,s)}return __extends(t,e),t}(e.PostProcess);e.DisplayPassPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,i){this.quality=e,this.distance=t,this.optimizeMesh=i}return e}();e.SimplificationSettings=t;var i=function(){function t(){this.running=!1,this._simplificationArray=[]}return t.prototype.addTask=function(e){this._simplificationArray.push(e)},t.prototype.executeNext=function(){var e=this._simplificationArray.pop();e?(this.running=!0,this.runSimplification(e)):this.running=!1},t.prototype.runSimplification=function(t){var i=this;if(t.parallelProcessing)t.settings.forEach(function(e){var n=i.getSimplifier(t);n.simplify(e,function(n){t.mesh.addLODLevel(e.distance,n),n.isVisible=!0,e.quality===t.settings[t.settings.length-1].quality&&t.successCallback&&t.successCallback(),i.executeNext()})});else{var n=this.getSimplifier(t),r=function(e,i){n.simplify(e,function(n){t.mesh.addLODLevel(e.distance,n),n.isVisible=!0,i()})};e.AsyncLoop.Run(t.settings.length,function(e){r(t.settings[e.index],function(){e.executeNext()})},function(){t.successCallback&&t.successCallback(),i.executeNext()})}},t.prototype.getSimplifier=function(e){switch(e.simplificationType){case n.QUADRATIC:default:return new h(e.mesh)}},t}();e.SimplificationQueue=i,function(e){e[e.QUADRATIC=0]="QUADRATIC"}(e.SimplificationType||(e.SimplificationType={}));var n=e.SimplificationType,r=function(){function e(e){this.vertices=e,this.error=new Array(4),this.deleted=!1,this.isDirty=!1,this.deletePending=!1,this.borderFactor=0}return e}();e.DecimationTriangle=r;var o=function(){function e(e,t){this.position=e,this.id=t,this.isBorder=!0,this.q=new s,this.triangleCount=0,this.triangleStart=0,this.originalOffsets=[]}return e.prototype.updatePosition=function(e){this.position.copyFrom(e)},e}();e.DecimationVertex=o;var s=function(){function e(e){this.data=new Array(10);for(var t=0;10>t;++t)e&&e[t]?this.data[t]=e[t]:this.data[t]=0}return e.prototype.det=function(e,t,i,n,r,o,s,a,h){var c=this.data[e]*this.data[r]*this.data[h]+this.data[i]*this.data[n]*this.data[a]+this.data[t]*this.data[o]*this.data[s]-this.data[i]*this.data[r]*this.data[s]-this.data[e]*this.data[o]*this.data[a]-this.data[t]*this.data[n]*this.data[h];return c},e.prototype.addInPlace=function(e){for(var t=0;10>t;++t)this.data[t]+=e.data[t]},e.prototype.addArrayInPlace=function(e){for(var t=0;10>t;++t)this.data[t]+=e[t]},e.prototype.add=function(t){for(var i=new e,n=0;10>n;++n)i.data[n]=this.data[n]+t.data[n];return i},e.FromData=function(t,i,n,r){return new e(e.DataFromNumbers(t,i,n,r))},e.DataFromNumbers=function(e,t,i,n){return[e*e,e*t,e*i,e*n,t*t,t*i,t*n,i*i,i*n,n*n]},e}();e.QuadraticMatrix=s;var a=function(){function e(e,t){this.vertexId=e,this.triangleId=t}return e}();e.Reference=a;var h=function(){function t(t){this._mesh=t,this.initialized=!1,this.syncIterations=5e3,this.aggressiveness=7,this.decimationIterations=100,this.boundingBoxEpsilon=e.Epsilon}return t.prototype.simplify=function(t,i){var n=this;this.initDecimatedMesh(),e.AsyncLoop.Run(this._mesh.subMeshes.length,function(e){n.initWithMesh(e.index,function(){n.runDecimation(t,e.index,function(){e.executeNext()})},t.optimizeMesh)},function(){setTimeout(function(){i(n._reconstructedMesh)},0)})},t.prototype.isTriangleOnBoundingBox=function(e){var t=this,i=0;return e.vertices.forEach(function(e){var n=0,r=e.position,o=t._mesh.getBoundingInfo().boundingBox;(o.maximum.x-r.x<t.boundingBoxEpsilon||r.x-o.minimum.x>t.boundingBoxEpsilon)&&++n,o.maximum.y!==r.y&&r.y!==o.minimum.y||++n,o.maximum.z!==r.z&&r.z!==o.minimum.z||++n,n>1&&++i}),i>1&&console.log(e,i),i>1},t.prototype.runDecimation=function(t,i,n){var r=this,o=~~(this.triangles.length*t.quality),s=0,a=this.triangles.length,h=function(t,i){setTimeout(function(){t%5===0&&r.updateMesh(0===t);for(var n=0;n<r.triangles.length;++n)r.triangles[n].isDirty=!1;var h=1e-9*Math.pow(t+3,r.aggressiveness),c=function(t){var i=~~((r.triangles.length/2+t)%r.triangles.length),n=r.triangles[i];if(n&&!(n.error[3]>h||n.deleted||n.isDirty))for(var o=0;3>o;++o)if(n.error[o]<h){var a=[],c=[],l=n.vertices[o],u=n.vertices[(o+1)%3];if(l.isBorder||u.isBorder)continue;var d=e.Vector3.Zero(),f=e.Vector3.Zero(),p=e.Vector2.Zero(),m=new e.Color4(0,0,0,1);r.calculateError(l,u,d,f,p,m);var _=[];if(r.isFlipped(l,u,d,a,n.borderFactor,_))continue;if(r.isFlipped(u,l,d,c,n.borderFactor,_))continue;if(a.indexOf(!0)<0||c.indexOf(!0)<0)continue;var g=[];if(_.forEach(function(e){-1===g.indexOf(e)&&(e.deletePending=!0,g.push(e))}),g.length%2!==0)continue;l.q=u.q.add(l.q),l.updatePosition(d);var v=r.references.length;s=r.updateTriangles(l,l,a,s),s=r.updateTriangles(l,u,c,s);var y=r.references.length-v;if(y<=l.triangleCount){if(y)for(var x=0;y>x;x++)r.references[l.triangleStart+x]=r.references[v+x]}else l.triangleStart=v;l.triangleCount=y;break}};e.AsyncLoop.SyncAsyncForLoop(r.triangles.length,r.syncIterations,c,i,function(){return o>=a-s})},0)};e.AsyncLoop.Run(this.decimationIterations,function(e){o>=a-s?e.breakLoop():h(e.index,function(){e.executeNext()})},function(){setTimeout(function(){r.reconstructMesh(i),n()},0)})},t.prototype.initWithMesh=function(t,i,n){var s=this;this.vertices=[],this.triangles=[];var a=this._mesh.getVerticesData(e.VertexBuffer.PositionKind),h=this._mesh.getIndices(),c=this._mesh.subMeshes[t],l=function(e){if(n)for(var t=0;t<s.vertices.length;++t)if(s.vertices[t].position.equals(e))return s.vertices[t];return null},u=[],d=function(t){var i=t+c.verticesStart,n=e.Vector3.FromArray(a,3*i),r=l(n)||new o(n,s.vertices.length);r.originalOffsets.push(i),r.id===s.vertices.length&&s.vertices.push(r),u.push(r.id)},f=c.verticesCount;e.AsyncLoop.SyncAsyncForLoop(f,this.syncIterations/4>>0,d,function(){var t=function(e){var t=c.indexStart/3+e,i=3*t,n=h[i+0],o=h[i+1],a=h[i+2],l=s.vertices[u[n-c.verticesStart]],d=s.vertices[u[o-c.verticesStart]],f=s.vertices[u[a-c.verticesStart]],p=new r([l,d,f]);p.originalOffset=i,s.triangles.push(p)};e.AsyncLoop.SyncAsyncForLoop(c.indexCount/3,s.syncIterations,t,function(){s.init(i)})})},t.prototype.init=function(t){var i=this,n=function(t){var n=i.triangles[t];n.normal=e.Vector3.Cross(n.vertices[1].position.subtract(n.vertices[0].position),n.vertices[2].position.subtract(n.vertices[0].position)).normalize();for(var r=0;3>r;r++)n.vertices[r].q.addArrayInPlace(s.DataFromNumbers(n.normal.x,n.normal.y,n.normal.z,-e.Vector3.Dot(n.normal,n.vertices[0].position)))};e.AsyncLoop.SyncAsyncForLoop(this.triangles.length,this.syncIterations,n,function(){var n=function(e){for(var t=i.triangles[e],n=0;3>n;++n)t.error[n]=i.calculateError(t.vertices[n],t.vertices[(n+1)%3]);t.error[3]=Math.min(t.error[0],t.error[1],t.error[2])};e.AsyncLoop.SyncAsyncForLoop(i.triangles.length,i.syncIterations,n,function(){i.initialized=!0,t()})})},t.prototype.reconstructMesh=function(t){var i,n=[];for(i=0;i<this.vertices.length;++i)this.vertices[i].triangleCount=0;var r,o;for(i=0;i<this.triangles.length;++i)if(!this.triangles[i].deleted){for(r=this.triangles[i],o=0;3>o;++o)r.vertices[o].triangleCount=1;n.push(r)}var s=this._reconstructedMesh.getVerticesData(e.VertexBuffer.PositionKind)||[],a=this._reconstructedMesh.getVerticesData(e.VertexBuffer.NormalKind)||[],h=this._reconstructedMesh.getVerticesData(e.VertexBuffer.UVKind)||[],c=this._reconstructedMesh.getVerticesData(e.VertexBuffer.ColorKind)||[],l=this._mesh.getVerticesData(e.VertexBuffer.NormalKind),u=this._mesh.getVerticesData(e.VertexBuffer.UVKind),d=this._mesh.getVerticesData(e.VertexBuffer.ColorKind),f=0;for(i=0;i<this.vertices.length;++i){var p=this.vertices[i];p.id=f,p.triangleCount&&p.originalOffsets.forEach(function(e){s.push(p.position.x),s.push(p.position.y),s.push(p.position.z),a.push(l[3*e]),a.push(l[3*e+1]),a.push(l[3*e+2]),u&&u.length?(h.push(u[2*e]),h.push(u[2*e+1])):d&&d.length&&(c.push(d[4*e]),c.push(d[4*e+1]),c.push(d[4*e+2]),c.push(d[4*e+3])),++f})}var m=this._reconstructedMesh.getTotalIndices(),_=this._reconstructedMesh.getTotalVertices(),g=this._reconstructedMesh.subMeshes;this._reconstructedMesh.subMeshes=[];var v=this._reconstructedMesh.getIndices(),y=this._mesh.getIndices();for(i=0;i<n.length;++i)r=n[i],[0,1,2].forEach(function(e){var t=y[r.originalOffset+e],i=r.vertices[e].originalOffsets.indexOf(t);0>i&&(i=0),v.push(r.vertices[e].id+i+_)});this._reconstructedMesh.setIndices(v),this._reconstructedMesh.setVerticesData(e.VertexBuffer.PositionKind,s),this._reconstructedMesh.setVerticesData(e.VertexBuffer.NormalKind,a),h.length>0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.UVKind,h),c.length>0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.ColorKind,c);var x=this._mesh.subMeshes[t];if(t>0){this._reconstructedMesh.subMeshes=[],g.forEach(function(t){new e.SubMesh(t.materialIndex,t.verticesStart,t.verticesCount,t.indexStart,t.indexCount,t.getMesh())});new e.SubMesh(x.materialIndex,_,f,m,3*n.length,this._reconstructedMesh)}},t.prototype.initDecimatedMesh=function(){this._reconstructedMesh=new e.Mesh(this._mesh.name+"Decimated",this._mesh.getScene()),this._reconstructedMesh.material=this._mesh.material,this._reconstructedMesh.parent=this._mesh.parent,this._reconstructedMesh.isVisible=!1,this._reconstructedMesh.renderingGroupId=this._mesh.renderingGroupId},t.prototype.isFlipped=function(t,i,n,r,o,s){for(var a=0;a<t.triangleCount;++a){var h=this.triangles[this.references[t.triangleStart+a].triangleId];if(!h.deleted){var c=this.references[t.triangleStart+a].vertexId,l=h.vertices[(c+1)%3],u=h.vertices[(c+2)%3];if(l!==i&&u!==i){var d=l.position.subtract(n);d=d.normalize();var f=u.position.subtract(n);if(f=f.normalize(),Math.abs(e.Vector3.Dot(d,f))>.999)return!0;var p=e.Vector3.Cross(d,f).normalize();if(r[a]=!1,e.Vector3.Dot(p,h.normal)<.2)return!0}else r[a]=!0,s.push(h)}}return!1},t.prototype.updateTriangles=function(e,t,i,n){for(var r=n,o=0;o<t.triangleCount;++o){var s=this.references[t.triangleStart+o],a=this.triangles[s.triangleId];a.deleted||(i[o]&&a.deletePending?(a.deleted=!0,r++):(a.vertices[s.vertexId]=e,a.isDirty=!0,a.error[0]=this.calculateError(a.vertices[0],a.vertices[1])+a.borderFactor/2,a.error[1]=this.calculateError(a.vertices[1],a.vertices[2])+a.borderFactor/2,a.error[2]=this.calculateError(a.vertices[2],a.vertices[0])+a.borderFactor/2,a.error[3]=Math.min(a.error[0],a.error[1],a.error[2]),this.references.push(s)))}return r},t.prototype.identifyBorder=function(){for(var e=0;e<this.vertices.length;++e){var t,i=[],n=[],r=this.vertices[e];for(t=0;t<r.triangleCount;++t)for(var o=this.triangles[this.references[r.triangleStart+t].triangleId],s=0;3>s;s++){for(var a=0,h=o.vertices[s];a<i.length&&n[a]!==h.id;)++a;a===i.length?(i.push(1),n.push(h.id)):i[a]++}for(t=0;t<i.length;++t)1===i[t]?this.vertices[n[t]].isBorder=!0:this.vertices[n[t]].isBorder=!1}},t.prototype.updateMesh=function(e){void 0===e&&(e=!1);var t;if(!e){var i=[];for(t=0;t<this.triangles.length;++t)this.triangles[t].deleted||i.push(this.triangles[t]);this.triangles=i}for(t=0;t<this.vertices.length;++t)this.vertices[t].triangleCount=0,this.vertices[t].triangleStart=0;var n,r,o;for(t=0;t<this.triangles.length;++t)for(n=this.triangles[t],r=0;3>r;++r)o=n.vertices[r],o.triangleCount++;var s=0;for(t=0;t<this.vertices.length;++t)this.vertices[t].triangleStart=s,s+=this.vertices[t].triangleCount,this.vertices[t].triangleCount=0;var h=new Array(3*this.triangles.length);for(t=0;t<this.triangles.length;++t)for(n=this.triangles[t],r=0;3>r;++r)o=n.vertices[r],h[o.triangleStart+o.triangleCount]=new a(r,t),o.triangleCount++;this.references=h,e&&this.identifyBorder()},t.prototype.vertexError=function(e,t){var i=t.x,n=t.y,r=t.z;return e.data[0]*i*i+2*e.data[1]*i*n+2*e.data[2]*i*r+2*e.data[3]*i+e.data[4]*n*n+2*e.data[5]*n*r+2*e.data[6]*n+e.data[7]*r*r+2*e.data[8]*r+e.data[9]},t.prototype.calculateError=function(t,i,n,r,o,s){var a=t.q.add(i.q),h=t.isBorder&&i.isBorder,c=0,l=a.det(0,1,2,1,4,5,2,5,7);if(0===l||h){var u=t.position.add(i.position).divide(new e.Vector3(2,2,2)),d=this.vertexError(a,t.position),f=this.vertexError(a,i.position),p=this.vertexError(a,u);c=Math.min(d,f,p),c===d?n&&n.copyFrom(t.position):c===f?n&&n.copyFrom(i.position):n&&n.copyFrom(u)}else n||(n=e.Vector3.Zero()),n.x=-1/l*a.det(1,2,3,4,5,6,5,7,8),n.y=1/l*a.det(0,2,3,1,5,6,2,7,8),n.z=-1/l*a.det(0,1,3,1,4,6,2,5,8),c=this.vertexError(a,n);return c},t}();e.QuadraticErrorSimplification=h}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=[],i=function(i,n){if(!t[i.id]){if(i instanceof e.Geometry.Primitives.Box)n.boxes.push(i.serialize());else if(i instanceof e.Geometry.Primitives.Sphere)n.spheres.push(i.serialize());else if(i instanceof e.Geometry.Primitives.Cylinder)n.cylinders.push(i.serialize());else if(i instanceof e.Geometry.Primitives.Torus)n.toruses.push(i.serialize());else if(i instanceof e.Geometry.Primitives.Ground)n.grounds.push(i.serialize());else if(i instanceof e.Geometry.Primitives.Plane)n.planes.push(i.serialize());else if(i instanceof e.Geometry.Primitives.TorusKnot)n.torusKnots.push(i.serialize());else{if(i instanceof e.Geometry.Primitives._Primitive)throw new Error("Unknown primitive type");n.vertexData.push(i.serializeVerticeData())}t[i.id]=!0}},n=function(t,n){var r={};r.name=t.name,r.id=t.id,e.Tags.HasTags(t)&&(r.tags=e.Tags.GetTags(t)),r.position=t.position.asArray(),t.rotationQuaternion?r.rotationQuaternion=t.rotationQuaternion.asArray():t.rotation&&(r.rotation=t.rotation.asArray()),r.scaling=t.scaling.asArray(),r.localMatrix=t.getPivotMatrix().asArray(),r.isEnabled=t.isEnabled(),r.isVisible=t.isVisible,r.infiniteDistance=t.infiniteDistance,r.pickable=t.isPickable,r.receiveShadows=t.receiveShadows,r.billboardMode=t.billboardMode,r.visibility=t.visibility,r.checkCollisions=t.checkCollisions,t.parent&&(r.parentId=t.parent.id);var o=t._geometry;if(o){var s=o.id;r.geometryId=s,t.getScene().getGeometryByID(s)||i(o,n.geometries),r.subMeshes=[];for(var a=0;a<t.subMeshes.length;a++){var h=t.subMeshes[a];r.subMeshes.push({materialIndex:h.materialIndex,verticesStart:h.verticesStart,verticesCount:h.verticesCount,indexStart:h.indexStart,indexCount:h.indexCount})}}t.material?r.materialId=t.material.id:t.material=null,t.skeleton&&(r.skeletonId=t.skeleton.id),t.getPhysicsImpostor()&&(r.physicsMass=t.getPhysicsMass(),r.physicsFriction=t.getPhysicsFriction(),r.physicsRestitution=t.getPhysicsRestitution(),r.physicsImpostor=t.getPhysicsImpostor().type),r.instances=[];for(var c=0;c<t.instances.length;c++){var l=t.instances[c],u={name:l.name,position:l.position.asArray(),scaling:l.scaling.asArray()};l.rotationQuaternion?u.rotationQuaternion=l.rotationQuaternion.asArray():l.rotation&&(u.rotation=l.rotation.asArray()),r.instances.push(u),e.Animation.AppendSerializedAnimations(l,u),u.ranges=l.serializeAnimationRanges()}return e.Animation.AppendSerializedAnimations(t,r),r.ranges=t.serializeAnimationRanges(),r.layerMask=t.layerMask,r},r=function(t,r){if(t.delayLoadState===e.Engine.DELAYLOADSTATE_LOADED||t.delayLoadState===e.Engine.DELAYLOADSTATE_NONE){t.material&&(t.material instanceof e.StandardMaterial?(r.materials=r.materials||[],r.materials.some(function(e){return e.id===t.material.id})||r.materials.push(t.material.serialize())):t.material instanceof e.MultiMaterial&&(r.multiMaterials=r.multiMaterials||[],r.multiMaterials.some(function(e){return e.id===t.material.id})||r.multiMaterials.push(t.material.serialize())));var o=t._geometry;o&&(r.geometries||(r.geometries={},r.geometries.boxes=[],r.geometries.spheres=[],r.geometries.cylinders=[],r.geometries.toruses=[],r.geometries.grounds=[],r.geometries.planes=[],r.geometries.torusKnots=[],r.geometries.vertexData=[]),i(o,r.geometries)),t.skeleton&&(r.skeletons=r.skeletons||[],r.skeletons.push(t.skeleton.serialize())),r.meshes=r.meshes||[],r.meshes.push(n(t,r))}},o=function(){function o(){}return o.ClearCache=function(){t=[]},o.Serialize=function(r){var o={};o.useDelayedTextureLoading=r.useDelayedTextureLoading,o.autoClear=r.autoClear,o.clearColor=r.clearColor.asArray(),o.ambientColor=r.ambientColor.asArray(),o.gravity=r.gravity.asArray(),o.collisionsEnabled=r.collisionsEnabled,o.workerCollisions=r.workerCollisions,r.fogMode&&0!==r.fogMode&&(o.fogMode=r.fogMode,o.fogColor=r.fogColor.asArray(),o.fogStart=r.fogStart,o.fogEnd=r.fogEnd,o.fogDensity=r.fogDensity),r.isPhysicsEnabled()&&(o.physicsEnabled=!0,o.physicsGravity=r.getPhysicsEngine().gravity.asArray(),o.physicsEngine=r.getPhysicsEngine().getPhysicsPluginName()),o.lights=[];var s,a;for(s=0;s<r.lights.length;s++)a=r.lights[s],o.lights.push(a.serialize());for(o.cameras=[],s=0;s<r.cameras.length;s++){var h=r.cameras[s];o.cameras.push(h.serialize())}r.activeCamera&&(o.activeCameraID=r.activeCamera.id),e.Animation.AppendSerializedAnimations(r,o),o.materials=[],o.multiMaterials=[];var c;for(s=0;s<r.materials.length;s++)c=r.materials[s],o.materials.push(c.serialize());for(o.multiMaterials=[],s=0;s<r.multiMaterials.length;s++){var l=r.multiMaterials[s];o.multiMaterials.push(l.serialize())}for(o.skeletons=[],s=0;s<r.skeletons.length;s++)o.skeletons.push(r.skeletons[s].serialize());o.geometries={},o.geometries.boxes=[],o.geometries.spheres=[],o.geometries.cylinders=[],o.geometries.toruses=[],o.geometries.grounds=[],o.geometries.planes=[],o.geometries.torusKnots=[],o.geometries.vertexData=[],t=[];var u=r.getGeometries();for(s=0;s<u.length;s++){var d=u[s];d.isReady()&&i(d,o.geometries)}for(o.meshes=[],s=0;s<r.meshes.length;s++){var f=r.meshes[s];if(f instanceof e.Mesh){var p=f;p.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADED&&p.delayLoadState!==e.Engine.DELAYLOADSTATE_NONE||o.meshes.push(n(p,o))}}for(o.particleSystems=[],s=0;s<r.particleSystems.length;s++)o.particleSystems.push(r.particleSystems[s].serialize());for(o.lensFlareSystems=[],s=0;s<r.lensFlareSystems.length;s++)o.lensFlareSystems.push(r.lensFlareSystems[s].serialize());for(o.shadowGenerators=[],s=0;s<r.lights.length;s++)a=r.lights[s],a.getShadowGenerator()&&o.shadowGenerators.push(a.getShadowGenerator().serialize());return o},o.SerializeMesh=function(t,i,n){void 0===i&&(i=!1),void 0===n&&(n=!1);var o={};if(t=t instanceof Array?t:[t],i||n)for(var s=0;s<t.length;++s)n&&t[s].getDescendants().forEach(function(i){i instanceof e.Mesh&&t.indexOf(i)<0&&t.push(i)}),i&&t[s].parent&&t.indexOf(t[s].parent)<0&&t.push(t[s].parent);return t.forEach(function(e){r(e,o)}),o},o}();e.SceneSerializer=o}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=0,i=function(){function t(e,t,i){this.pos=e,this.normal=t,this.uv=i}return t.prototype.clone=function(){return new t(this.pos.clone(),this.normal.clone(),this.uv.clone())},t.prototype.flip=function(){this.normal=this.normal.scale(-1)},t.prototype.interpolate=function(i,n){return new t(e.Vector3.Lerp(this.pos,i.pos,n),e.Vector3.Lerp(this.normal,i.normal,n),e.Vector2.Lerp(this.uv,i.uv,n))},t}(),n=function(){function t(e,t){this.normal=e,this.w=t}return t.FromPoints=function(i,n,r){var o=r.subtract(i),s=n.subtract(i);if(0===o.lengthSquared()||0===s.lengthSquared())return null;var a=e.Vector3.Normalize(e.Vector3.Cross(o,s));return new t(a,e.Vector3.Dot(a,i))},t.prototype.clone=function(){return new t(this.normal.clone(),this.w)},t.prototype.flip=function(){this.normal.scaleInPlace(-1),this.w=-this.w},t.prototype.splitPolygon=function(i,n,o,s,a){var h,c,l=0,u=1,d=2,f=3,p=0,m=[];for(h=0;h<i.vertices.length;h++){c=e.Vector3.Dot(this.normal,i.vertices[h].pos)-this.w;var _=c<-t.EPSILON?d:c>t.EPSILON?u:l;p|=_,m.push(_)}switch(p){case l:(e.Vector3.Dot(this.normal,i.plane.normal)>0?n:o).push(i);break;case u:s.push(i);break;case d:a.push(i);break;case f:var g=[],v=[];for(h=0;h<i.vertices.length;h++){var y=(h+1)%i.vertices.length,x=m[h],b=m[y],E=i.vertices[h],A=i.vertices[y];if(x!==d&&g.push(E),x!==u&&v.push(x!==d?E.clone():E),(x|b)===f){c=(this.w-e.Vector3.Dot(this.normal,E.pos))/e.Vector3.Dot(this.normal,A.pos.subtract(E.pos));var T=E.interpolate(A,c);g.push(T),v.push(T.clone())}}var P;g.length>=3&&(P=new r(g,i.shared),P.plane&&s.push(P)),v.length>=3&&(P=new r(v,i.shared),P.plane&&a.push(P))}},t.EPSILON=1e-5,t}(),r=function(){function e(e,t){this.vertices=e,this.shared=t,this.plane=n.FromPoints(e[0].pos,e[1].pos,e[2].pos)}return e.prototype.clone=function(){var t=this.vertices.map(function(e){return e.clone()});return new e(t,this.shared)},e.prototype.flip=function(){this.vertices.reverse().map(function(e){e.flip()}),this.plane.flip()},e}(),o=function(){function e(e){this.plane=null,this.front=null,this.back=null,this.polygons=[],e&&this.build(e)}return e.prototype.clone=function(){var t=new e;return t.plane=this.plane&&this.plane.clone(),t.front=this.front&&this.front.clone(),t.back=this.back&&this.back.clone(),t.polygons=this.polygons.map(function(e){return e.clone()}),t},e.prototype.invert=function(){for(var e=0;e<this.polygons.length;e++)this.polygons[e].flip();this.plane&&this.plane.flip(),this.front&&this.front.invert(),this.back&&this.back.invert();var t=this.front;this.front=this.back,this.back=t},e.prototype.clipPolygons=function(e){if(!this.plane)return e.slice();for(var t=[],i=[],n=0;n<e.length;n++)this.plane.splitPolygon(e[n],t,i,t,i);return this.front&&(t=this.front.clipPolygons(t)),i=this.back?this.back.clipPolygons(i):[],t.concat(i)},e.prototype.clipTo=function(e){this.polygons=e.clipPolygons(this.polygons),this.front&&this.front.clipTo(e),this.back&&this.back.clipTo(e)},e.prototype.allPolygons=function(){var e=this.polygons.slice();return this.front&&(e=e.concat(this.front.allPolygons())),this.back&&(e=e.concat(this.back.allPolygons())),e},e.prototype.build=function(t){if(t.length){this.plane||(this.plane=t[0].plane.clone());for(var i=[],n=[],r=0;r<t.length;r++)this.plane.splitPolygon(t[r],this.polygons,this.polygons,i,n);i.length&&(this.front||(this.front=new e),this.front.build(i)),n.length&&(this.back||(this.back=new e),this.back.build(n))}},e}(),s=function(){function n(){this.polygons=new Array}return n.FromMesh=function(o){var s,a,h,c,l,u,d,f,p,m,_,g=new Array;if(!(o instanceof e.Mesh))throw"BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh";o.computeWorldMatrix(!0),d=o.getWorldMatrix(),f=o.position.clone(),p=o.rotation.clone(),o.rotationQuaternion&&(m=o.rotationQuaternion.clone()),_=o.scaling.clone();for(var v=o.getIndices(),y=o.getVerticesData(e.VertexBuffer.PositionKind),x=o.getVerticesData(e.VertexBuffer.NormalKind),b=o.getVerticesData(e.VertexBuffer.UVKind),E=o.subMeshes,A=0,T=E.length;T>A;A++)for(var P=E[A].indexStart,M=E[A].indexCount+E[A].indexStart;M>P;P+=3){u=[];for(var C=0;3>C;C++){var S=new e.Vector3(x[3*v[P+C]],x[3*v[P+C]+1],x[3*v[P+C]+2]);h=new e.Vector2(b[2*v[P+C]],b[2*v[P+C]+1]);var R=new e.Vector3(y[3*v[P+C]],y[3*v[P+C]+1],y[3*v[P+C]+2]);c=e.Vector3.TransformCoordinates(R,d),a=e.Vector3.TransformNormal(S,d),s=new i(c,a,h),u.push(s)}l=new r(u,{subMeshId:A,meshId:t,materialIndex:E[A].materialIndex}),l.plane&&g.push(l)}var I=n.FromPolygons(g);return I.matrix=d,I.position=f,I.rotation=p,I.scaling=_,I.rotationQuaternion=m,t++,I},n.FromPolygons=function(e){var t=new n;return t.polygons=e,t},n.prototype.clone=function(){var e=new n;return e.polygons=this.polygons.map(function(e){return e.clone()}),e.copyTransformAttributes(this),e},n.prototype.toPolygons=function(){return this.polygons},n.prototype.union=function(e){var t=new o(this.clone().polygons),i=new o(e.clone().polygons);return t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),n.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},n.prototype.unionInPlace=function(e){var t=new o(this.polygons),i=new o(e.polygons);t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),this.polygons=t.allPolygons()},n.prototype.subtract=function(e){var t=new o(this.clone().polygons),i=new o(e.clone().polygons);return t.invert(),t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),t.invert(),n.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},n.prototype.subtractInPlace=function(e){var t=new o(this.polygons),i=new o(e.polygons);t.invert(),t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),t.invert(),this.polygons=t.allPolygons()},n.prototype.intersect=function(e){var t=new o(this.clone().polygons),i=new o(e.clone().polygons);return t.invert(),i.clipTo(t),i.invert(),t.clipTo(i),i.clipTo(t),t.build(i.allPolygons()),t.invert(),n.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},n.prototype.intersectInPlace=function(e){var t=new o(this.polygons),i=new o(e.polygons);t.invert(),i.clipTo(t),i.invert(),t.clipTo(i),i.clipTo(t),t.build(i.allPolygons()),t.invert(),this.polygons=t.allPolygons()},n.prototype.inverse=function(){var e=this.clone();return e.inverseInPlace(),e},n.prototype.inverseInPlace=function(){this.polygons.map(function(e){e.flip()})},n.prototype.copyTransformAttributes=function(e){return this.matrix=e.matrix,this.position=e.position,this.rotation=e.rotation,this.scaling=e.scaling,this.rotationQuaternion=e.rotationQuaternion,this},n.prototype.buildMeshGeometry=function(t,i,n){var r=this.matrix.clone();r.invert();var o,s,a,h=new e.Mesh(t,i),c=[],l=[],u=[],d=[],f=e.Vector3.Zero(),p=e.Vector3.Zero(),m=e.Vector2.Zero(),_=this.polygons,g=[0,0,0],v={},y=0,x={};n&&_.sort(function(e,t){return e.shared.meshId===t.shared.meshId?e.shared.subMeshId-t.shared.subMeshId:e.shared.meshId-t.shared.meshId});for(var b=0,E=_.length;E>b;b++){o=_[b],x[o.shared.meshId]||(x[o.shared.meshId]={}),x[o.shared.meshId][o.shared.subMeshId]||(x[o.shared.meshId][o.shared.subMeshId]={indexStart:+(1/0),indexEnd:-(1/0),materialIndex:o.shared.materialIndex}),a=x[o.shared.meshId][o.shared.subMeshId];for(var A=2,T=o.vertices.length;T>A;A++){g[0]=0,g[1]=A-1,g[2]=A;for(var P=0;3>P;P++){f.copyFrom(o.vertices[g[P]].pos),p.copyFrom(o.vertices[g[P]].normal),m.copyFrom(o.vertices[g[P]].uv);var M=e.Vector3.TransformCoordinates(f,r),C=e.Vector3.TransformNormal(p,r);s=v[M.x+","+M.y+","+M.z],"undefined"!=typeof s&&u[3*s]===C.x&&u[3*s+1]===C.y&&u[3*s+2]===C.z&&d[2*s]===m.x&&d[2*s+1]===m.y||(c.push(M.x,M.y,M.z),d.push(m.x,m.y),u.push(p.x,p.y,p.z),s=v[M.x+","+M.y+","+M.z]=c.length/3-1),l.push(s),a.indexStart=Math.min(y,a.indexStart),a.indexEnd=Math.max(y,a.indexEnd),y++}}}if(h.setVerticesData(e.VertexBuffer.PositionKind,c),h.setVerticesData(e.VertexBuffer.NormalKind,u),h.setVerticesData(e.VertexBuffer.UVKind,d),h.setIndices(l),n){var S,R=0;h.subMeshes=new Array;for(var I in x){S=-1;for(var D in x[I])a=x[I][D],e.SubMesh.CreateFromIndices(a.materialIndex+R,a.indexStart,a.indexEnd-a.indexStart+1,h),S=Math.max(a.materialIndex,S);R+=++S}}return h},n.prototype.toMesh=function(e,t,i,n){var r=this.buildMeshGeometry(e,i,n);return r.material=t,r.position.copyFrom(this.position),r.rotation.copyFrom(this.rotation),this.rotationQuaternion&&(r.rotationQuaternion=this.rotationQuaternion.clone()),r.scaling.copyFrom(this.scaling),r.computeWorldMatrix(!0),r},n}();e.CSG=s}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o){var s=this;t.call(this,i,"vrDistortionCorrection",["LensCenter","Scale","ScaleIn","HmdWarpParam"],null,o.postProcessScaleFactor,n,e.Texture.BILINEAR_SAMPLINGMODE,null,null),this._isRightEye=r,this._distortionFactors=o.distortionK,this._postProcessScaleFactor=o.postProcessScaleFactor,this._lensCenterOffset=o.lensCenterOffset,this.onSizeChanged=function(){s.aspectRatio=.5*s.width/s.height,s._scaleIn=new e.Vector2(2,2/s.aspectRatio),s._scaleFactor=new e.Vector2(.5*(1/s._postProcessScaleFactor),.5*(1/s._postProcessScaleFactor)*s.aspectRatio),s._lensCenter=new e.Vector2(s._isRightEye?.5-.5*s._lensCenterOffset:.5+.5*s._lensCenterOffset,.5)},this.onApply=function(e){e.setFloat2("LensCenter",s._lensCenter.x,s._lensCenter.y),e.setFloat2("Scale",s._scaleFactor.x,s._scaleFactor.y),e.setFloat2("ScaleIn",s._scaleIn.x,s._scaleIn.y),e.setFloat4("HmdWarpParam",s._distortionFactors[0],s._distortionFactors[1],s._distortionFactors[2],s._distortionFactors[3])}}return __extends(i,t),i}(e.PostProcess);e.VRDistortionCorrectionPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){!function(e){e[e.X=0]="X",e[e.Y=1]="Y",e[e.Z=2]="Z"}(e.JoystickAxis||(e.JoystickAxis={}));var t=e.JoystickAxis,i=function(){function i(n){var r=this;n?this._leftJoystick=!0:this._leftJoystick=!1,this._joystickIndex=i._globalJoystickIndex,i._globalJoystickIndex++,this._axisTargetedByLeftAndRight=t.X,this._axisTargetedByUpAndDown=t.Y,this.reverseLeftRight=!1,this.reverseUpDown=!1,this._touches=new e.SmartCollection,this.deltaPosition=e.Vector3.Zero(),this._joystickSensibility=25,this._inversedSensibility=1/(this._joystickSensibility/1e3),this._rotationSpeed=25,this._inverseRotationSpeed=1/(this._rotationSpeed/1e3),this._rotateOnAxisRelativeToMesh=!1,this._onResize=function(e){i.vjCanvasWidth=window.innerWidth,i.vjCanvasHeight=window.innerHeight,i.vjCanvas.width=i.vjCanvasWidth,i.vjCanvas.height=i.vjCanvasHeight,i.halfWidth=i.vjCanvasWidth/2,i.halfHeight=i.vjCanvasHeight/2},i.vjCanvas||(window.addEventListener("resize",this._onResize,!1),i.vjCanvas=document.createElement("canvas"),i.vjCanvasWidth=window.innerWidth,i.vjCanvasHeight=window.innerHeight,i.vjCanvas.width=window.innerWidth,i.vjCanvas.height=window.innerHeight,i.vjCanvas.style.width="100%",i.vjCanvas.style.height="100%",i.vjCanvas.style.position="absolute",i.vjCanvas.style.backgroundColor="transparent",i.vjCanvas.style.top="0px",i.vjCanvas.style.left="0px",i.vjCanvas.style.zIndex="5",i.vjCanvas.style.msTouchAction="none",i.vjCanvas.setAttribute("touch-action","none"),i.vjCanvasContext=i.vjCanvas.getContext("2d"),i.vjCanvasContext.strokeStyle="#ffffff",i.vjCanvasContext.lineWidth=2,document.body.appendChild(i.vjCanvas)),i.halfWidth=i.vjCanvas.width/2,i.halfHeight=i.vjCanvas.height/2,this.pressed=!1,this._joystickColor="cyan",this._joystickPointerID=-1,this._joystickPointerPos=new e.Vector2(0,0),this._joystickPreviousPointerPos=new e.Vector2(0,0),this._joystickPointerStartPos=new e.Vector2(0,0),this._deltaJoystickVector=new e.Vector2(0,0),this._onPointerDownHandlerRef=function(e){r._onPointerDown(e)},this._onPointerMoveHandlerRef=function(e){r._onPointerMove(e)},this._onPointerOutHandlerRef=function(e){r._onPointerUp(e)},this._onPointerUpHandlerRef=function(e){r._onPointerUp(e)},i.vjCanvas.addEventListener("pointerdown",this._onPointerDownHandlerRef,!1),i.vjCanvas.addEventListener("pointermove",this._onPointerMoveHandlerRef,!1),i.vjCanvas.addEventListener("pointerup",this._onPointerUpHandlerRef,!1),i.vjCanvas.addEventListener("pointerout",this._onPointerUpHandlerRef,!1),i.vjCanvas.addEventListener("contextmenu",function(e){e.preventDefault()},!1),requestAnimationFrame(function(){r._drawVirtualJoystick()})}return i.prototype.setJoystickSensibility=function(e){this._joystickSensibility=e,this._inversedSensibility=1/(this._joystickSensibility/1e3)},i.prototype._onPointerDown=function(e){
  24. var t;e.preventDefault(),t=this._leftJoystick===!0?e.clientX<i.halfWidth:e.clientX>i.halfWidth,t&&this._joystickPointerID<0?(this._joystickPointerID=e.pointerId,this._joystickPointerStartPos.x=e.clientX,this._joystickPointerStartPos.y=e.clientY,this._joystickPointerPos=this._joystickPointerStartPos.clone(),this._joystickPreviousPointerPos=this._joystickPointerStartPos.clone(),this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this.pressed=!0,this._touches.add(e.pointerId.toString(),e)):i._globalJoystickIndex<2&&this._action&&(this._action(),this._touches.add(e.pointerId.toString(),{x:e.clientX,y:e.clientY,prevX:e.clientX,prevY:e.clientY}))},i.prototype._onPointerMove=function(e){if(this._joystickPointerID==e.pointerId){this._joystickPointerPos.x=e.clientX,this._joystickPointerPos.y=e.clientY,this._deltaJoystickVector=this._joystickPointerPos.clone(),this._deltaJoystickVector=this._deltaJoystickVector.subtract(this._joystickPointerStartPos);var i=this.reverseLeftRight?-1:1,n=i*this._deltaJoystickVector.x/this._inversedSensibility;switch(this._axisTargetedByLeftAndRight){case t.X:this.deltaPosition.x=Math.min(1,Math.max(-1,n));break;case t.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,n));break;case t.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,n))}var r=this.reverseUpDown?1:-1,o=r*this._deltaJoystickVector.y/this._inversedSensibility;switch(this._axisTargetedByUpAndDown){case t.X:this.deltaPosition.x=Math.min(1,Math.max(-1,o));break;case t.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,o));break;case t.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,o))}}else this._touches.item(e.pointerId.toString())&&(this._touches.item(e.pointerId.toString()).x=e.clientX,this._touches.item(e.pointerId.toString()).y=e.clientY)},i.prototype._onPointerUp=function(e){if(this._joystickPointerID==e.pointerId)i.vjCanvasContext.clearRect(this._joystickPointerStartPos.x-63,this._joystickPointerStartPos.y-63,126,126),i.vjCanvasContext.clearRect(this._joystickPreviousPointerPos.x-41,this._joystickPreviousPointerPos.y-41,82,82),this._joystickPointerID=-1,this.pressed=!1;else{var t=this._touches.item(e.pointerId.toString());t&&i.vjCanvasContext.clearRect(t.prevX-43,t.prevY-43,86,86)}this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this._touches.remove(e.pointerId.toString())},i.prototype.setJoystickColor=function(e){this._joystickColor=e},i.prototype.setActionOnTouch=function(e){this._action=e},i.prototype.setAxisForLeftRight=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByLeftAndRight=e;break;default:this._axisTargetedByLeftAndRight=t.X}},i.prototype.setAxisForUpDown=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByUpAndDown=e;break;default:this._axisTargetedByUpAndDown=t.Y}},i.prototype._clearCanvas=function(){this._leftJoystick?i.vjCanvasContext.clearRect(0,0,i.vjCanvasWidth/2,i.vjCanvasHeight):i.vjCanvasContext.clearRect(i.vjCanvasWidth/2,0,i.vjCanvasWidth,i.vjCanvasHeight)},i.prototype._drawVirtualJoystick=function(){var e=this;this.pressed&&this._touches.forEach(function(t){t.pointerId===e._joystickPointerID?(i.vjCanvasContext.clearRect(e._joystickPointerStartPos.x-63,e._joystickPointerStartPos.y-63,126,126),i.vjCanvasContext.clearRect(e._joystickPreviousPointerPos.x-41,e._joystickPreviousPointerPos.y-41,82,82),i.vjCanvasContext.beginPath(),i.vjCanvasContext.lineWidth=6,i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.lineWidth=2,i.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,60,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.arc(e._joystickPointerPos.x,e._joystickPointerPos.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),e._joystickPreviousPointerPos=e._joystickPointerPos.clone()):(i.vjCanvasContext.clearRect(t.prevX-43,t.prevY-43,86,86),i.vjCanvasContext.beginPath(),i.vjCanvasContext.fillStyle="white",i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle="red",i.vjCanvasContext.lineWidth=6,i.vjCanvasContext.arc(t.x,t.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),t.prevX=t.x,t.prevY=t.y)}),requestAnimationFrame(function(){e._drawVirtualJoystick()})},i.prototype.releaseCanvas=function(){i.vjCanvas&&(i.vjCanvas.removeEventListener("pointerdown",this._onPointerDownHandlerRef),i.vjCanvas.removeEventListener("pointermove",this._onPointerMoveHandlerRef),i.vjCanvas.removeEventListener("pointerup",this._onPointerUpHandlerRef),i.vjCanvas.removeEventListener("pointerout",this._onPointerUpHandlerRef),window.removeEventListener("resize",this._onResize),document.body.removeChild(i.vjCanvas),i.vjCanvas=null)},i._globalJoystickIndex=0,i}();e.VirtualJoystick=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n){e.call(this,t,i,n),this.inputs.addVirtualJoystick()}return __extends(t,e),t}(e.FreeCamera);e.VirtualJoysticksCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n,r,o,s){e.call(this,t,"anaglyph",null,["leftSampler"],i,n,r,o,s)}return __extends(t,e),t}(e.PostProcess);e.AnaglyphPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e){this._scene=e}return t.prototype.render=function(t,i,n){var r=this;void 0===n&&(n=!1);var o=this._scene,s=this._scene.getEngine(),a=null!==s.getCaps().instancedArrays&&null!==i.visibleInstances[t._id]&&void 0!==i.visibleInstances[t._id];if(this.isReady(t,a)){var h=t.getRenderingMesh(),c=t.getMaterial();if(s.enableEffect(this._effect),this._effect.setFloat("offset",n?0:h.outlineWidth),this._effect.setColor4("color",n?h.overlayColor:h.outlineColor,n?h.overlayAlpha:1),this._effect.setMatrix("viewProjection",o.getTransformMatrix()),h.useBones&&h.computeBonesUsingShaders&&this._effect.setMatrices("mBones",h.skeleton.getTransformMatrices(h)),h._bind(t,this._effect,e.Material.TriangleFillMode),c&&c.needAlphaTesting()){var l=c.getAlphaTestTexture();this._effect.setTexture("diffuseSampler",l),this._effect.setMatrix("diffuseMatrix",l.getTextureMatrix())}h._processRendering(t,this._effect,e.Material.TriangleFillMode,i,a,function(e,t){r._effect.setMatrix("world",t)})}},t.prototype.isReady=function(t,i){var n=[],r=[e.VertexBuffer.PositionKind,e.VertexBuffer.NormalKind],o=t.getMesh(),s=t.getMaterial();s&&s.needAlphaTesting()&&(n.push("#define ALPHATEST"),o.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(r.push(e.VertexBuffer.UVKind),n.push("#define UV1")),o.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(r.push(e.VertexBuffer.UV2Kind),n.push("#define UV2"))),o.useBones&&o.computeBonesUsingShaders?(r.push(e.VertexBuffer.MatricesIndicesKind),r.push(e.VertexBuffer.MatricesWeightsKind),o.numBoneInfluencers>4&&(r.push(e.VertexBuffer.MatricesIndicesExtraKind),r.push(e.VertexBuffer.MatricesWeightsExtraKind)),n.push("#define NUM_BONE_INFLUENCERS "+o.numBoneInfluencers),n.push("#define BonesPerMesh "+(o.skeleton.bones.length+1))):n.push("#define NUM_BONE_INFLUENCERS 0"),i&&(n.push("#define INSTANCES"),r.push("world0"),r.push("world1"),r.push("world2"),r.push("world3"));var a=n.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("outline",r,["world","mBones","viewProjection","diffuseMatrix","offset","color"],["diffuseSampler"],a)),this._effect.isReady()},t}();e.OutlineRenderer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i,n){this.name=e,this.meshesNames=t,this.rootUrl=i,this.sceneFilename=n,this.isCompleted=!1}return t.prototype.run=function(t,i,n){var r=this;e.SceneLoader.ImportMesh(this.meshesNames,this.rootUrl,this.sceneFilename,t,function(e,t,n){r.loadedMeshes=e,r.loadedParticleSystems=t,r.loadedSkeletons=n,r.isCompleted=!0,r.onSuccess&&r.onSuccess(r),i()},null,function(){r.onError&&r.onError(r),n()})},t}();e.MeshAssetTask=t;var i=function(){function t(e,t){this.name=e,this.url=t,this.isCompleted=!1}return t.prototype.run=function(t,i,n){var r=this;e.Tools.LoadFile(this.url,function(e){r.text=e,r.isCompleted=!0,r.onSuccess&&r.onSuccess(r),i()},null,t.database,!1,function(){r.onError&&r.onError(r),n()})},t}();e.TextFileAssetTask=i;var n=function(){function t(e,t){this.name=e,this.url=t,this.isCompleted=!1}return t.prototype.run=function(t,i,n){var r=this;e.Tools.LoadFile(this.url,function(e){r.data=e,r.isCompleted=!0,r.onSuccess&&r.onSuccess(r),i()},null,t.database,!0,function(){r.onError&&r.onError(r),n()})},t}();e.BinaryFileAssetTask=n;var r=function(){function e(e,t){this.name=e,this.url=t,this.isCompleted=!1}return e.prototype.run=function(e,t,i){var n=this,r=new Image;r.onload=function(){n.image=r,n.isCompleted=!0,n.onSuccess&&n.onSuccess(n),t()},r.onerror=function(){n.onError&&n.onError(n),i()},r.src=this.url},e}();e.ImageAssetTask=r;var o=function(){function t(t,i,n,r,o){void 0===o&&(o=e.Texture.TRILINEAR_SAMPLINGMODE),this.name=t,this.url=i,this.noMipmap=n,this.invertY=r,this.samplingMode=o,this.isCompleted=!1}return t.prototype.run=function(t,i,n){var r=this,o=function(){r.isCompleted=!0,r.onSuccess&&r.onSuccess(r),i()},s=function(){r.onError&&r.onError(r),n()};this.texture=new e.Texture(this.url,t,this.noMipmap,this.invertY,this.samplingMode,o,s)},t}();e.TextureAssetTask=o;var s=function(){function s(e){this._tasks=new Array,this._waitingTasksCount=0,this.useDefaultLoadingScreen=!0,this._scene=e}return s.prototype.addMeshTask=function(e,i,n,r){var o=new t(e,i,n,r);return this._tasks.push(o),o},s.prototype.addTextFileTask=function(e,t){var n=new i(e,t);return this._tasks.push(n),n},s.prototype.addBinaryFileTask=function(e,t){var i=new n(e,t);return this._tasks.push(i),i},s.prototype.addImageTask=function(e,t){var i=new r(e,t);return this._tasks.push(i),i},s.prototype.addTextureTask=function(t,i,n,r,s){void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE);var a=new o(t,i,n,r,s);return this._tasks.push(a),a},s.prototype._decreaseWaitingTasksCount=function(){this._waitingTasksCount--,0===this._waitingTasksCount&&(this.onFinish&&this.onFinish(this._tasks),this._scene.getEngine().hideLoadingUI())},s.prototype._runTask=function(e){var t=this;e.run(this._scene,function(){t.onTaskSuccess&&t.onTaskSuccess(e),t._decreaseWaitingTasksCount()},function(){t.onTaskError&&t.onTaskError(e),t._decreaseWaitingTasksCount()})},s.prototype.reset=function(){return this._tasks=new Array,this},s.prototype.load=function(){if(this._waitingTasksCount=this._tasks.length,0===this._waitingTasksCount)return this.onFinish&&this.onFinish(this._tasks),this;this.useDefaultLoadingScreen&&this._scene.getEngine().displayLoadingUI();for(var e=0;e<this._tasks.length;e++){var t=this._tasks[e];this._runTask(t)}return this},s}();e.AssetsManager=s}(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,i=4*t/this.hScreenSize;return e.Matrix.Translation(i,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightHMatrix",{get:function(){var t=this.hScreenSize/4-this.lensSeparationDistance/2,i=4*t/this.hScreenSize;return e.Matrix.Translation(-i,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}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o){void 0===o&&(o=!0),t.call(this,i,n,r);var s=e.VRCameraMetrics.GetDefault();s.compensateDistortion=o,this.setCameraRigMode(e.Camera.RIG_MODE_VR,{vrCameraMetrics:s}),this.inputs.addVRDeviceOrientation()}return __extends(i,t),i.prototype.getTypeName=function(){return"VRDeviceOrientationFreeCamera"},i}(e.FreeCamera);e.VRDeviceOrientationFreeCamera=t;var i=function(t){function i(i,n,r,o,s,a,h){void 0===h&&(h=!0),t.call(this,i,n,r,o,s,a);var c=e.VRCameraMetrics.GetDefault();c.compensateDistortion=h,this.setCameraRigMode(e.Camera.RIG_MODE_VR,{vrCameraMetrics:c}),this.inputs.addVRDeviceOrientation()}return __extends(i,t),i.prototype.getTypeName=function(){return"VRDeviceOrientationArcRotateCamera"},i}(e.ArcRotateCamera);e.VRDeviceOrientationArcRotateCamera=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o){void 0===o&&(o=!0),t.call(this,i,n,r),this._hmdDevice=null,this._sensorDevice=null,this._cacheState=null,this._cacheQuaternion=new e.Quaternion,this._cacheRotation=e.Vector3.Zero(),this._vrEnabled=!1;var s=e.VRCameraMetrics.GetDefault();s.compensateDistortion=o,this.setCameraRigMode(e.Camera.RIG_MODE_VR,{vrCameraMetrics:s}),this._getWebVRDevices=this._getWebVRDevices.bind(this)}return __extends(i,t),i.prototype._getWebVRDevices=function(e){var t=e.length,i=0;for(this._sensorDevice=null,this._hmdDevice=null;t>i&&null===this._hmdDevice;)e[i]instanceof HMDVRDevice&&(this._hmdDevice=e[i]),i++;for(i=0;t>i&&null===this._sensorDevice;)e[i]instanceof PositionSensorVRDevice&&(!this._hmdDevice||e[i].hardwareUnitId===this._hmdDevice.hardwareUnitId)&&(this._sensorDevice=e[i]),i++;this._vrEnabled=!(!this._sensorDevice||!this._hmdDevice)},i.prototype._checkInputs=function(){this._vrEnabled&&(this._cacheState=this._sensorDevice.getState(),this._cacheQuaternion.copyFromFloats(this._cacheState.orientation.x,this._cacheState.orientation.y,this._cacheState.orientation.z,this._cacheState.orientation.w),this._cacheQuaternion.toEulerAnglesToRef(this._cacheRotation),this.rotation.x=-this._cacheRotation.x,this.rotation.y=-this._cacheRotation.y,this.rotation.z=this._cacheRotation.z),t.prototype._checkInputs.call(this)},i.prototype.attachControl=function(i,n){t.prototype.attachControl.call(this,i,n),n=e.Camera.ForceAttachControlToAlwaysPreventDefault?!1:n,navigator.getVRDevices?navigator.getVRDevices().then(this._getWebVRDevices):navigator.mozGetVRDevices&&navigator.mozGetVRDevices(this._getWebVRDevices)},i.prototype.detachControl=function(e){t.prototype.detachControl.call(this,e),this._vrEnabled=!1},i.prototype.getTypeName=function(){return"WebVRFreeCamera"},i}(e.FreeCamera);e.WebVRFreeCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){void 0===e&&(e=0),this.priority=e,this.apply=function(e){return!0}}return e}();e.SceneOptimization=t;var i=function(e){function t(t,i){var n=this;void 0===t&&(t=0),void 0===i&&(i=1024),e.call(this,t),this.priority=t,this.maximumSize=i,this.apply=function(e){for(var t=!0,i=0;i<e.textures.length;i++){var r=e.textures[i];if(r.canRescale){var o=r.getSize(),s=Math.max(o.width,o.height);s>n.maximumSize&&(r.scale(.5),t=!1)}}return t}}return __extends(t,e),t}(t);e.TextureOptimization=i;var n=function(e){function t(t,i){var n=this;void 0===t&&(t=0),void 0===i&&(i=2),e.call(this,t),this.priority=t,this.maximumScale=i,this._currentScale=1,this.apply=function(e){return n._currentScale++,e.getEngine().setHardwareScalingLevel(n._currentScale),n._currentScale>=n.maximumScale}}return __extends(t,e),t}(t);e.HardwareScalingOptimization=n;var r=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.shadowsEnabled=!1,!0}}return __extends(t,e),t}(t);e.ShadowsOptimization=r;var o=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.postProcessesEnabled=!1,!0}}return __extends(t,e),t}(t);e.PostProcessesOptimization=o;var s=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.lensFlaresEnabled=!1,!0}}return __extends(t,e),t}(t);e.LensFlaresOptimization=s;var a=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.particlesEnabled=!1,!0}}return __extends(t,e),t}(t);e.ParticlesOptimization=a;var h=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.renderTargetsEnabled=!1,!0}}return __extends(t,e),t}(t);e.RenderTargetsOptimization=h;var c=function(t){function i(){var n=this;t.apply(this,arguments),this._canBeMerged=function(t){if(!(t instanceof e.Mesh))return!1;var i=t;return i.isVisible&&i.isEnabled()?i.instances.length>0?!1:i.skeleton||i.hasLODLevels?!1:!i.parent:!1},this.apply=function(t,r){for(var o=t.meshes.slice(0),s=o.length,a=0;s>a;a++){var h=new Array,c=o[a];if(n._canBeMerged(c)){h.push(c);for(var l=a+1;s>l;l++){var u=o[l];n._canBeMerged(u)&&u.material===c.material&&u.checkCollisions===c.checkCollisions&&(h.push(u),s--,o.splice(l,1),l--)}h.length<2||e.Mesh.MergeMeshes(h)}}return void 0!=r?r&&t.createOrUpdateSelectionOctree():i.UpdateSelectionTree&&t.createOrUpdateSelectionOctree(),!0}}return __extends(i,t),Object.defineProperty(i,"UpdateSelectionTree",{get:function(){return i._UpdateSelectionTree},set:function(e){i._UpdateSelectionTree=e},enumerable:!0,configurable:!0}),i._UpdateSelectionTree=!1,i}(t);e.MergeMeshesOptimization=c;var l=function(){function e(e,t){void 0===e&&(e=60),void 0===t&&(t=2e3),this.targetFrameRate=e,this.trackerDuration=t,this.optimizations=new Array}return e.LowDegradationAllowed=function(t){var n=new e(t),h=0;return n.optimizations.push(new c(h)),n.optimizations.push(new r(h)),n.optimizations.push(new s(h)),h++,n.optimizations.push(new o(h)),n.optimizations.push(new a(h)),h++,n.optimizations.push(new i(h,1024)),n},e.ModerateDegradationAllowed=function(t){var l=new e(t),u=0;return l.optimizations.push(new c(u)),l.optimizations.push(new r(u)),l.optimizations.push(new s(u)),u++,l.optimizations.push(new o(u)),l.optimizations.push(new a(u)),u++,l.optimizations.push(new i(u,512)),u++,l.optimizations.push(new h(u)),u++,l.optimizations.push(new n(u,2)),l},e.HighDegradationAllowed=function(t){var l=new e(t),u=0;return l.optimizations.push(new c(u)),l.optimizations.push(new r(u)),l.optimizations.push(new s(u)),u++,l.optimizations.push(new o(u)),l.optimizations.push(new a(u)),u++,l.optimizations.push(new i(u,256)),u++,l.optimizations.push(new h(u)),u++,l.optimizations.push(new n(u,4)),l},e}();e.SceneOptimizerOptions=l;var u=function(){function e(){}return e._CheckCurrentState=function(t,i,n,r,o){if(t.getEngine().getFps()>=i.targetFrameRate)return void(r&&r());for(var s=!0,a=!0,h=0;h<i.optimizations.length;h++){var c=i.optimizations[h];c.priority===n&&(a=!1,s=s&&c.apply(t))}return a?void(o&&o()):(s&&n++,void t.executeWhenReady(function(){setTimeout(function(){e._CheckCurrentState(t,i,n,r,o)},i.trackerDuration)}))},e.OptimizeAsync=function(t,i,n,r){i||(i=l.ModerateDegradationAllowed()),t.executeWhenReady(function(){setTimeout(function(){e._CheckCurrentState(t,i,0,n,r)},i.trackerDuration)})},e}();e.SceneOptimizer=u}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(e){var t=function(){function e(e,t){this.distance=e,this.mesh=t}return e}();e.MeshLODLevel=t}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s,a,h,c){void 0===a&&(a=!0),void 0===h&&(h=!1),void 0===c&&(c=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,s,!a,h),this.format=o,this._texture=s.getEngine().createRawTexture(i,n,r,o,a,h,c),this.wrapU=e.Texture.CLAMP_ADDRESSMODE,this.wrapV=e.Texture.CLAMP_ADDRESSMODE}return __extends(i,t),i.prototype.update=function(e){this.getScene().getEngine().updateRawTexture(this._texture,e,this.format,this._invertY)},i.CreateLuminanceTexture=function(t,n,r,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,n,r,e.Engine.TEXTUREFORMAT_LUMINANCE,o,s,a,h)},i.CreateLuminanceAlphaTexture=function(t,n,r,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,n,r,e.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA,o,s,a,h)},i.CreateAlphaTexture=function(t,n,r,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,n,r,e.Engine.TEXTUREFORMAT_ALPHA,o,s,a,h)},i.CreateRGBTexture=function(t,n,r,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,n,r,e.Engine.TEXTUREFORMAT_RGB,o,s,a,h)},i.CreateRGBATexture=function(t,n,r,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,n,r,e.Engine.TEXTUREFORMAT_RGBA,o,s,a,h)},i}(e.Texture);e.RawTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i){e.call(this,t.x,t.y),this.index=i}return __extends(t,e),t}(e.Vector2),i=function(){function i(){this.elements=new Array}return i.prototype.add=function(e){var i=this,n=new Array;return e.forEach(function(e){if(0===n.length||!e.equalsWithEpsilon(n[0])){var r=new t(e,i.elements.length);n.push(r),i.elements.push(r)}}),n},i.prototype.computeBounds=function(){var t=new e.Vector2(this.elements[0].x,this.elements[0].y),i=new e.Vector2(this.elements[0].x,this.elements[0].y);return this.elements.forEach(function(e){e.x<t.x?t.x=e.x:e.x>i.x&&(i.x=e.x),e.y<t.y?t.y=e.y:e.y>i.y&&(i.y=e.y)}),{min:t,max:i,width:i.x-t.x,height:i.y-t.y}},i}(),n=function(){function t(){}return t.Rectangle=function(t,i,n,r){return[new e.Vector2(t,i),new e.Vector2(n,i),new e.Vector2(n,r),new e.Vector2(t,r)]},t.Circle=function(t,i,n,r){void 0===i&&(i=0),void 0===n&&(n=0),void 0===r&&(r=32);for(var o=new Array,s=0,a=2*Math.PI/r,h=0;r>h;h++)o.push(new e.Vector2(i+Math.cos(s)*t,n+Math.sin(s)*t)),s-=a;return o},t.Parse=function(t){var i,n=t.split(/[^-+eE\.\d]+/).map(parseFloat).filter(function(e){return!isNaN(e)}),r=[];for(i=0;i<(2147483646&n.length);i+=2)r.push(new e.Vector2(n[i],n[i+1]));return r},t.StartingAt=function(t,i){return e.Path2.StartingAt(t,i)},t}();e.Polygon=n;var r=function(){function t(t,n,r){if(this._points=new i,this._outlinepoints=new i,this._holes=[],!("poly2tri"in window))throw"PolygonMeshBuilder cannot be used because poly2tri is not referenced";this._name=t,this._scene=r;var o;o=n instanceof e.Path2?n.getPoints():n,this._swctx=new poly2tri.SweepContext(this._points.add(o)),this._outlinepoints.add(o)}return t.prototype.addHole=function(e){this._swctx.addHole(this._points.add(e));var t=new i;return t.add(e),this._holes.push(t),this},t.prototype.build=function(t,i){var n=this;void 0===t&&(t=!1);var r=new e.Mesh(this._name,this._scene),o=[],s=[],a=[],h=this._points.computeBounds();this._points.elements.forEach(function(e){o.push(0,1,0),s.push(e.x,0,e.y),a.push((e.x-h.min.x)/h.width,(e.y-h.min.y)/h.height)});var c=[];if(this._swctx.triangulate(),this._swctx.getTriangles().forEach(function(e){e.getPoints().forEach(function(e){c.push(e.index)})}),i>0){var l=s.length/3;this._points.elements.forEach(function(e){o.push(0,-1,0),s.push(e.x,-i,e.y),a.push(1-(e.x-h.min.x)/h.width,1-(e.y-h.min.y)/h.height)});var u,d,f=0;this._swctx.getTriangles().forEach(function(e){e.getPoints().forEach(function(e){switch(f){case 0:u=e;break;case 1:d=e;break;case 2:c.push(e.index+l),c.push(d.index+l),c.push(u.index+l),f=-1}f++})}),this.addSide(s,o,a,c,h,this._outlinepoints,i,!1),this._holes.forEach(function(e){n.addSide(s,o,a,c,h,e,i,!0)})}return r.setVerticesData(e.VertexBuffer.PositionKind,s,t),r.setVerticesData(e.VertexBuffer.NormalKind,o,t),r.setVerticesData(e.VertexBuffer.UVKind,a,t),r.setIndices(c),r},t.prototype.addSide=function(t,i,n,r,o,s,a,h){for(var c=t.length/3,l=0,u=0;u<s.elements.length;u++){var d,f=s.elements[u];d=u+1>s.elements.length-1?s.elements[0]:s.elements[u+1],t.push(f.x,0,f.y),t.push(f.x,-a,f.y),t.push(d.x,0,d.y),t.push(d.x,-a,d.y);var p=new e.Vector3(f.x,0,f.y),m=new e.Vector3(d.x,0,d.y),_=m.subtract(p),g=new e.Vector3(0,1,0),v=e.Vector3.Cross(_,g);v=v.normalize(),n.push(l/o.width,0),n.push(l/o.width,1),l+=_.length(),n.push(l/o.width,0),n.push(l/o.width,1),h?(i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),r.push(c),r.push(c+2),r.push(c+1),r.push(c+1),r.push(c+2),r.push(c+3)):(i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),r.push(c),r.push(c+1),r.push(c+2),r.push(c+1),r.push(c+3),r.push(c+2)),c+=4}},t}();e.PolygonMeshBuilder=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,n){void 0===n&&(n=2),this.maxDepth=n,this.dynamicContent=new Array,this._maxBlockCapacity=i||64,this._selectionContent=new e.SmartArray(1024),this._creationFunc=t}return t.prototype.update=function(e,i,n){t._CreateBlocks(e,i,n,this._maxBlockCapacity,0,this.maxDepth,this,this._creationFunc)},t.prototype.addMesh=function(e){for(var t=0;t<this.blocks.length;t++){var i=this.blocks[t];i.addEntry(e)}},t.prototype.select=function(e,t){this._selectionContent.reset();for(var i=0;i<this.blocks.length;i++){var n=this.blocks[i];n.select(e,this._selectionContent,t)}return t?this._selectionContent.concat(this.dynamicContent):this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},t.prototype.intersects=function(e,t,i){this._selectionContent.reset();for(var n=0;n<this.blocks.length;n++){var r=this.blocks[n];r.intersects(e,t,this._selectionContent,i)}return i?this._selectionContent.concat(this.dynamicContent):this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},t.prototype.intersectsRay=function(e){this._selectionContent.reset();for(var t=0;t<this.blocks.length;t++){var i=this.blocks[t];i.intersectsRay(e,this._selectionContent)}return this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},t._CreateBlocks=function(t,i,n,r,o,s,a,h){a.blocks=new Array;for(var c=new e.Vector3((i.x-t.x)/2,(i.y-t.y)/2,(i.z-t.z)/2),l=0;2>l;l++)for(var u=0;2>u;u++)for(var d=0;2>d;d++){var f=t.add(c.multiplyByFloats(l,u,d)),p=t.add(c.multiplyByFloats(l+1,u+1,d+1)),m=new e.OctreeBlock(f,p,r,o+1,s,h);m.addEntries(n),a.blocks.push(m)}},t.CreationFuncForMeshes=function(e,t){!e.isBlocked&&e.getBoundingInfo().boundingBox.intersectsMinMax(t.minPoint,t.maxPoint)&&t.entries.push(e)},t.CreationFuncForSubMeshes=function(e,t){e.getBoundingInfo().boundingBox.intersectsMinMax(t.minPoint,t.maxPoint)&&t.entries.push(e)},t}();e.Octree=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i,n,r,o){this.entries=new Array,this._boundingVectors=new Array,this._capacity=i,this._depth=n,this._maxDepth=r,this._creationFunc=o,this._minPoint=e,this._maxPoint=t,this._boundingVectors.push(e.clone()),this._boundingVectors.push(t.clone()),this._boundingVectors.push(e.clone()),this._boundingVectors[2].x=t.x,this._boundingVectors.push(e.clone()),this._boundingVectors[3].y=t.y,this._boundingVectors.push(e.clone()),this._boundingVectors[4].z=t.z,this._boundingVectors.push(t.clone()),this._boundingVectors[5].z=e.z,this._boundingVectors.push(t.clone()),this._boundingVectors[6].x=e.x,this._boundingVectors.push(t.clone()),this._boundingVectors[7].y=e.y}return Object.defineProperty(t.prototype,"capacity",{get:function(){return this._capacity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"minPoint",{get:function(){return this._minPoint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxPoint",{get:function(){return this._maxPoint},enumerable:!0,configurable:!0}),t.prototype.addEntry=function(e){if(this.blocks)for(var t=0;t<this.blocks.length;t++){var i=this.blocks[t];i.addEntry(e)}else this._creationFunc(e,this),this.entries.length>this.capacity&&this._depth<this._maxDepth&&this.createInnerBlocks()},t.prototype.addEntries=function(e){for(var t=0;t<e.length;t++){var i=e[t];this.addEntry(i)}},t.prototype.select=function(t,i,n){if(e.BoundingBox.IsInFrustum(this._boundingVectors,t)){if(this.blocks){for(var r=0;r<this.blocks.length;r++){var o=this.blocks[r];o.select(t,i,n)}return}n?i.concat(this.entries):i.concatWithNoDuplicate(this.entries)}},t.prototype.intersects=function(t,i,n,r){if(e.BoundingBox.IntersectsSphere(this._minPoint,this._maxPoint,t,i)){if(this.blocks){for(var o=0;o<this.blocks.length;o++){var s=this.blocks[o];s.intersects(t,i,n,r)}return}r?n.concat(this.entries):n.concatWithNoDuplicate(this.entries)}},t.prototype.intersectsRay=function(e,t){if(e.intersectsBoxMinMax(this._minPoint,this._maxPoint)){if(this.blocks){for(var i=0;i<this.blocks.length;i++){var n=this.blocks[i];n.intersectsRay(e,t)}return}t.concatWithNoDuplicate(this.entries)}},t.prototype.createInnerBlocks=function(){e.Octree._CreateBlocks(this._minPoint,this._maxPoint,this.entries,this._capacity,this._depth,this._maxDepth,this,this._creationFunc)},t}();e.OctreeBlock=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s,a,h,c){var l=this;void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE),t.call(this,i,"blur",["screenSize","direction","blurWidth"],null,o,s,a,h,c),this.direction=n,this.blurWidth=r,this.onApply=function(e){e.setFloat2("screenSize",l.width,l.height),e.setVector2("direction",l.direction),e.setFloat("blurWidth",l.blurWidth)}}return __extends(i,t),i}(e.PostProcess);e.BlurPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s,a,h,c,l,u){var d=this;t.call(this,i,"refraction",["baseColor","depth","colorLevel"],["refractionSampler"],a,h,c,l,u),this.color=r,this.depth=o,this.colorLevel=s,this.onActivate=function(t){d._refRexture=d._refRexture||new e.Texture(n,t.getScene())},this.onApply=function(e){e.setColor3("baseColor",d.color),e.setFloat("depth",d.depth),e.setFloat("colorLevel",d.colorLevel),e.setTexture("refractionSampler",d._refRexture)}}return __extends(i,t),i.prototype.dispose=function(e){this._refRexture&&this._refRexture.dispose(),t.prototype.dispose.call(this,e)},i}(e.PostProcess);e.RefractionPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n,r,o,s){e.call(this,t,"blackAndWhite",null,null,i,n,r,o,s)}return __extends(t,e),t}(e.PostProcess);e.BlackAndWhitePostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n,r,o,s,a){var h=this;e.call(this,t,"convolution",["kernel","screenSize"],null,n,r,o,s,a),this.kernel=i,this.onApply=function(e){e.setFloat2("screenSize",h.width,h.height),e.setArray("kernel",h.kernel)}}return __extends(t,e),t.EdgeDetect0Kernel=[1,0,-1,0,0,0,-1,0,1],t.EdgeDetect1Kernel=[0,1,0,1,-4,1,0,1,0],t.EdgeDetect2Kernel=[-1,-1,-1,-1,8,-1,-1,-1,-1],t.SharpenKernel=[0,-1,0,-1,5,-1,0,-1,0],t.EmbossKernel=[-2,-1,0,-1,1,1,0,1,2],t.GaussianKernel=[0,1,0,1,1,1,0,1,0],t}(e.PostProcess);e.ConvolutionPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n,r,o,s,a){var h=this;e.call(this,t,"filter",["kernelMatrix"],null,n,r,o,s,a),this.kernelMatrix=i,this.onApply=function(e){e.setMatrix("kernelMatrix",h.kernelMatrix)}}return __extends(t,e),t}(e.PostProcess);e.FilterPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n,r,o,s){
  25. var a=this;e.call(this,t,"fxaa",["texelSize"],null,i,n,r,o,s),this.onSizeChanged=function(){a.texelWidth=1/a.width,a.texelHeight=1/a.height},this.onApply=function(e){e.setFloat2("texelSize",a.texelWidth,a.texelHeight)}}return __extends(t,e),t}(e.PostProcess);e.FxaaPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s){var a=this;t.call(this,i,"stereoscopicInterlace",["stepSize"],["camASampler"],1,n,s,n.getScene().getEngine(),!1,o?"#define IS_STEREOSCOPIC_HORIZ 1":void 0),this._stepSize=new e.Vector2(1/this.width,1/this.height),this.onSizeChanged=function(){a._stepSize=new e.Vector2(1/a.width,1/a.height)},this.onApply=function(e){e.setTextureFromPostProcess("camASampler",r),e.setFloat2("stepSize",a._stepSize.x,a._stepSize.y)}}return __extends(i,t),i}(e.PostProcess);e.StereoscopicInterlacePostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,n,r,o){this.size=t,this.position=i,this.dispose=function(){this.texture&&this.texture.dispose();var e=this._system.lensFlares.indexOf(this);this._system.lensFlares.splice(e,1)},this.color=n||new e.Color3(1,1,1),this.texture=r?new e.Texture(r,o.getScene(),!0):null,this._system=o,o.lensFlares.push(this)}return t}();e.LensFlare=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i){this.name=e,this.lensFlares=new Array,this.borderLimit=300,this.layerMask=268435455,this._vertexDeclaration=[2],this._vertexStrideSize=8,this._isEnabled=!0,this._scene=i,this._emitter=t,this.id=e,i.lensFlareSystems.push(this),this.meshesSelectionPredicate=function(e){return e.material&&e.isVisible&&e.isEnabled()&&e.isBlocker&&0!=(e.layerMask&i.activeCamera.layerMask)};var n=[];n.push(1,1),n.push(-1,1),n.push(-1,-1),n.push(1,-1),this._vertexBuffer=i.getEngine().createVertexBuffer(n);var r=[];r.push(0),r.push(1),r.push(2),r.push(0),r.push(2),r.push(3),this._indexBuffer=i.getEngine().createIndexBuffer(r),this._effect=this._scene.getEngine().createEffect("lensFlare",["position"],["color","viewportMatrix"],["textureSampler"],"")}return Object.defineProperty(t.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(e){this._isEnabled=e},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},t.prototype.getEmitter=function(){return this._emitter},t.prototype.setEmitter=function(e){this._emitter=e},t.prototype.getEmitterPosition=function(){return this._emitter.getAbsolutePosition?this._emitter.getAbsolutePosition():this._emitter.position},t.prototype.computeEffectivePosition=function(t){var i=this.getEmitterPosition();return i=e.Vector3.Project(i,e.Matrix.Identity(),this._scene.getTransformMatrix(),t),this._positionX=i.x,this._positionY=i.y,i=e.Vector3.TransformCoordinates(this.getEmitterPosition(),this._scene.getViewMatrix()),i.z>0&&this._positionX>t.x&&this._positionX<t.x+t.width&&this._positionY>t.y&&this._positionY<t.y+t.height},t.prototype._isVisible=function(){if(!this._isEnabled)return!1;var t=this.getEmitterPosition(),i=t.subtract(this._scene.activeCamera.position),n=i.length();i.normalize();var r=new e.Ray(this._scene.activeCamera.position,i),o=this._scene.pickWithRay(r,this.meshesSelectionPredicate,!0);return!o.hit||o.distance>n},t.prototype.render=function(){if(!this._effect.isReady())return!1;var t=this._scene.getEngine(),i=this._scene.activeCamera.viewport,n=i.toGlobal(t.getRenderWidth(!0),t.getRenderHeight(!0));if(!this.computeEffectivePosition(n))return!1;if(!this._isVisible())return!1;var r,o;r=this._positionX<this.borderLimit+n.x?this.borderLimit+n.x-this._positionX:this._positionX>n.x+n.width-this.borderLimit?this._positionX-n.x-n.width+this.borderLimit:0,o=this._positionY<this.borderLimit+n.y?this.borderLimit+n.y-this._positionY:this._positionY>n.y+n.height-this.borderLimit?this._positionY-n.y-n.height+this.borderLimit:0;var s=r>o?r:o;s>this.borderLimit&&(s=this.borderLimit);var a=1-s/this.borderLimit;if(0>a)return!1;a>1&&(a=1);var h=n.x+n.width/2,c=n.y+n.height/2,l=h-this._positionX,u=c-this._positionY;t.enableEffect(this._effect),t.setState(!1),t.setDepthBuffer(!1),t.setAlphaMode(e.Engine.ALPHA_ONEONE),t.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,this._effect);for(var d=0;d<this.lensFlares.length;d++){var f=this.lensFlares[d],p=h-l*f.position,m=c-u*f.position,_=f.size,g=f.size*t.getAspectRatio(this._scene.activeCamera,!0),v=2*(p/n.width)-1,y=1-2*(m/n.height),x=e.Matrix.FromValues(_/2,0,0,0,0,g/2,0,0,0,0,1,0,v,y,0,1);this._effect.setMatrix("viewportMatrix",x),this._effect.setTexture("textureSampler",f.texture),this._effect.setFloat4("color",f.color.r*a,f.color.g*a,f.color.b*a,1),t.draw(!0,0,6)}return t.setDepthBuffer(!0),t.setAlphaMode(e.Engine.ALPHA_DISABLE),!0},t.prototype.dispose=function(){for(this._vertexBuffer&&(this._scene.getEngine()._releaseBuffer(this._vertexBuffer),this._vertexBuffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null);this.lensFlares.length;)this.lensFlares[0].dispose();var e=this._scene.lensFlareSystems.indexOf(this);this._scene.lensFlareSystems.splice(e,1)},t.Parse=function(i,n,r){var o=n.getLastEntryByID(i.emitterId),s=i.name||"lensFlareSystem#"+i.emitterId,a=new t(s,o,n);a.id=i.id||s,a.borderLimit=i.borderLimit;for(var h=0;h<i.flares.length;h++){var c=i.flares[h];new e.LensFlare(c.size,c.position,e.Color3.FromArray(c.color),r+c.textureName,a)}return a},t.prototype.serialize=function(){var t={};t.id=this.id,t.name=this.name,t.emitterId=this.getEmitter().id,t.borderLimit=this.borderLimit,t.flares=[];for(var i=0;i<this.lensFlares.length;i++){var n=this.lensFlares[i];t.flares.push({size:n.size,position:n.position,color:n.color.asArray(),textureName:e.Tools.GetFilename(n.texture.name)})}return t},t}();e.LensFlareSystem=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n){e.call(this,t,i,n),this.inputs.addDeviceOrientation()}return __extends(t,e),Object.defineProperty(t.prototype,"angularSensibility",{get:function(){var e=this.inputs.attached.deviceOrientation;return e?e.angularSensibility:void 0},set:function(e){var t=this.inputs.attached.deviceOrientation;t&&(t.angularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"moveSensibility",{get:function(){var e=this.inputs.attached.deviceOrientation;return e?e.moveSensibility:void 0},set:function(e){var t=this.inputs.attached.deviceOrientation;t&&(t.moveSensibility=e)},enumerable:!0,configurable:!0}),t.prototype.getTypeName=function(){return"DeviceOrientationCamera"},t}(e.FreeCamera);e.DeviceOrientationCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,n){e.call(this,t,i,n),this.inputs.addGamepad()}return __extends(t,e),Object.defineProperty(t.prototype,"gamepadAngularSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadAngularSensibility:void 0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadAngularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"gamepadMoveSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadMoveSensibility:void 0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadMoveSensibility=e)},enumerable:!0,configurable:!0}),t.prototype.getTypeName=function(){return"UniversalCamera"},t}(e.TouchCamera);e.UniversalCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){var t=this;this.babylonGamepads=[],this.oneGamepadConnected=!1,this.isMonitoring=!1,this.gamepadEventSupported="GamepadEvent"in window,this.gamepadSupportAvailable=navigator.getGamepads||!!navigator.webkitGetGamepads||!!navigator.msGetGamepads||!!navigator.webkitGamepads,this._callbackGamepadConnected=e,this.gamepadSupportAvailable&&(this.gamepadEventSupported?(this._onGamepadConnectedEvent=function(e){t._onGamepadConnected(e)},this._onGamepadDisonnectedEvent=function(e){t._onGamepadDisconnected(e)},window.addEventListener("gamepadconnected",this._onGamepadConnectedEvent,!1),window.addEventListener("gamepaddisconnected",this._onGamepadDisonnectedEvent,!1)):this._startMonitoringGamepads())}return e.prototype.dispose=function(){e.gamepadDOMInfo&&document.body.removeChild(e.gamepadDOMInfo),this._onGamepadConnectedEvent&&(window.removeEventListener("gamepadconnected",this._onGamepadConnectedEvent,!1),window.removeEventListener("gamepaddisconnected",this._onGamepadDisonnectedEvent,!1),this._onGamepadConnectedEvent=null,this._onGamepadDisonnectedEvent=null)},e.prototype._onGamepadConnected=function(e){var t=this._addNewGamepad(e.gamepad);this._callbackGamepadConnected&&this._callbackGamepadConnected(t),this._startMonitoringGamepads()},e.prototype._addNewGamepad=function(t){this.oneGamepadConnected||(this.oneGamepadConnected=!0,e.gamepadDOMInfo&&(document.body.removeChild(e.gamepadDOMInfo),e.gamepadDOMInfo=null));var i;return i=-1!==t.id.search("Xbox 360")||-1!==t.id.search("xinput")?new a(t.id,t.index,t):new r(t.id,t.index,t),this.babylonGamepads.push(i),i},e.prototype._onGamepadDisconnected=function(e){for(var t in this.babylonGamepads)if(this.babylonGamepads[t].index==e.gamepad.index){this.babylonGamepads.splice(+t,1);break}0==this.babylonGamepads.length&&this._stopMonitoringGamepads()},e.prototype._startMonitoringGamepads=function(){this.isMonitoring||(this.isMonitoring=!0,this._checkGamepadsStatus())},e.prototype._stopMonitoringGamepads=function(){this.isMonitoring=!1},e.prototype._checkGamepadsStatus=function(){var e=this;this._updateGamepadObjects();for(var t in this.babylonGamepads)this.babylonGamepads[t].update();this.isMonitoring&&(window.requestAnimationFrame?window.requestAnimationFrame(function(){e._checkGamepadsStatus()}):window.mozRequestAnimationFrame?window.mozRequestAnimationFrame(function(){e._checkGamepadsStatus()}):window.webkitRequestAnimationFrame&&window.webkitRequestAnimationFrame(function(){e._checkGamepadsStatus()}))},e.prototype._updateGamepadObjects=function(){for(var e=navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads():[],t=0;t<e.length;t++)if(e[t])if(e[t].index in this.babylonGamepads)this.babylonGamepads[t].browserGamepad=e[t];else{var i=this._addNewGamepad(e[t]);this._callbackGamepadConnected&&this._callbackGamepadConnected(i)}},e}();e.Gamepads=t;var i=function(){function e(e,t){this.x=e,this.y=t}return e}();e.StickValues=i;var n=function(){function e(e,t,i){this.id=e,this.index=t,this.browserGamepad=i,this.browserGamepad.axes.length>=2&&(this._leftStick={x:this.browserGamepad.axes[0],y:this.browserGamepad.axes[1]}),this.browserGamepad.axes.length>=4&&(this._rightStick={x:this.browserGamepad.axes[2],y:this.browserGamepad.axes[3]})}return e.prototype.onleftstickchanged=function(e){this._onleftstickchanged=e},e.prototype.onrightstickchanged=function(e){this._onrightstickchanged=e},Object.defineProperty(e.prototype,"leftStick",{get:function(){return this._leftStick},set:function(e){!this._onleftstickchanged||this._leftStick.x===e.x&&this._leftStick.y===e.y||this._onleftstickchanged(e),this._leftStick=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rightStick",{get:function(){return this._rightStick},set:function(e){!this._onrightstickchanged||this._rightStick.x===e.x&&this._rightStick.y===e.y||this._onrightstickchanged(e),this._rightStick=e},enumerable:!0,configurable:!0}),e.prototype.update=function(){this._leftStick&&(this.leftStick={x:this.browserGamepad.axes[0],y:this.browserGamepad.axes[1]}),this._rightStick&&(this.rightStick={x:this.browserGamepad.axes[2],y:this.browserGamepad.axes[3]})},e}();e.Gamepad=n;var r=function(e){function t(t,i,n){e.call(this,t,i,n),this.id=t,this.index=i,this.gamepad=n,this._buttons=new Array(n.buttons.length)}return __extends(t,e),t.prototype.onbuttondown=function(e){this._onbuttondown=e},t.prototype.onbuttonup=function(e){this._onbuttonup=e},t.prototype._setButtonValue=function(e,t,i){return e!==t&&(this._onbuttondown&&1===e&&this._onbuttondown(i),this._onbuttonup&&0===e&&this._onbuttonup(i)),e},t.prototype.update=function(){e.prototype.update.call(this);for(var t=0;t<this._buttons.length;t++)this._buttons[t]=this._setButtonValue(this.gamepad.buttons[t].value,this._buttons[t],t)},t}(n);e.GenericPad=r,function(e){e[e.A=0]="A",e[e.B=1]="B",e[e.X=2]="X",e[e.Y=3]="Y",e[e.Start=4]="Start",e[e.Back=5]="Back",e[e.LB=6]="LB",e[e.RB=7]="RB",e[e.LeftStick=8]="LeftStick",e[e.RightStick=9]="RightStick"}(e.Xbox360Button||(e.Xbox360Button={}));var o=e.Xbox360Button;!function(e){e[e.Up=0]="Up",e[e.Down=1]="Down",e[e.Left=2]="Left",e[e.Right=3]="Right"}(e.Xbox360Dpad||(e.Xbox360Dpad={}));var s=e.Xbox360Dpad,a=function(e){function t(){e.apply(this,arguments),this._leftTrigger=0,this._rightTrigger=0,this._buttonA=0,this._buttonB=0,this._buttonX=0,this._buttonY=0,this._buttonBack=0,this._buttonStart=0,this._buttonLB=0,this._buttonRB=0,this._buttonLeftStick=0,this._buttonRightStick=0,this._dPadUp=0,this._dPadDown=0,this._dPadLeft=0,this._dPadRight=0}return __extends(t,e),t.prototype.onlefttriggerchanged=function(e){this._onlefttriggerchanged=e},t.prototype.onrighttriggerchanged=function(e){this._onrighttriggerchanged=e},Object.defineProperty(t.prototype,"leftTrigger",{get:function(){return this._leftTrigger},set:function(e){this._onlefttriggerchanged&&this._leftTrigger!==e&&this._onlefttriggerchanged(e),this._leftTrigger=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightTrigger",{get:function(){return this._rightTrigger},set:function(e){this._onrighttriggerchanged&&this._rightTrigger!==e&&this._onrighttriggerchanged(e),this._rightTrigger=e},enumerable:!0,configurable:!0}),t.prototype.onbuttondown=function(e){this._onbuttondown=e},t.prototype.onbuttonup=function(e){this._onbuttonup=e},t.prototype.ondpaddown=function(e){this._ondpaddown=e},t.prototype.ondpadup=function(e){this._ondpadup=e},t.prototype._setButtonValue=function(e,t,i){return e!==t&&(this._onbuttondown&&1===e&&this._onbuttondown(i),this._onbuttonup&&0===e&&this._onbuttonup(i)),e},t.prototype._setDPadValue=function(e,t,i){return e!==t&&(this._ondpaddown&&1===e&&this._ondpaddown(i),this._ondpadup&&0===e&&this._ondpadup(i)),e},Object.defineProperty(t.prototype,"buttonA",{get:function(){return this._buttonA},set:function(e){this._buttonA=this._setButtonValue(e,this._buttonA,o.A)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonB",{get:function(){return this._buttonB},set:function(e){this._buttonB=this._setButtonValue(e,this._buttonB,o.B)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonX",{get:function(){return this._buttonX},set:function(e){this._buttonX=this._setButtonValue(e,this._buttonX,o.X)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonY",{get:function(){return this._buttonY},set:function(e){this._buttonY=this._setButtonValue(e,this._buttonY,o.Y)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonStart",{get:function(){return this._buttonStart},set:function(e){this._buttonStart=this._setButtonValue(e,this._buttonStart,o.Start)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonBack",{get:function(){return this._buttonBack},set:function(e){this._buttonBack=this._setButtonValue(e,this._buttonBack,o.Back)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonLB",{get:function(){return this._buttonLB},set:function(e){this._buttonLB=this._setButtonValue(e,this._buttonLB,o.LB)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonRB",{get:function(){return this._buttonRB},set:function(e){this._buttonRB=this._setButtonValue(e,this._buttonRB,o.RB)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonLeftStick",{get:function(){return this._buttonLeftStick},set:function(e){this._buttonLeftStick=this._setButtonValue(e,this._buttonLeftStick,o.LeftStick)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonRightStick",{get:function(){return this._buttonRightStick},set:function(e){this._buttonRightStick=this._setButtonValue(e,this._buttonRightStick,o.RightStick)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dPadUp",{get:function(){return this._dPadUp},set:function(e){this._dPadUp=this._setDPadValue(e,this._dPadUp,s.Up)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dPadDown",{get:function(){return this._dPadDown},set:function(e){this._dPadDown=this._setDPadValue(e,this._dPadDown,s.Down)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dPadLeft",{get:function(){return this._dPadLeft},set:function(e){this._dPadLeft=this._setDPadValue(e,this._dPadLeft,s.Left)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dPadRight",{get:function(){return this._dPadRight},set:function(e){this._dPadRight=this._setDPadValue(e,this._dPadRight,s.Right)},enumerable:!0,configurable:!0}),t.prototype.update=function(){e.prototype.update.call(this),this.buttonA=this.browserGamepad.buttons[0].value,this.buttonB=this.browserGamepad.buttons[1].value,this.buttonX=this.browserGamepad.buttons[2].value,this.buttonY=this.browserGamepad.buttons[3].value,this.buttonLB=this.browserGamepad.buttons[4].value,this.buttonRB=this.browserGamepad.buttons[5].value,this.leftTrigger=this.browserGamepad.buttons[6].value,this.rightTrigger=this.browserGamepad.buttons[7].value,this.buttonBack=this.browserGamepad.buttons[8].value,this.buttonStart=this.browserGamepad.buttons[9].value,this.buttonLeftStick=this.browserGamepad.buttons[10].value,this.buttonRightStick=this.browserGamepad.buttons[11].value,this.dPadUp=this.browserGamepad.buttons[12].value,this.dPadDown=this.browserGamepad.buttons[13].value,this.dPadLeft=this.browserGamepad.buttons[14].value,this.dPadRight=this.browserGamepad.buttons[15].value},t}(n);e.Xbox360Pad=a}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r){e.Tools.Warn("Deprecated. Please use Universal Camera instead."),t.call(this,i,n,r)}return __extends(i,t),Object.defineProperty(i.prototype,"gamepadAngularSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadAngularSensibility:void 0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadAngularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"gamepadMoveSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadMoveSensibility:void 0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadMoveSensibility=e)},enumerable:!0,configurable:!0}),i.prototype.getTypeName=function(){return"GamepadCamera"},i}(e.UniversalCamera);e.GamepadCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.SMOOTHING=.75,this.FFT_SIZE=512,this.BARGRAPHAMPLITUDE=256,this.DEBUGCANVASPOS={x:20,y:20},this.DEBUGCANVASSIZE={width:320,height:200},this._scene=t,this._audioEngine=e.Engine.audioEngine,this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser=this._audioEngine.audioContext.createAnalyser(),this._webAudioAnalyser.minDecibels=-140,this._webAudioAnalyser.maxDecibels=0,this._byteFreqs=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._byteTime=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._floatFreqs=new Float32Array(this._webAudioAnalyser.frequencyBinCount))}return t.prototype.getFrequencyBinCount=function(){return this._audioEngine.canUseWebAudio?this._webAudioAnalyser.frequencyBinCount:0},t.prototype.getByteFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteFrequencyData(this._byteFreqs)),this._byteFreqs},t.prototype.getByteTimeDomainData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteTimeDomainData(this._byteTime)),this._byteTime},t.prototype.getFloatFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getFloatFrequencyData(this._floatFreqs)),this._floatFreqs},t.prototype.drawDebugCanvas=function(){var e=this;if(this._audioEngine.canUseWebAudio&&(this._debugCanvas||(this._debugCanvas=document.createElement("canvas"),this._debugCanvas.width=this.DEBUGCANVASSIZE.width,this._debugCanvas.height=this.DEBUGCANVASSIZE.height,this._debugCanvas.style.position="absolute",this._debugCanvas.style.top=this.DEBUGCANVASPOS.y+"px",this._debugCanvas.style.left=this.DEBUGCANVASPOS.x+"px",this._debugCanvasContext=this._debugCanvas.getContext("2d"),document.body.appendChild(this._debugCanvas),this._registerFunc=function(){e.drawDebugCanvas()},this._scene.registerBeforeRender(this._registerFunc)),this._registerFunc)){var t=this.getByteFrequencyData();this._debugCanvasContext.fillStyle="rgb(0, 0, 0)",this._debugCanvasContext.fillRect(0,0,this.DEBUGCANVASSIZE.width,this.DEBUGCANVASSIZE.height);for(var i=0;i<this.getFrequencyBinCount();i++){var n=t[i],r=n/this.BARGRAPHAMPLITUDE,o=this.DEBUGCANVASSIZE.height*r,s=this.DEBUGCANVASSIZE.height-o-1,a=this.DEBUGCANVASSIZE.width/this.getFrequencyBinCount(),h=i/this.getFrequencyBinCount()*360;this._debugCanvasContext.fillStyle="hsl("+h+", 100%, 50%)",this._debugCanvasContext.fillRect(i*a,s,a,o)}}},t.prototype.stopDebugCanvas=function(){this._debugCanvas&&(this._scene.unregisterBeforeRender(this._registerFunc),this._registerFunc=null,document.body.removeChild(this._debugCanvas),this._debugCanvas=null,this._debugCanvasContext=null)},t.prototype.connectAudioNodes=function(e,t){this._audioEngine.canUseWebAudio&&(e.connect(this._webAudioAnalyser),this._webAudioAnalyser.connect(t))},t.prototype.dispose=function(){this._audioEngine.canUseWebAudio&&this._webAudioAnalyser.disconnect()},t}();e.Analyser=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){var n=this;void 0===i&&(i=e.Engine.TEXTURETYPE_FLOAT),this._viewMatrix=e.Matrix.Zero(),this._projectionMatrix=e.Matrix.Zero(),this._transformMatrix=e.Matrix.Zero(),this._worldViewProjection=e.Matrix.Zero(),this._scene=t;var r=t.getEngine();this._depthMap=new e.RenderTargetTexture("depthMap",{width:r.getRenderWidth(),height:r.getRenderHeight()},this._scene,!1,!0,i),this._depthMap.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._depthMap.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._depthMap.refreshRate=1,this._depthMap.renderParticles=!1,this._depthMap.renderList=null,this._depthMap.onClear=function(t){t.clear(new e.Color4(1,1,1,1),!0,!0)};var o=function(t){var i=t.getRenderingMesh(),r=n._scene,o=r.getEngine();o.setState(t.getMaterial().backFaceCulling);var s=i._getInstancesRenderList(t._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[t._id];if(n.isReady(t,a)){o.enableEffect(n._effect),i._bind(t,n._effect,e.Material.TriangleFillMode);var h=t.getMaterial();if(n._effect.setMatrix("viewProjection",r.getTransformMatrix()),n._effect.setFloat("far",r.activeCamera.maxZ),h&&h.needAlphaTesting()){var c=h.getAlphaTestTexture();n._effect.setTexture("diffuseSampler",c),n._effect.setMatrix("diffuseMatrix",c.getTextureMatrix())}i.useBones&&i.computeBonesUsingShaders&&n._effect.setMatrices("mBones",i.skeleton.getTransformMatrices(i)),i._processRendering(t,n._effect,e.Material.TriangleFillMode,s,a,function(e,t){return n._effect.setMatrix("world",t)})}}};this._depthMap.customRenderFunction=function(e,t){var i;for(i=0;i<e.length;i++)o(e.data[i]);for(i=0;i<t.length;i++)o(t.data[i])}}return t.prototype.isReady=function(t,i){var n=t.getMaterial();if(n.disableDepthWrite)return!1;var r=[],o=[e.VertexBuffer.PositionKind],s=t.getMesh();s.getScene();n&&n.needAlphaTesting()&&(r.push("#define ALPHATEST"),s.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(o.push(e.VertexBuffer.UVKind),r.push("#define UV1")),s.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(o.push(e.VertexBuffer.UV2Kind),r.push("#define UV2"))),s.useBones&&s.computeBonesUsingShaders?(o.push(e.VertexBuffer.MatricesIndicesKind),o.push(e.VertexBuffer.MatricesWeightsKind),s.numBoneInfluencers>4&&(o.push(e.VertexBuffer.MatricesIndicesExtraKind),o.push(e.VertexBuffer.MatricesWeightsExtraKind)),r.push("#define NUM_BONE_INFLUENCERS "+s.numBoneInfluencers),r.push("#define BonesPerMesh "+(s.skeleton.bones.length+1))):r.push("#define NUM_BONE_INFLUENCERS 0"),i&&(r.push("#define INSTANCES"),o.push("world0"),o.push("world1"),o.push("world2"),o.push("world3"));var a=r.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("depth",o,["world","mBones","viewProjection","diffuseMatrix","far"],["diffuseSampler"],a)),this._effect.isReady()},t.prototype.getDepthMap=function(){return this._depthMap},t.prototype.dispose=function(){this._depthMap.dispose()},t}();e.DepthRenderer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o){var s=this;t.call(this,n.getEngine(),i),this.SSAOOriginalSceneColorEffect="SSAOOriginalSceneColorEffect",this.SSAORenderEffect="SSAORenderEffect",this.SSAOBlurHRenderEffect="SSAOBlurHRenderEffect",this.SSAOBlurVRenderEffect="SSAOBlurVRenderEffect",this.SSAOCombineRenderEffect="SSAOCombineRenderEffect",this.totalStrength=1,this.radius=1e-4,this.area=.0075,this.fallOff=1e-6,this.base=.5,this._firstUpdate=!0,this._scene=n,this._createRandomTexture(),this._depthTexture=n.enableDepthRenderer().getDepthMap();var a=r.ssaoRatio||r,h=r.combineRatio||r;this._originalColorPostProcess=new e.PassPostProcess("SSAOOriginalSceneColor",h,null,e.Texture.BILINEAR_SAMPLINGMODE,n.getEngine(),!1),this._createSSAOPostProcess(a),this._blurHPostProcess=new e.BlurPostProcess("SSAOBlurH",new e.Vector2(1,0),2,a,null,e.Texture.BILINEAR_SAMPLINGMODE,n.getEngine(),!1),this._blurVPostProcess=new e.BlurPostProcess("SSAOBlurV",new e.Vector2(0,1),2,a,null,e.Texture.BILINEAR_SAMPLINGMODE,n.getEngine(),!1),this._createSSAOCombinePostProcess(h),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),this.SSAOOriginalSceneColorEffect,function(){return s._originalColorPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),this.SSAORenderEffect,function(){return s._ssaoPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),this.SSAOBlurHRenderEffect,function(){return s._blurHPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),this.SSAOBlurVRenderEffect,function(){return s._blurVPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),this.SSAOCombineRenderEffect,function(){return s._ssaoCombinePostProcess},!0)),n.postProcessRenderPipelineManager.addPipeline(this),o&&n.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(i,o)}return __extends(i,t),i.prototype.getBlurHPostProcess=function(){return this._blurHPostProcess},i.prototype.getBlurVPostProcess=function(){return this._blurVPostProcess},i.prototype.dispose=function(e){void 0===e&&(e=!1),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras),this._originalColorPostProcess=void 0,this._ssaoPostProcess=void 0,this._blurHPostProcess=void 0,this._blurVPostProcess=void 0,this._ssaoCombinePostProcess=void 0,this._randomTexture.dispose(),e&&this._scene.disableDepthRenderer()},i.prototype._createSSAOPostProcess=function(t){var i=this,n=16,r=[.5381,.1856,-.4319,.1379,.2486,.443,.3371,.5679,-.0057,-.6999,-.0451,-.0019,.0689,-.1598,-.8547,.056,.0069,-.1843,-.0146,.1402,.0762,.01,-.1924,-.0344,-.3577,-.5301,-.4358,-.3169,.1063,.0158,.0103,-.5869,.0046,-.0897,-.494,.3287,.7119,-.0154,-.0918,-.0533,.0596,-.5411,.0352,-.0631,.546,-.4776,.2847,-.0271],o=1/n;this._ssaoPostProcess=new e.PostProcess("ssao","ssao",["sampleSphere","samplesFactor","randTextureTiles","totalStrength","radius","area","fallOff","base"],["randomSampler"],t,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define SAMPLES "+n),this._ssaoPostProcess.onApply=function(e){i._firstUpdate&&(e.setArray3("sampleSphere",r),e.setFloat("samplesFactor",o),e.setFloat("randTextureTiles",4),i._firstUpdate=!1),e.setFloat("totalStrength",i.totalStrength),e.setFloat("radius",i.radius),e.setFloat("area",i.area),e.setFloat("fallOff",i.fallOff),e.setFloat("base",i.base),e.setTexture("textureSampler",i._depthTexture),e.setTexture("randomSampler",i._randomTexture)}},i.prototype._createSSAOCombinePostProcess=function(t){var i=this;this._ssaoCombinePostProcess=new e.PostProcess("ssaoCombine","ssaoCombine",[],["originalColor"],t,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._ssaoCombinePostProcess.onApply=function(e){e.setTextureFromPostProcess("originalColor",i._originalColorPostProcess)}},i.prototype._createRandomTexture=function(){var t=512;this._randomTexture=new e.DynamicTexture("SSAORandomTexture",t,this._scene,!1,e.Texture.BILINEAR_SAMPLINGMODE),this._randomTexture.wrapU=e.Texture.WRAP_ADDRESSMODE,this._randomTexture.wrapV=e.Texture.WRAP_ADDRESSMODE;for(var i=this._randomTexture.getContext(),n=function(e,t){return Math.random()*(t-e)+e},r=e.Vector3.Zero(),o=0;t>o;o++)for(var s=0;t>s;s++)r.x=Math.floor(255*n(-1,1)),r.y=Math.floor(255*n(-1,1)),r.z=Math.floor(255*n(-1,1)),i.fillStyle="rgb("+r.x+", "+r.y+", "+r.z+")",i.fillRect(o,s,1,1);this._randomTexture.update(!1)},i}(e.PostProcessRenderPipeline);e.SSAORenderingPipeline=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(n,r,o,s,a,h,c,l,u){var d=this;void 0===a&&(a=100),void 0===h&&(h=e.Texture.BILINEAR_SAMPLINGMODE),t.call(this,n,"volumetricLightScattering",["decay","exposure","weight","meshPositionOnScreen","density"],["lightScatteringSampler"],r.postProcessRatio||r,o,h,c,l,"#define NUM_SAMPLES "+a),this._screenCoordinates=e.Vector2.Zero(),this.customMeshPosition=e.Vector3.Zero(),this.useCustomMeshPosition=!1,this.invert=!0,this.excludedMeshes=new Array,this.exposure=.3,this.decay=.96815,this.weight=.58767,this.density=.926,u=null===o?u:o.getScene();var c=u.getEngine();this._viewPort=new e.Viewport(0,0,1,1).toGlobal(c.getRenderWidth(),c.getRenderHeight()),this.mesh=null!==s?s:i.CreateDefaultMesh("VolumetricLightScatteringMesh",u),this._createPass(u,r.passRatio||r),this.onActivate=function(e){d.isSupported||d.dispose(e),d.onActivate=null},this.onApply=function(e){d._updateMeshScreenCoordinates(u),e.setTexture("lightScatteringSampler",d._volumetricLightScatteringRTT),e.setFloat("exposure",d.exposure),e.setFloat("decay",d.decay),e.setFloat("weight",d.weight),e.setFloat("density",d.density),e.setVector2("meshPositionOnScreen",d._screenCoordinates)}}return __extends(i,t),Object.defineProperty(i.prototype,"useDiffuseColor",{get:function(){return e.Tools.Warn("VolumetricLightScatteringPostProcess.useDiffuseColor is no longer used, use the mesh material directly instead"),!1},set:function(t){e.Tools.Warn("VolumetricLightScatteringPostProcess.useDiffuseColor is no longer used, use the mesh material directly instead")},enumerable:!0,configurable:!0}),i.prototype.isReady=function(t,i){var n=t.getMesh();if(n===this.mesh)return n.material.isReady(n);var r=[],o=[e.VertexBuffer.PositionKind],s=t.getMaterial();s&&(s.needAlphaTesting()&&r.push("#define ALPHATEST"),n.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(o.push(e.VertexBuffer.UVKind),r.push("#define UV1")),n.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(o.push(e.VertexBuffer.UV2Kind),r.push("#define UV2"))),n.useBones&&n.computeBonesUsingShaders?(o.push(e.VertexBuffer.MatricesIndicesKind),o.push(e.VertexBuffer.MatricesWeightsKind),r.push("#define NUM_BONE_INFLUENCERS "+n.numBoneInfluencers),r.push("#define BonesPerMesh "+(n.skeleton.bones.length+1))):r.push("#define NUM_BONE_INFLUENCERS 0"),
  26. i&&(r.push("#define INSTANCES"),o.push("world0"),o.push("world1"),o.push("world2"),o.push("world3"));var a=r.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._volumetricLightScatteringPass=n.getScene().getEngine().createEffect({vertexElement:"depth",fragmentElement:"volumetricLightScatteringPass"},o,["world","mBones","viewProjection","diffuseMatrix"],["diffuseSampler"],a)),this._volumetricLightScatteringPass.isReady()},i.prototype.setCustomMeshPosition=function(e){this.customMeshPosition=e},i.prototype.getCustomMeshPosition=function(){return this.customMeshPosition},i.prototype.dispose=function(e){var i=e.getScene().customRenderTargets.indexOf(this._volumetricLightScatteringRTT);-1!==i&&e.getScene().customRenderTargets.splice(i,1),this._volumetricLightScatteringRTT.dispose(),t.prototype.dispose.call(this,e)},i.prototype.getPass=function(){return this._volumetricLightScatteringRTT},i.prototype._meshExcluded=function(e){return this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e)},i.prototype._createPass=function(t,i){var n=this,r=t.getEngine();this._volumetricLightScatteringRTT=new e.RenderTargetTexture("volumetricLightScatteringMap",{width:r.getRenderWidth()*i,height:r.getRenderHeight()*i},t,!1,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT),this._volumetricLightScatteringRTT.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.renderList=null,this._volumetricLightScatteringRTT.renderParticles=!1,t.customRenderTargets.push(this._volumetricLightScatteringRTT);var o,s=function(t){var i=t.getRenderingMesh();if(!n._meshExcluded(i)){var r=i.getScene(),o=r.getEngine();o.setState(t.getMaterial().backFaceCulling);var s=i._getInstancesRenderList(t._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[t._id];if(n.isReady(t,a)){var h=n._volumetricLightScatteringPass;if(i===n.mesh&&(h=t.getMaterial().getEffect()),o.enableEffect(h),i._bind(t,h,e.Material.TriangleFillMode),i===n.mesh)t.getMaterial().bind(i.getWorldMatrix(),i);else{var c=t.getMaterial();if(n._volumetricLightScatteringPass.setMatrix("viewProjection",r.getTransformMatrix()),c&&c.needAlphaTesting()){var l=c.getAlphaTestTexture();n._volumetricLightScatteringPass.setTexture("diffuseSampler",l),l&&n._volumetricLightScatteringPass.setMatrix("diffuseMatrix",l.getTextureMatrix())}i.useBones&&i.computeBonesUsingShaders&&n._volumetricLightScatteringPass.setMatrices("mBones",i.skeleton.getTransformMatrices(i))}i._processRendering(t,n._volumetricLightScatteringPass,e.Material.TriangleFillMode,s,a,function(e,t){return h.setMatrix("world",t)})}}}},a=new e.Color4(0,0,0,1);this._volumetricLightScatteringRTT.onBeforeRender=function(){o=t.clearColor,t.clearColor=a},this._volumetricLightScatteringRTT.onAfterRender=function(){t.clearColor=o},this._volumetricLightScatteringRTT.customRenderFunction=function(i,n,r){var o,a=t.getEngine();for(o=0;o<i.length;o++)s(i.data[o]);for(a.setAlphaTesting(!0),o=0;o<n.length;o++)s(n.data[o]);if(a.setAlphaTesting(!1),r.length){for(o=0;o<r.length;o++){var h=r.data[o];h._alphaIndex=h.getMesh().alphaIndex,h._distanceToCamera=h.getBoundingInfo().boundingSphere.centerWorld.subtract(t.activeCamera.position).length()}var c=r.data.slice(0,r.length);for(c.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}),a.setAlphaMode(e.Engine.ALPHA_COMBINE),o=0;o<c.length;o++)s(c[o]);a.setAlphaMode(e.Engine.ALPHA_DISABLE)}}},i.prototype._updateMeshScreenCoordinates=function(t){var i,n=t.getTransformMatrix();i=this.useCustomMeshPosition?this.customMeshPosition:this.attachedNode?this.attachedNode.position:this.mesh.parent?this.mesh.getAbsolutePosition():this.mesh.position;var r=e.Vector3.Project(i,e.Matrix.Identity(),n,this._viewPort);this._screenCoordinates.x=r.x/this._viewPort.width,this._screenCoordinates.y=r.y/this._viewPort.height,this.invert&&(this._screenCoordinates.y=1-this._screenCoordinates.y)},i.CreateDefaultMesh=function(t,i){var n=e.Mesh.CreatePlane(t,1,i);n.billboardMode=e.AbstractMesh.BILLBOARDMODE_ALL;var r=new e.StandardMaterial(t+"Material",i);return r.emissiveColor=new e.Color3(1,1,1),n.material=r,n},__decorate([e.serializeAsVector3()],i.prototype,"customMeshPosition",void 0),__decorate([e.serialize()],i.prototype,"useCustomMeshPosition",void 0),__decorate([e.serialize()],i.prototype,"invert",void 0),__decorate([e.serializeAsMeshReference()],i.prototype,"mesh",void 0),__decorate([e.serialize()],i.prototype,"excludedMeshes",void 0),__decorate([e.serialize()],i.prototype,"exposure",void 0),__decorate([e.serialize()],i.prototype,"decay",void 0),__decorate([e.serialize()],i.prototype,"weight",void 0),__decorate([e.serialize()],i.prototype,"density",void 0),i}(e.PostProcess);e.VolumetricLightScatteringPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s){var a=this;void 0===o&&(o=1),t.call(this,r.getEngine(),i),this.LensChromaticAberrationEffect="LensChromaticAberrationEffect",this.HighlightsEnhancingEffect="HighlightsEnhancingEffect",this.LensDepthOfFieldEffect="LensDepthOfFieldEffect",this._scene=r,this._depthTexture=r.enableDepthRenderer().getDepthMap(),n.grain_texture?this._grainTexture=n.grain_texture:this._createGrainTexture(),this._edgeBlur=n.edge_blur?n.edge_blur:0,this._grainAmount=n.grain_amount?n.grain_amount:0,this._chromaticAberration=n.chromatic_aberration?n.chromatic_aberration:0,this._distortion=n.distortion?n.distortion:0,this._highlightsGain=void 0!==n.dof_gain?n.dof_gain:-1,this._highlightsThreshold=n.dof_threshold?n.dof_threshold:1,this._dofDistance=void 0!==n.dof_focus_distance?n.dof_focus_distance:-1,this._dofAperture=n.dof_aperture?n.dof_aperture:1,this._dofDarken=n.dof_darken?n.dof_darken:0,this._dofPentagon=void 0!==n.dof_pentagon?n.dof_pentagon:!0,this._blurNoise=void 0!==n.blur_noise?n.blur_noise:!0,this._createChromaticAberrationPostProcess(o),this._createHighlightsPostProcess(o),this._createDepthOfFieldPostProcess(o/4),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),this.LensChromaticAberrationEffect,function(){return a._chromaticAberrationPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),this.HighlightsEnhancingEffect,function(){return a._highlightsPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),this.LensDepthOfFieldEffect,function(){return a._depthOfFieldPostProcess},!0)),-1===this._highlightsGain&&this._disableEffect(this.HighlightsEnhancingEffect,null),r.postProcessRenderPipelineManager.addPipeline(this),s&&r.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(i,s)}return __extends(i,t),i.prototype.setEdgeBlur=function(e){this._edgeBlur=e},i.prototype.disableEdgeBlur=function(){this._edgeBlur=0},i.prototype.setGrainAmount=function(e){this._grainAmount=e},i.prototype.disableGrain=function(){this._grainAmount=0},i.prototype.setChromaticAberration=function(e){this._chromaticAberration=e},i.prototype.disableChromaticAberration=function(){this._chromaticAberration=0},i.prototype.setEdgeDistortion=function(e){this._distortion=e},i.prototype.disableEdgeDistortion=function(){this._distortion=0},i.prototype.setFocusDistance=function(e){this._dofDistance=e},i.prototype.disableDepthOfField=function(){this._dofDistance=-1},i.prototype.setAperture=function(e){this._dofAperture=e},i.prototype.setDarkenOutOfFocus=function(e){this._dofDarken=e},i.prototype.enablePentagonBokeh=function(){this._highlightsPostProcess.updateEffect("#define PENTAGON\n")},i.prototype.disablePentagonBokeh=function(){this._highlightsPostProcess.updateEffect()},i.prototype.enableNoiseBlur=function(){this._blurNoise=!0},i.prototype.disableNoiseBlur=function(){this._blurNoise=!1},i.prototype.setHighlightsGain=function(e){this._highlightsGain=e},i.prototype.setHighlightsThreshold=function(e){-1===this._highlightsGain&&(this._highlightsGain=1),this._highlightsThreshold=e},i.prototype.disableHighlights=function(){this._highlightsGain=-1},i.prototype.dispose=function(e){void 0===e&&(e=!1),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras),this._chromaticAberrationPostProcess=void 0,this._highlightsPostProcess=void 0,this._depthOfFieldPostProcess=void 0,this._grainTexture.dispose(),e&&this._scene.disableDepthRenderer()},i.prototype._createChromaticAberrationPostProcess=function(t){var i=this;this._chromaticAberrationPostProcess=new e.PostProcess("LensChromaticAberration","chromaticAberration",["chromatic_aberration","screen_width","screen_height"],[],t,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._chromaticAberrationPostProcess.onApply=function(e){e.setFloat("chromatic_aberration",i._chromaticAberration),e.setFloat("screen_width",i._scene.getEngine().getRenderingCanvas().width),e.setFloat("screen_height",i._scene.getEngine().getRenderingCanvas().height)}},i.prototype._createHighlightsPostProcess=function(t){var i=this;this._highlightsPostProcess=new e.PostProcess("LensHighlights","lensHighlights",["gain","threshold","screen_width","screen_height"],[],t,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,this._dofPentagon?"#define PENTAGON\n":""),this._highlightsPostProcess.onApply=function(e){e.setFloat("gain",i._highlightsGain),e.setFloat("threshold",i._highlightsThreshold),e.setTextureFromPostProcess("textureSampler",i._chromaticAberrationPostProcess),e.setFloat("screen_width",i._scene.getEngine().getRenderingCanvas().width),e.setFloat("screen_height",i._scene.getEngine().getRenderingCanvas().height)}},i.prototype._createDepthOfFieldPostProcess=function(t){var i=this;this._depthOfFieldPostProcess=new e.PostProcess("LensDepthOfField","depthOfField",["grain_amount","blur_noise","screen_width","screen_height","distortion","dof_enabled","screen_distance","aperture","darken","edge_blur","highlights","near","far"],["depthSampler","grainSampler","highlightsSampler"],t,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._depthOfFieldPostProcess.onApply=function(e){e.setTexture("depthSampler",i._depthTexture),e.setTexture("grainSampler",i._grainTexture),e.setTextureFromPostProcess("textureSampler",i._highlightsPostProcess),e.setTextureFromPostProcess("highlightsSampler",i._depthOfFieldPostProcess),e.setFloat("grain_amount",i._grainAmount),e.setBool("blur_noise",i._blurNoise),e.setFloat("screen_width",i._scene.getEngine().getRenderingCanvas().width),e.setFloat("screen_height",i._scene.getEngine().getRenderingCanvas().height),e.setFloat("distortion",i._distortion),e.setBool("dof_enabled",-1!==i._dofDistance),e.setFloat("screen_distance",1/(.1-1/i._dofDistance)),e.setFloat("aperture",i._dofAperture),e.setFloat("darken",i._dofDarken),e.setFloat("edge_blur",i._edgeBlur),e.setBool("highlights",-1!==i._highlightsGain),e.setFloat("near",i._scene.activeCamera.minZ),e.setFloat("far",i._scene.activeCamera.maxZ)}},i.prototype._createGrainTexture=function(){var t=512;this._grainTexture=new e.DynamicTexture("LensNoiseTexture",t,this._scene,!1,e.Texture.BILINEAR_SAMPLINGMODE),this._grainTexture.wrapU=e.Texture.WRAP_ADDRESSMODE,this._grainTexture.wrapV=e.Texture.WRAP_ADDRESSMODE;for(var i,n=this._grainTexture.getContext(),r=function(e,t){return Math.random()*(t-e)+e},o=0;t>o;o++)for(var s=0;t>s;s++)i=Math.floor(255*r(.42,.58)),n.fillStyle="rgb("+i+", "+i+", "+i+")",n.fillRect(o,s,1,1);this._grainTexture.update(!1)},i}(e.PostProcessRenderPipeline);e.LensRenderingPipeline=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s,a,h){var c=this;t.call(this,i,"colorCorrection",null,["colorTable"],r,o,s,a,h),this._colorTableTexture=new e.Texture(n,o.getScene(),!0,!1,e.Texture.TRILINEAR_SAMPLINGMODE),this._colorTableTexture.anisotropicFilteringLevel=1,this._colorTableTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._colorTableTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,this.onApply=function(e){e.setTexture("colorTable",c._colorTableTexture)}}return __extends(i,t),i}(e.PostProcess);e.ColorCorrectionPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o){t.call(this,i,n,o),this.interaxialDistance=r,this.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:r})}return __extends(i,t),i.prototype.getTypeName=function(){return"AnaglyphFreeCamera"},i}(e.FreeCamera);e.AnaglyphFreeCamera=t;var i=function(t){function i(i,n,r,o,s,a,h){t.call(this,i,n,r,o,s,h),this.interaxialDistance=a,this.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:a})}return __extends(i,t),i.prototype.getTypeName=function(){return"AnaglyphArcRotateCamera"},i}(e.ArcRotateCamera);e.AnaglyphArcRotateCamera=i;var n=function(t){function i(i,n,r,o){t.call(this,i,n,o),this.interaxialDistance=r,this.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:r})}return __extends(i,t),i.prototype.getTypeName=function(){return"AnaglyphGamepadCamera"},i}(e.GamepadCamera);e.AnaglyphGamepadCamera=n;var r=function(t){function i(i,n,r,o){t.call(this,i,n,o),this.interaxialDistance=r,this.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:r})}return __extends(i,t),i.prototype.getTypeName=function(){return"AnaglyphUniversalCamera"},i}(e.UniversalCamera);e.AnaglyphUniversalCamera=r;var o=function(t){function i(i,n,r,o,s){t.call(this,i,n,s),this.interaxialDistance=r,this.isStereoscopicSideBySide=o,this.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:r})}return __extends(i,t),i.prototype.getTypeName=function(){return"StereoscopicFreeCamera"},i}(e.FreeCamera);e.StereoscopicFreeCamera=o;var s=function(t){function i(i,n,r,o,s,a,h,c){t.call(this,i,n,r,o,s,c),this.interaxialDistance=a,this.isStereoscopicSideBySide=h,this.setCameraRigMode(h?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:a})}return __extends(i,t),i.prototype.getTypeName=function(){return"StereoscopicArcRotateCamera"},i}(e.ArcRotateCamera);e.StereoscopicArcRotateCamera=s;var a=function(t){function i(i,n,r,o,s){t.call(this,i,n,s),this.interaxialDistance=r,this.isStereoscopicSideBySide=o,this.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:r})}return __extends(i,t),i.prototype.getTypeName=function(){return"StereoscopicGamepadCamera"},i}(e.GamepadCamera);e.StereoscopicGamepadCamera=a;var h=function(t){function i(i,n,r,o,s){t.call(this,i,n,s),this.interaxialDistance=r,this.isStereoscopicSideBySide=o,this.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:r})}return __extends(i,t),i.prototype.getTypeName=function(){return"StereoscopicUniversalCamera"},i}(e.UniversalCamera);e.StereoscopicUniversalCamera=h}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(n,r,o,s,a){var h=this;void 0===s&&(s=null),t.call(this,r.getEngine(),n),this.gaussCoeff=.3,this.gaussMean=1,this.gaussStandDev=.8,this.gaussMultiplier=4,this.exposure=1,this.minimumLuminance=1,this.maximumLuminance=1e20,this.luminanceIncreaserate=.5,this.luminanceDecreaseRate=.5,this.brightThreshold=.8,this._needUpdate=!0,this._scene=r,this._createBrightPassPostProcess(r,o),this._createDownSampleX4PostProcess(r,o),this._createGaussianBlurPostProcess(r,o),this._createTextureAdderPostProcess(r,o),this._createLuminanceGeneratorPostProcess(r),this._createHDRPostProcess(r,o),null===s?this._originalPostProcess=new e.PassPostProcess("hdr",o,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1):this._originalPostProcess=s,this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRPassPostProcess",function(){return h._originalPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRBrightPass",function(){return h._brightPassPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRDownSampleX4",function(){return h._downSampleX4PostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRGaussianBlurH",function(){return h._guassianBlurHPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRGaussianBlurV",function(){return h._guassianBlurVPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRTextureAdder",function(){return h._textureAdderPostProcess},!0));for(var c=function(t){h.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRDownSampler"+t,function(){return h._downSamplePostProcesses[t]},!0))},l=i.LUM_STEPS-1;l>=0;l--)c(l);this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDR",function(){return h._hdrPostProcess},!0)),r.postProcessRenderPipelineManager.addPipeline(this),null!==a&&r.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(n,a),this.update()}return __extends(i,t),i.prototype.update=function(){this._needUpdate=!0},i.prototype.getCurrentLuminance=function(){return this._hdrCurrentLuminance},i.prototype.getOutputLuminance=function(){return this._hdrOutputLuminance},i.prototype.dispose=function(){this._originalPostProcess=void 0,this._brightPassPostProcess=void 0,this._downSampleX4PostProcess=void 0,this._guassianBlurHPostProcess=void 0,this._guassianBlurVPostProcess=void 0,this._textureAdderPostProcess=void 0;for(var e=i.LUM_STEPS-1;e>=0;e--)this._downSamplePostProcesses[e]=void 0;this._hdrPostProcess=void 0,this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras)},i.prototype._createHDRPostProcess=function(t,i){var n=this,r=0;this._hdrOutputLuminance=-1,this._hdrCurrentLuminance=1,this._hdrPostProcess=new e.PostProcess("hdr","hdr",["exposure","avgLuminance"],["otherSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define HDR"),this._hdrPostProcess.onApply=function(i){if(n._hdrOutputLuminance<0)n._hdrOutputLuminance=n._hdrCurrentLuminance;else{var o=(r-(r+t.getEngine().getDeltaTime()))/1e3;n._hdrCurrentLuminance<n._hdrOutputLuminance+n.luminanceDecreaseRate*o?n._hdrOutputLuminance+=n.luminanceDecreaseRate*o:n._hdrCurrentLuminance>n._hdrOutputLuminance-n.luminanceIncreaserate*o?n._hdrOutputLuminance-=n.luminanceIncreaserate*o:n._hdrOutputLuminance=n._hdrCurrentLuminance}n._hdrOutputLuminance=e.MathTools.Clamp(n._hdrOutputLuminance,n.minimumLuminance,n.maximumLuminance),r+=t.getEngine().getDeltaTime(),i.setTextureFromPostProcess("textureSampler",n._textureAdderPostProcess),i.setTextureFromPostProcess("otherSampler",n._originalPostProcess),i.setFloat("exposure",n.exposure),i.setFloat("avgLuminance",n._hdrOutputLuminance),n._needUpdate=!1}},i.prototype._createTextureAdderPostProcess=function(t,i){var n=this;this._textureAdderPostProcess=new e.PostProcess("hdr","hdr",[],["otherSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define TEXTURE_ADDER"),this._textureAdderPostProcess.onApply=function(e){e.setTextureFromPostProcess("otherSampler",n._originalPostProcess)}},i.prototype._createDownSampleX4PostProcess=function(t,i){var n=this,r=new Array(32);this._downSampleX4PostProcess=new e.PostProcess("hdr","hdr",["dsOffsets"],[],i/4,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define DOWN_SAMPLE_X4"),this._downSampleX4PostProcess.onApply=function(e){if(n._needUpdate)for(var t=0,i=-2;2>i;i++)for(var o=-2;2>o;o++)r[t]=(i+.5)*(1/n._downSampleX4PostProcess.width),r[t+1]=(o+.5)*(1/n._downSampleX4PostProcess.height),t+=2;e.setArray2("dsOffsets",r)}},i.prototype._createBrightPassPostProcess=function(t,i){var n=this,r=new Array(8),o=function(e){if(n._needUpdate){var t=1/n._brightPassPostProcess.width,i=1/n._brightPassPostProcess.height;r[0]=-.5*t,r[1]=.5*i,r[2]=.5*t,r[3]=.5*i,r[4]=-.5*t,r[5]=-.5*i,r[6]=.5*t,r[7]=-.5*i}e.setArray2("dsOffsets",r),e.setFloat("brightThreshold",n.brightThreshold)};this._brightPassPostProcess=new e.PostProcess("hdr","hdr",["dsOffsets","brightThreshold"],[],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define BRIGHT_PASS"),this._brightPassPostProcess.onApply=o},i.prototype._createLuminanceGeneratorPostProcess=function(t){var n,r=this,o=i.LUM_STEPS,s=new Array(8),a=new Array(18);this._downSamplePostProcesses=new Array(o);var h=function(e,t){var i=1/e,n=1/t;s[0]=-.5*i,s[1]=.5*n,s[2]=.5*i,s[3]=.5*n,s[4]=-.5*i,s[5]=-.5*n,s[6]=.5*i,s[7]=-.5*n},c=function(e,t){for(var i=0,n=-1;2>n;n++)for(var r=-1;2>r;r++)a[i]=n/e,a[i+1]=r/t,i+=2},l=function(e){r._needUpdate&&h(r._textureAdderPostProcess.width,r._textureAdderPostProcess.height),e.setTextureFromPostProcess("textureSampler",r._textureAdderPostProcess),e.setArray2("lumOffsets",s)},u=function(e){var t=e;return function(e){h(r._downSamplePostProcesses[t].width,r._downSamplePostProcesses[t].height),c(r._downSamplePostProcesses[t].width,r._downSamplePostProcesses[t].height),n=.5/r._downSamplePostProcesses[t].width,e.setTextureFromPostProcess("textureSampler",r._downSamplePostProcesses[t+1]),e.setFloat("halfDestPixelSize",n),e.setArray2("dsOffsets",a)}},d=function(i){var n=t.getEngine().readPixels(0,0,1,1),o=new e.Vector4(1/16581375,1/65025,1/255,1);r._hdrCurrentLuminance=(n[0]*o.x+n[1]*o.y+n[2]*o.z+n[3]*o.w)/100},f={width:Math.pow(3,o-1),height:Math.pow(3,o-1)};this._downSamplePostProcesses[o-1]=new e.PostProcess("hdr","hdr",["lumOffsets"],[],f,null,e.Texture.NEAREST_SAMPLINGMODE,t.getEngine(),!1,"#define LUMINANCE_GENERATOR",e.Engine.TEXTURETYPE_FLOAT),this._downSamplePostProcesses[o-1].onApply=l;for(var p=o-2;p>=0;p--){var m=Math.pow(3,p);f={width:m,height:m};var _="#define DOWN_SAMPLE\n";0===p&&(_+="#define FINAL_DOWN_SAMPLE\n"),this._downSamplePostProcesses[p]=new e.PostProcess("hdr","hdr",["dsOffsets","halfDestPixelSize"],[],f,null,e.Texture.NEAREST_SAMPLINGMODE,t.getEngine(),!1,_,e.Engine.TEXTURETYPE_FLOAT),this._downSamplePostProcesses[p].onApply=u(p),0===p&&(this._downSamplePostProcesses[p].onAfterRender=d)}},i.prototype._createGaussianBlurPostProcess=function(t,i){var n=this,r=new Array(9),o=new Array(9),s=new Array(9),a=["blurOffsets","blurWeights","multiplier"],h=function(e){for(var i={width:t.getEngine().getRenderWidth(),height:t.getEngine().getRenderHeight()},n=0;9>n;n++){var s=(n-4)*(1/(e===!0?i.height:i.width));e?o[n]=s:r[n]=s}},c=function(){for(var e=0,t=0;9>t;t++)e=(t-4)/4,s[t]=n.gaussCoeff*(1/Math.sqrt(2*Math.PI*n.gaussStandDev))*Math.exp(-((e-n.gaussMean)*(e-n.gaussMean))/(2*n.gaussStandDev*n.gaussStandDev))},l=function(e){return function(t){n._needUpdate&&(c(),h(e)),t.setArray("blurOffsets",e?o:r),t.setArray("blurWeights",s),t.setFloat("multiplier",n.gaussMultiplier)}};this._guassianBlurHPostProcess=new e.PostProcess("hdr","hdr",a,[],i/4,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define GAUSSIAN_BLUR_H"),this._guassianBlurHPostProcess.onApply=l(!1),this._guassianBlurVPostProcess=new e.PostProcess("hdr","hdr",a,[],i/4,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define GAUSSIAN_BLUR_V"),this._guassianBlurVPostProcess.onApply=l(!0)},i.LUM_STEPS=6,i}(e.PostProcessRenderPipeline);e.HDRRenderingPipeline=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this.edges=new Array,this.edgesConnectedCount=0}return e}(),i=function(){function i(e,t,i){void 0===t&&(t=.95),void 0===i&&(i=!1),this.edgesWidthScalerForOrthographic=1e3,this.edgesWidthScalerForPerspective=50,this._linesPositions=new Array,this._linesNormals=new Array,this._linesIndices=new Array,this._buffers=new Array,this._checkVerticesInsteadOfIndices=!1,this._source=e,this._checkVerticesInsteadOfIndices=i,this._epsilon=t,this._prepareRessources(),this._generateEdgesLines()}return i.prototype._prepareRessources=function(){this._lineShader||(this._lineShader=new e.ShaderMaterial("lineShader",this._source.getScene(),"line",{attributes:["position","normal"],uniforms:["worldViewProjection","color","width","aspectRatio"]}),this._lineShader.disableDepthWrite=!0,this._lineShader.backFaceCulling=!1)},i.prototype.dispose=function(){this._vb0.dispose(),this._vb1.dispose(),this._source.getScene().getEngine()._releaseBuffer(this._ib),this._lineShader.dispose()},i.prototype._processEdgeForAdjacencies=function(e,t,i,n,r){return e===i&&t===n||e===n&&t===i?0:e===n&&t===r||e===r&&t===n?1:e===r&&t===i||e===i&&t===r?2:-1},i.prototype._processEdgeForAdjacenciesWithVertices=function(e,t,i,n,r){return e.equalsWithEpsilon(i)&&t.equalsWithEpsilon(n)||e.equalsWithEpsilon(n)&&t.equalsWithEpsilon(i)?0:e.equalsWithEpsilon(n)&&t.equalsWithEpsilon(r)||e.equalsWithEpsilon(r)&&t.equalsWithEpsilon(n)?1:e.equalsWithEpsilon(r)&&t.equalsWithEpsilon(i)||e.equalsWithEpsilon(i)&&t.equalsWithEpsilon(r)?2:-1},i.prototype._checkEdge=function(t,i,n,r,o){var s;if(void 0===i)s=!0;else{var a=e.Vector3.Dot(n[t],n[i]);s=a<this._epsilon}if(s){var h=this._linesPositions.length/3,c=r.subtract(o);c.normalize(),this._linesPositions.push(r.x),this._linesPositions.push(r.y),this._linesPositions.push(r.z),this._linesPositions.push(r.x),this._linesPositions.push(r.y),this._linesPositions.push(r.z),this._linesPositions.push(o.x),this._linesPositions.push(o.y),this._linesPositions.push(o.z),this._linesPositions.push(o.x),this._linesPositions.push(o.y),this._linesPositions.push(o.z),this._linesNormals.push(o.x),this._linesNormals.push(o.y),this._linesNormals.push(o.z),this._linesNormals.push(-1),this._linesNormals.push(o.x),this._linesNormals.push(o.y),this._linesNormals.push(o.z),this._linesNormals.push(1),this._linesNormals.push(r.x),this._linesNormals.push(r.y),this._linesNormals.push(r.z),this._linesNormals.push(-1),this._linesNormals.push(r.x),this._linesNormals.push(r.y),this._linesNormals.push(r.z),this._linesNormals.push(1),this._linesIndices.push(h),this._linesIndices.push(h+1),this._linesIndices.push(h+2),this._linesIndices.push(h),this._linesIndices.push(h+2),this._linesIndices.push(h+3)}},i.prototype._generateEdgesLines=function(){var i,n,r=this._source.getVerticesData(e.VertexBuffer.PositionKind),o=this._source.getIndices(),s=new Array,a=new Array;for(i=0;i<o.length;i+=3){n=new t;var h=o[i],c=o[i+1],l=o[i+2];n.p0=new e.Vector3(r[3*h],r[3*h+1],r[3*h+2]),n.p1=new e.Vector3(r[3*c],r[3*c+1],r[3*c+2]),n.p2=new e.Vector3(r[3*l],r[3*l+1],r[3*l+2]);var u=e.Vector3.Cross(n.p1.subtract(n.p0),n.p2.subtract(n.p1));u.normalize(),a.push(u),s.push(n)}for(i=0;i<s.length;i++){n=s[i];for(var d=i+1;d<s.length;d++){var f=s[d];if(3===n.edgesConnectedCount)break;if(3!==f.edgesConnectedCount)for(var p=o[3*d],m=o[3*d+1],_=o[3*d+2],g=0;3>g;g++){var v;if(void 0===n.edges[g]){switch(g){case 0:v=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(n.p0,n.p1,f.p0,f.p1,f.p2):this._processEdgeForAdjacencies(o[3*i],o[3*i+1],p,m,_);break;case 1:v=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(n.p1,n.p2,f.p0,f.p1,f.p2):this._processEdgeForAdjacencies(o[3*i+1],o[3*i+2],p,m,_);break;case 2:v=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(n.p2,n.p0,f.p0,f.p1,f.p2):this._processEdgeForAdjacencies(o[3*i+2],o[3*i],p,m,_)}if(-1!==v&&(n.edges[g]=d,f.edges[v]=i,n.edgesConnectedCount++,f.edgesConnectedCount++,3===n.edgesConnectedCount))break}}}}for(i=0;i<s.length;i++){var y=s[i];this._checkEdge(i,y.edges[0],a,y.p0,y.p1),this._checkEdge(i,y.edges[1],a,y.p1,y.p2),this._checkEdge(i,y.edges[2],a,y.p2,y.p0)}var x=this._source.getScene().getEngine();this._vb0=new e.VertexBuffer(x,this._linesPositions,e.VertexBuffer.PositionKind,!1),this._vb1=new e.VertexBuffer(x,this._linesNormals,e.VertexBuffer.NormalKind,!1,!1,4),this._buffers[e.VertexBuffer.PositionKind]=this._vb0,this._buffers[e.VertexBuffer.NormalKind]=this._vb1,this._ib=x.createIndexBuffer(this._linesIndices),this._indicesCount=this._linesIndices.length},i.prototype.render=function(){if(this._lineShader.isReady()){var t=this._source.getScene(),i=t.getEngine();this._lineShader._preBind(),i.bindMultiBuffers(this._buffers,this._ib,this._lineShader.getEffect()),t.resetCachedMaterial(),this._lineShader.setColor4("color",this._source.edgesColor),t.activeCamera.mode===e.Camera.ORTHOGRAPHIC_CAMERA?this._lineShader.setFloat("width",this._source.edgesWidth/this.edgesWidthScalerForOrthographic):this._lineShader.setFloat("width",this._source.edgesWidth/this.edgesWidthScalerForPerspective),this._lineShader.setFloat("aspectRatio",i.getAspectRatio(t.activeCamera)),this._lineShader.bind(this._source.getWorldMatrix()),i.draw(!0,0,this._indicesCount),this._lineShader.unbind(),i.setDepthWrite(!0)}},i}();e.EdgesRenderer=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){!function(e){e[e.Hable=0]="Hable",e[e.Reinhard=1]="Reinhard",e[e.HejiDawson=2]="HejiDawson",e[e.Photographic=3]="Photographic"}(e.TonemappingOperator||(e.TonemappingOperator={}));var t=e.TonemappingOperator,i=function(i){function n(n,r,o,s,a,h,c){var l=this;void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE),void 0===c&&(c=e.Engine.TEXTURETYPE_UNSIGNED_INT),i.call(this,n,"tonemap",["_ExposureAdjustment"],null,1,s,a,h,!0,u,c),this._operator=r,this.exposureAdjustment=o;var u="#define ";this._operator===t.Hable?u+="HABLE_TONEMAPPING":this._operator===t.Reinhard?u+="REINHARD_TONEMAPPING":this._operator===t.HejiDawson?u+="OPTIMIZED_HEJIDAWSON_TONEMAPPING":this._operator===t.Photographic&&(u+="PHOTOGRAPHIC_TONEMAPPING"),this.updateEffect(u),this.onApply=function(e){e.setFloat("_ExposureAdjustment",l.exposureAdjustment)}}return __extends(n,i),n}(e.PostProcess);e.TonemapPostProcess=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,n,r){var o=this;void 0===r&&(r=!0),this.name=t,this._viewMatrix=e.Matrix.Identity(),this._target=e.Vector3.Zero(),this._add=e.Vector3.Zero(),this.position=e.Vector3.Zero(),this._scene=n,this._scene.reflectionProbes.push(this),this._renderTargetTexture=new e.RenderTargetTexture(t,i,n,r,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT,!0),this._renderTargetTexture.onBeforeRender=function(t){switch(t){case 0:o._add.copyFromFloats(1,0,0);break;case 1:o._add.copyFromFloats(-1,0,0);break;case 2:o._add.copyFromFloats(0,-1,0);break;case 3:o._add.copyFromFloats(0,1,0);break;case 4:o._add.copyFromFloats(0,0,1);break;case 5:o._add.copyFromFloats(0,0,-1)}o._attachedMesh&&o.position.copyFrom(o._attachedMesh.getAbsolutePosition()),o.position.addToRef(o._add,o._target),e.Matrix.LookAtLHToRef(o.position,o._target,e.Vector3.Up(),o._viewMatrix),n.setTransformMatrix(o._viewMatrix,o._projectionMatrix)},this._renderTargetTexture.onAfterUnbind=function(){n.updateTransformMatrix(!0)},this._projectionMatrix=e.Matrix.PerspectiveFovLH(Math.PI/2,1,n.activeCamera.minZ,n.activeCamera.maxZ)}return Object.defineProperty(t.prototype,"refreshRate",{get:function(){return this._renderTargetTexture.refreshRate},set:function(e){this._renderTargetTexture.refreshRate=e},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},Object.defineProperty(t.prototype,"cubeTexture",{get:function(){return this._renderTargetTexture},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"renderList",{get:function(){return this._renderTargetTexture.renderList},enumerable:!0,configurable:!0}),t.prototype.attachToMesh=function(e){this._attachedMesh=e},t.prototype.dispose=function(){var e=this._scene.reflectionProbes.indexOf(this);-1!==e&&this._scene.reflectionProbes.splice(e,1),this._renderTargetTexture&&(this._renderTargetTexture.dispose(),this._renderTargetTexture=null)},t}();e.ReflectionProbe=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,n,r,o){this.color=new e.Color4(1,1,1,1),this.position=e.Vector3.Zero(),this.rotation=e.Vector3.Zero(),this.scaling=new e.Vector3(1,1,1),this.uvs=new e.Vector4(0,0,1,1),this.velocity=e.Vector3.Zero(),this.alive=!0,this.idx=t,this._pos=i,this._model=n,this.shapeId=r,this.idxInShape=o}return Object.defineProperty(t.prototype,"scale",{
  27. get:function(){return this.scaling},set:function(e){this.scaling=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"quaternion",{get:function(){return this.rotationQuaternion},set:function(e){this.rotationQuaternion=e},enumerable:!0,configurable:!0}),t}();e.SolidParticle=t;var i=function(){function e(e,t,i,n,r){this.shapeID=e,this._shape=t,this._shapeUV=i,this._positionFunction=n,this._vertexFunction=r}return e}();e.ModelShape=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,n){this.particles=new Array,this.nbParticles=0,this.billboard=!1,this.counter=0,this.vars={},this._positions=new Array,this._indices=new Array,this._normals=new Array,this._colors=new Array,this._uvs=new Array,this._index=0,this._updatable=!0,this._pickable=!1,this._isVisibilityBoxLocked=!1,this._alwaysVisible=!1,this._shapeCounter=0,this._copy=new e.SolidParticle(null,null,null,null,null),this._color=new e.Color4(0,0,0,0),this._computeParticleColor=!0,this._computeParticleTexture=!0,this._computeParticleRotation=!0,this._computeParticleVertex=!1,this._computeBoundingBox=!1,this._cam_axisZ=e.Vector3.Zero(),this._cam_axisY=e.Vector3.Zero(),this._cam_axisX=e.Vector3.Zero(),this._axisX=e.Axis.X,this._axisY=e.Axis.Y,this._axisZ=e.Axis.Z,this._fakeCamPos=e.Vector3.Zero(),this._rotMatrix=new e.Matrix,this._invertMatrix=new e.Matrix,this._rotated=e.Vector3.Zero(),this._quaternion=new e.Quaternion,this._vertex=e.Vector3.Zero(),this._normal=e.Vector3.Zero(),this._yaw=0,this._pitch=0,this._roll=0,this._halfroll=0,this._halfpitch=0,this._halfyaw=0,this._sinRoll=0,this._cosRoll=0,this._sinPitch=0,this._cosPitch=0,this._sinYaw=0,this._cosYaw=0,this._w=0,this._minimum=e.Tmp.Vector3[0],this._maximum=e.Tmp.Vector3[1],this.name=t,this._scene=i,this._camera=i.activeCamera,this._pickable=n?n.isPickable:!1,n&&n.updatable?this._updatable=n.updatable:this._updatable=!0,this._pickable&&(this.pickedParticles=[])}return t.prototype.buildMesh=function(){if(0===this.nbParticles){var t=e.MeshBuilder.CreateDisc("",{radius:1,tessellation:3},this._scene);this.addShape(t,1),t.dispose()}this._positions32=new Float32Array(this._positions),this._uvs32=new Float32Array(this._uvs),this._colors32=new Float32Array(this._colors),e.VertexData.ComputeNormals(this._positions32,this._indices,this._normals),this._normals32=new Float32Array(this._normals),this._fixedNormal32=new Float32Array(this._normals);var i=new e.VertexData;i.set(this._positions32,e.VertexBuffer.PositionKind),i.indices=this._indices,i.set(this._normals32,e.VertexBuffer.NormalKind),this._uvs32&&i.set(this._uvs32,e.VertexBuffer.UVKind),this._colors32&&i.set(this._colors32,e.VertexBuffer.ColorKind);var n=new e.Mesh(this.name,this._scene);return i.applyToMesh(n,this._updatable),this.mesh=n,this.mesh.isPickable=this._pickable,this._positions=null,this._normals=null,this._uvs=null,this._colors=null,this._updatable||(this.particles.length=0),n},t.prototype.digest=function(t,i){var n=i&&i.facetNb||1,r=i&&i.number,o=i&&i.delta||0,s=t.getVerticesData(e.VertexBuffer.PositionKind),a=t.getIndices(),h=t.getVerticesData(e.VertexBuffer.UVKind),c=t.getVerticesData(e.VertexBuffer.ColorKind),l=0,u=a.length/3;r?(r=r>u?u:r,n=Math.round(u/r),o=0):n=n>u?u:n;for(var d=[],f=[],p=[],m=[],_=e.Tmp.Vector3[0],g=n;u>l;){n=g+Math.floor((1+o)*Math.random()),l>u-n&&(n=u-l),d.length=0,f.length=0,p.length=0,m.length=0;for(var v=0,y=3*l;3*(l+n)>y;y++){f.push(v);var x=a[y];d.push(s[3*x],s[3*x+1],s[3*x+2]),h&&p.push(h[2*x],h[2*x+1]),c&&m.push(c[4*x],c[4*x+1],c[4*x+2],c[4*x+3]),v++}var b,E=this.nbParticles,A=this._posToShape(d),T=this._uvsToShapeUV(p);for(b=0;b<A.length;b++)_.addInPlace(A[b]);for(_.scaleInPlace(1/A.length),b=0;b<A.length;b++)A[b].subtractInPlace(_);var P=new e.ModelShape(this._shapeCounter,A,T,null,null);this._meshBuilder(this._index,A,this._positions,f,this._indices,p,this._uvs,m,this._colors,E,0,null),this._addParticle(E,this._positions.length,P,this._shapeCounter,0),this.particles[this.nbParticles].position.addInPlace(_),this._index+=A.length,E++,this.nbParticles++,this._shapeCounter++,l+=n}return this},t.prototype._resetCopy=function(){this._copy.position.x=0,this._copy.position.y=0,this._copy.position.z=0,this._copy.rotation.x=0,this._copy.rotation.y=0,this._copy.rotation.z=0,this._copy.rotationQuaternion=null,this._copy.scaling.x=1,this._copy.scaling.y=1,this._copy.scaling.z=1,this._copy.uvs.x=0,this._copy.uvs.y=0,this._copy.uvs.z=1,this._copy.uvs.w=1,this._copy.color=null},t.prototype._meshBuilder=function(t,i,n,r,o,s,a,h,c,l,u,d){var f,p=0,m=0;for(this._resetCopy(),d&&d.positionFunction&&d.positionFunction(this._copy,l,u),this._copy.rotationQuaternion?this._quaternion.copyFrom(this._copy.rotationQuaternion):(this._yaw=this._copy.rotation.y,this._pitch=this._copy.rotation.x,this._roll=this._copy.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix(),f=0;f<i.length;f++)this._vertex.x=i[f].x,this._vertex.y=i[f].y,this._vertex.z=i[f].z,d&&d.vertexFunction&&d.vertexFunction(this._copy,this._vertex,f),this._vertex.x*=this._copy.scaling.x,this._vertex.y*=this._copy.scaling.y,this._vertex.z*=this._copy.scaling.z,e.Vector3.TransformCoordinatesToRef(this._vertex,this._rotMatrix,this._rotated),n.push(this._copy.position.x+this._rotated.x,this._copy.position.y+this._rotated.y,this._copy.position.z+this._rotated.z),s&&(a.push((this._copy.uvs.z-this._copy.uvs.x)*s[p]+this._copy.uvs.x,(this._copy.uvs.w-this._copy.uvs.y)*s[p+1]+this._copy.uvs.y),p+=2),this._copy.color?this._color=this._copy.color:h&&h[m]?(this._color.r=h[m],this._color.g=h[m+1],this._color.b=h[m+2],this._color.a=h[m+3]):(this._color.r=1,this._color.g=1,this._color.b=1,this._color.a=1),c.push(this._color.r,this._color.g,this._color.b,this._color.a),m+=4;for(f=0;f<r.length;f++)o.push(t+r[f]);if(this._pickable){var _=r.length/3;for(f=0;_>f;f++)this.pickedParticles.push({idx:l,faceId:f})}},t.prototype._posToShape=function(t){for(var i=[],n=0;n<t.length;n+=3)i.push(new e.Vector3(t[n],t[n+1],t[n+2]));return i},t.prototype._uvsToShapeUV=function(e){var t=[];if(e)for(var i=0;i<e.length;i++)t.push(e[i]);return t},t.prototype._addParticle=function(t,i,n,r,o){this.particles.push(new e.SolidParticle(t,i,n,r,o))},t.prototype.addShape=function(t,i,n){for(var r=t.getVerticesData(e.VertexBuffer.PositionKind),o=t.getIndices(),s=t.getVerticesData(e.VertexBuffer.UVKind),a=t.getVerticesData(e.VertexBuffer.ColorKind),h=this._posToShape(r),c=this._uvsToShapeUV(s),l=n?n.positionFunction:null,u=n?n.vertexFunction:null,d=new e.ModelShape(this._shapeCounter,h,c,l,u),f=this.nbParticles,p=0;i>p;p++)this._meshBuilder(this._index,h,this._positions,o,this._indices,s,this._uvs,a,this._colors,f,p,n),this._updatable&&this._addParticle(f,this._positions.length,d,this._shapeCounter,p),this._index+=h.length,f++;return this.nbParticles+=i,this._shapeCounter++,this._shapeCounter-1},t.prototype._rebuildParticle=function(t){this._resetCopy(),t._model._positionFunction&&t._model._positionFunction(this._copy,t.idx,t.idxInShape),this._copy.rotationQuaternion?this._quaternion.copyFrom(this._copy.rotationQuaternion):(this._yaw=this._copy.rotation.y,this._pitch=this._copy.rotation.x,this._roll=this._copy.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix(),this._shape=t._model._shape;for(var i=0;i<this._shape.length;i++)this._vertex.x=this._shape[i].x,this._vertex.y=this._shape[i].y,this._vertex.z=this._shape[i].z,t._model._vertexFunction&&t._model._vertexFunction(this._copy,this._vertex,i),this._vertex.x*=this._copy.scaling.x,this._vertex.y*=this._copy.scaling.y,this._vertex.z*=this._copy.scaling.z,e.Vector3.TransformCoordinatesToRef(this._vertex,this._rotMatrix,this._rotated),this._positions32[t._pos+3*i]=this._copy.position.x+this._rotated.x,this._positions32[t._pos+3*i+1]=this._copy.position.y+this._rotated.y,this._positions32[t._pos+3*i+2]=this._copy.position.z+this._rotated.z;t.position.x=0,t.position.y=0,t.position.z=0,t.rotation.x=0,t.rotation.y=0,t.rotation.z=0,t.rotationQuaternion=null,t.scaling.x=1,t.scaling.y=1,t.scaling.z=1},t.prototype.rebuildMesh=function(){for(var t=0;t<this.particles.length;t++)this._rebuildParticle(this.particles[t]);this.mesh.updateVerticesData(e.VertexBuffer.PositionKind,this._positions32,!1,!1)},t.prototype.setParticles=function(t,i,n){if(void 0===t&&(t=0),void 0===i&&(i=this.nbParticles-1),void 0===n&&(n=!0),this._updatable){this.beforeUpdateParticles(t,i,n),this._cam_axisX.x=1,this._cam_axisX.y=0,this._cam_axisX.z=0,this._cam_axisY.x=0,this._cam_axisY.y=1,this._cam_axisY.z=0,this._cam_axisZ.x=0,this._cam_axisZ.y=0,this._cam_axisZ.z=1,this.billboard&&(this._yaw=this.mesh.rotation.y,this._pitch=this.mesh.rotation.x,this._roll=this.mesh.rotation.z,this._quaternionRotationYPR(),this._quaternionToRotationMatrix(),this._rotMatrix.invertToRef(this._invertMatrix),e.Vector3.TransformCoordinatesToRef(this._camera.globalPosition,this._invertMatrix,this._fakeCamPos),this._fakeCamPos.subtractToRef(this.mesh.position,this._cam_axisZ),e.Vector3.CrossToRef(this._cam_axisZ,this._axisX,this._cam_axisY),e.Vector3.CrossToRef(this._cam_axisZ,this._cam_axisY,this._cam_axisX),this._cam_axisY.normalize(),this._cam_axisX.normalize(),this._cam_axisZ.normalize()),e.Matrix.IdentityToRef(this._rotMatrix);var r=0,o=0,s=0,a=0,h=0,c=0;this._computeBoundingBox&&(e.Vector3.FromFloatsToRef(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,this._minimum),e.Vector3.FromFloatsToRef(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE,this._maximum)),i=i>this.nbParticles-1?this.nbParticles-1:i;for(var l=t;i>=l;l++){this._particle=this.particles[l],this._shape=this._particle._model._shape,this._shapeUV=this._particle._model._shapeUV,this.updateParticle(this._particle),this.billboard&&(this._particle.rotation.x=0,this._particle.rotation.y=0),this._computeParticleRotation&&(this._particle.rotationQuaternion?this._quaternion.copyFrom(this._particle.rotationQuaternion):(this._yaw=this._particle.rotation.y,this._pitch=this._particle.rotation.x,this._roll=this._particle.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix());for(var u=0;u<this._shape.length;u++)r=o+3*u,s=a+4*u,h=c+2*u,this._vertex.x=this._shape[u].x,this._vertex.y=this._shape[u].y,this._vertex.z=this._shape[u].z,this._computeParticleVertex&&this.updateParticleVertex(this._particle,this._vertex,u),this._vertex.x*=this._particle.scaling.x,this._vertex.y*=this._particle.scaling.y,this._vertex.z*=this._particle.scaling.z,this._w=this._vertex.x*this._rotMatrix.m[3]+this._vertex.y*this._rotMatrix.m[7]+this._vertex.z*this._rotMatrix.m[11]+this._rotMatrix.m[15],this._rotated.x=(this._vertex.x*this._rotMatrix.m[0]+this._vertex.y*this._rotMatrix.m[4]+this._vertex.z*this._rotMatrix.m[8]+this._rotMatrix.m[12])/this._w,this._rotated.y=(this._vertex.x*this._rotMatrix.m[1]+this._vertex.y*this._rotMatrix.m[5]+this._vertex.z*this._rotMatrix.m[9]+this._rotMatrix.m[13])/this._w,this._rotated.z=(this._vertex.x*this._rotMatrix.m[2]+this._vertex.y*this._rotMatrix.m[6]+this._vertex.z*this._rotMatrix.m[10]+this._rotMatrix.m[14])/this._w,this._positions32[r]=this._particle.position.x+this._cam_axisX.x*this._rotated.x+this._cam_axisY.x*this._rotated.y+this._cam_axisZ.x*this._rotated.z,this._positions32[r+1]=this._particle.position.y+this._cam_axisX.y*this._rotated.x+this._cam_axisY.y*this._rotated.y+this._cam_axisZ.y*this._rotated.z,this._positions32[r+2]=this._particle.position.z+this._cam_axisX.z*this._rotated.x+this._cam_axisY.z*this._rotated.y+this._cam_axisZ.z*this._rotated.z,this._computeBoundingBox&&(this._positions32[r]<this._minimum.x&&(this._minimum.x=this._positions32[r]),this._positions32[r]>this._maximum.x&&(this._maximum.x=this._positions32[r]),this._positions32[r+1]<this._minimum.y&&(this._minimum.y=this._positions32[r+1]),this._positions32[r+1]>this._maximum.y&&(this._maximum.y=this._positions32[r+1]),this._positions32[r+2]<this._minimum.z&&(this._minimum.z=this._positions32[r+2]),this._positions32[r+2]>this._maximum.z&&(this._maximum.z=this._positions32[r+2])),this._computeParticleVertex||this.billboard||(this._normal.x=this._fixedNormal32[r],this._normal.y=this._fixedNormal32[r+1],this._normal.z=this._fixedNormal32[r+2],this._w=this._normal.x*this._rotMatrix.m[3]+this._normal.y*this._rotMatrix.m[7]+this._normal.z*this._rotMatrix.m[11]+this._rotMatrix.m[15],this._rotated.x=(this._normal.x*this._rotMatrix.m[0]+this._normal.y*this._rotMatrix.m[4]+this._normal.z*this._rotMatrix.m[8]+this._rotMatrix.m[12])/this._w,this._rotated.y=(this._normal.x*this._rotMatrix.m[1]+this._normal.y*this._rotMatrix.m[5]+this._normal.z*this._rotMatrix.m[9]+this._rotMatrix.m[13])/this._w,this._rotated.z=(this._normal.x*this._rotMatrix.m[2]+this._normal.y*this._rotMatrix.m[6]+this._normal.z*this._rotMatrix.m[10]+this._rotMatrix.m[14])/this._w,this._normals32[r]=this._cam_axisX.x*this._rotated.x+this._cam_axisY.x*this._rotated.y+this._cam_axisZ.x*this._rotated.z,this._normals32[r+1]=this._cam_axisX.y*this._rotated.x+this._cam_axisY.y*this._rotated.y+this._cam_axisZ.y*this._rotated.z,this._normals32[r+2]=this._cam_axisX.z*this._rotated.x+this._cam_axisY.z*this._rotated.y+this._cam_axisZ.z*this._rotated.z),this._computeParticleColor&&(this._colors32[s]=this._particle.color.r,this._colors32[s+1]=this._particle.color.g,this._colors32[s+2]=this._particle.color.b,this._colors32[s+3]=this._particle.color.a),this._computeParticleTexture&&(this._uvs32[h]=this._shapeUV[2*u]*(this._particle.uvs.z-this._particle.uvs.x)+this._particle.uvs.x,this._uvs32[h+1]=this._shapeUV[2*u+1]*(this._particle.uvs.w-this._particle.uvs.y)+this._particle.uvs.y);o=r+3,a=s+4,c=h+2}if(n&&(this._computeParticleColor&&this.mesh.updateVerticesData(e.VertexBuffer.ColorKind,this._colors32,!1,!1),this._computeParticleTexture&&this.mesh.updateVerticesData(e.VertexBuffer.UVKind,this._uvs32,!1,!1),this.mesh.updateVerticesData(e.VertexBuffer.PositionKind,this._positions32,!1,!1),!this.mesh.areNormalsFrozen)){if(this._computeParticleVertex||this.billboard){e.VertexData.ComputeNormals(this._positions32,this._indices,this._normals32);for(var d=0;d<this._normals32.length;d++)this._fixedNormal32[d]=this._normals32[d]}this.mesh.updateVerticesData(e.VertexBuffer.NormalKind,this._normals32,!1,!1)}this._computeBoundingBox&&(this.mesh._boundingInfo=new e.BoundingInfo(this._minimum,this._maximum),this.mesh._boundingInfo.update(this.mesh._worldMatrix)),this.afterUpdateParticles(t,i,n)}},t.prototype._quaternionRotationYPR=function(){this._halfroll=.5*this._roll,this._halfpitch=.5*this._pitch,this._halfyaw=.5*this._yaw,this._sinRoll=Math.sin(this._halfroll),this._cosRoll=Math.cos(this._halfroll),this._sinPitch=Math.sin(this._halfpitch),this._cosPitch=Math.cos(this._halfpitch),this._sinYaw=Math.sin(this._halfyaw),this._cosYaw=Math.cos(this._halfyaw),this._quaternion.x=this._cosYaw*this._sinPitch*this._cosRoll+this._sinYaw*this._cosPitch*this._sinRoll,this._quaternion.y=this._sinYaw*this._cosPitch*this._cosRoll-this._cosYaw*this._sinPitch*this._sinRoll,this._quaternion.z=this._cosYaw*this._cosPitch*this._sinRoll-this._sinYaw*this._sinPitch*this._cosRoll,this._quaternion.w=this._cosYaw*this._cosPitch*this._cosRoll+this._sinYaw*this._sinPitch*this._sinRoll},t.prototype._quaternionToRotationMatrix=function(){this._rotMatrix.m[0]=1-2*(this._quaternion.y*this._quaternion.y+this._quaternion.z*this._quaternion.z),this._rotMatrix.m[1]=2*(this._quaternion.x*this._quaternion.y+this._quaternion.z*this._quaternion.w),this._rotMatrix.m[2]=2*(this._quaternion.z*this._quaternion.x-this._quaternion.y*this._quaternion.w),this._rotMatrix.m[3]=0,this._rotMatrix.m[4]=2*(this._quaternion.x*this._quaternion.y-this._quaternion.z*this._quaternion.w),this._rotMatrix.m[5]=1-2*(this._quaternion.z*this._quaternion.z+this._quaternion.x*this._quaternion.x),this._rotMatrix.m[6]=2*(this._quaternion.y*this._quaternion.z+this._quaternion.x*this._quaternion.w),this._rotMatrix.m[7]=0,this._rotMatrix.m[8]=2*(this._quaternion.z*this._quaternion.x+this._quaternion.y*this._quaternion.w),this._rotMatrix.m[9]=2*(this._quaternion.y*this._quaternion.z-this._quaternion.x*this._quaternion.w),this._rotMatrix.m[10]=1-2*(this._quaternion.y*this._quaternion.y+this._quaternion.x*this._quaternion.x),this._rotMatrix.m[11]=0,this._rotMatrix.m[12]=0,this._rotMatrix.m[13]=0,this._rotMatrix.m[14]=0,this._rotMatrix.m[15]=1},t.prototype.dispose=function(){this.mesh.dispose(),this.vars=null,this._positions=null,this._indices=null,this._normals=null,this._uvs=null,this._colors=null,this._positions32=null,this._normals32=null,this._fixedNormal32=null,this._uvs32=null,this._colors32=null,this.pickedParticles=null},t.prototype.refreshVisibleSize=function(){this._isVisibilityBoxLocked||this.mesh.refreshBoundingInfo()},t.prototype.setVisibilityBox=function(t){var i=t/2;this.mesh._boundingInfo=new e.BoundingInfo(new e.Vector3(-i,-i,-i),new e.Vector3(i,i,i))},Object.defineProperty(t.prototype,"isAlwaysVisible",{get:function(){return this._alwaysVisible},set:function(e){this._alwaysVisible=e,this.mesh.alwaysSelectAsActiveMesh=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isVisibilityBoxLocked",{get:function(){return this._isVisibilityBoxLocked},set:function(e){this._isVisibilityBoxLocked=e,this.mesh.getBoundingInfo().isLocked=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"computeParticleRotation",{get:function(){return this._computeParticleRotation},set:function(e){this._computeParticleRotation=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"computeParticleColor",{get:function(){return this._computeParticleColor},set:function(e){this._computeParticleColor=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"computeParticleTexture",{get:function(){return this._computeParticleTexture},set:function(e){this._computeParticleTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"computeParticleVertex",{get:function(){return this._computeParticleVertex},set:function(e){this._computeParticleVertex=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"computeBoundingBox",{get:function(){return this._computeBoundingBox},set:function(e){this._computeBoundingBox=e},enumerable:!0,configurable:!0}),t.prototype.initParticles=function(){},t.prototype.recycleParticle=function(e){return e},t.prototype.updateParticle=function(e){return e},t.prototype.updateParticleVertex=function(e,t,i){return t},t.prototype.beforeUpdateParticles=function(e,t,i){},t.prototype.afterUpdateParticles=function(e,t,i){},t}();e.SolidParticleSystem=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){var i=function(){function e(e,t,i,n){this.name=e,this.worldAxisForNormal=t,this.worldAxisForFileX=i,this.worldAxisForFileY=n}return e}(),n=function(){function t(){}return t.ConvertCubeMapToSphericalPolynomial=function(t){for(var i=new e.SphericalHarmonics,n=0,r=2/t.size,o=r,s=.5*r-1,a=0;6>a;a++)for(var h=this.FileFaces[a],c=t[h.name],l=s,u=0;u<t.size;u++){for(var d=s,f=0;f<t.size;f++){var p=h.worldAxisForFileX.scale(d).add(h.worldAxisForFileY.scale(l)).add(h.worldAxisForNormal);p.normalize();var m,_=Math.pow(1+d*d+l*l,-1.5),g=c[u*t.size*3+3*f+0],v=c[u*t.size*3+3*f+1],y=c[u*t.size*3+3*f+2],m=new e.Color3(g,v,y);i.addLight(p,m,_),n+=_,d+=r}l+=o}var x=4*Math.PI,b=x/n;return i.scale(b),i.scale(1/Math.PI),e.SphericalPolynomial.getSphericalPolynomialFromHarmonics(i)},t.FileFaces=[new i("right",new e.Vector3(1,0,0),new e.Vector3(0,0,-1),new e.Vector3(0,-1,0)),new i("left",new e.Vector3(-1,0,0),new e.Vector3(0,0,1),new e.Vector3(0,-1,0)),new i("up",new e.Vector3(0,1,0),new e.Vector3(1,0,0),new e.Vector3(0,0,1)),new i("down",new e.Vector3(0,-1,0),new e.Vector3(1,0,0),new e.Vector3(0,0,-1)),new i("front",new e.Vector3(0,0,1),new e.Vector3(1,0,0),new e.Vector3(0,-1,0)),new i("back",new e.Vector3(0,0,-1),new e.Vector3(-1,0,0),new e.Vector3(0,-1,0))],t}();t.CubeMapToSphericalPolynomialTools=n}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){var i=function(){function t(){}return t.ConvertPanoramaToCubemap=function(e,t,i,n){if(!e)throw"ConvertPanoramaToCubemap: input cannot be null";if(e.length!=t*i*3)throw"ConvertPanoramaToCubemap: input size is wrong";var r=this.CreateCubemapTexture(n,this.FACE_FRONT,e,t,i),o=this.CreateCubemapTexture(n,this.FACE_BACK,e,t,i),s=this.CreateCubemapTexture(n,this.FACE_LEFT,e,t,i),a=this.CreateCubemapTexture(n,this.FACE_RIGHT,e,t,i),h=this.CreateCubemapTexture(n,this.FACE_UP,e,t,i),c=this.CreateCubemapTexture(n,this.FACE_DOWN,e,t,i);return{front:r,back:o,left:s,right:a,up:h,down:c,size:n}},t.CreateCubemapTexture=function(e,t,i,n,r){for(var o=new ArrayBuffer(e*e*4*3),s=new Float32Array(o),a=t[1].subtract(t[0]).scale(1/e),h=t[3].subtract(t[2]).scale(1/e),c=1/e,l=0,u=0;e>u;u++){for(var d=t[0],f=t[2],p=0;e>p;p++){var m=f.subtract(d).scale(l).add(d);m.normalize();var _=this.CalcProjectionSpherical(m,i,n,r);s[u*e*3+3*p+0]=_.r,s[u*e*3+3*p+1]=_.g,s[u*e*3+3*p+2]=_.b,d=d.add(a),f=f.add(h)}l+=c}return s},t.CalcProjectionSpherical=function(e,t,i,n){for(var r=Math.atan2(e.z,e.x),o=Math.acos(e.y);r<-Math.PI;)r+=2*Math.PI;for(;r>Math.PI;)r-=2*Math.PI;var s=r/Math.PI,a=o/Math.PI;s=.5*s+.5;var h=Math.round(s*i);0>h?h=0:h>=i&&(h=i-1);var c=Math.round(a*n);0>c?c=0:c>=n&&(c=n-1);var l=n-c-1,u=t[l*i*3+3*h+0],d=t[l*i*3+3*h+1],f=t[l*i*3+3*h+2];return{r:u,g:d,b:f}},t.FACE_FRONT=[new e.Vector3(-1,-1,-1),new e.Vector3(1,-1,-1),new e.Vector3(-1,1,-1),new e.Vector3(1,1,-1)],t.FACE_BACK=[new e.Vector3(1,-1,1),new e.Vector3(-1,-1,1),new e.Vector3(1,1,1),new e.Vector3(-1,1,1)],t.FACE_RIGHT=[new e.Vector3(1,-1,-1),new e.Vector3(1,-1,1),new e.Vector3(1,1,-1),new e.Vector3(1,1,1)],t.FACE_LEFT=[new e.Vector3(-1,-1,1),new e.Vector3(-1,-1,-1),new e.Vector3(-1,1,1),new e.Vector3(-1,1,-1)],t.FACE_DOWN=[new e.Vector3(-1,1,-1),new e.Vector3(1,1,-1),new e.Vector3(-1,1,1),new e.Vector3(1,1,1)],t.FACE_UP=[new e.Vector3(-1,-1,1),new e.Vector3(1,-1,1),new e.Vector3(-1,-1,-1),new e.Vector3(1,-1,-1)],t}();t.PanoramaToCubeMapTools=i}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(e){var t=function(){function t(){}return t.Ldexp=function(e,t){return t>1023?e*Math.pow(2,1023)*Math.pow(2,t-1023):-1074>t?e*Math.pow(2,-1074)*Math.pow(2,t+1074):e*Math.pow(2,t)},t.Rgbe2float=function(e,t,i,n,r,o){r>0?(r=this.Ldexp(1,r-136),e[o+0]=t*r,e[o+1]=i*r,e[o+2]=n*r):(e[o+0]=0,e[o+1]=0,e[o+2]=0)},t.readStringLine=function(e,t){for(var i="",n="",r=t;r<e.length-t&&(n=String.fromCharCode(e[r]),"\n"!=n);r++)i+=n;return i},t.RGBE_ReadHeader=function(e){var t=0,i=0,n=this.readStringLine(e,0);if("#"!=n[0]||"?"!=n[1])throw"Bad HDR Format.";var r=!1,o=!1,s=0;do s+=n.length+1,n=this.readStringLine(e,s),"FORMAT=32-bit_rle_rgbe"==n?o=!0:0==n.length&&(r=!0);while(!r);if(!o)throw"HDR Bad header format, unsupported FORMAT";s+=n.length+1,n=this.readStringLine(e,s);var a=/^\-Y (.*) \+X (.*)$/g,h=a.exec(n);if(h.length<3)throw"HDR Bad header format, no size";if(i=parseInt(h[2]),t=parseInt(h[1]),8>i||i>32767)throw"HDR Bad header format, unsupported size";return s+=n.length+1,{height:t,width:i,dataPosition:s}},t.GetCubeMapTextureData=function(t,i){var n=new Uint8Array(t),r=this.RGBE_ReadHeader(n),o=this.RGBE_ReadPixels_RLE(n,r),s=e.PanoramaToCubeMapTools.ConvertPanoramaToCubemap(o,r.width,r.height,i);return s},t.RGBE_ReadPixels=function(e,t){return this.RGBE_ReadPixels_RLE(e,t)},t.RGBE_ReadPixels_RLE=function(e,t){for(var i,n,r,o,s,a=t.height,h=t.width,c=t.dataPosition,l=0,u=0,d=0,f=new ArrayBuffer(4*h),p=new Uint8Array(f),m=new ArrayBuffer(t.width*t.height*4*3),_=new Float32Array(m);a>0;){if(i=e[c++],n=e[c++],r=e[c++],o=e[c++],2!=i||2!=n||128&r)throw"HDR Bad header format, not RLE";if((r<<8|o)!=h)throw"HDR Bad header format, wrong scan line width";for(l=0,d=0;4>d;d++)for(u=(d+1)*h;u>l;)if(i=e[c++],n=e[c++],i>128){if(s=i-128,0==s||s>u-l)throw"HDR Bad Format, bad scanline data (run)";for(;s-- >0;)p[l++]=n}else{if(s=i,0==s||s>u-l)throw"HDR Bad Format, bad scanline data (non-run)";if(p[l++]=n,--s>0)for(var g=0;s>g;g++)p[l++]=e[c++]}for(d=0;h>d;d++)i=p[d],n=p[d+h],r=p[d+2*h],o=p[d+3*h],this.Rgbe2float(_,i,n,r,o,(t.height-a)*h*3+3*d);a--}return _},t}();e.HDRTools=t}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){var i=function(){function t(){this.min=new e.Vector3(0,0,0),this.max=new e.Vector3(0,0,0),this.clear()}return t.prototype.clear=function(){this.min.x=t.MAX,this.min.y=t.MAX,this.min.z=t.MAX,this.max.x=t.MIN,this.max.y=t.MIN,this.max.z=t.MIN},t.prototype.augment=function(e,t,i){this.min.x=Math.min(this.min.x,e),this.min.y=Math.min(this.min.y,t),this.min.z=Math.min(this.min.z,i),this.max.x=Math.max(this.max.x,e),this.max.y=Math.max(this.max.y,t),this.max.z=Math.max(this.max.z,i)},t.prototype.clampMin=function(e,t,i){this.min.x=Math.max(this.min.x,e),this.min.y=Math.max(this.min.y,t),this.min.z=Math.max(this.min.z,i)},t.prototype.clampMax=function(e,t,i){this.max.x=Math.min(this.max.x,e),this.max.y=Math.min(this.max.y,t),this.max.z=Math.min(this.max.z,i)},t.prototype.empty=function(){return this.min.x>this.max.y||this.min.y>this.max.y||this.min.z>this.max.y},t.MAX=Number.MAX_VALUE,t.MIN=Number.MIN_VALUE,t}(),n=function(){function t(e,t,i,n,r,o,s,a,h,c){this.input=e,this.inputSize=t,this.outputSize=i,this.maxNumMipLevels=n,this.numChannels=r,this.isFloat=o,this.specularPower=s,this.cosinePowerDropPerMip=a,this.excludeBase=h,this.fixup=c,this._outputSurface=[],this._numMipLevels=0}return t.prototype.filterCubeMap=function(){return this.init(),this.filterCubeMapMipChain(),this._outputSurface},t.prototype.init=function(){var e,i,n;for(0==this.maxNumMipLevels&&(this.maxNumMipLevels=t.CP_MAX_MIPLEVELS),n=this.outputSize,i=0;i<this.maxNumMipLevels;i++){for(this._outputSurface.length++,this._outputSurface[i]=[],e=0;6>e;e++)this._outputSurface[i].length++,this.isFloat?this._outputSurface[i][e]=new Float32Array(n*n*this.numChannels):this._outputSurface[i][e]=new Uint32Array(n*n*this.numChannels);if(n>>=1,this._numMipLevels++,0==n)return void(this.maxNumMipLevels=i)}},t.prototype.filterCubeMapMipChain=function(){var e=this.specularPower;this.precomputeFilterLookupTables(this.inputSize);for(var t=0;t<this._numMipLevels;t++){this.excludeBase&&0==t&&(e=1e5);var i=this.input,n=this._outputSurface[t],r=this.outputSize>>t,o=this.getBaseFilterAngle(e);this.filterCubeSurfaces(i,this.inputSize,n,r,o,e),this.fixup&&this.fixupCubeEdges(n,r),this.excludeBase&&0==t&&(e=this.specularPower),e*=this.cosinePowerDropPerMip}},t.prototype.getBaseFilterAngle=function(e){var t=1e-6,i=180;return i=Math.acos(Math.pow(t,1/e)),i*=180/Math.PI,i*=2},t.prototype.precomputeFilterLookupTables=function(e){this._normCubeMap=[],this.buildNormalizerSolidAngleCubemap(e)},t.prototype.buildNormalizerSolidAngleCubemap=function(e){var t,i,n;for(t=0;6>t;t++){this._normCubeMap.push(new Float32Array(e*e*4));this.input[t];for(n=0;e>n;n++)for(i=0;e>i;i++){var r=this.texelCoordToVect(t,i,n,e,this.fixup);this._normCubeMap[t][4*(n*e+i)+0]=r.x,this._normCubeMap[t][4*(n*e+i)+1]=r.y,this._normCubeMap[t][4*(n*e+i)+2]=r.z;var o=this.texelCoordSolidAngle(t,i,n,e);this._normCubeMap[t][4*(n*e+i)+4]=o}}},t.prototype.texelCoordToVect=function(e,i,n,r,o){var s,a;if(s=2*(i+.5)/r-1,a=2*(n+.5)/r-1,o&&r>1){var h=Math.pow(r,2)/Math.pow(r-1,3);s=h*Math.pow(s,3)+s,a=h*Math.pow(a,3)+a}var c=t._sgFace2DMapping[e][t.CP_UDIR];t._vectorTemp.x=c[0]*s,t._vectorTemp.y=c[1]*s,t._vectorTemp.z=c[2]*s;var l=t._sgFace2DMapping[e][t.CP_VDIR];t._vectorTemp.x+=l[0]*a,t._vectorTemp.y+=l[1]*a,t._vectorTemp.z+=l[2]*a;var u=t._sgFace2DMapping[e][t.CP_FACEAXIS];return t._vectorTemp.x+=u[0],t._vectorTemp.y+=u[1],t._vectorTemp.z+=u[2],t._vectorTemp.normalize(),t._vectorTemp},t.prototype.vectToTexelCoord=function(e,i,n,r){var o,s,a=Math.abs(e),h=Math.abs(i),c=Math.abs(n);a>=h&&a>=c?(o=a,s=e>=0?t.CP_FACE_X_POS:t.CP_FACE_X_NEG):h>=a&&h>=c?(o=h,s=i>=0?t.CP_FACE_Y_POS:t.CP_FACE_Y_NEG):(o=c,s=n>=0?t.CP_FACE_Z_POS:t.CP_FACE_Z_NEG);var l=1/o;e*=l,i*=l,n*=l;var u=t._sgFace2DMapping[s][t.CP_UDIR],d=u[0]*e+u[1]*i+u[2]*n;u=t._sgFace2DMapping[s][t.CP_VDIR];var f=u[0]*e+u[1]*i+u[2]*n,p=Math.floor(.5*(r-1)*(d+1)),m=Math.floor(.5*(r-1)*(f+1));return t._vectorTemp.x=s,t._vectorTemp.y=p,t._vectorTemp.z=m,t._vectorTemp},t.prototype.areaElement=function(e,t){return Math.atan2(e*t,Math.sqrt(e*e+t*t+1))},t.prototype.texelCoordSolidAngle=function(e,t,i,n){t=2*(t+.5)/n-1,i=2*(i+.5)/n-1;var r=1/n,o=t-r,s=i-r,a=t+r,h=i+r,c=this.areaElement(o,s)-this.areaElement(o,h)-this.areaElement(a,s)+this.areaElement(a,h);return c},t.prototype.filterCubeSurfaces=function(e,t,n,r,o,s){var a,h,c,l=[];for(a=0;6>a;a++)l.push(new i);var u=180/Math.PI*Math.atan2(1,t),d=o/2;u>d&&(d=u),d>90&&(d=90);var f=Math.ceil(d/u);1>f&&(f=1);var p=Math.cos(Math.PI/180*d);for(a=0;6>a;a++)for(c=0;r>c;c++)for(h=0;r>h;h++){var m=this.texelCoordToVect(a,h,c,r,this.fixup).clone();this.clearFilterExtents(l),this.determineFilterExtents(m,t,f,l);var _=this.processFilterExtents(m,p,l,e,t,s);n[a][(c*r+h)*this.numChannels+0]=_.x,n[a][(c*r+h)*this.numChannels+1]=_.y,n[a][(c*r+h)*this.numChannels+2]=_.z}},t.prototype.clearFilterExtents=function(e){for(var t=0;6>t;t++)e[t].clear()},t.prototype.determineFilterExtents=function(e,i,n,r){var o,s,a,h=[0,0,0,0],c=[0,0,0,0],l=[0,0,0,0],u=this.vectToTexelCoord(e.x,e.y,e.z,i),d=u.x,f=u.y,p=u.z;r[d].augment(f-n,p-n,0),r[d].augment(f+n,p+n,0),r[d].clampMin(0,0,0),r[d].clampMax(i-1,i-1,0);var m=r[d].min.x,_=r[d].min.y,g=r[d].max.x,v=r[d].max.y;h[0]=n-f,c[0]=_,l[0]=v,h[1]=f+n-(i-1),c[1]=_,l[1]=v,h[2]=n-p,c[2]=m,l[2]=g,h[3]=p+n-(i-1),c[3]=m,l[3]=g;for(var y=0;4>y;y++){if(h[y]>0){switch(o=t._sgCubeNgh[d][y][0],s=t._sgCubeNgh[d][y][1],y!=s&&y+s!=3||(c[y]=i-1-c[y],l[y]=i-1-l[y]),t._sgCubeNgh[d][y][1]){case t.CP_EDGE_LEFT:r[o].augment(0,c[y],0),r[o].augment(h[y],l[y],0);break;case t.CP_EDGE_RIGHT:r[o].augment(i-1,c[y],0),r[o].augment(i-1-h[y],l[y],0);break;case t.CP_EDGE_TOP:r[o].augment(c[y],0,0),r[o].augment(l[y],h[y],0);break;case t.CP_EDGE_BOTTOM:r[o].augment(c[y],i-1,0),r[o].augment(l[y],i-1-h[y],0)}r[o].clampMin(0,0,0),r[o].clampMax(i-1,i-1,0)}if(h[y]>i){switch(d){case t.CP_FACE_X_POS:a=t.CP_FACE_X_NEG;break;case t.CP_FACE_X_NEG:a=t.CP_FACE_X_POS;break;case t.CP_FACE_Y_POS:a=t.CP_FACE_Y_NEG;break;case t.CP_FACE_Y_NEG:a=t.CP_FACE_Y_POS;break;case t.CP_FACE_Z_POS:a=t.CP_FACE_Z_NEG;break;case t.CP_FACE_Z_NEG:a=t.CP_FACE_Z_POS}r[a].augment(0,0,0),r[a].augment(i-1,i-1,0)}}},t.prototype.processFilterExtents=function(e,i,n,r,o,s){for(var a=[0,0,0,0],h=0,c=0,l=this.numChannels,u=o,d=4*u,f=u*this.numChannels,p=1,m=0;6>m;m++)if(!n[m].empty())for(var _=n[m].min.x,g=n[m].min.y,v=n[m].max.x,y=n[m].max.y,x=4*(g*u+_),b=this.numChannels*(g*u+_),E=g;y>=E;E++){for(var A=0,T=0,P=_;v>=P;P++){var M=this._normCubeMap[m][x+A+0],C=this._normCubeMap[m][x+A+1],S=this._normCubeMap[m][x+A+2],R=M*e.x+C*e.y+S*e.z;if(R>=i&&R>0){var I=this._normCubeMap[m][x+A+3];for(I*=Math.pow(R,s+p),c=0;l>c;c++)a[c]+=I*r[m][b+T],T++;h+=I}else T+=l;A+=4}x+=d,b+=f}if(0!=h)t._vectorTemp.x=a[0]/h,t._vectorTemp.y=a[1]/h,t._vectorTemp.z=a[2]/h,this.numChannels>3&&(t._vectorTemp.w=a[3]/h);else{var D=this.vectToTexelCoord(e.x,e.y,e.z,o).clone();t._vectorTemp.x=r[D.x][this.numChannels*(D.z*o+D.y)+0],t._vectorTemp.y=r[D.x][this.numChannels*(D.z*o+D.y)+1],t._vectorTemp.z=r[D.x][this.numChannels*(D.z*o+D.y)+2],this.numChannels>3&&(t._vectorTemp.z=r[D.x][this.numChannels*(D.z*o+D.y)+3])}return t._vectorTemp},t.prototype.fixupCubeEdges=function(e,i){var n,r,o,s,a=0,h=[0,0,0,0,0,0,0,0],c=[[],[],[],[]],l=[[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]]];if(!(1>i))if(1!=i){for(s=0;6>s;s++)for(c[0]=[s,0],c[1]=[s,(i-1)*this.numChannels],c[2]=[s,i*(i-1)*this.numChannels],c[3]=[s,(i*(i-1)+(i-1))*this.numChannels],a=0;4>a;a++){var u=t._sgCubeCornerList[s][a];l[u][h[u]]=c[a],h[u]++}for(a=0;8>a;a++)for(n=0;n<this.numChannels;n++){var d=0;for(o=0;3>o;o++)d+=e[l[a][o][0]][l[a][o][1]+n];
  28. for(d*=1/3,o=0;3>o;o++)e[l[a][o][0]][l[a][o][1]+n]=d}for(o=0;12>o;o++){var f=t._sgCubeEdgeList[o][0],p=t._sgCubeEdgeList[o][1],m=t._sgCubeNgh[f][p][0],_=t._sgCubeNgh[f][p][1],g=0,v=0,y=0,x=0;switch(p){case t.CP_EDGE_LEFT:y=this.numChannels*i;break;case t.CP_EDGE_RIGHT:g+=(i-1)*this.numChannels,y=this.numChannels*i;break;case t.CP_EDGE_TOP:y=this.numChannels;break;case t.CP_EDGE_BOTTOM:g+=i*(i-1)*this.numChannels,y=this.numChannels}if(p==_||p+_==3)switch(_){case t.CP_EDGE_LEFT:v+=(i-1)*i*this.numChannels,x=-(this.numChannels*i);break;case t.CP_EDGE_RIGHT:v+=((i-1)*i+(i-1))*this.numChannels,x=-(this.numChannels*i);break;case t.CP_EDGE_TOP:v+=(i-1)*this.numChannels,x=-this.numChannels;break;case t.CP_EDGE_BOTTOM:v+=((i-1)*i+(i-1))*this.numChannels,x=-this.numChannels}else switch(_){case t.CP_EDGE_LEFT:x=this.numChannels*i;break;case t.CP_EDGE_RIGHT:v+=(i-1)*this.numChannels,x=this.numChannels*i;break;case t.CP_EDGE_TOP:x=this.numChannels;break;case t.CP_EDGE_BOTTOM:v+=i*(i-1)*this.numChannels,x=this.numChannels}for(g+=y,v+=x,r=1;i-1>r;r++){for(n=0;n<this.numChannels;n++){var b=e[f][g+n],E=e[m][v+n],A=.5*(b+E);e[f][g+n]=A,e[m][v+n]=A}g+=y,v+=x}}}else for(n=0;n<this.numChannels;n++){var T=0;for(s=0;6>s;s++)T+=e[s][n];for(T/=6,s=0;6>s;s++)e[s][n]=T}},t.CP_MAX_MIPLEVELS=16,t.CP_UDIR=0,t.CP_VDIR=1,t.CP_FACEAXIS=2,t.CP_FACE_X_POS=0,t.CP_FACE_X_NEG=1,t.CP_FACE_Y_POS=2,t.CP_FACE_Y_NEG=3,t.CP_FACE_Z_POS=4,t.CP_FACE_Z_NEG=5,t.CP_EDGE_LEFT=0,t.CP_EDGE_RIGHT=1,t.CP_EDGE_TOP=2,t.CP_EDGE_BOTTOM=3,t.CP_CORNER_NNN=0,t.CP_CORNER_NNP=1,t.CP_CORNER_NPN=2,t.CP_CORNER_NPP=3,t.CP_CORNER_PNN=4,t.CP_CORNER_PNP=5,t.CP_CORNER_PPN=6,t.CP_CORNER_PPP=7,t._vectorTemp=new e.Vector4(0,0,0,0),t._sgFace2DMapping=[[[0,0,-1],[0,-1,0],[1,0,0]],[[0,0,1],[0,-1,0],[-1,0,0]],[[1,0,0],[0,0,1],[0,1,0]],[[1,0,0],[0,0,-1],[0,-1,0]],[[1,0,0],[0,-1,0],[0,0,1]],[[-1,0,0],[0,-1,0],[0,0,-1]]],t._sgCubeNgh=[[[t.CP_FACE_Z_POS,t.CP_EDGE_RIGHT],[t.CP_FACE_Z_NEG,t.CP_EDGE_LEFT],[t.CP_FACE_Y_POS,t.CP_EDGE_RIGHT],[t.CP_FACE_Y_NEG,t.CP_EDGE_RIGHT]],[[t.CP_FACE_Z_NEG,t.CP_EDGE_RIGHT],[t.CP_FACE_Z_POS,t.CP_EDGE_LEFT],[t.CP_FACE_Y_POS,t.CP_EDGE_LEFT],[t.CP_FACE_Y_NEG,t.CP_EDGE_LEFT]],[[t.CP_FACE_X_NEG,t.CP_EDGE_TOP],[t.CP_FACE_X_POS,t.CP_EDGE_TOP],[t.CP_FACE_Z_NEG,t.CP_EDGE_TOP],[t.CP_FACE_Z_POS,t.CP_EDGE_TOP]],[[t.CP_FACE_X_NEG,t.CP_EDGE_BOTTOM],[t.CP_FACE_X_POS,t.CP_EDGE_BOTTOM],[t.CP_FACE_Z_POS,t.CP_EDGE_BOTTOM],[t.CP_FACE_Z_NEG,t.CP_EDGE_BOTTOM]],[[t.CP_FACE_X_NEG,t.CP_EDGE_RIGHT],[t.CP_FACE_X_POS,t.CP_EDGE_LEFT],[t.CP_FACE_Y_POS,t.CP_EDGE_BOTTOM],[t.CP_FACE_Y_NEG,t.CP_EDGE_TOP]],[[t.CP_FACE_X_POS,t.CP_EDGE_RIGHT],[t.CP_FACE_X_NEG,t.CP_EDGE_LEFT],[t.CP_FACE_Y_POS,t.CP_EDGE_TOP],[t.CP_FACE_Y_NEG,t.CP_EDGE_BOTTOM]]],t._sgCubeEdgeList=[[t.CP_FACE_X_POS,t.CP_EDGE_LEFT],[t.CP_FACE_X_POS,t.CP_EDGE_RIGHT],[t.CP_FACE_X_POS,t.CP_EDGE_TOP],[t.CP_FACE_X_POS,t.CP_EDGE_BOTTOM],[t.CP_FACE_X_NEG,t.CP_EDGE_LEFT],[t.CP_FACE_X_NEG,t.CP_EDGE_RIGHT],[t.CP_FACE_X_NEG,t.CP_EDGE_TOP],[t.CP_FACE_X_NEG,t.CP_EDGE_BOTTOM],[t.CP_FACE_Z_POS,t.CP_EDGE_TOP],[t.CP_FACE_Z_POS,t.CP_EDGE_BOTTOM],[t.CP_FACE_Z_NEG,t.CP_EDGE_TOP],[t.CP_FACE_Z_NEG,t.CP_EDGE_BOTTOM]],t._sgCubeCornerList=[[t.CP_CORNER_PPP,t.CP_CORNER_PPN,t.CP_CORNER_PNP,t.CP_CORNER_PNN],[t.CP_CORNER_NPN,t.CP_CORNER_NPP,t.CP_CORNER_NNN,t.CP_CORNER_NNP],[t.CP_CORNER_NPN,t.CP_CORNER_PPN,t.CP_CORNER_NPP,t.CP_CORNER_PPP],[t.CP_CORNER_NNP,t.CP_CORNER_PNP,t.CP_CORNER_NNN,t.CP_CORNER_PNN],[t.CP_CORNER_NPP,t.CP_CORNER_PPP,t.CP_CORNER_NNP,t.CP_CORNER_PNP],[t.CP_CORNER_PPN,t.CP_CORNER_NPN,t.CP_CORNER_PNN,t.CP_CORNER_NNN]],t}();t.PMREMGenerator=n}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,n,r,o,s,a,h){void 0===o&&(o=!1),void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=!1),t.call(this,n),this._useInGammaSpace=!1,this._generateHarmonics=!0,this.coordinatesMode=e.Texture.CUBIC_MODE,this.sphericalPolynomial=null,this.isPMREM=!1,this.name=i,this.url=i,this._noMipmap=o,this.hasAlpha=!1,this._size=r,this._useInGammaSpace=a,this._usePMREMGenerator=h&&n.getEngine().getCaps().textureLOD,this.isPMREM=this._usePMREMGenerator,i&&(this._texture=this._getFromCache(i,o),this._texture||(n.useDelayedTextureLoading?this.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:this.loadTexture()),this.isCube=!0,this._textureMatrix=e.Matrix.Identity())}return __extends(i,t),i.prototype.loadTexture=function(){var t=this,n=function(n){var r=e.Internals.HDRTools.GetCubeMapTextureData(n,t._size);t._generateHarmonics&&(t.sphericalPolynomial=e.Internals.CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(r));var o=[],s=null;if(!t.getScene().getEngine().getCaps().textureFloat){var a=new ArrayBuffer(t._size*t._size*3);s=new Uint8Array(a)}for(var h=0;6>h;h++){var c=r[i._facesMapping[h]];if(t._useInGammaSpace||s)for(var l=0;l<t._size*t._size;l++)t._useInGammaSpace&&(c[3*l+0]=Math.pow(c[3*l+0],e.ToGammaSpace),c[3*l+1]=Math.pow(c[3*l+1],e.ToGammaSpace),c[3*l+2]=Math.pow(c[3*l+2],e.ToGammaSpace)),s&&(s[3*l+0]=255*c[3*l+0],s[3*l+0]=Math.min(255,s[3*l+0]),s[3*l+1]=255*c[3*l+1],s[3*l+1]=Math.min(255,s[3*l+1]),s[3*l+2]=255*c[3*l+2],s[3*l+2]=Math.min(255,s[3*l+2]));o.push(c)}return o},r=null;!this._noMipmap&&this._usePMREMGenerator&&(r=function(i){var n=new e.Internals.PMREMGenerator(i,t._size,t._size,0,3,t.getScene().getEngine().getCaps().textureFloat,2048,.25,!1,!0);return n.filterCubeMap()}),this._texture=this.getScene().getEngine().createRawCubeTexture(this.url,this.getScene(),this._size,e.Engine.TEXTUREFORMAT_RGB,e.Engine.TEXTURETYPE_FLOAT,this._noMipmap,n,r)},i.prototype.clone=function(){var e=new i(this.url,this.getScene(),this._size,this._noMipmap,this._generateHarmonics,this._useInGammaSpace,this._usePMREMGenerator);return e.level=this.level,e.wrapU=this.wrapU,e.wrapV=this.wrapV,e.coordinatesIndex=this.coordinatesIndex,e.coordinatesMode=this.coordinatesMode,e},i.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.loadTexture())},i.prototype.getReflectionTextureMatrix=function(){return this._textureMatrix},i.Parse=function(t,i,n){var r=null;return t.name&&!t.isRenderTarget&&(r=new e.HDRCubeTexture(n+t.name,i,t.size,r.generateHarmonics,r.useInGammaSpace,r.usePMREMGenerator),r.name=t.name,r.hasAlpha=t.hasAlpha,r.level=t.level,r.coordinatesMode=t.coordinatesMode),r},i.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.size=this._size,e.coordinatesMode=this.coordinatesMode,e.useInGammaSpace=this._useInGammaSpace,e.generateHarmonics=this._generateHarmonics,e.usePMREMGenerator=this._usePMREMGenerator,e},i._facesMapping=["right","up","front","left","down","back"],i}(e.BaseTexture);e.HDRCubeTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){var i=function(){function t(t,i,n,r,o){void 0===r&&(r=!0),void 0===o&&(o=1),this.skeleton=t,this.mesh=i,this.autoUpdateBonesMatrices=r,this.renderingGroupId=o,this.color=e.Color3.White(),this._debugLines=[],this._isEnabled=!1,this._scene=n,this.update(),this._renderFunction=this.update.bind(this)}return Object.defineProperty(t.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(e){this._isEnabled!==e&&(this._isEnabled=e,e?this._scene.registerBeforeRender(this._renderFunction):this._scene.unregisterBeforeRender(this._renderFunction))},enumerable:!0,configurable:!0}),t.prototype._getBonePosition=function(t,i,n,r,o,s){void 0===r&&(r=0),void 0===o&&(o=0),void 0===s&&(s=0);var a=e.Tmp.Matrix[0],h=i.getParent();if(a.copyFrom(i.getLocalMatrix()),0!==r||0!==o||0!==s){var c=e.Tmp.Matrix[1];e.Matrix.IdentityToRef(c),c.m[12]=r,c.m[13]=o,c.m[14]=s,c.multiplyToRef(a,a)}h&&a.multiplyToRef(h.getAbsoluteTransform(),a),a.multiplyToRef(n,a),t.x=a.m[12],t.y=a.m[13],t.z=a.m[14]},t.prototype._getLinesForBonesWithLength=function(t,i){for(var n=t.length,r=0;n>r;r++){var o=t[r],s=this._debugLines[r];s||(s=[e.Vector3.Zero(),e.Vector3.Zero()],this._debugLines[r]=s),this._getBonePosition(s[0],o,i),this._getBonePosition(s[1],o,i,0,o.length,0)}},t.prototype._getLinesForBonesNoLength=function(t,i){for(var n=t.length,r=0,o=n-1;o>=0;o--){var s=t[o],a=s.getParent();if(a){var h=this._debugLines[r];h||(h=[e.Vector3.Zero(),e.Vector3.Zero()],this._debugLines[r]=h),this._getBonePosition(h[0],s,i),this._getBonePosition(h[1],a,i),r++}}},t.prototype.update=function(){this.autoUpdateBonesMatrices&&this._updateBoneMatrix(this.skeleton.bones[0]),void 0===this.skeleton.bones[0].length?this._getLinesForBonesNoLength(this.skeleton.bones,this.mesh.getWorldMatrix()):this._getLinesForBonesWithLength(this.skeleton.bones,this.mesh.getWorldMatrix()),this._debugMesh?e.MeshBuilder.CreateLineSystem(null,{lines:this._debugLines,updatable:!0,instance:this._debugMesh},this._scene):(this._debugMesh=e.MeshBuilder.CreateLineSystem(null,{lines:this._debugLines,updatable:!0},this._scene),this._debugMesh.renderingGroupId=this.renderingGroupId),this._debugMesh.color=this.color},t.prototype._updateBoneMatrix=function(e){e.getParent()&&e.getLocalMatrix().multiplyToRef(e.getParent().getAbsoluteTransform(),e.getAbsoluteTransform());for(var t=e.children,i=t.length,n=0;i>n;n++)this._updateBoneMatrix(t[n])},t.prototype.dispose=function(){this._debugMesh&&(this.isEnabled=!1,this._debugMesh.dispose(),this._debugMesh=null)},t}();t.SkeletonViewer=i}(t=e.Debug||(e.Debug={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=4,i=function(e){function t(){e.call(this),this.ALBEDO=!1,this.AMBIENT=!1,this.OPACITY=!1,this.OPACITYRGB=!1,this.REFLECTION=!1,this.EMISSIVE=!1,this.REFLECTIVITY=!1,this.BUMP=!1,this.PARALLAX=!1,this.PARALLAXOCCLUSION=!1,this.SPECULAROVERALPHA=!1,this.CLIPPLANE=!1,this.ALPHATEST=!1,this.ALPHAFROMALBEDO=!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.OPACITYFRESNEL=!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.MICROSURFACEFROMREFLECTIVITYMAP=!1,this.MICROSURFACEAUTOMATIC=!1,this.EMISSIVEASILLUMINATION=!1,this.LINKEMISSIVEWITHALBEDO=!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.INVERTCUBICMAP=!1,this.LOGARITHMICDEPTH=!1,this.CAMERATONEMAP=!1,this.CAMERACONTRAST=!1,this.OVERLOADEDVALUES=!1,this.OVERLOADEDSHADOWVALUES=!1,this.USESPHERICALFROMREFLECTIONMAP=!1,this.REFRACTION=!1,this.REFRACTIONMAP_3D=!1,this.LINKREFRACTIONTOTRANSPARENCY=!1,this.REFRACTIONMAPINLINEARSPACE=!1,this.LODBASEDMICROSFURACE=!1,this.USEPHYSICALLIGHTFALLOFF=!1,this.RADIANCEOVERALPHA=!1,this.USEPMREMREFLECTION=!1,this.USEPMREMREFRACTION=!1,this._keys=Object.keys(this)}return __extends(t,e),t}(e.MaterialDefines),n=function(n){function r(t,r){var o=this;n.call(this,t,r),this.directIntensity=1,this.emissiveIntensity=1,this.environmentIntensity=1,this.specularIntensity=1,this._lightingInfos=new e.Vector4(this.directIntensity,this.emissiveIntensity,this.environmentIntensity,this.specularIntensity),this.disableBumpMap=!1,this.overloadedShadowIntensity=1,this.overloadedShadeIntensity=1,this._overloadedShadowInfos=new e.Vector4(this.overloadedShadowIntensity,this.overloadedShadeIntensity,0,0),this.cameraExposure=1,this.cameraContrast=1,this._cameraInfos=new e.Vector4(1,1,0,0),this._microsurfaceTextureLods=new e.Vector2(0,0),this.overloadedAmbient=e.Color3.White(),this.overloadedAmbientIntensity=0,this.overloadedAlbedo=e.Color3.White(),this.overloadedAlbedoIntensity=0,this.overloadedReflectivity=new e.Color3(.3,.3,.3),this.overloadedReflectivityIntensity=0,this.overloadedEmissive=e.Color3.White(),this.overloadedEmissiveIntensity=0,this._overloadedIntensity=new e.Vector4(this.overloadedAmbientIntensity,this.overloadedAlbedoIntensity,this.overloadedReflectivityIntensity,this.overloadedEmissiveIntensity),this.overloadedReflection=e.Color3.White(),this.overloadedReflectionIntensity=0,this.overloadedMicroSurface=0,this.overloadedMicroSurfaceIntensity=0,this._overloadedMicroSurface=new e.Vector3(this.overloadedMicroSurface,this.overloadedMicroSurfaceIntensity,this.overloadedReflectionIntensity),this.ambientColor=new e.Color3(0,0,0),this.albedoColor=new e.Color3(1,1,1),this.reflectivityColor=new e.Color3(1,1,1),this.reflectionColor=new e.Color3(.5,.5,.5),this.emissiveColor=new e.Color3(0,0,0),this.microSurface=.9,this.indexOfRefraction=.66,this.invertRefractionY=!1,this.linkRefractionWithTransparency=!1,this.linkEmissiveWithAlbedo=!1,this.useLightmapAsShadowmap=!1,this.useEmissiveAsIllumination=!1,this.useAlphaFromAlbedoTexture=!1,this.useSpecularOverAlpha=!0,this.useMicroSurfaceFromReflectivityMapAlpha=!1,this.useAutoMicroSurfaceFromReflectivityMap=!1,this.useScalarInLinearSpace=!1,this.usePhysicalLightFalloff=!0,this.useRadianceOverAlpha=!0,this.useParallax=!1,this.useParallaxOcclusion=!1,this.parallaxScaleBias=.05,this.disableLighting=!1,this._renderTargets=new e.SmartArray(16),this._worldViewProjectionMatrix=e.Matrix.Zero(),this._globalAmbientColor=new e.Color3(0,0,0),this._tempColor=new e.Color3,this._defines=new i,this._cachedDefines=new i,this._myScene=null,this._myShadowGenerator=null,this._cachedDefines.BonesPerMesh=-1,this.getRenderTargetTextures=function(){return o._renderTargets.reset(),o.reflectionTexture&&o.reflectionTexture.isRenderTarget&&o._renderTargets.push(o.reflectionTexture),o.refractionTexture&&o.refractionTexture.isRenderTarget&&o._renderTargets.push(o.refractionTexture),o._renderTargets}}return __extends(r,n),Object.defineProperty(r.prototype,"useLogarithmicDepth",{get:function(){return this._useLogarithmicDepth},set:function(e){this._useLogarithmicDepth=e&&this.getScene().getEngine().getCaps().fragmentDepthSupported},enumerable:!0,configurable:!0}),r.prototype.needAlphaBlending=function(){return this.linkRefractionWithTransparency?!1:this.alpha<1||null!=this.opacityTexture||this._shouldUseAlphaFromAlbedoTexture()||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled},r.prototype.needAlphaTesting=function(){return this.linkRefractionWithTransparency?!1:null!=this.albedoTexture&&this.albedoTexture.hasAlpha},r.prototype._shouldUseAlphaFromAlbedoTexture=function(){return null!=this.albedoTexture&&this.albedoTexture.hasAlpha&&this.useAlphaFromAlbedoTexture},r.prototype.getAlphaTestTexture=function(){return this.albedoTexture},r.prototype._checkCache=function(e,t,i){return t?this._defines.INSTANCES!==i?!1:!(!t._materialDefines||!t._materialDefines.isEqual(this._defines)):!0},r.prototype.convertColorToLinearSpaceToRef=function(e,t){r.convertColorToLinearSpaceToRef(e,t,this.useScalarInLinearSpace)},r.convertColorToLinearSpaceToRef=function(e,t,i){i?(t.r=e.r,t.g=e.g,t.b=e.b):e.toLinearSpaceToRef(t)},r.BindLights=function(i,n,o,s,a){for(var h=0,c=!1,l=0;l<i.lights.length;l++){var u=i.lights[l];if(u.isEnabled()&&u.canAffectMesh(n)&&(this._lightRadiuses[h]=u.radius,e.MaterialHelper.BindLightProperties(u,o,h),this.convertColorToLinearSpaceToRef(u.diffuse,r._scaledAlbedo,a),r._scaledAlbedo.scaleToRef(u.intensity,r._scaledAlbedo),o.setColor4("vLightDiffuse"+h,r._scaledAlbedo,u.range),s.SPECULARTERM&&(this.convertColorToLinearSpaceToRef(u.specular,r._scaledReflectivity,a),r._scaledReflectivity.scaleToRef(u.intensity,r._scaledReflectivity),o.setColor3("vLightSpecular"+h,r._scaledReflectivity)),i.shadowsEnabled&&(c=e.MaterialHelper.BindLightShadow(u,i,n,h,o,c)),h++,h===t))break}o.setFloat4("vLightRadiuses",this._lightRadiuses[0],this._lightRadiuses[1],this._lightRadiuses[2],this._lightRadiuses[3])},r.prototype.isReady=function(t,n){if(this.checkReadyOnlyOnce&&this._wasPreviouslyReady)return!0;var r=this.getScene();if(!this.checkReadyOnEveryCall&&this._renderId===r.getRenderId()&&this._checkCache(r,t,n))return!0;var o=r.getEngine(),s=!1,a=!1;if(this._defines.reset(),r.texturesEnabled){if(r.texturesEnabled){if(r.getEngine().getCaps().textureLOD&&(this._defines.LODBASEDMICROSFURACE=!0),this.albedoTexture&&e.StandardMaterial.DiffuseTextureEnabled){if(!this.albedoTexture.isReady())return!1;a=!0,this._defines.ALBEDO=!0}if(this.ambientTexture&&e.StandardMaterial.AmbientTextureEnabled){if(!this.ambientTexture.isReady())return!1;a=!0,this._defines.AMBIENT=!0}if(this.opacityTexture&&e.StandardMaterial.OpacityTextureEnabled){if(!this.opacityTexture.isReady())return!1;a=!0,this._defines.OPACITY=!0,this.opacityTexture.getAlphaFromRGB&&(this._defines.OPACITYRGB=!0)}if(this.reflectionTexture&&e.StandardMaterial.ReflectionTextureEnabled){if(!this.reflectionTexture.isReady())return!1;switch(s=!0,this._defines.REFLECTION=!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}this.reflectionTexture instanceof e.HDRCubeTexture&&this.reflectionTexture&&(this._defines.USESPHERICALFROMREFLECTIONMAP=!0,s=!0,this.reflectionTexture.isPMREM&&(this._defines.USEPMREMREFLECTION=!0))}if(this.lightmapTexture&&e.StandardMaterial.LightmapTextureEnabled){if(!this.lightmapTexture.isReady())return!1;a=!0,this._defines.LIGHTMAP=!0,this._defines.USELIGHTMAPASSHADOWMAP=this.useLightmapAsShadowmap}if(this.emissiveTexture&&e.StandardMaterial.EmissiveTextureEnabled){if(!this.emissiveTexture.isReady())return!1;a=!0,this._defines.EMISSIVE=!0}if(this.reflectivityTexture&&e.StandardMaterial.SpecularTextureEnabled){if(!this.reflectivityTexture.isReady())return!1;a=!0,this._defines.REFLECTIVITY=!0,this._defines.MICROSURFACEFROMREFLECTIVITYMAP=this.useMicroSurfaceFromReflectivityMapAlpha,this._defines.MICROSURFACEAUTOMATIC=this.useAutoMicroSurfaceFromReflectivityMap}}if(r.getEngine().getCaps().standardDerivatives&&this.bumpTexture&&e.StandardMaterial.BumpTextureEnabled&&!this.disableBumpMap){if(!this.bumpTexture.isReady())return!1;a=!0,this._defines.BUMP=!0,this.useParallax&&(this._defines.PARALLAX=!0,this.useParallaxOcclusion&&(this._defines.PARALLAXOCCLUSION=!0))}if(this.refractionTexture&&e.StandardMaterial.RefractionTextureEnabled){if(!this.refractionTexture.isReady())return!1;a=!0,this._defines.REFRACTION=!0,this._defines.REFRACTIONMAP_3D=this.refractionTexture.isCube,this.linkRefractionWithTransparency&&(this._defines.LINKREFRACTIONTOTRANSPARENCY=!0),this.refractionTexture instanceof e.HDRCubeTexture&&(this._defines.REFRACTIONMAPINLINEARSPACE=!0,this.refractionTexture.isPMREM&&(this._defines.USEPMREMREFRACTION=!0))}}if(r.clipPlane&&(this._defines.CLIPPLANE=!0),o.getAlphaTesting()&&(this._defines.ALPHATEST=!0),this._shouldUseAlphaFromAlbedoTexture()&&(this._defines.ALPHAFROMALBEDO=!0),this.useEmissiveAsIllumination&&(this._defines.EMISSIVEASILLUMINATION=!0),this.linkEmissiveWithAlbedo&&(this._defines.LINKEMISSIVEWITHALBEDO=!0),this.useLogarithmicDepth&&(this._defines.LOGARITHMICDEPTH=!0),1!=this.cameraContrast&&(this._defines.CAMERACONTRAST=!0),1!=this.cameraExposure&&(this._defines.CAMERATONEMAP=!0),1==this.overloadedShadeIntensity&&1==this.overloadedShadowIntensity||(this._defines.OVERLOADEDSHADOWVALUES=!0),(this.overloadedMicroSurfaceIntensity>0||this.overloadedEmissiveIntensity>0||this.overloadedReflectivityIntensity>0||this.overloadedAlbedoIntensity>0||this.overloadedAmbientIntensity>0||this.overloadedReflectionIntensity>0)&&(this._defines.OVERLOADEDVALUES=!0),(this.pointsCloud||r.forcePointsCloud)&&(this._defines.POINTSIZE=!0),r.fogEnabled&&t&&t.applyFog&&r.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(this._defines.FOG=!0),r.lightsEnabled&&!this.disableLighting&&(s=e.MaterialHelper.PrepareDefinesForLights(r,t,this._defines)||s),e.StandardMaterial.FresnelEnabled&&(this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled||this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled)&&(this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&(this._defines.OPACITYFRESNEL=!0),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._defines.EMISSIVEFRESNEL=!0),s=!0,this._defines.FRESNEL=!0),this._defines.SPECULARTERM&&this.useSpecularOverAlpha&&(this._defines.SPECULAROVERALPHA=!0),this.usePhysicalLightFalloff&&(this._defines.USEPHYSICALLIGHTFALLOFF=!0),this.useRadianceOverAlpha&&(this._defines.RADIANCEOVERALPHA=!0),t&&(s&&t.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(this._defines.NORMAL=!0),a&&(t.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(this._defines.UV1=!0),t.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(this._defines.UV2=!0)),t.useVertexColors&&t.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(this._defines.VERTEXCOLOR=!0,t.hasVertexAlpha&&(this._defines.VERTEXALPHA=!0)),t.useBones&&t.computeBonesUsingShaders&&(this._defines.NUM_BONE_INFLUENCERS=t.numBoneInfluencers,this._defines.BonesPerMesh=t.skeleton.bones.length+1),n&&(this._defines.INSTANCES=!0)),!this._defines.isEqual(this._cachedDefines)){this._defines.cloneTo(this._cachedDefines),r.resetCachedMaterial();var h=new e.EffectFallbacks;this._defines.REFLECTION&&h.addFallback(0,"REFLECTION"),this._defines.REFRACTION&&h.addFallback(0,"REFRACTION"),this._defines.REFLECTIVITY&&h.addFallback(0,"REFLECTIVITY"),this._defines.BUMP&&h.addFallback(0,"BUMP"),this._defines.PARALLAX&&h.addFallback(1,"PARALLAX"),this._defines.PARALLAXOCCLUSION&&h.addFallback(0,"PARALLAXOCCLUSION"),this._defines.SPECULAROVERALPHA&&h.addFallback(0,"SPECULAROVERALPHA"),this._defines.FOG&&h.addFallback(1,"FOG"),this._defines.POINTSIZE&&h.addFallback(0,"POINTSIZE"),this._defines.LOGARITHMICDEPTH&&h.addFallback(0,"LOGARITHMICDEPTH"),e.MaterialHelper.HandleFallbacksForShadows(this._defines,h),this._defines.SPECULARTERM&&h.addFallback(0,"SPECULARTERM"),this._defines.OPACITYFRESNEL&&h.addFallback(1,"OPACITYFRESNEL"),this._defines.EMISSIVEFRESNEL&&h.addFallback(2,"EMISSIVEFRESNEL"),this._defines.FRESNEL&&h.addFallback(3,"FRESNEL"),this._defines.NUM_BONE_INFLUENCERS>0&&h.addCPUSkinningFallback(0,t);var c=[e.VertexBuffer.PositionKind];this._defines.NORMAL&&c.push(e.VertexBuffer.NormalKind),this._defines.UV1&&c.push(e.VertexBuffer.UVKind),this._defines.UV2&&c.push(e.VertexBuffer.UV2Kind),this._defines.VERTEXCOLOR&&c.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(c,t,this._defines,h),e.MaterialHelper.PrepareAttributesForInstances(c,this._defines);var l="pbr";r.getEngine().getCaps().standardDerivatives||(l="legacypbr");var u=this._defines.toString();this._effect=r.getEngine().createEffect(l,c,["world","view","viewProjection","vEyePosition","vLightsType","vAmbientColor","vAlbedoColor","vReflectivityColor","vEmissiveColor","vReflectionColor","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","vAlbedoInfos","vAmbientInfos","vOpacityInfos","vReflectionInfos","vEmissiveInfos","vReflectivityInfos","vBumpInfos","vLightmapInfos","vRefractionInfos","mBones","vClipPlane","albedoMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","reflectivityMatrix","bumpMatrix","lightmapMatrix","refractionMatrix","shadowsInfo0","shadowsInfo1","shadowsInfo2","shadowsInfo3","depthValues","opacityParts","emissiveLeftColor","emissiveRightColor","vLightingIntensity","vOverloadedShadowIntensity","vOverloadedIntensity","vCameraInfos","vOverloadedAlbedo","vOverloadedReflection","vOverloadedReflectivity","vOverloadedEmissive","vOverloadedMicroSurface","logarithmicDepthConstant","vSphericalX","vSphericalY","vSphericalZ","vSphericalXX","vSphericalYY","vSphericalZZ","vSphericalXY","vSphericalYZ","vSphericalZX","vMicrosurfaceTextureLods","vLightRadiuses"],["albedoSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","reflectivitySampler","bumpSampler","lightmapSampler","refractionCubeSampler","refraction2DSampler","shadowSampler0","shadowSampler1","shadowSampler2","shadowSampler3"],u,h,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=r.getRenderId(),this._wasPreviouslyReady=!0,t&&(t._materialDefines||(t._materialDefines=new i),this._defines.cloneTo(t._materialDefines)),!0):!1},r.prototype.unbind=function(){this.reflectionTexture&&this.reflectionTexture.isRenderTarget&&this._effect.setTexture("reflection2DSampler",null),this.refractionTexture&&this.refractionTexture.isRenderTarget&&this._effect.setTexture("refraction2DSampler",null),n.prototype.unbind.call(this)},r.prototype.bindOnlyWorldMatrix=function(e){this._effect.setMatrix("world",e)},r.prototype.bind=function(t,i){if(this._myScene=this.getScene(),this.bindOnlyWorldMatrix(t),e.MaterialHelper.BindBonesParameters(i,this._effect),this._myScene.getCachedMaterial()!==this){if(this._effect.setMatrix("viewProjection",this._myScene.getTransformMatrix()),e.StandardMaterial.FresnelEnabled&&(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.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._effect.setColor4("emissiveLeftColor",this.emissiveFresnelParameters.leftColor,this.emissiveFresnelParameters.power),this._effect.setColor4("emissiveRightColor",this.emissiveFresnelParameters.rightColor,this.emissiveFresnelParameters.bias))),this._myScene.texturesEnabled){if(this.albedoTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._effect.setTexture("albedoSampler",this.albedoTexture),this._effect.setFloat2("vAlbedoInfos",this.albedoTexture.coordinatesIndex,this.albedoTexture.level),this._effect.setMatrix("albedoMatrix",this.albedoTexture.getTextureMatrix())),this.ambientTexture&&e.StandardMaterial.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&&e.StandardMaterial.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&&e.StandardMaterial.ReflectionTextureEnabled&&(this._microsurfaceTextureLods.x=Math.round(Math.log(this.reflectionTexture.getSize().width)*Math.LOG2E),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,0),this._defines.USESPHERICALFROMREFLECTIONMAP&&(this._effect.setFloat3("vSphericalX",this.reflectionTexture.sphericalPolynomial.x.x,this.reflectionTexture.sphericalPolynomial.x.y,this.reflectionTexture.sphericalPolynomial.x.z),this._effect.setFloat3("vSphericalY",this.reflectionTexture.sphericalPolynomial.y.x,this.reflectionTexture.sphericalPolynomial.y.y,this.reflectionTexture.sphericalPolynomial.y.z),this._effect.setFloat3("vSphericalZ",this.reflectionTexture.sphericalPolynomial.z.x,this.reflectionTexture.sphericalPolynomial.z.y,this.reflectionTexture.sphericalPolynomial.z.z),this._effect.setFloat3("vSphericalXX",this.reflectionTexture.sphericalPolynomial.xx.x,this.reflectionTexture.sphericalPolynomial.xx.y,this.reflectionTexture.sphericalPolynomial.xx.z),this._effect.setFloat3("vSphericalYY",this.reflectionTexture.sphericalPolynomial.yy.x,this.reflectionTexture.sphericalPolynomial.yy.y,this.reflectionTexture.sphericalPolynomial.yy.z),this._effect.setFloat3("vSphericalZZ",this.reflectionTexture.sphericalPolynomial.zz.x,this.reflectionTexture.sphericalPolynomial.zz.y,this.reflectionTexture.sphericalPolynomial.zz.z),this._effect.setFloat3("vSphericalXY",this.reflectionTexture.sphericalPolynomial.xy.x,this.reflectionTexture.sphericalPolynomial.xy.y,this.reflectionTexture.sphericalPolynomial.xy.z),this._effect.setFloat3("vSphericalYZ",this.reflectionTexture.sphericalPolynomial.yz.x,this.reflectionTexture.sphericalPolynomial.yz.y,this.reflectionTexture.sphericalPolynomial.yz.z),this._effect.setFloat3("vSphericalZX",this.reflectionTexture.sphericalPolynomial.zx.x,this.reflectionTexture.sphericalPolynomial.zx.y,this.reflectionTexture.sphericalPolynomial.zx.z))),this.emissiveTexture&&e.StandardMaterial.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&&e.StandardMaterial.LightmapTextureEnabled&&(this._effect.setTexture("lightmapSampler",this.lightmapTexture),this._effect.setFloat2("vLightmapInfos",this.lightmapTexture.coordinatesIndex,this.lightmapTexture.level),this._effect.setMatrix("lightmapMatrix",this.lightmapTexture.getTextureMatrix())),this.reflectivityTexture&&e.StandardMaterial.SpecularTextureEnabled&&(this._effect.setTexture("reflectivitySampler",this.reflectivityTexture),this._effect.setFloat2("vReflectivityInfos",this.reflectivityTexture.coordinatesIndex,this.reflectivityTexture.level),this._effect.setMatrix("reflectivityMatrix",this.reflectivityTexture.getTextureMatrix())),this.bumpTexture&&this._myScene.getEngine().getCaps().standardDerivatives&&e.StandardMaterial.BumpTextureEnabled&&!this.disableBumpMap&&(this._effect.setTexture("bumpSampler",this.bumpTexture),this._effect.setFloat3("vBumpInfos",this.bumpTexture.coordinatesIndex,1/this.bumpTexture.level,this.parallaxScaleBias),this._effect.setMatrix("bumpMatrix",this.bumpTexture.getTextureMatrix())),this.refractionTexture&&e.StandardMaterial.RefractionTextureEnabled){this._microsurfaceTextureLods.y=Math.round(Math.log(this.refractionTexture.getSize().width)*Math.LOG2E);var o=1;this.refractionTexture.isCube?this._effect.setTexture("refractionCubeSampler",this.refractionTexture):(this._effect.setTexture("refraction2DSampler",this.refractionTexture),
  29. this._effect.setMatrix("refractionMatrix",this.refractionTexture.getReflectionTextureMatrix()),this.refractionTexture.depth&&(o=this.refractionTexture.depth)),this._effect.setFloat4("vRefractionInfos",this.refractionTexture.level,this.indexOfRefraction,o,this.invertRefractionY?-1:1)}(this.reflectionTexture||this.refractionTexture)&&this._effect.setFloat2("vMicrosurfaceTextureLods",this._microsurfaceTextureLods.x,this._microsurfaceTextureLods.y)}e.MaterialHelper.BindClipPlane(this._effect,this._myScene),this.pointsCloud&&this._effect.setFloat("pointSize",this.pointSize),this._myScene.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor),this.convertColorToLinearSpaceToRef(this.reflectivityColor,r._scaledReflectivity),this._effect.setVector3("vEyePosition",this._myScene._mirroredCameraPosition?this._myScene._mirroredCameraPosition:this._myScene.activeCamera.position),this._effect.setColor3("vAmbientColor",this._globalAmbientColor),this._effect.setColor4("vReflectivityColor",r._scaledReflectivity,this.microSurface),this.convertColorToLinearSpaceToRef(this.emissiveColor,r._scaledEmissive),this._effect.setColor3("vEmissiveColor",r._scaledEmissive),this.convertColorToLinearSpaceToRef(this.reflectionColor,r._scaledReflection),this._effect.setColor3("vReflectionColor",r._scaledReflection)}this._myScene.getCachedMaterial()===this&&this.isFrozen||(this.convertColorToLinearSpaceToRef(this.albedoColor,r._scaledAlbedo),this._effect.setColor4("vAlbedoColor",r._scaledAlbedo,this.alpha*i.visibility),this._myScene.lightsEnabled&&!this.disableLighting&&r.BindLights(this._myScene,i,this._effect,this._defines,this.useScalarInLinearSpace),(this._myScene.fogEnabled&&i.applyFog&&this._myScene.fogMode!==e.Scene.FOGMODE_NONE||this.reflectionTexture)&&this._effect.setMatrix("view",this._myScene.getViewMatrix()),e.MaterialHelper.BindFogParameters(this._myScene,i,this._effect),this._lightingInfos.x=this.directIntensity,this._lightingInfos.y=this.emissiveIntensity,this._lightingInfos.z=this.environmentIntensity,this._lightingInfos.w=this.specularIntensity,this._effect.setVector4("vLightingIntensity",this._lightingInfos),this._overloadedShadowInfos.x=this.overloadedShadowIntensity,this._overloadedShadowInfos.y=this.overloadedShadeIntensity,this._effect.setVector4("vOverloadedShadowIntensity",this._overloadedShadowInfos),this._cameraInfos.x=this.cameraExposure,this._cameraInfos.y=this.cameraContrast,this._effect.setVector4("vCameraInfos",this._cameraInfos),this._overloadedIntensity.x=this.overloadedAmbientIntensity,this._overloadedIntensity.y=this.overloadedAlbedoIntensity,this._overloadedIntensity.z=this.overloadedReflectivityIntensity,this._overloadedIntensity.w=this.overloadedEmissiveIntensity,this._effect.setVector4("vOverloadedIntensity",this._overloadedIntensity),this.convertColorToLinearSpaceToRef(this.overloadedAmbient,this._tempColor),this._effect.setColor3("vOverloadedAmbient",this._tempColor),this.convertColorToLinearSpaceToRef(this.overloadedAlbedo,this._tempColor),this._effect.setColor3("vOverloadedAlbedo",this._tempColor),this.convertColorToLinearSpaceToRef(this.overloadedReflectivity,this._tempColor),this._effect.setColor3("vOverloadedReflectivity",this._tempColor),this.convertColorToLinearSpaceToRef(this.overloadedEmissive,this._tempColor),this._effect.setColor3("vOverloadedEmissive",this._tempColor),this.convertColorToLinearSpaceToRef(this.overloadedReflection,this._tempColor),this._effect.setColor3("vOverloadedReflection",this._tempColor),this._overloadedMicroSurface.x=this.overloadedMicroSurface,this._overloadedMicroSurface.y=this.overloadedMicroSurfaceIntensity,this._overloadedMicroSurface.z=this.overloadedReflectionIntensity,this._effect.setVector3("vOverloadedMicroSurface",this._overloadedMicroSurface),e.MaterialHelper.BindLogDepth(this._defines,this._effect,this._myScene)),n.prototype.bind.call(this,t,i),this._myScene=null},r.prototype.getAnimatables=function(){var e=[];return this.albedoTexture&&this.albedoTexture.animations&&this.albedoTexture.animations.length>0&&e.push(this.albedoTexture),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.reflectivityTexture&&this.reflectivityTexture.animations&&this.reflectivityTexture.animations.length>0&&e.push(this.reflectivityTexture),this.bumpTexture&&this.bumpTexture.animations&&this.bumpTexture.animations.length>0&&e.push(this.bumpTexture),this.lightmapTexture&&this.lightmapTexture.animations&&this.lightmapTexture.animations.length>0&&e.push(this.lightmapTexture),this.refractionTexture&&this.refractionTexture.animations&&this.refractionTexture.animations.length>0&&e.push(this.refractionTexture),e},r.prototype.dispose=function(e){this.albedoTexture&&this.albedoTexture.dispose(),this.ambientTexture&&this.ambientTexture.dispose(),this.opacityTexture&&this.opacityTexture.dispose(),this.reflectionTexture&&this.reflectionTexture.dispose(),this.emissiveTexture&&this.emissiveTexture.dispose(),this.reflectivityTexture&&this.reflectivityTexture.dispose(),this.bumpTexture&&this.bumpTexture.dispose(),this.lightmapTexture&&this.lightmapTexture.dispose(),this.refractionTexture&&this.refractionTexture.dispose(),n.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.PBRMaterial",t},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},r._scaledAlbedo=new e.Color3,r._scaledReflectivity=new e.Color3,r._scaledEmissive=new e.Color3,r._scaledReflection=new e.Color3,r._lightRadiuses=[1,1,1,1],__decorate([e.serialize()],r.prototype,"directIntensity",void 0),__decorate([e.serialize()],r.prototype,"emissiveIntensity",void 0),__decorate([e.serialize()],r.prototype,"environmentIntensity",void 0),__decorate([e.serialize()],r.prototype,"specularIntensity",void 0),__decorate([e.serialize()],r.prototype,"disableBumpMap",void 0),__decorate([e.serialize()],r.prototype,"overloadedShadowIntensity",void 0),__decorate([e.serialize()],r.prototype,"overloadedShadeIntensity",void 0),__decorate([e.serialize()],r.prototype,"cameraExposure",void 0),__decorate([e.serialize()],r.prototype,"cameraContrast",void 0),__decorate([e.serializeAsColor3()],r.prototype,"overloadedAmbient",void 0),__decorate([e.serialize()],r.prototype,"overloadedAmbientIntensity",void 0),__decorate([e.serializeAsColor3()],r.prototype,"overloadedAlbedo",void 0),__decorate([e.serialize()],r.prototype,"overloadedAlbedoIntensity",void 0),__decorate([e.serializeAsColor3()],r.prototype,"overloadedReflectivity",void 0),__decorate([e.serialize()],r.prototype,"overloadedReflectivityIntensity",void 0),__decorate([e.serializeAsColor3()],r.prototype,"overloadedEmissive",void 0),__decorate([e.serialize()],r.prototype,"overloadedEmissiveIntensity",void 0),__decorate([e.serializeAsColor3()],r.prototype,"overloadedReflection",void 0),__decorate([e.serialize()],r.prototype,"overloadedReflectionIntensity",void 0),__decorate([e.serialize()],r.prototype,"overloadedMicroSurface",void 0),__decorate([e.serialize()],r.prototype,"overloadedMicroSurfaceIntensity",void 0),__decorate([e.serializeAsTexture()],r.prototype,"albedoTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"ambientTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"opacityTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"reflectionTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"emissiveTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"reflectivityTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"bumpTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"lightmapTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"refractionTexture",void 0),__decorate([e.serializeAsColor3("ambient")],r.prototype,"ambientColor",void 0),__decorate([e.serializeAsColor3("albedo")],r.prototype,"albedoColor",void 0),__decorate([e.serializeAsColor3("reflectivity")],r.prototype,"reflectivityColor",void 0),__decorate([e.serializeAsColor3("reflection")],r.prototype,"reflectionColor",void 0),__decorate([e.serializeAsColor3("emissive")],r.prototype,"emissiveColor",void 0),__decorate([e.serialize()],r.prototype,"microSurface",void 0),__decorate([e.serialize()],r.prototype,"indexOfRefraction",void 0),__decorate([e.serialize()],r.prototype,"invertRefractionY",void 0),__decorate([e.serializeAsFresnelParameters()],r.prototype,"opacityFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters()],r.prototype,"emissiveFresnelParameters",void 0),__decorate([e.serialize()],r.prototype,"linkRefractionWithTransparency",void 0),__decorate([e.serialize()],r.prototype,"linkEmissiveWithAlbedo",void 0),__decorate([e.serialize()],r.prototype,"useLightmapAsShadowmap",void 0),__decorate([e.serialize()],r.prototype,"useEmissiveAsIllumination",void 0),__decorate([e.serialize()],r.prototype,"useAlphaFromAlbedoTexture",void 0),__decorate([e.serialize()],r.prototype,"useSpecularOverAlpha",void 0),__decorate([e.serialize()],r.prototype,"useMicroSurfaceFromReflectivityMapAlpha",void 0),__decorate([e.serialize()],r.prototype,"useAutoMicroSurfaceFromReflectivityMap",void 0),__decorate([e.serialize()],r.prototype,"useScalarInLinearSpace",void 0),__decorate([e.serialize()],r.prototype,"usePhysicalLightFalloff",void 0),__decorate([e.serialize()],r.prototype,"useRadianceOverAlpha",void 0),__decorate([e.serialize()],r.prototype,"useParallax",void 0),__decorate([e.serialize()],r.prototype,"useParallaxOcclusion",void 0),__decorate([e.serialize()],r.prototype,"parallaxScaleBias",void 0),__decorate([e.serialize()],r.prototype,"disableLighting",void 0),__decorate([e.serialize()],r.prototype,"useLogarithmicDepth",null),r}(e.Material);e.PBRMaterial=n}(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore={anaglyphPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D leftSampler;\nvoid main(void)\n{\nvec4 leftFrag=texture2D(leftSampler,vUV);\nleftFrag=vec4(1.0,leftFrag.g,leftFrag.b,1.0);\nvec4 rightFrag=texture2D(textureSampler,vUV);\nrightFrag=vec4(rightFrag.r,1.0,1.0,1.0);\ngl_FragColor=vec4(rightFrag.rgb*leftFrag.rgb,1.0);\n}",blackAndWhitePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nvoid main(void) \n{\nfloat luminance=dot(texture2D(textureSampler,vUV).rgb,vec3(0.3,0.59,0.11));\ngl_FragColor=vec4(luminance,luminance,luminance,1.0);\n}",blurPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec2 screenSize;\nuniform vec2 direction;\nuniform float blurWidth;\nvoid main(void)\n{\nfloat weights[7];\nweights[0]=0.05;\nweights[1]=0.1;\nweights[2]=0.2;\nweights[3]=0.3;\nweights[4]=0.2;\nweights[5]=0.1;\nweights[6]=0.05;\nvec2 texelSize=vec2(1.0/screenSize.x,1.0/screenSize.y);\nvec2 texelStep=texelSize*direction*blurWidth;\nvec2 start=vUV-3.0*texelStep;\nvec4 baseColor=vec4(0.,0.,0.,0.);\nvec2 texelOffset=vec2(0.,0.);\nfor (int i=0; i<7; i++)\n{\nbaseColor+=texture2D(textureSampler,start+texelOffset)*weights[i];\ntexelOffset+=texelStep;\n}\ngl_FragColor=baseColor;\n}",chromaticAberrationPixelShader:"\nuniform sampler2D textureSampler; \n\nuniform float chromatic_aberration;\nuniform float screen_width;\nuniform float screen_height;\n\nvarying vec2 vUV;\nvoid main(void)\n{\nvec2 centered_screen_pos=vec2(vUV.x-0.5,vUV.y-0.5);\nfloat radius2=centered_screen_pos.x*centered_screen_pos.x\n+centered_screen_pos.y*centered_screen_pos.y;\nfloat radius=sqrt(radius2);\nvec4 original=texture2D(textureSampler,vUV);\nif (chromatic_aberration>0.0) {\n\nvec3 ref_indices=vec3(-0.3,0.0,0.3);\nfloat ref_shiftX=chromatic_aberration*radius*17.0/screen_width;\nfloat ref_shiftY=chromatic_aberration*radius*17.0/screen_height;\n\nvec2 ref_coords_r=vec2(vUV.x+ref_indices.r*ref_shiftX,vUV.y+ref_indices.r*ref_shiftY*0.5);\nvec2 ref_coords_g=vec2(vUV.x+ref_indices.g*ref_shiftX,vUV.y+ref_indices.g*ref_shiftY*0.5);\nvec2 ref_coords_b=vec2(vUV.x+ref_indices.b*ref_shiftX,vUV.y+ref_indices.b*ref_shiftY*0.5);\noriginal.r=texture2D(textureSampler,ref_coords_r).r;\noriginal.g=texture2D(textureSampler,ref_coords_g).g;\noriginal.b=texture2D(textureSampler,ref_coords_b).b;\n}\ngl_FragColor=original;\n}",colorPixelShader:"uniform vec4 color;\nvoid main(void) {\ngl_FragColor=color;\n}",colorVertexShader:"\nattribute vec3 position;\n\nuniform mat4 worldViewProjection;\nvoid main(void) {\ngl_Position=worldViewProjection*vec4(position,1.0);\n}",colorCorrectionPixelShader:"\nuniform sampler2D textureSampler; \nuniform sampler2D colorTable; \n\nvarying vec2 vUV;\n\nconst float SLICE_COUNT=16.0; \n\nvec4 sampleAs3DTexture(sampler2D texture,vec3 uv,float width) {\nfloat sliceSize=1.0/width; \nfloat slicePixelSize=sliceSize/width; \nfloat sliceInnerSize=slicePixelSize*(width-1.0); \nfloat zSlice0=min(floor(uv.z*width),width-1.0);\nfloat zSlice1=min(zSlice0+1.0,width-1.0);\nfloat xOffset=slicePixelSize*0.5+uv.x*sliceInnerSize;\nfloat s0=xOffset+(zSlice0*sliceSize);\nfloat s1=xOffset+(zSlice1*sliceSize);\nvec4 slice0Color=texture2D(texture,vec2(s0,uv.y));\nvec4 slice1Color=texture2D(texture,vec2(s1,uv.y));\nfloat zOffset=mod(uv.z*width,1.0);\nvec4 result=mix(slice0Color,slice1Color,zOffset);\nreturn result;\n}\nvoid main(void)\n{\nvec4 screen_color=texture2D(textureSampler,vUV);\ngl_FragColor=sampleAs3DTexture(colorTable,screen_color.rgb,SLICE_COUNT);\n}",convolutionPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 screenSize;\nuniform float kernel[9];\nvoid main(void)\n{\nvec2 onePixel=vec2(1.0,1.0)/screenSize;\nvec4 colorSum =\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,-1))*kernel[0] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,-1))*kernel[1] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,-1))*kernel[2] +\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,0))*kernel[3] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,0))*kernel[4] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,0))*kernel[5] +\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,1))*kernel[6] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,1))*kernel[7] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,1))*kernel[8];\nfloat kernelWeight =\nkernel[0] +\nkernel[1] +\nkernel[2] +\nkernel[3] +\nkernel[4] +\nkernel[5] +\nkernel[6] +\nkernel[7] +\nkernel[8];\nif (kernelWeight<=0.0) {\nkernelWeight=1.0;\n}\ngl_FragColor=vec4((colorSum/kernelWeight).rgb,1);\n}",defaultPixelShader:"#ifdef BUMP\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n\n#define RECIPROCAL_PI2 0.15915494\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<lightFragmentDeclaration>[0]\n#include<lightFragmentDeclaration>[1]\n#include<lightFragmentDeclaration>[2]\n#include<lightFragmentDeclaration>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform vec2 vLightmapInfos;\nuniform sampler2D lightmapSampler;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\nuniform mat4 refractionMatrix;\n#endif\n#ifdef REFRACTIONFRESNEL\nuniform vec4 refractionLeftColor;\nuniform vec4 refractionRightColor;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nvarying vec2 vSpecularUV;\nuniform vec2 vSpecularInfos;\nuniform sampler2D specularSampler;\n#endif\n\n#include<fresnelFunction>\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;\nuniform vec4 diffuseRightColor;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvarying vec3 vDirectionW;\n#endif\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#include<reflectionFunction>\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n#endif\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef DIFFUSE\nvec2 diffuseUV=vDiffuseUV;\n#endif\n#include<bumpFragment>\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,diffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#ifdef ALPHAFROMDIFFUSE\nalpha*=baseColor.a;\n#endif\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV).rgb*vAmbientInfos.y;\n#endif\n\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV);\nspecularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n\nvec3 refractionColor=vec3(0.,0.,0.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0)\n{\nrefractionColor=textureCube(refractionCubeSampler,refractionVector).rgb*vRefractionInfos.x;\n}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\nrefractionColor=texture2D(refraction2DSampler,refractionCoords).rgb*vRefractionInfos.x;\n#endif\n#endif\n\nvec3 reflectionColor=vec3(0.,0.,0.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb*vReflectionInfos.x;\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb*vReflectionInfos.x;\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\nreflectionColor=texture2D(reflection2DSampler,coords).rgb*vReflectionInfos.x;\n#endif\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\nrefractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nemissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\ndiffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\n#ifdef LINKEMISSIVEWITHDIFFUSE\nvec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#endif\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#ifdef REFLECTIONOVERALPHA\nalpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n#else\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n#endif\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV).rgb*vLightmapInfos.y;\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor;\n#else\ncolor.rgb+=lightmapColor;\n#endif\n#endif\n#include<logDepthFragment>\n#include<fogFragment>\ngl_FragColor=color;\n}",defaultVertexShader:"\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nvarying vec2 vSpecularUV;\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nvarying vec2 vBumpUV;\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#include<pointCloudVertexDeclaration>\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<shadowsVertexDeclaration>\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=position;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvDirectionW=normalize(vec3(finalWorld*vec4(position,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef AMBIENT\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef OPACITY\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef EMISSIVE\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef LIGHTMAP\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nif (vSpecularInfos.x == 0.)\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef BUMP\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<shadowsVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n#include<pointCloudVertex>\n#include<logDepthVertex>\n}",depthPixelShader:"#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\nuniform float far;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\nfloat depth=(gl_FragCoord.z/gl_FragCoord.w)/far;\ngl_FragColor=vec4(depth,depth*depth,0.0,1.0);\n}",depthVertexShader:"\nattribute vec3 position;\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\n#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",depthBoxBlurPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec2 screenSize;\nvoid main(void)\n{\nvec4 colorDepth=vec4(0.0);\nfor (int x=-OFFSET; x<=OFFSET; x++)\nfor (int y=-OFFSET; y<=OFFSET; y++)\ncolorDepth+=texture2D(textureSampler,vUV+vec2(x,y)/screenSize);\ngl_FragColor=(colorDepth/float((OFFSET*2+1)*(OFFSET*2+1)));\n}",depthOfFieldPixelShader:"\n\n\n\n\nuniform sampler2D textureSampler;\nuniform sampler2D highlightsSampler;\nuniform sampler2D depthSampler;\nuniform sampler2D grainSampler;\n\nuniform float grain_amount;\nuniform bool blur_noise;\nuniform float screen_width;\nuniform float screen_height;\nuniform float distortion;\nuniform bool dof_enabled;\n\nuniform float screen_distance; \nuniform float aperture;\nuniform float darken;\nuniform float edge_blur;\nuniform bool highlights;\n\nuniform float near;\nuniform float far;\n\nvarying vec2 vUV;\n\n#define PI 3.14159265\n#define TWOPI 6.28318530\n#define inverse_focal_length 0.1 \n\nvec2 centered_screen_pos;\nvec2 distorted_coords;\nfloat radius2;\nfloat radius;\n\nvec2 rand(vec2 co)\n{\nfloat noise1=(fract(sin(dot(co,vec2(12.9898,78.233)))*43758.5453));\nfloat noise2=(fract(sin(dot(co,vec2(12.9898,78.233)*2.0))*43758.5453));\nreturn clamp(vec2(noise1,noise2),0.0,1.0);\n}\n\nvec2 getDistortedCoords(vec2 coords) {\nif (distortion == 0.0) { return coords; }\nvec2 direction=1.0*normalize(centered_screen_pos);\nvec2 dist_coords=vec2(0.5,0.5);\ndist_coords.x=0.5+direction.x*radius2*1.0;\ndist_coords.y=0.5+direction.y*radius2*1.0;\nfloat dist_amount=clamp(distortion*0.23,0.0,1.0);\ndist_coords=mix(coords,dist_coords,dist_amount);\nreturn dist_coords;\n}\n\nfloat sampleScreen(inout vec4 color,const in vec2 offset,const in float weight) {\n\nvec2 coords=distorted_coords;\nfloat angle=rand(coords*100.0).x*TWOPI;\ncoords+=vec2(offset.x*cos(angle)-offset.y*sin(angle),offset.x*sin(angle)+offset.y*cos(angle));\ncolor+=texture2D(textureSampler,coords)*weight;\nreturn weight;\n}\n\nfloat getBlurLevel(float size) {\nreturn min(3.0,ceil(size/1.0));\n}\n\nvec4 getBlurColor(float size) {\nvec4 col=texture2D(textureSampler,distorted_coords);\nif (size == 0.0) { return col; }\n\n\nfloat blur_level=getBlurLevel(size);\nfloat w=(size/screen_width);\nfloat h=(size/screen_height);\nfloat total_weight=1.0;\nvec2 sample_coords;\ntotal_weight+=sampleScreen(col,vec2(-0.50*w,0.24*h),0.93);\ntotal_weight+=sampleScreen(col,vec2(0.30*w,-0.75*h),0.90);\ntotal_weight+=sampleScreen(col,vec2(0.36*w,0.96*h),0.87);\ntotal_weight+=sampleScreen(col,vec2(-1.08*w,-0.55*h),0.85);\ntotal_weight+=sampleScreen(col,vec2(1.33*w,-0.37*h),0.83);\ntotal_weight+=sampleScreen(col,vec2(-0.82*w,1.31*h),0.80);\ntotal_weight+=sampleScreen(col,vec2(-0.31*w,-1.67*h),0.78);\ntotal_weight+=sampleScreen(col,vec2(1.47*w,1.11*h),0.76);\ntotal_weight+=sampleScreen(col,vec2(-1.97*w,0.19*h),0.74);\ntotal_weight+=sampleScreen(col,vec2(1.42*w,-1.57*h),0.72);\nif (blur_level>1.0) {\ntotal_weight+=sampleScreen(col,vec2(0.01*w,2.25*h),0.70);\ntotal_weight+=sampleScreen(col,vec2(-1.62*w,-1.74*h),0.67);\ntotal_weight+=sampleScreen(col,vec2(2.49*w,0.20*h),0.65);\ntotal_weight+=sampleScreen(col,vec2(-2.07*w,1.61*h),0.63);\ntotal_weight+=sampleScreen(col,vec2(0.46*w,-2.70*h),0.61);\ntotal_weight+=sampleScreen(col,vec2(1.55*w,2.40*h),0.59);\ntotal_weight+=sampleScreen(col,vec2(-2.88*w,-0.75*h),0.56);\ntotal_weight+=sampleScreen(col,vec2(2.73*w,-1.44*h),0.54);\ntotal_weight+=sampleScreen(col,vec2(-1.08*w,3.02*h),0.52);\ntotal_weight+=sampleScreen(col,vec2(-1.28*w,-3.05*h),0.49);\n}\nif (blur_level>2.0) {\ntotal_weight+=sampleScreen(col,vec2(3.11*w,1.43*h),0.46);\ntotal_weight+=sampleScreen(col,vec2(-3.36*w,1.08*h),0.44);\ntotal_weight+=sampleScreen(col,vec2(1.80*w,-3.16*h),0.41);\ntotal_weight+=sampleScreen(col,vec2(0.83*w,3.65*h),0.38);\ntotal_weight+=sampleScreen(col,vec2(-3.16*w,-2.19*h),0.34);\ntotal_weight+=sampleScreen(col,vec2(3.92*w,-0.53*h),0.31);\ntotal_weight+=sampleScreen(col,vec2(-2.59*w,3.12*h),0.26);\ntotal_weight+=sampleScreen(col,vec2(-0.20*w,-4.15*h),0.22);\ntotal_weight+=sampleScreen(col,vec2(3.02*w,3.00*h),0.15);\n}\ncol/=total_weight; \n\nif (darken>0.0) {\ncol.rgb*=clamp(0.3,1.0,1.05-size*0.5*darken);\n}\n\n\n\n\nreturn col;\n}\nvoid main(void)\n{\n\ncentered_screen_pos=vec2(vUV.x-0.5,vUV.y-0.5);\nradius2=centered_screen_pos.x*centered_screen_pos.x+centered_screen_pos.y*centered_screen_pos.y;\nradius=sqrt(radius2);\ndistorted_coords=getDistortedCoords(vUV); \nvec2 texels_coords=vec2(vUV.x*screen_width,vUV.y*screen_height); \nfloat depth=texture2D(depthSampler,distorted_coords).r; \nfloat distance=near+(far-near)*depth; \nvec4 color=texture2D(textureSampler,vUV); \n\n\nfloat coc=abs(aperture*(screen_distance*(inverse_focal_length-1.0/distance)-1.0));\n\nif (dof_enabled == false || coc<0.07) { coc=0.0; }\n\nfloat edge_blur_amount=0.0;\nif (edge_blur>0.0) {\nedge_blur_amount=clamp((radius*2.0-1.0+0.15*edge_blur)*1.5,0.0,1.0)*1.3;\n}\n\nfloat blur_amount=max(edge_blur_amount,coc);\n\nif (blur_amount == 0.0) {\ngl_FragColor=texture2D(textureSampler,distorted_coords);\n}\nelse {\n\ngl_FragColor=getBlurColor(blur_amount*1.7);\n\nif (highlights) {\ngl_FragColor.rgb+=clamp(coc,0.0,1.0)*texture2D(highlightsSampler,distorted_coords).rgb;\n}\nif (blur_noise) {\n\nvec2 noise=rand(distorted_coords)*0.01*blur_amount;\nvec2 blurred_coord=vec2(distorted_coords.x+noise.x,distorted_coords.y+noise.y);\ngl_FragColor=0.04*texture2D(textureSampler,blurred_coord)+0.96*gl_FragColor;\n}\n}\n\nif (grain_amount>0.0) {\nvec4 grain_color=texture2D(grainSampler,texels_coords*0.003);\ngl_FragColor.rgb+=(-0.5+grain_color.rgb)*0.30*grain_amount;\n}\n}\n",
  30. displayPassPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D passSampler;\nvoid main(void)\n{\ngl_FragColor=texture2D(passSampler,vUV);\n}",filterPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform mat4 kernelMatrix;\nvoid main(void)\n{\nvec3 baseColor=texture2D(textureSampler,vUV).rgb;\nvec3 updatedColor=(kernelMatrix*vec4(baseColor,1.0)).rgb;\ngl_FragColor=vec4(updatedColor,1.0);\n}",fxaaPixelShader:"#define FXAA_REDUCE_MIN (1.0/128.0)\n#define FXAA_REDUCE_MUL (1.0/8.0)\n#define FXAA_SPAN_MAX 8.0\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 texelSize;\nvoid main(){\nvec2 localTexelSize=texelSize;\nvec4 rgbNW=texture2D(textureSampler,(vUV+vec2(-1.0,-1.0)*localTexelSize));\nvec4 rgbNE=texture2D(textureSampler,(vUV+vec2(1.0,-1.0)*localTexelSize));\nvec4 rgbSW=texture2D(textureSampler,(vUV+vec2(-1.0,1.0)*localTexelSize));\nvec4 rgbSE=texture2D(textureSampler,(vUV+vec2(1.0,1.0)*localTexelSize));\nvec4 rgbM=texture2D(textureSampler,vUV);\nvec4 luma=vec4(0.299,0.587,0.114,1.0);\nfloat lumaNW=dot(rgbNW,luma);\nfloat lumaNE=dot(rgbNE,luma);\nfloat lumaSW=dot(rgbSW,luma);\nfloat lumaSE=dot(rgbSE,luma);\nfloat lumaM=dot(rgbM,luma);\nfloat lumaMin=min(lumaM,min(min(lumaNW,lumaNE),min(lumaSW,lumaSE)));\nfloat lumaMax=max(lumaM,max(max(lumaNW,lumaNE),max(lumaSW,lumaSE)));\nvec2 dir=vec2(-((lumaNW+lumaNE)-(lumaSW+lumaSE)),((lumaNW+lumaSW)-(lumaNE+lumaSE)));\nfloat dirReduce=max(\n(lumaNW+lumaNE+lumaSW+lumaSE)*(0.25*FXAA_REDUCE_MUL),\nFXAA_REDUCE_MIN);\nfloat rcpDirMin=1.0/(min(abs(dir.x),abs(dir.y))+dirReduce);\ndir=min(vec2(FXAA_SPAN_MAX,FXAA_SPAN_MAX),\nmax(vec2(-FXAA_SPAN_MAX,-FXAA_SPAN_MAX),\ndir*rcpDirMin))*localTexelSize;\nvec4 rgbA=0.5*(\ntexture2D(textureSampler,vUV+dir*(1.0/3.0-0.5)) +\ntexture2D(textureSampler,vUV+dir*(2.0/3.0-0.5)));\nvec4 rgbB=rgbA*0.5+0.25*(\ntexture2D(textureSampler,vUV+dir*-0.5) +\ntexture2D(textureSampler,vUV+dir*0.5));\nfloat lumaB=dot(rgbB,luma);\nif ((lumaB<lumaMin) || (lumaB>lumaMax)) {\ngl_FragColor=rgbA;\n}\nelse {\ngl_FragColor=rgbB;\n}\n}",hdrPixelShader:"uniform sampler2D textureSampler;\nvarying vec2 vUV;\n#if defined(GAUSSIAN_BLUR_H) || defined(GAUSSIAN_BLUR_V)\nuniform float blurOffsets[9];\nuniform float blurWeights[9];\nuniform float multiplier;\nvoid main(void) {\nvec4 color=vec4(0.0,0.0,0.0,0.0);\nfor (int i=0; i<9; i++) {\n#ifdef GAUSSIAN_BLUR_H\ncolor+=(texture2D(textureSampler,vUV+vec2(blurOffsets[i]*multiplier,0.0))*blurWeights[i]);\n#else\ncolor+=(texture2D(textureSampler,vUV+vec2(0.0,blurOffsets[i]*multiplier))*blurWeights[i]);\n#endif\n}\ncolor.a=1.0;\ngl_FragColor=color;\n}\n#endif\n#if defined(TEXTURE_ADDER)\nuniform sampler2D otherSampler;\nvoid main() {\nvec4 sum=texture2D(textureSampler,vUV)+texture2D(otherSampler,vUV);\nsum.a=clamp(sum.a,0.0,1.0);\ngl_FragColor=sum;\n}\n#endif\n#if defined(LUMINANCE_GENERATOR)\nuniform vec2 lumOffsets[4];\nvoid main() {\nfloat average=0.0;\nvec4 color=vec4(0.0,0.0,0.0,0.0);\nfloat maximum=-1e20;\nfor (int i=0; i<4; i++) {\ncolor=texture2D(textureSampler,vUV+lumOffsets[i]);\nfloat GreyValue=length(color.rgb);\nmaximum=max(maximum,GreyValue);\naverage+=(0.25*log(1e-5+GreyValue));\n}\naverage=exp(average);\ngl_FragColor=vec4(average,maximum,0.0,1.0);\n}\n#endif\n#if defined(DOWN_SAMPLE)\nuniform vec2 dsOffsets[9];\nuniform float halfDestPixelSize;\n#ifdef FINAL_DOWN_SAMPLE\nvec4 pack(float value) {\nconst vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);\nconst vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);\nvec4 res=fract(value*bit_shift);\nres-=res.xxyz*bit_mask;\nreturn res;\n}\n#endif\nvoid main() {\nvec4 color=vec4(0.0,0.0,0.0,0.0);\nfloat average=0.0;\nfor (int i=0; i<9; i++) {\ncolor=texture2D(textureSampler,vUV+vec2(halfDestPixelSize,halfDestPixelSize)+dsOffsets[i]);\naverage+=color.r;\n}\naverage/=9.0;\n#ifndef FINAL_DOWN_SAMPLE\ngl_FragColor=vec4(average,average,0.0,1.0);\n#else\ngl_FragColor=pack(average);\n#endif\n}\n#endif\n#if defined(BRIGHT_PASS)\nuniform vec2 dsOffsets[4];\nuniform float brightThreshold;\nvoid main() {\nvec4 average=vec4(0.0,0.0,0.0,0.0);\naverage=texture2D(textureSampler,vUV+vec2(dsOffsets[0].x,dsOffsets[0].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[1].x,dsOffsets[1].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[2].x,dsOffsets[2].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[3].x,dsOffsets[3].y));\naverage*=0.25;\nfloat luminance=length(average.rgb);\nif (luminance<brightThreshold) {\naverage=vec4(0.0,0.0,0.0,1.0);\n}\ngl_FragColor=average;\n}\n#endif\n#if defined(DOWN_SAMPLE_X4)\nuniform vec2 dsOffsets[16];\nvoid main() {\nvec4 average=vec4(0.0,0.0,0.0,0.0);\naverage=texture2D(textureSampler,vUV+dsOffsets[0]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[1]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[2]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[3]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[4]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[5]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[6]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[7]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[8]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[9]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[10]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[11]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[12]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[13]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[14]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[15]);\naverage/=16.0;\ngl_FragColor=average;\n}\n#endif\n#if defined(HDR)\nuniform sampler2D otherSampler;\nuniform float exposure;\nuniform float avgLuminance;\nvoid main() {\nvec4 color=texture2D(textureSampler,vUV)+texture2D(otherSampler,vUV);\nvec4 adjustedColor=color/avgLuminance*exposure;\ncolor=adjustedColor;\ncolor.a=1.0;\ngl_FragColor=color;\n}\n#endif\n",layerPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec4 color;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\ngl_FragColor=baseColor*color;\n}",layerVertexShader:"\nattribute vec2 position;\n\nuniform vec2 scale;\nuniform vec2 offset;\nuniform mat4 textureMatrix;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvec2 shiftedPosition=position*scale+offset;\nvUV=vec2(textureMatrix*vec4(shiftedPosition*madd+madd,1.0,0.0));\ngl_Position=vec4(shiftedPosition,0.0,1.0);\n}",legacydefaultPixelShader:"#define MAP_PROJECTION 4.\n\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;\n\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<lightFragmentDeclaration>[0]\n#include<lightFragmentDeclaration>[1]\n#include<lightFragmentDeclaration>[2]\n#include<lightFragmentDeclaration>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef REFLECTION\nvarying vec3 vReflectionUVW;\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\nuniform vec2 vReflectionInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform sampler2D emissiveSampler;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nvarying vec2 vSpecularUV;\nuniform vec2 vSpecularInfos;\nuniform sampler2D specularSampler;\n#endif\n\n#include<fresnelFunction>\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;\nuniform vec4 diffuseRightColor;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n#include<clipPlaneFragmentDeclaration>\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 normalW=normalize(vNormalW);\n\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV).rgb*vAmbientInfos.y;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\nglossiness=vSpecularColor.a;\n#endif\nfloat shadow=1.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n\nvec3 reflectionColor=vec3(0.,0.,0.);\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb*vReflectionInfos.x;\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\nreflectionColor=texture2D(reflection2DSampler,coords).rgb*vReflectionInfos.x;\n#endif\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n\nfloat alpha=vDiffuseColor.a;\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nemissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef SPECULARTERM\nvec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nspecularColor=texture2D(specularSampler,vSpecularUV).rgb*vSpecularInfos.y;\n#endif\n#endif\n\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\ndiffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}",legacydefaultVertexShader:"\nattribute vec3 position;\nattribute vec3 normal;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nvarying vec2 vSpecularUV;\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nvarying vec2 vBumpUV;\nuniform vec2 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<shadowsVertexDeclaration>\n#ifdef REFLECTION\nuniform vec3 vEyePosition;\nvarying vec3 vReflectionUVW;\nuniform mat4 reflectionMatrix;\nvec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)\n{\n#ifdef REFLECTIONMAP_SPHERICAL\nvec3 coords=vec3(view*vec4(worldNormal,0.0));\nreturn vec3(reflectionMatrix*vec4(coords,1.0));\n#endif\n#ifdef REFLECTIONMAP_PLANAR\nvec3 viewDir=worldPos.xyz-vEyePosition;\nvec3 coords=normalize(reflect(viewDir,worldNormal));\nreturn vec3(reflectionMatrix*vec4(coords,1));\n#endif\n#ifdef REFLECTIONMAP_CUBIC\nvec3 viewDir=worldPos.xyz-vEyePosition;\nvec3 coords=reflect(viewDir,worldNormal);\n#ifdef INVERTCUBICMAP\ncoords.y=1.0-coords.y;\n#endif\nreturn vec3(reflectionMatrix*vec4(coords,0));\n#endif\n#ifdef REFLECTIONMAP_PROJECTION\nreturn vec3(reflectionMatrix*(view*worldPos));\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nreturn position;\n#endif\n#ifdef REFLECTIONMAP_EXPLICIT\nreturn vec3(0,0,0);\n#endif\n}\n#endif\nvoid main(void) {\nmat4 finalWorld=world;\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef AMBIENT\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef OPACITY\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef REFLECTION\nvReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),vNormalW);\n#endif\n#ifdef EMISSIVE\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nif (vSpecularInfos.x == 0.)\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef BUMP\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<shadowsVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n}",legacypbrPixelShader:"precision mediump float;\n\n#define RECIPROCAL_PI2 0.15915494\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vAlbedoColor;\nuniform vec3 vReflectionColor;\nuniform vec4 vLightRadiuses;\n\nuniform vec4 vLightingIntensity;\nuniform vec4 vCameraInfos;\n#ifdef OVERLOADEDVALUES\nuniform vec4 vOverloadedIntensity;\nuniform vec3 vOverloadedAmbient;\nuniform vec3 vOverloadedAlbedo;\nuniform vec3 vOverloadedReflectivity;\nuniform vec3 vOverloadedEmissive;\nuniform vec3 vOverloadedReflection;\nuniform vec3 vOverloadedMicroSurface;\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nuniform vec4 vOverloadedShadowIntensity;\n#endif\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<lightFragmentDeclaration>[0]\n#include<lightFragmentDeclaration>[1]\n#include<lightFragmentDeclaration>[2]\n#include<lightFragmentDeclaration>[3]\n\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform sampler2D albedoSampler;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform vec2 vLightmapInfos;\nuniform sampler2D lightmapSampler;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform sampler2D reflectivitySampler;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<pbrFunctions>\n#include<harmonicsFunctions>\n#include<pbrLightFunctions>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 surfaceAlbedo=vec4(1.,1.,1.,1.);\nvec3 surfaceAlbedoContribution=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nsurfaceAlbedo=texture2D(albedoSampler,vAlbedoUV);\nsurfaceAlbedo=vec4(toLinearSpace(surfaceAlbedo.rgb),surfaceAlbedo.a);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#ifdef ALPHAFROMALBEDO\nalpha*=surfaceAlbedo.a;\n#endif\nsurfaceAlbedo.rgb*=vAlbedoInfos.y;\n#else\n\nsurfaceAlbedo.rgb=surfaceAlbedoContribution;\nsurfaceAlbedoContribution=vec3(1.,1.,1.);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceAlbedo.rgb=mix(surfaceAlbedo.rgb,vOverloadedAlbedo,vOverloadedIntensity.y);\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 ambientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nambientColor=texture2D(ambientSampler,vAmbientUV).rgb*vAmbientInfos.y;\n#ifdef OVERLOADEDVALUES\nambientColor.rgb=mix(ambientColor.rgb,vOverloadedAmbient,vOverloadedIntensity.x);\n#endif\n#endif\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor.rgb=mix(surfaceReflectivityColor.rgb,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV);\nsurfaceReflectivityColor=surfaceReflectivityColorMap.rgb;\nsurfaceReflectivityColor=toLinearSpace(surfaceReflectivityColor);\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface=surfaceReflectivityColorMap.a;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#endif\n#endif\n#ifdef OVERLOADEDVALUES\nmicroSurface=mix(microSurface,vOverloadedMicroSurface.x,vOverloadedMicroSurface.y);\n#endif\n\nfloat NdotV=max(0.00000000001,dot(normalW,viewDirectionW));\n\nmicroSurface=clamp(microSurface,0.,1.)*0.98;\n\nfloat roughness=clamp(1.-microSurface,0.000001,1.0);\n\nvec3 lightDiffuseContribution=vec3(0.,0.,0.);\n#ifdef OVERLOADEDSHADOWVALUES\nvec3 shadowedOnlyLightDiffuseContribution=vec3(1.,1.,1.);\n#endif\n#ifdef SPECULARTERM\nvec3 lightSpecularContribution= vec3(0.,0.,0.);\n#endif\nfloat notShadowLevel=1.; \nfloat NdotL=-1.;\nlightingInfo info;\n#include<pbrLightFunctionsCall>[0]\n#include<pbrLightFunctionsCall>[1]\n#include<pbrLightFunctionsCall>[2]\n#include<pbrLightFunctionsCall>[3]\n#ifdef SPECULARTERM\nlightSpecularContribution*=vLightingIntensity.w;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n\nvec3 environmentRadiance=vReflectionColor.rgb;\nvec3 environmentIrradiance=vReflectionColor.rgb;\n#ifdef OVERLOADEDVALUES\nenvironmentIrradiance=mix(environmentIrradiance,vOverloadedReflection,vOverloadedMicroSurface.z);\nenvironmentRadiance=mix(environmentRadiance,vOverloadedReflection,vOverloadedMicroSurface.z);\n#endif\nenvironmentRadiance*=vLightingIntensity.z;\nenvironmentIrradiance*=vLightingIntensity.z;\n\nvec3 specularEnvironmentR0=surfaceReflectivityColor.rgb;\nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0);\nvec3 specularEnvironmentReflectance=FresnelSchlickEnvironmentGGX(clamp(NdotV,0.,1.),specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n\nfloat reflectance=max(max(surfaceReflectivityColor.r,surfaceReflectivityColor.g),surfaceReflectivityColor.b);\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\nenvironmentRadiance*=specularEnvironmentReflectance;\n\nvec3 surfaceEmissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV).rgb;\nsurfaceEmissiveColor=toLinearSpace(emissiveColorTex.rgb)*surfaceEmissiveColor*vEmissiveInfos.y;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceEmissiveColor=mix(surfaceEmissiveColor,vOverloadedEmissive,vOverloadedIntensity.w);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=max(lightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\n#ifdef LINKEMISSIVEWITHALBEDO\nvec3 finalDiffuse=max((lightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max((shadowedOnlyLightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\nvec3 finalDiffuse=max(lightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#endif\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nfinalDiffuse=mix(finalDiffuse,shadowedOnlyLightDiffuseContribution,(1.0-vOverloadedShadowIntensity.y));\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=lightSpecularContribution*surfaceReflectivityColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+getLuminance(finalSpecular),0.,1.);\n#endif\n#ifdef RADIANCEOVERALPHA\nalpha=clamp(alpha+getLuminance(environmentRadiance),0.,1.);\n#endif\n\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance+surfaceEmissiveColor*vLightingIntensity.y,alpha);\n#else\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance,alpha);\n#endif\nfinalColor=max(finalColor,0.0);\n#ifdef CAMERATONEMAP\nfinalColor.rgb=toneMaps(finalColor.rgb);\n#endif\nfinalColor.rgb=toGammaSpace(finalColor.rgb);\n#ifdef CAMERACONTRAST\nfinalColor=contrasts(finalColor);\n#endif\ngl_FragColor=finalColor;\n}",legacypbrVertexShader:"precision mediump float;\n\nattribute vec3 position;\nattribute vec3 normal;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform mat4 albedoMatrix;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform mat4 reflectivityMatrix;\n#endif\n\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\nvoid main(void) {\nmat4 finalWorld=world;\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef ALBEDO\nif (vAlbedoInfos.x == 0.)\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef AMBIENT\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef OPACITY\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef EMISSIVE\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(REFLECTIVITY)\nif (vReflectivityInfos.x == 0.)\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include<clipPlaneVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n}",lensFlarePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec4 color;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\ngl_FragColor=baseColor*color;\n}",lensFlareVertexShader:"\nattribute vec2 position;\n\nuniform mat4 viewportMatrix;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=position*madd+madd;\ngl_Position=viewportMatrix*vec4(position,0.0,1.0);\n}",lensHighlightsPixelShader:"\nuniform sampler2D textureSampler; \n\nuniform float gain;\nuniform float threshold;\nuniform float screen_width;\nuniform float screen_height;\n\nvarying vec2 vUV;\n\nvec4 highlightColor(vec4 color) {\nvec4 highlight=color;\nfloat luminance=dot(highlight.rgb,vec3(0.2125,0.7154,0.0721));\nfloat lum_threshold;\nif (threshold>1.0) { lum_threshold=0.94+0.01*threshold; }\nelse { lum_threshold=0.5+0.44*threshold; }\nluminance=clamp((luminance-lum_threshold)*(1.0/(1.0-lum_threshold)),0.0,1.0);\nhighlight*=luminance*gain;\nhighlight.a=1.0;\nreturn highlight;\n}\nvoid main(void)\n{\nvec4 original=texture2D(textureSampler,vUV);\n\nif (gain == -1.0) {\ngl_FragColor=vec4(0.0,0.0,0.0,1.0);\nreturn;\n}\nfloat w=2.0/screen_width;\nfloat h=2.0/screen_height;\nfloat weight=1.0;\n\nvec4 blurred=vec4(0.0,0.0,0.0,0.0);\n#ifdef PENTAGON\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.84*w,0.43*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.48*w,-1.29*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.61*w,1.51*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.55*w,-0.74*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.71*w,-0.52*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.94*w,1.59*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.40*w,-1.87*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.62*w,1.16*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.09*w,0.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.46*w,-1.71*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.08*w,2.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.85*w,-1.89*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.89*w,0.16*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.29*w,1.88*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.40*w,-2.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.54*w,2.26*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.60*w,-0.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.31*w,-1.30*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.83*w,2.53*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.12*w,-2.48*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.60*w,1.11*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.99*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.50*w,-2.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.85*w,3.33*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.94*w,-1.92*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.27*w,-0.53*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.95*w,2.48*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.23*w,-3.04*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.17*w,2.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.97*w,-0.04*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.25*w,-2.00*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.31*w,3.08*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.94*w,-2.59*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.37*w,0.64*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.13*w,1.93*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.03*w,-3.65*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.60*w,3.17*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.14*w,-1.19*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.00*w,-1.19*h)));\n#else\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.85*w,0.36*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.52*w,-1.14*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.46*w,1.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.46*w,-0.83*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.79*w,-0.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.11*w,1.62*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.29*w,-2.07*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.69*w,1.39*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.28*w,0.12*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.65*w,-1.69*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.08*w,2.44*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.63*w,-1.90*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.55*w,0.31*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.13*w,1.52*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.56*w,-2.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.38*w,2.34*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.64*w,-0.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.53*w,-1.21*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.06*w,2.63*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.00*w,-2.69*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.59*w,1.32*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.78*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.57*w,-2.50*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.54*w,2.93*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.39*w,-1.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,-0.28*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.04*w,2.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.02*w,-3.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.09*w,2.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.07*w,-0.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.44*w,-1.90*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.52*w,3.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.68*w,-2.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,0.79*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.76*w,1.46*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.05*w,-2.94*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.21*w,2.88*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.84*w,-1.30*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.98*w,-0.96*h)));\n#endif\nblurred/=39.0;\ngl_FragColor=blurred;\n\n}",
  31. linePixelShader:"uniform vec4 color;\nvoid main(void) {\ngl_FragColor=color;\n}",lineVertexShader:"\nattribute vec3 position;\nattribute vec4 normal;\n\nuniform mat4 worldViewProjection;\nuniform float width;\nuniform float aspectRatio;\nvoid main(void) {\nvec4 viewPosition=worldViewProjection*vec4(position,1.0);\nvec4 viewPositionNext=worldViewProjection*vec4(normal.xyz,1.0);\nvec2 currentScreen=viewPosition.xy/viewPosition.w;\nvec2 nextScreen=viewPositionNext.xy/viewPositionNext.w;\ncurrentScreen.x*=aspectRatio;\nnextScreen.x*=aspectRatio;\nvec2 dir=normalize(nextScreen-currentScreen);\nvec2 normalDir=vec2(-dir.y,dir.x);\nnormalDir*=width/2.0;\nnormalDir.x/=aspectRatio;\nvec4 offset=vec4(normalDir*normal.w,0.0,0.0);\ngl_Position=viewPosition+offset;\n}",outlinePixelShader:"uniform vec4 color;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\nvoid main(void) {\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\ngl_FragColor=color;\n}",outlineVertexShader:"\nattribute vec3 position;\nattribute vec3 normal;\n#include<bonesDeclaration>\n\nuniform float offset;\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\nvoid main(void)\n{\nvec3 offsetPosition=position+normal*offset;\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(offsetPosition,1.0);\n#ifdef ALPHATEST\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}\n",particlesPixelShader:"\nvarying vec2 vUV;\nvarying vec4 vColor;\nuniform vec4 textureMask;\nuniform sampler2D diffuseSampler;\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\nvoid main(void) {\n#ifdef CLIPPLANE\nif (fClipDistance>0.0)\ndiscard;\n#endif\nvec4 baseColor=texture2D(diffuseSampler,vUV);\ngl_FragColor=(baseColor*textureMask+(vec4(1.,1.,1.,1.)-textureMask))*vColor;\n}",particlesVertexShader:"\nattribute vec3 position;\nattribute vec4 color;\nattribute vec4 options;\n\nuniform mat4 view;\nuniform mat4 projection;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nuniform mat4 invView;\nvarying float fClipDistance;\n#endif\nvoid main(void) { \nvec3 viewPos=(view*vec4(position,1.0)).xyz; \nvec3 cornerPos;\nfloat size=options.y;\nfloat angle=options.x;\nvec2 offset=options.zw;\ncornerPos=vec3(offset.x-0.5,offset.y-0.5,0.)*size;\n\nvec3 rotatedCorner;\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.z=0.;\n\nviewPos+=rotatedCorner;\ngl_Position=projection*vec4(viewPos,1.0); \nvColor=color;\nvUV=offset;\n\n#ifdef CLIPPLANE\nvec4 worldPos=invView*vec4(viewPos,1.0);\nfClipDistance=dot(worldPos,vClipPlane);\n#endif\n}",passPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nvoid main(void) \n{\ngl_FragColor=texture2D(textureSampler,vUV);\n}",pbrPixelShader:"#ifdef BUMP\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LODBASEDMICROSFURACE\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\nuniform vec4 vLightRadiuses;\n\nuniform vec4 vLightingIntensity;\nuniform vec4 vCameraInfos;\n#ifdef OVERLOADEDVALUES\nuniform vec4 vOverloadedIntensity;\nuniform vec3 vOverloadedAmbient;\nuniform vec3 vOverloadedAlbedo;\nuniform vec3 vOverloadedReflectivity;\nuniform vec3 vOverloadedEmissive;\nuniform vec3 vOverloadedReflection;\nuniform vec3 vOverloadedMicroSurface;\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nuniform vec4 vOverloadedShadowIntensity;\n#endif\n#if defined(REFLECTION) || defined(REFRACTION)\nuniform vec2 vMicrosurfaceTextureLods;\n#endif\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<lightFragmentDeclaration>[0]\n#include<lightFragmentDeclaration>[1]\n#include<lightFragmentDeclaration>[2]\n#include<lightFragmentDeclaration>[3]\n\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform sampler2D albedoSampler;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform vec2 vLightmapInfos;\nuniform sampler2D lightmapSampler;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform sampler2D reflectivitySampler;\n#endif\n\n#include<fresnelFunction>\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\nuniform mat4 refractionMatrix;\n#endif\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvarying vec3 vDirectionW;\n#endif\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n\n#include<pbrShadowFunctions>\n#include<pbrFunctions>\n#include<harmonicsFunctions>\n#include<pbrLightFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 surfaceAlbedo=vec4(1.,1.,1.,1.);\nvec3 surfaceAlbedoContribution=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nsurfaceAlbedo=texture2D(albedoSampler,vAlbedoUV);\nsurfaceAlbedo=vec4(toLinearSpace(surfaceAlbedo.rgb),surfaceAlbedo.a);\n#ifndef LINKREFRACTIONTOTRANSPARENCY\n#ifdef ALPHATEST\nif (surfaceAlbedo.a<0.4)\ndiscard;\n#endif\n#endif\n#ifdef ALPHAFROMALBEDO\nalpha*=surfaceAlbedo.a;\n#endif\nsurfaceAlbedo.rgb*=vAlbedoInfos.y;\n#else\n\nsurfaceAlbedo.rgb=surfaceAlbedoContribution;\nsurfaceAlbedoContribution=vec3(1.,1.,1.);\n#endif\n#ifdef VERTEXCOLOR\nsurfaceAlbedo.rgb*=vColor.rgb;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceAlbedo.rgb=mix(surfaceAlbedo.rgb,vOverloadedAlbedo,vOverloadedIntensity.y);\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#include<bumpFragment>\n\nvec3 ambientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nambientColor=texture2D(ambientSampler,vAmbientUV).rgb*vAmbientInfos.y;\n#ifdef OVERLOADEDVALUES\nambientColor.rgb=mix(ambientColor.rgb,vOverloadedAmbient,vOverloadedIntensity.x);\n#endif\n#endif\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor.rgb=mix(surfaceReflectivityColor.rgb,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV);\nsurfaceReflectivityColor=surfaceReflectivityColorMap.rgb;\nsurfaceReflectivityColor=toLinearSpace(surfaceReflectivityColor);\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface=surfaceReflectivityColorMap.a;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#endif\n#endif\n#ifdef OVERLOADEDVALUES\nmicroSurface=mix(microSurface,vOverloadedMicroSurface.x,vOverloadedMicroSurface.y);\n#endif\n\nfloat NdotV=max(0.00000000001,dot(normalW,viewDirectionW));\n\nmicroSurface=clamp(microSurface,0.,1.)*0.98;\n\nfloat roughness=clamp(1.-microSurface,0.000001,1.0);\n\nvec3 lightDiffuseContribution=vec3(0.,0.,0.);\n#ifdef OVERLOADEDSHADOWVALUES\nvec3 shadowedOnlyLightDiffuseContribution=vec3(1.,1.,1.);\n#endif\n#ifdef SPECULARTERM\nvec3 lightSpecularContribution= vec3(0.,0.,0.);\n#endif\nfloat notShadowLevel=1.; \nfloat NdotL=-1.;\nlightingInfo info;\n#include<pbrLightFunctionsCall>[0]\n#include<pbrLightFunctionsCall>[1]\n#include<pbrLightFunctionsCall>[2]\n#include<pbrLightFunctionsCall>[3]\n#ifdef SPECULARTERM\nlightSpecularContribution*=vLightingIntensity.w;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 surfaceRefractionColor=vec3(0.,0.,0.);\n\n#ifdef LODBASEDMICROSFURACE\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\n#endif\n#ifdef REFRACTION\nvec3 refractionVector=refract(-viewDirectionW,normalW,vRefractionInfos.y);\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFRACTION\nfloat lodRefraction=getMipMapIndexFromAverageSlopeWithPMREM(vMicrosurfaceTextureLods.y,alphaG);\n#else\nfloat lodRefraction=getMipMapIndexFromAverageSlope(vMicrosurfaceTextureLods.y,alphaG);\n#endif\n#else\nfloat biasRefraction=(vMicrosurfaceTextureLods.y+2.)*(1.0-microSurface);\n#endif\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0)\n{\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFRACTION\n\nif (microSurface>0.5)\n{\n\nfloat scaleRefraction=1.-exp2(lodRefraction)/exp2(vMicrosurfaceTextureLods.y); \nfloat maxRefraction=max(max(abs(refractionVector.x),abs(refractionVector.y)),abs(refractionVector.z));\nif (abs(refractionVector.x) != maxRefraction) refractionVector.x*=scaleRefraction;\nif (abs(refractionVector.y) != maxRefraction) refractionVector.y*=scaleRefraction;\nif (abs(refractionVector.z) != maxRefraction) refractionVector.z*=scaleRefraction;\n}\n#endif\nsurfaceRefractionColor=textureCubeLodEXT(refractionCubeSampler,refractionVector,lodRefraction).rgb*vRefractionInfos.x;\n#else\nsurfaceRefractionColor=textureCube(refractionCubeSampler,refractionVector,biasRefraction).rgb*vRefractionInfos.x;\n#endif\n}\n#ifndef REFRACTIONMAPINLINEARSPACE\nsurfaceRefractionColor=toLinearSpace(surfaceRefractionColor.rgb); \n#endif\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\n#ifdef LODBASEDMICROSFURACE\nsurfaceRefractionColor=texture2DLodEXT(refraction2DSampler,refractionCoords,lodRefraction).rgb*vRefractionInfos.x;\n#else\nsurfaceRefractionColor=texture2D(refraction2DSampler,refractionCoords,biasRefraction).rgb*vRefractionInfos.x;\n#endif \nsurfaceRefractionColor=toLinearSpace(surfaceRefractionColor.rgb); \n#endif\n#endif\n\nvec3 environmentRadiance=vReflectionColor.rgb;\nvec3 environmentIrradiance=vReflectionColor.rgb;\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFLECTION\nfloat lodReflection=getMipMapIndexFromAverageSlopeWithPMREM(vMicrosurfaceTextureLods.x,alphaG);\n#else\nfloat lodReflection=getMipMapIndexFromAverageSlope(vMicrosurfaceTextureLods.x,alphaG);\n#endif\n#else\nfloat biasReflection=(vMicrosurfaceTextureLods.x+2.)*(1.0-microSurface);\n#endif\n#ifdef REFLECTIONMAP_3D\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFLECTION\n\nif (microSurface>0.5)\n{\n\nfloat scaleReflection=1.-exp2(lodReflection)/exp2(vMicrosurfaceTextureLods.x); \nfloat maxReflection=max(max(abs(vReflectionUVW.x),abs(vReflectionUVW.y)),abs(vReflectionUVW.z));\nif (abs(vReflectionUVW.x) != maxReflection) vReflectionUVW.x*=scaleReflection;\nif (abs(vReflectionUVW.y) != maxReflection) vReflectionUVW.y*=scaleReflection;\nif (abs(vReflectionUVW.z) != maxReflection) vReflectionUVW.z*=scaleReflection;\n}\n#endif\nenvironmentRadiance=textureCubeLodEXT(reflectionCubeSampler,vReflectionUVW,lodReflection).rgb*vReflectionInfos.x;\n#else\nenvironmentRadiance=textureCube(reflectionCubeSampler,vReflectionUVW,biasReflection).rgb*vReflectionInfos.x;\n#endif\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifndef REFLECTIONMAP_SKYBOX\nvec3 normalEnvironmentSpace=(reflectionMatrix*vec4(normalW,1)).xyz;\nenvironmentIrradiance=EnvironmentIrradiance(normalEnvironmentSpace);\n#endif\n#else\nenvironmentRadiance=toLinearSpace(environmentRadiance.rgb);\nenvironmentIrradiance=textureCube(reflectionCubeSampler,normalW,20.).rgb*vReflectionInfos.x;\nenvironmentIrradiance=toLinearSpace(environmentIrradiance.rgb);\nenvironmentIrradiance*=0.2; \n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\n#ifdef LODBASEDMICROSFURACE\nenvironmentRadiance=texture2DLodEXT(reflection2DSampler,coords,lodReflection).rgb*vReflectionInfos.x;\n#else\nenvironmentRadiance=texture2D(reflection2DSampler,coords,biasReflection).rgb*vReflectionInfos.x;\n#endif\nenvironmentRadiance=toLinearSpace(environmentRadiance.rgb);\nenvironmentIrradiance=texture2D(reflection2DSampler,coords,20.).rgb*vReflectionInfos.x;\nenvironmentIrradiance=toLinearSpace(environmentIrradiance.rgb);\n#endif\n#endif\n#ifdef OVERLOADEDVALUES\nenvironmentIrradiance=mix(environmentIrradiance,vOverloadedReflection,vOverloadedMicroSurface.z);\nenvironmentRadiance=mix(environmentRadiance,vOverloadedReflection,vOverloadedMicroSurface.z);\n#endif\nenvironmentRadiance*=vLightingIntensity.z;\nenvironmentIrradiance*=vLightingIntensity.z;\n\nvec3 specularEnvironmentR0=surfaceReflectivityColor.rgb;\nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0);\nvec3 specularEnvironmentReflectance=FresnelSchlickEnvironmentGGX(clamp(NdotV,0.,1.),specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n\nvec3 refractance=vec3(0.0 ,0.0,0.0);\n#ifdef REFRACTION\nvec3 transmission=vec3(1.0 ,1.0,1.0);\n#ifdef LINKREFRACTIONTOTRANSPARENCY\n\ntransmission*=(1.0-alpha);\n\n\nvec3 mixedAlbedo=surfaceAlbedoContribution.rgb*surfaceAlbedo.rgb;\nfloat maxChannel=max(max(mixedAlbedo.r,mixedAlbedo.g),mixedAlbedo.b);\nvec3 tint=clamp(maxChannel*mixedAlbedo,0.0,1.0);\n\nsurfaceAlbedoContribution*=alpha;\n\nenvironmentIrradiance*=alpha;\n\nsurfaceRefractionColor*=tint;\n\nalpha=1.0;\n#endif\n\nvec3 bounceSpecularEnvironmentReflectance=(2.0*specularEnvironmentReflectance)/(1.0+specularEnvironmentReflectance);\nspecularEnvironmentReflectance=mix(bounceSpecularEnvironmentReflectance,specularEnvironmentReflectance,alpha);\n\ntransmission*=1.0-specularEnvironmentReflectance;\n\nrefractance=surfaceRefractionColor*transmission;\n#endif\n\nfloat reflectance=max(max(surfaceReflectivityColor.r,surfaceReflectivityColor.g),surfaceReflectivityColor.b);\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\nrefractance*=vLightingIntensity.z;\nenvironmentRadiance*=specularEnvironmentReflectance;\n\nvec3 surfaceEmissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV).rgb;\nsurfaceEmissiveColor=toLinearSpace(emissiveColorTex.rgb)*surfaceEmissiveColor*vEmissiveInfos.y;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceEmissiveColor=mix(surfaceEmissiveColor,vOverloadedEmissive,vOverloadedIntensity.w);\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nsurfaceEmissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=max(lightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\n#ifdef LINKEMISSIVEWITHALBEDO\nvec3 finalDiffuse=max((lightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max((shadowedOnlyLightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\nvec3 finalDiffuse=max(lightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#endif\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nfinalDiffuse=mix(finalDiffuse,shadowedOnlyLightDiffuseContribution,(1.0-vOverloadedShadowIntensity.y));\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=lightSpecularContribution*surfaceReflectivityColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+getLuminance(finalSpecular),0.,1.);\n#endif\n#ifdef RADIANCEOVERALPHA\nalpha=clamp(alpha+getLuminance(environmentRadiance),0.,1.);\n#endif\n\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance+surfaceEmissiveColor*vLightingIntensity.y+refractance,alpha);\n#else\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance+refractance,alpha);\n#endif\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV).rgb*vLightmapInfos.y;\n#ifdef USELIGHTMAPASSHADOWMAP\nfinalColor.rgb*=lightmapColor;\n#else\nfinalColor.rgb+=lightmapColor;\n#endif\n#endif\nfinalColor=max(finalColor,0.0);\n#ifdef CAMERATONEMAP\nfinalColor.rgb=toneMaps(finalColor.rgb);\n#endif\nfinalColor.rgb=toGammaSpace(finalColor.rgb);\n#ifdef CAMERACONTRAST\nfinalColor=contrasts(finalColor);\n#endif\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n#include<logDepthFragment>\n#include<fogFragment>(color,finalColor)\ngl_FragColor=finalColor;\n}",pbrVertexShader:"precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform mat4 albedoMatrix;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform mat4 reflectivityMatrix;\n#endif\n#ifdef BUMP\nvarying vec2 vBumpUV;\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<shadowsVertexDeclaration>\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=position;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvDirectionW=normalize(vec3(finalWorld*vec4(position,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef ALBEDO\nif (vAlbedoInfos.x == 0.)\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef AMBIENT\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef OPACITY\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef EMISSIVE\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef LIGHTMAP\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(REFLECTIVITY)\nif (vReflectivityInfos.x == 0.)\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef BUMP\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n\n#include<logDepthVertex>\n}",postprocessVertexShader:"\nattribute vec2 position;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=position*madd+madd;\ngl_Position=vec4(position,0.0,1.0);\n}",proceduralVertexShader:"\nattribute vec2 position;\n\nvarying vec2 vPosition;\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvPosition=position;\nvUV=position*madd+madd;\ngl_Position=vec4(position,0.0,1.0);\n}",refractionPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D refractionSampler;\n\nuniform vec3 baseColor;\nuniform float depth;\nuniform float colorLevel;\nvoid main() {\nfloat ref=1.0-texture2D(refractionSampler,vUV).r;\nvec2 uv=vUV-vec2(0.5);\nvec2 offset=uv*depth*ref;\nvec3 sourceColor=texture2D(textureSampler,vUV-offset).rgb;\ngl_FragColor=vec4(sourceColor+sourceColor*ref*colorLevel,1.0);\n}",shadowMapPixelShader:"vec4 pack(float depth)\n{\nconst vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);\nconst vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);\nvec4 res=fract(depth*bit_shift);\nres-=res.xxyz*bit_mask;\nreturn res;\n}\n\nvec2 packHalf(float depth) \n{ \nconst vec2 bitOffset=vec2(1.0/255.,0.);\nvec2 color=vec2(depth,fract(depth*255.));\nreturn color-(color.yy*bitOffset);\n}\nvarying vec4 vPosition;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef CUBEMAP\nuniform vec3 lightPosition;\nuniform vec2 depthValues;\n#endif\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\n#ifdef CUBEMAP\nvec3 directionToLight=vPosition.xyz-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth-depthValues.x)/(depthValues.y-depthValues.x);\ndepth=clamp(depth,0.,1.0);\n#else\nfloat depth=vPosition.z/vPosition.w;\ndepth=depth*0.5+0.5;\n#endif\n#ifdef VSM\nfloat moment1=depth;\nfloat moment2=moment1*moment1;\ngl_FragColor=vec4(packHalf(moment1),packHalf(moment2));\n#else\ngl_FragColor=pack(depth);\n#endif\n}",shadowMapVertexShader:"\nattribute vec3 position;\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\nvarying vec4 vPosition;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\n#ifdef CUBEMAP\nvPosition=finalWorld*vec4(position,1.0);\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#else\nvPosition=viewProjection*finalWorld*vec4(position,1.0);\ngl_Position=vPosition;\n#endif\n#ifdef ALPHATEST\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",spritesPixelShader:"uniform bool alphaTest;\nvarying vec4 vColor;\n\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\nvec4 color=texture2D(diffuseSampler,vUV);\nif (alphaTest) \n{\nif (color.a<0.95)\ndiscard;\n}\ncolor*=vColor;\n#include<fogFragment>\ngl_FragColor=color;\n}",spritesVertexShader:"\nattribute vec4 position;\nattribute vec4 options;\nattribute vec4 cellInfo;\nattribute vec4 color;\n\nuniform vec2 textureInfos;\nuniform mat4 view;\nuniform mat4 projection;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\n#include<fogVertexDeclaration>\nvoid main(void) { \nvec3 viewPos=(view*vec4(position.xyz,1.0)).xyz; \nvec2 cornerPos;\nfloat angle=position.w;\nvec2 size=vec2(options.x,options.y);\nvec2 offset=options.zw;\nvec2 uvScale=textureInfos.xy;\ncornerPos=vec2(offset.x-0.5,offset.y-0.5)*size;\n\nvec3 rotatedCorner;\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.z=0.;\n\nviewPos+=rotatedCorner;\ngl_Position=projection*vec4(viewPos,1.0); \n\nvColor=color;\n\nvec2 uvOffset=vec2(abs(offset.x-cellInfo.x),1.0-abs(offset.y-cellInfo.y));\nvUV=(uvOffset+cellInfo.zw)*uvScale;\n\n#ifdef FOG\nfFogDistance=viewPos.z;\n#endif\n}",ssaoPixelShader:"uniform sampler2D textureSampler;\nuniform sampler2D randomSampler;\nuniform float randTextureTiles;\nuniform float samplesFactor;\nuniform vec3 sampleSphere[SAMPLES];\nuniform float totalStrength;\nuniform float radius;\nuniform float area;\nuniform float fallOff;\nuniform float base;\nvarying vec2 vUV;\nvec3 normalFromDepth(float depth,vec2 coords) {\nvec2 offset1=vec2(0.0,radius);\nvec2 offset2=vec2(radius,0.0);\nfloat depth1=texture2D(textureSampler,coords+offset1).r;\nfloat depth2=texture2D(textureSampler,coords+offset2).r;\nvec3 p1=vec3(offset1,depth1-depth);\nvec3 p2=vec3(offset2,depth2-depth);\nvec3 normal=cross(p1,p2);\nnormal.z=-normal.z;\nreturn normalize(normal);\n}\nvoid main()\n{\nvec3 random=normalize(texture2D(randomSampler,vUV*randTextureTiles).rgb);\nfloat depth=texture2D(textureSampler,vUV).r;\nvec3 position=vec3(vUV,depth);\nvec3 normal=normalFromDepth(depth,vUV);\nfloat radiusDepth=radius/depth;\nfloat occlusion=0.0;\nvec3 ray;\nvec3 hemiRay;\nfloat occlusionDepth;\nfloat difference;\nfor (int i=0; i<SAMPLES; i++)\n{\nray=radiusDepth*reflect(sampleSphere[i],random);\nhemiRay=position+sign(dot(ray,normal))*ray;\nocclusionDepth=texture2D(textureSampler,clamp(hemiRay.xy,vec2(0.001,0.001),vec2(0.999,0.999))).r;\ndifference=depth-occlusionDepth;\nocclusion+=step(fallOff,difference)*(1.0-smoothstep(fallOff,area,difference));\n}\nfloat ao=1.0-totalStrength*occlusion*samplesFactor;\nfloat result=clamp(ao+base,0.0,1.0);\ngl_FragColor.r=result;\ngl_FragColor.g=result;\ngl_FragColor.b=result;\ngl_FragColor.a=1.0;\n}\n",ssaoCombinePixelShader:"uniform sampler2D textureSampler;\nuniform sampler2D originalColor;\nvarying vec2 vUV;\nvoid main(void) {\nvec4 ssaoColor=texture2D(textureSampler,vUV);\nvec4 sceneColor=texture2D(originalColor,vUV);\ngl_FragColor=sceneColor*ssaoColor;\n}\n",stereoscopicInterlacePixelShader:"const vec3 TWO=vec3(2.0,2.0,2.0);\nvarying vec2 vUV;\nuniform sampler2D camASampler;\nuniform sampler2D textureSampler;\nuniform vec2 stepSize;\nvoid main(void)\n{\nbool useCamB;\nvec2 texCoord1;\nvec2 texCoord2;\nvec3 frag1;\nvec3 frag2;\n#ifdef IS_STEREOSCOPIC_HORIZ\nuseCamB=vUV.x>0.5;\ntexCoord1=vec2(useCamB ? (vUV.x-0.5)*2.0 : vUV.x*2.0,vUV.y);\ntexCoord2=vec2(texCoord1.x+stepSize.x,vUV.y);\n#else\nuseCamB=vUV.y>0.5;\ntexCoord1=vec2(vUV.x,useCamB ? (vUV.y-0.5)*2.0 : vUV.y*2.0);\ntexCoord2=vec2(vUV.x,texCoord1.y+stepSize.y);\n#endif\n\nif (useCamB){\nfrag1=texture2D(textureSampler,texCoord1).rgb;\nfrag2=texture2D(textureSampler,texCoord2).rgb;\n}else{\nfrag1=texture2D(camASampler ,texCoord1).rgb;\nfrag2=texture2D(camASampler ,texCoord2).rgb;\n}\ngl_FragColor=vec4((frag1+frag2)/TWO,1.0);\n}",tonemapPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform float _ExposureAdjustment;\n#if defined(HABLE_TONEMAPPING)\nconst float A=0.15;\nconst float B=0.50;\nconst float C=0.10;\nconst float D=0.20;\nconst float E=0.02;\nconst float F=0.30;\nconst float W=11.2;\n#endif\nfloat Luminance(vec3 c)\n{\nreturn dot(c,vec3(0.22,0.707,0.071));\n}\nvoid main(void) \n{\nvec3 colour=texture2D(textureSampler,vUV).rgb;\n#if defined(REINHARD_TONEMAPPING)\nfloat lum=Luminance(colour.rgb); \nfloat lumTm=lum*_ExposureAdjustment;\nfloat scale=lumTm/(1.0+lumTm); \ncolour*=scale/lum;\n#elif defined(HABLE_TONEMAPPING)\ncolour*=_ExposureAdjustment;\nconst float ExposureBias=2.0;\nvec3 x=ExposureBias*colour;\nvec3 curr=((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;\nx=vec3(W,W,W);\nvec3 whiteScale=1.0/(((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F);\ncolour=curr*whiteScale;\n#elif defined(OPTIMIZED_HEJIDAWSON_TONEMAPPING)\ncolour*=_ExposureAdjustment;\nvec3 X=max(vec3(0.0,0.0,0.0),colour-0.004);\nvec3 retColor=(X*(6.2*X+0.5))/(X*(6.2*X+1.7)+0.06);\ncolour=retColor*retColor;\n#elif defined(PHOTOGRAPHIC_TONEMAPPING)\ncolour=vec3(1.0,1.0,1.0)-exp2(-_ExposureAdjustment*colour);\n#endif\ngl_FragColor=vec4(colour.rgb,1.0);\n}",volumetricLightScatteringPixelShader:"uniform sampler2D textureSampler;\nuniform sampler2D lightScatteringSampler;\nuniform float decay;\nuniform float exposure;\nuniform float weight;\nuniform float density;\nuniform vec2 meshPositionOnScreen;\nvarying vec2 vUV;\nvoid main(void) {\nvec2 tc=vUV;\nvec2 deltaTexCoord=(tc-meshPositionOnScreen.xy);\ndeltaTexCoord*=1.0/float(NUM_SAMPLES)*density;\nfloat illuminationDecay=1.0;\nvec4 color=texture2D(lightScatteringSampler,tc)*0.4;\nfor(int i=0; i<NUM_SAMPLES; i++) {\ntc-=deltaTexCoord;\nvec4 sample=texture2D(lightScatteringSampler,tc)*0.4;\nsample*=illuminationDecay*weight;\ncolor+=sample;\nilluminationDecay*=decay;\n}\nvec4 realColor=texture2D(textureSampler,vUV);\ngl_FragColor=((vec4((vec3(color.r,color.g,color.b)*exposure),1))+(realColor*(1.5-0.4)));\n}\n",volumetricLightScatteringPassPixelShader:"#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;\n#endif\n#if defined(ALPHATEST)\nuniform sampler2D diffuseSampler;\n#endif\nvoid main(void)\n{\n#if defined(ALPHATEST)\nvec4 diffuseColor=texture2D(diffuseSampler,vUV);\nif (diffuseColor.a<0.4)\ndiscard;\n#endif\ngl_FragColor=vec4(0.0,0.0,0.0,1.0);\n}\n",vrDistortionCorrectionPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 LensCenter;\nuniform vec2 Scale;\nuniform vec2 ScaleIn;\nuniform vec4 HmdWarpParam;\nvec2 HmdWarp(vec2 in01) {\nvec2 theta=(in01-LensCenter)*ScaleIn; \nfloat rSq=theta.x*theta.x+theta.y*theta.y;\nvec2 rvector=theta*(HmdWarpParam.x+HmdWarpParam.y*rSq+HmdWarpParam.z*rSq*rSq+HmdWarpParam.w*rSq*rSq*rSq);\nreturn LensCenter+Scale*rvector;\n}\nvoid main(void)\n{\nvec2 tc=HmdWarp(vUV);\nif (tc.x <0.0 || tc.x>1.0 || tc.y<0.0 || tc.y>1.0)\ngl_FragColor=vec4(0.0,0.0,0.0,1.0);\nelse{\ngl_FragColor=vec4(texture2D(textureSampler,tc).rgb,1.0);\n}\n}"
  32. },BABYLON.Effect.IncludesShadersStore={bonesDeclaration:"#if NUM_BONE_INFLUENCERS>0\nuniform mat4 mBones[BonesPerMesh];\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nattribute vec4 matricesIndicesExtra;\nattribute vec4 matricesWeightsExtra;\n#endif\n#endif",bonesVertex:"#if NUM_BONE_INFLUENCERS>0\nmat4 influence;\ninfluence=mBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\ninfluence+=mBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif \n#if NUM_BONE_INFLUENCERS>2\ninfluence+=mBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif \n#if NUM_BONE_INFLUENCERS>3\ninfluence+=mBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif \n#if NUM_BONE_INFLUENCERS>4\ninfluence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif \n#if NUM_BONE_INFLUENCERS>5\ninfluence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif \n#if NUM_BONE_INFLUENCERS>6\ninfluence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif \n#if NUM_BONE_INFLUENCERS>7\ninfluence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif \nfinalWorld=finalWorld*influence;\n#endif",bumpFragment:"#ifdef BUMP\nvec2 bumpUV=vBumpUV;\n#endif\n#if defined(BUMP) || defined(PARALLAX)\nmat3 TBN=cotangent_frame(normalW*vBumpInfos.y,-viewDirectionW,bumpUV);\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nvec2 uvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,bumpUV,vBumpInfos.z);\n#else\nvec2 uvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\ndiffuseUV+=uvOffset;\nbumpUV+=uvOffset;\n#endif\n#ifdef BUMP\nnormalW=perturbNormal(viewDirectionW,TBN,bumpUV);\n#endif",bumpFragmentFunctions:"#ifdef BUMP\nvarying vec2 vBumpUV;\nuniform vec3 vBumpInfos;\nuniform sampler2D bumpSampler;\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 binormal=dp2perp*duv1.y+dp1perp*duv2.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(binormal,binormal)));\nreturn mat3(tangent*invmax,binormal*invmax,normal);\n}\nvec3 perturbNormal(vec3 viewDir,mat3 cotangentFrame,vec2 uv)\n{\nvec3 map=texture2D(bumpSampler,uv).xyz;\nmap=map*255./127.-128./127.;\nreturn normalize(cotangentFrame*map);\n}\n#ifdef PARALLAX\nconst float minSamples=4.;\nconst float maxSamples=15.;\nconst int iMaxSamples=15;\n\nvec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {\nfloat parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;\nparallaxLimit*=parallaxScale;\nvec2 vOffsetDir=normalize(vViewDirCoT.xy);\nvec2 vMaxOffset=vOffsetDir*parallaxLimit;\nfloat numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));\nfloat stepSize=1.0/numSamples;\n\nfloat currRayHeight=1.0;\nvec2 vCurrOffset=vec2(0,0);\nvec2 vLastOffset=vec2(0,0);\nfloat lastSampledHeight=1.0;\nfloat currSampledHeight=1.0;\nfor (int i=0; i<iMaxSamples; i++)\n{\ncurrSampledHeight=texture2D(bumpSampler,vBumpUV+vCurrOffset).w;\n\nif (currSampledHeight>currRayHeight)\n{\nfloat delta1=currSampledHeight-currRayHeight;\nfloat delta2=(currRayHeight+stepSize)-lastSampledHeight;\nfloat ratio=delta1/(delta1+delta2);\nvCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;\n\nbreak;\n}\nelse\n{\ncurrRayHeight-=stepSize;\nvLastOffset=vCurrOffset;\nvCurrOffset+=stepSize*vMaxOffset;\nlastSampledHeight=currSampledHeight;\n}\n}\nreturn vCurrOffset;\n}\nvec2 parallaxOffset(vec3 viewDir,float heightScale)\n{\n\nfloat height=texture2D(bumpSampler,vBumpUV).w;\nvec2 texCoordOffset=heightScale*viewDir.xy*height;\nreturn -texCoordOffset;\n}\n#endif\n#endif",clipPlaneFragment:"#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif",clipPlaneFragmentDeclaration:"#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif",clipPlaneVertex:"#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif",clipPlaneVertexDeclaration:"#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif",fogFragment:"#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif",fogFragmentDeclaration:"#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying float fFogDistance;\nfloat CalcFogFactor()\n{\nfloat fogCoeff=1.0;\nfloat fogStart=vFogInfos.y;\nfloat fogEnd=vFogInfos.z;\nfloat fogDensity=vFogInfos.w;\nif (FOGMODE_LINEAR == vFogInfos.x)\n{\nfogCoeff=(fogEnd-fFogDistance)/(fogEnd-fogStart);\n}\nelse if (FOGMODE_EXP == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fFogDistance*fogDensity);\n}\nelse if (FOGMODE_EXP2 == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fFogDistance*fFogDistance*fogDensity*fogDensity);\n}\nreturn clamp(fogCoeff,0.0,1.0);\n}\n#endif",fogVertex:"#ifdef FOG\nfFogDistance=(view*worldPos).z;\n#endif",fogVertexDeclaration:"#ifdef FOG\nvarying float fFogDistance;\n#endif",fresnelFunction:"#ifdef FRESNEL\nfloat computeFresnelTerm(vec3 viewDirection,vec3 worldNormal,float bias,float power)\n{\nfloat fresnelTerm=pow(bias+abs(dot(viewDirection,worldNormal)),power);\nreturn clamp(fresnelTerm,0.,1.);\n}\n#endif",harmonicsFunctions:"#ifdef USESPHERICALFROMREFLECTIONMAP\nuniform vec3 vSphericalX;\nuniform vec3 vSphericalY;\nuniform vec3 vSphericalZ;\nuniform vec3 vSphericalXX;\nuniform vec3 vSphericalYY;\nuniform vec3 vSphericalZZ;\nuniform vec3 vSphericalXY;\nuniform vec3 vSphericalYZ;\nuniform vec3 vSphericalZX;\nvec3 EnvironmentIrradiance(vec3 normal)\n{\n\n\n\nvec3 result =\nvSphericalX*normal.x +\nvSphericalY*normal.y +\nvSphericalZ*normal.z +\nvSphericalXX*normal.x*normal.x +\nvSphericalYY*normal.y*normal.y +\nvSphericalZZ*normal.z*normal.z +\nvSphericalYZ*normal.y*normal.z +\nvSphericalZX*normal.z*normal.x +\nvSphericalXY*normal.x*normal.y;\nreturn result.rgb;\n}\n#endif",helperFunctions:"mat3 transposeMat3(mat3 inMatrix) {\nvec3 i0=inMatrix[0];\nvec3 i1=inMatrix[1];\nvec3 i2=inMatrix[2];\nmat3 outMatrix=mat3(\nvec3(i0.x,i1.x,i2.x),\nvec3(i0.y,i1.y,i2.y),\nvec3(i0.z,i1.z,i2.z)\n);\nreturn outMatrix;\n}",instancesDeclaration:"#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif",instancesVertex:"#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif",lightFragment:"#ifdef LIGHT{X}\n#ifndef SPECULARTERM\nvec3 vLightSpecular{X}=vec3(0.);\n#endif\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData{X},vLightDirection{X},vLightDiffuse{X}.rgb,vLightSpecular{X},vLightDiffuse{X}.a,glossiness);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData{X},vLightDiffuse{X}.rgb,vLightSpecular{X},vLightGround{X},glossiness);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,vLightData{X},vLightDiffuse{X}.rgb,vLightSpecular{X},vLightDiffuse{X}.a,glossiness);\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWVSM{X}\nshadow=computeShadowWithVSM(vPositionFromLight{X},shadowSampler{X},shadowsInfo{X}.z,shadowsInfo{X}.x);\n#else\n#ifdef SHADOWPCF{X}\n#if defined(POINTLIGHT{X})\nshadow=computeShadowWithPCFCube(vLightData{X}.xyz,shadowSampler{X},shadowsInfo{X}.y,shadowsInfo{X}.z,shadowsInfo{X}.x);\n#else\nshadow=computeShadowWithPCF(vPositionFromLight{X},shadowSampler{X},shadowsInfo{X}.y,shadowsInfo{X}.z,shadowsInfo{X}.x);\n#endif\n#else\n#if defined(POINTLIGHT{X})\nshadow=computeShadowCube(vLightData{X}.xyz,shadowSampler{X},shadowsInfo{X}.x,shadowsInfo{X}.z);\n#else\nshadow=computeShadow(vPositionFromLight{X},shadowSampler{X},shadowsInfo{X}.x,shadowsInfo{X}.z);\n#endif\n#endif\n#endif\n#else\nshadow=1.;\n#endif\ndiffuseBase+=info.diffuse*shadow;\n#ifdef SPECULARTERM\nspecularBase+=info.specular*shadow;\n#endif\n#endif",lightFragmentDeclaration:"#ifdef LIGHT{X}\nuniform vec4 vLightData{X};\nuniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular{X};\n#endif\n#ifdef SHADOW{X}\n#if defined(SPOTLIGHT{X}) || defined(DIRLIGHT{X})\nvarying vec4 vPositionFromLight{X};\nuniform sampler2D shadowSampler{X};\n#else\nuniform samplerCube shadowSampler{X};\n#endif\nuniform vec3 shadowsInfo{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};\n#endif\n#ifdef HEMILIGHT{X}\nuniform vec3 vLightGround{X};\n#endif\n#endif",lightsFragmentFunctions:"\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 lightVectorW;\nfloat attenuation=1.0;\nif (lightData.w == 0.)\n{\nvec3 direction=lightData.xyz-vPositionW;\nattenuation=max(0.,1.0-length(direction)/range);\nlightVectorW=normalize(direction);\n}\nelse\n{\nlightVectorW=normalize(-lightData.xyz);\n}\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 direction=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(direction);\nfloat attenuation=max(0.,1.0-length(direction)/range);\n\nfloat cosAngle=max(0.,dot(-lightDirection.xyz,lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\nattenuation*=cosAngle;\n\nfloat ndl=max(0.,dot(vNormal,-lightDirection.xyz));\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW-lightDirection.xyz);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {\nlightingInfo result;\n\nfloat ndl=dot(vNormal,lightData.xyz)*0.5+0.5;\nresult.diffuse=mix(groundColor,diffuseColor,ndl);\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightData.xyz);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor;\n#endif\nreturn result;\n}\n",logDepthDeclaration:"#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif",logDepthFragment:"#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif",logDepthVertex:"#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif",pbrFunctions:"\n#define RECIPROCAL_PI2 0.15915494\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\n\nconst float kPi=3.1415926535897932384626433832795;\nconst float kRougnhessToAlphaScale=0.1;\nconst float kRougnhessToAlphaOffset=0.29248125;\nfloat Square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\nfloat convertRoughnessToAverageSlope(float roughness)\n{\n\nconst float kMinimumVariance=0.0005;\nfloat alphaG=Square(roughness)+kMinimumVariance;\nreturn alphaG;\n}\n\nfloat getMipMapIndexFromAverageSlope(float maxMipLevel,float alpha)\n{\n\n\n\n\n\n\n\nfloat mip=kRougnhessToAlphaOffset+maxMipLevel+(maxMipLevel*kRougnhessToAlphaScale*log2(alpha));\nreturn clamp(mip,0.,maxMipLevel);\n}\nfloat getMipMapIndexFromAverageSlopeWithPMREM(float maxMipLevel,float alphaG)\n{\nfloat specularPower=clamp(2./alphaG-2.,0.000001,2048.);\n\nreturn clamp(- 0.5*log2(specularPower)+5.5,0.,maxMipLevel);\n}\n\nfloat smithVisibilityG1_TrowbridgeReitzGGX(float dot,float alphaG)\n{\nfloat tanSquared=(1.0-dot*dot)/(dot*dot);\nreturn 2.0/(1.0+sqrt(1.0+alphaG*alphaG*tanSquared));\n}\nfloat smithVisibilityG_TrowbridgeReitzGGX_Walter(float NdotL,float NdotV,float alphaG)\n{\nreturn smithVisibilityG1_TrowbridgeReitzGGX(NdotL,alphaG)*smithVisibilityG1_TrowbridgeReitzGGX(NdotV,alphaG);\n}\n\n\nfloat normalDistributionFunction_TrowbridgeReitzGGX(float NdotH,float alphaG)\n{\n\n\n\nfloat a2=Square(alphaG);\nfloat d=NdotH*NdotH*(a2-1.0)+1.0;\nreturn a2/(kPi*d*d);\n}\nvec3 fresnelSchlickGGX(float VdotH,vec3 reflectance0,vec3 reflectance90)\n{\nreturn reflectance0+(reflectance90-reflectance0)*pow(clamp(1.0-VdotH,0.,1.),5.0);\n}\nvec3 FresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{\n\nfloat weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);\nreturn reflectance0+weight*(reflectance90-reflectance0)*pow(clamp(1.0-VdotN,0.,1.),5.0);\n}\n\nvec3 computeSpecularTerm(float NdotH,float NdotL,float NdotV,float VdotH,float roughness,vec3 specularColor)\n{\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\nfloat distribution=normalDistributionFunction_TrowbridgeReitzGGX(NdotH,alphaG);\nfloat visibility=smithVisibilityG_TrowbridgeReitzGGX_Walter(NdotL,NdotV,alphaG);\nvisibility/=(4.0*NdotL*NdotV); \nvec3 fresnel=fresnelSchlickGGX(VdotH,specularColor,vec3(1.,1.,1.));\nfloat specTerm=max(0.,visibility*distribution)*NdotL;\nreturn fresnel*specTerm*kPi; \n}\nfloat computeDiffuseTerm(float NdotL,float NdotV,float VdotH,float roughness)\n{\n\n\nfloat diffuseFresnelNV=pow(clamp(1.0-NdotL,0.000001,1.),5.0);\nfloat diffuseFresnelNL=pow(clamp(1.0-NdotV,0.000001,1.),5.0);\nfloat diffuseFresnel90=0.5+2.0*VdotH*VdotH*roughness;\nfloat diffuseFresnelTerm =\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNL) *\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNV);\nreturn diffuseFresnelTerm*NdotL;\n\n\n}\nfloat adjustRoughnessFromLightProperties(float roughness,float lightRadius,float lightDistance)\n{\n\nfloat lightRoughness=lightRadius/lightDistance;\n\nfloat totalRoughness=clamp(lightRoughness+roughness,0.,1.);\nreturn totalRoughness;\n}\nfloat computeDefaultMicroSurface(float microSurface,vec3 reflectivityColor)\n{\nfloat kReflectivityNoAlphaWorkflow_SmoothnessMax=0.95;\nfloat reflectivityLuminance=getLuminance(reflectivityColor);\nfloat reflectivityLuma=sqrt(reflectivityLuminance);\nmicroSurface=reflectivityLuma*kReflectivityNoAlphaWorkflow_SmoothnessMax;\nreturn microSurface;\n}\nvec3 toLinearSpace(vec3 color)\n{\nreturn vec3(pow(color.r,2.2),pow(color.g,2.2),pow(color.b,2.2));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn vec3(pow(color.r,1.0/2.2),pow(color.g,1.0/2.2),pow(color.b,1.0/2.2));\n}\nfloat computeLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\nfloat lightDistanceFalloff=1.0/((lightDistanceSquared+0.0001));\nreturn lightDistanceFalloff;\n#else\nfloat lightFalloff=max(0.,1.0-length(lightOffset)/range);\nreturn lightFalloff;\n#endif\n}\n#ifdef CAMERATONEMAP\nvec3 toneMaps(vec3 color)\n{\ncolor=max(color,0.0);\n\ncolor.rgb=color.rgb*vCameraInfos.x;\nfloat tuning=1.5; \n\n\nvec3 tonemapped=1.0-exp2(-color.rgb*tuning); \ncolor.rgb=mix(color.rgb,tonemapped,1.0);\nreturn color;\n}\n#endif\n#ifdef CAMERACONTRAST\nvec4 contrasts(vec4 color)\n{\ncolor=clamp(color,0.0,1.0);\nvec3 resultHighContrast=color.rgb*color.rgb*(3.0-2.0*color.rgb);\nfloat contrast=vCameraInfos.y;\nif (contrast<1.0)\n{\n\ncolor.rgb=mix(vec3(0.5,0.5,0.5),color.rgb,contrast);\n}\nelse\n{\n\ncolor.rgb=mix(color.rgb,resultHighContrast,contrast-1.0);\n}\nreturn color;\n}\n#endif",pbrLightFunctions:"\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float roughness,float NdotV,float lightRadius,out float NdotL) {\nlightingInfo result;\nvec3 lightDirection;\nfloat attenuation=1.0;\nfloat lightDistance;\n\nif (lightData.w == 0.)\n{\nvec3 lightOffset=lightData.xyz-vPositionW;\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nattenuation=computeLightFalloff(lightOffset,lightDistanceSquared,range);\nlightDistance=sqrt(lightDistanceSquared);\nlightDirection=normalize(lightOffset);\n}\n\nelse\n{\nlightDistance=length(-lightData.xyz);\nlightDirection=normalize(-lightData.xyz);\n}\n\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+lightDirection);\nNdotL=max(0.00000000001,dot(vNormal,lightDirection));\nfloat VdotH=clamp(0.00000000001,1.0,dot(viewDirectionW,H));\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float roughness,float NdotV,float lightRadius,out float NdotL) {\nlightingInfo result;\nvec3 lightOffset=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(lightOffset);\n\nfloat cosAngle=max(0.000000000000001,dot(-lightDirection.xyz,lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\n\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nfloat attenuation=computeLightFalloff(lightOffset,lightDistanceSquared,range);\n\nattenuation*=cosAngle;\n\nfloat lightDistance=sqrt(lightDistanceSquared);\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW-lightDirection.xyz);\nNdotL=max(0.00000000001,dot(vNormal,-lightDirection.xyz));\nfloat VdotH=clamp(dot(viewDirectionW,H),0.00000000001,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float roughness,float NdotV,float lightRadius,out float NdotL) {\nlightingInfo result;\n\n\n\nNdotL=dot(vNormal,lightData.xyz)*0.5+0.5;\nresult.diffuse=mix(groundColor,diffuseColor,NdotL);\n#ifdef SPECULARTERM\n\nvec3 lightVectorW=normalize(lightData.xyz);\nvec3 H=normalize(viewDirectionW+lightVectorW);\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nNdotL=max(0.00000000001,NdotL);\nfloat VdotH=clamp(0.00000000001,1.0,dot(viewDirectionW,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor);\nresult.specular=specTerm;\n#endif\nreturn result;\n}",pbrLightFunctionsCall:"#ifdef LIGHT{X}\n#ifndef SPECULARTERM\nvec3 vLightSpecular{X}=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData{X},vLightDirection{X},vLightDiffuse{X}.rgb,vLightSpecular{X},vLightDiffuse{X}.a,roughness,NdotV,vLightRadiuses[{X}],NdotL);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData{X},vLightDiffuse{X}.rgb,vLightSpecular{X},vLightGround{X},roughness,NdotV,vLightRadiuses[{X}],NdotL);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,vLightData{X},vLightDiffuse{X}.rgb,vLightSpecular{X},vLightDiffuse{X}.a,roughness,NdotV,vLightRadiuses[{X}],NdotL);\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWVSM{X}\nnotShadowLevel=computeShadowWithVSM(vPositionFromLight{X},shadowSampler{X},shadowsInfo{X}.z,shadowsInfo{X}.x);\n#else\n#ifdef SHADOWPCF{X}\n#if defined(POINTLIGHT{X})\nnotShadowLevel=computeShadowWithPCFCube(vLightData{X}.xyz,shadowSampler{X},shadowsInfo{X}.y,shadowsInfo{X}.z,shadowsInfo{X}.x);\n#else\nnotShadowLevel=computeShadowWithPCF(vPositionFromLight{X},shadowSampler{X},shadowsInfo{X}.y,shadowsInfo{X}.z,shadowsInfo{X}.x);\n#endif\n#else\n#if defined(POINTLIGHT{X})\nnotShadowLevel=computeShadowCube(vLightData{X}.xyz,shadowSampler{X},shadowsInfo{X}.x,shadowsInfo{X}.z);\n#else\nnotShadowLevel=computeShadow(vPositionFromLight{X},shadowSampler{X},shadowsInfo{X}.x,shadowsInfo{X}.z);\n#endif\n#endif\n#endif\n#else\nnotShadowLevel=1.;\n#endif\nlightDiffuseContribution+=info.diffuse*notShadowLevel;\n#ifdef OVERLOADEDSHADOWVALUES\nif (NdotL<0.000000000011)\n{\nnotShadowLevel=1.;\n}\nshadowedOnlyLightDiffuseContribution*=notShadowLevel;\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution+=info.specular*notShadowLevel;\n#endif\n#endif",pbrShadowFunctions:"\n#ifdef SHADOWS\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#if defined(POINTLIGHT0) || defined(POINTLIGHT1) || defined(POINTLIGHT2) || defined(POINTLIGHT3)\nuniform vec2 depthValues;\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float bias)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y =-directionToLight.y;\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight))+bias;\nif (depth>shadow)\n{\n#ifdef OVERLOADEDSHADOWVALUES\nreturn mix(1.0,darkness,vOverloadedShadowIntensity.x);\n#else\nreturn darkness;\n#endif\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float bias,float darkness)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth-depthValues.x)/(depthValues.y-depthValues.x);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\nfloat biasedDepth=depth-bias;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<biasedDepth) visibility-=0.25;\n#ifdef OVERLOADEDSHADOWVALUES\nreturn min(1.0,mix(1.0,visibility+darkness,vOverloadedShadowIntensity.x));\n#else\nreturn min(1.0,visibility+darkness);\n#endif\n}\n#endif\n#if defined(SPOTLIGHT0) || defined(SPOTLIGHT1) || defined(SPOTLIGHT2) || defined(SPOTLIGHT3) || defined(DIRLIGHT0) || defined(DIRLIGHT1) || defined(DIRLIGHT2) || defined(DIRLIGHT3)\nfloat computeShadow(vec4 vPositionFromLight,sampler2D shadowSampler,float darkness,float bias)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadow=unpack(texture2D(shadowSampler,uv))+bias;\nif (depth.z>shadow)\n{\n#ifdef OVERLOADEDSHADOWVALUES\nreturn mix(1.0,darkness,vOverloadedShadowIntensity.x);\n#else\nreturn darkness;\n#endif\n}\nreturn 1.;\n}\nfloat computeShadowWithPCF(vec4 vPositionFromLight,sampler2D shadowSampler,float mapSize,float bias,float darkness)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\nfloat biasedDepth=depth.z-bias;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[1]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[2]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[3]*mapSize))<biasedDepth) visibility-=0.25;\n#ifdef OVERLOADEDSHADOWVALUES\nreturn min(1.0,mix(1.0,visibility+darkness,vOverloadedShadowIntensity.x));\n#else\nreturn min(1.0,visibility+darkness);\n#endif\n}\n\nfloat unpackHalf(vec2 color)\n{\nreturn color.x+(color.y/255.0);\n}\nfloat linstep(float low,float high,float v) {\nreturn clamp((v-low)/(high-low),0.0,1.0);\n}\nfloat ChebychevInequality(vec2 moments,float compare,float bias)\n{\nfloat p=smoothstep(compare-bias,compare,moments.x);\nfloat variance=max(moments.y-moments.x*moments.x,0.02);\nfloat d=compare-moments.x;\nfloat p_max=linstep(0.2,1.0,variance/(variance+d*d));\nreturn clamp(max(p,p_max),0.0,1.0);\n}\nfloat computeShadowWithVSM(vec4 vPositionFromLight,sampler2D shadowSampler,float bias,float darkness)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0 || depth.z>=1.0)\n{\nreturn 1.0;\n}\nvec4 texel=texture2D(shadowSampler,uv);\nvec2 moments=vec2(unpackHalf(texel.xy),unpackHalf(texel.zw));\n#ifdef OVERLOADEDSHADOWVALUES\nreturn min(1.0,mix(1.0,1.0-ChebychevInequality(moments,depth.z,bias)+darkness,vOverloadedShadowIntensity.x));\n#else\nreturn min(1.0,1.0-ChebychevInequality(moments,depth.z,bias)+darkness);\n#endif\n}\n#endif\n#endif",pointCloudVertex:"#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif",pointCloudVertexDeclaration:"#ifdef POINTSIZE\nuniform float pointSize;\n#endif",reflectionFunction:"vec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)\n{\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvec3 direction=normalize(vDirectionW);\nfloat t=clamp(direction.y*-0.5+0.5,0.,1.0);\nfloat s=atan(direction.z,direction.x)*RECIPROCAL_PI2+0.5;\nreturn vec3(s,t,0);\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR\nvec3 cameraToVertex=normalize(worldPos.xyz-vEyePosition);\nvec3 r=reflect(cameraToVertex,worldNormal);\nfloat t=clamp(r.y*-0.5+0.5,0.,1.0);\nfloat s=atan(r.z,r.x)*RECIPROCAL_PI2+0.5;\nreturn vec3(s,t,0);\n#endif\n#ifdef REFLECTIONMAP_SPHERICAL\nvec3 viewDir=normalize(vec3(view*worldPos));\nvec3 viewNormal=normalize(vec3(view*vec4(worldNormal,0.0)));\nvec3 r=reflect(viewDir,viewNormal);\nr.z=r.z-1.0;\nfloat m=2.0*length(r);\nreturn vec3(r.x/m+0.5,1.0-r.y/m-0.5,0);\n#endif\n#ifdef REFLECTIONMAP_PLANAR\nvec3 viewDir=worldPos.xyz-vEyePosition;\nvec3 coords=normalize(reflect(viewDir,worldNormal));\nreturn vec3(reflectionMatrix*vec4(coords,1));\n#endif\n#ifdef REFLECTIONMAP_CUBIC\nvec3 viewDir=worldPos.xyz-vEyePosition;\nvec3 coords=reflect(viewDir,worldNormal);\n#ifdef INVERTCUBICMAP\ncoords.y=1.0-coords.y;\n#endif\nreturn vec3(reflectionMatrix*vec4(coords,0));\n#endif\n#ifdef REFLECTIONMAP_PROJECTION\nreturn vec3(reflectionMatrix*(view*worldPos));\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nreturn vPositionUVW;\n#endif\n#ifdef REFLECTIONMAP_EXPLICIT\nreturn vec3(0,0,0);\n#endif\n}",shadowsFragmentFunctions:"#ifdef SHADOWS\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#if defined(POINTLIGHT0) || defined(POINTLIGHT1) || defined(POINTLIGHT2) || defined(POINTLIGHT3)\nuniform vec2 depthValues;\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float bias)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth-depthValues.x)/(depthValues.y-depthValues.x);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight))+bias;\nif (depth>shadow)\n{\nreturn darkness;\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float bias,float darkness)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth-depthValues.x)/(depthValues.y-depthValues.x);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\nfloat biasedDepth=depth-bias;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<biasedDepth) visibility-=0.25;\nreturn min(1.0,visibility+darkness);\n}\n#endif\n#if defined(SPOTLIGHT0) || defined(SPOTLIGHT1) || defined(SPOTLIGHT2) || defined(SPOTLIGHT3) || defined(DIRLIGHT0) || defined(DIRLIGHT1) || defined(DIRLIGHT2) || defined(DIRLIGHT3)\nfloat computeShadow(vec4 vPositionFromLight,sampler2D shadowSampler,float darkness,float bias)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadow=unpack(texture2D(shadowSampler,uv))+bias;\nif (depth.z>shadow)\n{\nreturn darkness;\n}\nreturn 1.;\n}\nfloat computeShadowWithPCF(vec4 vPositionFromLight,sampler2D shadowSampler,float mapSize,float bias,float darkness)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\nfloat biasedDepth=depth.z-bias;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[1]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[2]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[3]*mapSize))<biasedDepth) visibility-=0.25;\nreturn min(1.0,visibility+darkness);\n}\n\nfloat unpackHalf(vec2 color)\n{\nreturn color.x+(color.y/255.0);\n}\nfloat linstep(float low,float high,float v) {\nreturn clamp((v-low)/(high-low),0.0,1.0);\n}\nfloat ChebychevInequality(vec2 moments,float compare,float bias)\n{\nfloat p=smoothstep(compare-bias,compare,moments.x);\nfloat variance=max(moments.y-moments.x*moments.x,0.02);\nfloat d=compare-moments.x;\nfloat p_max=linstep(0.2,1.0,variance/(variance+d*d));\nreturn clamp(max(p,p_max),0.0,1.0);\n}\nfloat computeShadowWithVSM(vec4 vPositionFromLight,sampler2D shadowSampler,float bias,float darkness)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0 || depth.z>=1.0)\n{\nreturn 1.0;\n}\nvec4 texel=texture2D(shadowSampler,uv);\nvec2 moments=vec2(unpackHalf(texel.xy),unpackHalf(texel.zw));\nreturn min(1.0,1.0-ChebychevInequality(moments,depth.z,bias)+darkness);\n}\n#endif\n#endif",
  33. shadowsVertex:"#ifdef SHADOWS\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\nvPositionFromLight0=lightMatrix0*worldPos;\n#endif\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\nvPositionFromLight1=lightMatrix1*worldPos;\n#endif\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\nvPositionFromLight2=lightMatrix2*worldPos;\n#endif\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\nvPositionFromLight3=lightMatrix3*worldPos;\n#endif\n#endif",shadowsVertexDeclaration:"#ifdef SHADOWS\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\nuniform mat4 lightMatrix0;\nvarying vec4 vPositionFromLight0;\n#endif\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\nuniform mat4 lightMatrix1;\nvarying vec4 vPositionFromLight1;\n#endif\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\nuniform mat4 lightMatrix2;\nvarying vec4 vPositionFromLight2;\n#endif\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\nuniform mat4 lightMatrix3;\nvarying vec4 vPositionFromLight3;\n#endif\n#endif"},BABYLON.CollisionWorker='var BABYLON;!function(t){var e=function(t,e,o,i){return t.x>o.x+i?!1:o.x-i>e.x?!1:t.y>o.y+i?!1:o.y-i>e.y?!1:t.z>o.z+i?!1:!(o.z-i>e.z)},o=function(t,e,o,i){var s=e*e-4*t*o,r={root:0,found:!1};if(0>s)return r;var n=Math.sqrt(s),c=(-e-n)/(2*t),h=(-e+n)/(2*t);if(c>h){var a=h;h=c,c=a}return c>0&&i>c?(r.root=c,r.found=!0,r):h>0&&i>h?(r.root=h,r.found=!0,r):r},i=function(){function i(){this.radius=new t.Vector3(1,1,1),this.retry=0,this.basePointWorld=t.Vector3.Zero(),this.velocityWorld=t.Vector3.Zero(),this.normalizedVelocity=t.Vector3.Zero(),this._collisionPoint=t.Vector3.Zero(),this._planeIntersectionPoint=t.Vector3.Zero(),this._tempVector=t.Vector3.Zero(),this._tempVector2=t.Vector3.Zero(),this._tempVector3=t.Vector3.Zero(),this._tempVector4=t.Vector3.Zero(),this._edge=t.Vector3.Zero(),this._baseToVertex=t.Vector3.Zero(),this._destinationPoint=t.Vector3.Zero(),this._slidePlaneNormal=t.Vector3.Zero(),this._displacementVector=t.Vector3.Zero()}return i.prototype._initialize=function(e,o,i){this.velocity=o,t.Vector3.NormalizeToRef(o,this.normalizedVelocity),this.basePoint=e,e.multiplyToRef(this.radius,this.basePointWorld),o.multiplyToRef(this.radius,this.velocityWorld),this.velocityWorldLength=this.velocityWorld.length(),this.epsilon=i,this.collisionFound=!1},i.prototype._checkPointInTriangle=function(e,o,i,s,r){o.subtractToRef(e,this._tempVector),i.subtractToRef(e,this._tempVector2),t.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var n=t.Vector3.Dot(this._tempVector4,r);return 0>n?!1:(s.subtractToRef(e,this._tempVector3),t.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),n=t.Vector3.Dot(this._tempVector4,r),0>n?!1:(t.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),n=t.Vector3.Dot(this._tempVector4,r),n>=0))},i.prototype._canDoCollision=function(o,i,s,r){var n=t.Vector3.Distance(this.basePointWorld,o),c=Math.max(this.radius.x,this.radius.y,this.radius.z);return n>this.velocityWorldLength+c+i?!1:!!e(s,r,this.basePointWorld,this.velocityWorldLength+c)},i.prototype._testTriangle=function(e,i,s,r,n,c){var h,a=!1;i||(i=[]),i[e]||(i[e]=new t.Plane(0,0,0,0),i[e].copyFromPoints(s,r,n));var l=i[e];if(c||l.isFrontFacingTo(this.normalizedVelocity,0)){var _=l.signedDistanceTo(this.basePoint),d=t.Vector3.Dot(l.normal,this.velocity);if(0==d){if(Math.abs(_)>=1)return;a=!0,h=0}else{h=(-1-_)/d;var V=(1-_)/d;if(h>V){var u=V;V=h,h=u}if(h>1||0>V)return;0>h&&(h=0),h>1&&(h=1)}this._collisionPoint.copyFromFloats(0,0,0);var P=!1,p=1;if(a||(this.basePoint.subtractToRef(l.normal,this._planeIntersectionPoint),this.velocity.scaleToRef(h,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,s,r,n,l.normal)&&(P=!0,p=h,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!P){var m=this.velocity.lengthSquared(),f=m;this.basePoint.subtractToRef(s,this._tempVector);var T=2*t.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,y=o(f,T,b,p);y.found&&(p=y.root,P=!0,this._collisionPoint.copyFrom(s)),this.basePoint.subtractToRef(r,this._tempVector),T=2*t.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,y=o(f,T,b,p),y.found&&(p=y.root,P=!0,this._collisionPoint.copyFrom(r)),this.basePoint.subtractToRef(n,this._tempVector),T=2*t.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,y=o(f,T,b,p),y.found&&(p=y.root,P=!0,this._collisionPoint.copyFrom(n)),r.subtractToRef(s,this._edge),s.subtractToRef(this.basePoint,this._baseToVertex);var g=this._edge.lengthSquared(),v=t.Vector3.Dot(this._edge,this.velocity),R=t.Vector3.Dot(this._edge,this._baseToVertex);if(f=g*-m+v*v,T=g*(2*t.Vector3.Dot(this.velocity,this._baseToVertex))-2*v*R,b=g*(1-this._baseToVertex.lengthSquared())+R*R,y=o(f,T,b,p),y.found){var D=(v*y.root-R)/g;D>=0&&1>=D&&(p=y.root,P=!0,this._edge.scaleInPlace(D),s.addToRef(this._edge,this._collisionPoint))}n.subtractToRef(r,this._edge),r.subtractToRef(this.basePoint,this._baseToVertex),g=this._edge.lengthSquared(),v=t.Vector3.Dot(this._edge,this.velocity),R=t.Vector3.Dot(this._edge,this._baseToVertex),f=g*-m+v*v,T=g*(2*t.Vector3.Dot(this.velocity,this._baseToVertex))-2*v*R,b=g*(1-this._baseToVertex.lengthSquared())+R*R,y=o(f,T,b,p),y.found&&(D=(v*y.root-R)/g,D>=0&&1>=D&&(p=y.root,P=!0,this._edge.scaleInPlace(D),r.addToRef(this._edge,this._collisionPoint))),s.subtractToRef(n,this._edge),n.subtractToRef(this.basePoint,this._baseToVertex),g=this._edge.lengthSquared(),v=t.Vector3.Dot(this._edge,this.velocity),R=t.Vector3.Dot(this._edge,this._baseToVertex),f=g*-m+v*v,T=g*(2*t.Vector3.Dot(this.velocity,this._baseToVertex))-2*v*R,b=g*(1-this._baseToVertex.lengthSquared())+R*R,y=o(f,T,b,p),y.found&&(D=(v*y.root-R)/g,D>=0&&1>=D&&(p=y.root,P=!0,this._edge.scaleInPlace(D),n.addToRef(this._edge,this._collisionPoint)))}if(P){var x=p*this.velocity.length();(!this.collisionFound||x<this.nearestDistance)&&(this.intersectionPoint?this.intersectionPoint.copyFrom(this._collisionPoint):this.intersectionPoint=this._collisionPoint.clone(),this.nearestDistance=x,this.collisionFound=!0)}}},i.prototype._collide=function(t,e,o,i,s,r,n){for(var c=i;s>c;c+=3){var h=e[o[c]-r],a=e[o[c+1]-r],l=e[o[c+2]-r];this._testTriangle(c,t,l,a,h,n)}},i.prototype._getResponse=function(e,o){e.addToRef(o,this._destinationPoint),o.scaleInPlace(this.nearestDistance/o.length()),this.basePoint.addToRef(o,e),e.subtractToRef(this.intersectionPoint,this._slidePlaneNormal),this._slidePlaneNormal.normalize(),this._slidePlaneNormal.scaleToRef(this.epsilon,this._displacementVector),e.addInPlace(this._displacementVector),this.intersectionPoint.addInPlace(this._displacementVector),this._slidePlaneNormal.scaleInPlace(t.Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint,this._slidePlaneNormal,this._destinationPoint)),this._destinationPoint.subtractInPlace(this._slidePlaneNormal),this._destinationPoint.subtractToRef(this.intersectionPoint,o)},i}();t.Collider=i}(BABYLON||(BABYLON={}));var BABYLON;!function(o){o.WorkerIncluded=!0;var e=function(){function o(){this._meshes={},this._geometries={}}return o.prototype.getMeshes=function(){return this._meshes},o.prototype.getGeometries=function(){return this._geometries},o.prototype.getMesh=function(o){return this._meshes[o]},o.prototype.addMesh=function(o){this._meshes[o.uniqueId]=o},o.prototype.removeMesh=function(o){delete this._meshes[o]},o.prototype.getGeometry=function(o){return this._geometries[o]},o.prototype.addGeometry=function(o){this._geometries[o.id]=o},o.prototype.removeGeometry=function(o){delete this._geometries[o]},o}();o.CollisionCache=e;var i=function(){function e(e,i,r){this.collider=e,this._collisionCache=i,this.finalPosition=r,this.collisionsScalingMatrix=o.Matrix.Zero(),this.collisionTranformationMatrix=o.Matrix.Zero()}return e.prototype.collideWithWorld=function(o,e,i,r){var t=.01;if(this.collider.retry>=i)return void this.finalPosition.copyFrom(o);this.collider._initialize(o,e,t);for(var s,l=this._collisionCache.getMeshes(),n=Object.keys(l),a=n.length,c=0;a>c;++c)if(s=n[c],parseInt(s)!=r){var d=l[s];d.checkCollisions&&this.checkCollision(d)}return this.collider.collisionFound?(0===e.x&&0===e.y&&0===e.z||this.collider._getResponse(o,e),e.length()<=t?void this.finalPosition.copyFrom(o):(this.collider.retry++,void this.collideWithWorld(o,e,i,r))):void o.addToRef(e,this.finalPosition)},e.prototype.checkCollision=function(e){if(this.collider._canDoCollision(o.Vector3.FromArray(e.sphereCenter),e.sphereRadius,o.Vector3.FromArray(e.boxMinimum),o.Vector3.FromArray(e.boxMaximum))){o.Matrix.ScalingToRef(1/this.collider.radius.x,1/this.collider.radius.y,1/this.collider.radius.z,this.collisionsScalingMatrix);var i=o.Matrix.FromArray(e.worldMatrixFromCache);i.multiplyToRef(this.collisionsScalingMatrix,this.collisionTranformationMatrix),this.processCollisionsForSubMeshes(this.collisionTranformationMatrix,e)}},e.prototype.processCollisionsForSubMeshes=function(o,e){var i=e.subMeshes,r=i.length;if(!e.geometryId)return void console.log("no mesh geometry id");var t=this._collisionCache.getGeometry(e.geometryId);if(!t)return void console.log("couldn\'t find geometry",e.geometryId);for(var s=0;r>s;s++){var l=i[s];r>1&&!this.checkSubmeshCollision(l)||(this.collideForSubMesh(l,o,t),this.collider.collisionFound&&(this.collider.collidedMesh=e.uniqueId))}},e.prototype.collideForSubMesh=function(e,i,r){if(!r.positionsArray){r.positionsArray=[];for(var t=0,s=r.positions.length;s>t;t+=3){var l=o.Vector3.FromArray([r.positions[t],r.positions[t+1],r.positions[t+2]]);r.positionsArray.push(l)}}if(!e._lastColliderWorldVertices||!e._lastColliderTransformMatrix.equals(i)){e._lastColliderTransformMatrix=i.clone(),e._lastColliderWorldVertices=[],e._trianglePlanes=[];for(var n=e.verticesStart,a=e.verticesStart+e.verticesCount,t=n;a>t;t++)e._lastColliderWorldVertices.push(o.Vector3.TransformCoordinates(r.positionsArray[t],i))}this.collider._collide(e._trianglePlanes,e._lastColliderWorldVertices,r.indices,e.indexStart,e.indexStart+e.indexCount,e.verticesStart,e.hasMaterial)},e.prototype.checkSubmeshCollision=function(e){return this.collider._canDoCollision(o.Vector3.FromArray(e.sphereCenter),e.sphereRadius,o.Vector3.FromArray(e.boxMinimum),o.Vector3.FromArray(e.boxMaximum))},e}();o.CollideWorker=i;var r=function(){function r(){}return r.prototype.onInit=function(i){this._collisionCache=new e;var r={error:o.WorkerReplyType.SUCCESS,taskType:o.WorkerTaskType.INIT};postMessage(r,void 0)},r.prototype.onUpdate=function(e){var i=this,r={error:o.WorkerReplyType.SUCCESS,taskType:o.WorkerTaskType.UPDATE};try{for(var t in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(t)&&this._collisionCache.addGeometry(e.updatedGeometries[t]);for(var s in e.updatedMeshes)e.updatedMeshes.hasOwnProperty(s)&&this._collisionCache.addMesh(e.updatedMeshes[s]);e.removedGeometries.forEach(function(o){i._collisionCache.removeGeometry(o)}),e.removedMeshes.forEach(function(o){i._collisionCache.removeMesh(o)})}catch(l){r.error=o.WorkerReplyType.UNKNOWN_ERROR}postMessage(r,void 0)},r.prototype.onCollision=function(e){var r=o.Vector3.Zero(),t=new o.Collider;t.radius=o.Vector3.FromArray(e.collider.radius);var s=new i(t,this._collisionCache,r);s.collideWithWorld(o.Vector3.FromArray(e.collider.position),o.Vector3.FromArray(e.collider.velocity),e.maximumRetry,e.excludedMeshUniqueId);var l={collidedMeshUniqueId:t.collidedMesh,collisionId:e.collisionId,newPosition:r.asArray()},n={error:o.WorkerReplyType.SUCCESS,taskType:o.WorkerTaskType.COLLIDE,payload:l};postMessage(n,void 0)},r}();o.CollisionDetectorTransferable=r;try{if(self&&self instanceof WorkerGlobalScope){window={},o.Collider||(importScripts("./babylon.collisionCoordinator.js"),importScripts("./babylon.collider.js"),importScripts("../Math/babylon.math.js"));var t=new r,s=function(e){var i=e.data;switch(i.taskType){case o.WorkerTaskType.INIT:t.onInit(i.payload);break;case o.WorkerTaskType.COLLIDE:t.onCollision(i.payload);break;case o.WorkerTaskType.UPDATE:t.onUpdate(i.payload)}};self.onmessage=s}}catch(l){console.log("single worker init")}}(BABYLON||(BABYLON={}));var BABYLON;!function(e){e.CollisionWorker="",function(e){e[e.INIT=0]="INIT",e[e.UPDATE=1]="UPDATE",e[e.COLLIDE=2]="COLLIDE"}(e.WorkerTaskType||(e.WorkerTaskType={}));var o=e.WorkerTaskType;!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.UNKNOWN_ERROR=1]="UNKNOWN_ERROR"}(e.WorkerReplyType||(e.WorkerReplyType={}));var i=e.WorkerReplyType,t=function(){function t(){var r=this;this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this.onMeshUpdated=function(e){r._addUpdateMeshesList[e.uniqueId]=t.SerializeMesh(e)},this.onGeometryUpdated=function(e){r._addUpdateGeometriesList[e.id]=t.SerializeGeometry(e)},this._afterRender=function(){if(r._init&&!(0==r._toRemoveGeometryArray.length&&0==r._toRemoveMeshesArray.length&&0==Object.keys(r._addUpdateGeometriesList).length&&0==Object.keys(r._addUpdateMeshesList).length||r._runningUpdated>4)){++r._runningUpdated;var e={updatedMeshes:r._addUpdateMeshesList,updatedGeometries:r._addUpdateGeometriesList,removedGeometries:r._toRemoveGeometryArray,removedMeshes:r._toRemoveMeshesArray},i={payload:e,taskType:o.UPDATE},t=[];for(var s in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(s)&&(t.push(i.payload.updatedGeometries[s].indices.buffer),t.push(i.payload.updatedGeometries[s].normals.buffer),t.push(i.payload.updatedGeometries[s].positions.buffer));r._worker.postMessage(i,t),r._addUpdateMeshesList={},r._addUpdateGeometriesList={},r._toRemoveGeometryArray=[],r._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(t){var s=t.data;if(s.error!=i.SUCCESS)return void e.Tools.Warn("error returned from worker!");switch(s.taskType){case o.INIT:r._init=!0,r._scene.meshes.forEach(function(e){r.onMeshAdded(e)}),r._scene.getGeometries().forEach(function(e){r.onGeometryAdded(e)});break;case o.UPDATE:r._runningUpdated--;break;case o.COLLIDE:r._runningCollisionTask=!1;var n=s.payload;if(!r._collisionsCallbackArray[n.collisionId])return;r._collisionsCallbackArray[n.collisionId](n.collisionId,e.Vector3.FromArray(n.newPosition),r._scene.getMeshByUniqueID(n.collidedMeshUniqueId)),r._collisionsCallbackArray[n.collisionId]=void 0}},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,this._runningCollisionTask=!1,this._addUpdateMeshesList={},this._addUpdateGeometriesList={},this._toRemoveGeometryArray=[],this._toRemoveMeshesArray=[]}return t.prototype.getNewPosition=function(e,i,t,r,s,n,a){if(this._init&&!this._collisionsCallbackArray[a]&&!this._collisionsCallbackArray[a+1e5]){e.divideToRef(t.radius,this._scaledPosition),i.divideToRef(t.radius,this._scaledVelocity),this._collisionsCallbackArray[a]=n;var d={collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:t.radius.asArray()},collisionId:a,excludedMeshUniqueId:s?s.uniqueId:null,maximumRetry:r},l={payload:d,taskType:o.COLLIDE};this._worker.postMessage(l)}},t.prototype.init=function(i){this._scene=i,this._scene.registerAfterRender(this._afterRender);var t=e.WorkerIncluded?e.Engine.CodeRepository+"Collisions/babylon.collisionWorker.js":URL.createObjectURL(new Blob([e.CollisionWorker],{type:"application/javascript"}));this._worker=new Worker(t),this._worker.onmessage=this._onMessageFromWorker;var r={payload:{},taskType:o.INIT};this._worker.postMessage(r)},t.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},t.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},t.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},t.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},t.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},t.SerializeMesh=function(o){var i=[];o.subMeshes&&(i=o.subMeshes.map(function(e,o){return{position:o,verticesStart:e.verticesStart,verticesCount:e.verticesCount,indexStart:e.indexStart,indexCount:e.indexCount,hasMaterial:!!e.getMaterial(),sphereCenter:e.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:e.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:e.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:e.getBoundingInfo().boundingBox.maximumWorld.asArray()}}));var t=null;return o instanceof e.Mesh?t=o.geometry?o.geometry.id:null:o instanceof e.InstancedMesh&&(t=o.sourceMesh&&o.sourceMesh.geometry?o.sourceMesh.geometry.id:null),{uniqueId:o.uniqueId,id:o.id,name:o.name,geometryId:t,sphereCenter:o.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:o.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:o.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:o.getBoundingInfo().boundingBox.maximumWorld.asArray(),worldMatrixFromCache:o.worldMatrixFromCache.asArray(),subMeshes:i,checkCollisions:o.checkCollisions}},t.SerializeGeometry=function(o){return{id:o.id,positions:new Float32Array(o.getVerticesData(e.VertexBuffer.PositionKind)||[]),normals:new Float32Array(o.getVerticesData(e.VertexBuffer.NormalKind)||[]),indices:new Int32Array(o.getIndices()||[])}},t}();e.CollisionCoordinatorWorker=t;var r=function(){function o(){this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this._finalPosition=e.Vector3.Zero()}return o.prototype.getNewPosition=function(e,o,i,t,r,s,n){e.divideToRef(i.radius,this._scaledPosition),o.divideToRef(i.radius,this._scaledVelocity),i.collidedMesh=null,i.retry=0,i.initialVelocity=this._scaledVelocity,i.initialPosition=this._scaledPosition,this._collideWithWorld(this._scaledPosition,this._scaledVelocity,i,t,this._finalPosition,r),this._finalPosition.multiplyInPlace(i.radius),s(n,this._finalPosition,i.collidedMesh)},o.prototype.init=function(e){this._scene=e},o.prototype.destroy=function(){},o.prototype.onMeshAdded=function(e){},o.prototype.onMeshUpdated=function(e){},o.prototype.onMeshRemoved=function(e){},o.prototype.onGeometryAdded=function(e){},o.prototype.onGeometryUpdated=function(e){},o.prototype.onGeometryDeleted=function(e){},o.prototype._collideWithWorld=function(o,i,t,r,s,n){void 0===n&&(n=null);var a=10*e.Engine.CollisionsEpsilon;if(t.retry>=r)return void s.copyFrom(o);t._initialize(o,i,a);for(var d=0;d<this._scene.meshes.length;d++){var l=this._scene.meshes[d];l.isEnabled()&&l.checkCollisions&&l.subMeshes&&l!==n&&l._checkCollision(t)}return t.collisionFound?(0===i.x&&0===i.y&&0===i.z||t._getResponse(o,i),i.length()<=a?void s.copyFrom(o):(t.retry++,void this._collideWithWorld(o,i,t,r,s,n))):void o.addToRef(i,s)},o}();e.CollisionCoordinatorLegacy=r}(BABYLON||(BABYLON={}));var BABYLON;!function(t){t.ToGammaSpace=1/2.2,t.ToLinearSpace=2.2,t.Epsilon=.001;var i=function(){function t(){}return t.WithinEpsilon=function(t,i,n){void 0===n&&(n=1.401298e-45);var r=t-i;return r>=-n&&n>=r},t.ToHex=function(t){var i=t.toString(16);return 15>=t?("0"+i).toUpperCase():i.toUpperCase()},t.Sign=function(t){return t=+t,0===t||isNaN(t)?t:t>0?1:-1},t.Clamp=function(t,i,n){return void 0===i&&(i=0),void 0===n&&(n=1),Math.min(n,Math.max(i,t))},t}();t.MathTools=i;var n=function(){function n(t,i,n){void 0===t&&(t=0),void 0===i&&(i=0),void 0===n&&(n=0),this.r=t,this.g=i,this.b=n}return n.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+"}"},n.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.r,t[i+1]=this.g,t[i+2]=this.b,this},n.prototype.toColor4=function(t){return void 0===t&&(t=1),new r(this.r,this.g,this.b,t)},n.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},n.prototype.toLuminance=function(){return.3*this.r+.59*this.g+.11*this.b},n.prototype.multiply=function(t){return new n(this.r*t.r,this.g*t.g,this.b*t.b)},n.prototype.multiplyToRef=function(t,i){return i.r=this.r*t.r,i.g=this.g*t.g,i.b=this.b*t.b,this},n.prototype.equals=function(t){return t&&this.r===t.r&&this.g===t.g&&this.b===t.b},n.prototype.equalsFloats=function(t,i,n){return this.r===t&&this.g===i&&this.b===n},n.prototype.scale=function(t){return new n(this.r*t,this.g*t,this.b*t)},n.prototype.scaleToRef=function(t,i){return i.r=this.r*t,i.g=this.g*t,i.b=this.b*t,this},n.prototype.add=function(t){return new n(this.r+t.r,this.g+t.g,this.b+t.b)},n.prototype.addToRef=function(t,i){return i.r=this.r+t.r,i.g=this.g+t.g,i.b=this.b+t.b,this},n.prototype.subtract=function(t){return new n(this.r-t.r,this.g-t.g,this.b-t.b)},n.prototype.subtractToRef=function(t,i){return i.r=this.r-t.r,i.g=this.g-t.g,i.b=this.b-t.b,this},n.prototype.clone=function(){return new n(this.r,this.g,this.b)},n.prototype.copyFrom=function(t){return this.r=t.r,this.g=t.g,this.b=t.b,this},n.prototype.copyFromFloats=function(t,i,n){return this.r=t,this.g=i,this.b=n,this},n.prototype.toHexString=function(){var t=255*this.r|0,n=255*this.g|0,r=255*this.b|0;return"#"+i.ToHex(t)+i.ToHex(n)+i.ToHex(r)},n.prototype.toLinearSpace=function(){var t=new n;return this.toLinearSpaceToRef(t),t},n.prototype.toLinearSpaceToRef=function(i){return i.r=Math.pow(this.r,t.ToLinearSpace),i.g=Math.pow(this.g,t.ToLinearSpace),i.b=Math.pow(this.b,t.ToLinearSpace),this},n.prototype.toGammaSpace=function(){var t=new n;return this.toGammaSpaceToRef(t),t},n.prototype.toGammaSpaceToRef=function(i){return i.r=Math.pow(this.r,t.ToGammaSpace),i.g=Math.pow(this.g,t.ToGammaSpace),i.b=Math.pow(this.b,t.ToGammaSpace),this},n.FromHexString=function(t){if("#"!==t.substring(0,1)||7!==t.length)return new n(0,0,0);var i=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),o=parseInt(t.substring(5,7),16);return n.FromInts(i,r,o)},n.FromArray=function(t,i){return void 0===i&&(i=0),new n(t[i],t[i+1],t[i+2])},n.FromInts=function(t,i,r){return new n(t/255,i/255,r/255)},n.Lerp=function(t,i,r){var o=t.r+(i.r-t.r)*r,s=t.g+(i.g-t.g)*r,e=t.b+(i.b-t.b)*r;return new n(o,s,e)},n.Red=function(){return new n(1,0,0)},n.Green=function(){return new n(0,1,0)},n.Blue=function(){return new n(0,0,1)},n.Black=function(){return new n(0,0,0)},n.White=function(){return new n(1,1,1)},n.Purple=function(){return new n(.5,0,.5)},n.Magenta=function(){return new n(1,0,1)},n.Yellow=function(){return new n(1,1,0)},n.Gray=function(){return new n(.5,.5,.5)},n}();t.Color3=n;var r=function(){function t(t,i,n,r){this.r=t,this.g=i,this.b=n,this.a=r}return t.prototype.addInPlace=function(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this.a+=t.a,this},t.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},t.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.r,t[i+1]=this.g,t[i+2]=this.b,t[i+3]=this.a,this},t.prototype.add=function(i){return new t(this.r+i.r,this.g+i.g,this.b+i.b,this.a+i.a)},t.prototype.subtract=function(i){return new t(this.r-i.r,this.g-i.g,this.b-i.b,this.a-i.a)},t.prototype.subtractToRef=function(t,i){return i.r=this.r-t.r,i.g=this.g-t.g,i.b=this.b-t.b,i.a=this.a-t.a,this},t.prototype.scale=function(i){return new t(this.r*i,this.g*i,this.b*i,this.a*i)},t.prototype.scaleToRef=function(t,i){return i.r=this.r*t,i.g=this.g*t,i.b=this.b*t,i.a=this.a*t,this},t.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+" A:"+this.a+"}"},t.prototype.clone=function(){return new t(this.r,this.g,this.b,this.a)},t.prototype.copyFrom=function(t){return this.r=t.r,this.g=t.g,this.b=t.b,this.a=t.a,this},t.prototype.toHexString=function(){var t=255*this.r|0,n=255*this.g|0,r=255*this.b|0,o=255*this.a|0;return"#"+i.ToHex(t)+i.ToHex(n)+i.ToHex(r)+i.ToHex(o)},t.FromHexString=function(i){if("#"!==i.substring(0,1)||9!==i.length)return new t(0,0,0,0);var n=parseInt(i.substring(1,3),16),r=parseInt(i.substring(3,5),16),o=parseInt(i.substring(5,7),16),s=parseInt(i.substring(7,9),16);return t.FromInts(n,r,o,s)},t.Lerp=function(i,n,r){var o=new t(0,0,0,0);return t.LerpToRef(i,n,r,o),o},t.LerpToRef=function(t,i,n,r){r.r=t.r+(i.r-t.r)*n,r.g=t.g+(i.g-t.g)*n,r.b=t.b+(i.b-t.b)*n,r.a=t.a+(i.a-t.a)*n},t.FromArray=function(i,n){return void 0===n&&(n=0),new t(i[n],i[n+1],i[n+2],i[n+3])},t.FromInts=function(i,n,r,o){return new t(i/255,n/255,r/255,o/255)},t.CheckColors4=function(t,i){if(t.length===3*i){for(var n=[],r=0;r<t.length;r+=3){var o=r/3*4;n[o]=t[r],n[o+1]=t[r+1],n[o+2]=t[r+2],n[o+3]=1}return n}return t},t}();t.Color4=r;var o=function(){function n(t,i){this.x=t,this.y=i}return n.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}"},n.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.x,t[i+1]=this.y,this},n.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},n.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this},n.prototype.copyFromFloats=function(t,i){return this.x=t,this.y=i,this},n.prototype.add=function(t){return new n(this.x+t.x,this.y+t.y)},n.prototype.addVector3=function(t){return new n(this.x+t.x,this.y+t.y)},n.prototype.subtract=function(t){return new n(this.x-t.x,this.y-t.y)},n.prototype.subtractInPlace=function(t){return this.x-=t.x,this.y-=t.y,this},n.prototype.multiplyInPlace=function(t){return this.x*=t.x,this.y*=t.y,this},n.prototype.multiply=function(t){return new n(this.x*t.x,this.y*t.y)},n.prototype.multiplyToRef=function(t,i){return i.x=this.x*t.x,i.y=this.y*t.y,this},n.prototype.multiplyByFloats=function(t,i){return new n(this.x*t,this.y*i)},n.prototype.divide=function(t){return new n(this.x/t.x,this.y/t.y)},n.prototype.divideToRef=function(t,i){return i.x=this.x/t.x,i.y=this.y/t.y,this},n.prototype.negate=function(){return new n(-this.x,-this.y)},n.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this},n.prototype.scale=function(t){return new n(this.x*t,this.y*t)},n.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y},n.prototype.equalsWithEpsilon=function(n,r){return void 0===r&&(r=t.Epsilon),n&&i.WithinEpsilon(this.x,n.x,r)&&i.WithinEpsilon(this.y,n.y,r)},n.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},n.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},n.prototype.normalize=function(){var t=this.length();if(0===t)return this;var i=1/t;return this.x*=i,this.y*=i,this},n.prototype.clone=function(){return new n(this.x,this.y)},n.Zero=function(){return new n(0,0)},n.FromArray=function(t,i){return void 0===i&&(i=0),new n(t[i],t[i+1])},n.FromArrayToRef=function(t,i,n){n.x=t[i],n.y=t[i+1]},n.CatmullRom=function(t,i,r,o,s){var e=s*s,h=s*e,a=.5*(2*i.x+(-t.x+r.x)*s+(2*t.x-5*i.x+4*r.x-o.x)*e+(-t.x+3*i.x-3*r.x+o.x)*h),u=.5*(2*i.y+(-t.y+r.y)*s+(2*t.y-5*i.y+4*r.y-o.y)*e+(-t.y+3*i.y-3*r.y+o.y)*h);return new n(a,u)},n.Clamp=function(t,i,r){var o=t.x;o=o>r.x?r.x:o,o=o<i.x?i.x:o;var s=t.y;return s=s>r.y?r.y:s,s=s<i.y?i.y:s,new n(o,s)},n.Hermite=function(t,i,r,o,s){var e=s*s,h=s*e,a=2*h-3*e+1,u=-2*h+3*e,m=h-2*e+s,y=h-e,c=t.x*a+r.x*u+i.x*m+o.x*y,p=t.y*a+r.y*u+i.y*m+o.y*y;return new n(c,p)},n.Lerp=function(t,i,r){var o=t.x+(i.x-t.x)*r,s=t.y+(i.y-t.y)*r;return new n(o,s)},n.Dot=function(t,i){return t.x*i.x+t.y*i.y},n.Normalize=function(t){var i=t.clone();return i.normalize(),i},n.Minimize=function(t,i){var r=t.x<i.x?t.x:i.x,o=t.y<i.y?t.y:i.y;return new n(r,o)},n.Maximize=function(t,i){var r=t.x>i.x?t.x:i.x,o=t.y>i.y?t.y:i.y;return new n(r,o)},n.Transform=function(t,i){var r=t.x*i.m[0]+t.y*i.m[4],o=t.x*i.m[1]+t.y*i.m[5];return new n(r,o)},n.Distance=function(t,i){return Math.sqrt(n.DistanceSquared(t,i))},n.DistanceSquared=function(t,i){var n=t.x-i.x,r=t.y-i.y;return n*n+r*r},n}();t.Vector2=o;var s=function(){function n(t,i,n){this.x=t,this.y=i,this.z=n}return n.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},n.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},n.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.x,t[i+1]=this.y,t[i+2]=this.z,this},n.prototype.toQuaternion=function(){var t=new h(0,0,0,1),i=Math.cos(.5*(this.x+this.z)),n=Math.sin(.5*(this.x+this.z)),r=Math.cos(.5*(this.z-this.x)),o=Math.sin(.5*(this.z-this.x)),s=Math.cos(.5*this.y),e=Math.sin(.5*this.y);return t.x=r*e,t.y=-o*e,t.z=n*s,t.w=i*s,t},n.prototype.addInPlace=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},n.prototype.add=function(t){return new n(this.x+t.x,this.y+t.y,this.z+t.z)},n.prototype.addToRef=function(t,i){return i.x=this.x+t.x,i.y=this.y+t.y,i.z=this.z+t.z,this},n.prototype.subtractInPlace=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},n.prototype.subtract=function(t){return new n(this.x-t.x,this.y-t.y,this.z-t.z)},n.prototype.subtractToRef=function(t,i){return i.x=this.x-t.x,i.y=this.y-t.y,i.z=this.z-t.z,this},n.prototype.subtractFromFloats=function(t,i,r){return new n(this.x-t,this.y-i,this.z-r)},n.prototype.subtractFromFloatsToRef=function(t,i,n,r){return r.x=this.x-t,r.y=this.y-i,r.z=this.z-n,this},n.prototype.negate=function(){return new n(-this.x,-this.y,-this.z)},n.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this.z*=t,this},n.prototype.scale=function(t){return new n(this.x*t,this.y*t,this.z*t)},n.prototype.scaleToRef=function(t,i){i.x=this.x*t,i.y=this.y*t,i.z=this.z*t},n.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y&&this.z===t.z},n.prototype.equalsWithEpsilon=function(n,r){return void 0===r&&(r=t.Epsilon),n&&i.WithinEpsilon(this.x,n.x,r)&&i.WithinEpsilon(this.y,n.y,r)&&i.WithinEpsilon(this.z,n.z,r)},n.prototype.equalsToFloats=function(t,i,n){return this.x===t&&this.y===i&&this.z===n},n.prototype.multiplyInPlace=function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this},n.prototype.multiply=function(t){return new n(this.x*t.x,this.y*t.y,this.z*t.z)},n.prototype.multiplyToRef=function(t,i){return i.x=this.x*t.x,i.y=this.y*t.y,i.z=this.z*t.z,this},n.prototype.multiplyByFloats=function(t,i,r){return new n(this.x*t,this.y*i,this.z*r)},n.prototype.divide=function(t){return new n(this.x/t.x,this.y/t.y,this.z/t.z)},n.prototype.divideToRef=function(t,i){return i.x=this.x/t.x,i.y=this.y/t.y,i.z=this.z/t.z,this},n.prototype.MinimizeInPlace=function(t){return t.x<this.x&&(this.x=t.x),t.y<this.y&&(this.y=t.y),t.z<this.z&&(this.z=t.z),this},n.prototype.MaximizeInPlace=function(t){return t.x>this.x&&(this.x=t.x),t.y>this.y&&(this.y=t.y),t.z>this.z&&(this.z=t.z),this},n.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},n.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},n.prototype.normalize=function(){var t=this.length();if(0===t||1===t)return this;var i=1/t;return this.x*=i,this.y*=i,this.z*=i,this},n.prototype.clone=function(){return new n(this.x,this.y,this.z)},n.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},n.prototype.copyFromFloats=function(t,i,n){return this.x=t,this.y=i,this.z=n,this},n.GetClipFactor=function(t,i,r,o){var s=n.Dot(t,r)-o,e=n.Dot(i,r)-o,h=s/(s-e);return h},n.FromArray=function(t,i){return i||(i=0),new n(t[i],t[i+1],t[i+2])},n.FromFloatArray=function(t,i){return i||(i=0),new n(t[i],t[i+1],t[i+2])},n.FromArrayToRef=function(t,i,n){n.x=t[i],n.y=t[i+1],n.z=t[i+2]},n.FromFloatArrayToRef=function(t,i,n){n.x=t[i],n.y=t[i+1],n.z=t[i+2]},n.FromFloatsToRef=function(t,i,n,r){r.x=t,r.y=i,r.z=n},n.Zero=function(){return new n(0,0,0)},n.Up=function(){return new n(0,1,0)},n.TransformCoordinates=function(t,i){var r=n.Zero();return n.TransformCoordinatesToRef(t,i,r),r},n.TransformCoordinatesToRef=function(t,i,n){var r=t.x*i.m[0]+t.y*i.m[4]+t.z*i.m[8]+i.m[12],o=t.x*i.m[1]+t.y*i.m[5]+t.z*i.m[9]+i.m[13],s=t.x*i.m[2]+t.y*i.m[6]+t.z*i.m[10]+i.m[14],e=t.x*i.m[3]+t.y*i.m[7]+t.z*i.m[11]+i.m[15];n.x=r/e,n.y=o/e,n.z=s/e},n.TransformCoordinatesFromFloatsToRef=function(t,i,n,r,o){var s=t*r.m[0]+i*r.m[4]+n*r.m[8]+r.m[12],e=t*r.m[1]+i*r.m[5]+n*r.m[9]+r.m[13],h=t*r.m[2]+i*r.m[6]+n*r.m[10]+r.m[14],a=t*r.m[3]+i*r.m[7]+n*r.m[11]+r.m[15];o.x=s/a,o.y=e/a,o.z=h/a},n.TransformNormal=function(t,i){var r=n.Zero();return n.TransformNormalToRef(t,i,r),r},n.TransformNormalToRef=function(t,i,n){n.x=t.x*i.m[0]+t.y*i.m[4]+t.z*i.m[8],n.y=t.x*i.m[1]+t.y*i.m[5]+t.z*i.m[9],n.z=t.x*i.m[2]+t.y*i.m[6]+t.z*i.m[10]},n.TransformNormalFromFloatsToRef=function(t,i,n,r,o){o.x=t*r.m[0]+i*r.m[4]+n*r.m[8],o.y=t*r.m[1]+i*r.m[5]+n*r.m[9],o.z=t*r.m[2]+i*r.m[6]+n*r.m[10]},n.CatmullRom=function(t,i,r,o,s){var e=s*s,h=s*e,a=.5*(2*i.x+(-t.x+r.x)*s+(2*t.x-5*i.x+4*r.x-o.x)*e+(-t.x+3*i.x-3*r.x+o.x)*h),u=.5*(2*i.y+(-t.y+r.y)*s+(2*t.y-5*i.y+4*r.y-o.y)*e+(-t.y+3*i.y-3*r.y+o.y)*h),m=.5*(2*i.z+(-t.z+r.z)*s+(2*t.z-5*i.z+4*r.z-o.z)*e+(-t.z+3*i.z-3*r.z+o.z)*h);return new n(a,u,m)},n.Clamp=function(t,i,r){var o=t.x;o=o>r.x?r.x:o,o=o<i.x?i.x:o;var s=t.y;s=s>r.y?r.y:s,s=s<i.y?i.y:s;var e=t.z;return e=e>r.z?r.z:e,e=e<i.z?i.z:e,new n(o,s,e)},n.Hermite=function(t,i,r,o,s){var e=s*s,h=s*e,a=2*h-3*e+1,u=-2*h+3*e,m=h-2*e+s,y=h-e,c=t.x*a+r.x*u+i.x*m+o.x*y,p=t.y*a+r.y*u+i.y*m+o.y*y,f=t.z*a+r.z*u+i.z*m+o.z*y;return new n(c,p,f)},n.Lerp=function(t,i,r){var o=t.x+(i.x-t.x)*r,s=t.y+(i.y-t.y)*r,e=t.z+(i.z-t.z)*r;return new n(o,s,e)},n.Dot=function(t,i){return t.x*i.x+t.y*i.y+t.z*i.z},n.Cross=function(t,i){var r=n.Zero();return n.CrossToRef(t,i,r),r},n.CrossToRef=function(t,i,n){n.x=t.y*i.z-t.z*i.y,n.y=t.z*i.x-t.x*i.z,n.z=t.x*i.y-t.y*i.x},n.Normalize=function(t){var i=n.Zero();return n.NormalizeToRef(t,i),i},n.NormalizeToRef=function(t,i){i.copyFrom(t),i.normalize()},n.Project=function(t,i,r,o){var s=o.width,e=o.height,h=o.x,u=o.y,m=a.FromValues(s/2,0,0,0,0,-e/2,0,0,0,0,1,0,h+s/2,e/2+u,0,1),y=i.multiply(r).multiply(m);return n.TransformCoordinates(t,y)},n.UnprojectFromTransform=function(t,r,o,s,e){var h=s.multiply(e);h.invert(),t.x=t.x/r*2-1,t.y=-(t.y/o*2-1);var a=n.TransformCoordinates(t,h),u=t.x*h.m[3]+t.y*h.m[7]+t.z*h.m[11]+h.m[15];return i.WithinEpsilon(u,1)&&(a=a.scale(1/u)),a},n.Unproject=function(t,r,o,s,e,h){var a=s.multiply(e).multiply(h);a.invert();var u=new n(t.x/r*2-1,-(t.y/o*2-1),t.z),m=n.TransformCoordinates(u,a),y=u.x*a.m[3]+u.y*a.m[7]+u.z*a.m[11]+a.m[15];return i.WithinEpsilon(y,1)&&(m=m.scale(1/y)),m},n.Minimize=function(t,i){var n=t.clone();return n.MinimizeInPlace(i),n},n.Maximize=function(t,i){var n=t.clone();return n.MaximizeInPlace(i),n},n.Distance=function(t,i){return Math.sqrt(n.DistanceSquared(t,i))},n.DistanceSquared=function(t,i){var n=t.x-i.x,r=t.y-i.y,o=t.z-i.z;return n*n+r*r+o*o},n.Center=function(t,i){var n=t.add(i);return n.scaleInPlace(.5),n},n.RotationFromAxis=function(t,i,r){var o=n.Zero();return n.RotationFromAxisToRef(t,i,r,o),o},n.RotationFromAxisToRef=function(r,o,s,e){var h=r.normalize(),a=s.normalize(),u=c.X,m=c.Y,y=0,p=0,f=0,l=0,x=0,z=0,w=0,v=-1,d=0,g=_.Vector3[0],T=0,R=_.Vector3[1];i.WithinEpsilon(a.z,0,t.Epsilon)?z=1:i.WithinEpsilon(a.x,0,t.Epsilon)?l=1:(w=a.z/a.x,l=-w*Math.sqrt(1/(1+w*w)),z=Math.sqrt(1/(1+w*w))),R.x=l,R.y=x,R.z=z,R.normalize(),n.CrossToRef(h,R,g),g.normalize(),n.Dot(a,g)<0&&(v=1),T=n.Dot(h,R),T=Math.min(1,Math.max(-1,T)),f=Math.acos(T)*v,n.Dot(R,u)<0&&(f=Math.PI+f,R=R.scaleInPlace(-1),d++);var M=_.Vector3[2],F=_.Vector3[3];l=0,x=0,z=0,v=-1,i.WithinEpsilon(a.z,0,t.Epsilon)?l=1:(w=R.z/R.x,l=-w*Math.sqrt(1/(1+w*w)),z=Math.sqrt(1/(1+w*w))),M.x=l,M.y=x,M.z=z,M.normalize(),n.CrossToRef(M,R,F),F.normalize(),n.CrossToRef(a,M,g),g.normalize(),n.Dot(R,g)<0&&(v=1),T=n.Dot(a,M),T=Math.min(1,Math.max(-1,T)),p=Math.acos(T)*v,n.Dot(F,m)<0&&(p=Math.PI+p,d++),v=-1,n.CrossToRef(u,R,g),g.normalize(),n.Dot(g,m)<0&&(v=1),T=n.Dot(R,u),T=Math.min(1,Math.max(-1,T)),y=-Math.acos(T)*v,0>T&&2>d&&(y=Math.PI+y),e.x=p,e.y=y,e.z=f},n}();t.Vector3=s;var e=function(){function n(t,i,n,r){this.x=t,this.y=i,this.z=n,this.w=r}return n.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"W:"+this.w+"}"},n.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},n.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.x,t[i+1]=this.y,t[i+2]=this.z,t[i+3]=this.w,this},n.prototype.addInPlace=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this},n.prototype.add=function(t){return new n(this.x+t.x,this.y+t.y,this.z+t.z,this.w+t.w)},n.prototype.addToRef=function(t,i){return i.x=this.x+t.x,i.y=this.y+t.y,i.z=this.z+t.z,i.w=this.w+t.w,this},n.prototype.subtractInPlace=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this},n.prototype.subtract=function(t){return new n(this.x-t.x,this.y-t.y,this.z-t.z,this.w-t.w)},n.prototype.subtractToRef=function(t,i){return i.x=this.x-t.x,i.y=this.y-t.y,i.z=this.z-t.z,i.w=this.w-t.w,this},n.prototype.subtractFromFloats=function(t,i,r,o){return new n(this.x-t,this.y-i,this.z-r,this.w-o)},n.prototype.subtractFromFloatsToRef=function(t,i,n,r,o){return o.x=this.x-t,o.y=this.y-i,o.z=this.z-n,o.w=this.w-r,this},n.prototype.negate=function(){return new n(-this.x,-this.y,-this.z,-this.w)},n.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},n.prototype.scale=function(t){return new n(this.x*t,this.y*t,this.z*t,this.w*t)},n.prototype.scaleToRef=function(t,i){i.x=this.x*t,i.y=this.y*t,i.z=this.z*t,i.w=this.w*t},n.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w},n.prototype.equalsWithEpsilon=function(n,r){return void 0===r&&(r=t.Epsilon),n&&i.WithinEpsilon(this.x,n.x,r)&&i.WithinEpsilon(this.y,n.y,r)&&i.WithinEpsilon(this.z,n.z,r)&&i.WithinEpsilon(this.w,n.w,r)},n.prototype.equalsToFloats=function(t,i,n,r){return this.x===t&&this.y===i&&this.z===n&&this.w===r},n.prototype.multiplyInPlace=function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this},n.prototype.multiply=function(t){return new n(this.x*t.x,this.y*t.y,this.z*t.z,this.w*t.w)},n.prototype.multiplyToRef=function(t,i){return i.x=this.x*t.x,i.y=this.y*t.y,i.z=this.z*t.z,i.w=this.w*t.w,this},n.prototype.multiplyByFloats=function(t,i,r,o){return new n(this.x*t,this.y*i,this.z*r,this.w*o)},n.prototype.divide=function(t){return new n(this.x/t.x,this.y/t.y,this.z/t.z,this.w/t.w)},n.prototype.divideToRef=function(t,i){return i.x=this.x/t.x,i.y=this.y/t.y,i.z=this.z/t.z,i.w=this.w/t.w,this},n.prototype.MinimizeInPlace=function(t){return t.x<this.x&&(this.x=t.x),t.y<this.y&&(this.y=t.y),t.z<this.z&&(this.z=t.z),t.w<this.w&&(this.w=t.w),this},n.prototype.MaximizeInPlace=function(t){return t.x>this.x&&(this.x=t.x),t.y>this.y&&(this.y=t.y),t.z>this.z&&(this.z=t.z),t.w>this.w&&(this.w=t.w),this},n.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},n.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},n.prototype.normalize=function(){var t=this.length();if(0===t)return this;var i=1/t;return this.x*=i,this.y*=i,this.z*=i,this.w*=i,this},n.prototype.clone=function(){return new n(this.x,this.y,this.z,this.w)},n.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},n.prototype.copyFromFloats=function(t,i,n,r){return this.x=t,this.y=i,this.z=n,this.w=r,this},n.FromArray=function(t,i){return i||(i=0),new n(t[i],t[i+1],t[i+2],t[i+3])},n.FromArrayToRef=function(t,i,n){n.x=t[i],n.y=t[i+1],n.z=t[i+2],n.w=t[i+3]},n.FromFloatArrayToRef=function(t,i,n){n.x=t[i],n.y=t[i+1],n.z=t[i+2],n.w=t[i+3]},n.FromFloatsToRef=function(t,i,n,r,o){o.x=t,o.y=i,o.z=n,o.w=r},n.Zero=function(){return new n(0,0,0,0)},n.Normalize=function(t){var i=n.Zero();return n.NormalizeToRef(t,i),i},n.NormalizeToRef=function(t,i){i.copyFrom(t),i.normalize()},n.Minimize=function(t,i){var n=t.clone();return n.MinimizeInPlace(i),n},n.Maximize=function(t,i){var n=t.clone();return n.MaximizeInPlace(i),n},n.Distance=function(t,i){return Math.sqrt(n.DistanceSquared(t,i))},n.DistanceSquared=function(t,i){var n=t.x-i.x,r=t.y-i.y,o=t.z-i.z,s=t.w-i.w;return n*n+r*r+o*o+s*s},n.Center=function(t,i){var n=t.add(i);return n.scaleInPlace(.5),n},n}();t.Vector4=e;var h=function(){function t(t,i,n,r){void 0===t&&(t=0),void 0===i&&(i=0),void 0===n&&(n=0),void 0===r&&(r=1),this.x=t,this.y=i,this.z=n,this.w=r}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},t.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},t.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},t.prototype.copyFromFloats=function(t,i,n,r){return this.x=t,this.y=i,this.z=n,this.w=r,this},t.prototype.add=function(i){return new t(this.x+i.x,this.y+i.y,this.z+i.z,this.w+i.w)},t.prototype.subtract=function(i){return new t(this.x-i.x,this.y-i.y,this.z-i.z,this.w-i.w)},t.prototype.scale=function(i){return new t(this.x*i,this.y*i,this.z*i,this.w*i)},t.prototype.multiply=function(i){var n=new t(0,0,0,1);return this.multiplyToRef(i,n),n},t.prototype.multiplyToRef=function(t,i){var n=this.x*t.w+this.y*t.z-this.z*t.y+this.w*t.x,r=-this.x*t.z+this.y*t.w+this.z*t.x+this.w*t.y,o=this.x*t.y-this.y*t.x+this.z*t.w+this.w*t.z,s=-this.x*t.x-this.y*t.y-this.z*t.z+this.w*t.w;return i.copyFromFloats(n,r,o,s),this},t.prototype.multiplyInPlace=function(t){return this.multiplyToRef(t,this),this},t.prototype.conjugateToRef=function(t){return t.copyFromFloats(-this.x,-this.y,-this.z,this.w),this},t.prototype.conjugateInPlace=function(){return this.x*=-1,this.y*=-1,this.z*=-1,this},t.prototype.conjugate=function(){var i=new t(-this.x,-this.y,-this.z,this.w);return i},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},t.prototype.normalize=function(){var t=1/this.length();return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.toEulerAngles=function(t){void 0===t&&(t="YZX");var i=s.Zero();return this.toEulerAnglesToRef(i,t),i},t.prototype.toEulerAnglesToRef=function(t,i){void 0===i&&(i="YZX");var n,r,o,s=this.x,e=this.y,h=this.z,a=this.w;switch(i){case"YZX":var u=s*e+h*a;if(u>.499&&(n=2*Math.atan2(s,a),r=Math.PI/2,o=0),-.499>u&&(n=-2*Math.atan2(s,a),r=-Math.PI/2,o=0),isNaN(n)){var m=s*s,y=e*e,c=h*h;n=Math.atan2(2*e*a-2*s*h,1-2*y-2*c),r=Math.asin(2*u),o=Math.atan2(2*s*a-2*e*h,1-2*m-2*c)}break;default:throw new Error("Euler order "+i+" not supported yet.")}return t.y=n,t.z=r,t.x=o,this},t.prototype.toRotationMatrix=function(t){var i=this.x*this.x,n=this.y*this.y,r=this.z*this.z,o=this.x*this.y,s=this.z*this.w,e=this.z*this.x,h=this.y*this.w,a=this.y*this.z,u=this.x*this.w;return t.m[0]=1-2*(n+r),t.m[1]=2*(o+s),t.m[2]=2*(e-h),t.m[3]=0,t.m[4]=2*(o-s),t.m[5]=1-2*(r+i),t.m[6]=2*(a+u),t.m[7]=0,t.m[8]=2*(e+h),t.m[9]=2*(a-u),t.m[10]=1-2*(n+i),t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0,t.m[15]=1,this},t.prototype.fromRotationMatrix=function(i){return t.FromRotationMatrixToRef(i,this),this},t.FromRotationMatrix=function(i){var n=new t;return t.FromRotationMatrixToRef(i,n),n},t.FromRotationMatrixToRef=function(t,i){var n,r=t.m,o=r[0],s=r[4],e=r[8],h=r[1],a=r[5],u=r[9],m=r[2],y=r[6],c=r[10],p=o+a+c;p>0?(n=.5/Math.sqrt(p+1),i.w=.25/n,i.x=(y-u)*n,i.y=(e-m)*n,i.z=(h-s)*n):o>a&&o>c?(n=2*Math.sqrt(1+o-a-c),i.w=(y-u)/n,i.x=.25*n,i.y=(s+h)/n,i.z=(e+m)/n):a>c?(n=2*Math.sqrt(1+a-o-c),i.w=(e-m)/n,i.x=(s+h)/n,i.y=.25*n,i.z=(u+y)/n):(n=2*Math.sqrt(1+c-o-a),i.w=(h-s)/n,i.x=(e+m)/n,i.y=(u+y)/n,i.z=.25*n)},t.Inverse=function(i){return new t(-i.x,-i.y,-i.z,i.w)},t.Identity=function(){return new t(0,0,0,1)},t.RotationAxis=function(i,n){var r=new t,o=Math.sin(n/2);return i.normalize(),r.w=Math.cos(n/2),r.x=i.x*o,r.y=i.y*o,r.z=i.z*o,r},t.FromArray=function(i,n){return n||(n=0),new t(i[n],i[n+1],i[n+2],i[n+3])},t.RotationYawPitchRoll=function(i,n,r){var o=new t;return t.RotationYawPitchRollToRef(i,n,r,o),o},t.RotationYawPitchRollToRef=function(t,i,n,r){var o=.5*n,s=.5*i,e=.5*t,h=Math.sin(o),a=Math.cos(o),u=Math.sin(s),m=Math.cos(s),y=Math.sin(e),c=Math.cos(e);r.x=c*u*a+y*m*h,r.y=y*m*a-c*u*h,r.z=c*m*h-y*u*a,r.w=c*m*a+y*u*h},t.RotationAlphaBetaGamma=function(i,n,r){var o=new t;return t.RotationAlphaBetaGammaToRef(i,n,r,o),o},t.RotationAlphaBetaGammaToRef=function(t,i,n,r){var o=.5*(n+t),s=.5*(n-t),e=.5*i;r.x=Math.cos(s)*Math.sin(e),r.y=Math.sin(s)*Math.sin(e),r.z=Math.sin(o)*Math.cos(e),r.w=Math.cos(o)*Math.cos(e)},t.Slerp=function(i,n,r){var o,s,e=r,h=i.x*n.x+i.y*n.y+i.z*n.z+i.w*n.w,a=!1;if(0>h&&(a=!0,h=-h),h>.999999)s=1-e,o=a?-e:e;else{var u=Math.acos(h),m=1/Math.sin(u);s=Math.sin((1-e)*u)*m,o=a?-Math.sin(e*u)*m:Math.sin(e*u)*m}return new t(s*i.x+o*n.x,s*i.y+o*n.y,s*i.z+o*n.z,s*i.w+o*n.w)},t}();t.Quaternion=h;var a=function(){function t(){this.m=new Float32Array(16)}return t.prototype.isIdentity=function(){return 1!==this.m[0]||1!==this.m[5]||1!==this.m[10]||1!==this.m[15]?!1:0===this.m[1]&&0===this.m[2]&&0===this.m[3]&&0===this.m[4]&&0===this.m[6]&&0===this.m[7]&&0===this.m[8]&&0===this.m[9]&&0===this.m[11]&&0===this.m[12]&&0===this.m[13]&&0===this.m[14]},t.prototype.determinant=function(){var t=this.m[10]*this.m[15]-this.m[11]*this.m[14],i=this.m[9]*this.m[15]-this.m[11]*this.m[13],n=this.m[9]*this.m[14]-this.m[10]*this.m[13],r=this.m[8]*this.m[15]-this.m[11]*this.m[12],o=this.m[8]*this.m[14]-this.m[10]*this.m[12],s=this.m[8]*this.m[13]-this.m[9]*this.m[12];return this.m[0]*(this.m[5]*t-this.m[6]*i+this.m[7]*n)-this.m[1]*(this.m[4]*t-this.m[6]*r+this.m[7]*o)+this.m[2]*(this.m[4]*i-this.m[5]*r+this.m[7]*s)-this.m[3]*(this.m[4]*n-this.m[5]*o+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 t=0;16>t;t++)this.m[t]=0;return this},t.prototype.add=function(i){var n=new t;return this.addToRef(i,n),n},t.prototype.addToRef=function(t,i){for(var n=0;16>n;n++)i.m[n]=this.m[n]+t.m[n];return this},t.prototype.addToSelf=function(t){for(var i=0;16>i;i++)this.m[i]+=t.m[i];return this},t.prototype.invertToRef=function(t){var i=this.m[0],n=this.m[1],r=this.m[2],o=this.m[3],s=this.m[4],e=this.m[5],h=this.m[6],a=this.m[7],u=this.m[8],m=this.m[9],y=this.m[10],c=this.m[11],p=this.m[12],f=this.m[13],l=this.m[14],x=this.m[15],z=y*x-c*l,w=m*x-c*f,v=m*l-y*f,d=u*x-c*p,g=u*l-y*p,T=u*f-m*p,R=e*z-h*w+a*v,_=-(s*z-h*d+a*g),M=s*w-e*d+a*T,F=-(s*v-e*g+h*T),b=1/(i*R+n*_+r*M+o*F),A=h*x-a*l,L=e*x-a*f,P=e*l-h*f,Z=s*x-a*p,C=s*l-h*p,S=s*f-e*p,I=h*c-a*y,q=e*c-a*m,E=e*y-h*m,D=s*c-a*u,V=s*y-h*u,W=s*m-e*u;return t.m[0]=R*b,t.m[4]=_*b,t.m[8]=M*b,t.m[12]=F*b,t.m[1]=-(n*z-r*w+o*v)*b,t.m[5]=(i*z-r*d+o*g)*b,t.m[9]=-(i*w-n*d+o*T)*b,t.m[13]=(i*v-n*g+r*T)*b,t.m[2]=(n*A-r*L+o*P)*b,t.m[6]=-(i*A-r*Z+o*C)*b,t.m[10]=(i*L-n*Z+o*S)*b,t.m[14]=-(i*P-n*C+r*S)*b,t.m[3]=-(n*I-r*q+o*E)*b,t.m[7]=(i*I-r*D+o*V)*b,t.m[11]=-(i*q-n*D+o*W)*b,t.m[15]=(i*E-n*V+r*W)*b,this},t.prototype.setTranslation=function(t){return this.m[12]=t.x,this.m[13]=t.y,this.m[14]=t.z,this},t.prototype.multiply=function(i){var n=new t;return this.multiplyToRef(i,n),n},t.prototype.copyFrom=function(t){for(var i=0;16>i;i++)this.m[i]=t.m[i];return this},t.prototype.copyToArray=function(t,i){void 0===i&&(i=0);for(var n=0;16>n;n++)t[i+n]=this.m[n];return this},t.prototype.multiplyToRef=function(t,i){return this.multiplyToArray(t,i.m,0),this},t.prototype.multiplyToArray=function(t,i,n){var r=this.m[0],o=this.m[1],s=this.m[2],e=this.m[3],h=this.m[4],a=this.m[5],u=this.m[6],m=this.m[7],y=this.m[8],c=this.m[9],p=this.m[10],f=this.m[11],l=this.m[12],x=this.m[13],z=this.m[14],w=this.m[15],v=t.m[0],d=t.m[1],g=t.m[2],T=t.m[3],R=t.m[4],_=t.m[5],M=t.m[6],F=t.m[7],b=t.m[8],A=t.m[9],L=t.m[10],P=t.m[11],Z=t.m[12],C=t.m[13],S=t.m[14],I=t.m[15];return i[n]=r*v+o*R+s*b+e*Z,i[n+1]=r*d+o*_+s*A+e*C,i[n+2]=r*g+o*M+s*L+e*S,i[n+3]=r*T+o*F+s*P+e*I,i[n+4]=h*v+a*R+u*b+m*Z,i[n+5]=h*d+a*_+u*A+m*C,i[n+6]=h*g+a*M+u*L+m*S,i[n+7]=h*T+a*F+u*P+m*I,i[n+8]=y*v+c*R+p*b+f*Z,i[n+9]=y*d+c*_+p*A+f*C,i[n+10]=y*g+c*M+p*L+f*S,i[n+11]=y*T+c*F+p*P+f*I,i[n+12]=l*v+x*R+z*b+w*Z,i[n+13]=l*d+x*_+z*A+w*C,i[n+14]=l*g+x*M+z*L+w*S,i[n+15]=l*T+x*F+z*P+w*I,this},t.prototype.equals=function(t){return t&&this.m[0]===t.m[0]&&this.m[1]===t.m[1]&&this.m[2]===t.m[2]&&this.m[3]===t.m[3]&&this.m[4]===t.m[4]&&this.m[5]===t.m[5]&&this.m[6]===t.m[6]&&this.m[7]===t.m[7]&&this.m[8]===t.m[8]&&this.m[9]===t.m[9]&&this.m[10]===t.m[10]&&this.m[11]===t.m[11]&&this.m[12]===t.m[12]&&this.m[13]===t.m[13]&&this.m[14]===t.m[14]&&this.m[15]===t.m[15]},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(n,r,o){o.x=this.m[12],o.y=this.m[13],o.z=this.m[14];var s=i.Sign(this.m[0]*this.m[1]*this.m[2]*this.m[3])<0?-1:1,e=i.Sign(this.m[4]*this.m[5]*this.m[6]*this.m[7])<0?-1:1,a=i.Sign(this.m[8]*this.m[9]*this.m[10]*this.m[11])<0?-1:1;if(n.x=s*Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]+this.m[2]*this.m[2]),n.y=e*Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]+this.m[6]*this.m[6]),n.z=a*Math.sqrt(this.m[8]*this.m[8]+this.m[9]*this.m[9]+this.m[10]*this.m[10]),0===n.x||0===n.y||0===n.z)return r.x=0,r.y=0,r.z=0,r.w=1,!1;var u=t.FromValues(this.m[0]/n.x,this.m[1]/n.x,this.m[2]/n.x,0,this.m[4]/n.y,this.m[5]/n.y,this.m[6]/n.y,0,this.m[8]/n.z,this.m[9]/n.z,this.m[10]/n.z,0,0,0,0,1);return h.FromRotationMatrixToRef(u,r),!0},t.FromArray=function(i,n){var r=new t;return n||(n=0),t.FromArrayToRef(i,n,r),r},t.FromArrayToRef=function(t,i,n){for(var r=0;16>r;r++)n.m[r]=t[r+i]},t.FromFloat32ArrayToRefScaled=function(t,i,n,r){for(var o=0;16>o;o++)r.m[o]=t[o+i]*n},t.FromValuesToRef=function(t,i,n,r,o,s,e,h,a,u,m,y,c,p,f,l,x){x.m[0]=t,x.m[1]=i,x.m[2]=n,x.m[3]=r,x.m[4]=o,x.m[5]=s,x.m[6]=e,x.m[7]=h,x.m[8]=a,x.m[9]=u,x.m[10]=m,x.m[11]=y,x.m[12]=c,x.m[13]=p,x.m[14]=f,x.m[15]=l},t.FromValues=function(i,n,r,o,s,e,h,a,u,m,y,c,p,f,l,x){var z=new t;return z.m[0]=i,z.m[1]=n,z.m[2]=r,z.m[3]=o,z.m[4]=s,z.m[5]=e,z.m[6]=h,z.m[7]=a,z.m[8]=u,z.m[9]=m,z.m[10]=y,z.m[11]=c,z.m[12]=p,z.m[13]=f,z.m[14]=l,z.m[15]=x,z},t.Compose=function(i,n,r){var o=t.FromValues(i.x,0,0,0,0,i.y,0,0,0,0,i.z,0,0,0,0,1),s=t.Identity();return n.toRotationMatrix(s),o=o.multiply(s),o.setTranslation(r),o},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(i){t.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,i)},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(i){var n=new t;return t.RotationXToRef(i,n),n},t.Invert=function(i){var n=new t;return i.invertToRef(n),n},t.RotationXToRef=function(t,i){var n=Math.sin(t),r=Math.cos(t);i.m[0]=1,i.m[15]=1,i.m[5]=r,i.m[10]=r,i.m[9]=-n,i.m[6]=n,i.m[1]=0,i.m[2]=0,i.m[3]=0,i.m[4]=0,i.m[7]=0,i.m[8]=0,i.m[11]=0,i.m[12]=0,i.m[13]=0,i.m[14]=0},t.RotationY=function(i){var n=new t;return t.RotationYToRef(i,n),n},t.RotationYToRef=function(t,i){var n=Math.sin(t),r=Math.cos(t);\ni.m[5]=1,i.m[15]=1,i.m[0]=r,i.m[2]=-n,i.m[8]=n,i.m[10]=r,i.m[1]=0,i.m[3]=0,i.m[4]=0,i.m[6]=0,i.m[7]=0,i.m[9]=0,i.m[11]=0,i.m[12]=0,i.m[13]=0,i.m[14]=0},t.RotationZ=function(i){var n=new t;return t.RotationZToRef(i,n),n},t.RotationZToRef=function(t,i){var n=Math.sin(t),r=Math.cos(t);i.m[10]=1,i.m[15]=1,i.m[0]=r,i.m[1]=n,i.m[4]=-n,i.m[5]=r,i.m[2]=0,i.m[3]=0,i.m[6]=0,i.m[7]=0,i.m[8]=0,i.m[9]=0,i.m[11]=0,i.m[12]=0,i.m[13]=0,i.m[14]=0},t.RotationAxis=function(i,n){var r=t.Zero();return t.RotationAxisToRef(i,n,r),r},t.RotationAxisToRef=function(t,i,n){var r=Math.sin(-i),o=Math.cos(-i),s=1-o;t.normalize(),n.m[0]=t.x*t.x*s+o,n.m[1]=t.x*t.y*s-t.z*r,n.m[2]=t.x*t.z*s+t.y*r,n.m[3]=0,n.m[4]=t.y*t.x*s+t.z*r,n.m[5]=t.y*t.y*s+o,n.m[6]=t.y*t.z*s-t.x*r,n.m[7]=0,n.m[8]=t.z*t.x*s-t.y*r,n.m[9]=t.z*t.y*s+t.x*r,n.m[10]=t.z*t.z*s+o,n.m[11]=0,n.m[15]=1},t.RotationYawPitchRoll=function(i,n,r){var o=new t;return t.RotationYawPitchRollToRef(i,n,r,o),o},t.RotationYawPitchRollToRef=function(t,i,n,r){h.RotationYawPitchRollToRef(t,i,n,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(r)},t.Scaling=function(i,n,r){var o=t.Zero();return t.ScalingToRef(i,n,r,o),o},t.ScalingToRef=function(t,i,n,r){r.m[0]=t,r.m[1]=0,r.m[2]=0,r.m[3]=0,r.m[4]=0,r.m[5]=i,r.m[6]=0,r.m[7]=0,r.m[8]=0,r.m[9]=0,r.m[10]=n,r.m[11]=0,r.m[12]=0,r.m[13]=0,r.m[14]=0,r.m[15]=1},t.Translation=function(i,n,r){var o=t.Identity();return t.TranslationToRef(i,n,r,o),o},t.TranslationToRef=function(i,n,r,o){t.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,i,n,r,1,o)},t.Lerp=function(i,n,r){var o=new s(0,0,0),e=new h,a=new s(0,0,0);i.decompose(o,e,a);var u=new s(0,0,0),m=new h,y=new s(0,0,0);n.decompose(u,m,y);var c=s.Lerp(o,u,r),p=h.Slerp(e,m,r),f=s.Lerp(a,y,r);return t.Compose(c,p,f)},t.LookAtLH=function(i,n,r){var o=t.Zero();return t.LookAtLHToRef(i,n,r,o),o},t.LookAtLHToRef=function(i,n,r,o){n.subtractToRef(i,this._zAxis),this._zAxis.normalize(),s.CrossToRef(r,this._zAxis,this._xAxis),0===this._xAxis.lengthSquared()?this._xAxis.x=1:this._xAxis.normalize(),s.CrossToRef(this._zAxis,this._xAxis,this._yAxis),this._yAxis.normalize();var e=-s.Dot(this._xAxis,i),h=-s.Dot(this._yAxis,i),a=-s.Dot(this._zAxis,i);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,e,h,a,1,o)},t.OrthoLH=function(i,n,r,o){var s=t.Zero();return t.OrthoLHToRef(i,n,r,o,s),s},t.OrthoLHToRef=function(i,n,r,o,s){var e=2/i,h=2/n,a=1/(o-r),u=r/(r-o);t.FromValuesToRef(e,0,0,0,0,h,0,0,0,0,a,0,0,0,u,1,s)},t.OrthoOffCenterLH=function(i,n,r,o,s,e){var h=t.Zero();return t.OrthoOffCenterLHToRef(i,n,r,o,s,e,h),h},t.OrthoOffCenterLHToRef=function(t,i,n,r,o,s,e){e.m[0]=2/(i-t),e.m[1]=e.m[2]=e.m[3]=0,e.m[5]=2/(r-n),e.m[4]=e.m[6]=e.m[7]=0,e.m[10]=-1/(o-s),e.m[8]=e.m[9]=e.m[11]=0,e.m[12]=(t+i)/(t-i),e.m[13]=(r+n)/(n-r),e.m[14]=o/(o-s),e.m[15]=1},t.PerspectiveLH=function(i,n,r,o){var s=t.Zero();return s.m[0]=2*r/i,s.m[1]=s.m[2]=s.m[3]=0,s.m[5]=2*r/n,s.m[4]=s.m[6]=s.m[7]=0,s.m[10]=-o/(r-o),s.m[8]=s.m[9]=0,s.m[11]=1,s.m[12]=s.m[13]=s.m[15]=0,s.m[14]=r*o/(r-o),s},t.PerspectiveFovLH=function(i,n,r,o){var s=t.Zero();return t.PerspectiveFovLHToRef(i,n,r,o,s),s},t.PerspectiveFovLHToRef=function(t,i,n,r,o,s){void 0===s&&(s=!0);var e=1/Math.tan(.5*t);s?o.m[0]=e/i:o.m[0]=e,o.m[1]=o.m[2]=o.m[3]=0,s?o.m[5]=e:o.m[5]=e*i,o.m[4]=o.m[6]=o.m[7]=0,o.m[8]=o.m[9]=0,o.m[10]=-r/(n-r),o.m[11]=1,o.m[12]=o.m[13]=o.m[15]=0,o.m[14]=n*r/(n-r)},t.GetFinalMatrix=function(i,n,r,o,s,e){var h=i.width,a=i.height,u=i.x,m=i.y,y=t.FromValues(h/2,0,0,0,0,-a/2,0,0,0,0,e-s,0,u+h/2,a/2+m,s,1);return n.multiply(r).multiply(o).multiply(y)},t.GetAsMatrix2x2=function(t){return new Float32Array([t.m[0],t.m[1],t.m[4],t.m[5]])},t.GetAsMatrix3x3=function(t){return new Float32Array([t.m[0],t.m[1],t.m[2],t.m[4],t.m[5],t.m[6],t.m[8],t.m[9],t.m[10]])},t.Transpose=function(i){var n=new t;return n.m[0]=i.m[0],n.m[1]=i.m[4],n.m[2]=i.m[8],n.m[3]=i.m[12],n.m[4]=i.m[1],n.m[5]=i.m[5],n.m[6]=i.m[9],n.m[7]=i.m[13],n.m[8]=i.m[2],n.m[9]=i.m[6],n.m[10]=i.m[10],n.m[11]=i.m[14],n.m[12]=i.m[3],n.m[13]=i.m[7],n.m[14]=i.m[11],n.m[15]=i.m[15],n},t.Reflection=function(i){var n=new t;return t.ReflectionToRef(i,n),n},t.ReflectionToRef=function(t,i){t.normalize();var n=t.normal.x,r=t.normal.y,o=t.normal.z,s=-2*n,e=-2*r,h=-2*o;i.m[0]=s*n+1,i.m[1]=e*n,i.m[2]=h*n,i.m[3]=0,i.m[4]=s*r,i.m[5]=e*r+1,i.m[6]=h*r,i.m[7]=0,i.m[8]=s*o,i.m[9]=e*o,i.m[10]=h*o+1,i.m[11]=0,i.m[12]=s*t.d,i.m[13]=e*t.d,i.m[14]=h*t.d,i.m[15]=1},t._tempQuaternion=new h,t._xAxis=s.Zero(),t._yAxis=s.Zero(),t._zAxis=s.Zero(),t}();t.Matrix=a;var u=function(){function t(t,i,n,r){this.normal=new s(t,i,n),this.d=r}return t.prototype.asArray=function(){return[this.normal.x,this.normal.y,this.normal.z,this.d]},t.prototype.clone=function(){return new t(this.normal.x,this.normal.y,this.normal.z,this.d)},t.prototype.normalize=function(){var t=Math.sqrt(this.normal.x*this.normal.x+this.normal.y*this.normal.y+this.normal.z*this.normal.z),i=0;return 0!==t&&(i=1/t),this.normal.x*=i,this.normal.y*=i,this.normal.z*=i,this.d*=i,this},t.prototype.transform=function(i){var n=a.Transpose(i),r=this.normal.x,o=this.normal.y,s=this.normal.z,e=this.d,h=r*n.m[0]+o*n.m[1]+s*n.m[2]+e*n.m[3],u=r*n.m[4]+o*n.m[5]+s*n.m[6]+e*n.m[7],m=r*n.m[8]+o*n.m[9]+s*n.m[10]+e*n.m[11],y=r*n.m[12]+o*n.m[13]+s*n.m[14]+e*n.m[15];return new t(h,u,m,y)},t.prototype.dotCoordinate=function(t){return this.normal.x*t.x+this.normal.y*t.y+this.normal.z*t.z+this.d},t.prototype.copyFromPoints=function(t,i,n){var r,o=i.x-t.x,s=i.y-t.y,e=i.z-t.z,h=n.x-t.x,a=n.y-t.y,u=n.z-t.z,m=s*u-e*a,y=e*h-o*u,c=o*a-s*h,p=Math.sqrt(m*m+y*y+c*c);return r=0!==p?1/p:0,this.normal.x=m*r,this.normal.y=y*r,this.normal.z=c*r,this.d=-(this.normal.x*t.x+this.normal.y*t.y+this.normal.z*t.z),this},t.prototype.isFrontFacingTo=function(t,i){var n=s.Dot(this.normal,t);return i>=n},t.prototype.signedDistanceTo=function(t){return s.Dot(t,this.normal)+this.d},t.FromArray=function(i){return new t(i[0],i[1],i[2],i[3])},t.FromPoints=function(i,n,r){var o=new t(0,0,0,0);return o.copyFromPoints(i,n,r),o},t.FromPositionAndNormal=function(i,n){var r=new t(0,0,0,0);return n.normalize(),r.normal=n,r.d=-(n.x*i.x+n.y*i.y+n.z*i.z),r},t.SignedDistanceToPlaneFromPositionAndNormal=function(t,i,n){var r=-(i.x*t.x+i.y*t.y+i.z*t.z);return s.Dot(n,i)+r},t}();t.Plane=u;var m=function(){function t(t,i,n,r){this.x=t,this.y=i,this.width=n,this.height=r}return t.prototype.toGlobal=function(i,n){return new t(this.x*i,this.y*n,this.width*i,this.height*n)},t}();t.Viewport=m;var y=function(){function t(){}return t.GetPlanes=function(i){for(var n=[],r=0;6>r;r++)n.push(new u(0,0,0,0));return t.GetPlanesToRef(i,n),n},t.GetPlanesToRef=function(t,i){i[0].normal.x=t.m[3]+t.m[2],i[0].normal.y=t.m[7]+t.m[6],i[0].normal.z=t.m[11]+t.m[10],i[0].d=t.m[15]+t.m[14],i[0].normalize(),i[1].normal.x=t.m[3]-t.m[2],i[1].normal.y=t.m[7]-t.m[6],i[1].normal.z=t.m[11]-t.m[10],i[1].d=t.m[15]-t.m[14],i[1].normalize(),i[2].normal.x=t.m[3]+t.m[0],i[2].normal.y=t.m[7]+t.m[4],i[2].normal.z=t.m[11]+t.m[8],i[2].d=t.m[15]+t.m[12],i[2].normalize(),i[3].normal.x=t.m[3]-t.m[0],i[3].normal.y=t.m[7]-t.m[4],i[3].normal.z=t.m[11]-t.m[8],i[3].d=t.m[15]-t.m[12],i[3].normalize(),i[4].normal.x=t.m[3]-t.m[1],i[4].normal.y=t.m[7]-t.m[5],i[4].normal.z=t.m[11]-t.m[9],i[4].d=t.m[15]-t.m[13],i[4].normalize(),i[5].normal.x=t.m[3]+t.m[1],i[5].normal.y=t.m[7]+t.m[5],i[5].normal.z=t.m[11]+t.m[9],i[5].d=t.m[15]+t.m[13],i[5].normalize()},t}();t.Frustum=y,function(t){t[t.LOCAL=0]="LOCAL",t[t.WORLD=1]="WORLD"}(t.Space||(t.Space={}));var c=(t.Space,function(){function t(){}return t.X=new s(1,0,0),t.Y=new s(0,1,0),t.Z=new s(0,0,1),t}());t.Axis=c;var p=function(){function t(){}return t.interpolate=function(t,i,n,r,o){for(var s=1-3*r+3*i,e=3*r-6*i,h=3*i,a=t,u=0;5>u;u++){var m=a*a,y=m*a,c=s*y+e*m+h*a,p=1/(3*s*m+2*e*a+h);a-=(c-t)*p,a=Math.min(1,Math.max(0,a))}return 3*Math.pow(1-a,2)*a*n+3*(1-a)*Math.pow(a,2)*o+Math.pow(a,3)},t}();t.BezierCurve=p,function(t){t[t.CW=0]="CW",t[t.CCW=1]="CCW"}(t.Orientation||(t.Orientation={}));var f=t.Orientation,l=function(){function t(t){var i=this;this.degrees=function(){return 180*i._radians/Math.PI},this.radians=function(){return i._radians},this._radians=t,this._radians<0&&(this._radians+=2*Math.PI)}return t.BetweenTwoPoints=function(i,n){var r=n.subtract(i),o=Math.atan2(r.y,r.x);return new t(o)},t.FromRadians=function(i){return new t(i)},t.FromDegrees=function(i){return new t(i*Math.PI/180)},t}();t.Angle=l;var x=function(){function t(t,i,n){this.startPoint=t,this.midPoint=i,this.endPoint=n;var r=Math.pow(i.x,2)+Math.pow(i.y,2),s=(Math.pow(t.x,2)+Math.pow(t.y,2)-r)/2,e=(r-Math.pow(n.x,2)-Math.pow(n.y,2))/2,h=(t.x-i.x)*(i.y-n.y)-(i.x-n.x)*(t.y-i.y);this.centerPoint=new o((s*(i.y-n.y)-e*(t.y-i.y))/h,((t.x-i.x)*e-(i.x-n.x)*s)/h),this.radius=this.centerPoint.subtract(this.startPoint).length(),this.startAngle=l.BetweenTwoPoints(this.centerPoint,this.startPoint);var a=this.startAngle.degrees(),u=l.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),m=l.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();u-a>180&&(u-=360),-180>u-a&&(u+=360),m-u>180&&(m-=360),-180>m-u&&(m+=360),this.orientation=0>u-a?f.CW:f.CCW,this.angle=l.FromDegrees(this.orientation===f.CW?a-m:m-a)}return t}();t.Arc2=x;var z=function(){function t(t,i){this._points=new Array,this._length=0,this.closed=!1,this._points.push(new o(t,i))}return t.prototype.addLineTo=function(t,i){if(closed)return this;var n=new o(t,i),r=this._points[this._points.length-1];return this._points.push(n),this._length+=n.subtract(r).length(),this},t.prototype.addArcTo=function(t,i,n,r,s){if(void 0===s&&(s=36),closed)return this;var e=this._points[this._points.length-1],h=new o(t,i),a=new o(n,r),u=new x(e,h,a),m=u.angle.radians()/s;u.orientation===f.CW&&(m*=-1);for(var y=u.startAngle.radians()+m,c=0;s>c;c++){var p=Math.cos(y)*u.radius+u.centerPoint.x,l=Math.sin(y)*u.radius+u.centerPoint.y;this.addLineTo(p,l),y+=m}return this},t.prototype.close=function(){return this.closed=!0,this},t.prototype.length=function(){var t=this._length;if(!this.closed){var i=this._points[this._points.length-1],n=this._points[0];t+=n.subtract(i).length()}return t},t.prototype.getPoints=function(){return this._points},t.prototype.getPointAtLengthPosition=function(t){if(0>t||t>1)return o.Zero();for(var i=t*this.length(),n=0,r=0;r<this._points.length;r++){var s=(r+1)%this._points.length,e=this._points[r],h=this._points[s],a=h.subtract(e),u=a.length()+n;if(i>=n&&u>=i){var m=a.normalize(),y=i-n;return new o(e.x+m.x*y,e.y+m.y*y)}n=u}return o.Zero()},t.StartingAt=function(i,n){return new t(i,n)},t}();t.Path2=z;var w=function(){function n(t,i,n){this.path=t,this._curve=new Array,this._distances=new Array,this._tangents=new Array,this._normals=new Array,this._binormals=new Array;for(var r=0;r<t.length;r++)this._curve[r]=t[r].clone();this._raw=n||!1,this._compute(i)}return n.prototype.getCurve=function(){return this._curve},n.prototype.getTangents=function(){return this._tangents},n.prototype.getNormals=function(){return this._normals},n.prototype.getBinormals=function(){return this._binormals},n.prototype.getDistances=function(){return this._distances},n.prototype.update=function(t,i){for(var n=0;n<t.length;n++)this._curve[n].x=t[n].x,this._curve[n].y=t[n].y,this._curve[n].z=t[n].z;return this._compute(i),this},n.prototype._compute=function(t){var i=this._curve.length;this._tangents[0]=this._getFirstNonNullVector(0),this._raw||this._tangents[0].normalize(),this._tangents[i-1]=this._curve[i-1].subtract(this._curve[i-2]),this._raw||this._tangents[i-1].normalize();var n=this._tangents[0],r=this._normalVector(this._curve[0],n,t);this._normals[0]=r,this._raw||this._normals[0].normalize(),this._binormals[0]=s.Cross(n,this._normals[0]),this._raw||this._binormals[0].normalize(),this._distances[0]=0;for(var o,e,h,a,u=1;i>u;u++)o=this._getLastNonNullVector(u),i-1>u&&(e=this._getFirstNonNullVector(u),this._tangents[u]=o.add(e),this._tangents[u].normalize()),this._distances[u]=this._distances[u-1]+o.length(),h=this._tangents[u],a=this._binormals[u-1],this._normals[u]=s.Cross(a,h),this._raw||this._normals[u].normalize(),this._binormals[u]=s.Cross(h,this._normals[u]),this._raw||this._binormals[u].normalize()},n.prototype._getFirstNonNullVector=function(t){for(var i=1,n=this._curve[t+i].subtract(this._curve[t]);0===n.length()&&t+i+1<this._curve.length;)i++,n=this._curve[t+i].subtract(this._curve[t]);return n},n.prototype._getLastNonNullVector=function(t){for(var i=1,n=this._curve[t].subtract(this._curve[t-i]);0===n.length()&&t>i+1;)i++,n=this._curve[t].subtract(this._curve[t-i]);return n},n.prototype._normalVector=function(n,r,o){var e;if(void 0===o||null===o){var h;i.WithinEpsilon(r.y,1,t.Epsilon)?i.WithinEpsilon(r.x,1,t.Epsilon)?i.WithinEpsilon(r.z,1,t.Epsilon)||(h=new s(0,0,1)):h=new s(1,0,0):h=new s(0,-1,0),e=s.Cross(r,h)}else e=s.Cross(r,o),s.CrossToRef(e,r,e);return e.normalize(),e},n}();t.Path3D=w;var v=function(){function t(t){this._length=0,this._points=t,this._length=this._computeLength(t)}return t.CreateQuadraticBezier=function(i,n,r,o){o=o>2?o:3;for(var e=new Array,h=function(t,i,n,r){var o=(1-t)*(1-t)*i+2*t*(1-t)*n+t*t*r;return o},a=0;o>=a;a++)e.push(new s(h(a/o,i.x,n.x,r.x),h(a/o,i.y,n.y,r.y),h(a/o,i.z,n.z,r.z)));return new t(e)},t.CreateCubicBezier=function(i,n,r,o,e){e=e>3?e:4;for(var h=new Array,a=function(t,i,n,r,o){var s=(1-t)*(1-t)*(1-t)*i+3*t*(1-t)*(1-t)*n+3*t*t*(1-t)*r+t*t*t*o;return s},u=0;e>=u;u++)h.push(new s(a(u/e,i.x,n.x,r.x,o.x),a(u/e,i.y,n.y,r.y,o.y),a(u/e,i.z,n.z,r.z,o.z)));return new t(h)},t.CreateHermiteSpline=function(i,n,r,o,e){for(var h=new Array,a=1/e,u=0;e>=u;u++)h.push(s.Hermite(i,n,r,o,u*a));return new t(h)},t.prototype.getPoints=function(){return this._points},t.prototype.length=function(){return this._length},t.prototype["continue"]=function(i){for(var n=this._points[this._points.length-1],r=this._points.slice(),o=i.getPoints(),s=1;s<o.length;s++)r.push(o[s].subtract(o[0]).add(n));var e=new t(r);return e},t.prototype._computeLength=function(t){for(var i=0,n=1;n<t.length;n++)i+=t[n].subtract(t[n-1]).length();return i},t}();t.Curve3=v;var d=function(){function t(){this.L00=s.Zero(),this.L1_1=s.Zero(),this.L10=s.Zero(),this.L11=s.Zero(),this.L2_2=s.Zero(),this.L2_1=s.Zero(),this.L20=s.Zero(),this.L21=s.Zero(),this.L22=s.Zero()}return t.prototype.addLight=function(t,i,n){var r=new s(i.r,i.g,i.b),o=r.scale(n);this.L00=this.L00.add(o.scale(.282095)),this.L1_1=this.L1_1.add(o.scale(.488603*t.y)),this.L10=this.L10.add(o.scale(.488603*t.z)),this.L11=this.L11.add(o.scale(.488603*t.x)),this.L2_2=this.L2_2.add(o.scale(1.092548*t.x*t.y)),this.L2_1=this.L2_1.add(o.scale(1.092548*t.y*t.z)),this.L21=this.L21.add(o.scale(1.092548*t.x*t.z)),this.L20=this.L20.add(o.scale(.315392*(3*t.z*t.z-1))),this.L22=this.L22.add(o.scale(.546274*(t.x*t.x-t.y*t.y)))},t.prototype.scale=function(t){this.L00=this.L00.scale(t),this.L1_1=this.L1_1.scale(t),this.L10=this.L10.scale(t),this.L11=this.L11.scale(t),this.L2_2=this.L2_2.scale(t),this.L2_1=this.L2_1.scale(t),this.L20=this.L20.scale(t),this.L21=this.L21.scale(t),this.L22=this.L22.scale(t)},t}();t.SphericalHarmonics=d;var g=function(){function t(){this.x=s.Zero(),this.y=s.Zero(),this.z=s.Zero(),this.xx=s.Zero(),this.yy=s.Zero(),this.zz=s.Zero(),this.xy=s.Zero(),this.yz=s.Zero(),this.zx=s.Zero()}return t.prototype.addAmbient=function(t){var i=new s(t.r,t.g,t.b);this.xx=this.xx.add(i),this.yy=this.yy.add(i),this.zz=this.zz.add(i)},t.getSphericalPolynomialFromHarmonics=function(i){var n=new t;return n.x=i.L11.scale(1.02333),n.y=i.L1_1.scale(1.02333),n.z=i.L10.scale(1.02333),n.xx=i.L00.scale(.886277).subtract(i.L20.scale(.247708)).add(i.L22.scale(.429043)),n.yy=i.L00.scale(.886277).subtract(i.L20.scale(.247708)).subtract(i.L22.scale(.429043)),n.zz=i.L00.scale(.886277).add(i.L20.scale(.495417)),n.yz=i.L2_1.scale(.858086),n.zx=i.L21.scale(.858086),n.xy=i.L2_2.scale(.858086),n},t}();t.SphericalPolynomial=g;var T=function(){function t(t,i){void 0===t&&(t=s.Zero()),void 0===i&&(i=s.Up()),this.position=t,this.normal=i}return t.prototype.clone=function(){return new t(this.position.clone(),this.normal.clone())},t}();t.PositionNormalVertex=T;var R=function(){function t(t,i,n){void 0===t&&(t=s.Zero()),void 0===i&&(i=s.Up()),void 0===n&&(n=o.Zero()),this.position=t,this.normal=i,this.uv=n}return t.prototype.clone=function(){return new t(this.position.clone(),this.normal.clone(),this.uv.clone())},t}();t.PositionNormalTextureVertex=R;var _=function(){function t(){}return t.Color3=[n.Black(),n.Black(),n.Black()],t.Vector2=[o.Zero(),o.Zero(),o.Zero()],t.Vector3=[s.Zero(),s.Zero(),s.Zero(),s.Zero(),s.Zero(),s.Zero(),s.Zero(),s.Zero(),s.Zero()],t.Vector4=[e.Zero(),e.Zero(),e.Zero()],t.Quaternion=[new h(0,0,0,0)],t.Matrix=[a.Zero(),a.Zero(),a.Zero(),a.Zero(),a.Zero(),a.Zero(),a.Zero(),a.Zero()],t}();t.Tmp=_}(BABYLON||(BABYLON={}));',
  34. ("undefined"!=typeof window&&window.module||"undefined"!=typeof module)&&"undefined"!=typeof module.exports&&(module.exports=BABYLON);