12345678910111213141516171819202122232425 |
- 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,g=0,_=0,v=0,y=-1,x=0,b=T.Vector3[0],E=0,A=T.Vector3[1];t.WithinEpsilon(h.z,0,e.Epsilon)?_=1:t.WithinEpsilon(h.x,0,e.Epsilon)?m=1:(v=h.z/h.x,m=-v*Math.sqrt(1/(1+v*v)),_=Math.sqrt(1/(1+v*v))),A.x=m,A.y=g,A.z=_,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 M=T.Vector3[2],P=T.Vector3[3];m=0,g=0,_=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)),_=Math.sqrt(1/(1+v*v))),M.x=m,M.y=g,M.z=_,M.normalize(),i.CrossToRef(M,A,P),P.normalize(),i.CrossToRef(h,M,b),b.normalize(),i.Dot(A,b)<0&&(y=1),E=i.Dot(h,M),E=Math.min(1,Math.max(-1,E)),f=Math.acos(E)*y,i.Dot(P,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],g=this.m[15],_=u*g-d*m,v=l*g-d*p,y=l*m-u*p,x=c*g-d*f,b=c*m-u*f,E=c*p-l*f,A=s*_-a*v+h*y,T=-(o*_-a*x+h*b),M=o*v-s*x+h*E,P=-(o*y-s*b+a*E),C=1/(t*A+i*T+n*M+r*P),S=a*g-h*m,R=s*g-h*p,I=s*m-a*p,D=o*g-h*f,O=o*m-a*f,L=o*p-s*f,w=a*d-h*u,B=s*d-h*l,V=s*u-a*l,F=o*d-h*c,N=o*u-a*c,U=o*l-s*c;return e.m[0]=A*C,e.m[4]=T*C,e.m[8]=M*C,e.m[12]=P*C,e.m[1]=-(i*_-n*v+r*y)*C,e.m[5]=(t*_-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*L)*C,e.m[14]=-(t*I-i*O+n*L)*C,e.m[3]=-(i*w-n*B+r*V)*C,e.m[7]=(t*w-n*F+r*N)*C,e.m[11]=-(t*B-i*F+r*U)*C,e.m[15]=(t*V-i*N+n*U)*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],g=this.m[13],_=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],M=e.m[6],P=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],L=e.m[14],w=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*M+o*R+s*L,t[i+3]=n*E+r*P+o*I+s*w,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*M+c*R+l*L,t[i+7]=a*E+h*P+c*I+l*w,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*M+f*R+p*L,t[i+11]=u*E+d*P+f*I+p*w,t[i+12]=m*y+g*A+_*C+v*D,t[i+13]=m*x+g*T+_*S+v*O,t[i+14]=m*b+g*M+_*R+v*L,t[i+15]=m*E+g*P+_*I+v*w,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,g){g.m[0]=e,g.m[1]=t,g.m[2]=i,g.m[3]=n,g.m[4]=r,g.m[5]=o,g.m[6]=s,g.m[7]=a,g.m[8]=h,g.m[9]=c,g.m[10]=l,g.m[11]=u,g.m[12]=d,g.m[13]=f,g.m[14]=p,g.m[15]=m},e.FromValues=function(t,i,n,r,o,s,a,h,c,l,u,d,f,p,m,g){var _=new e;return _.m[0]=t,_.m[1]=i,_.m[2]=n,_.m[3]=r,_.m[4]=o,_.m[5]=s,_.m[6]=a,_.m[7]=h,_.m[8]=c,_.m[9]=l,_.m[10]=u,_.m[11]=d,_.m[12]=f,_.m[13]=p,_.m[14]=m,_.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(){
- 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 g=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=g;var _=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 g(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=_;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>_;)if(p=n[r++],m=(127&p)+1,128&p){for(g=0;d>g;++g)v[g]=n[r++];for(g=0;m>g;++g)l.set(v,_+g*d);_+=d*m}else{for(m*=d,g=0;m>g;++g)l[_+g]=n[r++];_+=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 M="_getImageData"+(c?"Grey":"")+o.pixel_size+"bits",P=t[M](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,P)},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,g=0,_=new Uint8Array(p*m*4);for(u=n;u!==o;u+=r)for(l=s;l!==h;l+=a,g++)c=d[g],_[4*(l+p*u)+3]=255,_[4*(l+p*u)+2]=f[3*c+0],_[4*(l+p*u)+1]=f[3*c+1],_[4*(l+p*u)+0]=f[3*c+2];return _},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,g=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),g[4*(l+f*u)+0]=(31744&c)>>7,g[4*(l+f*u)+1]=(992&c)>>2,g[4*(l+f*u)+2]=(31&c)>>3,g[4*(l+f*u)+3]=32768&c?0:255;return g},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,g=new Uint8Array(f*p*4);for(u=n;u!==o;u+=r)for(l=s;l!==h;l+=a,m++)c=d[m],g[4*(l+f*u)+0]=c,g[4*(l+f*u)+1]=c,g[4*(l+f*u)+2]=c,g[4*(l+f*u)+3]=255;return g},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){
- 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),g=m.data;g.set(a),p.putImageData(m,0,0);var _=t.toDataURL();if(r)r(_);else if("download"in document.createElement("a")){var v=window.document.createElement("a");v.href=_;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=_,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 g=n(d,!h,i);i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,g.mag),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,g.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",{
- 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,g=".tga"===u;o._addPendingData(d),d.url=t,d.noMipmap=i,d.references=1,d.samplingMode=s,this._loadedTexturesCache.push(d);var _,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?_(c):e.Tools.LoadFile(t,function(e){_(e)},v,o.database,!0);else if(m)_=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?_(c):e.Tools.LoadFile(t,function(e){_(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 g=l.createFramebuffer();return l.bindFramebuffer(l.FRAMEBUFFER,g),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=g,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,g=m,_=e.Tools.IsExponentOfTwo(m)&&e.Tools.IsExponentOfTwo(g);d._width=m,d._height=g;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&&_)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,g,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);
- }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),g=e.Vector3.Dot(l,d),_=e.Vector3.Dot(u,d),v=f*m-p*p,y=v,x=v;v<t.smallnum?(s=0,y=1,h=_,x=m):(s=p*_-m*g,h=f*_-p*g,0>s?(s=0,h=_,x=m):s>y&&(s=y,h=_+p,x=m)),0>h?(h=0,0>-g?s=0:-g>f?s=y:(s=-g,y=f)):h>x&&(h=x,0>-g+p?s=0:-g+p>f?s=y:(s=-g+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){
- 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),g=f.add(m);return n.hit=!0,n.distance=e.Vector3.Distance(f,g),n.pickedPoint=g,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",{
- 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,g=1;if(c||(this.basePoint.subtractToRef(l.normal,this._planeIntersectionPoint),this.velocity.scaleToRef(h,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,r,o,s,l.normal)&&(m=!0,g=h,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!m){var _=this.velocity.lengthSquared(),v=_;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,g);b.found&&(g=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,g),b.found&&(g=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,g),b.found&&(g=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*-_+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,g),b.found){var M=(A*b.root-T)/E;M>=0&&1>=M&&(g=b.root,m=!0,this._edge.scaleInPlace(M),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*-_+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,g),b.found&&(M=(A*b.root-T)/E,M>=0&&1>=M&&(g=b.root,m=!0,this._edge.scaleInPlace(M),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*-_+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,g),b.found&&(M=(A*b.root-T)/E,M>=0&&1>=M&&(g=b.root,m=!0,this._edge.scaleInPlace(M),s.addToRef(this._edge,this._collisionPoint)))}if(m){var P=g*this.velocity.length();(!this.collisionFound||P<this.nearestDistance)&&(this.intersectionPoint?this.intersectionPoint.copyFrom(this._collisionPoint):this.intersectionPoint=this._collisionPoint.clone(),this.nearestDistance=P,this.collisionFound=!0)}}},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);
- };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),
- 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)),
- 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 g=0;g<this.lensFlareSystems.length;g++){var _=this.lensFlareSystems[g];0!==(t.layerMask&_.layerMask)&&_.render()}e.Tools.EndPerformanceCounter("Lens flares",this.lensFlareSystems.length>0)}if(this.layers.length){for(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());
- }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 g=0;g<this._toBeDisposed.length;g++)this._toBeDisposed.data[g].dispose(),this._toBeDisposed[g]=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"),g=n.getAttributeLocationByName("world3"),_=[f,p,m,g];r.updateAndBindInstancesBuffer(this._worldMatricesInstancesBuffer,this._worldMatricesInstancesArray,_),this._draw(e,t,c),r.unBindInstancesBuffer(this._worldMatricesInstancesBuffer,_)},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;
- },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),g=t[m]/255,_=t[m+1]/255,v=t[m+2]/255,y=.3*g+.59*_+.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(_,3*c),y=e.Vector3.FromArray(_,3*(c+1)),x=e.Vector3.FromArray(_,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++)g.push(A.x),g.push(A.y),g.push(A.z)}for(this.setIndices(u),this.setVerticesData(e.VertexBuffer.NormalKind,g,a),t=0;t<n.length;t++)i=n[t],this.setVerticesData(i,s[i],r[i].isUpdatable());this.releaseSubMeshes();for(var M=0;M<l.length;M++){var P=l[M];new e.SubMesh(P.materialIndex,P.indexStart,P.indexCount,P.indexStart,P.indexCount,this)}this.synchronizeInstances()},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 g=c[m];new e.SubMesh(g.materialIndex,g.indexStart,g.indexCount,g.indexStart,g.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 g;for(r=0;4>r&&(g=s[p+r],g>0);r++)e.Matrix.FromFloat32ArrayToRefScaled(l,16*o[p+r],g,f),d.addToSelf(f);if(a)for(r=0;4>r&&(g=c[p+r],g>0);r++)e.Matrix.FromFloat32ArrayToRefScaled(l,16*h[p+r],g,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,g=0;g<r.length;g++)p=3*h._idx[g],m=g+1<r.length?3*(h._idx[g+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 _=new e.Mesh(t,n);_.sideOrientation=a;var v=e.VertexData.CreateRibbon(i);return s&&(_._idx=v._idx),_._closePath=s,_._closeArray=o,v.applyToMesh(_,c),_},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,g=0,_=0,v=p/l*s,y=new Array;for(g=0;l>=g;g++){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(g*v)*h[0].x*c,h[0].y,Math.sin(g*v)*h[0].x*c))),_=0;_<h.length;_++)o=new e.Vector3(Math.cos(g*v)*h[_].x*c,h[_].y,Math.sin(g*v)*h[_].x*c),y.push(o);f!=e.Mesh.CAP_END&&f!=e.Mesh.CAP_ALL||(y.push(new e.Vector3(Math.cos(g*v)*h[h.length-1].x*c,h[h.length-1].y,Math.sin(g*v)*h[h.length-1].x*c)),y.push(new e.Vector3(0,h[h.length-1].y,0))),m.push(y)}var x=t.CreateRibbon(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(),g=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],_*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 g=n.arc||d.arc;return f=d.path3D.update(o),p=m(o,f,d.pathArray,s,d.tessellation,h,d.cap,g),d=t.CreateRibbon(null,{pathArray:p,instance:d}),d.path3D=f,d.pathArray=p,d.arc=g,d}f=new e.Path3D(o);var _=new Array;c=0>c||c>3?0:c,p=m(o,f,_,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),g=Math.atan2(h.y,m),_=e.Matrix.RotationYawPitchRoll(p,g,l).multiply(e.Matrix.Translation(a.x,a.y,a.z)),v=e.Matrix.Invert(_),y=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,g=e.Vector3.Dot(t[s].position,i)-n,_=e.Vector3.Dot(t[s+1].position,i)-n,v=e.Vector3.Dot(t[s+2].position,i)-n;switch(a=g>0,h=_>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},M=0;M<r.length;M+=3){var P=new Array;if(P.push(A(M)),P.push(A(M+1)),P.push(A(M+2)),P=T(P,new e.Vector3(1,0,0)),P=T(P,new e.Vector3(-1,0,0)),P=T(P,new e.Vector3(0,1,0)),P=T(P,new e.Vector3(0,-1,0)),P=T(P,new e.Vector3(0,0,1)),P=T(P,new e.Vector3(0,0,-1)),0!==P.length)for(var C=0;C<P.length;C++){var S=P[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),
- 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(g,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,g=function(){return o},_=function(){return s},v=l?h:_,y=l?a:g,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]),M=y(E,p[E]),P=0;P<t.length;P++){e.Matrix.RotationAxisToRef(u[E],m,b);var C=u[E].scale(t[P].z).add(d[E].scale(t[P].x)).add(f[E].scale(t[P].y)),S=A[P]?A[P]:e.Vector3.Zero();e.Vector3.TransformCoordinatesToRef(C,b,S),S.scaleInPlace(M).addInPlace(i[E]),A[P]=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 g=m.path3D.update(n),_=v(i,n,m.path3D,m.pathArray,r,o,s,a,m.cap,u),m=e.Mesh.CreateRibbon(null,_,null,null,null,null,null,null,m);g=new e.Path3D(n);var y=new Array;l=0>l||l>3?0:l,_=v(i,n,g,y,r,o,s,a,l,u);var x=e.Mesh.CreateRibbon(t,_,h,c,0,d,f,p);return x.pathArray=_,x.path3D=g,x.cap=l,x},t}();e.MeshBuilder=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.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,
- 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),
- 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!==_.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 M=0,P=T.materials.length;P>M;M++){var C=T.materials[M];_.push(C);var S=i(C,d,o,a);u+="\n Material "+S.toString(m)}_.push(T.id);var R=e.Material.ParseMultiMaterial(T,o);b=!0,u+="\n Multi-Material "+R.toString(m);break}}if(!b){_.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=g.indexOf(y.skeletonId)>-1;if(!I)for(var D=0,O=d.skeletons.length;O>D;D++){var L=d.skeletons[D];if(L.id===y.skeletonId){var w=e.Skeleton.Parse(L,o);l.push(w),g.push(L.id),u+="\n Skeleton "+w.toString(m)}}}var B=e.Mesh.Parse(y,o,a);h.push(B),u+="\n Mesh "+B.toString(m)}}var V;for(f=0,p=o.meshes.length;p>f;f++)V=o.meshes[f],V._waitingParentId&&(V.parent=o.getLastEntryByID(V._waitingParentId),V._waitingParentId=void 0);for(f=0,p=o.meshes.length;p>f;f++)V=o.meshes[f],V._waitingFreezeWorldMatrix?(V.freezeWorldMatrix(),V._waitingFreezeWorldMatrix=void 0):V.computeWorldMatrix(!0);if(d.particleSystems)for(f=0,p=d.particleSystems.length;p>f;f++){var F=d.particleSystems[f];-1!==v.indexOf(F.emitterId)&&c.push(e.ParticleSystem.Parse(F,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 g=s.materials[l],_=e.Material.Parse(g,t,n);o+=0===l?"\n Materials:":"",o+="\n "+_.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 M=E.spheres;if(M)for(l=0,u=M.length;u>l;l++){var P=M[l];e.Geometry.Primitives.Sphere.Parse(P,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 L=E.planes;if(L)for(l=0,u=L.length;u>l;l++){var w=L[l];e.Geometry.Primitives.Plane.Parse(w,t)}var B=E.torusKnots;if(B)for(l=0,u=B.length;u>l;l++){var V=B[l];e.Geometry.Primitives.TorusKnot.Parse(V,t)}var F=E.vertexData;if(F)for(l=0,u=F.length;u>l;l++){var N=F[l];e.Geometry.Parse(N,t,n)}}for(l=0,u=s.meshes.length;u>l;l++){var U=s.meshes[l],k=e.Mesh.Parse(U,t,n);o+=0===l?"\n Meshes:":"",o+="\n "+k.toString(a)}for(l=0,u=s.cameras.length;u>l;l++){var z=s.cameras[l],W=e.Camera.Parse(z,t);o+=0===l?"\n Cameras:":"",o+="\n "+W.toString(a)}for(s.activeCameraID&&t.setActiveCameraByID(s.activeCameraID),l=0,u=t.cameras.length;u>l;l++){var W=t.cameras[l];W._waitingParentId&&(W.parent=t.getLastEntryByID(W._waitingParentId),W._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 G,Y=[];if(e.AudioEngine&&s.sounds)for(l=0,u=s.sounds.length;u>l;l++){var K=s.sounds[l];if(e.Engine.audioEngine.canUseWebAudio)K.url||(K.url=K.name),Y[K.url]?e.Sound.Parse(K,t,n,Y[K.url]):(G=e.Sound.Parse(K,t,n),Y[K.url]=G);else{new e.Sound(K.name,null,t)}}for(Y=[],l=0,u=t.meshes.length;u>l;l++){var k=t.meshes[l];k._waitingParentId&&(k.parent=t.getLastEntryByID(k._waitingParentId),k._waitingParentId=void 0),k._waitingActions&&(e.ActionManager.Parse(k._waitingActions,k,t),k._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 H=s.particleSystems[l];e.ParticleSystem.Parse(H,t,n)}if(s.lensFlareSystems)for(l=0,u=s.lensFlareSystems.length;u>l;l++){var j=s.lensFlareSystems[l];e.LensFlareSystem.Parse(j,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,
- 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),g=this._interpolate(r,0,i.ANIMATIONLOOPMODE_CYCLE);switch(this.dataType){case i.ANIMATIONTYPE_FLOAT:this._offsetsCache[p]=g-m;break;case i.ANIMATIONTYPE_QUATERNION:this._offsetsCache[p]=g.subtract(m);break;case i.ANIMATIONTYPE_VECTOR3:this._offsetsCache[p]=g.subtract(m);case i.ANIMATIONTYPE_VECTOR2:this._offsetsCache[p]=g.subtract(m);case i.ANIMATIONTYPE_COLOR3:this._offsetsCache[p]=g.subtract(m)}this._highLimitsCache[p]=g}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 _=d/u>>0,v=h?n+d%u:r,y=this._interpolate(v,_,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,g=d?new e.Quaternion:null,_=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,_),_.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"),
- 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 M,P,C=0,S=o?1:0;h=n[0].length;var R,I;for(c=0;c<n.length;c++){for(y[c]=0,_[c]=[0],M=n[c],P=M.length,h=P>h?h:P,u=0;P>u;)f.push(M[u].x,M[u].y,M[u].z),u>0&&(R=M[u].subtract(M[u-1]).length(),I=R+y[c],_[c].push(I),y[c]=I),u++;o&&(u--,f.push(M[0].x,M[0].y,M[0].z),R=M[u].subtract(M[0]).length(),I=R+y[c],_[c].push(I),y[c]=I),b[c]=P+S,E[c]=C,C+=P+S}var D,O,L,w;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?(L=D[0],w=O[0]):(L=D[l],w=O[l]),R=w.subtract(L).length(),I=R+x[l],v[l].push(I),x[l]=I;r&&(D=n[c],O=n[0],l===h&&(w=O[0]),R=w.subtract(L).length(),I=R+x[l],x[l]=I)}var B,V;for(c=0;c<n.length;c++)for(l=0;h+S>l;l++)B=_[c][l]/y[c],V=v[l][c]/x[l],g.push(B,V);c=0;for(var F=0,N=b[c]-1,U=b[c+1]-1,k=U>N?N:U,z=E[1]-E[0],W=r?b.length:b.length-1;k>=F&&W>c;)p.push(F,F+z,F+1),p.push(F+z+1,F+1,F+z),F+=1,F===k&&(c++,c===b.length-1?(z=E[0]-E[c],N=b[c]-1,U=b[0]-1):(z=E[c+1]-E[c],N=b[c]-1,U=b[c+1]-1),F=E[c],k=U>N?N+F:U+F);if(t.ComputeNormals(f,p,m),o){var G=0,Y=0;for(c=0;c<n.length;c++)G=3*E[c],Y=c+1<n.length?3*(E[c+1]-1):m.length-3,m[G]=.5*(m[G]+m[Y]),m[G+1]=.5*(m[G+1]+m[Y+1]),m[G+2]=.5*(m[G+2]+m[Y+2]),m[Y]=m[G],m[Y+1]=m[G+1],m[Y+2]=m[G+2]}t._ComputeSides(d,f,p,m,g);var K=new t;return K.indices=p,K.positions=f,K.normals=m,K.uvs=g,o&&(K._idx=E),K},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 g=new e.Vector3(h/2,c/2,l/2),_=0;_<n.length;_++){var v=n[_],y=new e.Vector3(v.y,v.z,v.x),x=e.Vector3.Cross(v,y),b=o.length/3;
- 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(g);o.push(E.x,E.y,E.z),s.push(v.x,v.y,v.z),a.push(d[_].z,d[_].w),f&&p.push(f[_].r,f[_].g,f[_].b,f[_].a),E=v.subtract(y).add(x).multiply(g),o.push(E.x,E.y,E.z),s.push(v.x,v.y,v.z),a.push(d[_].x,d[_].w),f&&p.push(f[_].r,f[_].g,f[_].b,f[_].a),E=v.add(y).add(x).multiply(g),o.push(E.x,E.y,E.z),s.push(v.x,v.y,v.z),a.push(d[_].x,d[_].y),f&&p.push(f[_].r,f[_].g,f[_].b,f[_].a),E=v.add(y).subtract(x).multiply(g),o.push(E.x,E.y,E.z),s.push(v.x,v.y,v.z),a.push(d[_].z,d[_].y),f&&p.push(f[_].r,f[_].g,f[_].b,f[_].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>=_;_++){for(var v=_/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),M=e.Vector3.TransformCoordinates(e.Vector3.Up(),A),P=e.Vector3.TransformCoordinates(M,T),C=P.multiply(l),S=P.divide(l).normalize();p.push(C.x,C.y,C.z),m.push(S.x,S.y,S.z),g.push(b,v)}if(_>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,g);var D=new t;return D.indices=f,D.positions=p,D.normals=m,D.uvs=g,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,g=c?h:1,_=2+(1+m)*g;for(n=0;_>n;n++)p&&void 0===p[n]&&(p[n]=new e.Color4(1,1,1,1));for(n=0;_>n;n++)f&&void 0===f[n]&&(f[n]=new e.Vector4(0,0,1,1));var v,y,x,b,E,A,T=[],M=[],P=[],C=[],S=[],R=2*Math.PI*u/a,I=(s-o)/2/r,D=e.Vector3.Zero(),O=e.Vector3.Zero(),L=e.Vector3.Zero(),w=e.Vector3.Zero(),B=e.Vector3.Zero(),V=e.Axis.Y,F=1,N=1,U=0,k=0;for(b=0;h>=b;b++)for(y=b/h,x=(y*(o-s)+s)/2,F=c&&0!==b&&b!==h?2:1,A=0;F>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=P[P.length-3*(a+1)],O.y=P[P.length-3*(a+1)+1],O.z=P[P.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&&(L.copyFrom(D),w.copyFrom(O)),M.push(D.x,D.y,D.z),P.push(O.x,O.y,O.z),k=c?U!==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,k),p&&S.push(p[N].r,p[N].g,p[N].b,p[N].a);1!==u&&l&&(M.push(D.x,D.y,D.z),M.push(0,D.y,0),M.push(0,D.y,0),M.push(L.x,L.y,L.z),e.Vector3.CrossToRef(V,O,B),B.normalize(),P.push(B.x,B.y,B.z,B.x,B.y,B.z),e.Vector3.CrossToRef(w,V,B),B.normalize(),P.push(B.x,B.y,B.z,B.x,B.y,B.z),k=c?U!==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,k),C.push(f[N+1].z,k),k=c?U!==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,k),C.push(f[N+2].z,k),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))),U!==N&&(U=N)}var N,z=1!==u&&l?a+4:a;for(b=0,N=0;h>N;N++){for(E=0;a>E;E++){var W=b*(z+1)+E,G=(b+1)*(z+1)+E,Y=b*(z+1)+(E+1),K=(b+1)*(z+1)+(E+1);T.push(W,G,Y),T.push(K,Y,G)}1!==u&&l&&(T.push(W+2,G+2,Y+2),T.push(K+2,Y+2,G+2),T.push(W+4,G+4,Y+4),T.push(K+4,Y+4,G+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[_-1]:f[0];p&&(l=t?p[_-1]:p[0]);var m=M.length/3,g=t?r/2:-r/2,v=new e.Vector3(0,g,0);M.push(v.x,v.y,v.z),P.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,g,b*i);var E=new e.Vector2(x*y.x+.5,b*y.y+.5);M.push(h.x,h.y,h.z),P.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,M,T,P,C);var H=new t;return H.indices=T,H.positions=M,H.normals=P,H.uvs=C,p&&(H.colors=S),H},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)),g=0;c>=g;g++){var _=1-g/c,v=g*Math.PI*2/c+Math.PI,y=Math.cos(v),x=Math.sin(v),b=new e.Vector3(y,x,0),E=b.scale(h/2),A=new e.Vector2(f,_);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,M=(g+1)%u;n.push(d*u+g),n.push(d*u+M),n.push(T*u+g),n.push(d*u+M),n.push(T*u+M),n.push(T*u+g)}t._ComputeSides(l,r,n,o,s);var P=new t;return P.indices=n,P.positions=r,P.normals=o,P.uvs=s,P},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,g=0;for(g=0;g<s.length-1;g++)s[g+1].subtractToRef(s[g],c),l+=c.length();for(d=l/o,f=n*d/(n+r),g=0;g<s.length-1;g++){s[g+1].subtractToRef(s[g],c),u=Math.floor(c.length()/d),c.normalize();for(var _=0;u>_;_++)p=d*_,a.push(s[g].x+p*c.x,s[g].y+p*c.y,s[g].z+p*c.z),a.push(s[g].x+(p+f)*c.x,s[g].y+(p+f)*c.y,s[g].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),g.push(u.x,u.y,u.z),_.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=g,y.uvs=_,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,g=.3*f+.59*p+.11*m;c.y=i.minHeight+(i.maxHeight-i.minHeight)*g,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 _=new t;return _.indices=o,_.positions=s,_.normals=a,_.uvs=h,_},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),g=(p+1)/2,_=(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],g=138/1024,_=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=[],M=[],P=[],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]*g+v+E[I]*x,m[2*D+1]*_+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 g=e.Vector2.Lerp(R[0],R[2],i/a),_=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),M.push(f.x,f.y,f.z),P.push(v.x,v.y),A.push(C),C++},L=0;a>L;L++)for(var w=0;a>w+L;w++)O(w,L,w+1/3,L+1/3),O(w+1,L,w+1/3,L+1/3),O(w,L+1,w+1/3,L+1/3),a>w+L+1&&(O(w+1,L,w+2/3,L+2/3),O(w+1,L+1,w+2/3,L+2/3),O(w,L+1,w+2/3,L+2/3))}t._ComputeSides(r,T,A,M,P);var B=new t;return B.indices=A,B.positions=T,B.normals=M,B.uvs=P,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],g=m.face.length,_=i.faceUV||new Array(g),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=[],M=[],P=0,C=0,S=[],R=0,I=0;if(y)for(I=0;g>I;I++)v&&void 0===v[I]&&(v[I]=new e.Color4(1,1,1,1)),_&&void 0===_[I]&&(_[I]=new e.Vector4(0,0,1,1));if(y)for(I=0;g>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(P),P++,r=_[I].x+(_[I].z-_[I].x)*(.5+a),o=_[I].y+(_[I].w-_[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&&M.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;g>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=M),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,g=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 _=n%u,v=_/u*2*f*Math.PI,y=g(v),x=g(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,M=T/d*2*Math.PI,P=-l*Math.cos(M),C=l*Math.sin(M);s.push(y.x+P*E.x+C*A.x),s.push(y.y+P*E.y+C*A.y),s.push(y.z+P*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 L=new t;return L.indices=o,L.positions=s,L.normals=a,L.uvs=h,L},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,g=0;for(n=0;n<e.length;n++)i[n]=0;var _=t.length/3;for(n=0;_>n;n++)p=t[3*n],m=t[3*n+1],g=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*g]-e[3*m],h=e[3*g+1]-e[3*m+1],c=e[3*g+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*g]+=l,i[3*g+1]+=u,i[3*g+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 g=i.indices;g&&(r.indices=g),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),
- 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 g=new Array,_=0;_<i.combine.length;_++)h(i.combine[_],t.NothingTrigger,c,l,g);d.push(g)}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 g=new Int32Array(t,s.matricesIndicesAttrDesc.offset,s.matricesIndicesAttrDesc.count);i.setVerticesData(e.VertexBuffer.MatricesIndicesKind,g,!1)}if(s.matricesWeightsAttrDesc&&s.matricesWeightsAttrDesc.count>0){var _=new Float32Array(t,s.matricesWeightsAttrDesc.offset,s.matricesWeightsAttrDesc.count);i.setVerticesData(e.VertexBuffer.MatricesWeightsKind,_,!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],M=y[5*x+4];new e.SubMesh(b,E,A,T,M,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 P=[],x=0;x<t.matricesIndices.length;x++){var C=t.matricesIndices[x];P.push(255&C),P.push((65280&C)>>8),P.push((16711680&C)>>16),P.push(C>>24)}i.setVerticesData(e.VertexBuffer.MatricesIndicesKind,P,!1)}if(t.matricesIndicesExtra)if(t.matricesIndicesExtra._isExpanded)delete t.matricesIndices._isExpanded,i.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,t.matricesIndicesExtra,!1);else{for(var P=[],x=0;x<t.matricesIndicesExtra.length;x++){var C=t.matricesIndicesExtra[x];P.push(255&C),P.push((65280&C)>>8),P.push((16711680&C)>>16),P.push(C>>24)}i.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,P,!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);
- },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,g=0,_=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(),g=-(c.x*i.x+c.y*i.y+c.z*i.z),_=-(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,g),x.facet2.copyFromFloats(l.x,l.y,l.z,_)}},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+" ",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){
- 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={})),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",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}",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}"},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",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"},("undefined"!=typeof window&&window.module||"undefined"!=typeof module)&&"undefined"!=typeof module.exports&&(module.exports=BABYLON);
|