viewer.min.js 2.2 MB

12345678910111213141516171819202122232425262728293031323334
  1. !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("BabylonViewer",[],t):"object"==typeof exports?exports.BabylonViewer=t():e.BabylonViewer=t()}(this,function(){return function(e){function t(r){if(i[r])return i[r].exports;var n=i[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,t),n.l=!0,n.exports}var i={};return t.m=e,t.c=i,t.d=function(e,i,r){t.o(e,i)||Object.defineProperty(e,i,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=14)}([function(e,t,i){(function(t){var r=this&&this.__decorate||function(e,t,i,r){var n,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,r);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(s=(o<3?n(s):o>3?n(t,i,s):n(t,i))||s);return o>3&&s&&Object.defineProperty(t,i,s),s},n=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])};return function(t,i){function r(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}();!function(e){var t=function(){function e(){}return Object.defineProperty(e,"KEYDOWN",{get:function(){return e._KEYDOWN},enumerable:!0,configurable:!0}),Object.defineProperty(e,"KEYUP",{get:function(){return e._KEYUP},enumerable:!0,configurable:!0}),e._KEYDOWN=1,e._KEYUP=2,e}();e.KeyboardEventTypes=t;var i=function(){return function(e,t){this.type=e,this.event=t}}();e.KeyboardInfo=i;var r=function(e){function t(t,i){var r=e.call(this,t,i)||this;return r.skipOnPointerObservable=!1,r}return n(t,e),t}(i);e.KeyboardInfoPre=r}(s||(s={}));!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}),Object.defineProperty(e,"POINTERTAP",{get:function(){return e._POINTERTAP},enumerable:!0,configurable:!0}),Object.defineProperty(e,"POINTERDOUBLETAP",{get:function(){return e._POINTERDOUBLETAP},enumerable:!0,configurable:!0}),e._POINTERDOWN=1,e._POINTERUP=2,e._POINTERMOVE=4,e._POINTERWHEEL=8,e._POINTERPICK=16,e._POINTERTAP=32,e._POINTERDOUBLETAP=64,e}();e.PointerEventTypes=t;var i=function(){return function(e,t){this.type=e,this.event=t}}();e.PointerInfoBase=i;var r=function(t){function i(i,r,n,o){var s=t.call(this,i,r)||this;return s.skipOnPointerObservable=!1,s.localPosition=new e.Vector2(n,o),s}return n(i,t),i}(i);e.PointerInfoPre=r;var o=function(e){function t(t,i,r){var n=e.call(this,t,i)||this;return n.pickInfo=r,n}return n(t,e),t}(i);e.PointerInfo=o}(s||(s={}));!function(e){e.ToGammaSpace=1/2.2,e.ToLinearSpace=2.2,e.Epsilon=.001;var t=function(){function t(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 t.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+"}"},t.prototype.getClassName=function(){return"Color3"},t.prototype.getHashCode=function(){var e=this.r||0;return e=397*e^(this.g||0),e=397*e^(this.b||0)},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,this},t.prototype.toColor4=function(e){return void 0===e&&(e=1),new i(this.r,this.g,this.b,e)},t.prototype.asArray=function(){var e=new Array;return this.toArray(e,0),e},t.prototype.toLuminance=function(){return.3*this.r+.59*this.g+.11*this.b},t.prototype.multiply=function(e){return new t(this.r*e.r,this.g*e.g,this.b*e.b)},t.prototype.multiplyToRef=function(e,t){return t.r=this.r*e.r,t.g=this.g*e.g,t.b=this.b*e.b,this},t.prototype.equals=function(e){return e&&this.r===e.r&&this.g===e.g&&this.b===e.b},t.prototype.equalsFloats=function(e,t,i){return this.r===e&&this.g===t&&this.b===i},t.prototype.scale=function(e){return new t(this.r*e,this.g*e,this.b*e)},t.prototype.scaleToRef=function(e,t){return t.r=this.r*e,t.g=this.g*e,t.b=this.b*e,this},t.prototype.add=function(e){return new t(this.r+e.r,this.g+e.g,this.b+e.b)},t.prototype.addToRef=function(e,t){return t.r=this.r+e.r,t.g=this.g+e.g,t.b=this.b+e.b,this},t.prototype.subtract=function(e){return new t(this.r-e.r,this.g-e.g,this.b-e.b)},t.prototype.subtractToRef=function(e,t){return t.r=this.r-e.r,t.g=this.g-e.g,t.b=this.b-e.b,this},t.prototype.clone=function(){return new t(this.r,this.g,this.b)},t.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this},t.prototype.copyFromFloats=function(e,t,i){return this.r=e,this.g=t,this.b=i,this},t.prototype.set=function(e,t,i){return this.copyFromFloats(e,t,i)},t.prototype.toHexString=function(){var t=255*this.r|0,i=255*this.g|0,r=255*this.b|0;return"#"+e.Scalar.ToHex(t)+e.Scalar.ToHex(i)+e.Scalar.ToHex(r)},t.prototype.toLinearSpace=function(){var e=new t;return this.toLinearSpaceToRef(e),e},t.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},t.prototype.toGammaSpace=function(){var e=new t;return this.toGammaSpaceToRef(e),e},t.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},t.FromHexString=function(e){if("#"!==e.substring(0,1)||7!==e.length)return new t(0,0,0);var i=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),n=parseInt(e.substring(5,7),16);return t.FromInts(i,r,n)},t.FromArray=function(e,i){return void 0===i&&(i=0),new t(e[i],e[i+1],e[i+2])},t.FromInts=function(e,i,r){return new t(e/255,i/255,r/255)},t.Lerp=function(e,i,r){return new t(e.r+(i.r-e.r)*r,e.g+(i.g-e.g)*r,e.b+(i.b-e.b)*r)},t.Red=function(){return new t(1,0,0)},t.Green=function(){return new t(0,1,0)},t.Blue=function(){return new t(0,0,1)},t.Black=function(){return new t(0,0,0)},t.White=function(){return new t(1,1,1)},t.Purple=function(){return new t(.5,0,.5)},t.Magenta=function(){return new t(1,0,1)},t.Yellow=function(){return new t(1,1,0)},t.Gray=function(){return new t(.5,.5,.5)},t.Teal=function(){return new t(0,1,1)},t.Random=function(){return new t(Math.random(),Math.random(),Math.random())},t}();e.Color3=t;var i=function(){function t(e,t,i,r){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=1),this.r=e,this.g=t,this.b=i,this.a=r}return t.prototype.addInPlace=function(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this.a+=e.a,this},t.prototype.asArray=function(){var e=new Array;return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e[t+3]=this.a,this},t.prototype.add=function(e){return new t(this.r+e.r,this.g+e.g,this.b+e.b,this.a+e.a)},t.prototype.subtract=function(e){return new t(this.r-e.r,this.g-e.g,this.b-e.b,this.a-e.a)},t.prototype.subtractToRef=function(e,t){return t.r=this.r-e.r,t.g=this.g-e.g,t.b=this.b-e.b,t.a=this.a-e.a,this},t.prototype.scale=function(e){return new t(this.r*e,this.g*e,this.b*e,this.a*e)},t.prototype.scaleToRef=function(e,t){return t.r=this.r*e,t.g=this.g*e,t.b=this.b*e,t.a=this.a*e,this},t.prototype.multiply=function(e){return new t(this.r*e.r,this.g*e.g,this.b*e.b,this.a*e.a)},t.prototype.multiplyToRef=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,t},t.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+" A:"+this.a+"}"},t.prototype.getClassName=function(){return"Color4"},t.prototype.getHashCode=function(){var e=this.r||0;return e=397*e^(this.g||0),e=397*e^(this.b||0),e=397*e^(this.a||0)},t.prototype.clone=function(){return new t(this.r,this.g,this.b,this.a)},t.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this},t.prototype.copyFromFloats=function(e,t,i,r){return this.r=e,this.g=t,this.b=i,this.a=r,this},t.prototype.set=function(e,t,i,r){return this.copyFromFloats(e,t,i,r)},t.prototype.toHexString=function(){var t=255*this.r|0,i=255*this.g|0,r=255*this.b|0,n=255*this.a|0;return"#"+e.Scalar.ToHex(t)+e.Scalar.ToHex(i)+e.Scalar.ToHex(r)+e.Scalar.ToHex(n)},t.prototype.toLinearSpace=function(){var e=new t;return this.toLinearSpaceToRef(e),e},t.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),t.a=this.a,this},t.prototype.toGammaSpace=function(){var e=new t;return this.toGammaSpaceToRef(e),e},t.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),t.a=this.a,this},t.FromHexString=function(e){if("#"!==e.substring(0,1)||9!==e.length)return new t(0,0,0,0);var i=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),n=parseInt(e.substring(5,7),16),o=parseInt(e.substring(7,9),16);return t.FromInts(i,r,n,o)},t.Lerp=function(e,i,r){var n=new t(0,0,0,0);return t.LerpToRef(e,i,r,n),n},t.LerpToRef=function(e,t,i,r){r.r=e.r+(t.r-e.r)*i,r.g=e.g+(t.g-e.g)*i,r.b=e.b+(t.b-e.b)*i,r.a=e.a+(t.a-e.a)*i},t.FromArray=function(e,i){return void 0===i&&(i=0),new t(e[i],e[i+1],e[i+2],e[i+3])},t.FromInts=function(e,i,r,n){return new t(e/255,i/255,r/255,n/255)},t.CheckColors4=function(e,t){if(e.length===3*t){for(var i=[],r=0;r<e.length;r+=3){var n=r/3*4;i[n]=e[r],i[n+1]=e[r+1],i[n+2]=e[r+2],i[n+3]=1}return i}return e},t}();e.Color4=i;var r=function(){function t(e,t){this.x=e,this.y=t}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}"},t.prototype.getClassName=function(){return"Vector2"},t.prototype.getHashCode=function(){var e=this.x||0;return e=397*e^(this.y||0)},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,this},t.prototype.asArray=function(){var e=new Array;return this.toArray(e,0),e},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this},t.prototype.copyFromFloats=function(e,t){return this.x=e,this.y=t,this},t.prototype.set=function(e,t){return this.copyFromFloats(e,t)},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,this},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this},t.prototype.addVector3=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,this},t.prototype.multiplyByFloats=function(e,i){return new t(this.x*e,this.y*i)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,this},t.prototype.negate=function(){return new t(-this.x,-this.y)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e)},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y},t.prototype.equalsWithEpsilon=function(t,i){return void 0===i&&(i=e.Epsilon),t&&e.Scalar.WithinEpsilon(this.x,t.x,i)&&e.Scalar.WithinEpsilon(this.y,t.y,i)},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},t.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this},t.prototype.clone=function(){return new t(this.x,this.y)},t.Zero=function(){return new t(0,0)},t.One=function(){return new t(1,1)},t.FromArray=function(e,i){return void 0===i&&(i=0),new t(e[i],e[i+1])},t.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1]},t.CatmullRom=function(e,i,r,n,o){var s=o*o,a=o*s;return new t(.5*(2*i.x+(-e.x+r.x)*o+(2*e.x-5*i.x+4*r.x-n.x)*s+(-e.x+3*i.x-3*r.x+n.x)*a),.5*(2*i.y+(-e.y+r.y)*o+(2*e.y-5*i.y+4*r.y-n.y)*s+(-e.y+3*i.y-3*r.y+n.y)*a))},t.Clamp=function(e,i,r){var n=e.x;n=(n=n>r.x?r.x:n)<i.x?i.x:n;var o=e.y;return o=o>r.y?r.y:o,o=o<i.y?i.y:o,new t(n,o)},t.Hermite=function(e,i,r,n,o){var s=o*o,a=o*s,l=2*a-3*s+1,h=-2*a+3*s,u=a-2*s+o,c=a-s;return new t(e.x*l+r.x*h+i.x*u+n.x*c,e.y*l+r.y*h+i.y*u+n.y*c)},t.Lerp=function(e,i,r){return new t(e.x+(i.x-e.x)*r,e.y+(i.y-e.y)*r)},t.Dot=function(e,t){return e.x*t.x+e.y*t.y},t.Normalize=function(e){var t=e.clone();return t.normalize(),t},t.Minimize=function(e,i){return new t(e.x<i.x?e.x:i.x,e.y<i.y?e.y:i.y)},t.Maximize=function(e,i){return new t(e.x>i.x?e.x:i.x,e.y>i.y?e.y:i.y)},t.Transform=function(e,i){var r=t.Zero();return t.TransformToRef(e,i,r),r},t.TransformToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+t.m[12],n=e.x*t.m[1]+e.y*t.m[5]+t.m[13];i.x=r,i.y=n},t.PointInTriangle=function(e,t,i,r){var n=.5*(-i.y*r.x+t.y*(-i.x+r.x)+t.x*(i.y-r.y)+i.x*r.y),o=n<0?-1:1,s=(t.y*r.x-t.x*r.y+(r.y-t.y)*e.x+(t.x-r.x)*e.y)*o,a=(t.x*i.y-t.y*i.x+(t.y-i.y)*e.x+(i.x-t.x)*e.y)*o;return s>0&&a>0&&s+a<2*n*o},t.Distance=function(e,i){return Math.sqrt(t.DistanceSquared(e,i))},t.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y;return i*i+r*r},t.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},t.DistanceOfPointFromSegment=function(e,i,r){var n=t.DistanceSquared(i,r);if(0===n)return t.Distance(e,i);var o=r.subtract(i),s=Math.max(0,Math.min(1,t.Dot(e.subtract(i),o)/n)),a=i.add(o.multiplyByFloats(s,s));return t.Distance(e,a)},t}();e.Vector2=r;var n=function(){function t(e,t,i){this.x=e,this.y=t,this.z=i}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},t.prototype.getClassName=function(){return"Vector3"},t.prototype.getHashCode=function(){var e=this.x||0;return e=397*e^(this.y||0),e=397*e^(this.z||0)},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,this},t.prototype.toQuaternion=function(){var e=new a(0,0,0,1),t=Math.cos(.5*(this.x+this.z)),i=Math.sin(.5*(this.x+this.z)),r=Math.cos(.5*(this.z-this.x)),n=Math.sin(.5*(this.z-this.x)),o=Math.cos(.5*this.y),s=Math.sin(.5*this.y);return e.x=r*s,e.y=-n*s,e.z=i*o,e.w=t*o,e},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,this},t.prototype.subtractFromFloats=function(e,i,r){return new t(this.x-e,this.y-i,this.z-r)},t.prototype.subtractFromFloatsToRef=function(e,t,i,r){return r.x=this.x-e,r.y=this.y-t,r.z=this.z-i,this},t.prototype.negate=function(){return new t(-this.x,-this.y,-this.z)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e)},t.prototype.scaleToRef=function(e,t){return t.x=this.x*e,t.y=this.y*e,t.z=this.z*e,this},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z},t.prototype.equalsWithEpsilon=function(t,i){return void 0===i&&(i=e.Epsilon),t&&e.Scalar.WithinEpsilon(this.x,t.x,i)&&e.Scalar.WithinEpsilon(this.y,t.y,i)&&e.Scalar.WithinEpsilon(this.z,t.z,i)},t.prototype.equalsToFloats=function(e,t,i){return this.x===e&&this.y===t&&this.z===i},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y,this.z*e.z)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,t.z=this.z*e.z,this},t.prototype.multiplyByFloats=function(e,i,r){return new t(this.x*e,this.y*i,this.z*r)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y,this.z/e.z)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,t.z=this.z/e.z,this},t.prototype.MinimizeInPlace=function(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),this},t.prototype.MaximizeInPlace=function(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),this},Object.defineProperty(t.prototype,"isNonUniform",{get:function(){var e=Math.abs(this.x),t=Math.abs(this.y);if(e!==t)return!0;var i=Math.abs(this.z);return e!==i||t!==i},enumerable:!0,configurable:!0}),t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},t.prototype.normalize=function(){var e=this.length();if(0===e||1===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.clone=function(){return new t(this.x,this.y,this.z)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},t.prototype.copyFromFloats=function(e,t,i){return this.x=e,this.y=t,this.z=i,this},t.prototype.set=function(e,t,i){return this.copyFromFloats(e,t,i)},t.GetClipFactor=function(e,i,r,n){var o=t.Dot(e,r)-n;return o/(o-(t.Dot(i,r)-n))},t.FromArray=function(e,i){return i||(i=0),new t(e[i],e[i+1],e[i+2])},t.FromFloatArray=function(e,i){return t.FromArray(e,i)},t.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2]},t.FromFloatArrayToRef=function(e,i,r){return t.FromArrayToRef(e,i,r)},t.FromFloatsToRef=function(e,t,i,r){r.x=e,r.y=t,r.z=i},t.Zero=function(){return new t(0,0,0)},t.One=function(){return new t(1,1,1)},t.Up=function(){return new t(0,1,0)},t.Forward=function(){return new t(0,0,1)},t.Right=function(){return new t(1,0,0)},t.Left=function(){return new t(-1,0,0)},t.TransformCoordinates=function(e,i){var r=t.Zero();return t.TransformCoordinatesToRef(e,i,r),r},t.TransformCoordinatesToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8]+t.m[12],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9]+t.m[13],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=r/s,i.y=n/s,i.z=o/s},t.TransformCoordinatesFromFloatsToRef=function(e,t,i,r,n){var o=e*r.m[0]+t*r.m[4]+i*r.m[8]+r.m[12],s=e*r.m[1]+t*r.m[5]+i*r.m[9]+r.m[13],a=e*r.m[2]+t*r.m[6]+i*r.m[10]+r.m[14],l=e*r.m[3]+t*r.m[7]+i*r.m[11]+r.m[15];n.x=o/l,n.y=s/l,n.z=a/l},t.TransformNormal=function(e,i){var r=t.Zero();return t.TransformNormalToRef(e,i,r),r},t.TransformNormalToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9],o=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10];i.x=r,i.y=n,i.z=o},t.TransformNormalFromFloatsToRef=function(e,t,i,r,n){n.x=e*r.m[0]+t*r.m[4]+i*r.m[8],n.y=e*r.m[1]+t*r.m[5]+i*r.m[9],n.z=e*r.m[2]+t*r.m[6]+i*r.m[10]},t.CatmullRom=function(e,i,r,n,o){var s=o*o,a=o*s;return new t(.5*(2*i.x+(-e.x+r.x)*o+(2*e.x-5*i.x+4*r.x-n.x)*s+(-e.x+3*i.x-3*r.x+n.x)*a),.5*(2*i.y+(-e.y+r.y)*o+(2*e.y-5*i.y+4*r.y-n.y)*s+(-e.y+3*i.y-3*r.y+n.y)*a),.5*(2*i.z+(-e.z+r.z)*o+(2*e.z-5*i.z+4*r.z-n.z)*s+(-e.z+3*i.z-3*r.z+n.z)*a))},t.Clamp=function(e,i,r){var n=e.x;n=(n=n>r.x?r.x:n)<i.x?i.x:n;var o=e.y;o=(o=o>r.y?r.y:o)<i.y?i.y:o;var s=e.z;return s=s>r.z?r.z:s,s=s<i.z?i.z:s,new t(n,o,s)},t.Hermite=function(e,i,r,n,o){var s=o*o,a=o*s,l=2*a-3*s+1,h=-2*a+3*s,u=a-2*s+o,c=a-s;return new t(e.x*l+r.x*h+i.x*u+n.x*c,e.y*l+r.y*h+i.y*u+n.y*c,e.z*l+r.z*h+i.z*u+n.z*c)},t.Lerp=function(e,i,r){var n=new t(0,0,0);return t.LerpToRef(e,i,r,n),n},t.LerpToRef=function(e,t,i,r){r.x=e.x+(t.x-e.x)*i,r.y=e.y+(t.y-e.y)*i,r.z=e.z+(t.z-e.z)*i},t.Dot=function(e,t){return e.x*t.x+e.y*t.y+e.z*t.z},t.Cross=function(e,i){var r=t.Zero();return t.CrossToRef(e,i,r),r},t.CrossToRef=function(e,t,i){E.Vector3[0].x=e.y*t.z-e.z*t.y,E.Vector3[0].y=e.z*t.x-e.x*t.z,E.Vector3[0].z=e.x*t.y-e.y*t.x,i.copyFrom(E.Vector3[0])},t.Normalize=function(e){var i=t.Zero();return t.NormalizeToRef(e,i),i},t.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},t.Project=function(e,i,r,n){var o=n.width,s=n.height,a=n.x,h=n.y,u=t._viewportMatrixCache?t._viewportMatrixCache:t._viewportMatrixCache=new l;l.FromValuesToRef(o/2,0,0,0,0,-s/2,0,0,0,0,.5,0,a+o/2,s/2+h,.5,1,u);var c=E.Matrix[0];return i.multiplyToRef(r,c),c.multiplyToRef(u,c),t.TransformCoordinates(e,c)},t.UnprojectFromTransform=function(i,r,n,o,s){var a=E.Matrix[0];o.multiplyToRef(s,a),a.invert(),i.x=i.x/r*2-1,i.y=-(i.y/n*2-1);var l=t.TransformCoordinates(i,a),h=i.x*a.m[3]+i.y*a.m[7]+i.z*a.m[11]+a.m[15];return e.Scalar.WithinEpsilon(h,1)&&(l=l.scale(1/h)),l},t.Unproject=function(i,r,n,o,s,a){var l=E.Matrix[0];o.multiplyToRef(s,l),l.multiplyToRef(a,l),l.invert();var h=new t(i.x/r*2-1,-(i.y/n*2-1),2*i.z-1),u=t.TransformCoordinates(h,l),c=h.x*l.m[3]+h.y*l.m[7]+h.z*l.m[11]+l.m[15];return e.Scalar.WithinEpsilon(c,1)&&(u=u.scale(1/c)),u},t.Minimize=function(e,t){var i=e.clone();return i.MinimizeInPlace(t),i},t.Maximize=function(e,t){var i=e.clone();return i.MaximizeInPlace(t),i},t.Distance=function(e,i){return Math.sqrt(t.DistanceSquared(e,i))},t.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y,n=e.z-t.z;return i*i+r*r+n*n},t.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},t.RotationFromAxis=function(e,i,r){var n=t.Zero();return t.RotationFromAxisToRef(e,i,r,n),n},t.RotationFromAxisToRef=function(e,t,i,r){var n=E.Quaternion[0];a.RotationQuaternionFromAxisToRef(e,t,i,n),n.toEulerAnglesToRef(r)},t}();e.Vector3=n;var o=function(){function t(e,t,i,r){this.x=e,this.y=t,this.z=i,this.w=r}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},t.prototype.getClassName=function(){return"Vector4"},t.prototype.getHashCode=function(){var e=this.x||0;return e=397*e^(this.y||0),e=397*e^(this.z||0),e=397*e^(this.w||0)},t.prototype.asArray=function(){var e=new Array;return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,this},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,t.w=this.w+e.w,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,t.w=this.w-e.w,this},t.prototype.subtractFromFloats=function(e,i,r,n){return new t(this.x-e,this.y-i,this.z-r,this.w-n)},t.prototype.subtractFromFloatsToRef=function(e,t,i,r,n){return n.x=this.x-e,n.y=this.y-t,n.z=this.z-i,n.w=this.w-r,this},t.prototype.negate=function(){return new t(-this.x,-this.y,-this.z,-this.w)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e,this.w*e)},t.prototype.scaleToRef=function(e,t){return t.x=this.x*e,t.y=this.y*e,t.z=this.z*e,t.w=this.w*e,this},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},t.prototype.equalsWithEpsilon=function(t,i){return void 0===i&&(i=e.Epsilon),t&&e.Scalar.WithinEpsilon(this.x,t.x,i)&&e.Scalar.WithinEpsilon(this.y,t.y,i)&&e.Scalar.WithinEpsilon(this.z,t.z,i)&&e.Scalar.WithinEpsilon(this.w,t.w,i)},t.prototype.equalsToFloats=function(e,t,i,r){return this.x===e&&this.y===t&&this.z===i&&this.w===r},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y,this.z*e.z,this.w*e.w)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,t.z=this.z*e.z,t.w=this.w*e.w,this},t.prototype.multiplyByFloats=function(e,i,r,n){return new t(this.x*e,this.y*i,this.z*r,this.w*n)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y,this.z/e.z,this.w/e.w)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,t.z=this.z/e.z,t.w=this.w/e.w,this},t.prototype.MinimizeInPlace=function(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),e.w<this.w&&(this.w=e.w),this},t.prototype.MaximizeInPlace=function(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),e.w>this.w&&(this.w=e.w),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},t.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.toVector3=function(){return new n(this.x,this.y,this.z)},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},t.prototype.copyFromFloats=function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,this},t.prototype.set=function(e,t,i,r){return this.copyFromFloats(e,t,i,r)},t.FromArray=function(e,i){return i||(i=0),new t(e[i],e[i+1],e[i+2],e[i+3])},t.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2],i.w=e[t+3]},t.FromFloatArrayToRef=function(e,i,r){t.FromArrayToRef(e,i,r)},t.FromFloatsToRef=function(e,t,i,r,n){n.x=e,n.y=t,n.z=i,n.w=r},t.Zero=function(){return new t(0,0,0,0)},t.One=function(){return new t(1,1,1,1)},t.Normalize=function(e){var i=t.Zero();return t.NormalizeToRef(e,i),i},t.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},t.Minimize=function(e,t){var i=e.clone();return i.MinimizeInPlace(t),i},t.Maximize=function(e,t){var i=e.clone();return i.MaximizeInPlace(t),i},t.Distance=function(e,i){return Math.sqrt(t.DistanceSquared(e,i))},t.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y,n=e.z-t.z,o=e.w-t.w;return i*i+r*r+n*n+o*o},t.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},t.TransformNormal=function(e,i){var r=t.Zero();return t.TransformNormalToRef(e,i,r),r},t.TransformNormalToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9],o=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10];i.x=r,i.y=n,i.z=o,i.w=e.w},t.TransformNormalFromFloatsToRef=function(e,t,i,r,n,o){o.x=e*n.m[0]+t*n.m[4]+i*n.m[8],o.y=e*n.m[1]+t*n.m[5]+i*n.m[9],o.z=e*n.m[2]+t*n.m[6]+i*n.m[10],o.w=r},t}();e.Vector4=o;var s=function(){function e(e,t){this.width=e,this.height=t}return e.prototype.toString=function(){return"{W: "+this.width+", H: "+this.height+"}"},e.prototype.getClassName=function(){return"Size"},e.prototype.getHashCode=function(){var e=this.width||0;return e=397*e^(this.height||0)},e.prototype.copyFrom=function(e){this.width=e.width,this.height=e.height},e.prototype.copyFromFloats=function(e,t){return this.width=e,this.height=t,this},e.prototype.set=function(e,t){return this.copyFromFloats(e,t)},e.prototype.multiplyByFloats=function(t,i){return new e(this.width*t,this.height*i)},e.prototype.clone=function(){return new e(this.width,this.height)},e.prototype.equals=function(e){return!!e&&(this.width===e.width&&this.height===e.height)},Object.defineProperty(e.prototype,"surface",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),e.Zero=function(){return new e(0,0)},e.prototype.add=function(t){return new e(this.width+t.width,this.height+t.height)},e.prototype.subtract=function(t){return new e(this.width-t.width,this.height-t.height)},e.Lerp=function(t,i,r){return new e(t.width+(i.width-t.width)*r,t.height+(i.height-t.height)*r)},e}();e.Size=s;var a=function(){function t(e,t,i,r){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=1),this.x=e,this.y=t,this.z=i,this.w=r}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},t.prototype.getClassName=function(){return"Quaternion"},t.prototype.getHashCode=function(){var e=this.x||0;return e=397*e^(this.y||0),e=397*e^(this.z||0),e=397*e^(this.w||0)},t.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},t.prototype.copyFromFloats=function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,this},t.prototype.set=function(e,t,i,r){return this.copyFromFloats(e,t,i,r)},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e,this.w*e)},t.prototype.multiply=function(e){var i=new t(0,0,0,1);return this.multiplyToRef(e,i),i},t.prototype.multiplyToRef=function(e,t){var i=this.x*e.w+this.y*e.z-this.z*e.y+this.w*e.x,r=-this.x*e.z+this.y*e.w+this.z*e.x+this.w*e.y,n=this.x*e.y-this.y*e.x+this.z*e.w+this.w*e.z,o=-this.x*e.x-this.y*e.y-this.z*e.z+this.w*e.w;return t.copyFromFloats(i,r,n,o),this},t.prototype.multiplyInPlace=function(e){return this.multiplyToRef(e,this),this},t.prototype.conjugateToRef=function(e){return e.copyFromFloats(-this.x,-this.y,-this.z,this.w),this},t.prototype.conjugateInPlace=function(){return this.x*=-1,this.y*=-1,this.z*=-1,this},t.prototype.conjugate=function(){return new t(-this.x,-this.y,-this.z,this.w)},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},t.prototype.normalize=function(){var e=1/this.length();return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},t.prototype.toEulerAngles=function(e){void 0===e&&(e="YZX");var t=n.Zero();return this.toEulerAnglesToRef(t,e),t},t.prototype.toEulerAnglesToRef=function(e,t){void 0===t&&(t="YZX");var i=this.z,r=this.x,n=this.y,o=this.w,s=o*o,a=i*i,l=r*r,h=n*n,u=n*i-r*o;return u<-.4999999?(e.y=2*Math.atan2(n,o),e.x=Math.PI/2,e.z=0):u>.4999999?(e.y=2*Math.atan2(n,o),e.x=-Math.PI/2,e.z=0):(e.z=Math.atan2(2*(r*n+i*o),-a-l+h+s),e.x=Math.asin(-2*(i*n-r*o)),e.y=Math.atan2(2*(i*r+n*o),a-l-h+s)),this},t.prototype.toRotationMatrix=function(e){var t=this.x*this.x,i=this.y*this.y,r=this.z*this.z,n=this.x*this.y,o=this.z*this.w,s=this.z*this.x,a=this.y*this.w,l=this.y*this.z,h=this.x*this.w;return e.m[0]=1-2*(i+r),e.m[1]=2*(n+o),e.m[2]=2*(s-a),e.m[3]=0,e.m[4]=2*(n-o),e.m[5]=1-2*(r+t),e.m[6]=2*(l+h),e.m[7]=0,e.m[8]=2*(s+a),e.m[9]=2*(l-h),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,e._markAsUpdated(),this},t.prototype.fromRotationMatrix=function(e){return t.FromRotationMatrixToRef(e,this),this},t.FromRotationMatrix=function(e){var i=new t;return t.FromRotationMatrixToRef(e,i),i},t.FromRotationMatrixToRef=function(e,t){var i,r=e.m,n=r[0],o=r[4],s=r[8],a=r[1],l=r[5],h=r[9],u=r[2],c=r[6],f=r[10],p=n+l+f;p>0?(i=.5/Math.sqrt(p+1),t.w=.25/i,t.x=(c-h)*i,t.y=(s-u)*i,t.z=(a-o)*i):n>l&&n>f?(i=2*Math.sqrt(1+n-l-f),t.w=(c-h)/i,t.x=.25*i,t.y=(o+a)/i,t.z=(s+u)/i):l>f?(i=2*Math.sqrt(1+l-n-f),t.w=(s-u)/i,t.x=(o+a)/i,t.y=.25*i,t.z=(h+c)/i):(i=2*Math.sqrt(1+f-n-l),t.w=(a-o)/i,t.x=(s+u)/i,t.y=(h+c)/i,t.z=.25*i)},t.Zero=function(){return new t(0,0,0,0)},t.Inverse=function(e){return new t(-e.x,-e.y,-e.z,e.w)},t.Identity=function(){return new t(0,0,0,1)},t.IsIdentity=function(e){return e&&0===e.x&&0===e.y&&0===e.z&&1===e.w},t.RotationAxis=function(e,i){return t.RotationAxisToRef(e,i,new t)},t.RotationAxisToRef=function(e,t,i){var r=Math.sin(t/2);return e.normalize(),i.w=Math.cos(t/2),i.x=e.x*r,i.y=e.y*r,i.z=e.z*r,i},t.FromArray=function(e,i){return i||(i=0),new t(e[i],e[i+1],e[i+2],e[i+3])},t.RotationYawPitchRoll=function(e,i,r){var n=new t;return t.RotationYawPitchRollToRef(e,i,r,n),n},t.RotationYawPitchRollToRef=function(e,t,i,r){var n=.5*i,o=.5*t,s=.5*e,a=Math.sin(n),l=Math.cos(n),h=Math.sin(o),u=Math.cos(o),c=Math.sin(s),f=Math.cos(s);r.x=f*h*l+c*u*a,r.y=c*u*l-f*h*a,r.z=f*u*a-c*h*l,r.w=f*u*l+c*h*a},t.RotationAlphaBetaGamma=function(e,i,r){var n=new t;return t.RotationAlphaBetaGammaToRef(e,i,r,n),n},t.RotationAlphaBetaGammaToRef=function(e,t,i,r){var n=.5*(i+e),o=.5*(i-e),s=.5*t;r.x=Math.cos(o)*Math.sin(s),r.y=Math.sin(o)*Math.sin(s),r.z=Math.sin(n)*Math.cos(s),r.w=Math.cos(n)*Math.cos(s)},t.RotationQuaternionFromAxis=function(e,i,r,n){var o=new t(0,0,0,0);return t.RotationQuaternionFromAxisToRef(e,i,r,o),o},t.RotationQuaternionFromAxisToRef=function(t,i,r,n){var o=E.Matrix[0];e.Matrix.FromXYZAxesToRef(t.normalize(),i.normalize(),r.normalize(),o),e.Quaternion.FromRotationMatrixToRef(o,n)},t.Slerp=function(e,i,r){var n=t.Identity();return t.SlerpToRef(e,i,r,n),n},t.SlerpToRef=function(e,t,i,r){var n,o,s=i,a=e.x*t.x+e.y*t.y+e.z*t.z+e.w*t.w,l=!1;if(a<0&&(l=!0,a=-a),a>.999999)o=1-s,n=l?-s:s;else{var h=Math.acos(a),u=1/Math.sin(h);o=Math.sin((1-s)*h)*u,n=l?-Math.sin(s*h)*u:Math.sin(s*h)*u}r.x=o*e.x+n*t.x,r.y=o*e.y+n*t.y,r.z=o*e.z+n*t.z,r.w=o*e.w+n*t.w},t.Hermite=function(e,i,r,n,o){var s=o*o,a=o*s,l=2*a-3*s+1,h=-2*a+3*s,u=a-2*s+o,c=a-s;return new t(e.x*l+r.x*h+i.x*u+n.x*c,e.y*l+r.y*h+i.y*u+n.y*c,e.z*l+r.z*h+i.z*u+n.z*c,e.w*l+r.w*h+i.w*u+n.w*c)},t}();e.Quaternion=a;var l=function(){function t(){this._isIdentity=!1,this._isIdentityDirty=!0,this.m=new Float32Array(16),this._markAsUpdated()}return t.prototype._markAsUpdated=function(){this.updateFlag=t._updateFlagSeed++,this._isIdentityDirty=!0},t.prototype.isIdentity=function(e){return void 0===e&&(e=!1),this._isIdentityDirty&&(this._isIdentityDirty=!1,1!==this.m[0]||1!==this.m[5]||1!==this.m[15]?this._isIdentity=!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]?this._isIdentity=!1:this._isIdentity=!0,e||1===this.m[10]||(this._isIdentity=!1)),this._isIdentity},t.prototype.determinant=function(){var e=this.m[10]*this.m[15]-this.m[11]*this.m[14],t=this.m[9]*this.m[15]-this.m[11]*this.m[13],i=this.m[9]*this.m[14]-this.m[10]*this.m[13],r=this.m[8]*this.m[15]-this.m[11]*this.m[12],n=this.m[8]*this.m[14]-this.m[10]*this.m[12],o=this.m[8]*this.m[13]-this.m[9]*this.m[12];return this.m[0]*(this.m[5]*e-this.m[6]*t+this.m[7]*i)-this.m[1]*(this.m[4]*e-this.m[6]*r+this.m[7]*n)+this.m[2]*(this.m[4]*t-this.m[5]*r+this.m[7]*o)-this.m[3]*(this.m[4]*i-this.m[5]*n+this.m[6]*o)},t.prototype.toArray=function(){return this.m},t.prototype.asArray=function(){return this.toArray()},t.prototype.invert=function(){return this.invertToRef(this),this},t.prototype.reset=function(){for(var e=0;e<16;e++)this.m[e]=0;return this._markAsUpdated(),this},t.prototype.add=function(e){var i=new t;return this.addToRef(e,i),i},t.prototype.addToRef=function(e,t){for(var i=0;i<16;i++)t.m[i]=this.m[i]+e.m[i];return t._markAsUpdated(),this},t.prototype.addToSelf=function(e){for(var t=0;t<16;t++)this.m[t]+=e.m[t];return this._markAsUpdated(),this},t.prototype.invertToRef=function(e){var t=this.m[0],i=this.m[1],r=this.m[2],n=this.m[3],o=this.m[4],s=this.m[5],a=this.m[6],l=this.m[7],h=this.m[8],u=this.m[9],c=this.m[10],f=this.m[11],p=this.m[12],d=this.m[13],m=this.m[14],g=this.m[15],v=c*g-f*m,_=u*g-f*d,y=u*m-c*d,x=h*g-f*p,b=h*m-c*p,T=h*d-u*p,E=s*v-a*_+l*y,A=-(o*v-a*x+l*b),P=o*_-s*x+l*T,S=-(o*y-s*b+a*T),M=1/(t*E+i*A+r*P+n*S),C=a*g-l*m,R=s*g-l*d,I=s*m-a*d,O=o*g-l*p,D=o*m-a*p,w=o*d-s*p,L=a*f-l*c,F=s*f-l*u,N=s*c-a*u,B=o*f-l*h,V=o*c-a*h,U=o*u-s*h;return e.m[0]=E*M,e.m[4]=A*M,e.m[8]=P*M,e.m[12]=S*M,e.m[1]=-(i*v-r*_+n*y)*M,e.m[5]=(t*v-r*x+n*b)*M,e.m[9]=-(t*_-i*x+n*T)*M,e.m[13]=(t*y-i*b+r*T)*M,e.m[2]=(i*C-r*R+n*I)*M,e.m[6]=-(t*C-r*O+n*D)*M,e.m[10]=(t*R-i*O+n*w)*M,e.m[14]=-(t*I-i*D+r*w)*M,e.m[3]=-(i*L-r*F+n*N)*M,e.m[7]=(t*L-r*B+n*V)*M,e.m[11]=-(t*F-i*B+n*U)*M,e.m[15]=(t*N-i*V+r*U)*M,e._markAsUpdated(),this},t.prototype.setTranslationFromFloats=function(e,t,i){return this.m[12]=e,this.m[13]=t,this.m[14]=i,this._markAsUpdated(),this},t.prototype.setTranslation=function(e){return this.m[12]=e.x,this.m[13]=e.y,this.m[14]=e.z,this._markAsUpdated(),this},t.prototype.getTranslation=function(){return new n(this.m[12],this.m[13],this.m[14])},t.prototype.getTranslationToRef=function(e){return e.x=this.m[12],e.y=this.m[13],e.z=this.m[14],this},t.prototype.removeRotationAndScaling=function(){return this.setRowFromFloats(0,1,0,0,0),this.setRowFromFloats(1,0,1,0,0),this.setRowFromFloats(2,0,0,1,0),this},t.prototype.multiply=function(e){var i=new t;return this.multiplyToRef(e,i),i},t.prototype.copyFrom=function(e){for(var t=0;t<16;t++)this.m[t]=e.m[t];return this._markAsUpdated(),this},t.prototype.copyToArray=function(e,t){void 0===t&&(t=0);for(var i=0;i<16;i++)e[t+i]=this.m[i];return this},t.prototype.multiplyToRef=function(e,t){return this.multiplyToArray(e,t.m,0),t._markAsUpdated(),this},t.prototype.multiplyToArray=function(e,t,i){var r=this.m[0],n=this.m[1],o=this.m[2],s=this.m[3],a=this.m[4],l=this.m[5],h=this.m[6],u=this.m[7],c=this.m[8],f=this.m[9],p=this.m[10],d=this.m[11],m=this.m[12],g=this.m[13],v=this.m[14],_=this.m[15],y=e.m[0],x=e.m[1],b=e.m[2],T=e.m[3],E=e.m[4],A=e.m[5],P=e.m[6],S=e.m[7],M=e.m[8],C=e.m[9],R=e.m[10],I=e.m[11],O=e.m[12],D=e.m[13],w=e.m[14],L=e.m[15];return t[i]=r*y+n*E+o*M+s*O,t[i+1]=r*x+n*A+o*C+s*D,t[i+2]=r*b+n*P+o*R+s*w,t[i+3]=r*T+n*S+o*I+s*L,t[i+4]=a*y+l*E+h*M+u*O,t[i+5]=a*x+l*A+h*C+u*D,t[i+6]=a*b+l*P+h*R+u*w,t[i+7]=a*T+l*S+h*I+u*L,t[i+8]=c*y+f*E+p*M+d*O,t[i+9]=c*x+f*A+p*C+d*D,t[i+10]=c*b+f*P+p*R+d*w,t[i+11]=c*T+f*S+p*I+d*L,t[i+12]=m*y+g*E+v*M+_*O,t[i+13]=m*x+g*A+v*C+_*D,t[i+14]=m*b+g*P+v*R+_*w,t[i+15]=m*T+g*S+v*I+_*L,this},t.prototype.equals=function(e){return e&&this.m[0]===e.m[0]&&this.m[1]===e.m[1]&&this.m[2]===e.m[2]&&this.m[3]===e.m[3]&&this.m[4]===e.m[4]&&this.m[5]===e.m[5]&&this.m[6]===e.m[6]&&this.m[7]===e.m[7]&&this.m[8]===e.m[8]&&this.m[9]===e.m[9]&&this.m[10]===e.m[10]&&this.m[11]===e.m[11]&&this.m[12]===e.m[12]&&this.m[13]===e.m[13]&&this.m[14]===e.m[14]&&this.m[15]===e.m[15]},t.prototype.clone=function(){return t.FromValues(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5],this.m[6],this.m[7],this.m[8],this.m[9],this.m[10],this.m[11],this.m[12],this.m[13],this.m[14],this.m[15])},t.prototype.getClassName=function(){return"Matrix"},t.prototype.getHashCode=function(){for(var e=this.m[0]||0,t=1;t<16;t++)e=397*e^(this.m[t]||0);return e},t.prototype.decompose=function(e,i,r){return r.x=this.m[12],r.y=this.m[13],r.z=this.m[14],e.x=Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]+this.m[2]*this.m[2]),e.y=Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]+this.m[6]*this.m[6]),e.z=Math.sqrt(this.m[8]*this.m[8]+this.m[9]*this.m[9]+this.m[10]*this.m[10]),this.determinant()<=0&&(e.y*=-1),0===e.x||0===e.y||0===e.z?(i.x=0,i.y=0,i.z=0,i.w=1,!1):(t.FromValuesToRef(this.m[0]/e.x,this.m[1]/e.x,this.m[2]/e.x,0,this.m[4]/e.y,this.m[5]/e.y,this.m[6]/e.y,0,this.m[8]/e.z,this.m[9]/e.z,this.m[10]/e.z,0,0,0,0,1,E.Matrix[0]),a.FromRotationMatrixToRef(E.Matrix[0],i),!0)},t.prototype.getRotationMatrix=function(){var e=t.Identity();return this.getRotationMatrixToRef(e),e},t.prototype.getRotationMatrixToRef=function(e){var i=this.m,r=i[0]*i[1]*i[2]*i[3]<0?-1:1,n=i[4]*i[5]*i[6]*i[7]<0?-1:1,o=i[8]*i[9]*i[10]*i[11]<0?-1:1,s=r*Math.sqrt(i[0]*i[0]+i[1]*i[1]+i[2]*i[2]),a=n*Math.sqrt(i[4]*i[4]+i[5]*i[5]+i[6]*i[6]),l=o*Math.sqrt(i[8]*i[8]+i[9]*i[9]+i[10]*i[10]);return t.FromValuesToRef(i[0]/s,i[1]/s,i[2]/s,0,i[4]/a,i[5]/a,i[6]/a,0,i[8]/l,i[9]/l,i[10]/l,0,0,0,0,1,e),this},t.FromArray=function(e,i){var r=new t;return i||(i=0),t.FromArrayToRef(e,i,r),r},t.FromArrayToRef=function(e,t,i){for(var r=0;r<16;r++)i.m[r]=e[r+t];i._markAsUpdated()},t.FromFloat32ArrayToRefScaled=function(e,t,i,r){for(var n=0;n<16;n++)r.m[n]=e[n+t]*i;r._markAsUpdated()},t.FromValuesToRef=function(e,t,i,r,n,o,s,a,l,h,u,c,f,p,d,m,g){g.m[0]=e,g.m[1]=t,g.m[2]=i,g.m[3]=r,g.m[4]=n,g.m[5]=o,g.m[6]=s,g.m[7]=a,g.m[8]=l,g.m[9]=h,g.m[10]=u,g.m[11]=c,g.m[12]=f,g.m[13]=p,g.m[14]=d,g.m[15]=m,g._markAsUpdated()},t.prototype.getRow=function(e){if(e<0||e>3)return null;var t=4*e;return new o(this.m[t+0],this.m[t+1],this.m[t+2],this.m[t+3])},t.prototype.setRow=function(e,t){if(e<0||e>3)return this;var i=4*e;return this.m[i+0]=t.x,this.m[i+1]=t.y,this.m[i+2]=t.z,this.m[i+3]=t.w,this._markAsUpdated(),this},t.prototype.transpose=function(){return t.Transpose(this)},t.prototype.transposeToRef=function(e){return t.TransposeToRef(this,e),this},t.prototype.setRowFromFloats=function(e,t,i,r,n){if(e<0||e>3)return this;var o=4*e;return this.m[o+0]=t,this.m[o+1]=i,this.m[o+2]=r,this.m[o+3]=n,this._markAsUpdated(),this},Object.defineProperty(t,"IdentityReadOnly",{get:function(){return t._identityReadOnly},enumerable:!0,configurable:!0}),t.FromValues=function(e,i,r,n,o,s,a,l,h,u,c,f,p,d,m,g){var v=new t;return v.m[0]=e,v.m[1]=i,v.m[2]=r,v.m[3]=n,v.m[4]=o,v.m[5]=s,v.m[6]=a,v.m[7]=l,v.m[8]=h,v.m[9]=u,v.m[10]=c,v.m[11]=f,v.m[12]=p,v.m[13]=d,v.m[14]=m,v.m[15]=g,v},t.Compose=function(e,i,r){var n=t.Identity();return t.ComposeToRef(e,i,r,n),n},t.ComposeToRef=function(e,i,r,n){t.FromValuesToRef(e.x,0,0,0,0,e.y,0,0,0,0,e.z,0,0,0,0,1,E.Matrix[1]),i.toRotationMatrix(E.Matrix[0]),E.Matrix[1].multiplyToRef(E.Matrix[0],n),n.setTranslation(r)},t.Identity=function(){return t.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},t.IdentityToRef=function(e){t.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,e)},t.Zero=function(){return t.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},t.RotationX=function(e){var i=new t;return t.RotationXToRef(e,i),i},t.Invert=function(e){var i=new t;return e.invertToRef(i),i},t.RotationXToRef=function(e,t){var i=Math.sin(e),r=Math.cos(e);t.m[0]=1,t.m[15]=1,t.m[5]=r,t.m[10]=r,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,t._markAsUpdated()},t.RotationY=function(e){var i=new t;return t.RotationYToRef(e,i),i},t.RotationYToRef=function(e,t){var i=Math.sin(e),r=Math.cos(e);t.m[5]=1,t.m[15]=1,t.m[0]=r,t.m[2]=-i,t.m[8]=i,t.m[10]=r,t.m[1]=0,t.m[3]=0,t.m[4]=0,t.m[6]=0,t.m[7]=0,t.m[9]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0,t._markAsUpdated()},t.RotationZ=function(e){var i=new t;return t.RotationZToRef(e,i),i},t.RotationZToRef=function(e,t){var i=Math.sin(e),r=Math.cos(e);t.m[10]=1,t.m[15]=1,t.m[0]=r,t.m[1]=i,t.m[4]=-i,t.m[5]=r,t.m[2]=0,t.m[3]=0,t.m[6]=0,t.m[7]=0,t.m[8]=0,t.m[9]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0,t._markAsUpdated()},t.RotationAxis=function(e,i){var r=t.Zero();return t.RotationAxisToRef(e,i,r),r},t.RotationAxisToRef=function(e,t,i){var r=Math.sin(-t),n=Math.cos(-t),o=1-n;e.normalize(),i.m[0]=e.x*e.x*o+n,i.m[1]=e.x*e.y*o-e.z*r,i.m[2]=e.x*e.z*o+e.y*r,i.m[3]=0,i.m[4]=e.y*e.x*o+e.z*r,i.m[5]=e.y*e.y*o+n,i.m[6]=e.y*e.z*o-e.x*r,i.m[7]=0,i.m[8]=e.z*e.x*o-e.y*r,i.m[9]=e.z*e.y*o+e.x*r,i.m[10]=e.z*e.z*o+n,i.m[11]=0,i.m[15]=1,i._markAsUpdated()},t.RotationYawPitchRoll=function(e,i,r){var n=new t;return t.RotationYawPitchRollToRef(e,i,r,n),n},t.RotationYawPitchRollToRef=function(e,t,i,r){a.RotationYawPitchRollToRef(e,t,i,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(r)},t.Scaling=function(e,i,r){var n=t.Zero();return t.ScalingToRef(e,i,r,n),n},t.ScalingToRef=function(e,t,i,r){r.m[0]=e,r.m[1]=0,r.m[2]=0,r.m[3]=0,r.m[4]=0,r.m[5]=t,r.m[6]=0,r.m[7]=0,r.m[8]=0,r.m[9]=0,r.m[10]=i,r.m[11]=0,r.m[12]=0,r.m[13]=0,r.m[14]=0,r.m[15]=1,r._markAsUpdated()},t.Translation=function(e,i,r){var n=t.Identity();return t.TranslationToRef(e,i,r,n),n},t.TranslationToRef=function(e,i,r,n){t.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,e,i,r,1,n)},t.Lerp=function(e,i,r){for(var n=t.Zero(),o=0;o<16;o++)n.m[o]=e.m[o]*(1-r)+i.m[o]*r;return n._markAsUpdated(),n},t.DecomposeLerp=function(e,i,r){var o=new n(0,0,0),s=new a,l=new n(0,0,0);e.decompose(o,s,l);var h=new n(0,0,0),u=new a,c=new n(0,0,0);i.decompose(h,u,c);var f=n.Lerp(o,h,r),p=a.Slerp(s,u,r),d=n.Lerp(l,c,r);return t.Compose(f,p,d)},t.LookAtLH=function(e,i,r){var n=t.Zero();return t.LookAtLHToRef(e,i,r,n),n},t.LookAtLHToRef=function(e,i,r,o){i.subtractToRef(e,this._zAxis),this._zAxis.normalize(),n.CrossToRef(r,this._zAxis,this._xAxis),0===this._xAxis.lengthSquared()?this._xAxis.x=1:this._xAxis.normalize(),n.CrossToRef(this._zAxis,this._xAxis,this._yAxis),this._yAxis.normalize();var s=-n.Dot(this._xAxis,e),a=-n.Dot(this._yAxis,e),l=-n.Dot(this._zAxis,e);return t.FromValuesToRef(this._xAxis.x,this._yAxis.x,this._zAxis.x,0,this._xAxis.y,this._yAxis.y,this._zAxis.y,0,this._xAxis.z,this._yAxis.z,this._zAxis.z,0,s,a,l,1,o)},t.LookAtRH=function(e,i,r){var n=t.Zero();return t.LookAtRHToRef(e,i,r,n),n},t.LookAtRHToRef=function(e,i,r,o){e.subtractToRef(i,this._zAxis),this._zAxis.normalize(),n.CrossToRef(r,this._zAxis,this._xAxis),0===this._xAxis.lengthSquared()?this._xAxis.x=1:this._xAxis.normalize(),n.CrossToRef(this._zAxis,this._xAxis,this._yAxis),this._yAxis.normalize();var s=-n.Dot(this._xAxis,e),a=-n.Dot(this._yAxis,e),l=-n.Dot(this._zAxis,e);return t.FromValuesToRef(this._xAxis.x,this._yAxis.x,this._zAxis.x,0,this._xAxis.y,this._yAxis.y,this._zAxis.y,0,this._xAxis.z,this._yAxis.z,this._zAxis.z,0,s,a,l,1,o)},t.OrthoLH=function(e,i,r,n){var o=t.Zero();return t.OrthoLHToRef(e,i,r,n,o),o},t.OrthoLHToRef=function(t,i,r,n,o){var s=r,a=n,l=2/t,h=2/i,u=2/(a-s),c=-(a+s)/(a-s);e.Matrix.FromValuesToRef(l,0,0,0,0,h,0,0,0,0,u,0,0,0,c,1,o)},t.OrthoOffCenterLH=function(e,i,r,n,o,s){var a=t.Zero();return t.OrthoOffCenterLHToRef(e,i,r,n,o,s,a),a},t.OrthoOffCenterLHToRef=function(t,i,r,n,o,s,a){var l=o,h=s,u=2/(i-t),c=2/(n-r),f=2/(h-l),p=-(h+l)/(h-l),d=(t+i)/(t-i),m=(n+r)/(r-n);e.Matrix.FromValuesToRef(u,0,0,0,0,c,0,0,0,0,f,0,d,m,p,1,a)},t.OrthoOffCenterRH=function(e,i,r,n,o,s){var a=t.Zero();return t.OrthoOffCenterRHToRef(e,i,r,n,o,s,a),a},t.OrthoOffCenterRHToRef=function(e,i,r,n,o,s,a){t.OrthoOffCenterLHToRef(e,i,r,n,o,s,a),a.m[10]*=-1},t.PerspectiveLH=function(i,r,n,o){var s=t.Zero(),a=n,l=o,h=2*a/i,u=2*a/r,c=(l+a)/(l-a),f=-2*l*a/(l-a);return e.Matrix.FromValuesToRef(h,0,0,0,0,u,0,0,0,0,c,1,0,0,f,0,s),s},t.PerspectiveFovLH=function(e,i,r,n){var o=t.Zero();return t.PerspectiveFovLHToRef(e,i,r,n,o),o},t.PerspectiveFovLHToRef=function(t,i,r,n,o,s){void 0===s&&(s=!0);var a=r,l=n,h=1/Math.tan(.5*t),u=s?h/i:h,c=s?h:h*i,f=(l+a)/(l-a),p=-2*l*a/(l-a);e.Matrix.FromValuesToRef(u,0,0,0,0,c,0,0,0,0,f,1,0,0,p,0,o)},t.PerspectiveFovRH=function(e,i,r,n){var o=t.Zero();return t.PerspectiveFovRHToRef(e,i,r,n,o),o},t.PerspectiveFovRHToRef=function(t,i,r,n,o,s){void 0===s&&(s=!0);var a=r,l=n,h=1/Math.tan(.5*t),u=s?h/i:h,c=s?h:h*i,f=-(l+a)/(l-a),p=-2*l*a/(l-a);e.Matrix.FromValuesToRef(u,0,0,0,0,c,0,0,0,0,f,-1,0,0,p,0,o)},t.PerspectiveFovWebVRToRef=function(e,t,i,r,n){void 0===n&&(n=!1);var o=n?-1:1,s=Math.tan(e.upDegrees*Math.PI/180),a=Math.tan(e.downDegrees*Math.PI/180),l=Math.tan(e.leftDegrees*Math.PI/180),h=Math.tan(e.rightDegrees*Math.PI/180),u=2/(l+h),c=2/(s+a);r.m[0]=u,r.m[1]=r.m[2]=r.m[3]=r.m[4]=0,r.m[5]=c,r.m[6]=r.m[7]=0,r.m[8]=(l-h)*u*.5,r.m[9]=-(s-a)*c*.5,r.m[10]=-i/(t-i),r.m[11]=1*o,r.m[12]=r.m[13]=r.m[15]=0,r.m[14]=-2*i*t/(i-t),r._markAsUpdated()},t.GetFinalMatrix=function(e,i,r,n,o,s){var a=e.width,l=e.height,h=e.x,u=e.y,c=t.FromValues(a/2,0,0,0,0,-l/2,0,0,0,0,s-o,0,h+a/2,l/2+u,o,1);return i.multiply(r).multiply(n).multiply(c)},t.GetAsMatrix2x2=function(e){return new Float32Array([e.m[0],e.m[1],e.m[4],e.m[5]])},t.GetAsMatrix3x3=function(e){return new Float32Array([e.m[0],e.m[1],e.m[2],e.m[4],e.m[5],e.m[6],e.m[8],e.m[9],e.m[10]])},t.Transpose=function(e){var i=new t;return t.TransposeToRef(e,i),i},t.TransposeToRef=function(e,t){t.m[0]=e.m[0],t.m[1]=e.m[4],t.m[2]=e.m[8],t.m[3]=e.m[12],t.m[4]=e.m[1],t.m[5]=e.m[5],t.m[6]=e.m[9],t.m[7]=e.m[13],t.m[8]=e.m[2],t.m[9]=e.m[6],t.m[10]=e.m[10],t.m[11]=e.m[14],t.m[12]=e.m[3],t.m[13]=e.m[7],t.m[14]=e.m[11],t.m[15]=e.m[15]},t.Reflection=function(e){var i=new t;return t.ReflectionToRef(e,i),i},t.ReflectionToRef=function(e,t){e.normalize();var i=e.normal.x,r=e.normal.y,n=e.normal.z,o=-2*i,s=-2*r,a=-2*n;t.m[0]=o*i+1,t.m[1]=s*i,t.m[2]=a*i,t.m[3]=0,t.m[4]=o*r,t.m[5]=s*r+1,t.m[6]=a*r,t.m[7]=0,t.m[8]=o*n,t.m[9]=s*n,t.m[10]=a*n+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,t._markAsUpdated()},t.FromXYZAxesToRef=function(e,t,i,r){r.m[0]=e.x,r.m[1]=e.y,r.m[2]=e.z,r.m[3]=0,r.m[4]=t.x,r.m[5]=t.y,r.m[6]=t.z,r.m[7]=0,r.m[8]=i.x,r.m[9]=i.y,r.m[10]=i.z,r.m[11]=0,r.m[12]=0,r.m[13]=0,r.m[14]=0,r.m[15]=1,r._markAsUpdated()},t.FromQuaternionToRef=function(e,t){var i=e.x*e.x,r=e.y*e.y,n=e.z*e.z,o=e.x*e.y,s=e.z*e.w,a=e.z*e.x,l=e.y*e.w,h=e.y*e.z,u=e.x*e.w;t.m[0]=1-2*(r+n),t.m[1]=2*(o+s),t.m[2]=2*(a-l),t.m[3]=0,t.m[4]=2*(o-s),t.m[5]=1-2*(n+i),t.m[6]=2*(h+u),t.m[7]=0,t.m[8]=2*(a+l),t.m[9]=2*(h-u),t.m[10]=1-2*(r+i),t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0,t.m[15]=1,t._markAsUpdated()},t._tempQuaternion=new a,t._xAxis=n.Zero(),t._yAxis=n.Zero(),t._zAxis=n.Zero(),t._updateFlagSeed=0,t._identityReadOnly=t.Identity(),t}();e.Matrix=l;var h=function(){function e(e,t,i,r){this.normal=new n(e,t,i),this.d=r}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.getClassName=function(){return"Plane"},e.prototype.getHashCode=function(){var e=this.normal.getHashCode();return e=397*e^(this.d||0)},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=l.Transpose(t),r=this.normal.x,n=this.normal.y,o=this.normal.z,s=this.d;return new e(r*i.m[0]+n*i.m[1]+o*i.m[2]+s*i.m[3],r*i.m[4]+n*i.m[5]+o*i.m[6]+s*i.m[7],r*i.m[8]+n*i.m[9]+o*i.m[10]+s*i.m[11],r*i.m[12]+n*i.m[13]+o*i.m[14]+s*i.m[15])},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 r,n=t.x-e.x,o=t.y-e.y,s=t.z-e.z,a=i.x-e.x,l=i.y-e.y,h=i.z-e.z,u=o*h-s*l,c=s*a-n*h,f=n*l-o*a,p=Math.sqrt(u*u+c*c+f*f);return r=0!==p?1/p:0,this.normal.x=u*r,this.normal.y=c*r,this.normal.z=f*r,this.d=-(this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z),this},e.prototype.isFrontFacingTo=function(e,t){return n.Dot(this.normal,e)<=t},e.prototype.signedDistanceTo=function(e){return n.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,r){var n=new e(0,0,0,0);return n.copyFromPoints(t,i,r),n},e.FromPositionAndNormal=function(t,i){var r=new e(0,0,0,0);return i.normalize(),r.normal=i,r.d=-(i.x*t.x+i.y*t.y+i.z*t.z),r},e.SignedDistanceToPlaneFromPositionAndNormal=function(e,t,i){var r=-(t.x*e.x+t.y*e.y+t.z*e.z);return n.Dot(i,t)+r},e}();e.Plane=h;var u=function(){function e(e,t,i,r){this.x=e,this.y=t,this.width=i,this.height=r}return e.prototype.toGlobal=function(t,i){if(t.getRenderWidth){var r=t;return this.toGlobal(r.getRenderWidth(),r.getRenderHeight())}var n=t;return new e(this.x*n,this.y*i,this.width*n,this.height*i)},e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e}();e.Viewport=u;var c=function(){function e(){}return e.GetPlanes=function(t){for(var i=[],r=0;r<6;r++)i.push(new h(0,0,0,0));return e.GetPlanesToRef(t,i),i},e.GetNearPlaneToRef=function(e,t){t.normal.x=e.m[3]+e.m[2],t.normal.y=e.m[7]+e.m[6],t.normal.z=e.m[11]+e.m[10],t.d=e.m[15]+e.m[14],t.normalize()},e.GetFarPlaneToRef=function(e,t){t.normal.x=e.m[3]-e.m[2],t.normal.y=e.m[7]-e.m[6],t.normal.z=e.m[11]-e.m[10],t.d=e.m[15]-e.m[14],t.normalize()},e.GetLeftPlaneToRef=function(e,t){t.normal.x=e.m[3]+e.m[0],t.normal.y=e.m[7]+e.m[4],t.normal.z=e.m[11]+e.m[8],t.d=e.m[15]+e.m[12],t.normalize()},e.GetRightPlaneToRef=function(e,t){t.normal.x=e.m[3]-e.m[0],t.normal.y=e.m[7]-e.m[4],t.normal.z=e.m[11]-e.m[8],t.d=e.m[15]-e.m[12],t.normalize()},e.GetTopPlaneToRef=function(e,t){t.normal.x=e.m[3]-e.m[1],t.normal.y=e.m[7]-e.m[5],t.normal.z=e.m[11]-e.m[9],t.d=e.m[15]-e.m[13],t.normalize()},e.GetBottomPlaneToRef=function(e,t){t.normal.x=e.m[3]+e.m[1],t.normal.y=e.m[7]+e.m[5],t.normal.z=e.m[11]+e.m[9],t.d=e.m[15]+e.m[13],t.normalize()},e.GetPlanesToRef=function(t,i){e.GetNearPlaneToRef(t,i[0]),e.GetFarPlaneToRef(t,i[1]),e.GetLeftPlaneToRef(t,i[2]),e.GetRightPlaneToRef(t,i[3]),e.GetTopPlaneToRef(t,i[4]),e.GetBottomPlaneToRef(t,i[5])},e}();e.Frustum=c;!function(e){e[e.LOCAL=0]="LOCAL",e[e.WORLD=1]="WORLD",e[e.BONE=2]="BONE"}(e.Space||(e.Space={}));var f=function(){function e(){}return e.X=new n(1,0,0),e.Y=new n(0,1,0),e.Z=new n(0,0,1),e}();e.Axis=f;var p=function(){function e(){}return e.interpolate=function(e,t,i,r,n){for(var o=1-3*r+3*t,s=3*r-6*t,a=3*t,l=e,h=0;h<5;h++){var u=l*l;l-=(o*(u*l)+s*u+a*l-e)*(1/(3*o*u+2*s*l+a)),l=Math.min(1,Math.max(0,l))}return 3*Math.pow(1-l,2)*l*i+3*(1-l)*Math.pow(l,2)*n+Math.pow(l,3)},e}();e.BezierCurve=p;var d;!function(e){e[e.CW=0]="CW",e[e.CCW=1]="CCW"}(d=e.Orientation||(e.Orientation={}));var 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 r=i.subtract(t);return new e(Math.atan2(r.y,r.x))},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(){return function(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 l=this.startAngle.degrees(),h=m.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),u=m.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();h-l>180&&(h-=360),h-l<-180&&(h+=360),u-h>180&&(u-=360),u-h<-180&&(u+=360),this.orientation=h-l<0?d.CW:d.CCW,this.angle=m.FromDegrees(this.orientation===d.CW?l-u:u-l)}}();e.Arc2=g;var v=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),l=new r(i,n),h=new g(s,a,l),u=h.angle.radians()/o;h.orientation===d.CW&&(u*=-1);for(var c=h.startAngle.radians()+u,f=0;f<o;f++){var p=Math.cos(c)*h.radius+h.centerPoint.x,m=Math.sin(c)*h.radius+h.centerPoint.y;this.addLineTo(p,m),c+=u}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];e+=this._points[0].subtract(t).length()}return e},e.prototype.getPoints=function(){return this._points},e.prototype.getPointAtLengthPosition=function(e){if(e<0||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].subtract(s),l=a.length()+i;if(t>=i&&t<=l){var h=a.normalize(),u=t-i;return new r(s.x+h.x*u,s.y+h.y*u)}i=l}return r.Zero()},e.StartingAt=function(t,i){return new e(t,i)},e}();e.Path2=v;var _=function(){function t(e,t,i){void 0===t&&(t=null),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 r=0;r<e.length;r++)this._curve[r]=e[r].clone();this._raw=i||!1,this._compute(t)}return t.prototype.getCurve=function(){return this._curve},t.prototype.getTangents=function(){return this._tangents},t.prototype.getNormals=function(){return this._normals},t.prototype.getBinormals=function(){return this._binormals},t.prototype.getDistances=function(){return this._distances},t.prototype.update=function(e,t){void 0===t&&(t=null);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},t.prototype._compute=function(e){var t=this._curve.length;this._tangents[0]=this._getFirstNonNullVector(0),this._raw||this._tangents[0].normalize(),this._tangents[t-1]=this._curve[t-1].subtract(this._curve[t-2]),this._raw||this._tangents[t-1].normalize();var i=this._tangents[0],r=this._normalVector(this._curve[0],i,e);this._normals[0]=r,this._raw||this._normals[0].normalize(),this._binormals[0]=n.Cross(i,this._normals[0]),this._raw||this._binormals[0].normalize(),this._distances[0]=0;for(var o,s,a,l,h=1;h<t;h++)o=this._getLastNonNullVector(h),h<t-1&&(s=this._getFirstNonNullVector(h),this._tangents[h]=o.add(s),this._tangents[h].normalize()),this._distances[h]=this._distances[h-1]+o.length(),a=this._tangents[h],l=this._binormals[h-1],this._normals[h]=n.Cross(l,a),this._raw||this._normals[h].normalize(),this._binormals[h]=n.Cross(a,this._normals[h]),this._raw||this._binormals[h].normalize()},t.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},t.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},t.prototype._normalVector=function(t,i,r){var o,s=i.length();if(0===s&&(s=1),void 0===r||null===r){var a;a=e.Scalar.WithinEpsilon(Math.abs(i.y)/s,1,e.Epsilon)?e.Scalar.WithinEpsilon(Math.abs(i.x)/s,1,e.Epsilon)?e.Scalar.WithinEpsilon(Math.abs(i.z)/s,1,e.Epsilon)?n.Zero():new n(0,0,1):new n(1,0,0):new n(0,-1,0),o=n.Cross(i,a)}else o=n.Cross(i,r),n.CrossToRef(o,i,o);return o.normalize(),o},t}();e.Path3D=_;var y=function(){function e(e){this._length=0,this._points=e,this._length=this._computeLength(e)}return e.CreateQuadraticBezier=function(t,i,r,o){o=o>2?o:3;for(var s=new Array,a=function(e,t,i,r){return(1-e)*(1-e)*t+2*e*(1-e)*i+e*e*r},l=0;l<=o;l++)s.push(new n(a(l/o,t.x,i.x,r.x),a(l/o,t.y,i.y,r.y),a(l/o,t.z,i.z,r.z)));return new e(s)},e.CreateCubicBezier=function(t,i,r,o,s){s=s>3?s:4;for(var a=new Array,l=function(e,t,i,r,n){return(1-e)*(1-e)*(1-e)*t+3*e*(1-e)*(1-e)*i+3*e*e*(1-e)*r+e*e*e*n},h=0;h<=s;h++)a.push(new n(l(h/s,t.x,i.x,r.x,o.x),l(h/s,t.y,i.y,r.y,o.y),l(h/s,t.z,i.z,r.z,o.z)));return new e(a)},e.CreateHermiteSpline=function(t,i,r,o,s){for(var a=new Array,l=1/s,h=0;h<=s;h++)a.push(n.Hermite(t,i,r,o,h*l));return new e(a)},e.CreateCatmullRomSpline=function(t,i){var r=new Array;r.push(t[0].clone()),Array.prototype.push.apply(r,t),r.push(t[t.length-1].clone());for(var o=new Array,s=1/i,a=0,l=0;l<r.length-3;l++){a=0;for(var h=0;h<i;h++)o.push(n.CatmullRom(r[l],r[l+1],r[l+2],r[l+3],a)),a+=s}return l--,o.push(n.CatmullRom(r[l],r[l+1],r[l+2],r[l+3],a)),new e(o)},e.prototype.getPoints=function(){return this._points},e.prototype.length=function(){return this._length},e.prototype.continue=function(t){for(var i=this._points[this._points.length-1],r=this._points.slice(),n=t.getPoints(),o=1;o<n.length;o++)r.push(n[o].subtract(n[0]).add(i));return new e(r)},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(e,t){void 0===e&&(e=n.Zero()),void 0===t&&(t=n.Up()),this.position=e,this.normal=t}return e.prototype.clone=function(){return new e(this.position.clone(),this.normal.clone())},e}();e.PositionNormalVertex=x;var b=function(){function e(e,t,i){void 0===e&&(e=n.Zero()),void 0===t&&(t=n.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=b;var T=function(){function e(){}return e.Color3=[t.Black(),t.Black(),t.Black()],e.Vector2=[r.Zero(),r.Zero(),r.Zero()],e.Vector3=[n.Zero(),n.Zero(),n.Zero(),n.Zero(),n.Zero(),n.Zero(),n.Zero(),n.Zero(),n.Zero()],e.Vector4=[o.Zero(),o.Zero(),o.Zero()],e.Quaternion=[a.Zero(),a.Zero()],e.Matrix=[l.Zero(),l.Zero(),l.Zero(),l.Zero(),l.Zero(),l.Zero(),l.Zero(),l.Zero()],e}();e.Tmp=T;var E=function(){function e(){}return e.Vector3=[n.Zero()],e.Matrix=[l.Zero(),l.Zero()],e.Quaternion=[a.Zero()],e}()}(s||(s={}));!function(e){var t=function(){function e(){}return e.WithinEpsilon=function(e,t,i){void 0===i&&(i=1.401298e-45);var r=e-t;return-i<=r&&r<=i},e.ToHex=function(e){var t=e.toString(16);return e<=15?("0"+t).toUpperCase():t.toUpperCase()},e.Sign=function(e){return 0==(e=+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.Log2=function(e){return Math.log(e)*Math.LOG2E},e.Repeat=function(e,t){return e-Math.floor(e/t)*t},e.Normalize=function(e,t,i){return(e-t)/(i-t)},e.Denormalize=function(e,t,i){return e*(i-t)+t},e.DeltaAngle=function(t,i){var r=e.Repeat(i-t,360);return r>180&&(r-=360),r},e.PingPong=function(t,i){var r=e.Repeat(t,2*i);return i-Math.abs(r-i)},e.SmoothStep=function(t,i,r){var n=e.Clamp(r);return n=-2*n*n*n+3*n*n,i*n+t*(1-n)},e.MoveTowards=function(t,i,r){return Math.abs(i-t)<=r?i:t+e.Sign(i-t)*r},e.MoveTowardsAngle=function(t,i,r){var n=e.DeltaAngle(t,i);return-r<n&&n<r?i:e.MoveTowards(t,i=t+n,r)},e.Lerp=function(e,t,i){return e+(t-e)*i},e.LerpAngle=function(t,i,r){var n=e.Repeat(i-t,360);return n>180&&(n-=360),t+n*e.Clamp(r)},e.InverseLerp=function(t,i,r){return t!=i?e.Clamp((r-t)/(i-t)):0},e.Hermite=function(e,t,i,r,n){var o=n*n,s=n*o;return e*(2*s-3*o+1)+i*(-2*s+3*o)+t*(s-2*o+n)+r*(s-o)},e.RandomRange=function(e,t){return e===t?e:Math.random()*(t-e)+e},e.RangeToPercent=function(e,t,i){return(e-t)/(i-t)},e.PercentToRange=function(e,t,i){return(i-t)*e+t},e.NormalizeRadians=function(t){return t-=e.TwoPi*Math.floor((t+Math.PI)/e.TwoPi)},e.TwoPi=2*Math.PI,e}();e.Scalar=t}(s||(s={}));!function(e){function t(e){var t=e.getClassName();return o[t]||(o[t]={}),o[t]}function i(e){var t=e.getClassName();if(s[t])return s[t];s[t]={};for(var i=s[t],r=e,n=t;n;){var a=o[n];for(var l in a)i[l]=a[l];var h=void 0,u=!1;do{if(!(h=Object.getPrototypeOf(r)).getClassName){u=!0;break}if(h.getClassName()!==n)break;r=h}while(h);if(u)break;n=h.getClassName(),r=h}return i}function r(e,i){return function(r,n){var o=t(r);o[n]||(o[n]={type:e,sourceName:i})}}function n(e,t){return void 0===t&&(t=null),function(i,r){var n=t||"_"+r;Object.defineProperty(i,r,{get:function(){return this[n]},set:function(t){this[n]!==t&&(this[n]=t,i[e].apply(this))},enumerable:!0,configurable:!0})}}var o={},s={},a=function(t,r,n){var o=t();e.Tags&&e.Tags.AddTagsTo(o,r.tags);var s=i(o);for(var a in s){var l=s[a],h=r[a],u=l.type;if(void 0!==h&&null!==h)switch(u){case 0:case 6:o[a]=h;break;case 1:o[a]=n||h.isRenderTarget?h:h.clone();break;case 2:case 3:case 4:case 5:case 7:o[a]=n?h:h.clone()}}return o};e.expandToProperty=function(e,t){return void 0===t&&(t=null),n(e,t)},e.serialize=function(e){return r(0,e)},e.serializeAsTexture=function(e){return r(1,e)},e.serializeAsColor3=function(e){return r(2,e)},e.serializeAsFresnelParameters=function(e){return r(3,e)},e.serializeAsVector2=function(e){return r(4,e)},e.serializeAsVector3=function(e){return r(5,e)},e.serializeAsMeshReference=function(e){return r(6,e)},e.serializeAsColorCurves=function(e){return r(7,e)},e.serializeAsColor4=function(e){return r(8,e)},e.serializeAsImageProcessingConfiguration=function(e){return r(9,e)};var l=function(){function t(){}return t.Serialize=function(t,r){r||(r={}),e.Tags&&(r.tags=e.Tags.GetTags(t));var n=i(t);for(var o in n){var s=n[o],a=s.sourceName||o,l=s.type,h=t[o];if(void 0!==h&&null!==h)switch(l){case 0:r[a]=h;break;case 1:r[a]=h.serialize();break;case 2:r[a]=h.asArray();break;case 3:r[a]=h.serialize();break;case 4:case 5:r[a]=h.asArray();break;case 6:r[a]=h.id;break;case 7:r[a]=h.serialize();break;case 8:r[a]=h.asArray();break;case 9:r[a]=h.serialize()}}return r},t.Parse=function(t,r,n,o){void 0===o&&(o=null);var s=t();o||(o=""),e.Tags&&e.Tags.AddTagsTo(s,r.tags);var a=i(s);for(var l in a){var h=a[l],u=r[h.sourceName||l],c=h.type;if(void 0!==u&&null!==u){var f=s;switch(c){case 0:f[l]=u;break;case 1:n&&(f[l]=e.Texture.Parse(u,n,o));break;case 2:f[l]=e.Color3.FromArray(u);break;case 3:f[l]=e.FresnelParameters.Parse(u);break;case 4:f[l]=e.Vector2.FromArray(u);break;case 5:f[l]=e.Vector3.FromArray(u);break;case 6:n&&(f[l]=n.getLastMeshByID(u));break;case 7:f[l]=e.ColorCurves.Parse(u);break;case 8:f[l]=e.Color4.FromArray(u);break;case 9:f[l]=e.ImageProcessingConfiguration.Parse(u)}}}return s},t.Clone=function(e,t){return a(e,t,!1)},t.Instanciate=function(e,t){return a(e,t,!0)},t}();e.SerializationHelper=l}(s||(s={}));!function(e){var t=function(){function e(e,t,i,r){void 0===t&&(t=!1),this.initalize(e,t,i,r)}return e.prototype.initalize=function(e,t,i,r){return void 0===t&&(t=!1),this.mask=e,this.skipNextObservers=t,this.target=i,this.currentTarget=r,this},e}();e.EventState=t;var i=function(){return function(e,t,i){void 0===i&&(i=null),this.callback=e,this.mask=t,this.scope=i}}();e.Observer=i;var r=function(){function e(){}return e.prototype.dispose=function(){if(this._observers&&this._observables)for(var e=0;e<this._observers.length;e++)this._observables[e].remove(this._observers[e]);this._observers=null,this._observables=null},e.Watch=function(t,i,r,n){void 0===r&&(r=-1),void 0===n&&(n=null);var o=new e;o._observers=new Array,o._observables=t;for(var s=0,a=t;s<a.length;s++){var l=a[s].add(i,r,!1,n);l&&o._observers.push(l)}return o},e}();e.MultiObserver=r;var n=function(){function e(e){this._observers=new Array,this._eventState=new t(0),e&&(this._onObserverAdded=e)}return e.prototype.add=function(e,t,r,n){if(void 0===t&&(t=-1),void 0===r&&(r=!1),void 0===n&&(n=null),!e)return null;var o=new i(e,t,n);return r?this._observers.unshift(o):this._observers.push(o),this._onObserverAdded&&this._onObserverAdded(o),o},e.prototype.remove=function(e){if(!e)return!1;var t=this._observers.indexOf(e);return-1!==t&&(this._observers.splice(t,1),!0)},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,t,i,r){if(void 0===t&&(t=-1),!this._observers.length)return!0;var n=this._eventState;n.mask=t,n.target=i,n.currentTarget=r,n.skipNextObservers=!1;for(var o=0,s=this._observers;o<s.length;o++){var a=s[o];if(a.mask&t&&(a.scope?a.callback.apply(a.scope,[e,n]):a.callback(e,n)),n.skipNextObservers)return!1}return!0},e.prototype.notifyObserver=function(e,t,i){void 0===i&&(i=-1);var r=this._eventState;r.mask=i,r.skipNextObservers=!1,e.callback(t,r)},e.prototype.hasObservers=function(){return this._observers.length>0},e.prototype.clear=function(){this._observers=new Array,this._onObserverAdded=null},e.prototype.clone=function(){var t=new e;return t._observers=this._observers.slice(0),t},e.prototype.hasSpecificMask=function(e){void 0===e&&(e=-1);for(var t=0,i=this._observers;t<i.length;t++){var r=i[t];if(r.mask&e||r.mask===e)return!0}return!1},e}();e.Observable=n}(s||(s={}));!function(e){var t=function(){function e(t){this.length=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.prototype.forEach=function(e){for(var t=0;t<this.length;t++)e(this.data[t])},e.prototype.sort=function(e){this.data.sort(e)},e.prototype.reset=function(){this.length=0},e.prototype.dispose=function(){this.reset(),this.data&&(this.data.length=0,this.data=[])},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.indexOf=function(e){var t=this.data.indexOf(e);return t>=this.length?-1:t},e.prototype.contains=function(e){return-1!==this.data.indexOf(e)},e._GlobalId=0,e}();e.SmartArray=t;var i=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._duplicateId=0,t}return n(t,e),t.prototype.push=function(t){e.prototype.push.call(this,t),t.__smartArrayFlags||(t.__smartArrayFlags={}),t.__smartArrayFlags[this._id]=this._duplicateId},t.prototype.pushNoDuplicate=function(e){return(!e.__smartArrayFlags||e.__smartArrayFlags[this._id]!==this._duplicateId)&&(this.push(e),!0)},t.prototype.reset=function(){e.prototype.reset.call(this),this._duplicateId++},t.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)}}},t}(t);e.SmartArrayNoDuplicate=i}(s||(s={}));!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},r=function(){function r(){}return r.Mix=function(e,t,i){return e*(1-i)+t*i},r.Instantiate=function(e){if(r.RegisteredExternalClasses&&r.RegisteredExternalClasses[e])return r.RegisteredExternalClasses[e];for(var t=e.split("."),i=window||this,n=0,o=t.length;n<o;n++)i=i[t[n]];return"function"!=typeof i?null:i},r.SetImmediate=function(e){window.setImmediate?window.setImmediate(e):setTimeout(e,1)},r.IsExponentOfTwo=function(e){var t=1;do{t*=2}while(t<e);return t===e},r.CeilingPOT=function(e){return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e},r.FloorPOT=function(e){return e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,(e|=e>>16)-(e>>1)},r.NearestPOT=function(e){var t=r.CeilingPOT(e),i=r.FloorPOT(e);return t-e>e-i?i:t},r.GetExponentOfTwo=function(t,i,n){void 0===n&&(n=e.Engine.SCALEMODE_NEAREST);var o;switch(n){case e.Engine.SCALEMODE_FLOOR:o=r.FloorPOT(t);break;case e.Engine.SCALEMODE_NEAREST:o=r.NearestPOT(t);break;case e.Engine.SCALEMODE_CEILING:default:o=r.CeilingPOT(t)}return Math.min(o,i)},r.GetFilename=function(e){var t=e.lastIndexOf("/");return t<0?e:e.substring(t+1)},r.GetFolderPath=function(e){var t=e.lastIndexOf("/");return t<0?"":e.substring(0,t+1)},r.GetDOMTextContent=function(e){for(var t="",i=e.firstChild;i;)3===i.nodeType&&(t+=i.textContent),i=i.nextSibling;return t},r.ToDegrees=function(e){return 180*e/Math.PI},r.ToRadians=function(e){return e*Math.PI/180},r.EncodeArrayBufferTobase64=function(e){for(var t,i,r,n,o,s,a,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",h="",u=0,c=new Uint8Array(e);u<c.length;)n=(t=c[u++])>>2,o=(3&t)<<4|(i=u<c.length?c[u++]:Number.NaN)>>4,s=(15&i)<<2|(r=u<c.length?c[u++]:Number.NaN)>>6,a=63&r,isNaN(i)?s=a=64:isNaN(r)&&(a=64),h+=l.charAt(n)+l.charAt(o)+l.charAt(s)+l.charAt(a);return"data:image/png;base64,"+h},r.ExtractMinAndMaxIndexed=function(t,i,r,n,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),l=r;l<r+n;l++){var h=new e.Vector3(t[3*i[l]],t[3*i[l]+1],t[3*i[l]+2]);s=e.Vector3.Minimize(h,s),a=e.Vector3.Maximize(h,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}},r.ExtractMinAndMax=function(t,i,r,n,o){void 0===n&&(n=null);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);o||(o=3);for(var l=i;l<i+r;l++){var h=new e.Vector3(t[l*o],t[l*o+1],t[l*o+2]);s=e.Vector3.Minimize(h,s),a=e.Vector3.Maximize(h,a)}return n&&(s.x-=s.x*n.x+n.y,s.y-=s.y*n.x+n.y,s.z-=s.z*n.x+n.y,a.x+=a.x*n.x+n.y,a.y+=a.y*n.x+n.y,a.z+=a.z*n.x+n.y),{minimum:s,maximum:a}},r.Vector2ArrayFeeder=function(t){return function(i){var r=void 0!==t.BYTES_PER_ELEMENT;if(i>=(r?t.length/2:t.length))return null;if(r){var n=t;return new e.Vector2(n[2*i+0],n[2*i+1])}return t[i]}},r.ExtractMinAndMaxVector2=function(t,i){void 0===i&&(i=null);for(var r=new e.Vector2(Number.MAX_VALUE,Number.MAX_VALUE),n=new e.Vector2(-Number.MAX_VALUE,-Number.MAX_VALUE),o=0,s=t(o++);s;)r=e.Vector2.Minimize(s,r),n=e.Vector2.Maximize(s,n),s=t(o++);return i&&(r.x-=r.x*i.x+i.y,r.y-=r.y*i.x+i.y,n.x+=n.x*i.x+i.y,n.y+=n.y*i.x+i.y),{minimum:r,maximum:n}},r.MakeArray=function(e,t){return!0===t||void 0!==e&&null!=e?Array.isArray(e)?e:[e]:null},r.GetPointerPrefix=function(){var e="pointer";return!r.IsWindowObjectExist()||window.PointerEvent||navigator.pointerEnabled||(e="mouse"),e},r.QueueNewFrame=function(e,t){return r.IsWindowObjectExist()?(t||(t=window),t.requestAnimationFrame?t.requestAnimationFrame(e):t.msRequestAnimationFrame?t.msRequestAnimationFrame(e):t.webkitRequestAnimationFrame?t.webkitRequestAnimationFrame(e):t.mozRequestAnimationFrame?t.mozRequestAnimationFrame(e):t.oRequestAnimationFrame?t.oRequestAnimationFrame(e):window.setTimeout(e,16)):setTimeout(e,16)},r.RequestFullscreen=function(e){var t=e.requestFullscreen||e.msRequestFullscreen||e.webkitRequestFullscreen||e.mozRequestFullScreen;t&&t.call(e)},r.ExitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.msCancelFullScreen&&document.msCancelFullScreen()},r.SetCorsBehavior=function(e,t){if(r.CorsBehavior)switch(typeof r.CorsBehavior){case"function":var i=r.CorsBehavior(e);i&&(t.crossOrigin=i);break;case"string":default:t.crossOrigin=r.CorsBehavior}},r.CleanUrl=function(e){return e=e.replace(/#/gm,"%23")},r.LoadImage=function(t,i,n,o){t instanceof ArrayBuffer&&(t=r.EncodeArrayBufferTobase64(t)),t=r.CleanUrl(t),t=r.PreprocessUrl(t);var s=new Image;"data:"!==t.substr(0,5)&&r.SetCorsBehavior(t,s),s.onload=function(){i(s)},s.onerror=function(e){r.Error("Error while trying to load image: "+t),r.UseFallbackTexture?(s.src=r.fallbackTexture,i(s)):n("Error while trying to load image: "+t,e)};var a=function(){s.src=t};if("data:"!==t.substr(0,5)&&o&&o.enableTexturesOffline&&e.Database.IsUASupportingBlobStorage)o.openAsync(function(){o&&o.loadImageFromDB(t,s)},a);else if(0!==t.indexOf("file:"))a();else{var l=decodeURIComponent(t.substring(5).toLowerCase());if(e.FilesInput.FilesToLoad[l])try{var h;try{h=URL.createObjectURL(e.FilesInput.FilesToLoad[l],{oneTimeOnly:!0})}catch(t){h=URL.createObjectURL(e.FilesInput.FilesToLoad[l])}s.src=h}catch(e){s.src=""}else r.Error("Image: "+l+" not found. Did you forget to provide it?"),s.src=r.fallbackTexture}return s},r.LoadFile=function(t,i,n,o,s,a){t=r.CleanUrl(t);var l=null,h=function(){l=new XMLHttpRequest;var e=r.BaseUrl+t;l.open("GET",e,!0),s&&(l.responseType="arraybuffer"),n&&(l.onprogress=n),l.onreadystatechange=function(){var t=l;if(t.readyState===(XMLHttpRequest.DONE||4))if(t.onreadystatechange=function(){},t.status>=200&&t.status<300||!r.IsWindowObjectExist()&&0===t.status)i(s?t.response:t.responseText,t.responseURL);else{var n=new Error("Error status: "+t.status+" - Unable to load "+e);if(!a)throw n;a(t,n)}},l.send(null)};if(-1!==(t=r.PreprocessUrl(t)).indexOf("file:")){var u=decodeURIComponent(t.substring(5).toLowerCase());if(e.FilesInput.FilesToLoad[u])r.ReadFile(e.FilesInput.FilesToLoad[u],i,n,s);else{var c="File: "+u+" not found. Did you forget to provide it?";if(a){var f=new Error(c);a(void 0,f)}else r.Error(c)}}else o&&o.enableSceneOffline?o.openAsync(function(){o&&o.loadFileFromDB(t,i,n,h,s)},h):h();return l},r.LoadScript=function(e,t,i){var r=document.getElementsByTagName("head")[0],n=document.createElement("script");n.type="text/javascript",n.src=e,n.onload=function(){t&&t()},n.onerror=function(e){i&&i("Unable to load script",e)},r.appendChild(n)},r.ReadFileAsDataURL=function(e,t,i){var r=new FileReader;r.onload=function(e){t(e.target.result)},r.onprogress=i,r.readAsDataURL(e)},r.ReadFile=function(e,t,i,n){var o=new FileReader;o.onerror=function(i){r.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)},i&&(o.onprogress=i),n?o.readAsArrayBuffer(e):o.readAsText(e)},r.FileAsURL=function(e){var t=new Blob([e]);return(window.URL||window.webkitURL).createObjectURL(t)},r.Format=function(e,t){return void 0===t&&(t=2),e.toFixed(t)},r.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)},r.DeepCopy=function(e,t,r,n){for(var o in e)if(("_"!==o[0]||n&&-1!==n.indexOf(o))&&(!r||-1===r.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 l=0;l<s.length;l++){var h=i(s[l],t);-1===t[o].indexOf(h)&&t[o].push(h)}else t[o]=s.slice(0)}else t[o]=i(s,t);else t[o]=s}},r.IsEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},r.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(e){}}},r.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(e){}}},r.DumpFramebuffer=function(e,i,n,o,s){void 0===s&&(s="image/png");for(var a=4*e,l=i/2,h=n.readPixels(0,0,e,i),u=0;u<l;u++)for(var c=0;c<a;c++){var f=c+u*a,p=c+(i-u-1)*a,d=h[f];h[f]=h[p],h[p]=d}t||(t=document.createElement("canvas")),t.width=e,t.height=i;var m=t.getContext("2d");if(m){var g=m.createImageData(e,i);g.data.set(h),m.putImageData(g,0,0),r.EncodeScreenshotCanvasData(o,s)}},r.EncodeScreenshotCanvasData=function(e,i){void 0===i&&(i="image/png");var r=t.toDataURL(i);if(e)e(r);else if("download"in document.createElement("a")){var n=window.document.createElement("a");n.href=r;var o=new Date,s=(o.getFullYear()+"-"+(o.getMonth()+1)).slice(-2)+"-"+o.getDate()+"_"+o.getHours()+"-"+("0"+o.getMinutes()).slice(-2);n.setAttribute("download","screenshot_"+s+".png"),window.document.body.appendChild(n),n.addEventListener("click",function(){n.parentElement&&n.parentElement.removeChild(n)}),n.click()}else{var a=window.open(""),l=a.document.createElement("img");l.src=r,a.document.body.appendChild(l)}},r.CreateScreenshot=function(e,i,n,o,s){void 0===s&&(s="image/png");var a,l;if(n.precision)a=Math.round(e.getRenderWidth()*n.precision),l=Math.round(a/e.getAspectRatio(i));else if(n.width&&n.height)a=n.width,l=n.height;else if(n.width&&!n.height)a=n.width,l=Math.round(a/e.getAspectRatio(i));else if(n.height&&!n.width)l=n.height,a=Math.round(l*e.getAspectRatio(i));else{if(isNaN(n))return void r.Error("Invalid 'size' parameter !");l=n,a=n}t||(t=document.createElement("canvas")),t.width=a,t.height=l;var h=t.getContext("2d"),u=e.getRenderWidth()/e.getRenderHeight(),c=a,f=c/u;f>l&&(c=(f=l)*u);var p=Math.max(0,a-c)/2,d=Math.max(0,l-f)/2,m=e.getRenderingCanvas();h&&m&&h.drawImage(m,p,d,c,f),r.EncodeScreenshotCanvasData(o,s)},r.CreateScreenshotUsingRenderTarget=function(t,i,n,o,s,a){void 0===s&&(s="image/png"),void 0===a&&(a=1);var l,h;if(n.precision)l=Math.round(t.getRenderWidth()*n.precision),h=Math.round(l/t.getAspectRatio(i)),n={width:l,height:h};else if(n.width&&n.height)l=n.width,h=n.height;else if(n.width&&!n.height)l=n.width,h=Math.round(l/t.getAspectRatio(i)),n={width:l,height:h};else if(n.height&&!n.width)h=n.height,n={width:l=Math.round(h*t.getAspectRatio(i)),height:h};else{if(isNaN(n))return void r.Error("Invalid 'size' parameter !");h=n,l=n}var u=i.getScene(),c=null;u.activeCamera!==i&&(c=u.activeCamera,u.activeCamera=i);var f=new e.RenderTargetTexture("screenShot",n,u,!1,!1,e.Engine.TEXTURETYPE_UNSIGNED_INT,!1,e.Texture.NEAREST_SAMPLINGMODE);f.renderList=null,f.samples=a,f.onAfterRenderObservable.add(function(){r.DumpFramebuffer(l,h,t,o,s)}),u.incrementRenderId(),u.resetCachedMaterial(),f.render(!0),f.dispose(),c&&(u.activeCamera=c),i.getProjectionMatrix(!0)},r.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 r=e.Internals.TGATools.GetTGAHeader(t.response);if(r.width&&r.height&&r.width>0&&r.height>0)return!0;if(2===i)return!1}if(4&i){var n=new Uint8Array(t.response,0,3);return 68===n[0]&&68===n[1]&&83===n[2]}}catch(e){}return!1},r.RandomId=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})},Object.defineProperty(r,"NoneLogLevel",{get:function(){return r._NoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"MessageLogLevel",{get:function(){return r._MessageLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"WarningLogLevel",{get:function(){return r._WarningLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ErrorLogLevel",{get:function(){return r._ErrorLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"AllLogLevel",{get:function(){return r._MessageLogLevel|r._WarningLogLevel|r._ErrorLogLevel},enumerable:!0,configurable:!0}),r._AddLogEntry=function(e){r._LogCache=e+r._LogCache,r.OnNewCacheEntry&&r.OnNewCacheEntry(e)},r._FormatMessage=function(e){var t=function(e){return e<10?"0"+e:""+e},i=new Date;return"["+t(i.getHours())+":"+t(i.getMinutes())+":"+t(i.getSeconds())+"]: "+e},r._LogDisabled=function(e){},r._LogEnabled=function(e){var t=r._FormatMessage(e);console.log("BJS - "+t),r._AddLogEntry("<div style='color:white'>"+t+"</div><br>")},r._WarnDisabled=function(e){},r._WarnEnabled=function(e){var t=r._FormatMessage(e);console.warn("BJS - "+t),r._AddLogEntry("<div style='color:orange'>"+t+"</div><br>")},r._ErrorDisabled=function(e){},r._ErrorEnabled=function(e){r.errorsCount++;var t=r._FormatMessage(e);console.error("BJS - "+t),r._AddLogEntry("<div style='color:red'>"+t+"</div><br>")},Object.defineProperty(r,"LogCache",{get:function(){return r._LogCache},enumerable:!0,configurable:!0}),r.ClearLogCache=function(){r._LogCache="",r.errorsCount=0},Object.defineProperty(r,"LogLevels",{set:function(e){r.Log=(e&r.MessageLogLevel)===r.MessageLogLevel?r._LogEnabled:r._LogDisabled,r.Warn=(e&r.WarningLogLevel)===r.WarningLogLevel?r._WarnEnabled:r._WarnDisabled,r.Error=(e&r.ErrorLogLevel)===r.ErrorLogLevel?r._ErrorEnabled:r._ErrorDisabled},enumerable:!0,configurable:!0}),r.IsWindowObjectExist=function(){return"undefined"!=typeof window},Object.defineProperty(r,"PerformanceNoneLogLevel",{get:function(){return r._PerformanceNoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"PerformanceUserMarkLogLevel",{get:function(){return r._PerformanceUserMarkLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"PerformanceConsoleLogLevel",{get:function(){return r._PerformanceConsoleLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"PerformanceLogLevel",{set:function(e){return(e&r.PerformanceUserMarkLogLevel)===r.PerformanceUserMarkLogLevel?(r.StartPerformanceCounter=r._StartUserMark,void(r.EndPerformanceCounter=r._EndUserMark)):(e&r.PerformanceConsoleLogLevel)===r.PerformanceConsoleLogLevel?(r.StartPerformanceCounter=r._StartPerformanceConsole,void(r.EndPerformanceCounter=r._EndPerformanceConsole)):(r.StartPerformanceCounter=r._StartPerformanceCounterDisabled,void(r.EndPerformanceCounter=r._EndPerformanceCounterDisabled))},enumerable:!0,configurable:!0}),r._StartPerformanceCounterDisabled=function(e,t){},r._EndPerformanceCounterDisabled=function(e,t){},r._StartUserMark=function(e,t){if(void 0===t&&(t=!0),!r._performance){if(!r.IsWindowObjectExist())return;r._performance=window.performance}t&&r._performance.mark&&r._performance.mark(e+"-Begin")},r._EndUserMark=function(e,t){void 0===t&&(t=!0),t&&r._performance.mark&&(r._performance.mark(e+"-End"),r._performance.measure(e,e+"-Begin",e+"-End"))},r._StartPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(r._StartUserMark(e,t),console.time&&console.time(e))},r._EndPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(r._EndUserMark(e,t),console.time&&console.timeEnd(e))},Object.defineProperty(r,"Now",{get:function(){return r.IsWindowObjectExist()&&window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},enumerable:!0,configurable:!0}),r.GetClassName=function(e,t){void 0===t&&(t=!1);var i=null;return!t&&e.getClassName?i=e.getClassName():(e instanceof Object&&(i=(t?e:Object.getPrototypeOf(e)).constructor.__bjsclassName__),i||(i=typeof e)),i},r.First=function(e,t){for(var i=0,r=e;i<r.length;i++){var n=r[i];if(t(n))return n}return null},r.getFullClassName=function(e,t){void 0===t&&(t=!1);var i=null,r=null;if(!t&&e.getClassName)i=e.getClassName();else{if(e instanceof Object){var n=t?e:Object.getPrototypeOf(e);i=n.constructor.__bjsclassName__,r=n.constructor.__bjsmoduleName__}i||(i=typeof e)}return i?(null!=r?r+".":"")+i:null},r.arrayOrStringFeeder=function(e){return function(t){if(t>=e.length)return null;var i=e.charCodeAt?e.charCodeAt(t):e[t];return i&&i.getHashCode&&(i=i.getHashCode()),"string"==typeof i?r.hashCodeFromStream(r.arrayOrStringFeeder(i)):i}},r.hashCodeFromStream=function(e){for(var t=0,i=0,r=e(i++);null!=r;)t=(t<<5)-t+r,t|=0,r=e(i++);return t},r.BaseUrl="",r.CorsBehavior="anonymous",r.UseFallbackTexture=!0,r.RegisteredExternalClasses={},r.fallbackTexture="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMC41AP/bAEMABAIDAwMCBAMDAwQEBAQFCQYFBQUFCwgIBgkNCw0NDQsMDA4QFBEODxMPDAwSGBITFRYXFxcOERkbGRYaFBYXFv/bAEMBBAQEBQUFCgYGChYPDA8WFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFv/AABEIAQABAAMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APH6KKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76P//Z",r.PreprocessUrl=function(e){return e},r._NoneLogLevel=0,r._MessageLogLevel=1,r._WarningLogLevel=2,r._ErrorLogLevel=4,r._LogCache="",r.errorsCount=0,r.Log=r._LogEnabled,r.Warn=r._WarnEnabled,r.Error=r._ErrorEnabled,r._PerformanceNoneLogLevel=0,r._PerformanceUserMarkLogLevel=1,r._PerformanceConsoleLogLevel=2,r.StartPerformanceCounter=r._StartPerformanceCounterDisabled,r.EndPerformanceCounter=r._EndPerformanceCounterDisabled,r}();e.Tools=r;var n=function(){function e(){this._startMonitoringTime=0,this._min=0,this._max=0,this._average=0,this._lastSecAverage=0,this._current=0,this._totalValueCount=0,this._totalAccumulated=0,this._lastSecAccumulated=0,this._lastSecTime=0,this._lastSecValueCount=0}return Object.defineProperty(e.prototype,"min",{get:function(){return this._min},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"max",{get:function(){return this._max},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"average",{get:function(){return this._average},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"lastSecAverage",{get:function(){return this._lastSecAverage},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"current",{get:function(){return this._current},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"total",{get:function(){return this._totalAccumulated},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"count",{get:function(){return this._totalValueCount},enumerable:!0,configurable:!0}),e.prototype.fetchNewFrame=function(){this._totalValueCount++,this._current=0,this._lastSecValueCount++},e.prototype.addCount=function(t,i){e.Enabled&&(this._current+=t,i&&this._fetchResult())},e.prototype.beginMonitoring=function(){e.Enabled&&(this._startMonitoringTime=r.Now)},e.prototype.endMonitoring=function(t){if(void 0===t&&(t=!0),e.Enabled){t&&this.fetchNewFrame();var i=r.Now;this._current=i-this._startMonitoringTime,t&&this._fetchResult()}},e.prototype._fetchResult=function(){this._totalAccumulated+=this._current,this._lastSecAccumulated+=this._current,this._min=Math.min(this._min,this._current),this._max=Math.max(this._max,this._current),this._average=this._totalAccumulated/this._totalValueCount;var e=r.Now;e-this._lastSecTime>1e3&&(this._lastSecAverage=this._lastSecAccumulated/this._lastSecValueCount,this._lastSecTime=e,this._lastSecAccumulated=0,this._lastSecValueCount=0)},e.Enabled=!0,e}();e.PerfCounter=n,e.className=function(e,t){return function(i){i.__bjsclassName__=e,i.__bjsmoduleName__=null!=t?t:null}};var o=function(){function e(e,t,i,r){void 0===r&&(r=0),this.iterations=e,this._fn=t,this._successCallback=i,this.index=r-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,r,n){void 0===n&&(n=0);var o=new e(t,i,r,n);return o.executeNext(),o},e.SyncAsyncForLoop=function(t,i,r,n,o,s){void 0===s&&(s=0),e.Run(Math.ceil(t/i),function(e){o&&o()?e.breakLoop():setTimeout(function(){for(var n=0;n<i;++n){var s=e.index*i+n;if(s>=t)break;if(r(s),o&&o()){e.breakLoop();break}}e.executeNext()},s)},n)},e}();e.AsyncLoop=o}(s||(s={}));!function(e){!function(e){var t=function(){function e(){this._isAlphaBlendDirty=!1,this._isBlendFunctionParametersDirty=!1,this._isBlendEquationParametersDirty=!1,this._isBlendConstantsDirty=!1,this._alphaBlend=!1,this._blendFunctionParameters=new Array(4),this._blendEquationParameters=new Array(2),this._blendConstants=new Array(4),this.reset()}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.setAlphaBlendConstants=function(e,t,i,r){this._blendConstants[0]===e&&this._blendConstants[1]===t&&this._blendConstants[2]===i&&this._blendConstants[3]===r||(this._blendConstants[0]=e,this._blendConstants[1]=t,this._blendConstants[2]=i,this._blendConstants[3]=r,this._isBlendConstantsDirty=!0)},e.prototype.setAlphaBlendFunctionParameters=function(e,t,i,r){this._blendFunctionParameters[0]===e&&this._blendFunctionParameters[1]===t&&this._blendFunctionParameters[2]===i&&this._blendFunctionParameters[3]===r||(this._blendFunctionParameters[0]=e,this._blendFunctionParameters[1]=t,this._blendFunctionParameters[2]=i,this._blendFunctionParameters[3]=r,this._isBlendFunctionParametersDirty=!0)},e.prototype.setAlphaEquationParameters=function(e,t){this._blendEquationParameters[0]===e&&this._blendEquationParameters[1]===t||(this._blendEquationParameters[0]=e,this._blendEquationParameters[1]=t,this._isBlendEquationParametersDirty=!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._blendEquationParameters[0]=null,this._blendEquationParameters[1]=null,this._blendConstants[0]=null,this._blendConstants[1]=null,this._blendConstants[2]=null,this._blendConstants[3]=null,this._isAlphaBlendDirty=!0,this._isBlendFunctionParametersDirty=!1,this._isBlendEquationParametersDirty=!1,this._isBlendConstantsDirty=!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),this._isBlendEquationParametersDirty&&(e.blendEquationSeparate(this._isBlendEquationParametersDirty[0],this._isBlendEquationParametersDirty[1]),this._isBlendEquationParametersDirty=!1),this._isBlendConstantsDirty&&(e.blendColor(this._blendConstants[0],this._blendConstants[1],this._blendConstants[2],this._blendConstants[3]),this._isBlendConstantsDirty=!1))},e}();e._AlphaState=t}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){!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,this.reset()}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._cullFace=null,this._cull=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}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){!function(t){var i=function(){function t(){this._isStencilTestDirty=!1,this._isStencilMaskDirty=!1,this._isStencilFuncDirty=!1,this._isStencilOpDirty=!1,this.reset()}return Object.defineProperty(t.prototype,"isDirty",{get:function(){return this._isStencilTestDirty||this._isStencilMaskDirty||this._isStencilFuncDirty||this._isStencilOpDirty},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stencilFunc",{get:function(){return this._stencilFunc},set:function(e){this._stencilFunc!==e&&(this._stencilFunc=e,this._isStencilFuncDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stencilFuncRef",{get:function(){return this._stencilFuncRef},set:function(e){this._stencilFuncRef!==e&&(this._stencilFuncRef=e,this._isStencilFuncDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stencilFuncMask",{get:function(){return this._stencilFuncMask},set:function(e){this._stencilFuncMask!==e&&(this._stencilFuncMask=e,this._isStencilFuncDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stencilOpStencilFail",{get:function(){return this._stencilOpStencilFail},set:function(e){this._stencilOpStencilFail!==e&&(this._stencilOpStencilFail=e,this._isStencilOpDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stencilOpDepthFail",{get:function(){return this._stencilOpDepthFail},set:function(e){this._stencilOpDepthFail!==e&&(this._stencilOpDepthFail=e,this._isStencilOpDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stencilOpStencilDepthPass",{get:function(){return this._stencilOpStencilDepthPass},set:function(e){this._stencilOpStencilDepthPass!==e&&(this._stencilOpStencilDepthPass=e,this._isStencilOpDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stencilMask",{get:function(){return this._stencilMask},set:function(e){this._stencilMask!==e&&(this._stencilMask=e,this._isStencilMaskDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stencilTest",{get:function(){return this._stencilTest},set:function(e){this._stencilTest!==e&&(this._stencilTest=e,this._isStencilTestDirty=!0)},enumerable:!0,configurable:!0}),t.prototype.reset=function(){this._stencilTest=!1,this._stencilMask=255,this._stencilFunc=e.Engine.ALWAYS,this._stencilFuncRef=1,this._stencilFuncMask=255,this._stencilOpStencilFail=e.Engine.KEEP,this._stencilOpDepthFail=e.Engine.KEEP,this._stencilOpStencilDepthPass=e.Engine.REPLACE,this._isStencilTestDirty=!0,this._isStencilMaskDirty=!0,this._isStencilFuncDirty=!0,this._isStencilOpDirty=!0},t.prototype.apply=function(e){this.isDirty&&(this._isStencilTestDirty&&(this.stencilTest?e.enable(e.STENCIL_TEST):e.disable(e.STENCIL_TEST),this._isStencilTestDirty=!1),this._isStencilMaskDirty&&(e.stencilMask(this.stencilMask),this._isStencilMaskDirty=!1),this._isStencilFuncDirty&&(e.stencilFunc(this.stencilFunc,this.stencilFuncRef,this.stencilFuncMask),this._isStencilFuncDirty=!1),this._isStencilOpDirty&&(e.stencilOp(this.stencilOpStencilFail,this.stencilOpDepthFail,this.stencilOpStencilDepthPass),this._isStencilOpDirty=!1))},t}();t._StencilState=i}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){var t=function(e,t,r,n,o){return i(e,o+(n?n+"\n":"")+t,r)},i=function(e,t,i){var r=e.createShader("vertex"===i?e.VERTEX_SHADER:e.FRAGMENT_SHADER);if(e.shaderSource(r,t),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)){var n=e.getShaderInfoLog(r);if(n)throw new Error(n)}if(!r)throw new Error("Something went wrong while compile the shader.");return r},r=function(t,i,r){var n=r.NEAREST,o=r.NEAREST;switch(t){case e.Texture.BILINEAR_SAMPLINGMODE:n=r.LINEAR,o=i?r.LINEAR_MIPMAP_NEAREST:r.LINEAR;break;case e.Texture.TRILINEAR_SAMPLINGMODE:n=r.LINEAR,o=i?r.LINEAR_MIPMAP_LINEAR:r.LINEAR;break;case e.Texture.NEAREST_SAMPLINGMODE:n=r.NEAREST,o=i?r.NEAREST_MIPMAP_LINEAR:r.NEAREST;break;case e.Texture.NEAREST_NEAREST_MIPNEAREST:n=r.NEAREST,o=i?r.NEAREST_MIPMAP_NEAREST:r.NEAREST;break;case e.Texture.NEAREST_LINEAR_MIPNEAREST:n=r.NEAREST,o=i?r.LINEAR_MIPMAP_NEAREST:r.LINEAR;break;case e.Texture.NEAREST_LINEAR_MIPLINEAR:n=r.NEAREST,o=i?r.LINEAR_MIPMAP_LINEAR:r.LINEAR;break;case e.Texture.NEAREST_LINEAR:n=r.NEAREST,o=r.LINEAR;break;case e.Texture.NEAREST_NEAREST:n=r.NEAREST,o=r.NEAREST;break;case e.Texture.LINEAR_NEAREST_MIPNEAREST:n=r.LINEAR,o=i?r.NEAREST_MIPMAP_NEAREST:r.NEAREST;break;case e.Texture.LINEAR_NEAREST_MIPLINEAR:n=r.LINEAR,o=i?r.NEAREST_MIPMAP_LINEAR:r.NEAREST;break;case e.Texture.LINEAR_LINEAR:n=r.LINEAR,o=r.LINEAR;break;case e.Texture.LINEAR_NEAREST:n=r.LINEAR,o=r.NEAREST}return{min:o,mag:n}},n=function(t,i,r,n,o,s){void 0===s&&(s=null);var a;a=e.Tools.LoadImage(t,function(){r[i]=a,r._internalCount++,n&&n._removePendingData(a),6===r._internalCount&&o(r)},function(e,t){n&&n._removePendingData(a),s&&s(e,t)},n?n.database:null),n&&n._addPendingData(a)},o=function(e,t,i,r,o){void 0===o&&(o=null);var s=[];s._internalCount=0;for(var a=0;a<6;a++)n(r[a],a,s,t,i,o)},s=function(){return function(){}}(),a=function(){return function(){}}();e.InstancingAttributeInfo=a;var l=function(){return function(){}}();e.RenderTargetCreationOptions=l;var h=function(){return function(){}}();e.EngineCapabilities=h;var u=function(){function n(t,i,r,o){void 0===o&&(o=!1);var a=this;this.forcePOTTextures=!1,this.isFullscreen=!1,this.isPointerLock=!1,this.cullBackFaces=!0,this.renderEvenInBackground=!0,this.preventCacheWipeBetweenFrames=!1,this.enableOfflineSupport=!1,this.scenes=new Array,this.postProcesses=new Array,this.onResizeObservable=new e.Observable,this.onCanvasBlurObservable=new e.Observable,this.onCanvasFocusObservable=new e.Observable,this.onCanvasPointerOutObservable=new e.Observable,this.onBeforeTextureInitObservable=new e.Observable,this._vrDisplay=void 0,this._vrSupported=!1,this._vrExclusivePointerMode=!1,this.disableUniformBuffers=!1,this._uniformBuffers=new Array,this.onBeginFrameObservable=new e.Observable,this.onEndFrameObservable=new e.Observable,this.onBeforeShaderCompilationObservable=new e.Observable,this.onAfterShaderCompilationObservable=new e.Observable,this._windowIsBackground=!1,this._webGLVersion=1,this._badOS=!1,this._badDesktopOS=!1,this.onVRDisplayChangedObservable=new e.Observable,this.onVRRequestPresentComplete=new e.Observable,this.onVRRequestPresentStart=new e.Observable,this._colorWrite=!0,this._drawCalls=new e.PerfCounter,this._renderingQueueLaunched=!1,this._activeRenderLoops=new Array,this._deterministicLockstep=!1,this._lockstepMaxSteps=4,this.onContextLostObservable=new e.Observable,this.onContextRestoredObservable=new e.Observable,this._contextWasLost=!1,this._doNotHandleContextLost=!1,this._performanceMonitor=new e.PerformanceMonitor,this._fps=60,this._deltaTime=0,this.disablePerformanceMonitorInBackground=!1,this._depthCullingState=new e.Internals._DepthCullingState,this._stencilState=new e.Internals._StencilState,this._alphaState=new e.Internals._AlphaState,this._alphaMode=n.ALPHA_DISABLE,this._internalTexturesCache=new Array,this._activeTexturesCache={},this._compiledEffects={},this._vertexAttribArraysEnabled=[],this._uintIndicesCurrentlySet=!1,this._currentBoundBuffer=new Array,this._currentBufferPointers=new Array,this._currentInstanceLocations=new Array,this._currentInstanceBuffers=new Array,this._vaoRecordInProgress=!1,this._mustWipeVertexAttributes=!1,this._texturesSupported=new Array,this._onVRFullScreenTriggered=function(){if(a._vrDisplay&&a._vrDisplay.isPresenting){a._oldSize=new e.Size(a.getRenderWidth(),a.getRenderHeight()),a._oldHardwareScaleFactor=a.getHardwareScalingLevel();var t=a._vrDisplay.getEyeParameters("left");a.setHardwareScalingLevel(1),a.setSize(2*t.renderWidth,t.renderHeight)}else a.setHardwareScalingLevel(a._oldHardwareScaleFactor),a.setSize(a._oldSize.width,a._oldSize.height)};var l=null;if(n.Instances.push(this),t){if(r=r||{},t.getContext){if(l=t,this._renderingCanvas=l,null!=i&&(r.antialias=i),void 0===r.deterministicLockstep&&(r.deterministicLockstep=!1),void 0===r.lockstepMaxSteps&&(r.lockstepMaxSteps=4),void 0===r.preserveDrawingBuffer&&(r.preserveDrawingBuffer=!1),void 0===r.audioEngine&&(r.audioEngine=!0),void 0===r.stencil&&(r.stencil=!0),this._deterministicLockstep=r.deterministicLockstep,this._lockstepMaxSteps=r.lockstepMaxSteps,this._doNotHandleContextLost=!!r.doNotHandleContextLost,!r.disableWebGL2Support)try{this._gl=l.getContext("webgl2",r)||l.getContext("experimental-webgl2",r),this._gl&&(this._webGLVersion=2)}catch(e){}if(!this._gl){if(!l)throw new Error("The provided canvas is null or undefined.");try{this._gl=l.getContext("webgl",r)||l.getContext("experimental-webgl",r)}catch(e){throw new Error("WebGL not supported")}}if(!this._gl)throw new Error("WebGL not supported");this._onCanvasFocus=function(){a.onCanvasFocusObservable.notifyObservers(a)},this._onCanvasBlur=function(){a.onCanvasBlurObservable.notifyObservers(a)},l.addEventListener("focus",this._onCanvasFocus),l.addEventListener("blur",this._onCanvasBlur),this._onBlur=function(){a.disablePerformanceMonitorInBackground&&a._performanceMonitor.disable(),a._windowIsBackground=!0},this._onFocus=function(){a.disablePerformanceMonitorInBackground&&a._performanceMonitor.enable(),a._windowIsBackground=!1},this._onCanvasPointerOut=function(){a.onCanvasPointerOutObservable.notifyObservers(a)},window.addEventListener("blur",this._onBlur),window.addEventListener("focus",this._onFocus),l.addEventListener("pointerout",this._onCanvasPointerOut),this._doNotHandleContextLost||(this._onContextLost=function(t){t.preventDefault(),a._contextWasLost=!0,e.Tools.Warn("WebGL context lost."),a.onContextLostObservable.notifyObservers(a)},this._onContextRestored=function(t){setTimeout(function(){a._initGLContext(),a._rebuildEffects(),a._rebuildInternalTextures(),a._rebuildBuffers(),a.wipeCaches(!0),e.Tools.Warn("WebGL context successfully restored."),a.onContextRestoredObservable.notifyObservers(a),a._contextWasLost=!1},0)},l.addEventListener("webglcontextlost",this._onContextLost,!1),l.addEventListener("webglcontextrestored",this._onContextRestored,!1))}else this._gl=t,this._renderingCanvas=this._gl.canvas,this._gl.renderbufferStorageMultisample&&(this._webGLVersion=2),r.stencil=this._gl.getContextAttributes().stencil;var h=r.limitDeviceRatio||window.devicePixelRatio||1;this._hardwareScalingLevel=o?1/Math.min(h,window.devicePixelRatio||1):1,this.resize(),this._isStencilEnable=!!r.stencil,this._initGLContext(),l&&(this._onFullscreenChange=function(){void 0!==document.fullscreen?a.isFullscreen=document.fullscreen:void 0!==document.mozFullScreen?a.isFullscreen=document.mozFullScreen:void 0!==document.webkitIsFullScreen?a.isFullscreen=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(a.isFullscreen=document.msIsFullScreen),a.isFullscreen&&a._pointerLockRequested&&l&&(l.requestPointerLock=l.requestPointerLock||l.msRequestPointerLock||l.mozRequestPointerLock||l.webkitRequestPointerLock,l.requestPointerLock&&l.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(){a.isPointerLock=document.mozPointerLockElement===l||document.webkitPointerLockElement===l||document.msPointerLockElement===l||document.pointerLockElement===l},document.addEventListener("pointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mspointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mozpointerlockchange",this._onPointerLockChange,!1),document.addEventListener("webkitpointerlockchange",this._onPointerLockChange,!1),this._onVRDisplayPointerRestricted=function(){l&&l.requestPointerLock()},this._onVRDisplayPointerUnrestricted=function(){document.exitPointerLock()},window.addEventListener("vrdisplaypointerrestricted",this._onVRDisplayPointerRestricted,!1),window.addEventListener("vrdisplaypointerunrestricted",this._onVRDisplayPointerUnrestricted,!1)),r.audioEngine&&e.AudioEngine&&!n.audioEngine&&(n.audioEngine=new e.AudioEngine);for(var u=0;u<this._caps.maxVertexAttribs;u++)this._currentBufferPointers[u]=new s;r.autoEnableWebVR&&this.initWebVR(),this._badOS=/iPad/i.test(navigator.userAgent)||/iPhone/i.test(navigator.userAgent),this._badDesktopOS=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),e.Tools.Log("Babylon.js engine (v"+n.Version+") launched"),this.enableOfflineSupport=void 0!==e.Database}}return Object.defineProperty(n,"LastCreatedEngine",{get:function(){return 0===n.Instances.length?null:n.Instances[n.Instances.length-1]},enumerable:!0,configurable:!0}),Object.defineProperty(n,"LastCreatedScene",{get:function(){var e=n.LastCreatedEngine;return e?0===e.scenes.length?null:e.scenes[e.scenes.length-1]:null},enumerable:!0,configurable:!0}),n.MarkAllMaterialsAsDirty=function(e,t){for(var i=0;i<n.Instances.length;i++)for(var r=n.Instances[i],o=0;o<r.scenes.length;o++)r.scenes[o].markAllMaterialsAsDirty(e,t)},Object.defineProperty(n,"NEVER",{get:function(){return n._NEVER},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALWAYS",{get:function(){return n._ALWAYS},enumerable:!0,configurable:!0}),Object.defineProperty(n,"LESS",{get:function(){return n._LESS},enumerable:!0,configurable:!0}),Object.defineProperty(n,"EQUAL",{get:function(){return n._EQUAL},enumerable:!0,configurable:!0}),Object.defineProperty(n,"LEQUAL",{get:function(){return n._LEQUAL},enumerable:!0,configurable:!0}),Object.defineProperty(n,"GREATER",{get:function(){return n._GREATER},enumerable:!0,configurable:!0}),Object.defineProperty(n,"GEQUAL",{get:function(){return n._GEQUAL},enumerable:!0,configurable:!0}),Object.defineProperty(n,"NOTEQUAL",{get:function(){return n._NOTEQUAL},enumerable:!0,configurable:!0}),Object.defineProperty(n,"KEEP",{get:function(){return n._KEEP},enumerable:!0,configurable:!0}),Object.defineProperty(n,"REPLACE",{get:function(){return n._REPLACE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"INCR",{get:function(){return n._INCR},enumerable:!0,configurable:!0}),Object.defineProperty(n,"DECR",{get:function(){return n._DECR},enumerable:!0,configurable:!0}),Object.defineProperty(n,"INVERT",{get:function(){return n._INVERT},enumerable:!0,configurable:!0}),Object.defineProperty(n,"INCR_WRAP",{get:function(){return n._INCR_WRAP},enumerable:!0,configurable:!0}),Object.defineProperty(n,"DECR_WRAP",{get:function(){return n._DECR_WRAP},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALPHA_DISABLE",{get:function(){return n._ALPHA_DISABLE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALPHA_ONEONE",{get:function(){return n._ALPHA_ONEONE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALPHA_ADD",{get:function(){return n._ALPHA_ADD},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALPHA_COMBINE",{get:function(){return n._ALPHA_COMBINE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALPHA_SUBTRACT",{get:function(){return n._ALPHA_SUBTRACT},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALPHA_MULTIPLY",{get:function(){return n._ALPHA_MULTIPLY},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALPHA_MAXIMIZED",{get:function(){return n._ALPHA_MAXIMIZED},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALPHA_PREMULTIPLIED",{get:function(){return n._ALPHA_PREMULTIPLIED},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALPHA_PREMULTIPLIED_PORTERDUFF",{get:function(){return n._ALPHA_PREMULTIPLIED_PORTERDUFF},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALPHA_INTERPOLATE",{get:function(){return n._ALPHA_INTERPOLATE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"ALPHA_SCREENMODE",{get:function(){return n._ALPHA_SCREENMODE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"DELAYLOADSTATE_NONE",{get:function(){return n._DELAYLOADSTATE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"DELAYLOADSTATE_LOADED",{get:function(){return n._DELAYLOADSTATE_LOADED},enumerable:!0,configurable:!0}),Object.defineProperty(n,"DELAYLOADSTATE_LOADING",{get:function(){return n._DELAYLOADSTATE_LOADING},enumerable:!0,configurable:!0}),Object.defineProperty(n,"DELAYLOADSTATE_NOTLOADED",{get:function(){return n._DELAYLOADSTATE_NOTLOADED},enumerable:!0,configurable:!0}),Object.defineProperty(n,"TEXTUREFORMAT_ALPHA",{get:function(){return n._TEXTUREFORMAT_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(n,"TEXTUREFORMAT_LUMINANCE",{get:function(){return n._TEXTUREFORMAT_LUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(n,"TEXTUREFORMAT_LUMINANCE_ALPHA",{get:function(){return n._TEXTUREFORMAT_LUMINANCE_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(n,"TEXTUREFORMAT_RGB",{get:function(){return n._TEXTUREFORMAT_RGB},enumerable:!0,configurable:!0}),Object.defineProperty(n,"TEXTUREFORMAT_RGBA",{get:function(){return n._TEXTUREFORMAT_RGBA},enumerable:!0,configurable:!0}),Object.defineProperty(n,"TEXTURETYPE_UNSIGNED_INT",{get:function(){return n._TEXTURETYPE_UNSIGNED_INT},enumerable:!0,configurable:!0}),Object.defineProperty(n,"TEXTURETYPE_FLOAT",{get:function(){return n._TEXTURETYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(n,"TEXTURETYPE_HALF_FLOAT",{get:function(){return n._TEXTURETYPE_HALF_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(n,"SCALEMODE_FLOOR",{get:function(){return n._SCALEMODE_FLOOR},enumerable:!0,configurable:!0}),Object.defineProperty(n,"SCALEMODE_NEAREST",{get:function(){return n._SCALEMODE_NEAREST},enumerable:!0,configurable:!0}),Object.defineProperty(n,"SCALEMODE_CEILING",{get:function(){return n._SCALEMODE_CEILING},enumerable:!0,configurable:!0}),Object.defineProperty(n,"Version",{get:function(){return"3.1-beta-3"},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isInVRExclusivePointerMode",{get:function(){return this._vrExclusivePointerMode},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"supportsUniformBuffers",{get:function(){return this.webGLVersion>1&&!this.disableUniformBuffers},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"needPOTTextures",{get:function(){return this._webGLVersion<2||this.forcePOTTextures},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"badOS",{get:function(){return this._badOS},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"badDesktopOS",{get:function(){return this._badDesktopOS},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"performanceMonitor",{get:function(){return this._performanceMonitor},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"texturesSupported",{get:function(){return this._texturesSupported},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"textureFormatInUse",{get:function(){return this._textureFormatInUse},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"currentViewport",{get:function(){return this._cachedViewport},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"emptyTexture",{get:function(){return this._emptyTexture||(this._emptyTexture=this.createRawTexture(new Uint8Array(4),1,1,e.Engine.TEXTUREFORMAT_RGBA,!1,!1,e.Texture.NEAREST_SAMPLINGMODE)),this._emptyTexture},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"emptyTexture3D",{get:function(){return this._emptyTexture3D||(this._emptyTexture3D=this.createRawTexture3D(new Uint8Array(4),1,1,1,e.Engine.TEXTUREFORMAT_RGBA,!1,!1,e.Texture.NEAREST_SAMPLINGMODE)),this._emptyTexture3D},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"emptyCubeTexture",{get:function(){if(!this._emptyCubeTexture){var t=new Uint8Array(4),i=[t,t,t,t,t,t];this._emptyCubeTexture=this.createRawCubeTexture(i,1,e.Engine.TEXTUREFORMAT_RGBA,e.Engine.TEXTURETYPE_UNSIGNED_INT,!1,!1,e.Texture.NEAREST_SAMPLINGMODE)}return this._emptyCubeTexture},enumerable:!0,configurable:!0}),n.prototype._rebuildInternalTextures=function(){for(var e=0,t=this._internalTexturesCache.slice();e<t.length;e++)t[e]._rebuild()},n.prototype._rebuildEffects=function(){for(var t in this._compiledEffects)this._compiledEffects[t]._prepareEffect();e.Effect.ResetCache()},n.prototype._rebuildBuffers=function(){for(var e=0,t=this.scenes;e<t.length;e++){var i=t[e];i.resetCachedMaterial(),i._rebuildGeometries(),i._rebuildTextures()}for(var r=0,n=this._uniformBuffers;r<n.length;r++)n[r]._rebuild()},n.prototype._initGLContext=function(){this._caps=new h,this._caps.maxTexturesImageUnits=this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS),this._caps.maxVertexTextureImageUnits=this._gl.getParameter(this._gl.MAX_VERTEX_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._caps.maxVertexAttribs=this._gl.getParameter(this._gl.MAX_VERTEX_ATTRIBS),this._caps.maxVaryingVectors=this._gl.getParameter(this._gl.MAX_VARYING_VECTORS),this._caps.maxFragmentUniformVectors=this._gl.getParameter(this._gl.MAX_FRAGMENT_UNIFORM_VECTORS),this._caps.maxVertexUniformVectors=this._gl.getParameter(this._gl.MAX_VERTEX_UNIFORM_VECTORS),this._glVersion=this._gl.getParameter(this._gl.VERSION);var e=this._gl.getExtension("WEBGL_debug_renderer_info");if(null!=e&&(this._glRenderer=this._gl.getParameter(e.UNMASKED_RENDERER_WEBGL),this._glVendor=this._gl.getParameter(e.UNMASKED_VENDOR_WEBGL)),this._glVendor||(this._glVendor="Unknown vendor"),this._glRenderer||(this._glRenderer="Unknown renderer"),this._gl.HALF_FLOAT_OES=36193,34842!==this._gl.RGBA16F&&(this._gl.RGBA16F=34842),34836!==this._gl.RGBA32F&&(this._gl.RGBA32F=34836),35056!==this._gl.DEPTH24_STENCIL8&&(this._gl.DEPTH24_STENCIL8=35056),this._caps.standardDerivatives=this._webGLVersion>1||null!==this._gl.getExtension("OES_standard_derivatives"),this._caps.astc=this._gl.getExtension("WEBGL_compressed_texture_astc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_astc"),this._caps.s3tc=this._gl.getExtension("WEBGL_compressed_texture_s3tc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc"),this._caps.pvrtc=this._gl.getExtension("WEBGL_compressed_texture_pvrtc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),this._caps.etc1=this._gl.getExtension("WEBGL_compressed_texture_etc1")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc1"),this._caps.etc2=this._gl.getExtension("WEBGL_compressed_texture_etc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc")||this._gl.getExtension("WEBGL_compressed_texture_es3_0"),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.uintIndices=this._webGLVersion>1||null!==this._gl.getExtension("OES_element_index_uint"),this._caps.fragmentDepthSupported=this._webGLVersion>1||null!==this._gl.getExtension("EXT_frag_depth"),this._caps.highPrecisionShaderSupported=!0,this._caps.timerQuery=this._gl.getExtension("EXT_disjoint_timer_query_webgl2")||this._gl.getExtension("EXT_disjoint_timer_query"),this._caps.timerQuery&&(1===this._webGLVersion&&(this._gl.getQuery=this._caps.timerQuery.getQueryEXT.bind(this._caps.timerQuery)),this._caps.canUseTimestampForTimerQuery=this._gl.getQuery(this._caps.timerQuery.TIMESTAMP_EXT,this._caps.timerQuery.QUERY_COUNTER_BITS_EXT)>0),this._caps.colorBufferFloat=this._webGLVersion>1&&this._gl.getExtension("EXT_color_buffer_float"),this._caps.textureFloat=this._webGLVersion>1||this._gl.getExtension("OES_texture_float"),this._caps.textureFloatLinearFiltering=this._caps.textureFloat&&this._gl.getExtension("OES_texture_float_linear"),this._caps.textureFloatRender=this._caps.textureFloat&&this._canRenderToFloatFramebuffer(),this._caps.textureHalfFloat=this._webGLVersion>1||this._gl.getExtension("OES_texture_half_float"),this._caps.textureHalfFloatLinearFiltering=this._webGLVersion>1||this._caps.textureHalfFloat&&this._gl.getExtension("OES_texture_half_float_linear"),this._webGLVersion>1&&(this._gl.HALF_FLOAT_OES=5131),this._caps.textureHalfFloatRender=this._caps.textureHalfFloat&&this._canRenderToHalfFloatFramebuffer(),this._caps.textureLOD=this._webGLVersion>1||this._gl.getExtension("EXT_shader_texture_lod"),this._webGLVersion>1)this._caps.drawBuffersExtension=!0;else{var t=this._gl.getExtension("WEBGL_draw_buffers");if(null!==t){this._caps.drawBuffersExtension=!0,this._gl.drawBuffers=t.drawBuffersWEBGL.bind(t),this._gl.DRAW_FRAMEBUFFER=this._gl.FRAMEBUFFER;for(var i=0;i<16;i++)this._gl["COLOR_ATTACHMENT"+i+"_WEBGL"]=t["COLOR_ATTACHMENT"+i+"_WEBGL"]}else this._caps.drawBuffersExtension=!1}if(this._webGLVersion>1?this._caps.depthTextureExtension=!0:null!=this._gl.getExtension("WEBGL_depth_texture")&&(this._caps.depthTextureExtension=!0),this._webGLVersion>1)this._caps.vertexArrayObject=!0;else{var r=this._gl.getExtension("OES_vertex_array_object");null!=r?(this._caps.vertexArrayObject=!0,this._gl.createVertexArray=r.createVertexArrayOES.bind(r),this._gl.bindVertexArray=r.bindVertexArrayOES.bind(r),this._gl.deleteVertexArray=r.deleteVertexArrayOES.bind(r)):this._caps.vertexArrayObject=!1}if(this._webGLVersion>1)this._caps.instancedArrays=!0;else{var n=this._gl.getExtension("ANGLE_instanced_arrays");null!=n?(this._caps.instancedArrays=!0,this._gl.drawArraysInstanced=n.drawArraysInstancedANGLE.bind(n),this._gl.drawElementsInstanced=n.drawElementsInstancedANGLE.bind(n),this._gl.vertexAttribDivisor=n.vertexAttribDivisorANGLE.bind(n)):this._caps.instancedArrays=!1}if(this._caps.astc&&this.texturesSupported.push("-astc.ktx"),this._caps.s3tc&&this.texturesSupported.push("-dxt.ktx"),this._caps.pvrtc&&this.texturesSupported.push("-pvrtc.ktx"),this._caps.etc2&&this.texturesSupported.push("-etc2.ktx"),this._caps.etc1&&this.texturesSupported.push("-etc1.ktx"),this._gl.getShaderPrecisionFormat){var o=this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER,this._gl.HIGH_FLOAT);o&&(this._caps.highPrecisionShaderSupported=0!==o.precision)}this.setDepthBuffer(!0),this.setDepthFunctionToLessOrEqual(),this.setDepthWrite(!0)},Object.defineProperty(n.prototype,"webGLVersion",{get:function(){return this._webGLVersion},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isStencilEnable",{get:function(){return this._isStencilEnable},enumerable:!0,configurable:!0}),n.prototype._prepareWorkingCanvas=function(){if(!this._workingCanvas){this._workingCanvas=document.createElement("canvas");var e=this._workingCanvas.getContext("2d");e&&(this._workingContext=e)}},n.prototype.resetTextureCache=function(){for(var e in this._activeTexturesCache)this._activeTexturesCache[e]=null},n.prototype.isDeterministicLockStep=function(){return this._deterministicLockstep},n.prototype.getLockstepMaxSteps=function(){return this._lockstepMaxSteps},n.prototype.getGlInfo=function(){return{vendor:this._glVendor,renderer:this._glRenderer,version:this._glVersion}},n.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)},n.prototype.getRenderWidth=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget.width:this._gl.drawingBufferWidth},n.prototype.getRenderHeight=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget.height:this._gl.drawingBufferHeight},n.prototype.getRenderingCanvas=function(){return this._renderingCanvas},n.prototype.getRenderingCanvasClientRect=function(){return this._renderingCanvas?this._renderingCanvas.getBoundingClientRect():null},n.prototype.setHardwareScalingLevel=function(e){this._hardwareScalingLevel=e,this.resize()},n.prototype.getHardwareScalingLevel=function(){return this._hardwareScalingLevel},n.prototype.getLoadedTexturesCache=function(){return this._internalTexturesCache},n.prototype.getCaps=function(){return this._caps},Object.defineProperty(n.prototype,"drawCalls",{get:function(){return e.Tools.Warn("drawCalls is deprecated. Please use SceneInstrumentation class"),0},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"drawCallsPerfCounter",{get:function(){return e.Tools.Warn("drawCallsPerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),n.prototype.getDepthFunction=function(){return this._depthCullingState.depthFunc},n.prototype.setDepthFunction=function(e){this._depthCullingState.depthFunc=e},n.prototype.setDepthFunctionToGreater=function(){this._depthCullingState.depthFunc=this._gl.GREATER},n.prototype.setDepthFunctionToGreaterOrEqual=function(){this._depthCullingState.depthFunc=this._gl.GEQUAL},n.prototype.setDepthFunctionToLess=function(){this._depthCullingState.depthFunc=this._gl.LESS},n.prototype.setDepthFunctionToLessOrEqual=function(){this._depthCullingState.depthFunc=this._gl.LEQUAL},n.prototype.getStencilBuffer=function(){return this._stencilState.stencilTest},n.prototype.setStencilBuffer=function(e){this._stencilState.stencilTest=e},n.prototype.getStencilMask=function(){return this._stencilState.stencilMask},n.prototype.setStencilMask=function(e){this._stencilState.stencilMask=e},n.prototype.getStencilFunction=function(){return this._stencilState.stencilFunc},n.prototype.getStencilFunctionReference=function(){return this._stencilState.stencilFuncRef},n.prototype.getStencilFunctionMask=function(){return this._stencilState.stencilFuncMask},n.prototype.setStencilFunction=function(e){this._stencilState.stencilFunc=e},n.prototype.setStencilFunctionReference=function(e){this._stencilState.stencilFuncRef=e},n.prototype.setStencilFunctionMask=function(e){this._stencilState.stencilFuncMask=e},n.prototype.getStencilOperationFail=function(){return this._stencilState.stencilOpStencilFail},n.prototype.getStencilOperationDepthFail=function(){return this._stencilState.stencilOpDepthFail},n.prototype.getStencilOperationPass=function(){return this._stencilState.stencilOpStencilDepthPass},n.prototype.setStencilOperationFail=function(e){this._stencilState.stencilOpStencilFail=e},n.prototype.setStencilOperationDepthFail=function(e){this._stencilState.stencilOpDepthFail=e},n.prototype.setStencilOperationPass=function(e){this._stencilState.stencilOpStencilDepthPass=e},n.prototype.setDitheringState=function(e){e?this._gl.enable(this._gl.DITHER):this._gl.disable(this._gl.DITHER)},n.prototype.setRasterizerState=function(e){e?this._gl.disable(this._gl.RASTERIZER_DISCARD):this._gl.enable(this._gl.RASTERIZER_DISCARD)},n.prototype.stopRenderLoop=function(e){if(e){var t=this._activeRenderLoops.indexOf(e);t>=0&&this._activeRenderLoops.splice(t,1)}else this._activeRenderLoops=[]},n.prototype._renderLoop=function(){if(!this._contextWasLost){var t=!0;if(!this.renderEvenInBackground&&this._windowIsBackground&&(t=!1),t){this.beginFrame();for(var i=0;i<this._activeRenderLoops.length;i++)(0,this._activeRenderLoops[i])();this.endFrame()}}if(this._activeRenderLoops.length>0){var r=null;this._vrDisplay&&this._vrDisplay.isPresenting&&(r=this._vrDisplay),this._frameHandler=e.Tools.QueueNewFrame(this._bindedRenderFunction,r)}else this._renderingQueueLaunched=!1},n.prototype.runRenderLoop=function(t){-1===this._activeRenderLoops.indexOf(t)&&(this._activeRenderLoops.push(t),this._renderingQueueLaunched||(this._renderingQueueLaunched=!0,this._bindedRenderFunction=this._renderLoop.bind(this),this._frameHandler=e.Tools.QueueNewFrame(this._bindedRenderFunction)))},n.prototype.switchFullscreen=function(t){this.isFullscreen?e.Tools.ExitFullscreen():(this._pointerLockRequested=t,this._renderingCanvas&&e.Tools.RequestFullscreen(this._renderingCanvas))},n.prototype.clear=function(e,t,i,r){void 0===r&&(r=!1),this.applyStates();var n=0;t&&e&&(this._gl.clearColor(e.r,e.g,e.b,void 0!==e.a?e.a:1),n|=this._gl.COLOR_BUFFER_BIT),i&&(this._gl.clearDepth(1),n|=this._gl.DEPTH_BUFFER_BIT),r&&(this._gl.clearStencil(0),n|=this._gl.STENCIL_BUFFER_BIT),this._gl.clear(n)},n.prototype.scissorClear=function(e,t,i,r,n){var o=this._gl,s=o.getParameter(o.SCISSOR_TEST),a=o.getParameter(o.SCISSOR_BOX);o.enable(o.SCISSOR_TEST),o.scissor(e,t,i,r),this.clear(n,!0,!0,!0),o.scissor(a[0],a[1],a[2],a[3]),!0===s?o.enable(o.SCISSOR_TEST):o.disable(o.SCISSOR_TEST)},n.prototype.setViewport=function(e,t,i){var r=t||this.getRenderWidth(),n=i||this.getRenderHeight(),o=e.x||0,s=e.y||0;this._cachedViewport=e,this._gl.viewport(o*r,s*n,r*e.width,n*e.height)},n.prototype.setDirectViewport=function(e,t,i,r){var n=this._cachedViewport;return this._cachedViewport=null,this._gl.viewport(e,t,i,r),n},n.prototype.beginFrame=function(){this.onBeginFrameObservable.notifyObservers(this),this._measureFps()},n.prototype.endFrame=function(){this._badOS&&this.flushFramebuffer(),this._vrDisplay&&this._vrDisplay.isPresenting&&this._vrDisplay.submitFrame(),this.onEndFrameObservable.notifyObservers(this)},n.prototype.resize=function(){if(!this._vrDisplay||!this._vrDisplay.isPresenting){var e=this._renderingCanvas?this._renderingCanvas.clientWidth:window.innerWidth,t=this._renderingCanvas?this._renderingCanvas.clientHeight:window.innerHeight;this.setSize(e/this._hardwareScalingLevel,t/this._hardwareScalingLevel)}},n.prototype.setSize=function(e,t){if(this._renderingCanvas&&(this._renderingCanvas.width!==e||this._renderingCanvas.height!==t)){this._renderingCanvas.width=e,this._renderingCanvas.height=t;for(var i=0;i<this.scenes.length;i++)for(var r=this.scenes[i],n=0;n<r.cameras.length;n++)r.cameras[n]._currentRenderId=0;this.onResizeObservable.hasObservers&&this.onResizeObservable.notifyObservers(this)}},n.prototype.isVRDevicePresent=function(){return!!this._vrDisplay},n.prototype.getVRDevice=function(){return this._vrDisplay},n.prototype.initWebVR=function(){var t=this,i=function(){var e={vrDisplay:t._vrDisplay,vrSupported:t._vrSupported};t.onVRDisplayChangedObservable.notifyObservers(e)};return this._onVrDisplayConnect||(this._onVrDisplayConnect=function(e){t._vrDisplay=e.display,i()},this._onVrDisplayDisconnect=function(){t._vrDisplay.cancelAnimationFrame(t._frameHandler),t._vrDisplay=void 0,t._frameHandler=e.Tools.QueueNewFrame(t._bindedRenderFunction),i()},this._onVrDisplayPresentChange=function(){t._vrExclusivePointerMode=t._vrDisplay&&t._vrDisplay.isPresenting},window.addEventListener("vrdisplayconnect",this._onVrDisplayConnect),window.addEventListener("vrdisplaydisconnect",this._onVrDisplayDisconnect),window.addEventListener("vrdisplaypresentchange",this._onVrDisplayPresentChange)),this._getVRDisplays(i),this.onVRDisplayChangedObservable},n.prototype.enableVR=function(){var e=this;if(this._vrDisplay&&!this._vrDisplay.isPresenting){var t=function(){e.onVRRequestPresentComplete.notifyObservers(!0),e._onVRFullScreenTriggered()},i=function(){e.onVRRequestPresentComplete.notifyObservers(!1)};this.onVRRequestPresentStart.notifyObservers(this),this._vrDisplay.requestPresent([{source:this.getRenderingCanvas()}]).then(t).catch(i)}},n.prototype.disableVR=function(){this._vrDisplay&&this._vrDisplay.isPresenting&&this._vrDisplay.exitPresent().then(this._onVRFullScreenTriggered).catch(this._onVRFullScreenTriggered)},n.prototype._getVRDisplays=function(e){var t=this;navigator.getVRDisplays?navigator.getVRDisplays().then(function(e){return t._vrSupported=!0,t._vrDisplay=e[0]}).then(e).catch(function(i){t._vrSupported=!1,e()}):(this._vrDisplay=void 0,this._vrSupported=!1,e())},n.prototype.bindFramebuffer=function(e,t,i,r,n){this._currentRenderTarget&&this.unBindFramebuffer(this._currentRenderTarget),this._currentRenderTarget=e,this.bindUnboundFramebuffer(e._MSAAFramebuffer?e._MSAAFramebuffer:e._framebuffer);var o=this._gl;e.isCube&&(void 0===t&&(t=0),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_CUBE_MAP_POSITIVE_X+t,e._webGLTexture,0)),this._cachedViewport&&!n?this.setViewport(this._cachedViewport,i,r):o.viewport(0,0,i||e.width,r||e.height),this.wipeCaches()},n.prototype.bindUnboundFramebuffer=function(e){this._currentFramebuffer!==e&&(this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,e),this._currentFramebuffer=e)},n.prototype.unBindFramebuffer=function(e,t,i){void 0===t&&(t=!1),this._currentRenderTarget=null;var r=this._gl;e._MSAAFramebuffer&&(r.bindFramebuffer(r.READ_FRAMEBUFFER,e._MSAAFramebuffer),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,e._framebuffer),r.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,r.COLOR_BUFFER_BIT,r.NEAREST)),!e.generateMipMaps||t||e.isCube||(this._bindTextureDirectly(r.TEXTURE_2D,e),r.generateMipmap(r.TEXTURE_2D),this._bindTextureDirectly(r.TEXTURE_2D,null)),i&&(e._MSAAFramebuffer&&this.bindUnboundFramebuffer(e._framebuffer),i()),this.bindUnboundFramebuffer(null)},n.prototype.generateMipMapsForCubemap=function(e){if(e.generateMipMaps){var t=this._gl;this._bindTextureDirectly(t.TEXTURE_CUBE_MAP,e),t.generateMipmap(t.TEXTURE_CUBE_MAP),this._bindTextureDirectly(t.TEXTURE_CUBE_MAP,null)}},n.prototype.flushFramebuffer=function(){this._gl.flush()},n.prototype.restoreDefaultFramebuffer=function(){this._currentRenderTarget?this.unBindFramebuffer(this._currentRenderTarget):this.bindUnboundFramebuffer(null),this._cachedViewport&&this.setViewport(this._cachedViewport),this.wipeCaches()},n.prototype.createUniformBuffer=function(e){var t=this._gl.createBuffer();if(!t)throw new Error("Unable to create uniform buffer");return this.bindUniformBuffer(t),e instanceof Float32Array?this._gl.bufferData(this._gl.UNIFORM_BUFFER,e,this._gl.STATIC_DRAW):this._gl.bufferData(this._gl.UNIFORM_BUFFER,new Float32Array(e),this._gl.STATIC_DRAW),this.bindUniformBuffer(null),t.references=1,t},n.prototype.createDynamicUniformBuffer=function(e){var t=this._gl.createBuffer();if(!t)throw new Error("Unable to create dynamic uniform buffer");return this.bindUniformBuffer(t),e instanceof Float32Array?this._gl.bufferData(this._gl.UNIFORM_BUFFER,e,this._gl.DYNAMIC_DRAW):this._gl.bufferData(this._gl.UNIFORM_BUFFER,new Float32Array(e),this._gl.DYNAMIC_DRAW),this.bindUniformBuffer(null),t.references=1,t},n.prototype.updateUniformBuffer=function(e,t,i,r){this.bindUniformBuffer(e),void 0===i&&(i=0),void 0===r?t instanceof Float32Array?this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,i,t):this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,i,new Float32Array(t)):t instanceof Float32Array?this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,0,t.subarray(i,i+r)):this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,0,new Float32Array(t).subarray(i,i+r)),this.bindUniformBuffer(null)},n.prototype._resetVertexBufferBinding=function(){this.bindArrayBuffer(null),this._cachedVertexBuffers=null},n.prototype.createVertexBuffer=function(e){var t=this._gl.createBuffer();if(!t)throw new Error("Unable to create vertex buffer");return this.bindArrayBuffer(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},n.prototype.createDynamicVertexBuffer=function(e){var t=this._gl.createBuffer();if(!t)throw new Error("Unable to create dynamic vertex buffer");return this.bindArrayBuffer(t),e instanceof Float32Array?this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.DYNAMIC_DRAW):this._gl.bufferData(this._gl.ARRAY_BUFFER,new Float32Array(e),this._gl.DYNAMIC_DRAW),this._resetVertexBufferBinding(),t.references=1,t},n.prototype.updateDynamicIndexBuffer=function(e,t,i){void 0===i&&(i=0),this._currentBoundBuffer[this._gl.ELEMENT_ARRAY_BUFFER]=null,this.bindIndexBuffer(e);var r;r=t instanceof Uint16Array||t instanceof Uint32Array?t:e.is32Bits?new Uint32Array(t):new Uint16Array(t),this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,r,this._gl.DYNAMIC_DRAW),this._resetIndexBufferBinding()},n.prototype.updateDynamicVertexBuffer=function(e,t,i,r){this.bindArrayBuffer(e),void 0===i&&(i=0),void 0===r?t instanceof Float32Array?this._gl.bufferSubData(this._gl.ARRAY_BUFFER,i,t):this._gl.bufferSubData(this._gl.ARRAY_BUFFER,i,new Float32Array(t)):t instanceof Float32Array?this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,t.subarray(i,i+r)):this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,new Float32Array(t).subarray(i,i+r)),this._resetVertexBufferBinding()},n.prototype._resetIndexBufferBinding=function(){this.bindIndexBuffer(null),this._cachedIndexBuffer=null},n.prototype.createIndexBuffer=function(e,t){var i=this._gl.createBuffer();if(!i)throw new Error("Unable to create index buffer");this.bindIndexBuffer(i);var r,n=!1;if(e instanceof Uint16Array)r=e;else if(this._caps.uintIndices)if(e instanceof Uint32Array)r=e,n=!0;else{for(var o=0;o<e.length;o++)if(e[o]>65535){n=!0;break}r=n?new Uint32Array(e):new Uint16Array(e)}else r=new Uint16Array(e);return this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,r,t?this._gl.DYNAMIC_DRAW:this._gl.STATIC_DRAW),this._resetIndexBufferBinding(),i.references=1,i.is32Bits=n,i},n.prototype.bindArrayBuffer=function(e){this._vaoRecordInProgress||this._unbindVertexArrayObject(),this.bindBuffer(e,this._gl.ARRAY_BUFFER)},n.prototype.bindUniformBuffer=function(e){this._gl.bindBuffer(this._gl.UNIFORM_BUFFER,e)},n.prototype.bindUniformBufferBase=function(e,t){this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,t,e)},n.prototype.bindUniformBlock=function(e,t,i){var r=this._gl.getUniformBlockIndex(e,t);this._gl.uniformBlockBinding(e,r,i)},n.prototype.bindIndexBuffer=function(e){this._vaoRecordInProgress||this._unbindVertexArrayObject(),this.bindBuffer(e,this._gl.ELEMENT_ARRAY_BUFFER)},n.prototype.bindBuffer=function(e,t){(this._vaoRecordInProgress||this._currentBoundBuffer[t]!==e)&&(this._gl.bindBuffer(t,e),this._currentBoundBuffer[t]=e)},n.prototype.updateArrayBuffer=function(e){this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,e)},n.prototype.vertexAttribPointer=function(e,t,i,r,n,o,s){var a=this._currentBufferPointers[t],l=!1;a.active?(a.buffer!==e&&(a.buffer=e,l=!0),a.size!==i&&(a.size=i,l=!0),a.type!==r&&(a.type=r,l=!0),a.normalized!==n&&(a.normalized=n,l=!0),a.stride!==o&&(a.stride=o,l=!0),a.offset!==s&&(a.offset=s,l=!0)):(l=!0,a.active=!0,a.index=t,a.size=i,a.type=r,a.normalized=n,a.stride=o,a.offset=s,a.buffer=e),(l||this._vaoRecordInProgress)&&(this.bindArrayBuffer(e),this._gl.vertexAttribPointer(t,i,r,n,o,s))},n.prototype._bindIndexBufferWithCache=function(e){null!=e&&this._cachedIndexBuffer!==e&&(this._cachedIndexBuffer=e,this.bindIndexBuffer(e),this._uintIndicesCurrentlySet=e.is32Bits)},n.prototype._bindVertexBuffersAttributes=function(e,t){var i=t.getAttributesNames();this._vaoRecordInProgress||this._unbindVertexArrayObject(),this.unbindAllAttributes();for(var r=0;r<i.length;r++){var n=t.getAttributeLocation(r);if(n>=0){var o=e[i[r]];if(!o)continue;this._gl.enableVertexAttribArray(n),this._vaoRecordInProgress||(this._vertexAttribArraysEnabled[n]=!0);var s=o.getBuffer();s&&(this.vertexAttribPointer(s,n,o.getSize(),this._gl.FLOAT,!1,4*o.getStrideSize(),4*o.getOffset()),o.getIsInstanced()&&(this._gl.vertexAttribDivisor(n,o.getInstanceDivisor()),this._vaoRecordInProgress||(this._currentInstanceLocations.push(n),this._currentInstanceBuffers.push(s))))}}},n.prototype.recordVertexArrayObject=function(e,t,i){var r=this._gl.createVertexArray();return this._vaoRecordInProgress=!0,this._gl.bindVertexArray(r),this._mustWipeVertexAttributes=!0,this._bindVertexBuffersAttributes(e,i),this.bindIndexBuffer(t),this._vaoRecordInProgress=!1,this._gl.bindVertexArray(null),r},n.prototype.bindVertexArrayObject=function(e,t){this._cachedVertexArrayObject!==e&&(this._cachedVertexArrayObject=e,this._gl.bindVertexArray(e),this._cachedVertexBuffers=null,this._cachedIndexBuffer=null,this._uintIndicesCurrentlySet=null!=t&&t.is32Bits,this._mustWipeVertexAttributes=!0)},n.prototype.bindBuffersDirectly=function(e,t,i,r,n){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==n){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=n;var o=n.getAttributesCount();this._unbindVertexArrayObject(),this.unbindAllAttributes();for(var s=0,a=0;a<o;a++)if(a<i.length){var l=n.getAttributeLocation(a);l>=0&&(this._gl.enableVertexAttribArray(l),this._vertexAttribArraysEnabled[l]=!0,this.vertexAttribPointer(e,l,i[a],this._gl.FLOAT,!1,r,s)),s+=4*i[a]}}this._bindIndexBufferWithCache(t)},n.prototype._unbindVertexArrayObject=function(){this._cachedVertexArrayObject&&(this._cachedVertexArrayObject=null,this._gl.bindVertexArray(null))},n.prototype.bindBuffers=function(e,t,i){this._cachedVertexBuffers===e&&this._cachedEffectForVertexBuffers===i||(this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=i,this._bindVertexBuffersAttributes(e,i)),this._bindIndexBufferWithCache(t)},n.prototype.unbindInstanceAttributes=function(){for(var e,t=0,i=this._currentInstanceLocations.length;t<i;t++){var r=this._currentInstanceBuffers[t];e!=r&&r.references&&(e=r,this.bindArrayBuffer(r));var n=this._currentInstanceLocations[t];this._gl.vertexAttribDivisor(n,0)}this._currentInstanceBuffers.length=0,this._currentInstanceLocations.length=0},n.prototype.releaseVertexArrayObject=function(e){this._gl.deleteVertexArray(e)},n.prototype._releaseBuffer=function(e){return e.references--,0===e.references&&(this._gl.deleteBuffer(e),!0)},n.prototype.createInstancesBuffer=function(e){var t=this._gl.createBuffer();if(!t)throw new Error("Unable to create instance buffer");return t.capacity=e,this.bindArrayBuffer(t),this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.DYNAMIC_DRAW),t},n.prototype.deleteInstancesBuffer=function(e){this._gl.deleteBuffer(e)},n.prototype.updateAndBindInstancesBuffer=function(e,t,i){if(this.bindArrayBuffer(e),t&&this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,t),void 0!==i[0].index){for(var r=0,n=0;n<i.length;n++)r+=4*(o=i[n]).attributeSize;for(n=0;n<i.length;n++){var o=i[n];this._vertexAttribArraysEnabled[o.index]||(this._gl.enableVertexAttribArray(o.index),this._vertexAttribArraysEnabled[o.index]=!0),this.vertexAttribPointer(e,o.index,o.attributeSize,o.attribyteType||this._gl.FLOAT,o.normalized||!1,r,o.offset),this._gl.vertexAttribDivisor(o.index,1),this._currentInstanceLocations.push(o.index),this._currentInstanceBuffers.push(e)}}else for(var s=0;s<4;s++){var a=i[s];this._vertexAttribArraysEnabled[a]||(this._gl.enableVertexAttribArray(a),this._vertexAttribArraysEnabled[a]=!0),this.vertexAttribPointer(e,a,4,this._gl.FLOAT,!1,64,16*s),this._gl.vertexAttribDivisor(a,1),this._currentInstanceLocations.push(a),this._currentInstanceBuffers.push(e)}},n.prototype.applyStates=function(){this._depthCullingState.apply(this._gl),this._stencilState.apply(this._gl),this._alphaState.apply(this._gl)},n.prototype.draw=function(e,t,i,r){this.applyStates(),this._drawCalls.addCount(1,!1);var n=this._uintIndicesCurrentlySet?this._gl.UNSIGNED_INT:this._gl.UNSIGNED_SHORT,o=this._uintIndicesCurrentlySet?4:2;r?this._gl.drawElementsInstanced(e?this._gl.TRIANGLES:this._gl.LINES,i,n,t*o,r):this._gl.drawElements(e?this._gl.TRIANGLES:this._gl.LINES,i,n,t*o)},n.prototype.drawPointClouds=function(e,t,i){this.applyStates(),this._drawCalls.addCount(1,!1),i?this._gl.drawArraysInstanced(this._gl.POINTS,e,t,i):this._gl.drawArrays(this._gl.POINTS,e,t)},n.prototype.drawUnIndexed=function(e,t,i,r){this.applyStates(),this._drawCalls.addCount(1,!1),r?this._gl.drawArraysInstanced(e?this._gl.TRIANGLES:this._gl.LINES,t,i,r):this._gl.drawArrays(e?this._gl.TRIANGLES:this._gl.LINES,t,i)},n.prototype._releaseEffect=function(e){this._compiledEffects[e._key]&&(delete this._compiledEffects[e._key],this._deleteProgram(e.getProgram()))},n.prototype._deleteProgram=function(e){e&&(e.__SPECTOR_rebuildProgram=null,e.transformFeedback&&(this.deleteTransformFeedback(e.transformFeedback),e.transformFeedback=null),this._gl.deleteProgram(e))},n.prototype.createEffect=function(t,i,r,n,o,s,a,l,h){var u=(t.vertexElement||t.vertex||t)+"+"+(t.fragmentElement||t.fragment||t)+"@"+(o||i.defines);if(this._compiledEffects[u]){var c=this._compiledEffects[u];return a&&c.isReady()&&a(c),c}var f=new e.Effect(t,i,r,n,this,o,s,a,l,h);return f._key=u,this._compiledEffects[u]=f,f},n.prototype.createEffectForParticles=function(e,t,i,r,n,o,s){return void 0===t&&(t=[]),void 0===i&&(i=[]),void 0===r&&(r=""),this.createEffect({vertex:"particles",fragmentElement:e},["position","color","options"],["view","projection"].concat(t),["diffuseSampler"].concat(i),r,n,o,s)},n.prototype.createRawShaderProgram=function(e,t,r,n){void 0===n&&(n=null),r=r||this._gl;var o=i(r,e,"vertex"),s=i(r,t,"fragment");return this._createShaderProgram(o,s,r,n)},n.prototype.createShaderProgram=function(e,i,r,n,o){void 0===o&&(o=null),n=n||this._gl,this.onBeforeShaderCompilationObservable.notifyObservers(this);var s=this._webGLVersion>1?"#version 300 es\n":"",a=t(n,e,"vertex",r,s),l=t(n,i,"fragment",r,s),h=this._createShaderProgram(a,l,n,o);return this.onAfterShaderCompilationObservable.notifyObservers(this),h},n.prototype._createShaderProgram=function(e,t,i,r){void 0===r&&(r=null);var n=i.createProgram();if(!n)throw new Error("Unable to create program");if(i.attachShader(n,e),i.attachShader(n,t),this.webGLVersion>1&&r){var o=this.createTransformFeedback();this.bindTransformFeedback(o),this.setTranformFeedbackVaryings(n,r),n.transformFeedback=o}if(i.linkProgram(n),this.webGLVersion>1&&r&&this.bindTransformFeedback(null),!i.getProgramParameter(n,i.LINK_STATUS)){i.validateProgram(n);var s=i.getProgramInfoLog(n);if(s)throw new Error(s)}return i.deleteShader(e),i.deleteShader(t),n},n.prototype.getUniforms=function(e,t){for(var i=new Array,r=0;r<t.length;r++)i.push(this._gl.getUniformLocation(e,t[r]));return i},n.prototype.getAttributes=function(e,t){for(var i=[],r=0;r<t.length;r++)try{i.push(this._gl.getAttribLocation(e,t[r]))}catch(e){i.push(-1)}return i},n.prototype.enableEffect=function(e){e&&(this.setProgram(e.getProgram()),this._currentEffect=e,e.onBind&&e.onBind(e),e.onBindObservable.notifyObservers(e))},n.prototype.setIntArray=function(e,t){e&&this._gl.uniform1iv(e,t)},n.prototype.setIntArray2=function(e,t){e&&t.length%2==0&&this._gl.uniform2iv(e,t)},n.prototype.setIntArray3=function(e,t){e&&t.length%3==0&&this._gl.uniform3iv(e,t)},n.prototype.setIntArray4=function(e,t){e&&t.length%4==0&&this._gl.uniform4iv(e,t)},n.prototype.setFloatArray=function(e,t){e&&this._gl.uniform1fv(e,t)},n.prototype.setFloatArray2=function(e,t){e&&t.length%2==0&&this._gl.uniform2fv(e,t)},n.prototype.setFloatArray3=function(e,t){e&&t.length%3==0&&this._gl.uniform3fv(e,t)},n.prototype.setFloatArray4=function(e,t){e&&t.length%4==0&&this._gl.uniform4fv(e,t)},n.prototype.setArray=function(e,t){e&&this._gl.uniform1fv(e,t)},n.prototype.setArray2=function(e,t){e&&t.length%2==0&&this._gl.uniform2fv(e,t)},n.prototype.setArray3=function(e,t){e&&t.length%3==0&&this._gl.uniform3fv(e,t)},n.prototype.setArray4=function(e,t){e&&t.length%4==0&&this._gl.uniform4fv(e,t)},n.prototype.setMatrices=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t)},n.prototype.setMatrix=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t.toArray())},n.prototype.setMatrix3x3=function(e,t){e&&this._gl.uniformMatrix3fv(e,!1,t)},n.prototype.setMatrix2x2=function(e,t){e&&this._gl.uniformMatrix2fv(e,!1,t)},n.prototype.setFloat=function(e,t){e&&this._gl.uniform1f(e,t)},n.prototype.setFloat2=function(e,t,i){e&&this._gl.uniform2f(e,t,i)},n.prototype.setFloat3=function(e,t,i,r){e&&this._gl.uniform3f(e,t,i,r)},n.prototype.setBool=function(e,t){e&&this._gl.uniform1i(e,t)},n.prototype.setFloat4=function(e,t,i,r,n){e&&this._gl.uniform4f(e,t,i,r,n)},n.prototype.setColor3=function(e,t){e&&this._gl.uniform3f(e,t.r,t.g,t.b)},n.prototype.setColor4=function(e,t,i){e&&this._gl.uniform4f(e,t.r,t.g,t.b,i)},n.prototype.setState=function(e,t,i,r){void 0===t&&(t=0),void 0===r&&(r=!1);var n=r?this._gl.FRONT:this._gl.BACK,o=r?this._gl.BACK:this._gl.FRONT,s=this.cullBackFaces?n:o;(this._depthCullingState.cull!==e||i||this._depthCullingState.cullFace!==s)&&(e?(this._depthCullingState.cullFace=s,this._depthCullingState.cull=!0):this._depthCullingState.cull=!1),this.setZOffset(t)},n.prototype.setZOffset=function(e){this._depthCullingState.zOffset=e},n.prototype.getZOffset=function(){return this._depthCullingState.zOffset},n.prototype.setDepthBuffer=function(e){this._depthCullingState.depthTest=e},n.prototype.getDepthWrite=function(){return this._depthCullingState.depthMask},n.prototype.setDepthWrite=function(e){this._depthCullingState.depthMask=e},n.prototype.setColorWrite=function(e){this._gl.colorMask(e,e,e,e),this._colorWrite=e},n.prototype.getColorWrite=function(){return this._colorWrite},n.prototype.setAlphaConstants=function(e,t,i,r){this._alphaState.setAlphaBlendConstants(e,t,i,r)},n.prototype.setAlphaMode=function(e,t){if(void 0===t&&(t=!1),this._alphaMode!==e){switch(e){case n.ALPHA_DISABLE:this._alphaState.alphaBlend=!1;break;case n.ALPHA_PREMULTIPLIED:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE_MINUS_SRC_ALPHA,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case n.ALPHA_PREMULTIPLIED_PORTERDUFF:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE_MINUS_SRC_ALPHA,this._gl.ONE,this._gl.ONE_MINUS_SRC_ALPHA),this._alphaState.alphaBlend=!0;break;case n.ALPHA_COMBINE: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 n.ALPHA_ONEONE:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case n.ALPHA_ADD:this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case n.ALPHA_SUBTRACT:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ZERO,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case n.ALPHA_MULTIPLY:this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_COLOR,this._gl.ZERO,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case n.ALPHA_MAXIMIZED:this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case n.ALPHA_INTERPOLATE:this._alphaState.setAlphaBlendFunctionParameters(this._gl.CONSTANT_COLOR,this._gl.ONE_MINUS_CONSTANT_COLOR,this._gl.CONSTANT_ALPHA,this._gl.ONE_MINUS_CONSTANT_ALPHA),this._alphaState.alphaBlend=!0;break;case n.ALPHA_SCREENMODE:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE_MINUS_SRC_ALPHA),this._alphaState.alphaBlend=!0}t||this.setDepthWrite(e===n.ALPHA_DISABLE),this._alphaMode=e}},n.prototype.getAlphaMode=function(){return this._alphaMode},n.prototype.setAlphaTesting=function(e){this._alphaTest=e},n.prototype.getAlphaTesting=function(){return!!this._alphaTest},n.prototype.wipeCaches=function(e){this.preventCacheWipeBetweenFrames||(this.resetTextureCache(),this._currentEffect=null,e&&(this._currentProgram=null,this._stencilState.reset(),this._depthCullingState.reset(),this.setDepthFunctionToLessOrEqual(),this._alphaState.reset()),this._cachedVertexBuffers=null,this._cachedIndexBuffer=null,this._cachedEffectForVertexBuffers=null,this._unbindVertexArrayObject(),this.bindIndexBuffer(null),this.bindArrayBuffer(null))},n.prototype.setTextureFormatToUse=function(e){for(var t=0,i=this.texturesSupported.length;t<i;t++)for(var r=0,n=e.length;r<n;r++)if(this._texturesSupported[t]===e[r].toLowerCase())return this._textureFormatInUse=this._texturesSupported[t];return this._textureFormatInUse=null,null},n.prototype._createTexture=function(){var e=this._gl.createTexture();if(!e)throw new Error("Unable to create texture");return e},n.prototype.createTexture=function(t,i,r,n,o,s,a,l,h,u){var c=this;void 0===o&&(o=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===s&&(s=null),void 0===a&&(a=null),void 0===l&&(l=null),void 0===h&&(h=null),void 0===u&&(u=null);var f=String(t),p="data:"===f.substr(0,5),d="blob:"===f.substr(0,5),m=p&&-1!==f.indexOf("base64"),g=h||new e.InternalTexture(this,e.InternalTexture.DATASOURCE_URL),v=f.lastIndexOf("."),_=v>0?f.substring(v).toLowerCase():"",y=this.getCaps().s3tc&&".dds"===_,x=".tga"===_,b=!1;!this._textureFormatInUse||m||h||(f=f.substring(0,v)+this._textureFormatInUse,b=!0),n&&n._addPendingData(g),g.url=f,g.generateMipMaps=!i,g.samplingMode=o,g.invertY=r,this._doNotHandleContextLost||(g._buffer=l),s&&g.onLoadedObservable.add(s),h||this._internalTexturesCache.push(g);var T=function(){n&&n._removePendingData(g),b?c.createTexture(t,i,r,n,o,null,a,l,g):(x||y)&&e.Tools.UseFallbackTexture?c.createTexture(e.Tools.fallbackTexture,i,r,n,o,null,a,l,g):a&&a()},E=null;if(b||x||y)b?E=function(t){var s=new e.Internals.KhronosTextureContainer(t,1);c._prepareWebGLTexture(g,n,s.pixelWidth,s.pixelHeight,r,!1,!0,function(){return s.uploadLevels(c._gl,!i),!1},o)}:x?E=function(t){var s=new Uint8Array(t),a=e.Internals.TGATools.GetTGAHeader(s);c._prepareWebGLTexture(g,n,a.width,a.height,r,i,!1,function(){return e.Internals.TGATools.UploadContent(c._gl,s),!1},o)}:y&&(E=function(t){var s=e.Internals.DDSTools.GetDDSInfo(t),a=(s.isRGB||s.isLuminance||s.mipmapCount>1)&&!i&&s.width>>s.mipmapCount-1==1;c._prepareWebGLTexture(g,n,s.width,s.height,r,!a,s.isFourCC,function(){return e.Internals.DDSTools.UploadDDSLevels(c,c._gl,t,s,a,1),!1},o)}),l?E&&E(l):e.Tools.LoadFile(f,function(e){E&&E(e)},void 0,n?n.database:void 0,!0,T);else{var A=function(t){d&&!c._doNotHandleContextLost&&(g._buffer=t),c._prepareWebGLTexture(g,n,t.width,t.height,r,i,!1,function(i,r,o){var s=c._gl,a=t.width===i&&t.height===r,l=u?c._getInternalFormat(u):".jpg"===_?s.RGB:s.RGBA;if(a)return s.texImage2D(s.TEXTURE_2D,0,l,l,s.UNSIGNED_BYTE,t),!1;var h=new e.InternalTexture(c,e.InternalTexture.DATASOURCE_TEMP);return c._bindTextureDirectly(s.TEXTURE_2D,h),s.texImage2D(s.TEXTURE_2D,0,l,l,s.UNSIGNED_BYTE,t),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),c._rescaleTexture(h,g,n,l,function(){c._releaseTexture(h),c._bindTextureDirectly(s.TEXTURE_2D,g),o()}),!0},o)};!p||m?l instanceof HTMLImageElement?A(l):e.Tools.LoadImage(f,A,T,n?n.database:null):l instanceof Array||"string"==typeof l||l instanceof ArrayBuffer?e.Tools.LoadImage(l,A,T,n?n.database:null):A(l)}return g},n.prototype._rescaleTexture=function(t,i,r,o,s){var a=this,l=this.createRenderTargetTexture({width:i.width,height:i.height},{generateMipMaps:!1,type:n.TEXTURETYPE_UNSIGNED_INT,samplingMode:e.Texture.BILINEAR_SAMPLINGMODE,generateDepthBuffer:!1,generateStencilBuffer:!1});this._rescalePostProcess||(this._rescalePostProcess=new e.PassPostProcess("rescale",1,null,e.Texture.BILINEAR_SAMPLINGMODE,this,!1,n.TEXTURETYPE_UNSIGNED_INT)),this._rescalePostProcess.getEffect().executeWhenCompiled(function(){a._rescalePostProcess.onApply=function(e){e._bindTexture("textureSampler",t)};var e=r;e||(e=a.scenes[a.scenes.length-1]),e.postProcessManager.directRender([a._rescalePostProcess],l),a._bindTextureDirectly(a._gl.TEXTURE_2D,i),a._gl.copyTexImage2D(a._gl.TEXTURE_2D,0,o,0,0,i.width,i.height,0),a.unBindFramebuffer(l),a._releaseTexture(l),s&&s()})},n.prototype._getInternalFormat=function(e){var t=this._gl.RGBA;switch(e){case n.TEXTUREFORMAT_ALPHA:t=this._gl.ALPHA;break;case n.TEXTUREFORMAT_LUMINANCE:t=this._gl.LUMINANCE;break;case n.TEXTUREFORMAT_LUMINANCE_ALPHA:t=this._gl.LUMINANCE_ALPHA;break;case n.TEXTUREFORMAT_RGB:t=this._gl.RGB;break;case n.TEXTUREFORMAT_RGBA:t=this._gl.RGBA}return t},n.prototype.updateRawTexture=function(e,t,i,r,n){if(void 0===n&&(n=null),e){var o=this._getInternalFormat(i);this._bindTextureDirectly(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,void 0===r?1:r?1:0),this._doNotHandleContextLost||(e._bufferView=t,e.format=i,e.invertY=r,e._compression=n),e.width%4!=0&&this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT,1),n&&t?this._gl.compressedTexImage2D(this._gl.TEXTURE_2D,0,this.getCaps().s3tc[n],e.width,e.height,0,t):this._gl.texImage2D(this._gl.TEXTURE_2D,0,o,e.width,e.height,0,o,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),this.resetTextureCache(),e.isReady=!0}},n.prototype.createRawTexture=function(t,i,n,o,s,a,l,h){void 0===h&&(h=null);var u=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RAW);u.baseWidth=i,u.baseHeight=n,u.width=i,u.height=n,u.format=o,u.generateMipMaps=s,u.samplingMode=l,u.invertY=a,u._compression=h,this._doNotHandleContextLost||(u._bufferView=t),this.updateRawTexture(u,t,o,a,h),this._bindTextureDirectly(this._gl.TEXTURE_2D,u);var c=r(l,s,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,c.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,c.min),s&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),this._internalTexturesCache.push(u),u},n.prototype.createDynamicTexture=function(t,i,r,n){var o=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_DYNAMIC);return o.baseWidth=t,o.baseHeight=i,r&&(t=this.needPOTTextures?e.Tools.GetExponentOfTwo(t,this._caps.maxTextureSize):t,i=this.needPOTTextures?e.Tools.GetExponentOfTwo(i,this._caps.maxTextureSize):i),this.resetTextureCache(),o.width=t,o.height=i,o.isReady=!1,o.generateMipMaps=r,o.samplingMode=n,this.updateTextureSamplingMode(n,o),this._internalTexturesCache.push(o),o},n.prototype.updateTextureSamplingMode=function(e,t){var i=r(e,t.generateMipMaps,this._gl);t.isCube?(this._bindTextureDirectly(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._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,null)):t.is3D?(this._bindTextureDirectly(this._gl.TEXTURE_3D,t),this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_MAG_FILTER,i.mag),this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_MIN_FILTER,i.min),this._bindTextureDirectly(this._gl.TEXTURE_3D,null)):(this._bindTextureDirectly(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._bindTextureDirectly(this._gl.TEXTURE_2D,null)),t.samplingMode=e},n.prototype.updateDynamicTexture=function(e,t,i,r,n){if(void 0===r&&(r=!1),e){this._bindTextureDirectly(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,i?1:0),r&&this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1);var o=n?this._getInternalFormat(n):this._gl.RGBA;this._gl.texImage2D(this._gl.TEXTURE_2D,0,o,o,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),r&&this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,0),this.resetTextureCache(),e.isReady=!0}},n.prototype.updateVideoTexture=function(e,t,i){if(e&&!e._isDisabled){this._bindTextureDirectly(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,i?0:1);try{if(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);else{if(!e._workingCanvas){e._workingCanvas=document.createElement("canvas");var r=e._workingCanvas.getContext("2d");if(!r)throw new Error("Unable to get 2d context");e._workingContext=r,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._bindTextureDirectly(this._gl.TEXTURE_2D,null),this.resetTextureCache(),e.isReady=!0}catch(t){e._isDisabled=!0}}},n.prototype.createRenderTargetTexture=function(t,i){var o=new l;void 0!==i&&"object"==typeof i?(o.generateMipMaps=i.generateMipMaps,o.generateDepthBuffer=void 0===i.generateDepthBuffer||i.generateDepthBuffer,o.generateStencilBuffer=o.generateDepthBuffer&&i.generateStencilBuffer,o.type=void 0===i.type?n.TEXTURETYPE_UNSIGNED_INT:i.type,o.samplingMode=void 0===i.samplingMode?e.Texture.TRILINEAR_SAMPLINGMODE:i.samplingMode):(o.generateMipMaps=i,o.generateDepthBuffer=!0,o.generateStencilBuffer=!1,o.type=n.TEXTURETYPE_UNSIGNED_INT,o.samplingMode=e.Texture.TRILINEAR_SAMPLINGMODE),o.type!==n.TEXTURETYPE_FLOAT||this._caps.textureFloatLinearFiltering?o.type!==n.TEXTURETYPE_HALF_FLOAT||this._caps.textureHalfFloatLinearFiltering||(o.samplingMode=e.Texture.NEAREST_SAMPLINGMODE):o.samplingMode=e.Texture.NEAREST_SAMPLINGMODE;var s=this._gl,a=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RENDERTARGET);this._bindTextureDirectly(s.TEXTURE_2D,a);var h=t.width||t,u=t.height||t,c=r(o.samplingMode,!!o.generateMipMaps,s);o.type!==n.TEXTURETYPE_FLOAT||this._caps.textureFloat||(o.type=n.TEXTURETYPE_UNSIGNED_INT,e.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type")),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,c.mag),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,c.min),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texImage2D(s.TEXTURE_2D,0,this._getRGBABufferInternalSizedFormat(o.type),h,u,0,s.RGBA,this._getWebGLTextureType(o.type),null);var f=s.createFramebuffer();return this.bindUnboundFramebuffer(f),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,a._webGLTexture,0),a._depthStencilBuffer=this._setupFramebufferDepthAttachments(!!o.generateStencilBuffer,o.generateDepthBuffer,h,u),o.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(s.TEXTURE_2D,null),s.bindRenderbuffer(s.RENDERBUFFER,null),this.bindUnboundFramebuffer(null),a._framebuffer=f,a.baseWidth=h,a.baseHeight=u,a.width=h,a.height=u,a.isReady=!0,a.samples=1,a.generateMipMaps=!!o.generateMipMaps,a.samplingMode=o.samplingMode,a.type=o.type,a._generateDepthBuffer=o.generateDepthBuffer,a._generateStencilBuffer=!!o.generateStencilBuffer,this.resetTextureCache(),this._internalTexturesCache.push(a),a},n.prototype.createMultipleRenderTarget=function(t,i){var o=!1,s=!0,a=!1,l=!1,h=1,u=n.TEXTURETYPE_UNSIGNED_INT,c=e.Texture.TRILINEAR_SAMPLINGMODE,f=[],p=[];void 0!==i&&(o=i.generateMipMaps,s=void 0===i.generateDepthBuffer||i.generateDepthBuffer,a=i.generateStencilBuffer,l=i.generateDepthTexture,h=i.textureCount||1,i.types&&(f=i.types),i.samplingModes&&(p=i.samplingModes));var d=this._gl,m=d.createFramebuffer();this.bindUnboundFramebuffer(m);for(var g=t.width||t,v=t.height||t,_=[],y=[],x=this._setupFramebufferDepthAttachments(a,s,g,v),b=0;b<h;b++){var T=p[b]||c,E=f[b]||u;E!==n.TEXTURETYPE_FLOAT||this._caps.textureFloatLinearFiltering?E!==n.TEXTURETYPE_HALF_FLOAT||this._caps.textureHalfFloatLinearFiltering||(T=e.Texture.NEAREST_SAMPLINGMODE):T=e.Texture.NEAREST_SAMPLINGMODE;var A=r(T,o,d);E!==n.TEXTURETYPE_FLOAT||this._caps.textureFloat||(E=n.TEXTURETYPE_UNSIGNED_INT,e.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type"));var P=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_MULTIRENDERTARGET),S=d[this.webGLVersion>1?"COLOR_ATTACHMENT"+b:"COLOR_ATTACHMENT"+b+"_WEBGL"];_.push(P),y.push(S),d.activeTexture(d["TEXTURE"+b]),d.bindTexture(d.TEXTURE_2D,P._webGLTexture),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,A.mag),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,A.min),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE),d.texImage2D(d.TEXTURE_2D,0,this._getRGBABufferInternalSizedFormat(E),g,v,0,d.RGBA,this._getWebGLTextureType(E),null),d.framebufferTexture2D(d.DRAW_FRAMEBUFFER,S,d.TEXTURE_2D,P._webGLTexture,0),o&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(d.TEXTURE_2D,null),P._framebuffer=m,P._depthStencilBuffer=x,P.baseWidth=g,P.baseHeight=v,P.width=g,P.height=v,P.isReady=!0,P.samples=1,P.generateMipMaps=o,P.samplingMode=T,P.type=E,P._generateDepthBuffer=s,P._generateStencilBuffer=a,this._internalTexturesCache.push(P)}if(l&&this._caps.depthTextureExtension){var M=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_MULTIRENDERTARGET);d.activeTexture(d.TEXTURE0),d.bindTexture(d.TEXTURE_2D,M._webGLTexture),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.NEAREST),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.NEAREST),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE),d.texImage2D(d.TEXTURE_2D,0,this.webGLVersion<2?d.DEPTH_COMPONENT:d.DEPTH_COMPONENT16,g,v,0,d.DEPTH_COMPONENT,d.UNSIGNED_SHORT,null),d.framebufferTexture2D(d.FRAMEBUFFER,d.DEPTH_ATTACHMENT,d.TEXTURE_2D,M._webGLTexture,0),M._framebuffer=m,M.baseWidth=g,M.baseHeight=v,M.width=g,M.height=v,M.isReady=!0,M.samples=1,M.generateMipMaps=o,M.samplingMode=d.NEAREST,M._generateDepthBuffer=s,M._generateStencilBuffer=a,_.push(M),this._internalTexturesCache.push(M)}return d.drawBuffers(y),d.bindRenderbuffer(d.RENDERBUFFER,null),this.bindUnboundFramebuffer(null),this.resetTextureCache(),_},n.prototype._setupFramebufferDepthAttachments=function(e,t,i,r,n){void 0===n&&(n=1);var o=null,s=this._gl;return e?(o=s.createRenderbuffer(),s.bindRenderbuffer(s.RENDERBUFFER,o),n>1?s.renderbufferStorageMultisample(s.RENDERBUFFER,n,s.DEPTH24_STENCIL8,i,r):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,i,r),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,o)):t&&(o=s.createRenderbuffer(),s.bindRenderbuffer(s.RENDERBUFFER,o),n>1?s.renderbufferStorageMultisample(s.RENDERBUFFER,n,s.DEPTH_COMPONENT16,i,r):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_COMPONENT16,i,r),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,o)),o},n.prototype.updateRenderTargetTextureSampleCount=function(e,t){if(this.webGLVersion<2||!e)return 1;if(e.samples===t)return t;var i=this._gl;if(t=Math.min(t,i.getParameter(i.MAX_SAMPLES)),e._depthStencilBuffer&&i.deleteRenderbuffer(e._depthStencilBuffer),e._MSAAFramebuffer&&i.deleteFramebuffer(e._MSAAFramebuffer),e._MSAARenderBuffer&&i.deleteRenderbuffer(e._MSAARenderBuffer),t>1){var r=i.createFramebuffer();if(!r)throw new Error("Unable to create multi sampled framebuffer");e._MSAAFramebuffer=r,this.bindUnboundFramebuffer(e._MSAAFramebuffer);var n=i.createRenderbuffer();if(!n)throw new Error("Unable to create multi sampled framebuffer");i.bindRenderbuffer(i.RENDERBUFFER,n),i.renderbufferStorageMultisample(i.RENDERBUFFER,t,i.RGBA8,e.width,e.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,n),e._MSAARenderBuffer=n}else this.bindUnboundFramebuffer(e._framebuffer);return e.samples=t,e._depthStencilBuffer=this._setupFramebufferDepthAttachments(e._generateStencilBuffer,e._generateDepthBuffer,e.width,e.height,t),i.bindRenderbuffer(i.RENDERBUFFER,null),this.bindUnboundFramebuffer(null),t},n.prototype._uploadDataToTexture=function(e,t,i,r,n,o,s,a){this._gl.texImage2D(e,t,i,r,n,0,o,s,a)},n.prototype._uploadCompressedDataToTexture=function(e,t,i,r,n,o){this._gl.compressedTexImage2D(e,t,i,r,n,0,o)},n.prototype.createRenderTargetCubeTexture=function(t,i){var n=this._gl,o=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RENDERTARGET),s=!0,a=!0,l=!1,h=e.Texture.TRILINEAR_SAMPLINGMODE;void 0!==i&&(s=void 0===i.generateMipMaps||i.generateMipMaps,l=!(!(a=void 0===i.generateDepthBuffer||i.generateDepthBuffer)||!i.generateStencilBuffer),void 0!==i.samplingMode&&(h=i.samplingMode)),o.isCube=!0,o.generateMipMaps=s,o.samples=1,o.samplingMode=h;var u=r(h,s,n);this._bindTextureDirectly(n.TEXTURE_CUBE_MAP,o);for(var c=0;c<6;c++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+c,0,n.RGBA,t,t,0,n.RGBA,n.UNSIGNED_BYTE,null);n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_MAG_FILTER,u.mag),n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_MIN_FILTER,u.min),n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE);var f=n.createFramebuffer();return this.bindUnboundFramebuffer(f),o._depthStencilBuffer=this._setupFramebufferDepthAttachments(l,a,t,t),o.generateMipMaps&&(this._bindTextureDirectly(n.TEXTURE_CUBE_MAP,o),n.generateMipmap(n.TEXTURE_CUBE_MAP)),this._bindTextureDirectly(n.TEXTURE_CUBE_MAP,null),n.bindRenderbuffer(n.RENDERBUFFER,null),this.bindUnboundFramebuffer(null),o._framebuffer=f,o.width=t,o.height=t,o.isReady=!0,this.resetTextureCache(),this._internalTexturesCache.push(o),o},n.prototype.createPrefilteredCubeTexture=function(t,i,r,n,o,s,a,l){var h=this;void 0===o&&(o=null),void 0===s&&(s=null),void 0===l&&(l=null);return this.createCubeTexture(t,i,null,!1,function(t){if(t){var s=t.texture;if(s._dataSource=e.InternalTexture.DATASOURCE_CUBEPREFILTERED,s._lodGenerationScale=r,s._lodGenerationOffset=n,h._caps.textureLOD)o&&o(s);else{var a=h._gl,l=t.width;if(l){for(var u=[],c=0;c<3;c++){var f=1-c/2,p=n,d=e.Scalar.Log2(l)*r+n,m=p+(d-p)*f,g=Math.round(Math.min(Math.max(m,0),d)),v=new e.InternalTexture(h,e.InternalTexture.DATASOURCE_TEMP);if(v.isCube=!0,h._bindTextureDirectly(a.TEXTURE_CUBE_MAP,v),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MIN_FILTER,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),t.isDDS){var _=t.info,y=t.data;a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,_.isCompressed?1:0),e.Internals.DDSTools.UploadDDSLevels(h,h._gl,y,_,!0,6,g)}else e.Tools.Warn("DDS is the only prefiltered cube map supported so far.");h._bindTextureDirectly(a.TEXTURE_CUBE_MAP,null);var x=new e.BaseTexture(i);x.isCube=!0,x._texture=v,v.isReady=!0,u.push(x)}s._lodTextureHigh=u[2],s._lodTextureMid=u[1],s._lodTextureLow=u[0],o&&o(s)}}}else o&&o(null)},s,a,l)},n.prototype.createCubeTexture=function(t,i,r,n,s,a,l,h){var u=this;void 0===s&&(s=null),void 0===a&&(a=null),void 0===h&&(h=null);var c=this._gl,f=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_CUBE);f.isCube=!0,f.url=t,f.generateMipMaps=!n,this._doNotHandleContextLost||(f._extension=h,f._files=r);var p=!1,d=!1,m=t.lastIndexOf("."),g=h||(m>-1?t.substring(m).toLowerCase():"");this._textureFormatInUse?(g=this._textureFormatInUse,t=(m>-1?t.substring(0,m):t)+this._textureFormatInUse,p=!0):d=".dds"===g;var v=function(e,t){a&&a(e.status+" "+e.statusText,t)};if(p)e.Tools.LoadFile(t,function(t){var i=new e.Internals.KhronosTextureContainer(t,6),r=i.numberOfMipmapLevels>1&&!n;u._bindTextureDirectly(c.TEXTURE_CUBE_MAP,f),c.pixelStorei(c.UNPACK_FLIP_Y_WEBGL,1),i.uploadLevels(u._gl,!n),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,r?c.LINEAR_MIPMAP_LINEAR:c.LINEAR),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),u._bindTextureDirectly(c.TEXTURE_CUBE_MAP,null),u.resetTextureCache(),f.width=i.pixelWidth,f.height=i.pixelHeight,f.isReady=!0},void 0,void 0,!0,v);else if(d)e.Tools.LoadFile(t,function(t){var i=e.Internals.DDSTools.GetDDSInfo(t),r=(i.isRGB||i.isLuminance||i.mipmapCount>1)&&!n;u._bindTextureDirectly(c.TEXTURE_CUBE_MAP,f),c.pixelStorei(c.UNPACK_FLIP_Y_WEBGL,i.isCompressed?1:0),e.Internals.DDSTools.UploadDDSLevels(u,u._gl,t,i,r,6),n||i.isFourCC||1!==i.mipmapCount||c.generateMipmap(c.TEXTURE_CUBE_MAP),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,r?c.LINEAR_MIPMAP_LINEAR:c.LINEAR),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),u._bindTextureDirectly(c.TEXTURE_CUBE_MAP,null),u.resetTextureCache(),f.width=i.width,f.height=i.height,f.isReady=!0,f.type=i.textureType,s&&s({isDDS:!0,width:i.width,info:i,data:t,texture:f})},void 0,void 0,!0,v);else{if(!r)throw new Error("Cannot load cubemap because files were not defined");o(0,i,function(t){var i=u.needPOTTextures?e.Tools.GetExponentOfTwo(t[0].width,u._caps.maxCubemapTextureSize):t[0].width,r=i;if(u._prepareWorkingCanvas(),u._workingCanvas&&u._workingContext){u._workingCanvas.width=i,u._workingCanvas.height=r;var o=[c.TEXTURE_CUBE_MAP_POSITIVE_X,c.TEXTURE_CUBE_MAP_POSITIVE_Y,c.TEXTURE_CUBE_MAP_POSITIVE_Z,c.TEXTURE_CUBE_MAP_NEGATIVE_X,c.TEXTURE_CUBE_MAP_NEGATIVE_Y,c.TEXTURE_CUBE_MAP_NEGATIVE_Z];u._bindTextureDirectly(c.TEXTURE_CUBE_MAP,f),c.pixelStorei(c.UNPACK_FLIP_Y_WEBGL,0);for(var a=l?u._getInternalFormat(l):u._gl.RGBA,h=0;h<o.length;h++)u._workingContext.drawImage(t[h],0,0,t[h].width,t[h].height,0,0,i,r),c.texImage2D(o[h],0,a,a,c.UNSIGNED_BYTE,u._workingCanvas);n||c.generateMipmap(c.TEXTURE_CUBE_MAP),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,n?c.LINEAR:c.LINEAR_MIPMAP_LINEAR),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),u._bindTextureDirectly(c.TEXTURE_CUBE_MAP,null),u.resetTextureCache(),f.width=i,f.height=r,f.isReady=!0,l&&(f.format=l),f.onLoadedObservable.notifyObservers(f),f.onLoadedObservable.clear(),s&&s()}},r,a)}return this._internalTexturesCache.push(f),f},n.prototype.updateRawCubeTexture=function(t,i,r,n,o,s,a){void 0===s&&(s=null),void 0===a&&(a=0),t._bufferViewArray=i,t.format=r,t.type=n,t.invertY=o,t._compression=s;var l=this._gl,h=this._getWebGLTextureType(n),u=this._getInternalFormat(r),c=this._getRGBABufferInternalSizedFormat(n),f=!1;u===l.RGB&&(u=l.RGBA,f=!0),this._bindTextureDirectly(l.TEXTURE_CUBE_MAP,t),l.pixelStorei(l.UNPACK_FLIP_Y_WEBGL,void 0===o?1:o?1:0),t.width%4!=0&&l.pixelStorei(l.UNPACK_ALIGNMENT,1);for(var p=0;p<6;p++){var d=i[p];s?l.compressedTexImage2D(l.TEXTURE_CUBE_MAP_POSITIVE_X+p,a,this.getCaps().s3tc[s],t.width,t.height,0,d):(f&&(d=this._convertRGBtoRGBATextureData(d,t.width,t.height,n)),l.texImage2D(l.TEXTURE_CUBE_MAP_POSITIVE_X+p,a,c,t.width,t.height,0,u,h,d))}(!this.needPOTTextures||e.Tools.IsExponentOfTwo(t.width)&&e.Tools.IsExponentOfTwo(t.height))&&t.generateMipMaps&&0===a&&this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP),this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,null),this.resetTextureCache(),t.isReady=!0},n.prototype.createRawCubeTexture=function(t,i,n,o,s,a,l,h){void 0===h&&(h=null);var u=this._gl,c=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_CUBERAW);c.isCube=!0,c.generateMipMaps=s,c.format=n,c.type=o,this._doNotHandleContextLost||(c._bufferViewArray=t);var f=this._getWebGLTextureType(o),p=this._getInternalFormat(n);p===u.RGB&&(p=u.RGBA);var d=i,m=d;if(c.width=d,c.height=m,!this.needPOTTextures||e.Tools.IsExponentOfTwo(c.width)&&e.Tools.IsExponentOfTwo(c.height)||(s=!1),t&&this.updateRawCubeTexture(c,t,n,o,a,h),this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,c),t&&s&&this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP),f!==u.FLOAT||this._caps.textureFloatLinearFiltering)if(f!==this._gl.HALF_FLOAT_OES||this._caps.textureHalfFloatLinearFiltering){var g=r(l,s,u);u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MAG_FILTER,g.mag),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MIN_FILTER,g.min)}else u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MIN_FILTER,u.NEAREST);else u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MIN_FILTER,u.NEAREST);return 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),this._bindTextureDirectly(u.TEXTURE_CUBE_MAP,null),c},n.prototype.createRawCubeTextureFromUrl=function(t,i,r,n,o,s,a,l,h,u,c,f){var p=this;void 0===h&&(h=null),void 0===u&&(u=null),void 0===c&&(c=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===f&&(f=!1);var d=this._gl,m=this.createRawCubeTexture(null,r,n,o,!s,f,c);i._addPendingData(m),m.url=t,this._internalTexturesCache.push(m);var g=function(e){var t=m.width,r=a(e);if(r){if(l){var u=p._getWebGLTextureType(o),c=p._getInternalFormat(n),g=p._getRGBABufferInternalSizedFormat(o),v=!1;c===d.RGB&&(c=d.RGBA,v=!0),p._bindTextureDirectly(d.TEXTURE_CUBE_MAP,m),d.pixelStorei(d.UNPACK_FLIP_Y_WEBGL,0);for(var _=l(r),y=0;y<_.length;y++)for(var x=t>>y,b=0;b<6;b++){var T=_[y][b];v&&(T=p._convertRGBtoRGBATextureData(T,x,x,o)),d.texImage2D(b,y,g,x,x,0,c,u,T)}p._bindTextureDirectly(d.TEXTURE_CUBE_MAP,null)}else m.generateMipMaps=!s,p.updateRawCubeTexture(m,r,n,o,f);m.isReady=!0,p.resetTextureCache(),i._removePendingData(m),h&&h()}};return e.Tools.LoadFile(t,function(e){g(e)},void 0,i.database,!0,function(e,t){i._removePendingData(m),u&&u(e.status+" "+e.statusText,t)}),m},n.prototype.updateRawTexture3D=function(e,t,i,r,n){void 0===n&&(n=null);var o=this._getInternalFormat(i);this._bindTextureDirectly(this._gl.TEXTURE_3D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,void 0===r?1:r?1:0),this._doNotHandleContextLost||(e._bufferView=t,e.format=i,e.invertY=r,e._compression=n),e.width%4!=0&&this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT,1),n&&t?this._gl.compressedTexImage3D(this._gl.TEXTURE_3D,0,this.getCaps().s3tc[n],e.width,e.height,e.depth,0,t):this._gl.texImage3D(this._gl.TEXTURE_3D,0,o,e.width,e.height,e.depth,0,o,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_3D),this._bindTextureDirectly(this._gl.TEXTURE_3D,null),this.resetTextureCache(),e.isReady=!0},n.prototype.createRawTexture3D=function(t,i,n,o,s,a,l,h,u){void 0===u&&(u=null);var c=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RAW3D);c.baseWidth=i,c.baseHeight=n,c.baseDepth=o,c.width=i,c.height=n,c.depth=o,c.format=s,c.generateMipMaps=a,c.samplingMode=h,c.is3D=!0,this._doNotHandleContextLost||(c._bufferView=t),this.updateRawTexture3D(c,t,s,l,u),this._bindTextureDirectly(this._gl.TEXTURE_3D,c);var f=r(h,a,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_MAG_FILTER,f.mag),this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_MIN_FILTER,f.min),a&&this._gl.generateMipmap(this._gl.TEXTURE_3D),this._bindTextureDirectly(this._gl.TEXTURE_3D,null),this._internalTexturesCache.push(c),c},n.prototype._prepareWebGLTextureContinuation=function(e,t,i,n,o){var s=this._gl;if(s){var a=r(o,!i,s);s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,a.mag),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,a.min),i||n||s.generateMipmap(s.TEXTURE_2D),this._bindTextureDirectly(s.TEXTURE_2D,null),this.resetTextureCache(),t&&t._removePendingData(e),e.onLoadedObservable.notifyObservers(e),e.onLoadedObservable.clear()}},n.prototype._prepareWebGLTexture=function(t,i,r,n,o,s,a,l,h){var u=this;void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE);var c=this.needPOTTextures?e.Tools.GetExponentOfTwo(r,this.getCaps().maxTextureSize):r,f=this.needPOTTextures?e.Tools.GetExponentOfTwo(n,this.getCaps().maxTextureSize):n,p=this._gl;if(p){if(!t._webGLTexture)return this.resetTextureCache(),void(i&&i._removePendingData(t));this._bindTextureDirectly(p.TEXTURE_2D,t),p.pixelStorei(p.UNPACK_FLIP_Y_WEBGL,void 0===o?1:o?1:0),t.baseWidth=r,t.baseHeight=n,t.width=c,t.height=f,t.isReady=!0,l(c,f,function(){u._prepareWebGLTextureContinuation(t,i,s,a,h)})||this._prepareWebGLTextureContinuation(t,i,s,a,h)}},n.prototype._convertRGBtoRGBATextureData=function(e,t,i,r){var o;o=r===n.TEXTURETYPE_FLOAT?new Float32Array(t*i*4):new Uint32Array(t*i*4);for(var s=0;s<t;s++)for(var a=0;a<i;a++){var l=3*(a*t+s),h=4*(a*t+s);o[h+0]=e[l+0],o[h+1]=e[l+1],o[h+2]=e[l+2],o[h+3]=1}return o},n.prototype._releaseFramebufferObjects=function(e){var t=this._gl;e._framebuffer&&(t.deleteFramebuffer(e._framebuffer),e._framebuffer=null),e._depthStencilBuffer&&(t.deleteRenderbuffer(e._depthStencilBuffer),e._depthStencilBuffer=null),e._MSAAFramebuffer&&(t.deleteFramebuffer(e._MSAAFramebuffer),e._MSAAFramebuffer=null),e._MSAARenderBuffer&&(t.deleteRenderbuffer(e._MSAARenderBuffer),e._MSAARenderBuffer=null)},n.prototype._releaseTexture=function(e){var t=this._gl;this._releaseFramebufferObjects(e),t.deleteTexture(e._webGLTexture),this.unbindAllTextures();var i=this._internalTexturesCache.indexOf(e);-1!==i&&this._internalTexturesCache.splice(i,1),e._lodTextureHigh&&e._lodTextureHigh.dispose(),e._lodTextureMid&&e._lodTextureMid.dispose(),e._lodTextureLow&&e._lodTextureLow.dispose()},n.prototype.setProgram=function(e){this._currentProgram!==e&&(this._gl.useProgram(e),this._currentProgram=e)},n.prototype.bindSamplers=function(e){this.setProgram(e.getProgram());for(var t=e.getSamplers(),i=0;i<t.length;i++){var r=e.getUniform(t[i]);this._gl.uniform1i(r,i)}this._currentEffect=null},n.prototype.activateTextureChannel=function(e){this._activeTextureChannel!==e&&(this._gl.activeTexture(e),this._activeTextureChannel=e)},n.prototype._bindTextureDirectly=function(e,t){this._activeTexturesCache[this._activeTextureChannel]!==t&&(this._gl.bindTexture(e,t?t._webGLTexture:null),this._activeTexturesCache[this._activeTextureChannel]=t)},n.prototype._bindTexture=function(e,t){e<0||(this.activateTextureChannel(this._gl.TEXTURE0+e),this._bindTextureDirectly(this._gl.TEXTURE_2D,t))},n.prototype.setTextureFromPostProcess=function(e,t){this._bindTexture(e,t?t._textures.data[t._currentRenderTextureInd]:null)},n.prototype.unbindAllTextures=function(){for(var e=0;e<this._caps.maxTexturesImageUnits;e++)this.activateTextureChannel(this._gl.TEXTURE0+e),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,null),this.webGLVersion>1&&this._bindTextureDirectly(this._gl.TEXTURE_3D,null)},n.prototype.setTexture=function(e,t,i){e<0||this._setTexture(e,i)&&this._gl.uniform1i(t,e)},n.prototype._setTexture=function(t,i){if(!i)return null!=this._activeTexturesCache[t]&&(this.activateTextureChannel(this._gl.TEXTURE0+t),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,null),this.webGLVersion>1&&this._bindTextureDirectly(this._gl.TEXTURE_3D,null)),!1;var r=!1;if(i.video)this.activateTextureChannel(this._gl.TEXTURE0+t),r=!0,i.update();else if(i.delayLoadState===n.DELAYLOADSTATE_NOTLOADED)return i.delayLoad(),!1;var o;if(o=i.isReady()?i.getInternalTexture():i.isCube?this.emptyCubeTexture:i.is3D?this.emptyTexture3D:this.emptyTexture,r||this.activateTextureChannel(this._gl.TEXTURE0+t),this._activeTexturesCache[this._activeTextureChannel]===o)return!1;if(o&&o.is3D){if(this._bindTextureDirectly(this._gl.TEXTURE_3D,o),o&&o._cachedWrapU!==i.wrapU)switch(o._cachedWrapU=i.wrapU,i.wrapU){case e.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_WRAP_S,this._gl.REPEAT);break;case e.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_WRAP_S,this._gl.CLAMP_TO_EDGE);break;case e.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_WRAP_S,this._gl.MIRRORED_REPEAT)}if(o&&o._cachedWrapV!==i.wrapV)switch(o._cachedWrapV=i.wrapV,i.wrapV){case e.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_WRAP_T,this._gl.REPEAT);break;case e.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_WRAP_T,this._gl.CLAMP_TO_EDGE);break;case e.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_WRAP_T,this._gl.MIRRORED_REPEAT)}if(o&&o._cachedWrapR!==i.wrapR)switch(o._cachedWrapR=i.wrapR,i.wrapV){case e.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_WRAP_R,this._gl.REPEAT);break;case e.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_WRAP_R,this._gl.CLAMP_TO_EDGE);break;case e.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_WRAP_R,this._gl.MIRRORED_REPEAT)}this._setAnisotropicLevel(this._gl.TEXTURE_3D,i)}else if(o&&o.isCube){if(this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,o),o._cachedCoordinatesMode!==i.coordinatesMode){o._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._bindTextureDirectly(this._gl.TEXTURE_2D,o),o&&o._cachedWrapU!==i.wrapU)switch(o._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(o&&o._cachedWrapV!==i.wrapV)switch(o._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)}return!0},n.prototype.setTextureArray=function(e,t,i){if(!(e<0)&&t){this._textureUnits&&this._textureUnits.length===i.length||(this._textureUnits=new Int32Array(i.length));for(var r=0;r<i.length;r++)this._textureUnits[r]=e+r;this._gl.uniform1iv(t,this._textureUnits);for(var n=0;n<i.length;n++)this._setTexture(e+n,i[n])}},n.prototype._setAnisotropicLevel=function(t,i){var r=i.getInternalTexture();if(r){var n=this._caps.textureAnisotropicFilterExtension,o=i.anisotropicFilteringLevel;r.samplingMode!==e.Texture.LINEAR_LINEAR_MIPNEAREST&&r.samplingMode!==e.Texture.LINEAR_LINEAR_MIPLINEAR&&r.samplingMode!==e.Texture.LINEAR_LINEAR&&(o=1),n&&r._cachedAnisotropicFilteringLevel!==o&&(this._gl.texParameterf(t,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(o,this._caps.maxAnisotropy)),r._cachedAnisotropicFilteringLevel=o)}},n.prototype.readPixels=function(e,t,i,r){var n=new Uint8Array(r*i*4);return this._gl.readPixels(e,t,i,r,this._gl.RGBA,this._gl.UNSIGNED_BYTE,n),n},n.prototype.addExternalData=function(t,i){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.add(t,i)},n.prototype.getExternalData=function(t){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.get(t)},n.prototype.getOrAddExternalDataWithFactory=function(t,i){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.getOrAddWithFactory(t,i)},n.prototype.removeExternalData=function(t){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.remove(t)},n.prototype.unbindAllAttributes=function(){if(this._mustWipeVertexAttributes){this._mustWipeVertexAttributes=!1;for(e=0;e<this._caps.maxVertexAttribs;e++)this._gl.disableVertexAttribArray(e),this._vertexAttribArraysEnabled[e]=!1,this._currentBufferPointers[e].active=!1}else for(var e=0,t=this._vertexAttribArraysEnabled.length;e<t;e++)e>=this._caps.maxVertexAttribs||!this._vertexAttribArraysEnabled[e]||(this._gl.disableVertexAttribArray(e),this._vertexAttribArraysEnabled[e]=!1,this._currentBufferPointers[e].active=!1)},n.prototype.releaseEffects=function(){for(var e in this._compiledEffects)this._deleteProgram(this._compiledEffects[e]._program);this._compiledEffects={}},n.prototype.dispose=function(){for(this.hideLoadingUI(),this.stopRenderLoop();this.postProcesses.length;)this.postProcesses[0].dispose();for(this._emptyTexture&&(this._releaseTexture(this._emptyTexture),this._emptyTexture=null),this._emptyCubeTexture&&(this._releaseTexture(this._emptyCubeTexture),this._emptyCubeTexture=null),this._rescalePostProcess&&this._rescalePostProcess.dispose();this.scenes.length;)this.scenes[0].dispose();n.audioEngine&&n.audioEngine.dispose(),this.releaseEffects(),this.unbindAllAttributes(),this._dummyFramebuffer&&this._gl.deleteFramebuffer(this._dummyFramebuffer),this.disableVR(),e.Tools.IsWindowObjectExist()&&(window.removeEventListener("blur",this._onBlur),window.removeEventListener("focus",this._onFocus),window.removeEventListener("vrdisplaypointerrestricted",this._onVRDisplayPointerRestricted),window.removeEventListener("vrdisplaypointerunrestricted",this._onVRDisplayPointerUnrestricted),this._renderingCanvas&&(this._renderingCanvas.removeEventListener("focus",this._onCanvasFocus),this._renderingCanvas.removeEventListener("blur",this._onCanvasBlur),this._renderingCanvas.removeEventListener("pointerout",this._onCanvasBlur),this._doNotHandleContextLost||(this._renderingCanvas.removeEventListener("webglcontextlost",this._onContextLost),this._renderingCanvas.removeEventListener("webglcontextrestored",this._onContextRestored))),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),this._onVrDisplayConnect&&(window.removeEventListener("vrdisplayconnect",this._onVrDisplayConnect),this._onVrDisplayDisconnect&&window.removeEventListener("vrdisplaydisconnect",this._onVrDisplayDisconnect),this._onVrDisplayPresentChange&&window.removeEventListener("vrdisplaypresentchange",this._onVrDisplayPresentChange),this._onVrDisplayConnect=null,this._onVrDisplayDisconnect=null));var t=n.Instances.indexOf(this);t>=0&&n.Instances.splice(t,1),this._workingCanvas=null,this._workingContext=null,this._currentBufferPointers=[],this._renderingCanvas=null,this._currentProgram=null,this.onResizeObservable.clear(),this.onCanvasBlurObservable.clear(),this.onCanvasFocusObservable.clear(),this.onCanvasPointerOutObservable.clear(),this.onBeginFrameObservable.clear(),this.onEndFrameObservable.clear(),e.Effect.ResetCache()},n.prototype.displayLoadingUI=function(){if(e.Tools.IsWindowObjectExist()){var t=this.loadingScreen;t&&t.displayLoadingUI()}},n.prototype.hideLoadingUI=function(){if(e.Tools.IsWindowObjectExist()){var t=this.loadingScreen;t&&t.hideLoadingUI()}},Object.defineProperty(n.prototype,"loadingScreen",{get:function(){return!this._loadingScreen&&e.DefaultLoadingScreen&&this._renderingCanvas&&(this._loadingScreen=new e.DefaultLoadingScreen(this._renderingCanvas)),this._loadingScreen},set:function(e){this._loadingScreen=e},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"loadingUIText",{set:function(e){this.loadingScreen.loadingUIText=e},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"loadingUIBackgroundColor",{set:function(e){this.loadingScreen.loadingUIBackgroundColor=e},enumerable:!0,configurable:!0}),n.prototype.attachContextLostEvent=function(e){this._renderingCanvas&&this._renderingCanvas.addEventListener("webglcontextlost",e,!1)},n.prototype.attachContextRestoredEvent=function(e){this._renderingCanvas&&this._renderingCanvas.addEventListener("webglcontextrestored",e,!1)},n.prototype.getVertexShaderSource=function(e){var t=this._gl.getAttachedShaders(e);return t?this._gl.getShaderSource(t[0]):null},n.prototype.getFragmentShaderSource=function(e){var t=this._gl.getAttachedShaders(e);return t?this._gl.getShaderSource(t[1]):null},n.prototype.getError=function(){return this._gl.getError()},n.prototype.getFps=function(){return this._fps},n.prototype.getDeltaTime=function(){return this._deltaTime},n.prototype._measureFps=function(){this._performanceMonitor.sampleFrame(),this._fps=this._performanceMonitor.averageFPS,this._deltaTime=this._performanceMonitor.instantaneousFrameTime||0},n.prototype._readTexturePixels=function(e,t,i,r){void 0===r&&(r=-1);var n=this._gl;if(!this._dummyFramebuffer){var o=n.createFramebuffer();if(!o)throw new Error("Unable to create dummy framebuffer");this._dummyFramebuffer=o}n.bindFramebuffer(n.FRAMEBUFFER,this._dummyFramebuffer),r>-1?n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_CUBE_MAP_POSITIVE_X+r,e._webGLTexture,0):n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,e._webGLTexture,0);var s,a=void 0!==e.type?this._getWebGLTextureType(e.type):n.UNSIGNED_BYTE;switch(a){case n.UNSIGNED_BYTE:s=new Uint8Array(4*t*i),a=n.UNSIGNED_BYTE;break;default:s=new Float32Array(4*t*i),a=n.FLOAT}return n.readPixels(0,0,t,i,n.RGBA,a,s),n.bindFramebuffer(n.FRAMEBUFFER,this._currentFramebuffer),s},n.prototype._canRenderToFloatFramebuffer=function(){return this._webGLVersion>1?this._caps.colorBufferFloat:this._canRenderToFramebuffer(e.Engine.TEXTURETYPE_FLOAT)},n.prototype._canRenderToHalfFloatFramebuffer=function(){return this._webGLVersion>1?this._caps.colorBufferFloat:this._canRenderToFramebuffer(e.Engine.TEXTURETYPE_HALF_FLOAT)},n.prototype._canRenderToFramebuffer=function(e){for(var t=this._gl;t.getError()!==t.NO_ERROR;);var i=!0,r=t.createTexture();t.bindTexture(t.TEXTURE_2D,r),t.texImage2D(t.TEXTURE_2D,0,this._getRGBABufferInternalSizedFormat(e),1,1,0,t.RGBA,this._getWebGLTextureType(e),null),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST);var n=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,n),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r,0);var o=t.checkFramebufferStatus(t.FRAMEBUFFER);if(i=i&&o===t.FRAMEBUFFER_COMPLETE,(i=i&&t.getError()===t.NO_ERROR)&&(t.clear(t.COLOR_BUFFER_BIT),i=i&&t.getError()===t.NO_ERROR),i){t.bindFramebuffer(t.FRAMEBUFFER,null);var s=t.RGBA,a=t.UNSIGNED_BYTE,l=new Uint8Array(4);t.readPixels(0,0,1,1,s,a,l),i=i&&t.getError()===t.NO_ERROR}for(t.deleteTexture(r),t.deleteFramebuffer(n),t.bindFramebuffer(t.FRAMEBUFFER,null);!i&&t.getError()!==t.NO_ERROR;);return i},n.prototype._getWebGLTextureType=function(e){return e===n.TEXTURETYPE_FLOAT?this._gl.FLOAT:e===n.TEXTURETYPE_HALF_FLOAT?this._gl.HALF_FLOAT_OES:this._gl.UNSIGNED_BYTE},n.prototype._getRGBABufferInternalSizedFormat=function(e){return 1===this._webGLVersion?this._gl.RGBA:e===n.TEXTURETYPE_FLOAT?this._gl.RGBA32F:e===n.TEXTURETYPE_HALF_FLOAT?this._gl.RGBA16F:this._gl.RGBA},n.prototype.createQuery=function(){return this._gl.createQuery()},n.prototype.deleteQuery=function(e){return this._gl.deleteQuery(e),this},n.prototype.isQueryResultAvailable=function(e){return this._gl.getQueryParameter(e,this._gl.QUERY_RESULT_AVAILABLE)},n.prototype.getQueryResult=function(e){return this._gl.getQueryParameter(e,this._gl.QUERY_RESULT)},n.prototype.beginOcclusionQuery=function(e,t){var i=this.getGlAlgorithmType(e);return this._gl.beginQuery(i,t),this},n.prototype.endOcclusionQuery=function(e){var t=this.getGlAlgorithmType(e);return this._gl.endQuery(t),this},n.prototype._createTimeQuery=function(){var e=this._caps.timerQuery;return e.createQueryEXT?e.createQueryEXT():this.createQuery()},n.prototype._deleteTimeQuery=function(e){var t=this._caps.timerQuery;t.deleteQueryEXT?t.deleteQueryEXT(e):this.deleteQuery(e)},n.prototype._getTimeQueryResult=function(e){var t=this._caps.timerQuery;return t.getQueryObjectEXT?t.getQueryObjectEXT(e,t.QUERY_RESULT_EXT):this.getQueryResult(e)},n.prototype._getTimeQueryAvailability=function(e){var t=this._caps.timerQuery;return t.getQueryObjectEXT?t.getQueryObjectEXT(e,t.QUERY_RESULT_AVAILABLE_EXT):this.isQueryResultAvailable(e)},n.prototype.startTimeQuery=function(){var t=this._caps.timerQuery;if(!t)return null;var i=new e._TimeToken;if(this._gl.getParameter(t.GPU_DISJOINT_EXT),this._caps.canUseTimestampForTimerQuery)i._startTimeQuery=this._createTimeQuery(),t.queryCounterEXT(i._startTimeQuery,t.TIMESTAMP_EXT);else{if(this._currentNonTimestampToken)return this._currentNonTimestampToken;i._timeElapsedQuery=this._createTimeQuery(),t.beginQueryEXT?t.beginQueryEXT(t.TIME_ELAPSED_EXT,i._timeElapsedQuery):this._gl.beginQuery(t.TIME_ELAPSED_EXT,i._timeElapsedQuery),this._currentNonTimestampToken=i}return i},n.prototype.endTimeQuery=function(e){var t=this._caps.timerQuery;if(!t||!e)return-1;if(this._caps.canUseTimestampForTimerQuery){if(!e._startTimeQuery)return-1;e._endTimeQuery||(e._endTimeQuery=this._createTimeQuery(),t.queryCounterEXT(e._endTimeQuery,t.TIMESTAMP_EXT))}else if(!e._timeElapsedQueryEnded){if(!e._timeElapsedQuery)return-1;t.endQueryEXT?t.endQueryEXT(t.TIME_ELAPSED_EXT):this._gl.endQuery(t.TIME_ELAPSED_EXT),e._timeElapsedQueryEnded=!0}var i=this._gl.getParameter(t.GPU_DISJOINT_EXT),r=!1;if(e._endTimeQuery?r=this._getTimeQueryAvailability(e._endTimeQuery):e._timeElapsedQuery&&(r=this._getTimeQueryAvailability(e._timeElapsedQuery)),r&&!i){var n=0;if(this._caps.canUseTimestampForTimerQuery){if(!e._startTimeQuery||!e._endTimeQuery)return-1;var o=this._getTimeQueryResult(e._startTimeQuery);n=this._getTimeQueryResult(e._endTimeQuery)-o,this._deleteTimeQuery(e._startTimeQuery),this._deleteTimeQuery(e._endTimeQuery),e._startTimeQuery=null,e._endTimeQuery=null}else{if(!e._timeElapsedQuery)return-1;n=this._getTimeQueryResult(e._timeElapsedQuery),this._deleteTimeQuery(e._timeElapsedQuery),e._timeElapsedQuery=null,e._timeElapsedQueryEnded=!1,this._currentNonTimestampToken=null}return n}return-1},n.prototype.getGlAlgorithmType=function(t){return t===e.AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE?this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE:this._gl.ANY_SAMPLES_PASSED},n.prototype.createTransformFeedback=function(){return this._gl.createTransformFeedback()},n.prototype.deleteTransformFeedback=function(e){this._gl.deleteTransformFeedback(e)},n.prototype.bindTransformFeedback=function(e){this._gl.bindTransformFeedback(this._gl.TRANSFORM_FEEDBACK,e)},n.prototype.beginTransformFeedback=function(e){void 0===e&&(e=!0),this._gl.beginTransformFeedback(e?this._gl.POINTS:this._gl.TRIANGLES)},n.prototype.endTransformFeedback=function(){this._gl.endTransformFeedback()},n.prototype.setTranformFeedbackVaryings=function(e,t){this._gl.transformFeedbackVaryings(e,t,this._gl.INTERLEAVED_ATTRIBS)},n.prototype.bindTransformFeedbackBuffer=function(e){this._gl.bindBufferBase(this._gl.TRANSFORM_FEEDBACK_BUFFER,0,e)},n.isSupported=function(){try{var e=document.createElement("canvas");return null!=(e.getContext("webgl")||e.getContext("experimental-webgl"))&&!!window.WebGLRenderingContext}catch(e){return!1}},n.Instances=new Array,n._ALPHA_DISABLE=0,n._ALPHA_ADD=1,n._ALPHA_COMBINE=2,n._ALPHA_SUBTRACT=3,n._ALPHA_MULTIPLY=4,n._ALPHA_MAXIMIZED=5,n._ALPHA_ONEONE=6,n._ALPHA_PREMULTIPLIED=7,n._ALPHA_PREMULTIPLIED_PORTERDUFF=8,n._ALPHA_INTERPOLATE=9,n._ALPHA_SCREENMODE=10,n._DELAYLOADSTATE_NONE=0,n._DELAYLOADSTATE_LOADED=1,n._DELAYLOADSTATE_LOADING=2,n._DELAYLOADSTATE_NOTLOADED=4,n._TEXTUREFORMAT_ALPHA=0,n._TEXTUREFORMAT_LUMINANCE=1,n._TEXTUREFORMAT_LUMINANCE_ALPHA=2,n._TEXTUREFORMAT_RGB=4,n._TEXTUREFORMAT_RGBA=5,n._TEXTURETYPE_UNSIGNED_INT=0,n._TEXTURETYPE_FLOAT=1,n._TEXTURETYPE_HALF_FLOAT=2,n._NEVER=512,n._ALWAYS=519,n._LESS=513,n._EQUAL=514,n._LEQUAL=515,n._GREATER=516,n._GEQUAL=518,n._NOTEQUAL=517,n._KEEP=7680,n._REPLACE=7681,n._INCR=7682,n._DECR=7683,n._INVERT=5386,n._INCR_WRAP=34055,n._DECR_WRAP=34056,n._SCALEMODE_FLOOR=1,n._SCALEMODE_NEAREST=2,n._SCALEMODE_CEILING=3,n.CollisionsEpsilon=.001,n.CodeRepository="src/",n.ShadersRepository="src/Shaders/",n}();e.Engine=u}(s||(s={}));!function(e){var t=function(){function t(t,i){void 0===i&&(i=null),this.state="",this.metadata=null,this.doNotSerialize=!1,this.animations=new Array,this._ranges={},this._isEnabled=!0,this._isReady=!0,this._currentRenderId=-1,this._parentRenderId=-1,this.onDisposeObservable=new e.Observable,this._behaviors=new Array,this.name=t,this.id=t,this._scene=i||e.Engine.LastCreatedScene,this.uniqueId=this._scene.getUniqueId(),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.getClassName=function(){return"Node"},Object.defineProperty(t.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},t.prototype.getEngine=function(){return this._scene.getEngine()},t.prototype.addBehavior=function(e){var t=this;if(-1!==this._behaviors.indexOf(e))return this;if(e.init(),this._scene.isLoading)var i=this._scene.onDataLoadedObservable.add(function(){e.attach(t),t._scene.onDataLoadedObservable.remove(i)});else e.attach(this);return this._behaviors.push(e),this},t.prototype.removeBehavior=function(e){var t=this._behaviors.indexOf(e);return-1===t?this:(this._behaviors[t].detach(),this._behaviors.splice(t,1),this)},Object.defineProperty(t.prototype,"behaviors",{get:function(){return this._behaviors},enumerable:!0,configurable:!0}),t.prototype.getBehaviorByName=function(e){for(var t=0,i=this._behaviors;t<i.length;t++){var r=i[t];if(r.name===e)return r}return null},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.parent&&(this._parentRenderId=this.parent._currentRenderId)},t.prototype.isSynchronizedWithParent=function(){return!this.parent||this._parentRenderId===this.parent._currentRenderId&&this.parent.isSynchronized()},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&&(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())},t.prototype.setEnabled=function(e){this._isEnabled=e},t.prototype.isDescendantOf=function(e){return!!this.parent&&(this.parent===e||this.parent.isDescendantOf(e))},t.prototype._getDescendants=function(e,t,i){if(void 0===t&&(t=!1),this._children)for(var r=0;r<this._children.length;r++){var n=this._children[r];i&&!i(n)||e.push(n),t||n._getDescendants(e,!1,i)}},t.prototype.getDescendants=function(e,t){var i=new Array;return this._getDescendants(i,e,t),i},t.prototype.getChildMeshes=function(t,i){var r=[];return this._getDescendants(r,t,function(t){return(!i||i(t))&&t instanceof e.AbstractMesh}),r},t.prototype.getChildren=function(e){return this.getDescendants(!0,e)},t.prototype._setReady=function(e){e!==this._isReady&&(e?(this._isReady=!0,this.onReady&&this.onReady(this)):this._isReady=!1)},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,r){if(!this._ranges[t]){this._ranges[t]=new e.AnimationRange(t,i,r);for(var n=0,o=this.animations.length;n<o;n++)this.animations[n]&&this.animations[n].createRange(t,i,r)}},t.prototype.deleteAnimationRange=function(e,t){void 0===t&&(t=!0);for(var i=0,r=this.animations.length;i<r;i++)this.animations[i]&&this.animations[i].deleteRange(e,t);this._ranges[e]=null},t.prototype.getAnimationRange=function(e){return this._ranges[e]},t.prototype.beginAnimation=function(e,t,i,r){var n=this.getAnimationRange(e);n&&this._scene.beginAnimation(this,n.from,n.to,t,i,r)},t.prototype.serializeAnimationRanges=function(){var e=[];for(var t in this._ranges){var i=this._ranges[t];if(i){var r={};r.name=t,r.from=i.from,r.to=i.to,e.push(r)}}return e},t.prototype.dispose=function(){this.parent=null,this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear();for(var e=0,t=this._behaviors;e<t.length;e++)t[e].detach();this._behaviors=[]},t.ParseAnimationRanges=function(e,t,i){if(t.ranges)for(var r=0;r<t.ranges.length;r++){var n=t.ranges[r];e.createAnimationRange(n.name,n.from,n.to)}},r([e.serialize()],t.prototype,"name",void 0),r([e.serialize()],t.prototype,"id",void 0),r([e.serialize()],t.prototype,"uniqueId",void 0),r([e.serialize()],t.prototype,"state",void 0),r([e.serialize()],t.prototype,"metadata",void 0),t}();e.Node=t}(s||(s={}));!function(e){var t=function(){function t(t,i){this.minimum=t,this.maximum=i,this._tempRadiusVector=e.Vector3.Zero();var r=e.Vector3.Distance(t,i);this.center=e.Vector3.Lerp(t,i,.5),this.radius=.5*r,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;t<6;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,r=this.centerWorld.y-t.y,n=this.centerWorld.z-t.z,o=Math.sqrt(i*i+r*r+n*n);return!(Math.abs(this.radiusWorld-o)<e.Epsilon)},t.Intersects=function(e,t){var i=e.centerWorld.x-t.centerWorld.x,r=e.centerWorld.y-t.centerWorld.y,n=e.centerWorld.z-t.centerWorld.z,o=Math.sqrt(i*i+r*r+n*n);return!(e.radiusWorld+t.radiusWorld<o)},t}();e.BoundingSphere=t}(s||(s={}));!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 r=0;r<this.vectors.length;r++)this.vectorsWorld[r]=e.Vector3.Zero();this.minimumWorld=e.Vector3.Zero(),this.maximumWorld=e.Vector3.Zero(),this.centerWorld=e.Vector3.Zero(),this.extendSizeWorld=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 r=this.vectorsWorld[i];e.Vector3.TransformCoordinatesToRef(this.vectors[i],t,r),r.x<this.minimumWorld.x&&(this.minimumWorld.x=r.x),r.y<this.minimumWorld.y&&(this.minimumWorld.y=r.y),r.z<this.minimumWorld.z&&(this.minimumWorld.z=r.z),r.x>this.maximumWorld.x&&(this.maximumWorld.x=r.x),r.y>this.maximumWorld.y&&(this.maximumWorld.y=r.y),r.z>this.maximumWorld.z&&(this.maximumWorld.z=r.z)}this.maximumWorld.subtractToRef(this.minimumWorld,this.extendSizeWorld),this.extendSizeWorld.scaleInPlace(.5),this.maximumWorld.addToRef(this.minimumWorld,this.centerWorld),this.centerWorld.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)&&(!(this.maximumWorld.y-t.y<i||i>t.y-this.minimumWorld.y)&&!(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)&&(!(this.maximumWorld.y<e.y||this.minimumWorld.y>t.y)&&!(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)&&(!(e.maximumWorld.y<t.minimumWorld.y||e.minimumWorld.y>t.maximumWorld.y)&&!(e.maximumWorld.z<t.minimumWorld.z||e.minimumWorld.z>t.maximumWorld.z))},t.IntersectsSphere=function(t,i,r,n){var o=e.Vector3.Clamp(r,t,i);return e.Vector3.DistanceSquared(r,o)<=n*n},t.IsCompletelyInFrustum=function(e,t){for(var i=0;i<6;i++)for(var r=0;r<8;r++)if(t[i].dotCoordinate(e[r])<0)return!1;return!0},t.IsInFrustum=function(e,t){for(var i=0;i<6;i++){for(var r=8,n=0;n<8&&t[i].dotCoordinate(e[n])<0;n++)--r;if(0===r)return!1}return!0},t}();e.BoundingBox=t}(s||(s={}));!function(e){var t=function(t,i){var r=e.Vector3.Dot(i.centerWorld,t),n=Math.abs(e.Vector3.Dot(i.directions[0],t))*i.extendSize.x+Math.abs(e.Vector3.Dot(i.directions[1],t))*i.extendSize.y+Math.abs(e.Vector3.Dot(i.directions[2],t))*i.extendSize.z;return{min:r-n,max:r+n}},i=function(e,t,i,r){return!(e>r||i>t)},r=function(e,r,n){var o=t(e,r),s=t(e,n);return i(o.min,o.max,s.min,s.max)},n=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.centerOn=function(t,i){return this.minimum=t.subtract(i),this.maximum=t.add(i),this.boundingBox=new e.BoundingBox(this.minimum,this.maximum),this.boundingSphere=new e.BoundingSphere(this.minimum,this.maximum),this},t.prototype.isInFrustum=function(e){return!!this.boundingSphere.isInFrustum(e)&&this.boundingBox.isInFrustum(e)},Object.defineProperty(t.prototype,"diagonalLength",{get:function(){var e=this.boundingBox;return e.maximumWorld.subtract(e.minimumWorld).length()},enumerable:!0,configurable:!0}),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))},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 n=this.boundingBox,o=t.boundingBox;return!!r(n.directions[0],n,o)&&(!!r(n.directions[1],n,o)&&(!!r(n.directions[2],n,o)&&(!!r(o.directions[0],n,o)&&(!!r(o.directions[1],n,o)&&(!!r(o.directions[2],n,o)&&(!!r(e.Vector3.Cross(n.directions[0],o.directions[0]),n,o)&&(!!r(e.Vector3.Cross(n.directions[0],o.directions[1]),n,o)&&(!!r(e.Vector3.Cross(n.directions[0],o.directions[2]),n,o)&&(!!r(e.Vector3.Cross(n.directions[1],o.directions[0]),n,o)&&(!!r(e.Vector3.Cross(n.directions[1],o.directions[1]),n,o)&&(!!r(e.Vector3.Cross(n.directions[1],o.directions[2]),n,o)&&(!!r(e.Vector3.Cross(n.directions[2],o.directions[0]),n,o)&&(!!r(e.Vector3.Cross(n.directions[2],o.directions[1]),n,o)&&!!r(e.Vector3.Cross(n.directions[2],o.directions[2]),n,o))))))))))))))},t}();e.BoundingInfo=n}(s||(s={}));!function(e){var t=function(t){function i(i,r,n){void 0===r&&(r=null),void 0===n&&(n=!0);var o=t.call(this,i,r)||this;return o._rotation=e.Vector3.Zero(),o._scaling=e.Vector3.One(),o._isDirty=!1,o.billboardMode=e.AbstractMesh.BILLBOARDMODE_NONE,o.scalingDeterminant=1,o.infiniteDistance=!1,o.position=e.Vector3.Zero(),o._localWorld=e.Matrix.Zero(),o._worldMatrix=e.Matrix.Zero(),o._absolutePosition=e.Vector3.Zero(),o._pivotMatrix=e.Matrix.Identity(),o._postMultiplyPivotMatrix=!1,o._isWorldMatrixFrozen=!1,o.onAfterWorldMatrixUpdateObservable=new e.Observable,o._nonUniformScaling=!1,n&&o.getScene().addTransformNode(o),o}return n(i,t),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},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.getWorldMatrix=function(){return this._currentRenderId!==this.getScene().getRenderId()&&this.computeWorldMatrix(),this._worldMatrix},Object.defineProperty(i.prototype,"worldMatrixFromCache",{get:function(){return this._worldMatrix},enumerable:!0,configurable:!0}),i.prototype.updatePoseMatrix=function(e){return this._poseMatrix.copyFrom(e),this},i.prototype.getPoseMatrix=function(){return this._poseMatrix},i.prototype._isSynchronized=function(){return!this._isDirty&&(this.billboardMode===this._cache.billboardMode&&this.billboardMode===e.AbstractMesh.BILLBOARDMODE_NONE&&(!this._cache.pivotMatrixUpdated&&(!this.infiniteDistance&&(!!this._cache.position.equals(this.position)&&(!(this.rotationQuaternion&&!this._cache.rotationQuaternion.equals(this.rotationQuaternion))&&(!!this._cache.rotation.equals(this.rotation)&&!!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){return"rotation"===e&&(this.rotationQuaternion=null),this._currentRenderId=Number.MAX_VALUE,this._isDirty=!0,this},Object.defineProperty(i.prototype,"absolutePosition",{get:function(){return this._absolutePosition},enumerable:!0,configurable:!0}),i.prototype.setPivotMatrix=function(t,i){return void 0===i&&(i=!1),this._pivotMatrix=t.clone(),this._cache.pivotMatrixUpdated=!0,this._postMultiplyPivotMatrix=i,this._postMultiplyPivotMatrix&&(this._pivotMatrixInverse=e.Matrix.Invert(t)),this},i.prototype.getPivotMatrix=function(){return this._pivotMatrix},i.prototype.freezeWorldMatrix=function(){return this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0),this._isWorldMatrixFrozen=!0,this},i.prototype.unfreezeWorldMatrix=function(){return this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0),this},Object.defineProperty(i.prototype,"isWorldMatrixFrozen",{get:function(){return this._isWorldMatrixFrozen},enumerable:!0,configurable:!0}),i.prototype.getAbsolutePosition=function(){return this.computeWorldMatrix(),this._absolutePosition},i.prototype.setAbsolutePosition=function(t){if(!t)return this;var i,r,n;if(void 0===t.x){if(arguments.length<3)return this;i=arguments[0],r=arguments[1],n=arguments[2]}else i=t.x,r=t.y,n=t.z;if(this.parent){var o=this.parent.getWorldMatrix().clone();o.invert();var s=new e.Vector3(i,r,n);this.position=e.Vector3.TransformCoordinates(s,o)}else this.position.x=i,this.position.y=r,this.position.z=n;return this},i.prototype.setPositionWithLocalVector=function(t){return this.computeWorldMatrix(),this.position=e.Vector3.TransformNormal(t,this._localWorld),this},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){return this.computeWorldMatrix(!0),this.position=e.Vector3.TransformCoordinates(t,this._localWorld),this},i.prototype.lookAt=function(t,i,r,n,o){void 0===i&&(i=0),void 0===r&&(r=0),void 0===n&&(n=0),void 0===o&&(o=e.Space.LOCAL);var s=e.AbstractMesh._lookAtVectorCache,a=o===e.Space.LOCAL?this.position:this.getAbsolutePosition();t.subtractToRef(a,s);var l=-Math.atan2(s.z,s.x)-Math.PI/2,h=Math.sqrt(s.x*s.x+s.z*s.z),u=Math.atan2(s.y,h);return this.rotationQuaternion=this.rotationQuaternion||new e.Quaternion,e.Quaternion.RotationYawPitchRollToRef(l+i,u+r,n,this.rotationQuaternion),this},i.prototype.getDirection=function(t){var i=e.Vector3.Zero();return this.getDirectionToRef(t,i),i},i.prototype.getDirectionToRef=function(t,i){return e.Vector3.TransformNormalToRef(t,this.getWorldMatrix(),i),this},i.prototype.setPivotPoint=function(t,i){void 0===i&&(i=e.Space.LOCAL),0==this.getScene().getRenderId()&&this.computeWorldMatrix(!0);var r=this.getWorldMatrix();if(i==e.Space.WORLD){var n=e.Tmp.Matrix[0];r.invertToRef(n),t=e.Vector3.TransformCoordinates(t,n)}return e.Vector3.TransformCoordinatesToRef(t,r,this.position),this._pivotMatrix.m[12]=-t.x,this._pivotMatrix.m[13]=-t.y,this._pivotMatrix.m[14]=-t.z,this._cache.pivotMatrixUpdated=!0,this},i.prototype.getPivotPoint=function(){var t=e.Vector3.Zero();return this.getPivotPointToRef(t),t},i.prototype.getPivotPointToRef=function(e){return e.x=-this._pivotMatrix.m[12],e.y=-this._pivotMatrix.m[13],e.z=-this._pivotMatrix.m[14],this},i.prototype.getAbsolutePivotPoint=function(){var t=e.Vector3.Zero();return this.getAbsolutePivotPointToRef(t),t},i.prototype.getAbsolutePivotPointToRef=function(t){return t.x=this._pivotMatrix.m[12],t.y=this._pivotMatrix.m[13],t.z=this._pivotMatrix.m[14],this.getPivotPointToRef(t),e.Vector3.TransformCoordinatesToRef(t,this.getWorldMatrix(),t),this},i.prototype.setParent=function(t){var i=t;if(null==t){var r=e.Tmp.Quaternion[0],n=e.Tmp.Vector3[0],o=e.Tmp.Vector3[1];this.getWorldMatrix().decompose(o,r,n),this.rotationQuaternion?this.rotationQuaternion.copyFrom(r):r.toEulerAnglesToRef(this.rotation),this.position.x=n.x,this.position.y=n.y,this.position.z=n.z}else{var n=e.Tmp.Vector3[0],s=e.Tmp.Matrix[0];i.getWorldMatrix().invertToRef(s),e.Vector3.TransformCoordinatesToRef(this.position,s,n),this.position.copyFrom(n)}return this.parent=i,this},Object.defineProperty(i.prototype,"nonUniformScaling",{get:function(){return this._nonUniformScaling},enumerable:!0,configurable:!0}),i.prototype._updateNonUniformScalingState=function(e){return this._nonUniformScaling!==e&&(this._nonUniformScaling=!0,!0)},i.prototype.attachToBone=function(e,t){return this._transformToBoneReferal=t,this.parent=e,e.getWorldMatrix().determinant()<0&&(this.scalingDeterminant*=-1),this},i.prototype.detachFromBone=function(){return this.parent?(this.parent.getWorldMatrix().determinant()<0&&(this.scalingDeterminant*=-1),this._transformToBoneReferal=null,this.parent=null,this):this},i.prototype.rotate=function(t,i,r){t.normalize(),this.rotationQuaternion||(this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation=e.Vector3.Zero());var n;if(r&&r!==e.Space.LOCAL){if(this.parent){var o=this.parent.getWorldMatrix().clone();o.invert(),t=e.Vector3.TransformNormal(t,o)}(n=e.Quaternion.RotationAxisToRef(t,i,e.AbstractMesh._rotationAxisCache)).multiplyToRef(this.rotationQuaternion,this.rotationQuaternion)}else n=e.Quaternion.RotationAxisToRef(t,i,e.AbstractMesh._rotationAxisCache),this.rotationQuaternion.multiplyToRef(n,this.rotationQuaternion);return this},i.prototype.rotateAround=function(t,i,r){return i.normalize(),this.rotationQuaternion||(this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation.copyFromFloats(0,0,0)),t.subtractToRef(this.position,e.Tmp.Vector3[0]),e.Matrix.TranslationToRef(e.Tmp.Vector3[0].x,e.Tmp.Vector3[0].y,e.Tmp.Vector3[0].z,e.Tmp.Matrix[0]),e.Tmp.Matrix[0].invertToRef(e.Tmp.Matrix[2]),e.Matrix.RotationAxisToRef(i,r,e.Tmp.Matrix[1]),e.Tmp.Matrix[2].multiplyToRef(e.Tmp.Matrix[1],e.Tmp.Matrix[2]),e.Tmp.Matrix[2].multiplyToRef(e.Tmp.Matrix[0],e.Tmp.Matrix[2]),e.Tmp.Matrix[2].decompose(e.Tmp.Vector3[0],e.Tmp.Quaternion[0],e.Tmp.Vector3[1]),this.position.addInPlace(e.Tmp.Vector3[1]),e.Tmp.Quaternion[0].multiplyToRef(this.rotationQuaternion,this.rotationQuaternion),this},i.prototype.translate=function(t,i,r){var n=t.scale(i);if(r&&r!==e.Space.LOCAL)this.setAbsolutePosition(this.getAbsolutePosition().add(n));else{var o=this.getPositionExpressedInLocalSpace().add(n);this.setPositionWithLocalVector(o)}return this},i.prototype.addRotation=function(t,i,r){var n;this.rotationQuaternion?n=this.rotationQuaternion:(n=e.Tmp.Quaternion[1],e.Quaternion.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,n));var o=e.Tmp.Quaternion[0];return e.Quaternion.RotationYawPitchRollToRef(i,t,r,o),n.multiplyInPlace(o),this.rotationQuaternion||n.toEulerAnglesToRef(this.rotation),this},i.prototype.computeWorldMatrix=function(t){if(this._isWorldMatrixFrozen)return this._worldMatrix;if(!t&&this.isSynchronized(!0))return this._worldMatrix;this._cache.position.copyFrom(this.position),this._cache.scaling.copyFrom(this.scaling),this._cache.pivotMatrixUpdated=!1,this._cache.billboardMode=this.billboardMode,this._currentRenderId=this.getScene().getRenderId(),this._isDirty=!1,e.Matrix.ScalingToRef(this.scaling.x*this.scalingDeterminant,this.scaling.y*this.scalingDeterminant,this.scaling.z*this.scalingDeterminant,e.Tmp.Matrix[1]),this.rotationQuaternion&&this.rotation.length()&&(this.rotationQuaternion.multiplyInPlace(e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z)),this.rotation.copyFromFloats(0,0,0)),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));var i=this.getScene().activeCamera;if(this.infiniteDistance&&!this.parent&&i){var r=i.getWorldMatrix(),n=new e.Vector3(r.m[12],r.m[13],r.m[14]);e.Matrix.TranslationToRef(this.position.x+n.x,this.position.y+n.y,this.position.z+n.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!==e.AbstractMesh.BILLBOARDMODE_NONE&&i){if((this.billboardMode&e.AbstractMesh.BILLBOARDMODE_ALL)!==e.AbstractMesh.BILLBOARDMODE_ALL){var o=e.Tmp.Vector3[3];this.parent&&this.parent.getWorldMatrix?this._transformToBoneReferal?(this.parent.getWorldMatrix().multiplyToRef(this._transformToBoneReferal.getWorldMatrix(),e.Tmp.Matrix[6]),e.Vector3.TransformCoordinatesToRef(this.position,e.Tmp.Matrix[6],o)):e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),o):o.copyFrom(this.position),o.subtractInPlace(i.globalPosition);var s=e.Tmp.Vector3[4].copyFromFloats(0,0,0);(this.billboardMode&e.AbstractMesh.BILLBOARDMODE_X)===e.AbstractMesh.BILLBOARDMODE_X&&(s.x=Math.atan2(-o.y,o.z)),(this.billboardMode&e.AbstractMesh.BILLBOARDMODE_Y)===e.AbstractMesh.BILLBOARDMODE_Y&&(s.y=Math.atan2(o.x,o.z)),(this.billboardMode&e.AbstractMesh.BILLBOARDMODE_Z)===e.AbstractMesh.BILLBOARDMODE_Z&&(s.z=Math.atan2(o.y,o.x)),e.Matrix.RotationYawPitchRollToRef(s.y,s.x,s.z,e.Tmp.Matrix[0])}else e.Tmp.Matrix[1].copyFrom(i.getViewMatrix()),e.Tmp.Matrix[1].setTranslationFromFloats(0,0,0),e.Tmp.Matrix[1].invertToRef(e.Tmp.Matrix[0]);e.Tmp.Matrix[1].copyFrom(e.Tmp.Matrix[5]),e.Tmp.Matrix[1].multiplyToRef(e.Tmp.Matrix[0],e.Tmp.Matrix[5])}return e.Tmp.Matrix[5].multiplyToRef(e.Tmp.Matrix[2],this._localWorld),this.parent&&this.parent.getWorldMatrix?(this.billboardMode!==e.AbstractMesh.BILLBOARDMODE_NONE?(this._transformToBoneReferal?(this.parent.getWorldMatrix().multiplyToRef(this._transformToBoneReferal.getWorldMatrix(),e.Tmp.Matrix[6]),e.Tmp.Matrix[5].copyFrom(e.Tmp.Matrix[6])):e.Tmp.Matrix[5].copyFrom(this.parent.getWorldMatrix()),this._localWorld.getTranslationToRef(e.Tmp.Vector3[5]),e.Vector3.TransformCoordinatesToRef(e.Tmp.Vector3[5],e.Tmp.Matrix[5],e.Tmp.Vector3[5]),this._worldMatrix.copyFrom(this._localWorld),this._worldMatrix.setTranslation(e.Tmp.Vector3[5])):this._transformToBoneReferal?(this._localWorld.multiplyToRef(this.parent.getWorldMatrix(),e.Tmp.Matrix[6]),e.Tmp.Matrix[6].multiplyToRef(this._transformToBoneReferal.getWorldMatrix(),this._worldMatrix)):this._localWorld.multiplyToRef(this.parent.getWorldMatrix(),this._worldMatrix),this._markSyncedWithParent()):this._worldMatrix.copyFrom(this._localWorld),this._postMultiplyPivotMatrix&&this._worldMatrix.multiplyToRef(this._pivotMatrixInverse,this._worldMatrix),this.scaling.isNonUniform?this._updateNonUniformScalingState(!0):this.parent&&this.parent._nonUniformScaling?this._updateNonUniformScalingState(this.parent._nonUniformScaling):this._updateNonUniformScalingState(!1),this._afterComputeWorldMatrix(),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._afterComputeWorldMatrix=function(){},i.prototype.registerAfterWorldMatrixUpdate=function(e){return this.onAfterWorldMatrixUpdateObservable.add(e),this},i.prototype.unregisterAfterWorldMatrixUpdate=function(e){return this.onAfterWorldMatrixUpdateObservable.removeCallback(e),this},i.prototype.clone=function(t,r){var n=this,o=e.SerializationHelper.Clone(function(){return new i(t,n.getScene())},this);return o.name=t,o.id=t,r&&(o.parent=r),o},i.prototype.serialize=function(t){return void 0===t&&(t=null),t||(t={}),t.name=this.name,t.id=this.id,t.type=this.getClassName(),e.Tags&&e.Tags.HasTags(this)&&(t.tags=e.Tags.GetTags(this)),t.position=this.position.asArray(),this.rotationQuaternion?t.rotationQuaternion=this.rotationQuaternion.asArray():this.rotation&&(t.rotation=this.rotation.asArray()),t.scaling=this.scaling.asArray(),t.localMatrix=this.getPivotMatrix().asArray(),t.isEnabled=this.isEnabled(),t.infiniteDistance=this.infiniteDistance,t.billboardMode=this.billboardMode,this.parent&&(t.parentId=this.parent.id),this.metadata&&(t.metadata=this.metadata),t},i.Parse=function(t,r,n){var o=new i(t.name,r);return o.id=t.id,e.Tags&&e.Tags.AddTagsTo(o,t.tags),o.position=e.Vector3.FromArray(t.position),void 0!==t.metadata&&(o.metadata=t.metadata),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.infiniteDistance=t.infiniteDistance,o.billboardMode=t.billboardMode,t.parentId&&(o._waitingParentId=t.parentId),o},i.BILLBOARDMODE_NONE=0,i.BILLBOARDMODE_X=1,i.BILLBOARDMODE_Y=2,i.BILLBOARDMODE_Z=4,i.BILLBOARDMODE_ALL=7,i._lookAtVectorCache=new e.Vector3(0,0,0),i._rotationAxisCache=new e.Quaternion,i}(e.Node);e.TransformNode=t}(s||(s={}));!function(e){var t=function(t){function i(r,n){void 0===n&&(n=null);var o=t.call(this,r,n,!1)||this;return o._facetNb=0,o._partitioningSubdivisions=10,o._partitioningBBoxRatio=1.01,o._facetDataEnabled=!1,o._facetParameters={},o._bbSize=e.Vector3.Zero(),o._subDiv={max:1,X:1,Y:1,Z:1},o._facetDepthSort=!1,o.onCollideObservable=new e.Observable,o.onCollisionPositionChangeObservable=new e.Observable,o.onMaterialChangedObservable=new e.Observable,o.definedFacingForward=!0,o.occlusionQueryAlgorithmType=i.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE,o.occlusionType=i.OCCLUSION_TYPE_NONE,o.occlusionRetryCount=-1,o._occlusionInternalRetryCounter=0,o._isOccluded=!1,o._isOcclusionQueryInProgress=!1,o.visibility=1,o.alphaIndex=Number.MAX_VALUE,o.isVisible=!0,o.isPickable=!0,o.showBoundingBox=!1,o.showSubMeshesBoundingBox=!1,o.isBlocker=!1,o.enablePointerMoveEvents=!1,o.renderingGroupId=0,o._receiveShadows=!1,o.renderOutline=!1,o.outlineColor=e.Color3.Red(),o.outlineWidth=.02,o.renderOverlay=!1,o.overlayColor=e.Color3.Red(),o.overlayAlpha=.5,o._hasVertexAlpha=!1,o._useVertexColors=!0,o._computeBonesUsingShaders=!0,o._numBoneInfluencers=4,o._applyFog=!0,o.useOctreeForRenderingSelection=!0,o.useOctreeForPicking=!0,o.useOctreeForCollisions=!0,o._layerMask=268435455,o.alwaysSelectAsActiveMesh=!1,o._checkCollisions=!1,o._collisionMask=-1,o._collisionGroup=-1,o.ellipsoid=new e.Vector3(.5,1,.5),o.ellipsoidOffset=new e.Vector3(0,0,0),o._oldPositionForCollisions=new e.Vector3(0,0,0),o._diffPositionForCollisions=new e.Vector3(0,0,0),o.edgesWidth=1,o.edgesColor=new e.Color4(1,0,0,1),o._collisionsTransformMatrix=e.Matrix.Zero(),o._collisionsScalingMatrix=e.Matrix.Zero(),o._isDisposed=!1,o._renderId=0,o._intersectionsInProgress=new Array,o._unIndexed=!1,o._lightSources=new Array,o._onCollisionPositionChange=function(t,i,r){void 0===r&&(r=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),r&&o.onCollideObservable.notifyObservers(r),o.onCollisionPositionChangeObservable.notifyObservers(o.position)},o.getScene().addMesh(o),o._resyncLightSources(),o}return n(i,t),Object.defineProperty(i,"BILLBOARDMODE_NONE",{get:function(){return e.TransformNode.BILLBOARDMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_X",{get:function(){return e.TransformNode.BILLBOARDMODE_X},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Y",{get:function(){return e.TransformNode.BILLBOARDMODE_Y},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Z",{get:function(){return e.TransformNode.BILLBOARDMODE_Z},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_ALL",{get:function(){return e.TransformNode.BILLBOARDMODE_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"facetNb",{get:function(){return this._facetNb},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"partitioningSubdivisions",{get:function(){return this._partitioningSubdivisions},set:function(e){this._partitioningSubdivisions=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"partitioningBBoxRatio",{get:function(){return this._partitioningBBoxRatio},set:function(e){this._partitioningBBoxRatio=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"mustDepthSortFacets",{get:function(){return this._facetDepthSort},set:function(e){this._facetDepthSort=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"facetDepthSortFrom",{get:function(){return this._facetDepthSortFrom},set:function(e){this._facetDepthSortFrom=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isFacetDataEnabled",{get:function(){return this._facetDataEnabled},enumerable:!0,configurable:!0}),i.prototype._updateNonUniformScalingState=function(e){return!!t.prototype._updateNonUniformScalingState.call(this,e)&&(this._markSubMeshesAsMiscDirty(),!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,"isOccluded",{get:function(){return this._isOccluded},set:function(e){this._isOccluded=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isOcclusionQueryInProgress",{get:function(){return this._isOcclusionQueryInProgress},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"material",{get:function(){return this._material},set:function(e){if(this._material!==e&&(this._material=e,this.onMaterialChangedObservable.hasObservers&&this.onMaterialChangedObservable.notifyObservers(this),this.subMeshes))for(var t=0,i=this.subMeshes;t<i.length;t++)i[t].setEffect(null)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"receiveShadows",{get:function(){return this._receiveShadows},set:function(e){this._receiveShadows!==e&&(this._receiveShadows=e,this._markSubMeshesAsLightDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"hasVertexAlpha",{get:function(){return this._hasVertexAlpha},set:function(e){this._hasVertexAlpha!==e&&(this._hasVertexAlpha=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"useVertexColors",{get:function(){return this._useVertexColors},set:function(e){this._useVertexColors!==e&&(this._useVertexColors=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"computeBonesUsingShaders",{get:function(){return this._computeBonesUsingShaders},set:function(e){this._computeBonesUsingShaders!==e&&(this._computeBonesUsingShaders=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"numBoneInfluencers",{get:function(){return this._numBoneInfluencers},set:function(e){this._numBoneInfluencers!==e&&(this._numBoneInfluencers=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"applyFog",{get:function(){return this._applyFog},set:function(e){this._applyFog!==e&&(this._applyFog=e,this._markSubMeshesAsMiscDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"layerMask",{get:function(){return this._layerMask},set:function(e){e!==this._layerMask&&(this._layerMask=e,this._resyncLightSources())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"collisionMask",{get:function(){return this._collisionMask},set:function(e){this._collisionMask=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"collisionGroup",{get:function(){return this._collisionGroup},set:function(e){this._collisionGroup=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"_positions",{get:function(){return null},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),this._markSubMeshesAsAttributesDirty()},enumerable:!0,configurable:!0}),i.prototype.isDisposed=function(){return this._isDisposed},i.prototype.getClassName=function(){return"AbstractMesh"},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},i.prototype._rebuild=function(){if(this._occlusionQuery&&(this._occlusionQuery=null),this._edgesRenderer&&this._edgesRenderer._rebuild(),this.subMeshes)for(var e=0,t=this.subMeshes;e<t.length;e++)t[e]._rebuild()},i.prototype._resyncLightSources=function(){this._lightSources.length=0;for(var e=0,t=this.getScene().lights;e<t.length;e++){var i=t[e];i.isEnabled()&&(i.canAffectMesh(this)&&this._lightSources.push(i))}this._markSubMeshesAsLightDirty()},i.prototype._resyncLighSource=function(e){var t=e.isEnabled()&&e.canAffectMesh(this),i=this._lightSources.indexOf(e);if(-1===i){if(!t)return;this._lightSources.push(e)}else{if(t)return;this._lightSources.splice(i,1)}this._markSubMeshesAsLightDirty()},i.prototype._removeLightSource=function(e){var t=this._lightSources.indexOf(e);-1!==t&&this._lightSources.splice(t,1)},i.prototype._markSubMeshesAsDirty=function(e){if(this.subMeshes)for(var t=0,i=this.subMeshes;t<i.length;t++){var r=i[t];r._materialDefines&&e(r._materialDefines)}},i.prototype._markSubMeshesAsLightDirty=function(){this._markSubMeshesAsDirty(function(e){return e.markAsLightDirty()})},i.prototype._markSubMeshesAsAttributesDirty=function(){this._markSubMeshesAsDirty(function(e){return e.markAsAttributesDirty()})},i.prototype._markSubMeshesAsMiscDirty=function(){if(this.subMeshes)for(var t=0,i=this.subMeshes;t<i.length;t++){var r=i[t].getMaterial();r&&r.markAsDirty(e.Material.MiscDirtyFlag)}},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}),i.prototype.disableEdgesRendering=function(){return this._edgesRenderer&&(this._edgesRenderer.dispose(),this._edgesRenderer=null),this},i.prototype.enableEdgesRendering=function(t,i){return void 0===t&&(t=.95),void 0===i&&(i=!1),this.disableEdgesRendering(),this._edgesRenderer=new e.EdgesRenderer(this,t,i),this},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.setVerticesData=function(e,t,i,r){return this},i.prototype.updateVerticesData=function(e,t,i,r){return this},i.prototype.setIndices=function(e,t){return this},i.prototype.isVerticesDataPresent=function(e){return!1},i.prototype.getBoundingInfo=function(){return this._masterMesh?this._masterMesh.getBoundingInfo():(this._boundingInfo||this._updateBoundingInfo(),this._boundingInfo)},i.prototype.normalizeToUnitCube=function(e){void 0===e&&(e=!0);var t=this.getHierarchyBoundingVectors(e),i=t.max.subtract(t.min),r=Math.max(i.x,i.y,i.z);if(0===r)return this;var n=1/r;return this.scaling.scaleInPlace(n),this},i.prototype.setBoundingInfo=function(e){return this._boundingInfo=e,this},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():t.prototype.getWorldMatrix.call(this)},i.prototype.movePOV=function(e,t,i){return this.position.addInPlace(this.calcMovePOV(e,t,i)),this},i.prototype.calcMovePOV=function(t,i,r){var n=new e.Matrix;(this.rotationQuaternion?this.rotationQuaternion:e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z)).toRotationMatrix(n);var o=e.Vector3.Zero(),s=this.definedFacingForward?-1:1;return e.Vector3.TransformCoordinatesFromFloatsToRef(t*s,i,r*s,n,o),o},i.prototype.rotatePOV=function(e,t,i){return this.rotation.addInPlace(this.calcRotatePOV(e,t,i)),this},i.prototype.calcRotatePOV=function(t,i,r){var n=this.definedFacingForward?1:-1;return new e.Vector3(t*n,i,r*n)},i.prototype.getHierarchyBoundingVectors=function(t){void 0===t&&(t=!0),this.computeWorldMatrix(!0);var i,r,n=this.getBoundingInfo();if(this.subMeshes&&n?(i=n.boundingBox.minimumWorld,r=n.boundingBox.maximumWorld):(i=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),r=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE)),t)for(var o=0,s=this.getDescendants(!1);o<s.length;o++){var a=s[o];a.computeWorldMatrix(!0);var l=a.getBoundingInfo();if(0!==a.getTotalVertices()&&l){var h=l.boundingBox,u=h.minimumWorld,c=h.maximumWorld;e.Tools.CheckExtends(u,i,r),e.Tools.CheckExtends(c,i,r)}}return{min:i,max:r}},i.prototype._updateBoundingInfo=function(){return this._boundingInfo=this._boundingInfo||new e.BoundingInfo(this.absolutePosition,this.absolutePosition),this._boundingInfo.update(this.worldMatrixFromCache),this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache),this},i.prototype._updateSubMeshesBoundingInfo=function(e){if(!this.subMeshes)return this;for(var t=0;t<this.subMeshes.length;t++){var i=this.subMeshes[t];i.IsGlobal||i.updateBoundingInfo(e)}return this},i.prototype._afterComputeWorldMatrix=function(){this._updateBoundingInfo()},i.prototype.isInFrustum=function(e){return null!==this._boundingInfo&&this._boundingInfo.isInFrustum(e)},i.prototype.isCompletelyInFrustum=function(e){return null!==this._boundingInfo&&this._boundingInfo.isCompletelyInFrustum(e)},i.prototype.intersectsMesh=function(e,t,i){if(void 0===t&&(t=!1),!this._boundingInfo||!e._boundingInfo)return!1;if(this._boundingInfo.intersects(e._boundingInfo,t))return!0;if(i)for(var r=0,n=this.getChildMeshes();r<n.length;r++)if(n[r].intersectsMesh(e,t,!0))return!0;return!1},i.prototype.intersectsPoint=function(e){return!!this._boundingInfo&&this._boundingInfo.intersectsPoint(e)},i.prototype.getPhysicsImpostor=function(){return this.physicsImpostor},i.prototype.getPositionInCameraSpace=function(t){return void 0===t&&(t=null),t||(t=this.getScene().activeCamera),e.Vector3.TransformCoordinates(this.absolutePosition,t.getViewMatrix())},i.prototype.getDistanceToCamera=function(e){return void 0===e&&(e=null),e||(e=this.getScene().activeCamera),this.absolutePosition.subtract(e.position).length()},i.prototype.applyImpulse=function(e,t){return this.physicsImpostor?(this.physicsImpostor.applyImpulse(e,t),this):this},i.prototype.setPhysicsLinkWith=function(t,i,r,n){return this.physicsImpostor&&t.physicsImpostor?(this.physicsImpostor.createJoint(t.physicsImpostor,e.PhysicsJoint.HingeJoint,{mainPivot:i,connectedPivot:r,nativeParams:n}),this):this},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(t){return this.getAbsolutePosition().subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPositionForCollisions),this._oldPositionForCollisions.addInPlace(this.ellipsoidOffset),this._collider||(this._collider=new e.Collider),this._collider.radius=this.ellipsoid,this.getScene().collisionCoordinator.getNewPosition(this._oldPositionForCollisions,t,this._collider,3,this,this._onCollisionPositionChange,this.uniqueId),this},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 r=this.getBoundingInfo();if(r){var n=r.boundingBox;this._submeshesOctree.update(n.minimumWorld,n.maximumWorld,this.subMeshes)}return this._submeshesOctree},i.prototype._collideForSubMesh=function(t,i,r){if(this._generatePointsArray(),!this._positions)return this;if(!t._lastColliderWorldVertices||!t._lastColliderTransformMatrix.equals(i)){t._lastColliderTransformMatrix=i.clone(),t._lastColliderWorldVertices=[],t._trianglePlanes=[];for(var n=t.verticesStart,o=t.verticesStart+t.verticesCount,s=n;s<o;s++)t._lastColliderWorldVertices.push(e.Vector3.TransformCoordinates(this._positions[s],i))}return r._collide(t._trianglePlanes,t._lastColliderWorldVertices,this.getIndices(),t.indexStart,t.indexStart+t.indexCount,t.verticesStart,!!t.getMaterial()),r.collisionFound&&(r.collidedMesh=this),this},i.prototype._processCollisionsForSubMeshes=function(e,t){var i,r;if(this._submeshesOctree&&this.useOctreeForCollisions){var n=e.velocityWorldLength+Math.max(e.radius.x,e.radius.y,e.radius.z),o=this._submeshesOctree.intersects(e.basePointWorld,n);r=o.length,i=o.data}else r=(i=this.subMeshes).length;for(var s=0;s<r;s++){var a=i[s];r>1&&!a._checkCollision(e)||this._collideForSubMesh(a,t,e)}return this},i.prototype._checkCollision=function(t){return this._boundingInfo&&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),this):this},i.prototype._generatePointsArray=function(){return!1},i.prototype.intersects=function(t,i){var r=new e.PickingInfo;if(!(this.subMeshes&&this._boundingInfo&&t.intersectsSphere(this._boundingInfo.boundingSphere)&&t.intersectsBox(this._boundingInfo.boundingBox)))return r;if(!this._generatePointsArray())return r;var n,o,s=null;if(this._submeshesOctree&&this.useOctreeForPicking){var a=e.Ray.Transform(t,this.getWorldMatrix()),l=this._submeshesOctree.intersectsRay(a);o=l.length,n=l.data}else o=(n=this.subMeshes).length;for(var h=0;h<o;h++){var u=n[h];if(!(o>1)||u.canIntersects(t)){var c=u.intersects(t,this._positions,this.getIndices(),i);if(c&&(i||!s||c.distance<s.distance)&&(s=c,s.subMeshId=h,i))break}}if(s){var f=this.getWorldMatrix(),p=e.Vector3.TransformCoordinates(t.origin,f),d=t.direction.clone();d=d.scale(s.distance);var m=e.Vector3.TransformNormal(d,f),g=p.add(m);return r.hit=!0,r.distance=e.Vector3.Distance(p,g),r.pickedPoint=g,r.pickedMesh=this,r.bu=s.bu||0,r.bv=s.bv||0,r.faceId=s.faceId,r.subMeshId=s.subMeshId,r}return r},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;return this},i.prototype.dispose=function(e,i){var r=this;void 0===i&&(i=!1);var n;for(this.actionManager&&(this.actionManager.dispose(),this.actionManager=null),this.skeleton=null,this.getScene().stopAnimation(this),this.physicsImpostor&&this.physicsImpostor.dispose(),n=0;n<this._intersectionsInProgress.length;n++){var o=this._intersectionsInProgress[n],s=o._intersectionsInProgress.indexOf(this);o._intersectionsInProgress.splice(s,1)}this._intersectionsInProgress=[],this.getScene().lights.forEach(function(e){var t=e.includedOnlyMeshes.indexOf(r);-1!==t&&e.includedOnlyMeshes.splice(t,1),-1!==(t=e.excludedMeshes.indexOf(r))&&e.excludedMeshes.splice(t,1);var i=e.getShadowGenerator();if(i){var n=i.getShadowMap();n&&n.renderList&&-1!==(t=n.renderList.indexOf(r))&&n.renderList.splice(t,1)}}),this._edgesRenderer&&(this._edgesRenderer.dispose(),this._edgesRenderer=null),"InstancedMesh"!==this.getClassName()&&this.releaseSubMeshes();var a=this.getScene().selectionOctree;a&&-1!==(n=a.dynamicContent.indexOf(this))&&a.dynamicContent.splice(n,1);var l=this.getScene().getEngine();if(this._occlusionQuery&&(this._isOcclusionQueryInProgress=!1,l.deleteQuery(this._occlusionQuery),this._occlusionQuery=null),l.wipeCaches(),this.getScene().removeMesh(this),this._cache=null,i&&this.material&&this.material.dispose(!1,!0),e){var h=this.getChildMeshes(!0);for(n=0;n<h.length;n++){var u=h[n];u.parent=null,u.computeWorldMatrix(!0)}}else{for(n=0;n<this.getScene().particleSystems.length;n++)this.getScene().particleSystems[n].emitter===this&&(this.getScene().particleSystems[n].dispose(),n--);var c=this.getDescendants(!0);for(n=0;n<c.length;n++)c[n].dispose()}this._facetDataEnabled&&this.disableFacetData(),this.onAfterWorldMatrixUpdateObservable.clear(),this.onCollideObservable.clear(),this.onCollisionPositionChangeObservable.clear(),this._isDisposed=!0,t.prototype.dispose.call(this)},i.prototype.addChild=function(e){return e.setParent(this),this},i.prototype.removeChild=function(e){return e.setParent(null),this},i.prototype._initFacetData=function(){this._facetNormals||(this._facetNormals=new Array),this._facetPositions||(this._facetPositions=new Array),this._facetPartitioning||(this._facetPartitioning=new Array),this._facetNb=this.getIndices().length/3|0,this._partitioningSubdivisions=this._partitioningSubdivisions?this._partitioningSubdivisions:10,this._partitioningBBoxRatio=this._partitioningBBoxRatio?this._partitioningBBoxRatio:1.01;for(var t=0;t<this._facetNb;t++)this._facetNormals[t]=e.Vector3.Zero(),this._facetPositions[t]=e.Vector3.Zero();return this._facetDataEnabled=!0,this},i.prototype.updateFacetData=function(){this._facetDataEnabled||this._initFacetData();var t=this.getVerticesData(e.VertexBuffer.PositionKind),i=this.getIndices(),r=i,n=this.getVerticesData(e.VertexBuffer.NormalKind),o=this.getBoundingInfo();if(!o)return this;if(this._facetDepthSort&&!this._originalIndices){if(this._originalIndices=new Uint32Array(i),this._facetDepthSortFunction=function(e,t){return t.sqDistance-e.sqDistance},!this._facetDepthSortFrom){var s=this.getScene().activeCamera;this._facetDepthSortFrom=s?s.position:e.Vector3.Zero()}this._depthSortedFacets=[];for(var a=0;a<this._facetNb;a++){var l={ind:3*a,sqDistance:0};this._depthSortedFacets.push(l)}this._invertedMatrix=e.Matrix.Identity(),this._facetDepthSortOrigin=e.Vector3.Zero()}this._bbSize.x=o.maximum.x-o.minimum.x>e.Epsilon?o.maximum.x-o.minimum.x:e.Epsilon,this._bbSize.y=o.maximum.y-o.minimum.y>e.Epsilon?o.maximum.y-o.minimum.y:e.Epsilon,this._bbSize.z=o.maximum.z-o.minimum.z>e.Epsilon?o.maximum.z-o.minimum.z:e.Epsilon;var h=this._bbSize.x>this._bbSize.y?this._bbSize.x:this._bbSize.y;if(h=h>this._bbSize.z?h:this._bbSize.z,this._subDiv.max=this._partitioningSubdivisions,this._subDiv.X=Math.floor(this._subDiv.max*this._bbSize.x/h),this._subDiv.Y=Math.floor(this._subDiv.max*this._bbSize.y/h),this._subDiv.Z=Math.floor(this._subDiv.max*this._bbSize.z/h),this._subDiv.X=this._subDiv.X<1?1:this._subDiv.X,this._subDiv.Y=this._subDiv.Y<1?1:this._subDiv.Y,this._subDiv.Z=this._subDiv.Z<1?1:this._subDiv.Z,this._facetParameters.facetNormals=this.getFacetLocalNormals(),this._facetParameters.facetPositions=this.getFacetLocalPositions(),this._facetParameters.facetPartitioning=this.getFacetLocalPartitioning(),this._facetParameters.bInfo=o,this._facetParameters.bbSize=this._bbSize,this._facetParameters.subDiv=this._subDiv,this._facetParameters.ratio=this.partitioningBBoxRatio,this._facetParameters.depthSort=this._facetDepthSort,this._facetDepthSort&&(this.computeWorldMatrix(!0),this._worldMatrix.invertToRef(this._invertedMatrix),e.Vector3.TransformCoordinatesToRef(this._facetDepthSortFrom,this._invertedMatrix,this._facetDepthSortOrigin),this._facetParameters.distanceTo=this._facetDepthSortOrigin,r=this._originalIndices),this._facetParameters.depthSortedFacets=this._depthSortedFacets,e.VertexData.ComputeNormals(t,r,n,this._facetParameters),this._facetDepthSort){this._depthSortedFacets.sort(this._facetDepthSortFunction);for(var u=0;u<this._facetNb;u++){var c=this._depthSortedFacets[u].ind;i[3*u]=this._originalIndices[c],i[3*u+1]=this._originalIndices[c+1],i[3*u+2]=this._originalIndices[c+2]}this.updateIndices(i)}return this},i.prototype.getFacetLocalNormals=function(){return this._facetNormals||this.updateFacetData(),this._facetNormals},i.prototype.getFacetLocalPositions=function(){return this._facetPositions||this.updateFacetData(),this._facetPositions},i.prototype.getFacetLocalPartitioning=function(){return this._facetPartitioning||this.updateFacetData(),this._facetPartitioning},i.prototype.getFacetPosition=function(t){var i=e.Vector3.Zero();return this.getFacetPositionToRef(t,i),i},i.prototype.getFacetPositionToRef=function(t,i){var r=this.getFacetLocalPositions()[t],n=this.getWorldMatrix();return e.Vector3.TransformCoordinatesToRef(r,n,i),this},i.prototype.getFacetNormal=function(t){var i=e.Vector3.Zero();return this.getFacetNormalToRef(t,i),i},i.prototype.getFacetNormalToRef=function(t,i){var r=this.getFacetLocalNormals()[t];return e.Vector3.TransformNormalToRef(r,this.getWorldMatrix(),i),this},i.prototype.getFacetsAtLocalCoordinates=function(e,t,i){var r=this.getBoundingInfo();if(!r)return null;var n=Math.floor((e-r.minimum.x*this._partitioningBBoxRatio)*this._subDiv.X*this._partitioningBBoxRatio/this._bbSize.x),o=Math.floor((t-r.minimum.y*this._partitioningBBoxRatio)*this._subDiv.Y*this._partitioningBBoxRatio/this._bbSize.y),s=Math.floor((i-r.minimum.z*this._partitioningBBoxRatio)*this._subDiv.Z*this._partitioningBBoxRatio/this._bbSize.z);return n<0||n>this._subDiv.max||o<0||o>this._subDiv.max||s<0||s>this._subDiv.max?null:this._facetPartitioning[n+this._subDiv.max*o+this._subDiv.max*this._subDiv.max*s]},i.prototype.getClosestFacetAtCoordinates=function(t,i,r,n,o,s){void 0===o&&(o=!1),void 0===s&&(s=!0);var a=this.getWorldMatrix(),l=e.Tmp.Matrix[5];a.invertToRef(l);var h=e.Tmp.Vector3[8];e.Vector3.TransformCoordinatesFromFloatsToRef(t,i,r,l,h);var u=this.getClosestFacetAtLocalCoordinates(h.x,h.y,h.z,n,o,s);return n&&e.Vector3.TransformCoordinatesFromFloatsToRef(n.x,n.y,n.z,a,n),u},i.prototype.getClosestFacetAtLocalCoordinates=function(e,t,i,r,n,o){void 0===n&&(n=!1),void 0===o&&(o=!0);var s=null,a=0,l=0,h=0,u=0,c=0,f=0,p=0,d=0,m=this.getFacetLocalPositions(),g=this.getFacetLocalNormals(),v=this.getFacetsAtLocalCoordinates(e,t,i);if(!v)return null;for(var _,y,x,b=Number.MAX_VALUE,T=b,E=0;E<v.length;E++)y=g[_=v[E]],u=(e-(x=m[_]).x)*y.x+(t-x.y)*y.y+(i-x.z)*y.z,(!n||n&&o&&u>=0||n&&!o&&u<=0)&&(u=y.x*x.x+y.y*x.y+y.z*x.z,c=-(y.x*e+y.y*t+y.z*i-u)/(y.x*y.x+y.y*y.y+y.z*y.z),(T=(a=(f=e+y.x*c)-e)*a+(l=(p=t+y.y*c)-t)*l+(h=(d=i+y.z*c)-i)*h)<b&&(b=T,s=_,r&&(r.x=f,r.y=p,r.z=d)));return s},i.prototype.getFacetDataParameters=function(){return this._facetParameters},i.prototype.disableFacetData=function(){return this._facetDataEnabled&&(this._facetDataEnabled=!1,this._facetPositions=new Array,this._facetNormals=new Array,this._facetPartitioning=new Array,this._facetParameters=null,this._originalIndices=new Uint32Array(0)),this},i.prototype.updateIndices=function(e){return this},i.prototype.createNormals=function(t){var i,r=this.getVerticesData(e.VertexBuffer.PositionKind),n=this.getIndices();i=this.isVerticesDataPresent(e.VertexBuffer.NormalKind)?this.getVerticesData(e.VertexBuffer.NormalKind):[],e.VertexData.ComputeNormals(r,n,i,{useRightHandedSystem:this.getScene().useRightHandedSystem}),this.setVerticesData(e.VertexBuffer.NormalKind,i,t)},i.prototype.checkOcclusionQuery=function(){var e=this.getEngine();if(e.webGLVersion<2||this.occlusionType===i.OCCLUSION_TYPE_NONE)this._isOccluded=!1;else{if(this.isOcclusionQueryInProgress&&this._occlusionQuery)if(e.isQueryResultAvailable(this._occlusionQuery)){var t=e.getQueryResult(this._occlusionQuery);this._isOcclusionQueryInProgress=!1,this._occlusionInternalRetryCounter=0,this._isOccluded=1!==t}else{if(this._occlusionInternalRetryCounter++,!(-1!==this.occlusionRetryCount&&this._occlusionInternalRetryCounter>this.occlusionRetryCount))return;this._isOcclusionQueryInProgress=!1,this._occlusionInternalRetryCounter=0,this._isOccluded=this.occlusionType!==i.OCCLUSION_TYPE_OPTIMISTIC&&this._isOccluded}var r=this.getScene().getBoundingBoxRenderer();this._occlusionQuery||(this._occlusionQuery=e.createQuery()),e.beginOcclusionQuery(this.occlusionQueryAlgorithmType,this._occlusionQuery),r.renderOcclusionBoundingBox(this),e.endOcclusionQuery(this.occlusionQueryAlgorithmType),this._isOcclusionQueryInProgress=!0}},i.OCCLUSION_TYPE_NONE=0,i.OCCLUSION_TYPE_OPTIMISTIC=1,i.OCCLUSION_TYPE_STRICT=2,i.OCCLUSION_ALGORITHM_TYPE_ACCURATE=0,i.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE=1,i}(e.TransformNode);e.AbstractMesh=t}(s||(s={}));!function(e){var t=function(t){function i(r,n){var o=t.call(this,r,n)||this;return o.diffuse=new e.Color3(1,1,1),o.specular=new e.Color3(1,1,1),o.intensity=1,o.range=Number.MAX_VALUE,o._photometricScale=1,o._intensityMode=i.INTENSITYMODE_AUTOMATIC,o._radius=1e-5,o.renderPriority=0,o.shadowEnabled=!0,o._excludeWithLayerMask=0,o._includeOnlyWithLayerMask=0,o._lightmapMode=0,o._excludedMeshesIds=new Array,o._includedOnlyMeshesIds=new Array,o.getScene().addLight(o),o._uniformBuffer=new e.UniformBuffer(o.getScene().getEngine()),o._buildUniformLayout(),o.includedOnlyMeshes=new Array,o.excludedMeshes=new Array,o._resyncMeshes(),o}return n(i,t),Object.defineProperty(i,"LIGHTMAP_DEFAULT",{get:function(){return i._LIGHTMAP_DEFAULT},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTMAP_SPECULAR",{get:function(){return i._LIGHTMAP_SPECULAR},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTMAP_SHADOWSONLY",{get:function(){return i._LIGHTMAP_SHADOWSONLY},enumerable:!0,configurable:!0}),Object.defineProperty(i,"INTENSITYMODE_AUTOMATIC",{get:function(){return i._INTENSITYMODE_AUTOMATIC},enumerable:!0,configurable:!0}),Object.defineProperty(i,"INTENSITYMODE_LUMINOUSPOWER",{get:function(){return i._INTENSITYMODE_LUMINOUSPOWER},enumerable:!0,configurable:!0}),Object.defineProperty(i,"INTENSITYMODE_LUMINOUSINTENSITY",{get:function(){return i._INTENSITYMODE_LUMINOUSINTENSITY},enumerable:!0,configurable:!0}),Object.defineProperty(i,"INTENSITYMODE_ILLUMINANCE",{get:function(){return i._INTENSITYMODE_ILLUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"INTENSITYMODE_LUMINANCE",{get:function(){return i._INTENSITYMODE_LUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTTYPEID_POINTLIGHT",{get:function(){return i._LIGHTTYPEID_POINTLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTTYPEID_DIRECTIONALLIGHT",{get:function(){return i._LIGHTTYPEID_DIRECTIONALLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTTYPEID_SPOTLIGHT",{get:function(){return i._LIGHTTYPEID_SPOTLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTTYPEID_HEMISPHERICLIGHT",{get:function(){return i._LIGHTTYPEID_HEMISPHERICLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"intensityMode",{get:function(){return this._intensityMode},set:function(e){this._intensityMode=e,this._computePhotometricScale()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"radius",{get:function(){return this._radius},set:function(e){this._radius=e,this._computePhotometricScale()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"includedOnlyMeshes",{get:function(){return this._includedOnlyMeshes},set:function(e){this._includedOnlyMeshes=e,this._hookArrayForIncludedOnly(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"excludedMeshes",{get:function(){return this._excludedMeshes},set:function(e){this._excludedMeshes=e,this._hookArrayForExcluded(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"excludeWithLayerMask",{get:function(){return this._excludeWithLayerMask},set:function(e){this._excludeWithLayerMask=e,this._resyncMeshes()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"includeOnlyWithLayerMask",{get:function(){return this._includeOnlyWithLayerMask},set:function(e){this._includeOnlyWithLayerMask=e,this._resyncMeshes()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"lightmapMode",{get:function(){return this._lightmapMode},set:function(e){this._lightmapMode!==e&&(this._lightmapMode=e,this._markMeshesAsLightDirty())},enumerable:!0,configurable:!0}),i.prototype._buildUniformLayout=function(){},i.prototype.getClassName=function(){return"Light"},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.setEnabled=function(e){t.prototype.setEnabled.call(this,e),this._resyncMeshes()},i.prototype.getShadowGenerator=function(){return this._shadowGenerator},i.prototype.getAbsolutePosition=function(){return e.Vector3.Zero()},i.prototype.transferToEffect=function(e,t){},i.prototype._getWorldMatrix=function(){return e.Matrix.Identity()},i.prototype.canAffectMesh=function(e){return!e||!(this.includedOnlyMeshes&&this.includedOnlyMeshes.length>0&&-1===this.includedOnlyMeshes.indexOf(e))&&(!(this.excludedMeshes&&this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e))&&((0===this.includeOnlyWithLayerMask||0!=(this.includeOnlyWithLayerMask&e.layerMask))&&!(0!==this.excludeWithLayerMask&&this.excludeWithLayerMask&e.layerMask)))},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.compareLightsPriority=function(e,t){return e.shadowEnabled!==t.shadowEnabled?(t.shadowEnabled?1:0)-(e.shadowEnabled?1:0):t.renderPriority-e.renderPriority},i.prototype.dispose=function(){this._shadowGenerator&&(this._shadowGenerator.dispose(),this._shadowGenerator=null),this.getScene().stopAnimation(this);for(var e=0,i=this.getScene().meshes;e<i.length;e++)i[e]._removeLightSource(this);this._uniformBuffer.dispose(),this.getScene().removeLight(this),t.prototype.dispose.call(this)},i.prototype.getTypeID=function(){return 0},i.prototype.getScaledIntensity=function(){return this._photometricScale*this.intensity},i.prototype.clone=function(t){var r=i.GetConstructorFromName(this.getTypeID(),t,this.getScene());return r?e.SerializationHelper.Clone(r,this):null},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,r){switch(t){case 0:return function(){return new e.PointLight(i,e.Vector3.Zero(),r)};case 1:return function(){return new e.DirectionalLight(i,e.Vector3.Zero(),r)};case 2:return function(){return new e.SpotLight(i,e.Vector3.Zero(),e.Vector3.Zero(),0,0,r)};case 3:return function(){return new e.HemisphericLight(i,e.Vector3.Zero(),r)}}return null},i.Parse=function(t,r){var n=i.GetConstructorFromName(t.type,t.name,r);if(!n)return null;var o=e.SerializationHelper.Parse(n,t,r);if(t.excludedMeshesIds&&(o._excludedMeshesIds=t.excludedMeshesIds),t.includedOnlyMeshesIds&&(o._includedOnlyMeshesIds=t.includedOnlyMeshesIds),t.parentId&&(o._waitingParentId=t.parentId),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,r)}return t.autoAnimate&&r.beginAnimation(o,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,t.autoAnimateSpeed||1),o},i.prototype._hookArrayForExcluded=function(e){var t=this,i=e.push;e.push=function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];for(var o=i.apply(e,r),s=0,a=r;s<a.length;s++)a[s]._resyncLighSource(t);return o};var r=e.splice;e.splice=function(i,n){for(var o=r.apply(e,[i,n]),s=0,a=o;s<a.length;s++)a[s]._resyncLighSource(t);return o};for(var n=0,o=e;n<o.length;n++)o[n]._resyncLighSource(this)},i.prototype._hookArrayForIncludedOnly=function(e){var t=this,i=e.push;e.push=function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];var o=i.apply(e,r);return t._resyncMeshes(),o};var r=e.splice;e.splice=function(i,n){var o=r.apply(e,[i,n]);return t._resyncMeshes(),o},this._resyncMeshes()},i.prototype._resyncMeshes=function(){for(var e=0,t=this.getScene().meshes;e<t.length;e++)t[e]._resyncLighSource(this)},i.prototype._markMeshesAsLightDirty=function(){for(var e=0,t=this.getScene().meshes;e<t.length;e++){var i=t[e];-1!==i._lightSources.indexOf(this)&&i._markSubMeshesAsLightDirty()}},i.prototype._computePhotometricScale=function(){this._photometricScale=this._getPhotometricScale(),this.getScene().resetCachedMaterial()},i.prototype._getPhotometricScale=function(){var e=0,t=this.getTypeID(),r=this.intensityMode;switch(r===i.INTENSITYMODE_AUTOMATIC&&(r=t===i.LIGHTTYPEID_DIRECTIONALLIGHT?i.INTENSITYMODE_ILLUMINANCE:i.INTENSITYMODE_LUMINOUSINTENSITY),t){case i.LIGHTTYPEID_POINTLIGHT:case i.LIGHTTYPEID_SPOTLIGHT:switch(r){case i.INTENSITYMODE_LUMINOUSPOWER:e=1/(4*Math.PI);break;case i.INTENSITYMODE_LUMINOUSINTENSITY:e=1;break;case i.INTENSITYMODE_LUMINANCE:e=this.radius*this.radius}break;case i.LIGHTTYPEID_DIRECTIONALLIGHT:switch(r){case i.INTENSITYMODE_ILLUMINANCE:e=1;break;case i.INTENSITYMODE_LUMINANCE:var n=this.radius;n=Math.max(n,.001),e=2*Math.PI*(1-Math.cos(n))}break;case i.LIGHTTYPEID_HEMISPHERICLIGHT:e=1}return e},i.prototype._reorderLightsInScene=function(){var e=this.getScene();0!=this._renderPriority&&(e.requireLightSorting=!0),this.getScene().sortLightsByPriority()},i._LIGHTMAP_DEFAULT=0,i._LIGHTMAP_SPECULAR=1,i._LIGHTMAP_SHADOWSONLY=2,i._INTENSITYMODE_AUTOMATIC=0,i._INTENSITYMODE_LUMINOUSPOWER=1,i._INTENSITYMODE_LUMINOUSINTENSITY=2,i._INTENSITYMODE_ILLUMINANCE=3,i._INTENSITYMODE_LUMINANCE=4,i._LIGHTTYPEID_POINTLIGHT=0,i._LIGHTTYPEID_DIRECTIONALLIGHT=1,i._LIGHTTYPEID_SPOTLIGHT=2,i._LIGHTTYPEID_HEMISPHERICLIGHT=3,r([e.serializeAsColor3()],i.prototype,"diffuse",void 0),r([e.serializeAsColor3()],i.prototype,"specular",void 0),r([e.serialize()],i.prototype,"intensity",void 0),r([e.serialize()],i.prototype,"range",void 0),r([e.serialize()],i.prototype,"intensityMode",null),r([e.serialize()],i.prototype,"radius",null),r([e.serialize()],i.prototype,"_renderPriority",void 0),r([e.expandToProperty("_reorderLightsInScene")],i.prototype,"renderPriority",void 0),r([e.serialize()],i.prototype,"shadowEnabled",void 0),r([e.serialize("excludeWithLayerMask")],i.prototype,"_excludeWithLayerMask",void 0),r([e.serialize("includeOnlyWithLayerMask")],i.prototype,"_includeOnlyWithLayerMask",void 0),r([e.serialize("lightmapMode")],i.prototype,"_lightmapMode",void 0),i}(e.Node);e.Light=t}(s||(s={}));!function(e){var t=function(t){function i(r,n,o){var s=t.call(this,r,o)||this;return s.upVector=e.Vector3.Up(),s.orthoLeft=null,s.orthoRight=null,s.orthoBottom=null,s.orthoTop=null,s.fov=.8,s.minZ=1,s.maxZ=1e4,s.inertia=.9,s.mode=i.PERSPECTIVE_CAMERA,s.isIntermediate=!1,s.viewport=new e.Viewport(0,0,1,1),s.layerMask=268435455,s.fovMode=i.FOVMODE_VERTICAL_FIXED,s.cameraRigMode=i.RIG_MODE_NONE,s._rigCameras=new Array,s._webvrViewMatrix=e.Matrix.Identity(),s._skipRendering=!1,s.customRenderTargets=new Array,s.onViewMatrixChangedObservable=new e.Observable,s.onProjectionMatrixChangedObservable=new e.Observable,s.onAfterCheckInputsObservable=new e.Observable,s.onRestoreStateObservable=new e.Observable,s._computedViewMatrix=e.Matrix.Identity(),s._projectionMatrix=new e.Matrix,s._doNotComputeProjectionMatrix=!1,s._postProcesses=new Array,s._transformMatrix=e.Matrix.Zero(),s._activeMeshes=new e.SmartArray(256),s._globalPosition=e.Vector3.Zero(),s._refreshFrustumPlanes=!0,s.getScene().addCamera(s),s.getScene().activeCamera||(s.getScene().activeCamera=s),s.position=n,s}return n(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}),Object.defineProperty(i,"RIG_MODE_WEBVR",{get:function(){return i._RIG_MODE_WEBVR},enumerable:!0,configurable:!0}),i.prototype.storeState=function(){return this._stateStored=!0,this._storedFov=this.fov,this},i.prototype._restoreStateValues=function(){return!!this._stateStored&&(this.fov=this._storedFov,!0)},i.prototype.restoreState=function(){return!!this._restoreStateValues()&&(this.onRestoreStateObservable.notifyObservers(this),!0)},i.prototype.getClassName=function(){return"Camera"},i.prototype.toString=function(e){var t="Name: "+this.name;if(t+=", type: "+this.getClassName(),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.fovMode=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),this._cache.position.copyFrom(this.position),this._cache.upVector.copyFrom(this.upVector)},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())},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.fovMode===this.fovMode&&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._checkInputs(),this.cameraRigMode!==i.RIG_MODE_NONE&&this._updateRigCameras()},i.prototype._checkInputs=function(){this.onAfterCheckInputsObservable.notifyObservers(this)},Object.defineProperty(i.prototype,"rigCameras",{get:function(){return this._rigCameras},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"rigPostProcess",{get:function(){return this._rigPostProcess},enumerable:!0,configurable:!0}),i.prototype._cascadePostProcessesToRigCams=function(){this._postProcesses.length>0&&this._postProcesses[0].markTextureDirty();for(var t=0,i=this._rigCameras.length;t<i;t++){var r=this._rigCameras[t],n=r._rigPostProcess;n?(n instanceof e.PassPostProcess&&(r.isIntermediate=0===this._postProcesses.length),r._postProcesses=this._postProcesses.slice(0).concat(n),n.markTextureDirty()):r._postProcesses=this._postProcesses.slice(0)}},i.prototype.attachPostProcess=function(t,i){return void 0===i&&(i=null),!t.isReusable()&&this._postProcesses.indexOf(t)>-1?(e.Tools.Error("You're trying to reuse a post process not defined as reusable."),0):(null==i||i<0?this._postProcesses.push(t):this._postProcesses.splice(i,0,t),this._cascadePostProcessesToRigCams(),this._postProcesses.indexOf(t))},i.prototype.detachPostProcess=function(e){var t=this._postProcesses.indexOf(e);-1!==t&&this._postProcesses.splice(t,1),this._cascadePostProcessesToRigCams()},i.prototype.getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this.getViewMatrix().invertToRef(this._worldMatrix),this._worldMatrix},i.prototype._getViewMatrix=function(){return e.Matrix.Identity()},i.prototype.getViewMatrix=function(t){return!t&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this.updateCache(),this._computedViewMatrix=this._getViewMatrix(),this._currentRenderId=this.getScene().getRenderId(),this._refreshFrustumPlanes=!0,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._cameraRigParams&&this._cameraRigParams.vrPreViewMatrix&&this._computedViewMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix,this._computedViewMatrix),this.onViewMatrixChangedObservable.notifyObservers(this),this._computedViewMatrix)},i.prototype.freezeProjectionMatrix=function(e){this._doNotComputeProjectionMatrix=!0,void 0!==e&&(this._projectionMatrix=e)},i.prototype.unfreezeProjectionMatrix=function(){this._doNotComputeProjectionMatrix=!1},i.prototype.getProjectionMatrix=function(t){if(this._doNotComputeProjectionMatrix||!t&&this._isSynchronizedProjectionMatrix())return this._projectionMatrix;this._cache.mode=this.mode,this._cache.minZ=this.minZ,this._cache.maxZ=this.maxZ,this._refreshFrustumPlanes=!0;var r=this.getEngine(),n=this.getScene();if(this.mode===i.PERSPECTIVE_CAMERA)this._cache.fov=this.fov,this._cache.fovMode=this.fovMode,this._cache.aspectRatio=r.getAspectRatio(this),this.minZ<=0&&(this.minZ=.1),n.useRightHandedSystem?e.Matrix.PerspectiveFovRHToRef(this.fov,r.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode===i.FOVMODE_VERTICAL_FIXED):e.Matrix.PerspectiveFovLHToRef(this.fov,r.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode===i.FOVMODE_VERTICAL_FIXED);else{var o=r.getRenderWidth()/2,s=r.getRenderHeight()/2;n.useRightHandedSystem?e.Matrix.OrthoOffCenterRHToRef(this.orthoLeft||-o,this.orthoRight||o,this.orthoBottom||-s,this.orthoTop||s,this.minZ,this.maxZ,this._projectionMatrix):e.Matrix.OrthoOffCenterLHToRef(this.orthoLeft||-o,this.orthoRight||o,this.orthoBottom||-s,this.orthoTop||s,this.minZ,this.maxZ,this._projectionMatrix),this._cache.orthoLeft=this.orthoLeft,this._cache.orthoRight=this.orthoRight,this._cache.orthoBottom=this.orthoBottom,this._cache.orthoTop=this.orthoTop,this._cache.renderWidth=r.getRenderWidth(),this._cache.renderHeight=r.getRenderHeight()}return this.onProjectionMatrixChangedObservable.notifyObservers(this),this._projectionMatrix},i.prototype.getTranformationMatrix=function(){return this._computedViewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix),this._transformMatrix},i.prototype.updateFrustumPlanes=function(){this._refreshFrustumPlanes&&(this.getTranformationMatrix(),this._frustumPlanes?e.Frustum.GetPlanesToRef(this._transformMatrix,this._frustumPlanes):this._frustumPlanes=e.Frustum.GetPlanes(this._transformMatrix),this._refreshFrustumPlanes=!1)},i.prototype.isInFrustum=function(e){return this.updateFrustumPlanes(),e.isInFrustum(this._frustumPlanes)},i.prototype.isCompletelyInFrustum=function(e){return this.updateFrustumPlanes(),e.isCompletelyInFrustum(this._frustumPlanes)},i.prototype.getForwardRay=function(t,i,r){void 0===t&&(t=100),i||(i=this.getWorldMatrix()),r||(r=this.position);var n=new e.Vector3(0,0,1),o=e.Vector3.TransformNormal(n,i),s=e.Vector3.Normalize(o);return new e.Ray(r,s,t)},i.prototype.dispose=function(){for(this.onViewMatrixChangedObservable.clear(),this.onProjectionMatrixChangedObservable.clear(),this.onAfterCheckInputsObservable.clear(),this.onRestoreStateObservable.clear(),this.inputs&&this.inputs.clear(),this.getScene().stopAnimation(this),this.getScene().removeCamera(this);this._rigCameras.length>0;){var e=this._rigCameras.pop();e&&e.dispose()}if(this._rigPostProcess)this._rigPostProcess.dispose(this),this._rigPostProcess=null,this._postProcesses=[];else if(this.cameraRigMode!==i.RIG_MODE_NONE)this._rigPostProcess=null,this._postProcesses=[];else for(r=this._postProcesses.length;--r>=0;)this._postProcesses[r].dispose(this);for(var r=this.customRenderTargets.length;--r>=0;)this.customRenderTargets[r].dispose();this.customRenderTargets=[],this._activeMeshes.dispose(),t.prototype.dispose.call(this)},Object.defineProperty(i.prototype,"leftCamera",{get:function(){return this._rigCameras.length<1?null:this._rigCameras[0]},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"rightCamera",{get:function(){return this._rigCameras.length<2?null:this._rigCameras[1]},enumerable:!0,configurable:!0}),i.prototype.getLeftTarget=function(){return this._rigCameras.length<1?null:this._rigCameras[0].getTarget()},i.prototype.getRightTarget=function(){return this._rigCameras.length<2?null:this._rigCameras[1].getTarget()},i.prototype.setCameraRigMode=function(t,r){if(this.cameraRigMode!==t){for(;this._rigCameras.length>0;){var n=this._rigCameras.pop();n&&n.dispose()}if(this.cameraRigMode=t,this._cameraRigParams={},this._cameraRigParams.interaxialDistance=r.interaxialDistance||.0637,this._cameraRigParams.stereoHalfAngle=e.Tools.ToRadians(this._cameraRigParams.interaxialDistance/.0637),this.cameraRigMode!==i.RIG_MODE_NONE){var o=this.createRigCamera(this.name+"_L",0),s=this.createRigCamera(this.name+"_R",1);o&&s&&(this._rigCameras.push(o),this._rigCameras.push(s))}switch(this.cameraRigMode){case i.RIG_MODE_STEREOSCOPIC_ANAGLYPH:this._rigCameras[0]._rigPostProcess=new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[0]),this._rigCameras[1]._rigPostProcess=new e.AnaglyphPostProcess(this.name+"_anaglyph",1,this._rigCameras);break;case i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case i.RIG_MODE_STEREOSCOPIC_OVERUNDER:var a=this.cameraRigMode===i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL||this.cameraRigMode===i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED;this._rigCameras[0]._rigPostProcess=new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[0]),this._rigCameras[1]._rigPostProcess=new e.StereoscopicInterlacePostProcess(this.name+"_stereoInterlace",this._rigCameras,a);break;case i.RIG_MODE_VR:var l=r.vrCameraMetrics||e.VRCameraMetrics.GetDefault();this._rigCameras[0]._cameraRigParams.vrMetrics=l,this._rigCameras[0].viewport=new e.Viewport(0,0,.5,1),this._rigCameras[0]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[0]._cameraRigParams.vrHMatrix=l.leftHMatrix,this._rigCameras[0]._cameraRigParams.vrPreViewMatrix=l.leftPreViewMatrix,this._rigCameras[0].getProjectionMatrix=this._rigCameras[0]._getVRProjectionMatrix,this._rigCameras[1]._cameraRigParams.vrMetrics=l,this._rigCameras[1].viewport=new e.Viewport(.5,0,.5,1),this._rigCameras[1]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[1]._cameraRigParams.vrHMatrix=l.rightHMatrix,this._rigCameras[1]._cameraRigParams.vrPreViewMatrix=l.rightPreViewMatrix,this._rigCameras[1].getProjectionMatrix=this._rigCameras[1]._getVRProjectionMatrix,l.compensateDistortion&&(this._rigCameras[0]._rigPostProcess=new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Left",this._rigCameras[0],!1,l),this._rigCameras[1]._rigPostProcess=new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Right",this._rigCameras[1],!0,l));break;case i.RIG_MODE_WEBVR:if(r.vrDisplay){var h=r.vrDisplay.getEyeParameters("left"),u=r.vrDisplay.getEyeParameters("right");this._rigCameras[0].viewport=new e.Viewport(0,0,.5,1),this._rigCameras[0].setCameraRigParameter("left",!0),this._rigCameras[0].setCameraRigParameter("specs",r.specs),this._rigCameras[0].setCameraRigParameter("eyeParameters",h),this._rigCameras[0].setCameraRigParameter("frameData",r.frameData),this._rigCameras[0].setCameraRigParameter("parentCamera",r.parentCamera),this._rigCameras[0]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[0].getProjectionMatrix=this._getWebVRProjectionMatrix,this._rigCameras[0].parent=this,this._rigCameras[0]._getViewMatrix=this._getWebVRViewMatrix,this._rigCameras[1].viewport=new e.Viewport(.5,0,.5,1),this._rigCameras[1].setCameraRigParameter("eyeParameters",u),this._rigCameras[1].setCameraRigParameter("specs",r.specs),this._rigCameras[1].setCameraRigParameter("frameData",r.frameData),this._rigCameras[1].setCameraRigParameter("parentCamera",r.parentCamera),this._rigCameras[1]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[1].getProjectionMatrix=this._getWebVRProjectionMatrix,this._rigCameras[1].parent=this,this._rigCameras[1]._getViewMatrix=this._getWebVRViewMatrix,i.UseAlternateWebVRRendering&&(this._rigCameras[1]._skipRendering=!0,this._rigCameras[0]._alternateCamera=this._rigCameras[1])}}this._cascadePostProcessesToRigCams(),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._updateCameraRotationMatrix=function(){},i.prototype._updateWebVRCameraRotationMatrix=function(){},i.prototype._getWebVRProjectionMatrix=function(){return e.Matrix.Identity()},i.prototype._getWebVRViewMatrix=function(){return e.Matrix.Identity()},i.prototype.setCameraRigParameter=function(t,i){this._cameraRigParams||(this._cameraRigParams={}),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._setupInputs=function(){},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.type=this.getClassName(),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.clone=function(t){return e.SerializationHelper.Clone(i.GetConstructorFromName(this.getClassName(),t,this.getScene(),this.interaxialDistance,this.isStereoscopicSideBySide),this)},i.prototype.getDirection=function(t){var i=e.Vector3.Zero();return this.getDirectionToRef(t,i),i},i.prototype.getDirectionToRef=function(t,i){e.Vector3.TransformNormalToRef(t,this.getWorldMatrix(),i)},i.GetConstructorFromName=function(t,i,r,n,o){switch(void 0===n&&(n=0),void 0===o&&(o=!0),t){case"ArcRotateCamera":return function(){return new e.ArcRotateCamera(i,0,0,1,e.Vector3.Zero(),r)};case"DeviceOrientationCamera":return function(){return new e.DeviceOrientationCamera(i,e.Vector3.Zero(),r)};case"FollowCamera":return function(){return new e.FollowCamera(i,e.Vector3.Zero(),r)};case"ArcFollowCamera":return function(){return new e.ArcFollowCamera(i,0,0,1,null,r)};case"GamepadCamera":return function(){return new e.GamepadCamera(i,e.Vector3.Zero(),r)};case"TouchCamera":return function(){return new e.TouchCamera(i,e.Vector3.Zero(),r)};case"VirtualJoysticksCamera":return function(){return new e.VirtualJoysticksCamera(i,e.Vector3.Zero(),r)};case"WebVRFreeCamera":case"WebVRGamepadCamera":return function(){return new e.WebVRFreeCamera(i,e.Vector3.Zero(),r)};case"VRDeviceOrientationFreeCamera":return function(){return new e.VRDeviceOrientationFreeCamera(i,e.Vector3.Zero(),r)};case"VRDeviceOrientationGamepadCamera":return function(){return new e.VRDeviceOrientationGamepadCamera(i,e.Vector3.Zero(),r)};case"AnaglyphArcRotateCamera":return function(){return new e.AnaglyphArcRotateCamera(i,0,0,1,e.Vector3.Zero(),n,r)};case"AnaglyphFreeCamera":return function(){return new e.AnaglyphFreeCamera(i,e.Vector3.Zero(),n,r)};case"AnaglyphGamepadCamera":return function(){return new e.AnaglyphGamepadCamera(i,e.Vector3.Zero(),n,r)};case"AnaglyphUniversalCamera":return function(){return new e.AnaglyphUniversalCamera(i,e.Vector3.Zero(),n,r)};case"StereoscopicArcRotateCamera":return function(){return new e.StereoscopicArcRotateCamera(i,0,0,1,e.Vector3.Zero(),n,o,r)};case"StereoscopicFreeCamera":return function(){return new e.StereoscopicFreeCamera(i,e.Vector3.Zero(),n,o,r)};case"StereoscopicGamepadCamera":return function(){return new e.StereoscopicGamepadCamera(i,e.Vector3.Zero(),n,o,r)};case"StereoscopicUniversalCamera":return function(){return new e.StereoscopicUniversalCamera(i,e.Vector3.Zero(),n,o,r)};case"FreeCamera":default:return function(){return new e.UniversalCamera(i,e.Vector3.Zero(),r)}}},i.Parse=function(t,r){var n=t.type,o=i.GetConstructorFromName(n,t.name,r,t.interaxial_distance,t.isStereoscopicSideBySide),s=e.SerializationHelper.Parse(o,t,r);if(t.parentId&&(s._waitingParentId=t.parentId),s.inputs&&(s.inputs.parse(t),s._setupInputs()),s.setPosition&&(s.position.copyFromFloats(0,0,0),s.setPosition(e.Vector3.FromArray(t.position))),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 l=0;l<t.animations.length;l++){var h=t.animations[l];s.animations.push(e.Animation.Parse(h))}e.Node.ParseAnimationRanges(s,t,r)}return t.autoAnimate&&r.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._RIG_MODE_WEBVR=21,i.ForceAttachControlToAlwaysPreventDefault=!1,i.UseAlternateWebVRRendering=!1,r([e.serializeAsVector3()],i.prototype,"position",void 0),r([e.serializeAsVector3()],i.prototype,"upVector",void 0),r([e.serialize()],i.prototype,"orthoLeft",void 0),r([e.serialize()],i.prototype,"orthoRight",void 0),r([e.serialize()],i.prototype,"orthoBottom",void 0),r([e.serialize()],i.prototype,"orthoTop",void 0),r([e.serialize()],i.prototype,"fov",void 0),r([e.serialize()],i.prototype,"minZ",void 0),r([e.serialize()],i.prototype,"maxZ",void 0),r([e.serialize()],i.prototype,"inertia",void 0),r([e.serialize()],i.prototype,"mode",void 0),r([e.serialize()],i.prototype,"layerMask",void 0),r([e.serialize()],i.prototype,"fovMode",void 0),r([e.serialize()],i.prototype,"cameraRigMode",void 0),r([e.serialize()],i.prototype,"interaxialDistance",void 0),r([e.serialize()],i.prototype,"isStereoscopicSideBySide",void 0),i}(e.Node);e.Camera=t}(s||(s={}));!function(e){var t=function(){function t(e){this._renderingGroups=new Array,this._autoClearDepthStencil={},this._customOpaqueSortCompareFn={},this._customAlphaTestSortCompareFn={},this._customTransparentSortCompareFn={},this._renderinGroupInfo=null,this._scene=e;for(var i=t.MIN_RENDERINGGROUPS;i<t.MAX_RENDERINGGROUPS;i++)this._autoClearDepthStencil[i]={autoClear:!0,depth:!0,stencil:!0}}return t.prototype._clearDepthStencilBuffer=function(e,t){void 0===e&&(e=!0),void 0===t&&(t=!0),this._depthStencilBufferAlreadyCleaned||(this._scene.getEngine().clear(null,!1,e,t),this._depthStencilBufferAlreadyCleaned=!0)},t.prototype.render=function(i,r,n,o){var s=this._scene.onRenderingGroupObservable.hasObservers()?this._scene.onRenderingGroupObservable:null,a=null;if(s&&(this._renderinGroupInfo||(this._renderinGroupInfo=new e.RenderingGroupInfo),(a=this._renderinGroupInfo).scene=this._scene,a.camera=this._scene.activeCamera),o)for(h=0;h<this._scene.spriteManagers.length;h++){var l=this._scene.spriteManagers[h];this.dispatchSprites(l)}for(var h=t.MIN_RENDERINGGROUPS;h<t.MAX_RENDERINGGROUPS;h++){this._depthStencilBufferAlreadyCleaned=h===t.MIN_RENDERINGGROUPS;var u=this._renderingGroups[h];if(u||s){this._currentIndex=h;var c=0;if(s&&a&&(c=Math.pow(2,h),a.renderStage=e.RenderingGroupInfo.STAGE_PRECLEAR,a.renderingGroupId=h,s.notifyObservers(a,c)),t.AUTOCLEAR){var f=this._autoClearDepthStencil[h];f&&f.autoClear&&this._clearDepthStencilBuffer(f.depth,f.stencil)}s&&a&&(a.renderStage=e.RenderingGroupInfo.STAGE_PREOPAQUE,s.notifyObservers(a,c),a.renderStage=e.RenderingGroupInfo.STAGE_PRETRANSPARENT,s.notifyObservers(a,c)),u&&u.render(i,o,n,r),s&&a&&(a.renderStage=e.RenderingGroupInfo.STAGE_POSTTRANSPARENT,s.notifyObservers(a,c))}}},t.prototype.reset=function(){for(var e=t.MIN_RENDERINGGROUPS;e<t.MAX_RENDERINGGROUPS;e++){var i=this._renderingGroups[e];i&&i.prepare()}},t.prototype.dispose=function(){for(var e=t.MIN_RENDERINGGROUPS;e<t.MAX_RENDERINGGROUPS;e++){var i=this._renderingGroups[e];i&&i.dispose()}this._renderingGroups.length=0},t.prototype._prepareRenderingGroup=function(t){this._renderingGroups[t]||(this._renderingGroups[t]=new e.RenderingGroup(t,this._scene,this._customOpaqueSortCompareFn[t],this._customAlphaTestSortCompareFn[t],this._customTransparentSortCompareFn[t]))},t.prototype.dispatchSprites=function(e){var t=e.renderingGroupId||0;this._prepareRenderingGroup(t),this._renderingGroups[t].dispatchSprites(e)},t.prototype.dispatchParticles=function(e){var t=e.renderingGroupId||0;this._prepareRenderingGroup(t),this._renderingGroups[t].dispatchParticles(e)},t.prototype.dispatch=function(e){var t=e.getMesh().renderingGroupId||0;this._prepareRenderingGroup(t),this._renderingGroups[t].dispatch(e)},t.prototype.setRenderingOrder=function(e,t,i,r){if(void 0===t&&(t=null),void 0===i&&(i=null),void 0===r&&(r=null),this._customOpaqueSortCompareFn[e]=t,this._customAlphaTestSortCompareFn[e]=i,this._customTransparentSortCompareFn[e]=r,this._renderingGroups[e]){var n=this._renderingGroups[e];n.opaqueSortCompareFn=this._customOpaqueSortCompareFn[e],n.alphaTestSortCompareFn=this._customAlphaTestSortCompareFn[e],n.transparentSortCompareFn=this._customTransparentSortCompareFn[e]}},t.prototype.setRenderingAutoClearDepthStencil=function(e,t,i,r){void 0===i&&(i=!0),void 0===r&&(r=!0),this._autoClearDepthStencil[e]={autoClear:t,depth:i,stencil:r}},t.MAX_RENDERINGGROUPS=4,t.MIN_RENDERINGGROUPS=0,t.AUTOCLEAR=!0,t}();e.RenderingManager=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n,o){void 0===r&&(r=null),void 0===n&&(n=null),void 0===o&&(o=null),this.index=t,this._opaqueSubMeshes=new e.SmartArray(256),this._transparentSubMeshes=new e.SmartArray(256),this._alphaTestSubMeshes=new e.SmartArray(256),this._depthOnlySubMeshes=new e.SmartArray(256),this._particleSystems=new e.SmartArray(256),this._spriteManagers=new e.SmartArray(256),this._edgesRenderers=new e.SmartArray(16),this._scene=i,this.opaqueSortCompareFn=r,this.alphaTestSortCompareFn=n,this.transparentSortCompareFn=o}return Object.defineProperty(t.prototype,"opaqueSortCompareFn",{set:function(e){this._opaqueSortCompareFn=e,this._renderOpaque=e?this.renderOpaqueSorted:t.renderUnsorted},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"alphaTestSortCompareFn",{set:function(e){this._alphaTestSortCompareFn=e,this._renderAlphaTest=e?this.renderAlphaTestSorted:t.renderUnsorted},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"transparentSortCompareFn",{set:function(e){this._transparentSortCompareFn=e||t.defaultTransparentSortCompare,this._renderTransparent=this.renderTransparentSorted},enumerable:!0,configurable:!0}),t.prototype.render=function(t,i,r,n){if(t)t(this._opaqueSubMeshes,this._alphaTestSubMeshes,this._transparentSubMeshes,this._depthOnlySubMeshes);else{var o=this._scene.getEngine();0!==this._depthOnlySubMeshes.length&&(o.setAlphaTesting(!0),o.setColorWrite(!1),this._renderAlphaTest(this._depthOnlySubMeshes),o.setAlphaTesting(!1),o.setColorWrite(!0)),0!==this._opaqueSubMeshes.length&&this._renderOpaque(this._opaqueSubMeshes),0!==this._alphaTestSubMeshes.length&&(o.setAlphaTesting(!0),this._renderAlphaTest(this._alphaTestSubMeshes),o.setAlphaTesting(!1));var s=o.getStencilBuffer();o.setStencilBuffer(!1),i&&this._renderSprites(),r&&this._renderParticles(n),this.onBeforeTransparentRendering&&this.onBeforeTransparentRendering(),0!==this._transparentSubMeshes.length&&(this._renderTransparent(this._transparentSubMeshes),o.setAlphaMode(e.Engine.ALPHA_DISABLE)),o.setStencilBuffer(!1);for(var a=0;a<this._edgesRenderers.length;a++)this._edgesRenderers.data[a].render();o.setStencilBuffer(s)}},t.prototype.renderOpaqueSorted=function(e){return t.renderSorted(e,this._opaqueSortCompareFn,this._scene.activeCamera,!1)},t.prototype.renderAlphaTestSorted=function(e){return t.renderSorted(e,this._alphaTestSortCompareFn,this._scene.activeCamera,!1)},t.prototype.renderTransparentSorted=function(e){return t.renderSorted(e,this._transparentSortCompareFn,this._scene.activeCamera,!0)},t.renderSorted=function(t,i,r,n){for(var o,s=0,a=r?r.globalPosition:e.Vector3.Zero();s<t.length;s++)(o=t.data[s])._alphaIndex=o.getMesh().alphaIndex,o._distanceToCamera=o.getBoundingInfo().boundingSphere.centerWorld.subtract(a).length();var l=t.data.slice(0,t.length);for(i&&l.sort(i),s=0;s<l.length;s++){if(o=l[s],n){var h=o.getMaterial();if(h&&h.needDepthPrePass){var u=h.getScene().getEngine();u.setColorWrite(!1),u.setAlphaTesting(!0),u.setAlphaMode(e.Engine.ALPHA_DISABLE),o.render(!1),u.setAlphaTesting(!1),u.setColorWrite(!0)}}o.render(n)}},t.renderUnsorted=function(e){for(var t=0;t<e.length;t++)e.data[t].render(!1)},t.defaultTransparentSortCompare=function(e,i){return e._alphaIndex>i._alphaIndex?1:e._alphaIndex<i._alphaIndex?-1:t.backToFrontSortCompare(e,i)},t.backToFrontSortCompare=function(e,t){return e._distanceToCamera<t._distanceToCamera?1:e._distanceToCamera>t._distanceToCamera?-1:0},t.frontToBackSortCompare=function(e,t){return e._distanceToCamera<t._distanceToCamera?-1:e._distanceToCamera>t._distanceToCamera?1:0},t.prototype.prepare=function(){this._opaqueSubMeshes.reset(),this._transparentSubMeshes.reset(),this._alphaTestSubMeshes.reset(),this._depthOnlySubMeshes.reset(),this._particleSystems.reset(),this._spriteManagers.reset(),this._edgesRenderers.reset()},t.prototype.dispose=function(){this._opaqueSubMeshes.dispose(),this._transparentSubMeshes.dispose(),this._alphaTestSubMeshes.dispose(),this._depthOnlySubMeshes.dispose(),this._particleSystems.dispose(),this._spriteManagers.dispose(),this._edgesRenderers.dispose()},t.prototype.dispatch=function(e){var t=e.getMaterial(),i=e.getMesh();t&&(t.needAlphaBlendingForMesh(i)?this._transparentSubMeshes.push(e):t.needAlphaTesting()?(t.needDepthPrePass&&this._depthOnlySubMeshes.push(e),this._alphaTestSubMeshes.push(e)):(t.needDepthPrePass&&this._depthOnlySubMeshes.push(e),this._opaqueSubMeshes.push(e)),i._edgesRenderer&&this._edgesRenderers.push(i._edgesRenderer))},t.prototype.dispatchSprites=function(e){this._spriteManagers.push(e)},t.prototype.dispatchParticles=function(e){this._particleSystems.push(e)},t.prototype._renderParticles=function(e){if(0!==this._particleSystems.length){var t=this._scene.activeCamera;this._scene.onBeforeParticlesRenderingObservable.notifyObservers(this._scene);for(var i=0;i<this._scene._activeParticleSystems.length;i++){var r=this._scene._activeParticleSystems.data[i];if(0!==(t&&t.layerMask&r.layerMask)){var n=r.emitter;n.position&&e&&-1===e.indexOf(n)||this._scene._activeParticles.addCount(r.render(),!1)}}this._scene.onAfterParticlesRenderingObservable.notifyObservers(this._scene)}},t.prototype._renderSprites=function(){if(this._scene.spritesEnabled&&0!==this._spriteManagers.length){var e=this._scene.activeCamera;this._scene.onBeforeSpritesRenderingObservable.notifyObservers(this._scene);for(var t=0;t<this._spriteManagers.length;t++){var i=this._spriteManagers.data[t];0!==(e&&e.layerMask&i.layerMask)&&i.render()}this._scene.onAfterSpritesRenderingObservable.notifyObservers(this._scene)}},t}();e.RenderingGroup=t}(s||(s={}));!function(e){var t=function(){function e(){this._singleClick=!1,this._doubleClick=!1,this._hasSwiped=!1,this._ignore=!1}return Object.defineProperty(e.prototype,"singleClick",{get:function(){return this._singleClick},set:function(e){this._singleClick=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"doubleClick",{get:function(){return this._doubleClick},set:function(e){this._doubleClick=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hasSwiped",{get:function(){return this._hasSwiped},set:function(e){this._hasSwiped=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ignore",{get:function(){return this._ignore},set:function(e){this._ignore=e},enumerable:!0,configurable:!0}),e}(),i=function(){function e(){}return e.STAGE_PRECLEAR=1,e.STAGE_PREOPAQUE=2,e.STAGE_PRETRANSPARENT=3,e.STAGE_POSTTRANSPARENT=4,e}();e.RenderingGroupInfo=i;var r=function(){function i(t){this.autoClear=!0,this.autoClearDepthAndStencil=!0,this.clearColor=new e.Color4(.2,.2,.3,1),this.ambientColor=new e.Color3(0,0,0),this.forceWireframe=!1,this._forcePointsCloud=!1,this.forceShowBoundingBoxes=!1,this.animationsEnabled=!0,this.constantlyUpdateMeshUnderPointer=!1,this.hoverCursor="pointer",this.defaultCursor="",this.preventDefaultOnPointerDown=!0,this.metadata=null,this.onDisposeObservable=new e.Observable,this.onBeforeRenderObservable=new e.Observable,this.onAfterRenderObservable=new e.Observable,this.onBeforeAnimationsObservable=new e.Observable,this.onAfterAnimationsObservable=new e.Observable,this.onBeforeDrawPhaseObservable=new e.Observable,this.onAfterDrawPhaseObservable=new e.Observable,this.onBeforePhysicsObservable=new e.Observable,this.onAfterPhysicsObservable=new e.Observable,this.onReadyObservable=new e.Observable,this.onBeforeCameraRenderObservable=new e.Observable,this.onAfterCameraRenderObservable=new e.Observable,this.onBeforeActiveMeshesEvaluationObservable=new e.Observable,this.onAfterActiveMeshesEvaluationObservable=new e.Observable,this.onBeforeParticlesRenderingObservable=new e.Observable,this.onAfterParticlesRenderingObservable=new e.Observable,this.onBeforeSpritesRenderingObservable=new e.Observable,this.onAfterSpritesRenderingObservable=new e.Observable,this.onDataLoadedObservable=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.onNewTransformNodeAddedObservable=new e.Observable,this.onTransformNodeRemovedObservable=new e.Observable,this.onNewMeshAddedObservable=new e.Observable,this.onMeshRemovedObservable=new e.Observable,this.OnBeforeRenderTargetsRenderObservable=new e.Observable,this.OnAfterRenderTargetsRenderObservable=new e.Observable,this.onBeforeStepObservable=new e.Observable,this.onAfterStepObservable=new e.Observable,this.onRenderingGroupObservable=new e.Observable,this.animations=[],this.onPrePointerObservable=new e.Observable,this.onPointerObservable=new e.Observable,this._meshPickProceed=!1,this._previousHasSwiped=!1,this._currentPickResult=null,this._previousPickResult=null,this._totalPointersPressed=0,this._doubleClickOccured=!1,this.cameraToUseForPointers=null,this._startingPointerPosition=new e.Vector2(0,0),this._previousStartingPointerPosition=new e.Vector2(0,0),this._startingPointerTime=0,this._previousStartingPointerTime=0,this._timeAccumulator=0,this._currentStepId=0,this._currentInternalStep=0,this.onPreKeyboardObservable=new e.Observable,this.onKeyboardObservable=new e.Observable,this._useRightHandedSystem=!1,this._fogEnabled=!0,this._fogMode=i.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.transformNodes=new Array,this.meshes=new Array,this._geometries=new Array,this.materials=new Array,this.multiMaterials=new Array,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.highlightLayers=new Array,this._skeletonsEnabled=!0,this.skeletons=new Array,this.morphTargetManagers=new Array,this.lensFlaresEnabled=!0,this.lensFlareSystems=new Array,this.collisionsEnabled=!0,this.gravity=new e.Vector3(0,-9.807,0),this.postProcesses=new Array,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.SmartArrayNoDuplicate(256),this.proceduralTexturesEnabled=!0,this._proceduralTextures=new Array,this.soundTracks=new Array,this._audioEnabled=!0,this._headphone=!1,this._totalVertices=new e.PerfCounter,this._activeIndices=new e.PerfCounter,this._activeParticles=new e.PerfCounter,this._activeBones=new e.PerfCounter,this._animationTime=0,this.animationTimeScale=1,this._renderId=0,this._executeWhenReadyTimeoutId=-1,this._intermediateRendering=!1,this._viewUpdateFlag=-1,this._projectionUpdateFlag=-1,this._alternateViewUpdateFlag=-1,this._alternateProjectionUpdateFlag=-1,this._toBeDisposed=new e.SmartArray(256),this._pendingData=new Array,this._isDisposed=!1,this._activeMeshes=new e.SmartArray(256),this._processedMaterials=new e.SmartArray(256),this._renderTargets=new e.SmartArrayNoDuplicate(256),this._activeParticleSystems=new e.SmartArray(256),this._activeSkeletons=new e.SmartArrayNoDuplicate(32),this._softwareSkinnedMeshes=new e.SmartArrayNoDuplicate(32),this._activeAnimatables=new Array,this._transformMatrix=e.Matrix.Zero(),this._useAlternateCameraConfiguration=!1,this._alternateRendering=!1,this.requireLightSorting=!1,this._activeMeshesFrozen=!1,this._engine=t||e.Engine.LastCreatedEngine,this._engine.scenes.push(this),this._uid=null,this._renderingManager=new e.RenderingManager(this),this.postProcessManager=new e.PostProcessManager(this),e.OutlineRenderer&&(this._outlineRenderer=new e.OutlineRenderer(this)),e.Tools.IsWindowObjectExist()&&this.attachControl(),e.SimplificationQueue&&(this.simplificationQueue=new e.SimplificationQueue),this.workerCollisions=!1,this._createUbo(),this._imageProcessingConfiguration=new e.ImageProcessingConfiguration}return Object.defineProperty(i,"FOGMODE_NONE",{get:function(){return i._FOGMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"FOGMODE_EXP",{get:function(){return i._FOGMODE_EXP},enumerable:!0,configurable:!0}),Object.defineProperty(i,"FOGMODE_EXP2",{get:function(){return i._FOGMODE_EXP2},enumerable:!0,configurable:!0}),Object.defineProperty(i,"FOGMODE_LINEAR",{get:function(){return i._FOGMODE_LINEAR},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"environmentTexture",{get:function(){return this._environmentTexture},set:function(t){this._environmentTexture!==t&&(this._environmentTexture=t,this.markAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"forcePointsCloud",{get:function(){return this._forcePointsCloud},set:function(t){this._forcePointsCloud!==t&&(this._forcePointsCloud=t,this.markAllMaterialsAsDirty(e.Material.MiscDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"beforeRender",{set:function(e){this._onBeforeRenderObserver&&this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver),e&&(this._onBeforeRenderObserver=this.onBeforeRenderObservable.add(e))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"afterRender",{set:function(e){this._onAfterRenderObserver&&this.onAfterRenderObservable.remove(this._onAfterRenderObserver),e&&(this._onAfterRenderObserver=this.onAfterRenderObservable.add(e))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"beforeCameraRender",{set:function(e){this._onBeforeCameraRenderObserver&&this.onBeforeCameraRenderObservable.remove(this._onBeforeCameraRenderObserver),this._onBeforeCameraRenderObserver=this.onBeforeCameraRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"afterCameraRender",{set:function(e){this._onAfterCameraRenderObserver&&this.onAfterCameraRenderObservable.remove(this._onAfterCameraRenderObserver),this._onAfterCameraRenderObserver=this.onAfterCameraRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"gamepadManager",{get:function(){return this._gamepadManager||(this._gamepadManager=new e.GamepadManager),this._gamepadManager},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"unTranslatedPointer",{get:function(){return new e.Vector2(this._unTranslatedPointerX,this._unTranslatedPointerY)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"useRightHandedSystem",{get:function(){return this._useRightHandedSystem},set:function(t){this._useRightHandedSystem!==t&&(this._useRightHandedSystem=t,this.markAllMaterialsAsDirty(e.Material.MiscDirtyFlag))},enumerable:!0,configurable:!0}),i.prototype.setStepId=function(e){this._currentStepId=e},i.prototype.getStepId=function(){return this._currentStepId},i.prototype.getInternalStep=function(){return this._currentInternalStep},Object.defineProperty(i.prototype,"fogEnabled",{get:function(){return this._fogEnabled},set:function(t){this._fogEnabled!==t&&(this._fogEnabled=t,this.markAllMaterialsAsDirty(e.Material.MiscDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"fogMode",{get:function(){return this._fogMode},set:function(t){this._fogMode!==t&&(this._fogMode=t,this.markAllMaterialsAsDirty(e.Material.MiscDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"shadowsEnabled",{get:function(){return this._shadowsEnabled},set:function(t){this._shadowsEnabled!==t&&(this._shadowsEnabled=t,this.markAllMaterialsAsDirty(e.Material.LightDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"lightsEnabled",{get:function(){return this._lightsEnabled},set:function(t){this._lightsEnabled!==t&&(this._lightsEnabled=t,this.markAllMaterialsAsDirty(e.Material.LightDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"defaultMaterial",{get:function(){return this._defaultMaterial||(this._defaultMaterial=new e.StandardMaterial("default material",this)),this._defaultMaterial},set:function(e){this._defaultMaterial=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"texturesEnabled",{get:function(){return this._texturesEnabled},set:function(t){this._texturesEnabled!==t&&(this._texturesEnabled=t,this.markAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"skeletonsEnabled",{get:function(){return this._skeletonsEnabled},set:function(t){this._skeletonsEnabled!==t&&(this._skeletonsEnabled=t,this.markAllMaterialsAsDirty(e.Material.AttributesDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"postProcessRenderPipelineManager",{get:function(){return this._postProcessRenderPipelineManager||(this._postProcessRenderPipelineManager=new e.PostProcessRenderPipelineManager),this._postProcessRenderPipelineManager},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"mainSoundTrack",{get:function(){return this._mainSoundTrack||(this._mainSoundTrack=new e.SoundTrack(this,{mainTrack:!0})),this._mainSoundTrack},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"_isAlternateRenderingEnabled",{get:function(){return this._alternateRendering},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"frustumPlanes",{get:function(){return this._frustumPlanes},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"debugLayer",{get:function(){return this._debugLayer||(this._debugLayer=new e.DebugLayer(this)),this._debugLayer},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"workerCollisions",{get:function(){return this._workerCollisions},set:function(t){e.CollisionCoordinatorLegacy&&(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(i.prototype,"selectionOctree",{get:function(){return this._selectionOctree},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"meshUnderPointer",{get:function(){return this._pointerOverMesh},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"pointerX",{get:function(){return this._pointerX},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"pointerY",{get:function(){return this._pointerY},enumerable:!0,configurable:!0}),i.prototype.getCachedMaterial=function(){return this._cachedMaterial},i.prototype.getCachedEffect=function(){return this._cachedEffect},i.prototype.getCachedVisibility=function(){return this._cachedVisibility},i.prototype.isCachedMaterialInvalid=function(e,t,i){return void 0===i&&(i=1),this._cachedEffect!==t||this._cachedMaterial!==e||this._cachedVisibility!==i},i.prototype.getBoundingBoxRenderer=function(){return this._boundingBoxRenderer||(this._boundingBoxRenderer=new e.BoundingBoxRenderer(this)),this._boundingBoxRenderer},i.prototype.getOutlineRenderer=function(){return this._outlineRenderer},i.prototype.getEngine=function(){return this._engine},i.prototype.getTotalVertices=function(){return this._totalVertices.current},Object.defineProperty(i.prototype,"totalVerticesPerfCounter",{get:function(){return this._totalVertices},enumerable:!0,configurable:!0}),i.prototype.getActiveIndices=function(){return this._activeIndices.current},Object.defineProperty(i.prototype,"totalActiveIndicesPerfCounter",{get:function(){return this._activeIndices},enumerable:!0,configurable:!0}),i.prototype.getActiveParticles=function(){return this._activeParticles.current},Object.defineProperty(i.prototype,"activeParticlesPerfCounter",{get:function(){return this._activeParticles},enumerable:!0,configurable:!0}),i.prototype.getActiveBones=function(){return this._activeBones.current},Object.defineProperty(i.prototype,"activeBonesPerfCounter",{get:function(){return this._activeBones},enumerable:!0,configurable:!0}),i.prototype.getInterFramePerfCounter=function(){return e.Tools.Warn("getInterFramePerfCounter is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"interFramePerfCounter",{get:function(){return e.Tools.Warn("interFramePerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getLastFrameDuration=function(){return e.Tools.Warn("getLastFrameDuration is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"lastFramePerfCounter",{get:function(){return e.Tools.Warn("lastFramePerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getEvaluateActiveMeshesDuration=function(){return e.Tools.Warn("getEvaluateActiveMeshesDuration is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"evaluateActiveMeshesDurationPerfCounter",{get:function(){return e.Tools.Warn("evaluateActiveMeshesDurationPerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getActiveMeshes=function(){return this._activeMeshes},i.prototype.getRenderTargetsDuration=function(){return e.Tools.Warn("getRenderTargetsDuration is deprecated. Please use SceneInstrumentation class"),0},i.prototype.getRenderDuration=function(){return e.Tools.Warn("getRenderDuration is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"renderDurationPerfCounter",{get:function(){return e.Tools.Warn("renderDurationPerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getParticlesDuration=function(){return e.Tools.Warn("getParticlesDuration is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"particlesDurationPerfCounter",{get:function(){return e.Tools.Warn("particlesDurationPerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getSpritesDuration=function(){return e.Tools.Warn("getSpritesDuration is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"spriteDuractionPerfCounter",{get:function(){return e.Tools.Warn("spriteDuractionPerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getAnimationRatio=function(){return this._animationRatio},i.prototype.getRenderId=function(){return this._renderId},i.prototype.incrementRenderId=function(){this._renderId++},i.prototype._updatePointerPosition=function(e){var t=this._engine.getRenderingCanvasClientRect();t&&(this._pointerX=e.clientX-t.left,this._pointerY=e.clientY-t.top,this._unTranslatedPointerX=this._pointerX,this._unTranslatedPointerY=this._pointerY)},i.prototype._createUbo=function(){this._sceneUbo=new e.UniformBuffer(this._engine,void 0,!0),this._sceneUbo.addUniform("viewProjection",16),this._sceneUbo.addUniform("view",16)},i.prototype._createAlternateUbo=function(){this._alternateSceneUbo=new e.UniformBuffer(this._engine,void 0,!0),this._alternateSceneUbo.addUniform("viewProjection",16),this._alternateSceneUbo.addUniform("view",16)},i.prototype.simulatePointerMove=function(e){var t=new PointerEvent("pointermove");return this._processPointerMove(e,t)},i.prototype._processPointerMove=function(t,i){var r=this._engine.getRenderingCanvas();if(!r)return this;if(t&&t.hit&&t.pickedMesh?(this.setPointerOverSprite(null),this.setPointerOverMesh(t.pickedMesh),this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.hasPointerTriggers?this._pointerOverMesh.actionManager.hoverCursor?r.style.cursor=this._pointerOverMesh.actionManager.hoverCursor:r.style.cursor=this.hoverCursor:r.style.cursor=this.defaultCursor):(this.setPointerOverMesh(null),(t=this.pickSprite(this._unTranslatedPointerX,this._unTranslatedPointerY,this._spritePredicate,!1,this.cameraToUseForPointers||void 0))&&t.hit&&t.pickedSprite?(this.setPointerOverSprite(t.pickedSprite),this._pointerOverSprite&&this._pointerOverSprite.actionManager&&this._pointerOverSprite.actionManager.hoverCursor?r.style.cursor=this._pointerOverSprite.actionManager.hoverCursor:r.style.cursor=this.hoverCursor):(this.setPointerOverSprite(null),r.style.cursor=this.defaultCursor)),t&&(this.onPointerMove&&this.onPointerMove(i,t),this.onPointerObservable.hasObservers())){var n="mousewheel"===i.type||"DOMMouseScroll"===i.type?e.PointerEventTypes.POINTERWHEEL:e.PointerEventTypes.POINTERMOVE,o=new e.PointerInfo(n,i,t);this.onPointerObservable.notifyObservers(o,n)}return this},i.prototype.simulatePointerDown=function(e){var t=new PointerEvent("pointerdown");return this._processPointerDown(e,t)},i.prototype._processPointerDown=function(t,r){var n=this;if(t&&t.hit&&t.pickedMesh){this._pickedDownMesh=t.pickedMesh;var o=t.pickedMesh.actionManager;if(o){if(o.hasPickTriggers)switch(o.processTrigger(e.ActionManager.OnPickDownTrigger,e.ActionEvent.CreateNew(t.pickedMesh,r)),r.button){case 0:o.processTrigger(e.ActionManager.OnLeftPickTrigger,e.ActionEvent.CreateNew(t.pickedMesh,r));break;case 1:o.processTrigger(e.ActionManager.OnCenterPickTrigger,e.ActionEvent.CreateNew(t.pickedMesh,r));break;case 2:o.processTrigger(e.ActionManager.OnRightPickTrigger,e.ActionEvent.CreateNew(t.pickedMesh,r))}o.hasSpecificTrigger(e.ActionManager.OnLongPressTrigger)&&window.setTimeout(function(){var t=n.pick(n._unTranslatedPointerX,n._unTranslatedPointerY,function(t){return t.isPickable&&t.isVisible&&t.isReady()&&t.actionManager&&t.actionManager.hasSpecificTrigger(e.ActionManager.OnLongPressTrigger)&&t==n._pickedDownMesh},!1,n.cameraToUseForPointers);t&&t.hit&&t.pickedMesh&&o&&0!==n._totalPointersPressed&&(new Date).getTime()-n._startingPointerTime>i.LongPressDelay&&Math.abs(n._startingPointerPosition.x-n._pointerX)<i.DragMovementThreshold&&Math.abs(n._startingPointerPosition.y-n._pointerY)<i.DragMovementThreshold&&(n._startingPointerTime=0,o.processTrigger(e.ActionManager.OnLongPressTrigger,e.ActionEvent.CreateNew(t.pickedMesh,r)))},i.LongPressDelay)}}if(t&&(this.onPointerDown&&this.onPointerDown(r,t),this.onPointerObservable.hasObservers())){var s=e.PointerEventTypes.POINTERDOWN,a=new e.PointerInfo(s,r,t);this.onPointerObservable.notifyObservers(a,s)}return this},i.prototype.simulatePointerUp=function(e){var i=new PointerEvent("pointerup"),r=new t;return r.singleClick=!0,this._processPointerUp(e,i,r)},i.prototype._processPointerUp=function(t,i,r){if(t&&t&&t.pickedMesh){if(this._pickedUpMesh=t.pickedMesh,this._pickedDownMesh===this._pickedUpMesh&&(this.onPointerPick&&this.onPointerPick(i,t),r.singleClick&&!r.ignore&&this.onPointerObservable.hasObservers())){var n=e.PointerEventTypes.POINTERPICK,o=new e.PointerInfo(n,i,t);this.onPointerObservable.notifyObservers(o,n)}t.pickedMesh.actionManager&&(r.ignore&&t.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNew(t.pickedMesh,i)),r.hasSwiped||r.ignore||!r.singleClick||t.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickTrigger,e.ActionEvent.CreateNew(t.pickedMesh,i)),r.doubleClick&&!r.ignore&&t.pickedMesh.actionManager.hasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)&&t.pickedMesh.actionManager.processTrigger(e.ActionManager.OnDoublePickTrigger,e.ActionEvent.CreateNew(t.pickedMesh,i)))}if(this._pickedDownMesh&&this._pickedDownMesh.actionManager&&this._pickedDownMesh.actionManager.hasSpecificTrigger(e.ActionManager.OnPickOutTrigger)&&this._pickedDownMesh!==this._pickedUpMesh&&this._pickedDownMesh.actionManager.processTrigger(e.ActionManager.OnPickOutTrigger,e.ActionEvent.CreateNew(this._pickedDownMesh,i)),this.onPointerUp&&this.onPointerUp(i,t),this.onPointerObservable.hasObservers())if(r.ignore){var n=e.PointerEventTypes.POINTERUP,o=new e.PointerInfo(n,i,t);this.onPointerObservable.notifyObservers(o,n)}else if(!r.hasSwiped){if(r.singleClick&&this.onPointerObservable.hasSpecificMask(e.PointerEventTypes.POINTERTAP)){var n=e.PointerEventTypes.POINTERTAP,o=new e.PointerInfo(n,i,t);this.onPointerObservable.notifyObservers(o,n)}if(r.doubleClick&&this.onPointerObservable.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP)){var n=e.PointerEventTypes.POINTERDOUBLETAP,o=new e.PointerInfo(n,i,t);this.onPointerObservable.notifyObservers(o,n)}}return this},i.prototype.attachControl=function(r,n,o){var s=this;void 0===r&&(r=!0),void 0===n&&(n=!0),void 0===o&&(o=!0),this._initActionManager=function(e,t){if(!s._meshPickProceed){var i=s.pick(s._unTranslatedPointerX,s._unTranslatedPointerY,s.pointerDownPredicate,!1,s.cameraToUseForPointers);s._currentPickResult=i,i&&(e=i.hit&&i.pickedMesh?i.pickedMesh.actionManager:null),s._meshPickProceed=!0}return e},this._delayedSimpleClick=function(e,t,r){((new Date).getTime()-s._previousStartingPointerTime>i.DoubleClickDelay&&!s._doubleClickOccured||e!==s._previousButtonPressed)&&(s._doubleClickOccured=!1,t.singleClick=!0,t.ignore=!1,r(t,s._currentPickResult))},this._initClickEvent=function(r,n,o,a){var l=new t;s._currentPickResult=null;var h=null,u=r.hasSpecificMask(e.PointerEventTypes.POINTERPICK)||n.hasSpecificMask(e.PointerEventTypes.POINTERPICK)||r.hasSpecificMask(e.PointerEventTypes.POINTERTAP)||n.hasSpecificMask(e.PointerEventTypes.POINTERTAP)||r.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP)||n.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP);if(!u&&e.ActionManager&&e.ActionManager.HasPickTriggers&&(h=s._initActionManager(h,l))&&(u=h.hasPickTriggers),u){var c=o.button;if(l.hasSwiped=Math.abs(s._startingPointerPosition.x-s._pointerX)>i.DragMovementThreshold||Math.abs(s._startingPointerPosition.y-s._pointerY)>i.DragMovementThreshold,!l.hasSwiped){var f=!i.ExclusiveDoubleClickMode;f||(f=!r.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP)&&!n.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP))&&!e.ActionManager.HasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)&&(h=s._initActionManager(h,l))&&(f=!h.hasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)),f?((new Date).getTime()-s._previousStartingPointerTime>i.DoubleClickDelay||c!==s._previousButtonPressed)&&(l.singleClick=!0,a(l,s._currentPickResult)):(s._previousDelayedSimpleClickTimeout=s._delayedSimpleClickTimeout,s._delayedSimpleClickTimeout=window.setTimeout(s._delayedSimpleClick.bind(s,c,l,a),i.DoubleClickDelay));var p=r.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP)||n.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP);!p&&e.ActionManager.HasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)&&(h=s._initActionManager(h,l))&&(p=h.hasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)),p&&(c===s._previousButtonPressed&&(new Date).getTime()-s._previousStartingPointerTime<i.DoubleClickDelay&&!s._doubleClickOccured?!l.hasSwiped&&Math.abs(s._previousStartingPointerPosition.x-s._startingPointerPosition.x)<i.DragMovementThreshold&&Math.abs(s._previousStartingPointerPosition.y-s._startingPointerPosition.y)<i.DragMovementThreshold?(s._previousStartingPointerTime=0,s._doubleClickOccured=!0,l.doubleClick=!0,l.ignore=!1,i.ExclusiveDoubleClickMode&&s._previousDelayedSimpleClickTimeout&&clearTimeout(s._previousDelayedSimpleClickTimeout),s._previousDelayedSimpleClickTimeout=s._delayedSimpleClickTimeout,a(l,s._currentPickResult)):(s._doubleClickOccured=!1,s._previousStartingPointerTime=s._startingPointerTime,s._previousStartingPointerPosition.x=s._startingPointerPosition.x,s._previousStartingPointerPosition.y=s._startingPointerPosition.y,s._previousButtonPressed=c,s._previousHasSwiped=l.hasSwiped,i.ExclusiveDoubleClickMode?(s._previousDelayedSimpleClickTimeout&&clearTimeout(s._previousDelayedSimpleClickTimeout),s._previousDelayedSimpleClickTimeout=s._delayedSimpleClickTimeout,a(l,s._previousPickResult)):a(l,s._currentPickResult)):(s._doubleClickOccured=!1,s._previousStartingPointerTime=s._startingPointerTime,s._previousStartingPointerPosition.x=s._startingPointerPosition.x,s._previousStartingPointerPosition.y=s._startingPointerPosition.y,s._previousButtonPressed=c,s._previousHasSwiped=l.hasSwiped))}}l.ignore=!0,a(l,s._currentPickResult)},this._spritePredicate=function(e){return e.isPickable&&e.actionManager&&e.actionManager.hasPointerTriggers},this._onPointerMove=function(t){if(s._updatePointerPosition(t),s.onPrePointerObservable.hasObservers()){var i="mousewheel"===t.type||"DOMMouseScroll"===t.type?e.PointerEventTypes.POINTERWHEEL:e.PointerEventTypes.POINTERMOVE,r=new e.PointerInfoPre(i,t,s._unTranslatedPointerX,s._unTranslatedPointerY);if(s.onPrePointerObservable.notifyObservers(r,i),r.skipOnPointerObservable)return}if(s.cameraToUseForPointers||s.activeCamera){s.pointerMovePredicate||(s.pointerMovePredicate=function(e){return e.isPickable&&e.isVisible&&e.isReady()&&e.isEnabled()&&(e.enablePointerMoveEvents||s.constantlyUpdateMeshUnderPointer||null!==e.actionManager&&void 0!==e.actionManager)});var n=s.pick(s._unTranslatedPointerX,s._unTranslatedPointerY,s.pointerMovePredicate,!1,s.cameraToUseForPointers);s._processPointerMove(n,t)}},this._onPointerDown=function(t){if(s._totalPointersPressed++,s._pickedDownMesh=null,s._meshPickProceed=!1,s._updatePointerPosition(t),s.preventDefaultOnPointerDown&&h&&(t.preventDefault(),h.focus()),s.onPrePointerObservable.hasObservers()){var i=e.PointerEventTypes.POINTERDOWN,r=new e.PointerInfoPre(i,t,s._unTranslatedPointerX,s._unTranslatedPointerY);if(s.onPrePointerObservable.notifyObservers(r,i),r.skipOnPointerObservable)return}if(s.cameraToUseForPointers||s.activeCamera){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.isEnabled()}),s._pickedDownMesh=null;var n=s.pick(s._unTranslatedPointerX,s._unTranslatedPointerY,s.pointerDownPredicate,!1,s.cameraToUseForPointers);if(s._processPointerDown(n,t),s._pickedDownSprite=null,s.spriteManagers.length>0&&(n=s.pickSprite(s._unTranslatedPointerX,s._unTranslatedPointerY,s._spritePredicate,!1,s.cameraToUseForPointers||void 0))&&n.hit&&n.pickedSprite&&n.pickedSprite.actionManager){switch(s._pickedDownSprite=n.pickedSprite,t.button){case 0:n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnLeftPickTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t));break;case 1:n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnCenterPickTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t));break;case 2:n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnRightPickTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t))}n.pickedSprite.actionManager&&n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickDownTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t))}}},this._onPointerUp=function(t){0!==s._totalPointersPressed&&(s._totalPointersPressed--,s._pickedUpMesh=null,s._meshPickProceed=!1,s._updatePointerPosition(t),s._initClickEvent(s.onPrePointerObservable,s.onPointerObservable,t,function(r,n){if(s.onPrePointerObservable.hasObservers())if(r.ignore){var o=e.PointerEventTypes.POINTERUP,a=new e.PointerInfoPre(o,t,s._unTranslatedPointerX,s._unTranslatedPointerY);if(s.onPrePointerObservable.notifyObservers(a,o),a.skipOnPointerObservable)return}else if(!r.hasSwiped){if(r.singleClick&&s.onPrePointerObservable.hasSpecificMask(e.PointerEventTypes.POINTERTAP)){var o=e.PointerEventTypes.POINTERTAP,a=new e.PointerInfoPre(o,t,s._unTranslatedPointerX,s._unTranslatedPointerY);if(s.onPrePointerObservable.notifyObservers(a,o),a.skipOnPointerObservable)return}if(r.doubleClick&&s.onPrePointerObservable.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP)){var o=e.PointerEventTypes.POINTERDOUBLETAP,a=new e.PointerInfoPre(o,t,s._unTranslatedPointerX,s._unTranslatedPointerY);if(s.onPrePointerObservable.notifyObservers(a,o),a.skipOnPointerObservable)return}}if(s.cameraToUseForPointers||s.activeCamera){if(s.pointerUpPredicate||(s.pointerUpPredicate=function(e){return e.isPickable&&e.isVisible&&e.isReady()&&e.isEnabled()}),!s._meshPickProceed&&(e.ActionManager&&e.ActionManager.HasTriggers||s.onPointerObservable.hasObservers())&&s._initActionManager(null,r),n||(n=s._currentPickResult),s._processPointerUp(n,t,r),s.spriteManagers.length>0){var l=s.pickSprite(s._unTranslatedPointerX,s._unTranslatedPointerY,s._spritePredicate,!1,s.cameraToUseForPointers||void 0);l&&(l.hit&&l.pickedSprite&&l.pickedSprite.actionManager&&(l.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNewFromSprite(l.pickedSprite,s,t)),l.pickedSprite.actionManager&&Math.abs(s._startingPointerPosition.x-s._pointerX)<i.DragMovementThreshold&&Math.abs(s._startingPointerPosition.y-s._pointerY)<i.DragMovementThreshold&&l.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickTrigger,e.ActionEvent.CreateNewFromSprite(l.pickedSprite,s,t))),s._pickedDownSprite&&s._pickedDownSprite.actionManager&&s._pickedDownSprite!==l.pickedSprite&&s._pickedDownSprite.actionManager.processTrigger(e.ActionManager.OnPickOutTrigger,e.ActionEvent.CreateNewFromSprite(s._pickedDownSprite,s,t)))}s._previousPickResult=s._currentPickResult}}))},this._onKeyDown=function(t){var i=e.KeyboardEventTypes.KEYDOWN;if(s.onPreKeyboardObservable.hasObservers()){r=new e.KeyboardInfoPre(i,t);if(s.onPreKeyboardObservable.notifyObservers(r,i),r.skipOnPointerObservable)return}if(s.onKeyboardObservable.hasObservers()){var r=new e.KeyboardInfo(i,t);s.onKeyboardObservable.notifyObservers(r,i)}s.actionManager&&s.actionManager.processTrigger(e.ActionManager.OnKeyDownTrigger,e.ActionEvent.CreateNewFromScene(s,t))},this._onKeyUp=function(t){var i=e.KeyboardEventTypes.KEYUP;if(s.onPreKeyboardObservable.hasObservers()){r=new e.KeyboardInfoPre(i,t);if(s.onPreKeyboardObservable.notifyObservers(r,i),r.skipOnPointerObservable)return}if(s.onKeyboardObservable.hasObservers()){var r=new e.KeyboardInfo(i,t);s.onKeyboardObservable.notifyObservers(r,i)}s.actionManager&&s.actionManager.processTrigger(e.ActionManager.OnKeyUpTrigger,e.ActionEvent.CreateNewFromScene(s,t))};var a=this.getEngine();this._onCanvasFocusObserver=a.onCanvasFocusObservable.add(function(){h&&(h.addEventListener("keydown",s._onKeyDown,!1),h.addEventListener("keyup",s._onKeyUp,!1))}),this._onCanvasBlurObserver=a.onCanvasBlurObservable.add(function(){h&&(h.removeEventListener("keydown",s._onKeyDown),h.removeEventListener("keyup",s._onKeyUp))});var l=e.Tools.GetPointerPrefix(),h=this._engine.getRenderingCanvas();h&&(o&&(h.addEventListener(l+"move",this._onPointerMove,!1),h.addEventListener("mousewheel",this._onPointerMove,!1),h.addEventListener("DOMMouseScroll",this._onPointerMove,!1)),n&&h.addEventListener(l+"down",this._onPointerDown,!1),r&&window.addEventListener(l+"up",this._onPointerUp,!1),h.tabIndex=1)},i.prototype.detachControl=function(){var t=this.getEngine(),i=e.Tools.GetPointerPrefix(),r=t.getRenderingCanvas();r&&(r.removeEventListener(i+"move",this._onPointerMove),r.removeEventListener(i+"down",this._onPointerDown),window.removeEventListener(i+"up",this._onPointerUp),this._onCanvasBlurObserver&&t.onCanvasBlurObservable.remove(this._onCanvasBlurObserver),this._onCanvasFocusObserver&&t.onCanvasFocusObservable.remove(this._onCanvasFocusObserver),r.removeEventListener("mousewheel",this._onPointerMove),r.removeEventListener("DOMMouseScroll",this._onPointerMove),r.removeEventListener("keydown",this._onKeyDown),r.removeEventListener("keyup",this._onKeyUp),this.onKeyboardObservable.clear(),this.onPreKeyboardObservable.clear(),this.onPointerObservable.clear(),this.onPrePointerObservable.clear())},i.prototype.isReady=function(){if(this._isDisposed)return!1;if(this._pendingData.length>0)return!1;var t;for(t=0;t<this._geometries.length;t++)if(this._geometries[t].delayLoadState===e.Engine.DELAYLOADSTATE_LOADING)return!1;for(t=0;t<this.meshes.length;t++){var i=this.meshes[t];if(i.isEnabled()&&(i.subMeshes&&0!==i.subMeshes.length)){if(!i.isReady())return!1;var r=i.material;if(r&&!r.isReady(i))return!1}}return!0},i.prototype.resetCachedMaterial=function(){this._cachedMaterial=null,this._cachedEffect=null,this._cachedVisibility=null},i.prototype.registerBeforeRender=function(e){this.onBeforeRenderObservable.add(e)},i.prototype.unregisterBeforeRender=function(e){this.onBeforeRenderObservable.removeCallback(e)},i.prototype.registerAfterRender=function(e){this.onAfterRenderObservable.add(e)},i.prototype.unregisterAfterRender=function(e){this.onAfterRenderObservable.removeCallback(e)},i.prototype._addPendingData=function(e){this._pendingData.push(e)},i.prototype._removePendingData=function(e){var t=this.isLoading,i=this._pendingData.indexOf(e);-1!==i&&this._pendingData.splice(i,1),t&&!this.isLoading&&this.onDataLoadedObservable.notifyObservers(this)},i.prototype.getWaitingItemsCount=function(){return this._pendingData.length},Object.defineProperty(i.prototype,"isLoading",{get:function(){return this._pendingData.length>0},enumerable:!0,configurable:!0}),i.prototype.executeWhenReady=function(e){var t=this;this.onReadyObservable.add(e),-1===this._executeWhenReadyTimeoutId&&(this._executeWhenReadyTimeoutId=setTimeout(function(){t._checkIsReady()},150))},i.prototype._checkIsReady=function(){var e=this;if(this.isReady())return this.onReadyObservable.notifyObservers(this),this.onReadyObservable.clear(),void(this._executeWhenReadyTimeoutId=-1);this._executeWhenReadyTimeoutId=setTimeout(function(){e._checkIsReady()},150)},i.prototype.beginAnimation=function(t,i,r,n,o,s,a){if(void 0===o&&(o=1),i>r&&o>0&&(o*=-1),this.stopAnimation(t),a||(a=new e.Animatable(this,t,i,r,n,o,s)),t.animations&&a.appendAnimations(t,t.animations),t.getAnimatables)for(var l=t.getAnimatables(),h=0;h<l.length;h++)this.beginAnimation(l[h],i,r,n,o,s,a);return a.reset(),a},i.prototype.beginDirectAnimation=function(t,i,r,n,o,s,a){return void 0===s&&(s=1),new e.Animatable(this,t,r,n,o,s,a,i)},i.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(i.prototype,"Animatables",{get:function(){return this._activeAnimatables},enumerable:!0,configurable:!0}),i.prototype.stopAnimation=function(e,t){var i=this.getAnimatableByTarget(e);i&&i.stop(t)},i.prototype.stopAllAnimations=function(){if(this._activeAnimatables){for(var e=0;e<this._activeAnimatables.length;e++)this._activeAnimatables[e].stop();this._activeAnimatables=[]}},i.prototype._animate=function(){if(this.animationsEnabled&&0!==this._activeAnimatables.length){var t=e.Tools.Now;if(!this._animationTimeLast){if(this._pendingData.length>0)return;this._animationTimeLast=t}var i=(t-this._animationTimeLast)*this.animationTimeScale;this._animationTime+=i,this._animationTimeLast=t;for(var r=0;r<this._activeAnimatables.length;r++)this._activeAnimatables[r]._animate(this._animationTime)}},i.prototype._switchToAlternateCameraConfiguration=function(e){this._useAlternateCameraConfiguration=e},i.prototype.getViewMatrix=function(){return this._useAlternateCameraConfiguration?this._alternateViewMatrix:this._viewMatrix},i.prototype.getProjectionMatrix=function(){return this._useAlternateCameraConfiguration?this._alternateProjectionMatrix:this._projectionMatrix},i.prototype.getTransformMatrix=function(){return this._useAlternateCameraConfiguration?this._alternateTransformMatrix:this._transformMatrix},i.prototype.setTransformMatrix=function(t,i){if(this._viewUpdateFlag!==t.updateFlag||this._projectionUpdateFlag!==i.updateFlag){if(this._viewUpdateFlag=t.updateFlag,this._projectionUpdateFlag=i.updateFlag,this._viewMatrix=t,this._projectionMatrix=i,this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix),this._frustumPlanes?e.Frustum.GetPlanesToRef(this._transformMatrix,this._frustumPlanes):this._frustumPlanes=e.Frustum.GetPlanes(this._transformMatrix),this.activeCamera&&this.activeCamera._alternateCamera){var r=this.activeCamera._alternateCamera;r.getViewMatrix().multiplyToRef(r.getProjectionMatrix(),e.Tmp.Matrix[0]),e.Frustum.GetRightPlaneToRef(e.Tmp.Matrix[0],this._frustumPlanes[3])}this._sceneUbo.useUbo&&(this._sceneUbo.updateMatrix("viewProjection",this._transformMatrix),this._sceneUbo.updateMatrix("view",this._viewMatrix),this._sceneUbo.update())}},i.prototype._setAlternateTransformMatrix=function(t,i){this._alternateViewUpdateFlag===t.updateFlag&&this._alternateProjectionUpdateFlag===i.updateFlag||(this._alternateViewUpdateFlag=t.updateFlag,this._alternateProjectionUpdateFlag=i.updateFlag,this._alternateViewMatrix=t,this._alternateProjectionMatrix=i,this._alternateTransformMatrix||(this._alternateTransformMatrix=e.Matrix.Zero()),this._alternateViewMatrix.multiplyToRef(this._alternateProjectionMatrix,this._alternateTransformMatrix),this._alternateSceneUbo||this._createAlternateUbo(),this._alternateSceneUbo.useUbo&&(this._alternateSceneUbo.updateMatrix("viewProjection",this._alternateTransformMatrix),this._alternateSceneUbo.updateMatrix("view",this._alternateViewMatrix),this._alternateSceneUbo.update()))},i.prototype.getSceneUniformBuffer=function(){return this._useAlternateCameraConfiguration?this._alternateSceneUbo:this._sceneUbo},i.prototype.getUniqueId=function(){var e=i._uniqueIdCounter;return i._uniqueIdCounter++,e},i.prototype.addMesh=function(e){this.meshes.push(e),this.collisionCoordinator&&this.collisionCoordinator.onMeshAdded(e),this.onNewMeshAddedObservable.notifyObservers(e)},i.prototype.removeMesh=function(e){var t=this.meshes.indexOf(e);return-1!==t&&this.meshes.splice(t,1),this.onMeshRemovedObservable.notifyObservers(e),t},i.prototype.addTransformNode=function(e){this.transformNodes.push(e),this.onNewTransformNodeAddedObservable.notifyObservers(e)},i.prototype.removeTransformNode=function(e){var t=this.transformNodes.indexOf(e);return-1!==t&&this.transformNodes.splice(t,1),this.onTransformNodeRemovedObservable.notifyObservers(e),t},i.prototype.removeSkeleton=function(e){var t=this.skeletons.indexOf(e);return-1!==t&&this.skeletons.splice(t,1),t},i.prototype.removeMorphTargetManager=function(e){var t=this.morphTargetManagers.indexOf(e);return-1!==t&&this.morphTargetManagers.splice(t,1),t},i.prototype.removeLight=function(e){var t=this.lights.indexOf(e);return-1!==t&&(this.lights.splice(t,1),this.sortLightsByPriority()),this.onLightRemovedObservable.notifyObservers(e),t},i.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},i.prototype.addLight=function(e){this.lights.push(e),this.sortLightsByPriority(),this.onNewLightAddedObservable.notifyObservers(e)},i.prototype.sortLightsByPriority=function(){this.requireLightSorting&&this.lights.sort(e.Light.compareLightsPriority)},i.prototype.addCamera=function(e){this.cameras.push(e),this.onNewCameraAddedObservable.notifyObservers(e)},i.prototype.switchActiveCamera=function(e,t){void 0===t&&(t=!0);var i=this._engine.getRenderingCanvas();i&&(this.activeCamera&&this.activeCamera.detachControl(i),this.activeCamera=e,t&&e.attachControl(i))},i.prototype.setActiveCameraByID=function(e){var t=this.getCameraByID(e);return t?(this.activeCamera=t,t):null},i.prototype.setActiveCameraByName=function(e){var t=this.getCameraByName(e);return t?(this.activeCamera=t,t):null},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.prototype.getBoneByID=function(e){for(var t=0;t<this.skeletons.length;t++)for(var i=this.skeletons[t],r=0;r<i.bones.length;r++)if(i.bones[r].id===e)return i.bones[r];return null},i.prototype.getBoneByName=function(e){for(var t=0;t<this.skeletons.length;t++)for(var i=this.skeletons[t],r=0;r<i.bones.length;r++)if(i.bones[r].name===e)return i.bones[r];return null},i.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},i.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},i.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},i.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},i.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},i.prototype.pushGeometry=function(e,t){return!(!t&&this.getGeometryByID(e.id))&&(this._geometries.push(e),this.collisionCoordinator&&this.collisionCoordinator.onGeometryAdded(e),this.onNewGeometryAddedObservable.notifyObservers(e),!0)},i.prototype.removeGeometry=function(e){var t=this._geometries.indexOf(e);return t>-1&&(this._geometries.splice(t,1),this.collisionCoordinator&&this.collisionCoordinator.onGeometryDeleted(e),this.onGeometryRemovedObservable.notifyObservers(e),!0)},i.prototype.getGeometries=function(){return this._geometries},i.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},i.prototype.getMeshesByID=function(e){return this.meshes.filter(function(t){return t.id===e})},i.prototype.getTransformNodeByID=function(e){for(var t=0;t<this.transformNodes.length;t++)if(this.transformNodes[t].id===e)return this.transformNodes[t];return null},i.prototype.getTransformNodesByID=function(e){return this.transformNodes.filter(function(t){return t.id===e})},i.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},i.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},i.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.transformNodes.length-1;t>=0;t--)if(this.transformNodes[t].id===e)return this.transformNodes[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},i.prototype.getNodeByID=function(e){var t=this.getMeshByID(e);if(t)return t;var i=this.getLightByID(e);if(i)return i;var r=this.getCameraByID(e);return r||this.getBoneByID(e)},i.prototype.getNodeByName=function(e){var t=this.getMeshByName(e);if(t)return t;var i=this.getLightByName(e);if(i)return i;var r=this.getCameraByName(e);return r||this.getBoneByName(e)},i.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},i.prototype.getTransformNodeByName=function(e){for(var t=0;t<this.transformNodes.length;t++)if(this.transformNodes[t].name===e)return this.transformNodes[t];return null},i.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 r=0;r<this.soundTracks.length;r++)for(i=0;i<this.soundTracks[r].soundCollection.length;i++)if(this.soundTracks[r].soundCollection[i].name===t)return this.soundTracks[r].soundCollection[i]}return null},i.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},i.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},i.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},i.prototype.getMorphTargetManagerById=function(e){for(var t=0;t<this.morphTargetManagers.length;t++)if(this.morphTargetManagers[t].uniqueId===e)return this.morphTargetManagers[t];return null},i.prototype.isActiveMesh=function(e){return-1!==this._activeMeshes.indexOf(e)},i.prototype.getHighlightLayerByName=function(e){for(var t=0;t<this.highlightLayers.length;t++)if(this.highlightLayers[t].name===e)return this.highlightLayers[t];return null},Object.defineProperty(i.prototype,"uid",{get:function(){return this._uid||(this._uid=e.Tools.RandomId()),this._uid},enumerable:!0,configurable:!0}),i.prototype.addExternalData=function(t,i){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.add(t,i)},i.prototype.getExternalData=function(e){return this._externalData?this._externalData.get(e):null},i.prototype.getOrAddExternalDataWithFactory=function(t,i){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.getOrAddWithFactory(t,i)},i.prototype.removeExternalData=function(e){return this._externalData.remove(e)},i.prototype._evaluateSubMesh=function(e,t){if(t.alwaysSelectAsActiveMesh||1===t.subMeshes.length||e.isInFrustum(this._frustumPlanes)){var i=e.getMaterial();if(t.showSubMeshesBoundingBox){var r=e.getBoundingInfo();r&&this.getBoundingBoxRenderer().renderList.push(r.boundingBox)}i&&(i.getRenderTargetTextures&&-1===this._processedMaterials.indexOf(i)&&(this._processedMaterials.push(i),this._renderTargets.concatWithNoDuplicate(i.getRenderTargetTextures())),this._activeIndices.addCount(e.indexCount,!1),this._renderingManager.dispatch(e))}},i.prototype._isInIntermediateRendering=function(){return this._intermediateRendering},i.prototype.freezeActiveMeshes=function(){return this._evaluateActiveMeshes(),this._activeMeshesFrozen=!0,this},i.prototype.unfreezeActiveMeshes=function(){return this._activeMeshesFrozen=!1,this},i.prototype._evaluateActiveMeshes=function(){if((!this._activeMeshesFrozen||!this._activeMeshes.length)&&this.activeCamera){this.onBeforeActiveMeshesEvaluationObservable.notifyObservers(this),this.activeCamera._activeMeshes.reset(),this._activeMeshes.reset(),this._renderingManager.reset(),this._processedMaterials.reset(),this._activeParticleSystems.reset(),this._activeSkeletons.reset(),this._softwareSkinnedMeshes.reset(),this._boundingBoxRenderer&&this._boundingBoxRenderer.reset();var t,i;if(this._selectionOctree){var r=this._selectionOctree.select(this._frustumPlanes);t=r.data,i=r.length}else i=this.meshes.length,t=this.meshes;for(var n=0;n<i;n++){var o=t[n];if(!o.isBlocked&&(this._totalVertices.addCount(o.getTotalVertices(),!1),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),s!==o&&s._activate(this._renderId),this._activeMesh(o,s)))}}if(this.onAfterActiveMeshesEvaluationObservable.notifyObservers(this),this.particlesEnabled){this.onBeforeParticlesRenderingObservable.notifyObservers(this);for(var a=0;a<this.particleSystems.length;a++){var l=this.particleSystems[a];if(l.isStarted()&&l.emitter){var h=l.emitter;h.position&&!h.isEnabled()||(this._activeParticleSystems.push(l),l.animate(),this._renderingManager.dispatchParticles(l))}}this.onAfterParticlesRenderingObservable.notifyObservers(this)}}},i.prototype._activeMesh=function(e,t){if(t.skeleton&&this.skeletonsEnabled&&(this._activeSkeletons.pushNoDuplicate(t.skeleton)&&t.skeleton.prepare(),t.computeBonesUsingShaders||this._softwareSkinnedMeshes.pushNoDuplicate(t)),e.showBoundingBox||this.forceShowBoundingBoxes){var i=e.getBoundingInfo();i&&this.getBoundingBoxRenderer().renderList.push(i.boundingBox)}if(t&&t.subMeshes){var r,n;if(t._submeshesOctree&&t.useOctreeForRenderingSelection){var o=t._submeshesOctree.select(this._frustumPlanes);r=o.length,n=o.data}else r=(n=t.subMeshes).length;for(var s=0;s<r;s++){var a=n[s];this._evaluateSubMesh(a,t)}}},i.prototype.updateTransformMatrix=function(e){this.activeCamera&&this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(e))},i.prototype.updateAlternateTransformMatrix=function(e){this._setAlternateTransformMatrix(e.getViewMatrix(),e.getProjectionMatrix())},i.prototype._renderForCamera=function(t){if(!t||!t._skipRendering){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.activeCamera.update(),this.updateTransformMatrix(),t._alternateCamera&&(this.updateAlternateTransformMatrix(t._alternateCamera),this._alternateRendering=!0),this.onBeforeCameraRenderObservable.notifyObservers(this.activeCamera),this._evaluateActiveMeshes();for(var r=0;r<this._softwareSkinnedMeshes.length;r++){var n=this._softwareSkinnedMeshes.data[r];n.applySkeleton(n.skeleton)}this.OnBeforeRenderTargetsRenderObservable.notifyObservers(this);var o=!1;if(t.customRenderTargets&&t.customRenderTargets.length>0&&this._renderTargets.concatWithNoDuplicate(t.customRenderTargets),this.renderTargetsEnabled&&this._renderTargets.length>0){this._intermediateRendering=!0,e.Tools.StartPerformanceCounter("Render targets",this._renderTargets.length>0);for(var s=0;s<this._renderTargets.length;s++)if((c=this._renderTargets.data[s])._shouldRender()){this._renderId++;var a=c.activeCamera&&c.activeCamera!==this.activeCamera;c.render(a,this.dumpNextRenderTargets)}e.Tools.EndPerformanceCounter("Render targets",this._renderTargets.length>0),this._intermediateRendering=!1,this._renderId++,o=!0}var l=this._engine.getStencilBuffer(),h=!1;if(this.renderTargetsEnabled&&this.highlightLayers&&this.highlightLayers.length>0){this._intermediateRendering=!0;for(g=0;g<this.highlightLayers.length;g++){var u=this.highlightLayers[g];if(u.shouldRender()&&(!u.camera||u.camera.cameraRigMode===e.Camera.RIG_MODE_NONE&&t===u.camera||u.camera.cameraRigMode!==e.Camera.RIG_MODE_NONE&&u.camera._rigCameras.indexOf(t)>-1)){h=!0;var c=u._mainTexture;c._shouldRender()&&(this._renderId++,c.render(!1,!1),o=!0)}}this._intermediateRendering=!1,this._renderId++}o&&i.restoreDefaultFramebuffer(),this.OnAfterRenderTargetsRenderObservable.notifyObservers(this),this.postProcessManager._prepareFrame();var f,p;if(this.layers.length){for(i.setDepthBuffer(!1),f=0;f<this.layers.length;f++)(p=this.layers[f]).isBackground&&0!=(p.layerMask&this.activeCamera.layerMask)&&p.render();i.setDepthBuffer(!0)}if(h&&this._engine.setStencilBuffer(!0),this.onBeforeDrawPhaseObservable.notifyObservers(this),this._renderingManager.render(null,null,!0,!0),this.onAfterDrawPhaseObservable.notifyObservers(this),h&&this._engine.setStencilBuffer(l),this._boundingBoxRenderer&&this._boundingBoxRenderer.render(),this.lensFlaresEnabled){e.Tools.StartPerformanceCounter("Lens flares",this.lensFlareSystems.length>0);for(var d=0;d<this.lensFlareSystems.length;d++){var m=this.lensFlareSystems[d];0!=(t.layerMask&m.layerMask)&&m.render()}e.Tools.EndPerformanceCounter("Lens flares",this.lensFlareSystems.length>0)}if(this.layers.length){for(i.setDepthBuffer(!1),f=0;f<this.layers.length;f++)(p=this.layers[f]).isBackground||0==(p.layerMask&this.activeCamera.layerMask)||p.render();i.setDepthBuffer(!0)}if(h){i.setDepthBuffer(!1);for(var g=0;g<this.highlightLayers.length;g++)this.highlightLayers[g].shouldRender()&&this.highlightLayers[g].render();i.setDepthBuffer(!0)}this.postProcessManager._finalizeFrame(t.isIntermediate),this._renderTargets.reset(),this._alternateRendering=!1,this.onAfterCameraRenderObservable.notifyObservers(this.activeCamera),e.Tools.EndPerformanceCounter("Rendering camera "+this.activeCamera.name)}},i.prototype._processSubCameras=function(t){if(t.cameraRigMode!==e.Camera.RIG_MODE_NONE){this.activeCamera&&this.activeCamera.update();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())}else this._renderForCamera(t)},i.prototype._checkIntersections=function(){for(var t=0;t<this._meshesForIntersections.length;t++){var i=this._meshesForIntersections.data[t];if(i.actionManager)for(var r=0;r<i.actionManager.actions.length;r++){var n=i.actionManager.actions[r];if(n.trigger===e.ActionManager.OnIntersectionEnterTrigger||n.trigger===e.ActionManager.OnIntersectionExitTrigger){var o=n.getTriggerParameter(),s=o instanceof e.AbstractMesh?o:o.mesh,a=s.intersectsMesh(i,o.usePreciseIntersection),l=i._intersectionsInProgress.indexOf(s);a&&-1===l?n.trigger===e.ActionManager.OnIntersectionEnterTrigger?(n._executeCurrent(e.ActionEvent.CreateNew(i,void 0,s)),i._intersectionsInProgress.push(s)):n.trigger===e.ActionManager.OnIntersectionExitTrigger&&i._intersectionsInProgress.push(s):!a&&l>-1&&(n.trigger===e.ActionManager.OnIntersectionExitTrigger&&n._executeCurrent(e.ActionEvent.CreateNew(i,void 0,s)),i.actionManager.hasSpecificTrigger(e.ActionManager.OnIntersectionExitTrigger)&&n.trigger!==e.ActionManager.OnIntersectionExitTrigger||i._intersectionsInProgress.splice(l,1))}}}},i.prototype.render=function(){if(!this.isDisposed){if(this._activeParticles.fetchNewFrame(),this._totalVertices.fetchNewFrame(),this._activeIndices.fetchNewFrame(),this._activeBones.fetchNewFrame(),this._meshesForIntersections.reset(),this.resetCachedMaterial(),this.onBeforeAnimationsObservable.notifyObservers(this),this.actionManager&&this.actionManager.processTrigger(e.ActionManager.OnEveryFrameTrigger),this.simplificationQueue&&!this.simplificationQueue.running&&this.simplificationQueue.executeNext(),this._engine.isDeterministicLockStep()){var t=Math.max(i.MinDeltaTime,Math.min(this._engine.getDeltaTime(),i.MaxDeltaTime))/1e3,r=.06;this._physicsEngine&&(r=this._physicsEngine.getTimeStep());var n=this._engine.getLockstepMaxSteps();this._timeAccumulator+=t;var o=Math.floor(this._timeAccumulator/r);for(o=Math.min(o,n),this._currentInternalStep=0;this._currentInternalStep<o;this._currentInternalStep++)this.onBeforeStepObservable.notifyObservers(this),this._animationRatio=.06*r,this._animate(),this.onAfterAnimationsObservable.notifyObservers(this),this._physicsEngine&&(this.onBeforePhysicsObservable.notifyObservers(this),this._physicsEngine._step(r),this.onAfterPhysicsObservable.notifyObservers(this)),this._timeAccumulator-=r,this.onAfterStepObservable.notifyObservers(this),this._currentStepId++,o>1&&this._currentInternalStep!=o-1&&this._evaluateActiveMeshes()}else{t=Math.max(i.MinDeltaTime,Math.min(this._engine.getDeltaTime(),i.MaxDeltaTime));this._animationRatio=.06*t,this._animate(),this.onAfterAnimationsObservable.notifyObservers(this),this._physicsEngine&&(this.onBeforePhysicsObservable.notifyObservers(this),this._physicsEngine._step(t/1e3),this.onAfterPhysicsObservable.notifyObservers(this))}this.onBeforeRenderObservable.notifyObservers(this),this.OnBeforeRenderTargetsRenderObservable.notifyObservers(this);var s=this.getEngine(),a=this.activeCamera;if(this.renderTargetsEnabled){e.Tools.StartPerformanceCounter("Custom render targets",this.customRenderTargets.length>0),this._intermediateRendering=!0;for(var l=0;l<this.customRenderTargets.length;l++){var h=this.customRenderTargets[l];if(h._shouldRender()){if(this._renderId++,this.activeCamera=h.activeCamera||this.activeCamera,!this.activeCamera)throw new Error("Active camera not set");s.setViewport(this.activeCamera.viewport),this.updateTransformMatrix(),h.render(a!==this.activeCamera,this.dumpNextRenderTargets)}}e.Tools.EndPerformanceCounter("Custom render targets",this.customRenderTargets.length>0),this._intermediateRendering=!1,this._renderId++}if(this.customRenderTargets.length>0&&s.restoreDefaultFramebuffer(),this.OnAfterRenderTargetsRenderObservable.notifyObservers(this),this.activeCamera=a,this.proceduralTexturesEnabled){e.Tools.StartPerformanceCounter("Procedural textures",this._proceduralTextures.length>0);for(var u=0;u<this._proceduralTextures.length;u++){var c=this._proceduralTextures[u];c._shouldRender()&&c.render()}e.Tools.EndPerformanceCounter("Procedural textures",this._proceduralTextures.length>0)}if((this.autoClearDepthAndStencil||this.autoClear)&&this._engine.clear(this.clearColor,this.autoClear||this.forceWireframe||this.forcePointsCloud,this.autoClearDepthAndStencil,this.autoClearDepthAndStencil),this.shadowsEnabled)for(var f=0;f<this.lights.length;f++){var p=this.lights[f],d=p.getShadowGenerator();if(p.isEnabled()&&p.shadowEnabled&&d){var m=d.getShadowMap();-1!==this.textures.indexOf(m)&&this._renderTargets.push(m)}}if(this._depthRenderer&&this._renderTargets.push(this._depthRenderer.getDepthMap()),this._geometryBufferRenderer&&this._renderTargets.push(this._geometryBufferRenderer.getGBuffer()),this._postProcessRenderPipelineManager&&this._postProcessRenderPipelineManager.update(),this.activeCameras.length>0)for(var g=0;g<this.activeCameras.length;g++)g>0&&this._engine.clear(null,!1,!0,!0),this._processSubCameras(this.activeCameras[g]);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 v=0;v<this._toBeDisposed.length;v++){var _=this._toBeDisposed.data[v];_&&_.dispose(),this._toBeDisposed[v]=null}this._toBeDisposed.reset(),this.dumpNextRenderTargets&&(this.dumpNextRenderTargets=!1),this._activeBones.addCount(0,!0),this._activeIndices.addCount(0,!0),this._activeParticles.addCount(0,!0)}},i.prototype._updateAudioParameters=function(){if(this.audioEnabled&&this._mainSoundTrack&&(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)&&i.canUseWebAudio&&i.audioContext){i.audioContext.listener.setPosition(t.position.x,t.position.y,t.position.z),t.rigCameras&&t.rigCameras.length>0&&(t=t.rigCameras[0]);var r=e.Matrix.Invert(t.getViewMatrix()),n=e.Vector3.TransformNormal(new e.Vector3(0,0,-1),r);n.normalize(),isNaN(n.x)||isNaN(n.y)||isNaN(n.z)||i.audioContext.listener.setOrientation(n.x,n.y,n.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]).useCustomAttenuation&&s.updateDistanceFromListener()}}},Object.defineProperty(i.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}),i.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()},i.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(i.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}),i.prototype._switchAudioModeForHeadphones=function(){this.mainSoundTrack.switchPanningModelToHRTF();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].switchPanningModelToHRTF()},i.prototype._switchAudioModeForNormalSpeakers=function(){this.mainSoundTrack.switchPanningModelToEqualPower();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].switchPanningModelToEqualPower()},i.prototype.enableDepthRenderer=function(){return this._depthRenderer?this._depthRenderer:(this._depthRenderer=new e.DepthRenderer(this),this._depthRenderer)},i.prototype.disableDepthRenderer=function(){this._depthRenderer&&(this._depthRenderer.dispose(),this._depthRenderer=null)},i.prototype.enableGeometryBufferRenderer=function(t){return void 0===t&&(t=1),this._geometryBufferRenderer?this._geometryBufferRenderer:(this._geometryBufferRenderer=new e.GeometryBufferRenderer(this,t),this._geometryBufferRenderer.isSupported||(this._geometryBufferRenderer=null),this._geometryBufferRenderer)},i.prototype.disableGeometryBufferRenderer=function(){this._geometryBufferRenderer&&(this._geometryBufferRenderer.dispose(),this._geometryBufferRenderer=null)},i.prototype.freezeMaterials=function(){for(var e=0;e<this.materials.length;e++)this.materials[e].freeze()},i.prototype.unfreezeMaterials=function(){for(var e=0;e<this.materials.length;e++)this.materials[e].unfreeze()},i.prototype.dispose=function(){this.beforeRender=null,this.afterRender=null,this.skeletons=[],this.morphTargetManagers=[],this.importedMeshesFiles=new Array,this.stopAllAnimations(),this.resetCachedMaterial(),this._depthRenderer&&this._depthRenderer.dispose(),this._gamepadManager&&(this._gamepadManager.dispose(),this._gamepadManager=null),this.activeCamera&&(this.activeCamera._activeMeshes.dispose(),this.activeCamera=null),this._activeMeshes.dispose(),this._renderingManager.dispose(),this._processedMaterials.dispose(),this._activeParticleSystems.dispose(),this._activeSkeletons.dispose(),this._softwareSkinnedMeshes.dispose(),this._renderTargets.dispose(),this._boundingBoxRenderer&&this._boundingBoxRenderer.dispose(),this._meshesForIntersections.dispose(),this._toBeDisposed.dispose(),this._debugLayer&&this._debugLayer.hide(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this.onBeforeRenderObservable.clear(),this.onAfterRenderObservable.clear(),this.OnBeforeRenderTargetsRenderObservable.clear(),this.OnAfterRenderTargetsRenderObservable.clear(),this.onAfterStepObservable.clear(),this.onBeforeStepObservable.clear(),this.onBeforeActiveMeshesEvaluationObservable.clear(),this.onAfterActiveMeshesEvaluationObservable.clear(),this.onBeforeParticlesRenderingObservable.clear(),this.onAfterParticlesRenderingObservable.clear(),this.onBeforeSpritesRenderingObservable.clear(),this.onAfterSpritesRenderingObservable.clear(),this.onBeforeDrawPhaseObservable.clear(),this.onAfterDrawPhaseObservable.clear(),this.onBeforePhysicsObservable.clear(),this.onAfterPhysicsObservable.clear(),this.onBeforeAnimationsObservable.clear(),this.onAfterAnimationsObservable.clear(),this.onDataLoadedObservable.clear(),this.detachControl(),e.AudioEngine&&this.disposeSounds(),this.VRHelper&&this.VRHelper.dispose();var t=this._engine.getRenderingCanvas();if(t){var i;for(i=0;i<this.cameras.length;i++)this.cameras[i].detachControl(t)}for(;this.lights.length;)this.lights[0].dispose();for(;this.meshes.length;)this.meshes[0].dispose(!0);for(;this.transformNodes.length;)this.removeTransformNode(this.transformNodes[0]);for(;this.cameras.length;)this.cameras[0].dispose();for(this.defaultMaterial&&this.defaultMaterial.dispose();this.multiMaterials.length;)this.multiMaterials[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.postProcesses.length;)this.postProcesses[0].dispose();for(;this.layers.length;)this.layers[0].dispose();for(;this.highlightLayers.length;)this.highlightLayers[0].dispose();for(;this.textures.length;)this.textures[0].dispose();this._sceneUbo.dispose(),this._alternateSceneUbo&&this._alternateSceneUbo.dispose(),this.postProcessManager.dispose(),this._postProcessRenderPipelineManager&&this._postProcessRenderPipelineManager.dispose(),this._physicsEngine&&this.disablePhysicsEngine(),(i=this._engine.scenes.indexOf(this))>-1&&this._engine.scenes.splice(i,1),this._engine.wipeCaches(),this._isDisposed=!0},Object.defineProperty(i.prototype,"isDisposed",{get:function(){return this._isDisposed},enumerable:!0,configurable:!0}),i.prototype.disposeSounds=function(){if(this._mainSoundTrack){this.mainSoundTrack.dispose();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].dispose()}},i.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),r=0;r<this.meshes.length;r++){var n=this.meshes[r];if(n.subMeshes&&0!==n.subMeshes.length&&!n.infiniteDistance){n.computeWorldMatrix(!0);var o=n.getBoundingInfo();if(o){var s=o.boundingBox.minimumWorld,a=o.boundingBox.maximumWorld;e.Tools.CheckExtends(s,t,i),e.Tools.CheckExtends(a,t,i)}}}return{min:t,max:i}},i.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 r=this.getWorldExtends();return this._selectionOctree.update(r.min,r.max,this.meshes),this._selectionOctree},i.prototype.createPickingRay=function(t,i,r,n,o){void 0===o&&(o=!1);var s=this._engine;if(!n){if(!this.activeCamera)throw new Error("Active camera not set");n=this.activeCamera}var a=n.viewport.toGlobal(s.getRenderWidth(),s.getRenderHeight());return t=t/this._engine.getHardwareScalingLevel()-a.x,i=i/this._engine.getHardwareScalingLevel()-(this._engine.getRenderHeight()-a.y-a.height),e.Ray.CreateNew(t,i,a.width,a.height,r||e.Matrix.Identity(),o?e.Matrix.Identity():n.getViewMatrix(),n.getProjectionMatrix())},i.prototype.createPickingRayInCameraSpace=function(t,i,r){if(!e.PickingInfo)return null;var n=this._engine;if(!r){if(!this.activeCamera)throw new Error("Active camera not set");r=this.activeCamera}var o=r.viewport.toGlobal(n.getRenderWidth(),n.getRenderHeight()),s=e.Matrix.Identity();return t=t/this._engine.getHardwareScalingLevel()-o.x,i=i/this._engine.getHardwareScalingLevel()-(this._engine.getRenderHeight()-o.y-o.height),e.Ray.CreateNew(t,i,o.width,o.height,s,s,r.getProjectionMatrix())},i.prototype._internalPick=function(t,i,r){if(!e.PickingInfo)return null;for(var n=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=t(s.getWorldMatrix()),l=s.intersects(a,r);if(l&&l.hit&&((r||null==n||!(l.distance>=n.distance))&&(n=l,r)))break}return n||new e.PickingInfo},i.prototype._internalMultiPick=function(t,i){if(!e.PickingInfo)return null;for(var r=new Array,n=0;n<this.meshes.length;n++){var o=this.meshes[n];if(i){if(!i(o))continue}else if(!o.isEnabled()||!o.isVisible||!o.isPickable)continue;var s=t(o.getWorldMatrix()),a=o.intersects(s,!1);a&&a.hit&&r.push(a)}return r},i.prototype._internalPickSprites=function(t,i,r,n){if(!e.PickingInfo)return null;var o=null;if(!n){if(!this.activeCamera)return null;n=this.activeCamera}if(this.spriteManagers.length>0)for(var s=0;s<this.spriteManagers.length;s++){var a=this.spriteManagers[s];if(a.isPickable){var l=a.intersects(t,n,i,r);if(l&&l.hit&&(r||null==o||!(l.distance>=o.distance))&&(o=l,r))break}}return o||new e.PickingInfo},i.prototype.pick=function(e,t,i,r,n){var o=this;return this._internalPick(function(i){return o.createPickingRay(e,t,i,n||null)},i,r)},i.prototype.pickSprite=function(e,t,i,r,n){var o=this.createPickingRayInCameraSpace(e,t,n);return o?this._internalPickSprites(o,i,r,n):null},i.prototype.pickWithRay=function(t,i,r){var n=this;return this._internalPick(function(i){return n._pickWithRayInverseMatrix||(n._pickWithRayInverseMatrix=e.Matrix.Identity()),i.invertToRef(n._pickWithRayInverseMatrix),n._cachedRayForTransform||(n._cachedRayForTransform=new e.Ray(e.Vector3.Zero(),e.Vector3.Zero())),e.Ray.TransformToRef(t,n._pickWithRayInverseMatrix,n._cachedRayForTransform),n._cachedRayForTransform},i,r)},i.prototype.multiPick=function(e,t,i,r){var n=this;return this._internalMultiPick(function(i){return n.createPickingRay(e,t,i,r||null)},i)},i.prototype.multiPickWithRay=function(t,i){var r=this;return this._internalMultiPick(function(i){return r._pickWithRayInverseMatrix||(r._pickWithRayInverseMatrix=e.Matrix.Identity()),i.invertToRef(r._pickWithRayInverseMatrix),r._cachedRayForTransform||(r._cachedRayForTransform=new e.Ray(e.Vector3.Zero(),e.Vector3.Zero())),e.Ray.TransformToRef(t,r._pickWithRayInverseMatrix,r._cachedRayForTransform),r._cachedRayForTransform},i)},i.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)))},i.prototype.getPointerOverMesh=function(){return this._pointerOverMesh},i.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)))},i.prototype.getPointerOverSprite=function(){return this._pointerOverSprite},i.prototype.getPhysicsEngine=function(){return this._physicsEngine},i.prototype.enablePhysics=function(t,i){if(void 0===t&&(t=null),this._physicsEngine)return!0;try{return this._physicsEngine=new e.PhysicsEngine(t,i),!0}catch(t){return e.Tools.Error(t.message),!1}},i.prototype.disablePhysicsEngine=function(){this._physicsEngine&&(this._physicsEngine.dispose(),this._physicsEngine=null)},i.prototype.isPhysicsEnabled=function(){return void 0!==this._physicsEngine},i.prototype.deleteCompoundImpostor=function(e){var t=e.parts[0].mesh;t.physicsImpostor&&(t.physicsImpostor.dispose(),t.physicsImpostor=null)},i.prototype._rebuildGeometries=function(){for(var e=0,t=this._geometries;e<t.length;e++)t[e]._rebuild();for(var i=0,r=this.meshes;i<r.length;i++)r[i]._rebuild();this.postProcessManager&&this.postProcessManager._rebuild();for(var n=0,o=this.layers;n<o.length;n++)o[n]._rebuild();for(var s=0,a=this.highlightLayers;s<a.length;s++)a[s]._rebuild();this._boundingBoxRenderer&&this._boundingBoxRenderer._rebuild();for(var l=0,h=this.particleSystems;l<h.length;l++)h[l].rebuild();this._postProcessRenderPipelineManager&&this._postProcessRenderPipelineManager._rebuild()},i.prototype._rebuildTextures=function(){for(var t=0,i=this.textures;t<i.length;t++)i[t]._rebuild();this.markAllMaterialsAsDirty(e.Material.TextureDirtyFlag)},i.prototype.createDefaultCameraOrLight=function(t,i,r){if(void 0===t&&(t=!1),void 0===i&&(i=!1),void 0===r&&(r=!1),i&&(this.activeCamera&&(this.activeCamera.dispose(),this.activeCamera=null),this.lights))for(var n=0;n<this.lights.length;n++)this.lights[n].dispose();if(0===this.lights.length&&new e.HemisphericLight("default light",e.Vector3.Up(),this),!this.activeCamera){var o,s=this.getWorldExtends(),a=s.max.subtract(s.min),l=s.min.add(a.scale(.5)),h=1.5*a.length();if(t){var u=new e.ArcRotateCamera("default camera",-Math.PI/2,Math.PI/2,h,l,this);u.lowerRadiusLimit=.01*h,u.wheelPrecision=100/h,o=u}else{var c=new e.FreeCamera("default camera",new e.Vector3(l.x,l.y,-h),this);c.setTarget(l),o=c}o.minZ=.01*h,o.maxZ=100*h,o.speed=.2*h,this.activeCamera=o;var f=this.getEngine().getRenderingCanvas();r&&f&&o.attachControl(f)}},i.prototype.createDefaultSkybox=function(t,i,r,n){if(void 0===i&&(i=!1),void 0===r&&(r=1e3),void 0===n&&(n=0),t&&(this.environmentTexture=t),!this.environmentTexture)return e.Tools.Warn("Can not create default skybox without environment texture."),null;var o=e.Mesh.CreateBox("hdrSkyBox",r,this);if(i){var s=new e.PBRMaterial("skyBox",this);s.backFaceCulling=!1,s.reflectionTexture=this.environmentTexture.clone(),s.reflectionTexture&&(s.reflectionTexture.coordinatesMode=e.Texture.SKYBOX_MODE),s.microSurface=1-n,s.disableLighting=!0,s.twoSidedLighting=!0,o.infiniteDistance=!0,o.material=s}else{var a=new e.StandardMaterial("skyBox",this);a.backFaceCulling=!1,a.reflectionTexture=this.environmentTexture.clone(),a.reflectionTexture&&(a.reflectionTexture.coordinatesMode=e.Texture.SKYBOX_MODE),a.disableLighting=!0,o.infiniteDistance=!0,o.material=a}return o},i.prototype.createDefaultEnvironment=function(t){return e.EnvironmentHelper?new e.EnvironmentHelper(t,this):null},i.prototype.createDefaultVRExperience=function(t){return void 0===t&&(t={}),new e.VRExperienceHelper(this,t)},i.prototype._getByTags=function(t,i,r){if(void 0===i)return t;var n=[];r=r||function(e){};for(var o in t){var s=t[o];e.Tags.MatchesQuery(s,i)&&(n.push(s),r(s))}return n},i.prototype.getMeshesByTags=function(e,t){return this._getByTags(this.meshes,e,t)},i.prototype.getCamerasByTags=function(e,t){return this._getByTags(this.cameras,e,t)},i.prototype.getLightsByTags=function(e,t){return this._getByTags(this.lights,e,t)},i.prototype.getMaterialByTags=function(e,t){return this._getByTags(this.materials,e,t).concat(this._getByTags(this.multiMaterials,e,t))},i.prototype.setRenderingOrder=function(e,t,i,r){void 0===t&&(t=null),void 0===i&&(i=null),void 0===r&&(r=null),this._renderingManager.setRenderingOrder(e,t,i,r)},i.prototype.setRenderingAutoClearDepthStencil=function(e,t,i,r){void 0===i&&(i=!0),void 0===r&&(r=!0),this._renderingManager.setRenderingAutoClearDepthStencil(e,t,i,r)},i.prototype.markAllMaterialsAsDirty=function(e,t){for(var i=0,r=this.materials;i<r.length;i++){var n=r[i];t&&!t(n)||n.markAsDirty(e)}},i._FOGMODE_NONE=0,i._FOGMODE_EXP=1,i._FOGMODE_EXP2=2,i._FOGMODE_LINEAR=3,i._uniqueIdCounter=0,i.MinDeltaTime=1,i.MaxDeltaTime=1e3,i.DragMovementThreshold=10,i.LongPressDelay=500,i.DoubleClickDelay=300,i.ExclusiveDoubleClickMode=!1,i}();e.Scene=r}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n,o,s){void 0===s&&(s=!1),t instanceof e.Mesh?this._engine=t.getScene().getEngine():this._engine=t,this._updatable=r,this._data=i,this._strideSize=n,o||this.create(),this._instanced=s,this._instanceDivisor=s?1:0}return t.prototype.createVertexBuffer=function(t,i,r,n){return new e.VertexBuffer(this._engine,this,t,this._updatable,!0,n||this._strideSize,this._instanced,i,r)},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.getIsInstanced=function(){return this._instanced},Object.defineProperty(t.prototype,"instanceDivisor",{get:function(){return this._instanceDivisor},set:function(e){this._instanceDivisor=e,this._instanced=0!=e},enumerable:!0,configurable:!0}),t.prototype.create=function(e){void 0===e&&(e=null),!e&&this._buffer||(e=e||this._data)&&(this._buffer?this._updatable&&(this._engine.updateDynamicVertexBuffer(this._buffer,e),this._data=e):this._updatable?(this._buffer=this._engine.createDynamicVertexBuffer(e),this._data=e):this._buffer=this._engine.createVertexBuffer(e))},t.prototype._rebuild=function(){this._buffer=null,this.create(this._data)},t.prototype.update=function(e){this.create(e)},t.prototype.updateDirectly=function(e,t,i){this._buffer&&this._updatable&&(this._engine.updateDynamicVertexBuffer(this._buffer,e,t,i?i*this.getStrideSize():void 0),this._data=null)},t.prototype.dispose=function(){this._buffer&&this._engine._releaseBuffer(this._buffer)&&(this._buffer=null)},t}();e.Buffer=t}(s||(s={}));!function(e){var t=function(){function t(i,r,n,o,s,a,l,h,u){if(!a)switch(n){case t.PositionKind:case t.NormalKind:a=3;break;case t.UVKind:case t.UV2Kind:case t.UV3Kind:case t.UV4Kind:case t.UV5Kind:case t.UV6Kind:a=2;break;case t.TangentKind:case t.ColorKind:a=4;break;case t.MatricesIndicesKind:case t.MatricesIndicesExtraKind:a=4;break;case t.MatricesWeightsKind:case t.MatricesWeightsExtraKind:default:a=4}r instanceof e.Buffer?(a||(a=r.getStrideSize()),this._buffer=r,this._ownsBuffer=!1):(this._buffer=new e.Buffer(i,r,o,a,s,l),this._ownsBuffer=!0),this._stride=a,this._offset=h||0,this._size=u||a,this._kind=n}return t.prototype._rebuild=function(){this._buffer&&this._buffer._rebuild()},t.prototype.getKind=function(){return this._kind},t.prototype.isUpdatable=function(){return this._buffer.isUpdatable()},t.prototype.getData=function(){return this._buffer.getData()},t.prototype.getBuffer=function(){return this._buffer.getBuffer()},t.prototype.getStrideSize=function(){return this._stride},t.prototype.getOffset=function(){return this._offset},t.prototype.getSize=function(){return this._size},t.prototype.getIsInstanced=function(){return this._buffer.getIsInstanced()},t.prototype.getInstanceDivisor=function(){return this._buffer.instanceDivisor},t.prototype.create=function(e){return this._buffer.create(e)},t.prototype.update=function(e){return this._buffer.update(e)},t.prototype.updateDirectly=function(e,t){return this._buffer.updateDirectly(e,t)},t.prototype.dispose=function(){this._ownsBuffer&&this._buffer.dispose()},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,"TangentKind",{get:function(){return t._TangentKind},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._TangentKind="tangent",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}(s||(s={}));!function(e){var t=function(){function t(i,r){this.onLoadedObservable=new e.Observable,this._dataSource=t.DATASOURCE_UNKNOWN,this._references=1,this._engine=i,this._dataSource=r,this._webGLTexture=i._createTexture()}return Object.defineProperty(t.prototype,"dataSource",{get:function(){return this._dataSource},enumerable:!0,configurable:!0}),t.prototype.incrementReferences=function(){this._references++},t.prototype.updateSize=function(e,t,i){void 0===i&&(i=1),this.width=e,this.height=t,this.depth=i,this.baseWidth=e,this.baseHeight=t,this.baseDepth=i,this._size=e*t*i},t.prototype._rebuild=function(){var i,r=this;switch(this.isReady=!1,this._cachedCoordinatesMode=null,this._cachedWrapU=null,this._cachedWrapV=null,this._cachedAnisotropicFilteringLevel=null,this._dataSource){case t.DATASOURCE_TEMP:return;case t.DATASOURCE_URL:return void(i=this._engine.createTexture(this.url,!this.generateMipMaps,this.invertY,null,this.samplingMode,function(){r.isReady=!0},null,this._buffer,void 0,this.format))._swapAndDie(this);case t.DATASOURCE_RAW:return(i=this._engine.createRawTexture(this._bufferView,this.baseWidth,this.baseHeight,this.format,this.generateMipMaps,this.invertY,this.samplingMode,this._compression))._swapAndDie(this),void(this.isReady=!0);case t.DATASOURCE_RAW3D:return(i=this._engine.createRawTexture3D(this._bufferView,this.baseWidth,this.baseHeight,this.baseDepth,this.format,this.generateMipMaps,this.invertY,this.samplingMode,this._compression))._swapAndDie(this),void(this.isReady=!0);case t.DATASOURCE_DYNAMIC:return void(i=this._engine.createDynamicTexture(this.baseWidth,this.baseHeight,this.generateMipMaps,this.samplingMode))._swapAndDie(this);case t.DATASOURCE_RENDERTARGET:var n=new e.RenderTargetCreationOptions;if(n.generateDepthBuffer=this._generateDepthBuffer,n.generateMipMaps=this.generateMipMaps,n.generateStencilBuffer=this._generateStencilBuffer,n.samplingMode=this.samplingMode,n.type=this.type,this.isCube)i=this._engine.createRenderTargetCubeTexture(this.width,n);else{var o={width:this.width,height:this.height};i=this._engine.createRenderTargetTexture(o,n)}return i._swapAndDie(this),void(this.isReady=!0);case t.DATASOURCE_CUBE:return void(i=this._engine.createCubeTexture(this.url,null,this._files,!this.generateMipMaps,function(){r.isReady=!0},null,this.format,this._extension))._swapAndDie(this);case t.DATASOURCE_CUBERAW:return(i=this._engine.createRawCubeTexture(this._bufferViewArray,this.width,this.format,this.type,this.generateMipMaps,this.invertY,this.samplingMode,this._compression))._swapAndDie(this),void(this.isReady=!0);case t.DATASOURCE_CUBEPREFILTERED:return void(i=this._engine.createPrefilteredCubeTexture(this.url,null,this._lodGenerationScale,this._lodGenerationOffset,function(e){e&&e._swapAndDie(r),r.isReady=!0},null,this.format,this._extension))}},t.prototype._swapAndDie=function(e){e._webGLTexture=this._webGLTexture,this._framebuffer&&(e._framebuffer=this._framebuffer),this._depthStencilBuffer&&(e._depthStencilBuffer=this._depthStencilBuffer),this._lodTextureHigh&&(e._lodTextureHigh&&e._lodTextureHigh.dispose(),e._lodTextureHigh=this._lodTextureHigh),this._lodTextureMid&&(e._lodTextureMid&&e._lodTextureMid.dispose(),e._lodTextureMid=this._lodTextureMid),this._lodTextureLow&&(e._lodTextureLow&&e._lodTextureLow.dispose(),e._lodTextureLow=this._lodTextureLow);var t=this._engine.getLoadedTexturesCache(),i=t.indexOf(this);-1!==i&&t.splice(i,1)},t.prototype.dispose=function(){this._webGLTexture&&(this._references--,0===this._references&&(this._engine._releaseTexture(this),this._webGLTexture=null))},t.DATASOURCE_UNKNOWN=0,t.DATASOURCE_URL=1,t.DATASOURCE_TEMP=2,t.DATASOURCE_RAW=3,t.DATASOURCE_DYNAMIC=4,t.DATASOURCE_RENDERTARGET=5,t.DATASOURCE_MULTIRENDERTARGET=6,t.DATASOURCE_CUBE=7,t.DATASOURCE_CUBERAW=8,t.DATASOURCE_CUBEPREFILTERED=9,t.DATASOURCE_RAW3D=10,t}();e.InternalTexture=t}(s||(s={}));!function(e){var t=function(){function t(i){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.wrapR=e.Texture.WRAP_ADDRESSMODE,this.anisotropicFilteringLevel=t.DEFAULT_ANISOTROPIC_FILTERING_LEVEL,this.isCube=!1,this.is3D=!1,this.gammaSpace=!0,this.invertZ=!1,this.lodLevelInAlpha=!1,this.lodGenerationOffset=0,this.lodGenerationScale=.8,this.isRenderTarget=!1,this.animations=new Array,this.onDisposeObservable=new e.Observable,this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this._scene=i||e.Engine.LastCreatedScene,this._scene&&this._scene.textures.push(this),this._uid=null}return Object.defineProperty(t.prototype,"hasAlpha",{get:function(){return this._hasAlpha},set:function(t){this._hasAlpha!==t&&(this._hasAlpha=t,this._scene&&this._scene.markAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"coordinatesMode",{get:function(){return this._coordinatesMode},set:function(t){this._coordinatesMode!==t&&(this._coordinatesMode=t,this._scene&&this._scene.markAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"uid",{get:function(){return this._uid||(this._uid=e.Tools.RandomId()),this._uid},enumerable:!0,configurable:!0}),t.prototype.toString=function(){return this.name},t.prototype.getClassName=function(){return"BaseTexture"},Object.defineProperty(t.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isBlocking",{get:function(){return!0},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},t.prototype.getTextureMatrix=function(){return e.Matrix.IdentityReadOnly},t.prototype.getReflectionTextureMatrix=function(){return e.Matrix.IdentityReadOnly},t.prototype.getInternalTexture=function(){return this._texture},t.prototype.isReadyOrNotBlocking=function(){return!this.isBlocking||this.isReady()},t.prototype.isReady=function(){return this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED?(this.delayLoad(),!1):!!this._texture&&this._texture.isReady},t.prototype.getSize=function(){return this._texture&&this._texture.width?new e.Size(this._texture.width,this._texture.height):this._texture&&this._texture._size?new e.Size(this._texture._size,this._texture._size):e.Size.Zero()},t.prototype.getBaseSize=function(){return this.isReady()&&this._texture?this._texture._size?new e.Size(this._texture._size,this._texture._size):new e.Size(this._texture.baseWidth,this._texture.baseHeight):e.Size.Zero()},t.prototype.scale=function(e){},Object.defineProperty(t.prototype,"canRescale",{get:function(){return!1},enumerable:!0,configurable:!0}),t.prototype._getFromCache=function(e,t,i){if(!this._scene)return null;for(var r=this._scene.getEngine().getLoadedTexturesCache(),n=0;n<r.length;n++){var o=r[n];if(o.url===e&&o.generateMipMaps===!t&&(!i||i===o.samplingMode))return o.incrementReferences(),o}return null},t.prototype._rebuild=function(){},t.prototype.delayLoad=function(){},t.prototype.clone=function(){return null},Object.defineProperty(t.prototype,"textureType",{get:function(){return this._texture&&void 0!==this._texture.type?this._texture.type:e.Engine.TEXTURETYPE_UNSIGNED_INT},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"textureFormat",{get:function(){return this._texture&&void 0!==this._texture.format?this._texture.format:e.Engine.TEXTUREFORMAT_RGBA},enumerable:!0,configurable:!0}),t.prototype.readPixels=function(e){if(void 0===e&&(e=0),!this._texture)return null;var t=this.getSize(),i=this.getScene();if(!i)return null;var r=i.getEngine();return this._texture.isCube?r._readTexturePixels(this._texture,t.width,t.height,e):r._readTexturePixels(this._texture,t.width,t.height,-1)},t.prototype.releaseInternalTexture=function(){this._texture&&(this._texture.dispose(),this._texture=null)},Object.defineProperty(t.prototype,"sphericalPolynomial",{get:function(){return this._texture&&e.Internals.CubeMapToSphericalPolynomialTools&&this.isReady()?(this._texture._sphericalPolynomial||(this._texture._sphericalPolynomial=e.Internals.CubeMapToSphericalPolynomialTools.ConvertCubeMapTextureToSphericalPolynomial(this)),this._texture._sphericalPolynomial):null},set:function(e){this._texture&&(this._texture._sphericalPolynomial=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"_lodTextureHigh",{get:function(){return this._texture?this._texture._lodTextureHigh:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"_lodTextureMid",{get:function(){return this._texture?this._texture._lodTextureMid:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"_lodTextureLow",{get:function(){return this._texture?this._texture._lodTextureLow:null},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){if(this._scene){this._scene.stopAnimation(this),this._scene._removePendingData(this);var e=this._scene.textures.indexOf(this);e>=0&&this._scene.textures.splice(e,1),void 0!==this._texture&&(this.releaseInternalTexture(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear())}},t.prototype.serialize=function(){if(!this.name)return null;var t=e.SerializationHelper.Serialize(this);return e.Animation.AppendSerializedAnimations(this,t),t},t.WhenAllReady=function(e,t){var i=e.length;if(0!==i)for(var r,n,o=0;o<e.length;o++)!function(){if((r=e[o]).isReady())0==--i&&t();else{var s=function(){n.removeCallback(s),0==--i&&t()};(n=r.onLoadObservable).add(s)}}();else t()},t.DEFAULT_ANISOTROPIC_FILTERING_LEVEL=4,r([e.serialize()],t.prototype,"name",void 0),r([e.serialize("hasAlpha")],t.prototype,"_hasAlpha",void 0),r([e.serialize()],t.prototype,"getAlphaFromRGB",void 0),r([e.serialize()],t.prototype,"level",void 0),r([e.serialize()],t.prototype,"coordinatesIndex",void 0),r([e.serialize("coordinatesMode")],t.prototype,"_coordinatesMode",void 0),r([e.serialize()],t.prototype,"wrapU",void 0),r([e.serialize()],t.prototype,"wrapV",void 0),r([e.serialize()],t.prototype,"wrapR",void 0),r([e.serialize()],t.prototype,"anisotropicFilteringLevel",void 0),r([e.serialize()],t.prototype,"isCube",void 0),r([e.serialize()],t.prototype,"is3D",void 0),r([e.serialize()],t.prototype,"gammaSpace",void 0),r([e.serialize()],t.prototype,"invertZ",void 0),r([e.serialize()],t.prototype,"lodLevelInAlpha",void 0),r([e.serialize()],t.prototype,"lodGenerationOffset",void 0),r([e.serialize()],t.prototype,"lodGenerationScale",void 0),r([e.serialize()],t.prototype,"isRenderTarget",void 0),t}();e.BaseTexture=t}(s||(s={}));!function(e){var t=function(t){function i(r,n,o,s,a,l,h,u,c,f){void 0===o&&(o=!1),void 0===s&&(s=!0),void 0===a&&(a=i.TRILINEAR_SAMPLINGMODE),void 0===l&&(l=null),void 0===h&&(h=null),void 0===u&&(u=null),void 0===c&&(c=!1);var p=t.call(this,n)||this;if(p.uOffset=0,p.vOffset=0,p.uScale=1,p.vScale=1,p.uAng=0,p.vAng=0,p.wAng=0,p._isBlocking=!0,p.name=r||"",p.url=r,p._noMipmap=o,p._invertY=s,p._samplingMode=a,p._buffer=u,p._deleteBuffer=c,f&&(p._format=f),!(n=p.getScene()))return p;n.getEngine().onBeforeTextureInitObservable.notifyObservers(p);var d=function(){p._onLoadObservable&&p._onLoadObservable.hasObservers()&&p.onLoadObservable.notifyObservers(p),l&&l(),!p.isBlocking&&n&&n.resetCachedMaterial()};return p.url?(p._texture=p._getFromCache(p.url,o,a),p._texture?p._texture.isReady?e.Tools.SetImmediate(function(){return d()}):p._texture.onLoadedObservable.add(d):n.useDelayedTextureLoading?(p.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,p._delayedOnLoad=d,p._delayedOnError=h):(p._texture=n.getEngine().createTexture(p.url,o,s,n,p._samplingMode,d,h,p._buffer,void 0,p._format),c&&delete p._buffer),p):(p._delayedOnLoad=d,p._delayedOnError=h,p)}return n(i,t),Object.defineProperty(i.prototype,"noMipmap",{get:function(){return this._noMipmap},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isBlocking",{get:function(){return this._isBlocking},set:function(e){this._isBlocking=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"samplingMode",{get:function(){return this._samplingMode},enumerable:!0,configurable:!0}),i.prototype.updateURL=function(t){this.url=t,this.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,this.delayLoad()},i.prototype.delayLoad=function(){var t=this;if(this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED){var i=this.getScene();i&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap,this._samplingMode),this._texture?this._texture.isReady?e.Tools.SetImmediate(function(){t._delayedOnLoad&&t._delayedOnLoad()}):this._delayedOnLoad&&this._texture.onLoadedObservable.add(this._delayedOnLoad):(this._texture=i.getEngine().createTexture(this.url,this._noMipmap,this._invertY,i,this._samplingMode,this._delayedOnLoad,this._delayedOnError,this._buffer,null,this._format),this._deleteBuffer&&delete this._buffer))}},i.prototype.updateSamplingMode=function(e){if(this._texture){var t=this.getScene();t&&(this._samplingMode=e,t.getEngine().updateTextureSamplingMode(e,this._texture))}},i.prototype._prepareRowForTextureGeneration=function(t,i,r,n){t*=this.uScale,i*=this.vScale,t-=.5*this.uScale,i-=.5*this.vScale,r-=.5,e.Vector3.TransformCoordinatesFromFloatsToRef(t,i,r,this._rowGenerationMatrix,n),n.x+=.5*this.uScale+this.uOffset,n.y+=.5*this.vScale+this.vOffset,n.z+=.5},i.prototype.getTextureMatrix=function(){var t=this;if(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)return 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;var i=this.getScene();return i?(i.markAllMaterialsAsDirty(e.Material.TextureDirtyFlag,function(e){return e.hasTexture(t)}),this._cachedTextureMatrix):this._cachedTextureMatrix},i.prototype.getReflectionTextureMatrix=function(){var t=this,r=this.getScene();if(!r)return this._cachedTextureMatrix;if(this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.coordinatesMode===this._cachedCoordinatesMode){if(this.coordinatesMode!==i.PROJECTION_MODE)return this._cachedTextureMatrix;if(this._cachedProjectionMatrixId===r.getProjectionMatrix().updateFlag)return this._cachedTextureMatrix}switch(this._cachedTextureMatrix||(this._cachedTextureMatrix=e.Matrix.Zero()),this._projectionModeMatrix||(this._projectionModeMatrix=e.Matrix.Zero()),this._cachedUOffset=this.uOffset,this._cachedVOffset=this.vOffset,this._cachedUScale=this.uScale,this._cachedVScale=this.vScale,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;var n=r.getProjectionMatrix();this._cachedProjectionMatrixId=n.updateFlag,n.multiplyToRef(this._projectionModeMatrix,this._cachedTextureMatrix);break;default:e.Matrix.IdentityToRef(this._cachedTextureMatrix)}return r.markAllMaterialsAsDirty(e.Material.TextureDirtyFlag,function(e){return-1!==e.getActiveTextures().indexOf(t)}),this._cachedTextureMatrix},i.prototype.clone=function(){var t=this;return e.SerializationHelper.Clone(function(){return new i(t._texture?t._texture.url:null,t.getScene(),t._noMipmap,t._invertY,t._samplingMode)},this)},Object.defineProperty(i.prototype,"onLoadObservable",{get:function(){return this._onLoadObservable||(this._onLoadObservable=new e.Observable),this._onLoadObservable},enumerable:!0,configurable:!0}),i.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return"string"==typeof this._buffer&&"data:"===this._buffer.substr(0,5)&&(e.base64String=this._buffer,e.name=e.name.replace("data:","")),e},i.prototype.getClassName=function(){return"Texture"},i.prototype.dispose=function(){t.prototype.dispose.call(this),this.onLoadObservable&&(this.onLoadObservable.clear(),this._onLoadObservable=null),this._delayedOnLoad=null,this._delayedOnError=null},i.CreateFromBase64String=function(t,r,n,o,s,a,l,h,u){return void 0===a&&(a=i.TRILINEAR_SAMPLINGMODE),void 0===l&&(l=null),void 0===h&&(h=null),void 0===u&&(u=e.Engine.TEXTUREFORMAT_RGBA),new i("data:"+r,n,o,s,a,l,h,t,!1,u)},i.Parse=function(t,r,n){if(t.customType){var o=e.Tools.Instantiate(t.customType).Parse(t,r,n);return t.samplingMode&&o.updateSamplingMode&&o._samplingMode&&o._samplingMode!==t.samplingMode&&o.updateSamplingMode(t.samplingMode),o}if(t.isCube)return e.CubeTexture.Parse(t,r,n);if(!t.name&&!t.isRenderTarget)return null;var s=e.SerializationHelper.Parse(function(){if(t.mirrorPlane){var o=new e.MirrorTexture(t.name,t.renderTargetSize,r);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,r);return s._waitingRenderList=t.renderList,s}return t.base64String?i.CreateFromBase64String(t.base64String,t.name,r):new i(n+t.name,r)},t,r);if(t.samplingMode){var a=t.samplingMode;s._samplingMode!==a&&s.updateSamplingMode(a)}if(t.animations)for(var l=0;l<t.animations.length;l++){var h=t.animations[l];s.animations.push(e.Animation.Parse(h))}return s},i.LoadFromDataString=function(t,r,n,o,s,a,l,h,u,c){return void 0===o&&(o=!1),void 0===s&&(s=!1),void 0===a&&(a=!0),void 0===l&&(l=i.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=null),void 0===u&&(u=null),void 0===c&&(c=e.Engine.TEXTUREFORMAT_RGBA),"data:"!==t.substr(0,5)&&(t="data:"+t),new i(t,n,s,a,l,h,u,r,o,c)},i.NEAREST_SAMPLINGMODE=1,i.NEAREST_NEAREST_MIPLINEAR=1,i.BILINEAR_SAMPLINGMODE=2,i.LINEAR_LINEAR_MIPNEAREST=2,i.TRILINEAR_SAMPLINGMODE=3,i.LINEAR_LINEAR_MIPLINEAR=3,i.NEAREST_NEAREST_MIPNEAREST=4,i.NEAREST_LINEAR_MIPNEAREST=5,i.NEAREST_LINEAR_MIPLINEAR=6,i.NEAREST_LINEAR=7,i.NEAREST_NEAREST=8,i.LINEAR_NEAREST_MIPNEAREST=9,i.LINEAR_NEAREST_MIPLINEAR=10,i.LINEAR_LINEAR=11,i.LINEAR_NEAREST=12,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.FIXED_EQUIRECTANGULAR_MIRRORED_MODE=9,i.CLAMP_ADDRESSMODE=0,i.WRAP_ADDRESSMODE=1,i.MIRROR_ADDRESSMODE=2,r([e.serialize()],i.prototype,"url",void 0),r([e.serialize()],i.prototype,"uOffset",void 0),r([e.serialize()],i.prototype,"vOffset",void 0),r([e.serialize()],i.prototype,"uScale",void 0),r([e.serialize()],i.prototype,"vScale",void 0),r([e.serialize()],i.prototype,"uAng",void 0),r([e.serialize()],i.prototype,"vAng",void 0),r([e.serialize()],i.prototype,"wAng",void 0),r([e.serialize()],i.prototype,"isBlocking",null),i}(e.BaseTexture);e.Texture=t}(s||(s={}));!function(e){var t=function(){return function(){this.mustReturn=!1,this.visibleInstances=new Array,this.renderSelf=new Array}}();e._InstancesBatch=t;var i=function(i){function r(n,o,s,a,l,h){void 0===o&&(o=null),void 0===s&&(s=null),void 0===a&&(a=null),void 0===h&&(h=!0);var u=i.call(this,n,o)||this;if(u.onBeforeRenderObservable=new e.Observable,u.onAfterRenderObservable=new e.Observable,u.onBeforeDrawObservable=new e.Observable,u.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,u.instances=new Array,u._LODLevels=new Array,u._visibleInstances={},u._renderIdForInstances=new Array,u._batchCache=new t,u._instancesBufferSize=2048,u._originalBuilderSideOrientation=r._DEFAULTSIDE,u.overrideMaterialSideOrientation=null,u._areNormalsFrozen=!1,u._source=null,o=u.getScene(),a){u._source=a,a._geometry&&a._geometry.applyToMesh(u),e.Tools.DeepCopy(a,u,["name","material","skeleton","instances","parent","uniqueId","source"],["_poseMatrix","_source"]),e.Tags.HasTags(a)&&e.Tags.AddTagsTo(u,e.Tags.GetTags(a,!0)),u.metadata=a.metadata,u.parent=a.parent,u.setPivotMatrix(a.getPivotMatrix()),u.id=n+"."+a.id,u.material=a.material;var c;if(!l)for(c=0;c<o.meshes.length;c++){var f=o.meshes[c];f.parent===a&&f.clone(n+"."+f.name,u,l)}var p=u.getScene().getPhysicsEngine();if(h&&p){var d=p.getImpostorForPhysicsObject(a);d&&(u.physicsImpostor=d.clone(u))}for(c=0;c<o.particleSystems.length;c++){var m=o.particleSystems[c];m.emitter===a&&m.clone(m.name,u)}u.computeWorldMatrix(!0)}return null!==s&&(u.parent=s),u}return n(r,i),Object.defineProperty(r,"FRONTSIDE",{get:function(){return r._FRONTSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BACKSIDE",{get:function(){return r._BACKSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"DOUBLESIDE",{get:function(){return r._DOUBLESIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"DEFAULTSIDE",{get:function(){return r._DEFAULTSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"NO_CAP",{get:function(){return r._NO_CAP},enumerable:!0,configurable:!0}),Object.defineProperty(r,"CAP_START",{get:function(){return r._CAP_START},enumerable:!0,configurable:!0}),Object.defineProperty(r,"CAP_END",{get:function(){return r._CAP_END},enumerable:!0,configurable:!0}),Object.defineProperty(r,"CAP_ALL",{get:function(){return r._CAP_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onBeforeDraw",{set:function(e){this._onBeforeDrawObserver&&this.onBeforeDrawObservable.remove(this._onBeforeDrawObserver),this._onBeforeDrawObserver=this.onBeforeDrawObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"morphTargetManager",{get:function(){return this._morphTargetManager},set:function(e){this._morphTargetManager!==e&&(this._morphTargetManager=e,this._syncGeometryWithMorphTargetManager())},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"source",{get:function(){return this._source},enumerable:!0,configurable:!0}),r.prototype.getClassName=function(){return"Mesh"},r.prototype.toString=function(t){var r=i.prototype.toString.call(this,t);if(r+=", n vertices: "+this.getTotalVertices(),r+=", parent: "+(this._waitingParentId?this._waitingParentId:this.parent?this.parent.name:"NONE"),this.animations)for(var n=0;n<this.animations.length;n++)r+=", animation[0]: "+this.animations[n].toString(t);if(t)if(this._geometry){var o=this.getIndices(),s=this.getVerticesData(e.VertexBuffer.PositionKind);s&&o&&(r+=", flat shading: "+(s.length/3===o.length?"YES":"NO"))}else r+=", flat shading: UNKNOWN";return r},Object.defineProperty(r.prototype,"hasLODLevels",{get:function(){return this._LODLevels.length>0},enumerable:!0,configurable:!0}),r.prototype._sortLODLevels=function(){this._LODLevels.sort(function(e,t){return e.distance<t.distance?1:e.distance>t.distance?-1:0})},r.prototype.addLODLevel=function(t,i){if(i&&i._masterMesh)return e.Tools.Warn("You cannot use a mesh as LOD level twice"),this;var r=new e.Internals.MeshLODLevel(t,i);return this._LODLevels.push(r),i&&(i._masterMesh=this),this._sortLODLevels(),this},r.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},r.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},r.prototype.getLOD=function(e,t){if(!this._LODLevels||0===this._LODLevels.length)return this;var i;if(t)i=t;else{var r=this.getBoundingInfo();if(!r)return this;i=r.boundingSphere}var n=i.centerWorld.subtract(e.globalPosition).length();if(this._LODLevels[this._LODLevels.length-1].distance>n)return this.onLODLevelSelection&&this.onLODLevelSelection(n,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var o=0;o<this._LODLevels.length;o++){var s=this._LODLevels[o];if(s.distance<n)return s.mesh&&(s.mesh._preActivate(),s.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)),this.onLODLevelSelection&&this.onLODLevelSelection(n,this,s.mesh),s.mesh}return this.onLODLevelSelection&&this.onLODLevelSelection(n,this,this),this},Object.defineProperty(r.prototype,"geometry",{get:function(){return this._geometry},enumerable:!0,configurable:!0}),r.prototype.getTotalVertices=function(){return this._geometry?this._geometry.getTotalVertices():0},r.prototype.getVerticesData=function(e,t,i){return this._geometry?this._geometry.getVerticesData(e,t,i):null},r.prototype.getVertexBuffer=function(e){return this._geometry?this._geometry.getVertexBuffer(e):null},r.prototype.isVerticesDataPresent=function(e){return this._geometry?this._geometry.isVerticesDataPresent(e):!!this._delayInfo&&-1!==this._delayInfo.indexOf(e)},r.prototype.isVertexBufferUpdatable=function(e){return this._geometry?this._geometry.isVertexBufferUpdatable(e):!!this._delayInfo&&-1!==this._delayInfo.indexOf(e)},r.prototype.getVerticesDataKinds=function(){if(!this._geometry){var e=new Array;return this._delayInfo&&this._delayInfo.forEach(function(t,i,r){e.push(t)}),e}return this._geometry.getVerticesDataKinds()},r.prototype.getTotalIndices=function(){return this._geometry?this._geometry.getTotalIndices():0},r.prototype.getIndices=function(e){return this._geometry?this._geometry.getIndices(e):[]},Object.defineProperty(r.prototype,"isBlocked",{get:function(){return null!==this._masterMesh&&void 0!==this._masterMesh},enumerable:!0,configurable:!0}),r.prototype.isReady=function(){return this.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADING&&i.prototype.isReady.call(this)},Object.defineProperty(r.prototype,"areNormalsFrozen",{get:function(){return this._areNormalsFrozen},enumerable:!0,configurable:!0}),r.prototype.freezeNormals=function(){return this._areNormalsFrozen=!0,this},r.prototype.unfreezeNormals=function(){return this._areNormalsFrozen=!1,this},Object.defineProperty(r.prototype,"overridenInstanceCount",{set:function(e){this._overridenInstanceCount=e},enumerable:!0,configurable:!0}),r.prototype._preActivate=function(){var e=this.getScene().getRenderId();return this._preActivateId===e?this:(this._preActivateId=e,this._visibleInstances=null,this)},r.prototype._preActivateForIntermediateRendering=function(e){return this._visibleInstances&&(this._visibleInstances.intermediateDefaultRenderId=e),this},r.prototype._registerInstanceForRenderId=function(e,t){return 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),this},r.prototype.refreshBoundingInfo=function(){if(this._boundingInfo&&this._boundingInfo.isLocked)return this;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 r=0;r<this.subMeshes.length;r++)this.subMeshes[r].refreshBoundingInfo();return this._updateBoundingInfo(),this},r.prototype._createGlobalSubMesh=function(t){var i=this.getTotalVertices();if(!i||!this.getIndices())return null;if(this.subMeshes&&this.subMeshes.length>0){var r=this.getIndices();if(!r)return null;var n=r.length,o=!1;if(t)o=!0;else for(var s=0,a=this.subMeshes;s<a.length;s++){var l=a[s];if(l.indexStart+l.indexCount>=n){o=!0;break}if(l.verticesStart+l.verticesCount>=i){o=!0;break}}if(!o)return this.subMeshes[0]}return this.releaseSubMeshes(),new e.SubMesh(0,0,i,0,this.getTotalIndices(),this)},r.prototype.subdivide=function(t){if(!(t<1)){for(var i=this.getTotalIndices(),r=i/t|0,n=0;r%3!=0;)r++;this.releaseSubMeshes();for(var o=0;o<t&&!(n>=i);o++)e.SubMesh.CreateFromIndices(0,n,Math.min(r,i-n),this),n+=r;this.synchronizeInstances()}},r.prototype.setVerticesData=function(t,i,r,n){if(void 0===r&&(r=!1),this._geometry)this._geometry.setVerticesData(t,i,r,n);else{var o=new e.VertexData;o.set(i,t);var s=this.getScene();new e.Geometry(e.Geometry.RandomId(),s,o,r,this)}return this},r.prototype.markVerticesDataAsUpdatable=function(e,t){void 0===t&&(t=!0);var i=this.getVertexBuffer(e);i&&i.isUpdatable()!==t&&this.setVerticesData(e,this.getVerticesData(e),t)},r.prototype.setVerticesBuffer=function(t){return this._geometry||(this._geometry=e.Geometry.CreateGeometryForMesh(this)),this._geometry.setVerticesBuffer(t),this},r.prototype.updateVerticesData=function(e,t,i,r){return this._geometry?(r?(this.makeGeometryUnique(),this.updateVerticesData(e,t,i,!1)):this._geometry.updateVerticesData(e,t,i),this):this},r.prototype.updateMeshPositions=function(t,i){void 0===i&&(i=!0);var r=this.getVerticesData(e.VertexBuffer.PositionKind);if(!r)return this;if(t(r),this.updateVerticesData(e.VertexBuffer.PositionKind,r,!1,!1),i){var n=this.getIndices(),o=this.getVerticesData(e.VertexBuffer.NormalKind);if(!o)return this;e.VertexData.ComputeNormals(r,n,o),this.updateVerticesData(e.VertexBuffer.NormalKind,o,!1,!1)}return this},r.prototype.makeGeometryUnique=function(){if(!this._geometry)return this;var t=this._geometry,i=this._geometry.copy(e.Geometry.RandomId());return t.releaseForMesh(this,!0),i.applyToMesh(this),this},r.prototype.setIndices=function(t,i,r){if(void 0===i&&(i=null),void 0===r&&(r=!1),this._geometry)this._geometry.setIndices(t,i,r);else{var n=new e.VertexData;n.indices=t;var o=this.getScene();new e.Geometry(e.Geometry.RandomId(),o,n,r,this)}return this},r.prototype.updateIndices=function(e,t){return this._geometry?(this._geometry.updateIndices(e,t),this):this},r.prototype.toLeftHanded=function(){return this._geometry?(this._geometry.toLeftHanded(),this):this},r.prototype._bind=function(t,i,r){if(!this._geometry)return this;var n,o=this.getScene().getEngine();if(this._unIndexed)n=null;else switch(r){case e.Material.PointFillMode:n=null;break;case e.Material.WireFrameFillMode:n=t.getLinesIndexBuffer(this.getIndices(),o);break;default:case e.Material.TriangleFillMode:n=this._unIndexed?null:this._geometry.getIndexBuffer()}return this._geometry._bind(i,n),this},r.prototype._draw=function(t,i,r,n){if(void 0===n&&(n=!1),!this._geometry||!this._geometry.getVertexBuffers()||!this._geometry.getIndexBuffer())return this;this.onBeforeDrawObservable.notifyObservers(this);var o=this.getScene(),s=o.getEngine();switch(i){case e.Material.PointFillMode:s.drawPointClouds(t.verticesStart,t.verticesCount,r);break;case e.Material.WireFrameFillMode:this._unIndexed?s.drawUnIndexed(!1,t.verticesStart,t.verticesCount,r):s.draw(!1,0,t.linesIndexCount,r);break;default:this._unIndexed?s.drawUnIndexed(!0,t.verticesStart,t.verticesCount,r):s.draw(!0,t.indexStart,t.indexCount,r)}if(o._isAlternateRenderingEnabled&&!n){var a=t.effect||this._effectiveMaterial.getEffect();if(!a||!o.activeCamera)return this;o._switchToAlternateCameraConfiguration(!0),this._effectiveMaterial.bindView(a),this._effectiveMaterial.bindViewProjection(a),s.setViewport(o.activeCamera._alternateCamera.viewport),this._draw(t,i,r,!0),s.setViewport(o.activeCamera.viewport),o._switchToAlternateCameraConfiguration(!1),this._effectiveMaterial.bindView(a),this._effectiveMaterial.bindViewProjection(a)}return this},r.prototype.registerBeforeRender=function(e){return this.onBeforeRenderObservable.add(e),this},r.prototype.unregisterBeforeRender=function(e){return this.onBeforeRenderObservable.removeCallback(e),this},r.prototype.registerAfterRender=function(e){return this.onAfterRenderObservable.add(e),this},r.prototype.unregisterAfterRender=function(e){return this.onAfterRenderObservable.removeCallback(e),this},r.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(),r=t._isInIntermediateRendering()?this._visibleInstances.intermediateDefaultRenderId:this._visibleInstances.defaultRenderId;this._batchCache.visibleInstances[e]=this._visibleInstances[i];var n=this._renderId;!this._batchCache.visibleInstances[e]&&r&&(this._batchCache.visibleInstances[e]=this._visibleInstances[r],i=Math.max(r,i),n=Math.max(this._visibleInstances.selfDefaultRenderId,i));var o=this._batchCache.visibleInstances[e];if(o&&o.length){if(this._renderIdForInstances[e]===i)return this._batchCache.mustReturn=!0,this._batchCache;i!==n&&(this._batchCache.renderSelf[e]=!1)}this._renderIdForInstances[e]=i}return this._batchCache},r.prototype._renderWithInstances=function(t,i,r,n,o){var s=r.visibleInstances[t._id];if(!s)return this;for(var a=16*(s.length+1)*4,l=this._instancesBufferSize,h=this._instancesBuffer;this._instancesBufferSize<a;)this._instancesBufferSize*=2;this._instancesData&&l==this._instancesBufferSize||(this._instancesData=new Float32Array(this._instancesBufferSize/4));var u=0,c=0,f=this.getWorldMatrix();if(r.renderSelf[t._id]&&(f.copyToArray(this._instancesData,u),u+=16,c++),s)for(var p=0;p<s.length;p++)s[p].getWorldMatrix().copyToArray(this._instancesData,u),u+=16,c++;return h&&l==this._instancesBufferSize?h.updateDirectly(this._instancesData,0,c):(h&&h.dispose(),h=new e.Buffer(o,this._instancesData,!0,16,!1,!0),this._instancesBuffer=h,this.setVerticesBuffer(h.createVertexBuffer("world0",0,4)),this.setVerticesBuffer(h.createVertexBuffer("world1",4,4)),this.setVerticesBuffer(h.createVertexBuffer("world2",8,4)),this.setVerticesBuffer(h.createVertexBuffer("world3",12,4))),this._bind(t,n,i),this._draw(t,i,c),o.unbindInstanceAttributes(),this},r.prototype._processRendering=function(e,t,i,r,n,o,s){var a=this.getScene().getEngine();if(n)this._renderWithInstances(e,i,r,t,a);else{r.renderSelf[e._id]&&(o&&o(!1,this.getWorldMatrix(),s),this._draw(e,i,this._overridenInstanceCount));var l=r.visibleInstances[e._id];if(l)for(var h=0;h<l.length;h++){var u=l[h].getWorldMatrix();o&&o(!0,u,s),this._draw(e,i)}}return this},r.prototype.render=function(t,i){if(this.checkOcclusionQuery(),this._isOccluded)return this;var r=this.getScene(),n=this._getInstancesRenderList(t._id);if(n.mustReturn)return this;if(!this._geometry||!this._geometry.getVertexBuffers()||!this._geometry.getIndexBuffer())return this;this.onBeforeRenderObservable.notifyObservers(this);var o=r.getEngine(),s=o.getCaps().instancedArrays&&null!==n.visibleInstances[t._id]&&void 0!==n.visibleInstances[t._id],a=t.getMaterial();if(!a)return this;if(this._effectiveMaterial=a,this._effectiveMaterial.storeEffectOnSubMeshes){if(!this._effectiveMaterial.isReadyForSubMesh(this,t,s))return this}else if(!this._effectiveMaterial.isReady(this,s))return this;i&&o.setAlphaMode(this._effectiveMaterial.alphaMode);var l=o.getDepthWrite();this.renderOutline&&(o.setDepthWrite(!1),r.getOutlineRenderer().render(t,n),o.setDepthWrite(l));var h;if(!(h=this._effectiveMaterial.storeEffectOnSubMeshes?t.effect:this._effectiveMaterial.getEffect()))return this;var u=this._effectiveMaterial._preBind(h,this.overrideMaterialSideOrientation);this._effectiveMaterial.forceDepthWrite&&o.setDepthWrite(!0);var c=r.forcePointsCloud?e.Material.PointFillMode:r.forceWireframe?e.Material.WireFrameFillMode:this._effectiveMaterial.fillMode;s||this._bind(t,h,c);var f=this.getWorldMatrix();if(this._effectiveMaterial.storeEffectOnSubMeshes?this._effectiveMaterial.bindForSubMesh(f,this,t):this._effectiveMaterial.bind(f,this),!this._effectiveMaterial.backFaceCulling&&this._effectiveMaterial.separateCullingPass&&(o.setState(!0,this._effectiveMaterial.zOffset,!1,!u),this._processRendering(t,h,c,n,s,this._onBeforeDraw,this._effectiveMaterial),o.setState(!0,this._effectiveMaterial.zOffset,!1,u)),this._processRendering(t,h,c,n,s,this._onBeforeDraw,this._effectiveMaterial),this._effectiveMaterial.unbind(),this.renderOutline&&l&&(o.setDepthWrite(!0),o.setColorWrite(!1),r.getOutlineRenderer().render(t,n),o.setColorWrite(!0)),this.renderOverlay){var p=o.getAlphaMode();o.setAlphaMode(e.Engine.ALPHA_COMBINE),r.getOutlineRenderer().render(t,n,!0),o.setAlphaMode(p)}return this.onAfterRenderObservable.notifyObservers(this),this},r.prototype._onBeforeDraw=function(e,t,i){return e&&i.bindOnlyWorldMatrix(t),this},r.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},r.prototype.getHierarchyEmittedParticleSystems=function(){var e=new Array,t=this.getDescendants();t.push(this);for(var i=0;i<this.getScene().particleSystems.length;i++){var r=this.getScene().particleSystems[i],n=r.emitter;n.position&&-1!==t.indexOf(n)&&e.push(r)}return e},r.prototype._checkDelayState=function(){var t=this.getScene();return this._geometry?this._geometry.load(t):this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,this._queueLoad(this,t)),this},r.prototype._queueLoad=function(t,i){var r=this;i._addPendingData(t);var n=-1!==this.delayLoadingFile.indexOf(".babylonbinarymeshdata");return e.Tools.LoadFile(this.delayLoadingFile,function(t){t instanceof ArrayBuffer?r._delayLoadingFunction(t,r):r._delayLoadingFunction(JSON.parse(t),r),r.instances.forEach(function(e){e._syncSubMeshes()}),r.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,i._removePendingData(r)},function(){},i.database,n),this},r.prototype.isInFrustum=function(t){return this.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADING&&(!!i.prototype.isInFrustum.call(this,t)&&(this._checkDelayState(),!0))},r.prototype.setMaterialByID=function(e){var t,i=this.getScene().materials;for(t=i.length-1;t>-1;t--)if(i[t].id===e)return this.material=i[t],this;var r=this.getScene().multiMaterials;for(t=r.length-1;t>-1;t--)if(r[t].id===e)return this.material=r[t],this;return this},r.prototype.getAnimatables=function(){var e=new Array;return this.material&&e.push(this.material),this.skeleton&&e.push(this.skeleton),e},r.prototype.bakeTransformIntoVertices=function(t){if(!this.isVerticesDataPresent(e.VertexBuffer.PositionKind))return this;var i=this.subMeshes.splice(0);this._resetPointsArrayCache();var r,n=this.getVerticesData(e.VertexBuffer.PositionKind),o=new Array;for(r=0;r<n.length;r+=3)e.Vector3.TransformCoordinates(e.Vector3.FromArray(n,r),t).toArray(o,r);if(this.setVerticesData(e.VertexBuffer.PositionKind,o,this.getVertexBuffer(e.VertexBuffer.PositionKind).isUpdatable()),!this.isVerticesDataPresent(e.VertexBuffer.NormalKind))return this;for(n=this.getVerticesData(e.VertexBuffer.NormalKind),o=[],r=0;r<n.length;r+=3)e.Vector3.TransformNormal(e.Vector3.FromArray(n,r),t).normalize().toArray(o,r);return this.setVerticesData(e.VertexBuffer.NormalKind,o,this.getVertexBuffer(e.VertexBuffer.NormalKind).isUpdatable()),t.m[0]*t.m[5]*t.m[10]<0&&this.flipFaces(),this.releaseSubMeshes(),this.subMeshes=i,this},r.prototype.bakeCurrentTransformIntoVertices=function(){return 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(),this},Object.defineProperty(r.prototype,"_positions",{get:function(){return this._geometry?this._geometry._positions:null},enumerable:!0,configurable:!0}),r.prototype._resetPointsArrayCache=function(){return this._geometry&&this._geometry._resetPointsArrayCache(),this},r.prototype._generatePointsArray=function(){return!!this._geometry&&this._geometry._generatePointsArray()},r.prototype.clone=function(e,t,i,n){return void 0===n&&(n=!0),new r(e,this.getScene(),t,this,i,n)},r.prototype.dispose=function(e,t){var r=this;for(void 0===t&&(t=!1),this.morphTargetManager=null,this._geometry&&this._geometry.releaseForMesh(this,!0),this.getScene().meshes.forEach(function(e){e._source&&e._source===r&&(e._source=null)}),this._source=null,this._instancesBuffer&&(this._instancesBuffer.dispose(),this._instancesBuffer=null);this.instances.length;)this.instances[0].dispose();for(var n=this.getScene().highlightLayers,o=0;o<n.length;o++){var s=n[o];s&&(s.removeMesh(this),s.removeExcludedMesh(this))}i.prototype.dispose.call(this,e,t)},r.prototype.applyDisplacementMap=function(t,i,r,n,o,s){var a=this,l=this.getScene();return e.Tools.LoadImage(t,function(e){var t=document.createElement("canvas"),l=t.getContext("2d"),h=e.width,u=e.height;t.width=h,t.height=u,l.drawImage(e,0,0);var c=l.getImageData(0,0,h,u).data;a.applyDisplacementMapFromBuffer(c,h,u,i,r,o,s),n&&n(a)},function(){},l.database),this},r.prototype.applyDisplacementMapFromBuffer=function(t,i,r,n,o,s,a){if(!this.isVerticesDataPresent(e.VertexBuffer.PositionKind)||!this.isVerticesDataPresent(e.VertexBuffer.NormalKind)||!this.isVerticesDataPresent(e.VertexBuffer.UVKind))return e.Tools.Warn("Cannot call applyDisplacementMap: Given mesh is not complete. Position, Normal or UV are missing"),this;var l=this.getVerticesData(e.VertexBuffer.PositionKind),h=this.getVerticesData(e.VertexBuffer.NormalKind),u=this.getVerticesData(e.VertexBuffer.UVKind),c=e.Vector3.Zero(),f=e.Vector3.Zero(),p=e.Vector2.Zero();s=s||e.Vector2.Zero(),a=a||new e.Vector2(1,1);for(var d=0;d<l.length;d+=3){e.Vector3.FromArrayToRef(l,d,c),e.Vector3.FromArrayToRef(h,d,f),e.Vector2.FromArrayToRef(u,d/3*2,p);var m=4*((Math.abs(p.x*a.x+s.x)*i%i|0)+(Math.abs(p.y*a.y+s.y)*r%r|0)*i),g=.3*(t[m]/255)+.59*(t[m+1]/255)+.11*(t[m+2]/255);f.normalize(),f.scaleInPlace(n+(o-n)*g),(c=c.add(f)).toArray(l,d)}return e.VertexData.ComputeNormals(l,this.getIndices(),h),this.updateVerticesData(e.VertexBuffer.PositionKind,l),this.updateVerticesData(e.VertexBuffer.NormalKind,h),this},r.prototype.convertToFlatShadedMesh=function(){var t,i,r=this.getVerticesDataKinds(),n={},o={},s={},a=!1;for(t=0;t<r.length;t++){i=r[t];var l=this.getVertexBuffer(i);i!==e.VertexBuffer.NormalKind?(n[i]=l,o[i]=n[i].getData(),s[i]=[]):(a=l.isUpdatable(),r.splice(t,1),t--)}var h,u=this.subMeshes.slice(0),c=this.getIndices(),f=this.getTotalIndices();for(h=0;h<f;h++){var p=c[h];for(t=0;t<r.length;t++)for(var d=n[i=r[t]].getStrideSize(),m=0;m<d;m++)s[i].push(o[i][p*d+m])}var g=[],v=s[e.VertexBuffer.PositionKind];for(h=0;h<f;h+=3){c[h]=h,c[h+1]=h+1,c[h+2]=h+2;for(var _=e.Vector3.FromArray(v,3*h),y=e.Vector3.FromArray(v,3*(h+1)),x=e.Vector3.FromArray(v,3*(h+2)),b=_.subtract(y),T=x.subtract(y),E=e.Vector3.Normalize(e.Vector3.Cross(b,T)),A=0;A<3;A++)g.push(E.x),g.push(E.y),g.push(E.z)}for(this.setIndices(c),this.setVerticesData(e.VertexBuffer.NormalKind,g,a),t=0;t<r.length;t++)i=r[t],this.setVerticesData(i,s[i],n[i].isUpdatable());this.releaseSubMeshes();for(var P=0;P<u.length;P++){var S=u[P];e.SubMesh.AddToMesh(S.materialIndex,S.indexStart,S.indexCount,S.indexStart,S.indexCount,this)}return this.synchronizeInstances(),this},r.prototype.convertToUnIndexedMesh=function(){var t,i,r=this.getVerticesDataKinds(),n={},o={},s={};for(t=0;t<r.length;t++){i=r[t];var a=this.getVertexBuffer(i);n[i]=a,o[i]=n[i].getData(),s[i]=[]}var l,h=this.subMeshes.slice(0),u=this.getIndices(),c=this.getTotalIndices();for(l=0;l<c;l++){var f=u[l];for(t=0;t<r.length;t++)for(var p=n[i=r[t]].getStrideSize(),d=0;d<p;d++)s[i].push(o[i][f*p+d])}for(l=0;l<c;l+=3)u[l]=l,u[l+1]=l+1,u[l+2]=l+2;for(this.setIndices(u),t=0;t<r.length;t++)i=r[t],this.setVerticesData(i,s[i],n[i].isUpdatable());this.releaseSubMeshes();for(var m=0;m<h.length;m++){var g=h[m];e.SubMesh.AddToMesh(g.materialIndex,g.indexStart,g.indexCount,g.indexStart,g.indexCount,this)}return this._unIndexed=!0,this.synchronizeInstances(),this},r.prototype.flipFaces=function(t){void 0===t&&(t=!1);var i,r=e.VertexData.ExtractFromMesh(this);if(t&&this.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&r.normals)for(i=0;i<r.normals.length;i++)r.normals[i]*=-1;if(r.indices){var n;for(i=0;i<r.indices.length;i+=3)n=r.indices[i+1],r.indices[i+1]=r.indices[i+2],r.indices[i+2]=n}return r.applyToMesh(this),this},r.prototype.createInstance=function(t){return new e.InstancedMesh(t,this)},r.prototype.synchronizeInstances=function(){for(var e=0;e<this.instances.length;e++)this.instances[e]._syncSubMeshes();return this},r.prototype.simplify=function(t,i,r,n){return void 0===i&&(i=!0),void 0===r&&(r=e.SimplificationType.QUADRATIC),this.getScene().simplificationQueue.addTask({settings:t,parallelProcessing:i,mesh:this,simplificationType:r,successCallback:n}),this},r.prototype.optimizeIndices=function(t){var i=this,r=this.getIndices(),n=this.getVerticesData(e.VertexBuffer.PositionKind);if(!n||!r)return this;for(var o=new Array,s=0;s<n.length;s+=3)o.push(e.Vector3.FromArray(n,s));var a=new Array;return e.AsyncLoop.SyncAsyncForLoop(o.length,40,function(e){for(var t=o.length-1-e,i=o[t],r=0;r<t;++r){var n=o[r];if(i.equals(n)){a[t]=r;break}}},function(){for(var e=0;e<r.length;++e)r[e]=a[r[e]]||r[e];var n=i.subMeshes.slice(0);i.setIndices(r),i.subMeshes=n,t&&t(i)}),this},r.prototype.serialize=function(t){t.name=this.name,t.id=this.id,t.type=this.getClassName(),e.Tags&&e.Tags.HasTags(this)&&(t.tags=e.Tags.GetTags(this)),t.position=this.position.asArray(),this.rotationQuaternion?t.rotationQuaternion=this.rotationQuaternion.asArray():this.rotation&&(t.rotation=this.rotation.asArray()),t.scaling=this.scaling.asArray(),t.localMatrix=this.getPivotMatrix().asArray(),t.isEnabled=this.isEnabled(),t.isVisible=this.isVisible,t.infiniteDistance=this.infiniteDistance,t.pickable=this.isPickable,t.receiveShadows=this.receiveShadows,t.billboardMode=this.billboardMode,t.visibility=this.visibility,t.checkCollisions=this.checkCollisions,t.isBlocker=this.isBlocker,this.parent&&(t.parentId=this.parent.id);var i=this._geometry;if(i){var r=i.id;t.geometryId=r,t.subMeshes=[];for(var n=0;n<this.subMeshes.length;n++){var o=this.subMeshes[n];t.subMeshes.push({materialIndex:o.materialIndex,verticesStart:o.verticesStart,verticesCount:o.verticesCount,indexStart:o.indexStart,indexCount:o.indexCount})}}this.material?t.materialId=this.material.id:this.material=null,this.morphTargetManager&&(t.morphTargetManagerId=this.morphTargetManager.uniqueId),this.skeleton&&(t.skeletonId=this.skeleton.id);var s=this.getPhysicsImpostor();s&&(t.physicsMass=s.getParam("mass"),t.physicsFriction=s.getParam("friction"),t.physicsRestitution=s.getParam("mass"),t.physicsImpostor=s.type),this.metadata&&(t.metadata=this.metadata),t.instances=[];for(var a=0;a<this.instances.length;a++){var l=this.instances[a],h={name:l.name,position:l.position.asArray(),scaling:l.scaling.asArray()};l.rotationQuaternion?h.rotationQuaternion=l.rotationQuaternion.asArray():l.rotation&&(h.rotation=l.rotation.asArray()),t.instances.push(h),e.Animation.AppendSerializedAnimations(l,h),h.ranges=l.serializeAnimationRanges()}e.Animation.AppendSerializedAnimations(this,t),t.ranges=this.serializeAnimationRanges(),t.layerMask=this.layerMask,t.alphaIndex=this.alphaIndex,t.hasVertexAlpha=this.hasVertexAlpha,t.overlayAlpha=this.overlayAlpha,t.overlayColor=this.overlayColor.asArray(),t.renderOverlay=this.renderOverlay,t.applyFog=this.applyFog,this.actionManager&&(t.actions=this.actionManager.serialize(this.name))},r.prototype._syncGeometryWithMorphTargetManager=function(){if(this.geometry){this._markSubMeshesAsAttributesDirty();var t=this._morphTargetManager;if(t&&t.vertexCount){if(t.vertexCount!==this.getTotalVertices())return e.Tools.Error("Mesh is incompatible with morph targets. Targets and mesh must all have the same vertices count."),void(this.morphTargetManager=null);for(s=0;s<t.numInfluencers;s++){var i=t.getActiveTarget(s),r=i.getPositions();if(!r)return void e.Tools.Error("Invalid morph target. Target must have positions.");this.geometry.setVerticesData(e.VertexBuffer.PositionKind+s,r,!1,3);var n=i.getNormals();n&&this.geometry.setVerticesData(e.VertexBuffer.NormalKind+s,n,!1,3);var o=i.getTangents();o&&this.geometry.setVerticesData(e.VertexBuffer.TangentKind+s,o,!1,3)}}else for(var s=0;this.geometry.isVerticesDataPresent(e.VertexBuffer.PositionKind+s);)this.geometry.removeVerticesData(e.VertexBuffer.PositionKind+s),this.geometry.isVerticesDataPresent(e.VertexBuffer.NormalKind+s)&&this.geometry.removeVerticesData(e.VertexBuffer.NormalKind+s),this.geometry.isVerticesDataPresent(e.VertexBuffer.TangentKind+s)&&this.geometry.removeVerticesData(e.VertexBuffer.TangentKind+s),s++}},r.Parse=function(t,i,n){var o;if(o=t.type&&"GroundMesh"===t.type?e.GroundMesh.Parse(t,i):new r(t.name,i),o.id=t.id,e.Tags&&e.Tags.AddTagsTo(o,t.tags),o.position=e.Vector3.FromArray(t.position),void 0!==t.metadata&&(o.metadata=t.metadata),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,void 0!==t.isBlocker&&(o.isBlocker=t.isBlocker),o._shouldGenerateFlatShading=t.useFlatShading,t.freezeWorldMatrix&&(o._waitingFreezeWorldMatrix=t.freezeWorldMatrix),t.parentId&&(o._waitingParentId=t.parentId),void 0!==t.actions&&(o._waitingActions=t.actions),void 0!==t.overlayAlpha&&(o.overlayAlpha=t.overlayAlpha),void 0!==t.overlayColor&&(o.overlayColor=e.Color3.FromArray(t.overlayColor)),void 0!==t.renderOverlay&&(o.renderOverlay=t.renderOverlay),o.hasVertexAlpha=t.hasVertexAlpha,t.delayLoadingFile?(o.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,o.delayLoadingFile=n+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.morphTargetManagerId>-1&&(o.morphTargetManager=i.getMorphTargetManagerById(t.morphTargetManagerId)),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 l=0;l<t.instances.length;l++){var h=t.instances[l],u=o.createInstance(h.name);if(e.Tags&&e.Tags.AddTagsTo(u,h.tags),u.position=e.Vector3.FromArray(h.position),h.parentId&&(u._waitingParentId=h.parentId),h.rotationQuaternion?u.rotationQuaternion=e.Quaternion.FromArray(h.rotationQuaternion):h.rotation&&(u.rotation=e.Vector3.FromArray(h.rotation)),u.scaling=e.Vector3.FromArray(h.scaling),u.checkCollisions=o.checkCollisions,t.animations){for(s=0;s<t.animations.length;s++)a=t.animations[s],u.animations.push(e.Animation.Parse(a));e.Node.ParseAnimationRanges(u,t,i)}}return o},r.CreateRibbon=function(t,i,r,n,o,s,a,l,h){return void 0===r&&(r=!1),void 0===a&&(a=!1),e.MeshBuilder.CreateRibbon(t,{pathArray:i,closeArray:r,closePath:n,offset:o,updatable:a,sideOrientation:l,instance:h},s)},r.CreateDisc=function(t,i,r,n,o,s){void 0===n&&(n=null);var a={radius:i,tessellation:r,sideOrientation:s,updatable:o};return e.MeshBuilder.CreateDisc(t,a,n)},r.CreateBox=function(t,i,r,n,o){void 0===r&&(r=null);var s={size:i,sideOrientation:o,updatable:n};return e.MeshBuilder.CreateBox(t,s,r)},r.CreateSphere=function(t,i,r,n,o,s){var a={segments:i,diameterX:r,diameterY:r,diameterZ:r,sideOrientation:s,updatable:o};return e.MeshBuilder.CreateSphere(t,a,n)},r.CreateCylinder=function(t,i,n,o,s,a,l,h,u){void 0!==l&&l instanceof e.Scene||(void 0!==l&&(u=h||r.DEFAULTSIDE,h=l),l=a,a=1);var c={height:i,diameterTop:n,diameterBottom:o,tessellation:s,subdivisions:a,sideOrientation:u,updatable:h};return e.MeshBuilder.CreateCylinder(t,c,l)},r.CreateTorus=function(t,i,r,n,o,s,a){var l={diameter:i,thickness:r,tessellation:n,sideOrientation:a,updatable:s};return e.MeshBuilder.CreateTorus(t,l,o)},r.CreateTorusKnot=function(t,i,r,n,o,s,a,l,h,u){var c={radius:i,tube:r,radialSegments:n,tubularSegments:o,p:s,q:a,sideOrientation:u,updatable:h};return e.MeshBuilder.CreateTorusKnot(t,c,l)},r.CreateLines=function(t,i,r,n,o){void 0===r&&(r=null),void 0===n&&(n=!1),void 0===o&&(o=null);var s={points:i,updatable:n,instance:o};return e.MeshBuilder.CreateLines(t,s,r)},r.CreateDashedLines=function(t,i,r,n,o,s,a,l){void 0===s&&(s=null);var h={points:i,dashSize:r,gapSize:n,dashNb:o,updatable:a,instance:l};return e.MeshBuilder.CreateDashedLines(t,h,s)},r.CreatePolygon=function(t,i,r,n,o,s){var a={shape:i,holes:n,updatable:o,sideOrientation:s};return e.MeshBuilder.CreatePolygon(t,a,r)},r.ExtrudePolygon=function(t,i,r,n,o,s,a){var l={shape:i,holes:o,depth:r,updatable:s,sideOrientation:a};return e.MeshBuilder.ExtrudePolygon(t,l,n)},r.ExtrudeShape=function(t,i,n,o,s,a,l,h,u,c){void 0===l&&(l=null);var f={shape:i,path:n,scale:o,rotation:s,cap:0===a?0:a||r.NO_CAP,sideOrientation:u,instance:c,updatable:h};return e.MeshBuilder.ExtrudeShape(t,f,l)},r.ExtrudeShapeCustom=function(t,i,n,o,s,a,l,h,u,c,f,p){var d={shape:i,path:n,scaleFunction:o,rotationFunction:s,ribbonCloseArray:a,ribbonClosePath:l,cap:0===h?0:h||r.NO_CAP,sideOrientation:f,instance:p,updatable:c};return e.MeshBuilder.ExtrudeShapeCustom(t,d,u)},r.CreateLathe=function(t,i,r,n,o,s,a){var l={shape:i,radius:r,tessellation:n,sideOrientation:a,updatable:s};return e.MeshBuilder.CreateLathe(t,l,o)},r.CreatePlane=function(t,i,r,n,o){var s={size:i,width:i,height:i,sideOrientation:o,updatable:n};return e.MeshBuilder.CreatePlane(t,s,r)},r.CreateGround=function(t,i,r,n,o,s){var a={width:i,height:r,subdivisions:n,updatable:s};return e.MeshBuilder.CreateGround(t,a,o)},r.CreateTiledGround=function(t,i,r,n,o,s,a,l,h){var u={xmin:i,zmin:r,xmax:n,zmax:o,subdivisions:s,precision:a,updatable:h};return e.MeshBuilder.CreateTiledGround(t,u,l)},r.CreateGroundFromHeightMap=function(t,i,r,n,o,s,a,l,h,u){var c={width:r,height:n,subdivisions:o,minHeight:s,maxHeight:a,updatable:h,onReady:u};return e.MeshBuilder.CreateGroundFromHeightMap(t,i,c,l)},r.CreateTube=function(t,i,r,n,o,s,a,l,h,u){var c={path:i,radius:r,tessellation:n,radiusFunction:o,arc:1,cap:s,updatable:l,sideOrientation:h,instance:u};return e.MeshBuilder.CreateTube(t,c,a)},r.CreatePolyhedron=function(t,i,r){return e.MeshBuilder.CreatePolyhedron(t,i,r)},r.CreateIcoSphere=function(t,i,r){return e.MeshBuilder.CreateIcoSphere(t,i,r)},r.CreateDecal=function(t,i,r,n,o,s){var a={position:r,normal:n,size:o,angle:s};return e.MeshBuilder.CreateDecal(t,i,a)},r.prototype.setPositionsForCPUSkinning=function(){if(!this._sourcePositions){var t=this.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return this._sourcePositions;this._sourcePositions=new Float32Array(t),this.isVertexBufferUpdatable(e.VertexBuffer.PositionKind)||this.setVerticesData(e.VertexBuffer.PositionKind,t,!0)}return this._sourcePositions},r.prototype.setNormalsForCPUSkinning=function(){if(!this._sourceNormals){var t=this.getVerticesData(e.VertexBuffer.NormalKind);if(!t)return this._sourceNormals;this._sourceNormals=new Float32Array(t),this.isVertexBufferUpdatable(e.VertexBuffer.NormalKind)||this.setVerticesData(e.VertexBuffer.NormalKind,t,!0)}return this._sourceNormals},r.prototype.applySkeleton=function(t){if(!this.geometry)return this;if(this.geometry._softwareSkinningRenderId==this.getScene().getRenderId())return this;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;if(!this._sourcePositions){var i=this.subMeshes.slice();this.setPositionsForCPUSkinning(),this.subMeshes=i}this._sourceNormals||this.setNormalsForCPUSkinning();var r=this.getVerticesData(e.VertexBuffer.PositionKind);if(!r)return this;r instanceof Float32Array||(r=new Float32Array(r));var n=this.getVerticesData(e.VertexBuffer.NormalKind);if(!n)return this;n instanceof Float32Array||(n=new Float32Array(n));var o=this.getVerticesData(e.VertexBuffer.MatricesIndicesKind),s=this.getVerticesData(e.VertexBuffer.MatricesWeightsKind);if(!s||!o)return this;var a=this.numBoneInfluencers>4,l=a?this.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind):null,h=a?this.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind):null;if(!h||!l)return this;for(var u,c=t.getTransformMatrices(this),f=e.Vector3.Zero(),p=new e.Matrix,d=new e.Matrix,m=0,g=0;g<r.length;g+=3,m+=4){var v;for(u=0;u<4&&(v=s[m+u])>0;u++)e.Matrix.FromFloat32ArrayToRefScaled(c,16*o[m+u],v,d),p.addToSelf(d);if(a)for(u=0;u<4&&(v=h[m+u])>0;u++)e.Matrix.FromFloat32ArrayToRefScaled(c,16*l[m+u],v,d),p.addToSelf(d);e.Vector3.TransformCoordinatesFromFloatsToRef(this._sourcePositions[g],this._sourcePositions[g+1],this._sourcePositions[g+2],p,f),f.toArray(r,g),e.Vector3.TransformNormalFromFloatsToRef(this._sourceNormals[g],this._sourceNormals[g+1],this._sourceNormals[g+2],p,f),f.toArray(n,g),p.reset()}return this.updateVerticesData(e.VertexBuffer.PositionKind,r),this.updateVerticesData(e.VertexBuffer.NormalKind,n),this},r.MinMax=function(t){var i=null,r=null;return t.forEach(function(e,t,n){var o=e.getBoundingInfo();if(o){var s=o.boundingBox;i&&r?(i.MinimizeInPlace(s.minimumWorld),r.MaximizeInPlace(s.maximumWorld)):(i=s.minimumWorld,r=s.maximumWorld)}}),i&&r?{min:i,max:r}:{min:e.Vector3.Zero(),max:e.Vector3.Zero()}},r.Center=function(t){var i=t instanceof Array?e.Mesh.MinMax(t):t;return e.Vector3.Center(i.min,i.max)},r.MergeMeshes=function(t,i,n,o,s){void 0===i&&(i=!0);var a;if(!n){var l=0;for(a=0;a<t.length;a++)if(t[a]&&(l+=t[a].getTotalVertices())>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,u=null,c=new Array,f=null;for(a=0;a<t.length;a++)t[a]&&(t[a].computeWorldMatrix(!0),(h=e.VertexData.ExtractFromMesh(t[a],!0)).transform(t[a].getWorldMatrix()),u?u.merge(h):(u=h,f=t[a]),s&&c.push(t[a].getTotalIndices()));if(f=f,o||(o=new r(f.name+"_merged",f.getScene())),u.applyToMesh(o),o.material=f.material,o.checkCollisions=f.checkCollisions,i)for(a=0;a<t.length;a++)t[a]&&t[a].dispose();if(s){o.releaseSubMeshes(),a=0;for(var p=0;a<c.length;)e.SubMesh.CreateFromIndices(0,p,c[a],o),p+=c[a],a++}return o},r._FRONTSIDE=0,r._BACKSIDE=1,r._DOUBLESIDE=2,r._DEFAULTSIDE=0,r._NO_CAP=0,r._CAP_START=1,r._CAP_END=2,r._CAP_ALL=3,r}(e.AbstractMesh);e.Mesh=i}(s||(s={}));!function(e){var t=function(){function e(){}return Object.defineProperty(e.prototype,"effect",{get:function(){return this._materialEffect},enumerable:!0,configurable:!0}),e.prototype.setEffect=function(e,t){void 0===t&&(t=null),this._materialEffect!==e?(this._materialDefines=t,this._materialEffect=e):e||(this._materialDefines=null)},e}();e.BaseSubMesh=t;var i=function(t){function i(e,i,r,n,o,s,a,l){void 0===l&&(l=!0);var h=t.call(this)||this;return h.materialIndex=e,h.verticesStart=i,h.verticesCount=r,h.indexStart=n,h.indexCount=o,h._renderId=0,h._mesh=s,h._renderingMesh=a||s,s.subMeshes.push(h),h._trianglePlanes=[],h._id=s.subMeshes.length-1,l&&(h.refreshBoundingInfo(),s.computeWorldMatrix(!0)),h}return n(i,t),i.AddToMesh=function(e,t,r,n,o,s,a,l){return void 0===l&&(l=!0),new i(e,t,r,n,o,s,a,l)},Object.defineProperty(i.prototype,"IsGlobal",{get:function(){return 0===this.verticesStart&&this.verticesCount==this._mesh.getTotalVertices()},enumerable:!0,configurable:!0}),i.prototype.getBoundingInfo=function(){return this.IsGlobal?this._mesh.getBoundingInfo():this._boundingInfo},i.prototype.setBoundingInfo=function(e){return this._boundingInfo=e,this},i.prototype.getMesh=function(){return this._mesh},i.prototype.getRenderingMesh=function(){return this._renderingMesh},i.prototype.getMaterial=function(){var e=this._renderingMesh.material;if(e&&e.getSubMaterial){var t=e.getSubMaterial(this.materialIndex);return this._currentMaterial!==t&&(this._currentMaterial=t,this._materialDefines=null),t}return e||this._mesh.getScene().defaultMaterial},i.prototype.refreshBoundingInfo=function(){if(this._lastColliderWorldVertices=null,this.IsGlobal||!this._renderingMesh||!this._renderingMesh.geometry)return this;var t=this._renderingMesh.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return this._boundingInfo=this._mesh._boundingInfo,this;var i,r=this._renderingMesh.getIndices();if(0===this.indexStart&&this.indexCount===r.length){var n=this._renderingMesh.getBoundingInfo();if(!n)return this;i={minimum:n.minimum.clone(),maximum:n.maximum.clone()}}else i=e.Tools.ExtractMinAndMaxIndexed(t,r,this.indexStart,this.indexCount,this._renderingMesh.geometry.boundingBias);return this._boundingInfo=new e.BoundingInfo(i.minimum,i.maximum),this},i.prototype._checkCollision=function(e){var t=this._renderingMesh.getBoundingInfo();return!!t&&t._checkCollision(e)},i.prototype.updateBoundingInfo=function(e){var t=this.getBoundingInfo();return t||(this.refreshBoundingInfo(),t=this.getBoundingInfo()),t.update(e),this},i.prototype.isInFrustum=function(e){var t=this.getBoundingInfo();return!!t&&t.isInFrustum(e)},i.prototype.isCompletelyInFrustum=function(e){var t=this.getBoundingInfo();return!!t&&t.isCompletelyInFrustum(e)},i.prototype.render=function(e){return this._renderingMesh.render(this,e),this},i.prototype.getLinesIndexBuffer=function(e,t){if(!this._linesIndexBuffer){for(var i=[],r=this.indexStart;r<this.indexStart+this.indexCount;r+=3)i.push(e[r],e[r+1],e[r+1],e[r+2],e[r+2],e[r]);this._linesIndexBuffer=t.createIndexBuffer(i),this.linesIndexCount=i.length}return this._linesIndexBuffer},i.prototype.canIntersects=function(e){var t=this.getBoundingInfo();return!!t&&e.intersectsBox(t.boundingBox)},i.prototype.intersects=function(t,i,r,n){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 l=i[r[a]],h=i[r[a+1]],u=t.intersectionSegment(l,h,s.intersectionThreshold);if(!(u<0)&&((n||!o||u<o.distance)&&(o=new e.IntersectionInfo(null,null,u),n)))break}else for(a=this.indexStart;a<this.indexStart+this.indexCount;a+=3){var l=i[r[a]],h=i[r[a+1]],c=i[r[a+2]],f=t.intersectsTriangle(l,h,c);if(f){if(f.distance<0)continue;if((n||!o||f.distance<o.distance)&&(o=f,o.faceId=a/3,n))break}}return o},i.prototype._rebuild=function(){this._linesIndexBuffer&&(this._linesIndexBuffer=null)},i.prototype.clone=function(t,r){var n=new i(this.materialIndex,this.verticesStart,this.verticesCount,this.indexStart,this.indexCount,t,r,!1);if(!this.IsGlobal){var o=this.getBoundingInfo();if(!o)return n;n._boundingInfo=new e.BoundingInfo(o.minimum,o.maximum)}return n},i.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)},i.CreateFromIndices=function(e,t,r,n,o){for(var s=Number.MAX_VALUE,a=-Number.MAX_VALUE,l=(o=o||n).getIndices(),h=t;h<t+r;h++){var u=l[h];u<s&&(s=u),u>a&&(a=u)}return new i(e,s,a-s+1,t,r,n,o)},i}(t);e.SubMesh=i}(s||(s={}));!function(e){var t=function(){function t(){this._defines={},this._currentRank=32,this._maxRank=-1}return t.prototype.unBindMesh=function(){this._mesh=null},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._currentRank&&(this._currentRank=e),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){if(this._mesh&&this._mesh.computeBonesUsingShaders&&this._mesh.numBoneInfluencers>0){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);for(var i=this._mesh.getScene(),r=0;r<i.meshes.length;r++){var n=i.meshes[r];n.material===this._mesh.material&&n.computeBonesUsingShaders&&n.numBoneInfluencers>0&&(n.computeBonesUsingShaders=!1)}}else{var o=this._defines[this._currentRank];if(o)for(r=0;r<o.length;r++)t=t.replace("#define "+o[r],"");this._currentRank++}return t},t}();e.EffectFallbacks=t;var i=function(){return function(){}}();e.EffectCreationOptions=i;var r=function(){function t(i,r,n,o,s,a,l,h,u,c){void 0===o&&(o=null),void 0===a&&(a=null),void 0===l&&(l=null),void 0===h&&(h=null),void 0===u&&(u=null);var f=this;if(this.uniqueId=0,this.onCompileObservable=new e.Observable,this.onErrorObservable=new e.Observable,this.onBindObservable=new e.Observable,this._uniformBuffersNames={},this._isReady=!1,this._compilationError="",this.name=i,r.attributes){var p=r;if(this._engine=n,this._attributesNames=p.attributes,this._uniformsNames=p.uniformsNames.concat(p.samplers),this._samplers=p.samplers,this.defines=p.defines,this.onError=p.onError,this.onCompiled=p.onCompiled,this._fallbacks=p.fallbacks,this._indexParameters=p.indexParameters,this._transformFeedbackVaryings=p.transformFeedbackVaryings,p.uniformBuffersNames)for(var d=0;d<p.uniformBuffersNames.length;d++)this._uniformBuffersNames[p.uniformBuffersNames[d]]=d}else this._engine=s,this.defines=a,this._uniformsNames=n.concat(o),this._samplers=o,this._attributesNames=r,this.onError=u,this.onCompiled=h,this._indexParameters=c,this._fallbacks=l;this.uniqueId=t._uniqueIdSeed++;var m,g;i.vertexElement?(m=document.getElementById(i.vertexElement))||(m=i.vertexElement):m=i.vertex||i,i.fragmentElement?(g=document.getElementById(i.fragmentElement))||(g=i.fragmentElement):g=i.fragment||i,this._loadVertexShader(m,function(e){f._processIncludes(e,function(e){f._processShaderConversion(e,!1,function(e){f._loadFragmentShader(g,function(t){f._processIncludes(t,function(t){f._processShaderConversion(t,!0,function(t){if(i){var r=i.vertexElement||i.vertex||i,n=i.fragmentElement||i.fragment||i;f._vertexSourceCode="#define SHADER_NAME vertex:"+r+"\n"+e,f._fragmentSourceCode="#define SHADER_NAME fragment:"+n+"\n"+t}else f._vertexSourceCode=e,f._fragmentSourceCode=t;f._prepareEffect()})})})})})})}return Object.defineProperty(t.prototype,"key",{get:function(){return this._key},enumerable:!0,configurable:!0}),t.prototype.isReady=function(){return this._isReady},t.prototype.getEngine=function(){return this._engine},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.executeWhenCompiled=function(e){this.isReady()?e(this):this.onCompileObservable.add(function(t){e(t)})},t.prototype._loadVertexShader=function(i,r){if(e.Tools.IsWindowObjectExist()&&i instanceof HTMLElement)r(e.Tools.GetDOMTextContent(i));else if("base64:"!==i.substr(0,7))if(t.ShadersStore[i+"VertexShader"])r(t.ShadersStore[i+"VertexShader"]);else{var n;n="."===i[0]||"/"===i[0]||i.indexOf("http")>-1?i:e.Engine.ShadersRepository+i,e.Tools.LoadFile(n+".vertex.fx",r)}else r(window.atob(i.substr(7)))},t.prototype._loadFragmentShader=function(i,r){if(e.Tools.IsWindowObjectExist()&&i instanceof HTMLElement)r(e.Tools.GetDOMTextContent(i));else if("base64:"!==i.substr(0,7))if(t.ShadersStore[i+"PixelShader"])r(t.ShadersStore[i+"PixelShader"]);else if(t.ShadersStore[i+"FragmentShader"])r(t.ShadersStore[i+"FragmentShader"]);else{var n;n="."===i[0]||"/"===i[0]||i.indexOf("http")>-1?i:e.Engine.ShadersRepository+i,e.Tools.LoadFile(n+".fragment.fx",r)}else r(window.atob(i.substr(7)))},t.prototype._dumpShadersSource=function(t,i,r){var n=(this._engine.webGLVersion>1?"#version 300 es\n":"")+(r?r+"\n":"");i=n+i;var o=2,s=/\n/gm,a="\n1\t"+(t=n+t).replace(s,function(){return"\n"+o+++"\t"});o=2;var l="\n1\t"+i.replace(s,function(){return"\n"+o+++"\t"});this.name.vertexElement?(e.Tools.Error("Vertex shader: "+this.name.vertexElement+a),e.Tools.Error("Fragment shader: "+this.name.fragmentElement+l)):this.name.vertex?(e.Tools.Error("Vertex shader: "+this.name.vertex+a),e.Tools.Error("Fragment shader: "+this.name.fragment+l)):(e.Tools.Error("Vertex shader: "+this.name+a),e.Tools.Error("Fragment shader: "+this.name+l))},t.prototype._processShaderConversion=function(e,t,i){var r=this._processPrecision(e);if(1!=this._engine.webGLVersion)if(-1===r.indexOf("#version 3")){var n=-1!==r.search(/#extension.+GL_EXT_draw_buffers.+require/),o=r.replace(/#extension.+(GL_OES_standard_derivatives|GL_EXT_shader_texture_lod|GL_EXT_frag_depth|GL_EXT_draw_buffers).+(enable|require)/g,"");o=(o=(o=o.replace(/varying(?![\n\r])\s/g,t?"in ":"out ")).replace(/attribute[ \t]/g,"in ")).replace(/[ \t]attribute/g," in"),t&&(o=(o=(o=(o=(o=(o=(o=(o=o.replace(/texture2DLodEXT\s*\(/g,"textureLod(")).replace(/textureCubeLodEXT\s*\(/g,"textureLod(")).replace(/texture2D\s*\(/g,"texture(")).replace(/textureCube\s*\(/g,"texture(")).replace(/gl_FragDepthEXT/g,"gl_FragDepth")).replace(/gl_FragColor/g,"glFragColor")).replace(/gl_FragData/g,"glFragData")).replace(/void\s+?main\s*\(/g,(n?"":"out vec4 glFragColor;\n")+"void main(")),i(o)}else i(r.replace("#version 300 es",""));else i(r)},t.prototype._processIncludes=function(i,r){for(var n=this,o=/#include<(.+)>(\((.*)\))*(\[(.*)\])*/g,s=o.exec(i),a=new String(i);null!=s;){var l=s[1];if(-1!==l.indexOf("__decl__")&&(l=l.replace(/__decl__/,""),this._engine.supportsUniformBuffers&&(l=l.replace(/Vertex/,"Ubo"),l=l.replace(/Fragment/,"Ubo")),l+="Declaration"),!t.IncludesShadersStore[l]){var h=e.Engine.ShadersRepository+"ShadersInclude/"+l+".fx";return void e.Tools.LoadFile(h,function(e){t.IncludesShadersStore[l]=e,n._processIncludes(a,r)})}var u=t.IncludesShadersStore[l];if(s[2])for(var c=s[3].split(","),f=0;f<c.length;f+=2){var p=new RegExp(c[f],"g"),d=c[f+1];u=u.replace(p,d)}if(s[4]){var m=s[5];if(-1!==m.indexOf("..")){var g=m.split(".."),v=parseInt(g[0]),_=parseInt(g[1]),y=u.slice(0);u="",isNaN(_)&&(_=this._indexParameters[g[1]]);for(var x=v;x<_;x++)this._engine.supportsUniformBuffers||(y=y.replace(/light\{X\}.(\w*)/g,function(e,t){return t+"{X}"})),u+=y.replace(/\{X\}/g,x.toString())+"\n"}else this._engine.supportsUniformBuffers||(u=u.replace(/light\{X\}.(\w*)/g,function(e,t){return t+"{X}"})),u=u.replace(/\{X\}/g,m)}a=a.replace(s[0],u),s=o.exec(i)}r(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._rebuildProgram=function(t,i,r,n){var o=this;this._isReady=!1,this._vertexSourceCodeOverride=t,this._fragmentSourceCodeOverride=i,this.onError=function(e,t){n&&n(t)},this.onCompiled=function(){for(var t=o.getEngine().scenes,i=0;i<t.length;i++)t[i].markAllMaterialsAsDirty(e.Material.TextureDirtyFlag);r&&r(o._program)},this._fallbacks=null,this._prepareEffect()},t.prototype._prepareEffect=function(){var t=this._attributesNames,i=this.defines,r=this._fallbacks;this._valueCache={};var n=this._program;try{var o=this._engine;if(this._vertexSourceCodeOverride&&this._fragmentSourceCodeOverride?this._program=o.createRawShaderProgram(this._vertexSourceCodeOverride,this._fragmentSourceCodeOverride,void 0,this._transformFeedbackVaryings):this._program=o.createShaderProgram(this._vertexSourceCode,this._fragmentSourceCode,i,void 0,this._transformFeedbackVaryings),this._program.__SPECTOR_rebuildProgram=this._rebuildProgram.bind(this),o.webGLVersion>1)for(var s in this._uniformBuffersNames)this.bindUniformBlock(s,this._uniformBuffersNames[s]);this._uniforms=o.getUniforms(this._program,this._uniformsNames),this._attributes=o.getAttributes(this._program,t);var a;for(a=0;a<this._samplers.length;a++)null==this.getUniform(this._samplers[a])&&(this._samplers.splice(a,1),a--);o.bindSamplers(this),this._compilationError="",this._isReady=!0,this.onCompiled&&this.onCompiled(this),this.onCompileObservable.notifyObservers(this),this.onCompileObservable.clear(),this._fallbacks&&this._fallbacks.unBindMesh(),n&&this.getEngine()._deleteProgram(n)}catch(o){this._compilationError=o.message,e.Tools.Error("Unable to compile effect:"),e.Tools.Error("Uniforms: "+this._uniformsNames.map(function(e){return" "+e})),e.Tools.Error("Attributes: "+t.map(function(e){return" "+e})),this._dumpShadersSource(this._vertexSourceCode,this._fragmentSourceCode,i),e.Tools.Error("Error: "+this._compilationError),n&&(this._program=n,this._isReady=!0,this.onError&&this.onError(this,this._compilationError),this.onErrorObservable.notifyObservers(this)),r&&r.isMoreFallbacks?(e.Tools.Error("Trying next fallback."),this.defines=r.reduce(this.defines),this._prepareEffect()):(this.onError&&this.onError(this,this._compilationError),this.onErrorObservable.notifyObservers(this),this.onErrorObservable.clear(),this._fallbacks&&this._fallbacks.unBindMesh())}},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),this.getUniform(e),t)},t.prototype.setTextureArray=function(e,t){if(-1===this._samplers.indexOf(e+"Ex"))for(var i=this._samplers.indexOf(e),r=1;r<t.length;r++)this._samplers.splice(i+r,0,e+"Ex");this._engine.setTextureArray(this._samplers.indexOf(e),this.getUniform(e),t)},t.prototype.setTextureFromPostProcess=function(e,t){this._engine.setTextureFromPostProcess(this._samplers.indexOf(e),t)},t.prototype._cacheMatrix=function(e,t){var i=this._valueCache[e],r=t.updateFlag;return(void 0===i||i!==r)&&(this._valueCache[e]=r,!0)},t.prototype._cacheFloat2=function(e,t,i){var r=this._valueCache[e];if(!r)return r=[t,i],this._valueCache[e]=r,!0;var n=!1;return r[0]!==t&&(r[0]=t,n=!0),r[1]!==i&&(r[1]=i,n=!0),n},t.prototype._cacheFloat3=function(e,t,i,r){var n=this._valueCache[e];if(!n)return n=[t,i,r],this._valueCache[e]=n,!0;var o=!1;return n[0]!==t&&(n[0]=t,o=!0),n[1]!==i&&(n[1]=i,o=!0),n[2]!==r&&(n[2]=r,o=!0),o},t.prototype._cacheFloat4=function(e,t,i,r,n){var o=this._valueCache[e];if(!o)return o=[t,i,r,n],this._valueCache[e]=o,!0;var s=!1;return o[0]!==t&&(o[0]=t,s=!0),o[1]!==i&&(o[1]=i,s=!0),o[2]!==r&&(o[2]=r,s=!0),o[3]!==n&&(o[3]=n,s=!0),s},t.prototype.bindUniformBuffer=function(e,i){var r=this._uniformBuffersNames[i];t._baseCache[r]!==e&&(t._baseCache[r]=e,this._engine.bindUniformBufferBase(e,r))},t.prototype.bindUniformBlock=function(e,t){this._engine.bindUniformBlock(this._program,e,t)},t.prototype.setIntArray=function(e,t){return this._valueCache[e]=null,this._engine.setIntArray(this.getUniform(e),t),this},t.prototype.setIntArray2=function(e,t){return this._valueCache[e]=null,this._engine.setIntArray2(this.getUniform(e),t),this},t.prototype.setIntArray3=function(e,t){return this._valueCache[e]=null,this._engine.setIntArray3(this.getUniform(e),t),this},t.prototype.setIntArray4=function(e,t){return this._valueCache[e]=null,this._engine.setIntArray4(this.getUniform(e),t),this},t.prototype.setFloatArray=function(e,t){return this._valueCache[e]=null,this._engine.setFloatArray(this.getUniform(e),t),this},t.prototype.setFloatArray2=function(e,t){return this._valueCache[e]=null,this._engine.setFloatArray2(this.getUniform(e),t),this},t.prototype.setFloatArray3=function(e,t){return this._valueCache[e]=null,this._engine.setFloatArray3(this.getUniform(e),t),this},t.prototype.setFloatArray4=function(e,t){return this._valueCache[e]=null,this._engine.setFloatArray4(this.getUniform(e),t),this},t.prototype.setArray=function(e,t){return this._valueCache[e]=null,this._engine.setArray(this.getUniform(e),t),this},t.prototype.setArray2=function(e,t){return this._valueCache[e]=null,this._engine.setArray2(this.getUniform(e),t),this},t.prototype.setArray3=function(e,t){return this._valueCache[e]=null,this._engine.setArray3(this.getUniform(e),t),this},t.prototype.setArray4=function(e,t){return this._valueCache[e]=null,this._engine.setArray4(this.getUniform(e),t),this},t.prototype.setMatrices=function(e,t){return t?(this._valueCache[e]=null,this._engine.setMatrices(this.getUniform(e),t),this):this},t.prototype.setMatrix=function(e,t){return this._cacheMatrix(e,t)&&this._engine.setMatrix(this.getUniform(e),t),this},t.prototype.setMatrix3x3=function(e,t){return this._valueCache[e]=null,this._engine.setMatrix3x3(this.getUniform(e),t),this},t.prototype.setMatrix2x2=function(e,t){return this._valueCache[e]=null,this._engine.setMatrix2x2(this.getUniform(e),t),this},t.prototype.setFloat=function(e,t){var i=this._valueCache[e];return void 0!==i&&i===t?this:(this._valueCache[e]=t,this._engine.setFloat(this.getUniform(e),t),this)},t.prototype.setBool=function(e,t){var i=this._valueCache[e];return void 0!==i&&i===t?this:(this._valueCache[e]=t,this._engine.setBool(this.getUniform(e),t?1:0),this)},t.prototype.setVector2=function(e,t){return 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._cacheFloat2(e,t,i)&&this._engine.setFloat2(this.getUniform(e),t,i),this},t.prototype.setVector3=function(e,t){return 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,r){return this._cacheFloat3(e,t,i,r)&&this._engine.setFloat3(this.getUniform(e),t,i,r),this},t.prototype.setVector4=function(e,t){return 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,r,n){return this._cacheFloat4(e,t,i,r,n)&&this._engine.setFloat4(this.getUniform(e),t,i,r,n),this},t.prototype.setColor3=function(e,t){return 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._cacheFloat4(e,t.r,t.g,t.b,i)&&this._engine.setColor4(this.getUniform(e),t,i),this},t.ResetCache=function(){t._baseCache={}},t._uniqueIdSeed=0,t._baseCache={},t.ShadersStore={},t.IncludesShadersStore={},t}();e.Effect=r}(s||(s={}));!function(e){var t=function(){function t(){}return t.BindEyePosition=function(e,t){t._forcedViewPosition?e.setVector3("vEyePosition",t._forcedViewPosition):e.setVector3("vEyePosition",t._mirroredCameraPosition?t._mirroredCameraPosition:t.activeCamera.globalPosition)},t.PrepareDefinesForMergedUV=function(e,t,i){t._needUVs=!0,t[i]=!0,e.getTextureMatrix().isIdentity(!0)?(t[i+"DIRECTUV"]=e.coordinatesIndex+1,0===e.coordinatesIndex?t.MAINUV1=!0:t.MAINUV2=!0):t[i+"DIRECTUV"]=0},t.BindTextureMatrix=function(e,t,i){var r=e.getTextureMatrix();r.isIdentity(!0)||t.updateMatrix(i+"Matrix",r)},t.PrepareDefinesForMisc=function(t,i,r,n,o,s){s._areMiscDirty&&(s.LOGARITHMICDEPTH=r,s.POINTSIZE=n||i.forcePointsCloud,s.FOG=i.fogEnabled&&t.applyFog&&i.fogMode!==e.Scene.FOGMODE_NONE&&o,s.NONUNIFORMSCALING=t.nonUniformScaling)},t.PrepareDefinesForFrameBoundValues=function(e,t,i,r,n){void 0===n&&(n=!1);var o=!1;i.CLIPPLANE!==(void 0!==e.clipPlane&&null!==e.clipPlane)&&(i.CLIPPLANE=!i.CLIPPLANE,o=!0),i.ALPHATEST!==(t.getAlphaTesting()||n)&&(i.ALPHATEST=!i.ALPHATEST,o=!0),i.DEPTHPREPASS!==!t.getColorWrite()&&(i.DEPTHPREPASS=!i.DEPTHPREPASS,o=!0),i.INSTANCES!==r&&(i.INSTANCES=r,o=!0),o&&i.markAsUnprocessed()},t.PrepareDefinesForAttributes=function(t,i,r,n,o,s){if(void 0===o&&(o=!1),void 0===s&&(s=!0),!i._areAttributesDirty&&i._needNormals===i._normals&&i._needUVs===i._uvs)return!1;if(i._normals=i._needNormals,i._uvs=i._needUVs,i.NORMAL=i._needNormals&&t.isVerticesDataPresent(e.VertexBuffer.NormalKind),i._needNormals&&t.isVerticesDataPresent(e.VertexBuffer.TangentKind)&&(i.TANGENT=!0),i._needUVs?(i.UV1=t.isVerticesDataPresent(e.VertexBuffer.UVKind),i.UV2=t.isVerticesDataPresent(e.VertexBuffer.UV2Kind)):(i.UV1=!1,i.UV2=!1),r){var a=t.useVertexColors&&t.isVerticesDataPresent(e.VertexBuffer.ColorKind);i.VERTEXCOLOR=a,i.VERTEXALPHA=t.hasVertexAlpha&&a&&s}if(n&&(t.useBones&&t.computeBonesUsingShaders&&t.skeleton?(i.NUM_BONE_INFLUENCERS=t.numBoneInfluencers,i.BonesPerMesh=t.skeleton.bones.length+1):(i.NUM_BONE_INFLUENCERS=0,i.BonesPerMesh=0)),o){var l=t.morphTargetManager;l?(i.MORPHTARGETS_TANGENT=l.supportsTangents&&i.TANGENT,i.MORPHTARGETS_NORMAL=l.supportsNormals&&i.NORMAL,i.MORPHTARGETS=l.numInfluencers>0,i.NUM_MORPH_INFLUENCERS=l.numInfluencers):(i.MORPHTARGETS_TANGENT=!1,i.MORPHTARGETS_NORMAL=!1,i.MORPHTARGETS=!1,i.NUM_MORPH_INFLUENCERS=0)}return!0},t.PrepareDefinesForLights=function(t,i,r,n,o,s){if(void 0===o&&(o=4),void 0===s&&(s=!1),!r._areLightsDirty)return r._needNormals;var a=0,l=!1,h=!1,u=!1,c=!1,f=!1;if(t.lightsEnabled&&!s)for(var p=0,d=i._lightSources;p<d.length;p++){var m=d[p];l=!0,void 0===r["LIGHT"+a]&&(h=!0),r["LIGHT"+a]=!0,r["SPOTLIGHT"+a]=!1,r["HEMILIGHT"+a]=!1,r["POINTLIGHT"+a]=!1,r["DIRLIGHT"+a]=!1;var g;if(g=m.getTypeID()===e.Light.LIGHTTYPEID_SPOTLIGHT?"SPOTLIGHT"+a:m.getTypeID()===e.Light.LIGHTTYPEID_HEMISPHERICLIGHT?"HEMILIGHT"+a:m.getTypeID()===e.Light.LIGHTTYPEID_POINTLIGHT?"POINTLIGHT"+a:"DIRLIGHT"+a,r[g]=!0,n&&!m.specular.equalsFloats(0,0,0)&&(f=!0),r["SHADOW"+a]=!1,r["SHADOWPCF"+a]=!1,r["SHADOWESM"+a]=!1,r["SHADOWCUBE"+a]=!1,i&&i.receiveShadows&&t.shadowsEnabled&&m.shadowEnabled){var v=m.getShadowGenerator();v&&(c=!0,v.prepareDefines(r,a))}if(m.lightmapMode!=e.Light.LIGHTMAP_DEFAULT?(u=!0,r["LIGHTMAPEXCLUDED"+a]=!0,r["LIGHTMAPNOSPECULAR"+a]=m.lightmapMode==e.Light.LIGHTMAP_SHADOWSONLY):(r["LIGHTMAPEXCLUDED"+a]=!1,r["LIGHTMAPNOSPECULAR"+a]=!1),++a===o)break}r.SPECULARTERM=f,r.SHADOWS=c;for(var _=a;_<o;_++)void 0!==r["LIGHT"+_]&&(r["LIGHT"+_]=!1,r["HEMILIGHT"+a]=!1,r["POINTLIGHT"+a]=!1,r["DIRLIGHT"+a]=!1,r["SPOTLIGHT"+a]=!1,r["SHADOW"+a]=!1);var y=t.getEngine().getCaps();return void 0===r.SHADOWFLOAT&&(h=!0),r.SHADOWFLOAT=c&&(y.textureFloatRender&&y.textureFloatLinearFiltering||y.textureHalfFloatRender&&y.textureHalfFloatLinearFiltering),r.LIGHTMAPEXCLUDED=u,h&&r.rebuild(),l},t.PrepareUniformsAndSamplersList=function(e,t,i,r){void 0===r&&(r=4);var n,o=null;if(e.uniformsNames){var s=e;n=s.uniformsNames,o=s.uniformBuffersNames,t=s.samplers,i=s.defines,r=s.maxSimultaneousLights}else n=e,t||(t=[]);for(var a=0;a<r&&i["LIGHT"+a];a++)n.push("vLightData"+a,"vLightDiffuse"+a,"vLightSpecular"+a,"vLightDirection"+a,"vLightGround"+a,"lightMatrix"+a,"shadowsInfo"+a,"depthValues"+a),o&&o.push("Light"+a),t.push("shadowSampler"+a);i.NUM_MORPH_INFLUENCERS&&n.push("morphTargetInfluences")},t.HandleFallbacksForShadows=function(e,t,i,r){void 0===i&&(i=4),void 0===r&&(r=0);for(var n=0,o=0;o<i&&e["LIGHT"+o];o++)o>0&&(n=r+o,t.addFallback(n,"LIGHT"+o)),e.SHADOWS||(e["SHADOW"+o]&&t.addFallback(r,"SHADOW"+o),e["SHADOWPCF"+o]&&t.addFallback(r,"SHADOWPCF"+o),e["SHADOWESM"+o]&&t.addFallback(r,"SHADOWESM"+o));return n++},t.PrepareAttributesForMorphTargets=function(t,i,r){var n=r.NUM_MORPH_INFLUENCERS;if(n>0&&e.Engine.LastCreatedEngine)for(var o=e.Engine.LastCreatedEngine.getCaps().maxVertexAttribs,s=i.morphTargetManager,a=s&&s.supportsNormals&&r.NORMAL,l=s&&s.supportsTangents&&r.TANGENT,h=0;h<n;h++)t.push(e.VertexBuffer.PositionKind+h),a&&t.push(e.VertexBuffer.NormalKind+h),l&&t.push(e.VertexBuffer.TangentKind+h),t.length>o&&e.Tools.Error("Cannot add more vertex attributes for mesh "+i.name)},t.PrepareAttributesForBones=function(t,i,r,n){r.NUM_BONE_INFLUENCERS>0&&(n.addCPUSkinningFallback(0,i),t.push(e.VertexBuffer.MatricesIndicesKind),t.push(e.VertexBuffer.MatricesWeightsKind),r.NUM_BONE_INFLUENCERS>4&&(t.push(e.VertexBuffer.MatricesIndicesExtraKind),t.push(e.VertexBuffer.MatricesWeightsExtraKind)))},t.PrepareAttributesForInstances=function(e,t){t.INSTANCES&&(e.push("world0"),e.push("world1"),e.push("world2"),e.push("world3"))},t.BindLightShadow=function(e,t,i,r,n){if(e.shadowEnabled&&i.receiveShadows){var o=e.getShadowGenerator();o&&o.bindShadowLight(r,n)}},t.BindLightProperties=function(e,t,i){e.transferToEffect(t,i+"")},t.BindLights=function(i,r,n,o,s,a){void 0===s&&(s=4),void 0===a&&(a=!1);for(var l=0,h=0,u=r._lightSources;h<u.length;h++){var c=u[h],f=c.getScaledIntensity();if(c._uniformBuffer.bindToEffect(n,"Light"+l),t.BindLightProperties(c,n,l),c.diffuse.scaleToRef(f,e.Tmp.Color3[0]),c._uniformBuffer.updateColor4("vLightDiffuse",e.Tmp.Color3[0],a?c.radius:c.range,l+""),o.SPECULARTERM&&(c.specular.scaleToRef(f,e.Tmp.Color3[1]),c._uniformBuffer.updateColor3("vLightSpecular",e.Tmp.Color3[1],l+"")),i.shadowsEnabled&&this.BindLightShadow(c,i,r,l+"",n),c._uniformBuffer.update(),++l===s)break}},t.BindFogParameters=function(t,i,r){t.fogEnabled&&i.applyFog&&t.fogMode!==e.Scene.FOGMODE_NONE&&(r.setFloat4("vFogInfos",t.fogMode,t.fogStart,t.fogEnd,t.fogDensity),r.setColor3("vFogColor",t.fogColor))},t.BindBonesParameters=function(e,t){if(e&&e.useBones&&e.computeBonesUsingShaders&&e.skeleton){var i=e.skeleton.getTransformMatrices(e);i&&t&&t.setMatrices("mBones",i)}},t.BindMorphTargetParameters=function(e,t){var i=e.morphTargetManager;e&&i&&t.setFloatArray("morphTargetInfluences",i.influences)},t.BindLogDepth=function(e,t,i){e.LOGARITHMICDEPTH&&t.setFloat("logarithmicDepthConstant",2/(Math.log(i.activeCamera.maxZ+1)/Math.LN2))},t.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)}},t}();e.MaterialHelper=t}(s||(s={}));!function(e){var t=function(){function e(){this._isDirty=!0,this._areLightsDirty=!0,this._areAttributesDirty=!0,this._areTexturesDirty=!0,this._areFresnelDirty=!0,this._areMiscDirty=!0,this._areImageProcessingDirty=!0,this._normals=!1,this._uvs=!1,this._needNormals=!1,this._needUVs=!1}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isDirty},enumerable:!0,configurable:!0}),e.prototype.markAsProcessed=function(){this._isDirty=!1,this._areAttributesDirty=!1,this._areTexturesDirty=!1,this._areFresnelDirty=!1,this._areLightsDirty=!1,this._areMiscDirty=!1,this._areImageProcessingDirty=!1},e.prototype.markAsUnprocessed=function(){this._isDirty=!0},e.prototype.markAllAsDirty=function(){this._areTexturesDirty=!0,this._areAttributesDirty=!0,this._areLightsDirty=!0,this._areFresnelDirty=!0,this._areMiscDirty=!0,this._areImageProcessingDirty=!0,this._isDirty=!0},e.prototype.markAsImageProcessingDirty=function(){this._areImageProcessingDirty=!0,this._isDirty=!0},e.prototype.markAsLightDirty=function(){this._areLightsDirty=!0,this._isDirty=!0},e.prototype.markAsAttributesDirty=function(){this._areAttributesDirty=!0,this._isDirty=!0},e.prototype.markAsTexturesDirty=function(){this._areTexturesDirty=!0,this._isDirty=!0},e.prototype.markAsFresnelDirty=function(){this._areFresnelDirty=!0,this._isDirty=!0},e.prototype.markAsMiscDirty=function(){this._areMiscDirty=!0,this._isDirty=!0},e.prototype.rebuild=function(){this._keys&&delete this._keys,this._keys=[];for(var e=0,t=Object.keys(this);e<t.length;e++){var i=t[e];"_"!==i[0]&&this._keys.push(i)}},e.prototype.isEqual=function(e){if(this._keys.length!==e._keys.length)return!1;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){this._keys.length!==e._keys.length&&(e._keys=this._keys.slice(0));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],r=this[i];"number"==typeof r?e+="#define "+i+" "+this[i]+"\n":r&&(e+="#define "+i+"\n")}return e},e}();e.MaterialDefines=t;var i=function(){function t(i,r,n){this.checkReadyOnEveryCall=!1,this.checkReadyOnlyOnce=!1,this.state="",this.alpha=1,this._backFaceCulling=!0,this.doNotSerialize=!1,this.storeEffectOnSubMeshes=!1,this.onDisposeObservable=new e.Observable,this.onBindObservable=new e.Observable,this.onUnBindObservable=new e.Observable,this._alphaMode=e.Engine.ALPHA_COMBINE,this._needDepthPrePass=!1,this.disableDepthWrite=!1,this.forceDepthWrite=!1,this.separateCullingPass=!1,this._fogEnabled=!0,this.pointSize=1,this.zOffset=0,this._wasPreviouslyReady=!1,this._fillMode=t.TriangleFillMode,this.name=i,this.id=i||e.Tools.RandomId(),this._scene=r||e.Engine.LastCreatedScene,this._scene.useRightHandedSystem?this.sideOrientation=t.ClockWiseSideOrientation:this.sideOrientation=t.CounterClockWiseSideOrientation,this._uniformBuffer=new e.UniformBuffer(this._scene.getEngine()),this._useUBO=this.getScene().getEngine().supportsUniformBuffers,n||this._scene.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,"TextureDirtyFlag",{get:function(){return t._TextureDirtyFlag},enumerable:!0,configurable:!0}),Object.defineProperty(t,"LightDirtyFlag",{get:function(){return t._LightDirtyFlag},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FresnelDirtyFlag",{get:function(){return t._FresnelDirtyFlag},enumerable:!0,configurable:!0}),Object.defineProperty(t,"AttributesDirtyFlag",{get:function(){return t._AttributesDirtyFlag},enumerable:!0,configurable:!0}),Object.defineProperty(t,"MiscDirtyFlag",{get:function(){return t._MiscDirtyFlag},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"backFaceCulling",{get:function(){return this._backFaceCulling},set:function(e){this._backFaceCulling!==e&&(this._backFaceCulling=e,this.markAsDirty(t.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onBind",{set:function(e){this._onBindObserver&&this.onBindObservable.remove(this._onBindObserver),this._onBindObserver=this.onBindObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"alphaMode",{get:function(){return this._alphaMode},set:function(e){this._alphaMode!==e&&(this._alphaMode=e,this.markAsDirty(t.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"needDepthPrePass",{get:function(){return this._needDepthPrePass},set:function(e){this._needDepthPrePass!==e&&(this._needDepthPrePass=e,this._needDepthPrePass&&(this.checkReadyOnEveryCall=!0))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fogEnabled",{get:function(){return this._fogEnabled},set:function(e){this._fogEnabled!==e&&(this._fogEnabled=e,this.markAsDirty(t.MiscDirtyFlag))},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&&(this._fillMode=e,this.markAsDirty(t.MiscDirtyFlag))},enumerable:!0,configurable:!0}),t.prototype.toString=function(e){return"Name: "+this.name},t.prototype.getClassName=function(){return"Material"},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.isReadyForSubMesh=function(e,t,i){return!1},t.prototype.getEffect=function(){return this._effect},t.prototype.getScene=function(){return this._scene},t.prototype.needAlphaBlending=function(){return this.alpha<1},t.prototype.needAlphaBlendingForMesh=function(e){return this.needAlphaBlending()||e.visibility<1||e.hasVertexAlpha},t.prototype.needAlphaTesting=function(){return!1},t.prototype.getAlphaTestTexture=function(){return null},t.prototype.markDirty=function(){this._wasPreviouslyReady=!1},t.prototype._preBind=function(e,i){void 0===i&&(i=null);var r=this._scene.getEngine(),n=(null==i?this.sideOrientation:i)===t.ClockWiseSideOrientation;return r.enableEffect(e||this._effect),r.setState(this.backFaceCulling,this.zOffset,!1,n),n},t.prototype.bind=function(e,t){},t.prototype.bindForSubMesh=function(e,t,i){},t.prototype.bindOnlyWorldMatrix=function(e){},t.prototype.bindSceneUniformBuffer=function(e,t){t.bindToEffect(e,"Scene")},t.prototype.bindView=function(e){this._useUBO?this.bindSceneUniformBuffer(e,this.getScene().getSceneUniformBuffer()):e.setMatrix("view",this.getScene().getViewMatrix())},t.prototype.bindViewProjection=function(e){this._useUBO?this.bindSceneUniformBuffer(e,this.getScene().getSceneUniformBuffer()):e.setMatrix("viewProjection",this.getScene().getTransformMatrix())},t.prototype._afterBind=function(e){if(this._scene._cachedMaterial=this,this._scene._cachedVisibility=e?e.visibility:1,e&&this.onBindObservable.notifyObservers(e),this.disableDepthWrite){var t=this._scene.getEngine();this._cachedDepthWriteState=t.getDepthWrite(),t.setDepthWrite(!1)}},t.prototype.unbind=function(){this.onUnBindObservable.notifyObservers(this),this.disableDepthWrite&&this._scene.getEngine().setDepthWrite(this._cachedDepthWriteState)},t.prototype.getActiveTextures=function(){return[]},t.prototype.hasTexture=function(e){return!1},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.forceCompilation=function(t,i,r){var n=this,o=new e.BaseSubMesh,s=this.getScene(),a=s.getEngine(),l=function(){if(n._scene&&n._scene.getEngine()){o._materialDefines&&(o._materialDefines._renderId=-1);var h=a.getAlphaTesting(),u=s.clipPlane;a.setAlphaTesting(r?r.alphaTest:n.needAlphaTesting()),r&&r.clipPlane&&(s.clipPlane=new e.Plane(0,0,0,1)),n.storeEffectOnSubMeshes?n.isReadyForSubMesh(t,o)?i&&i(n):setTimeout(l,16):n.isReady(t)?i&&i(n):setTimeout(l,16),a.setAlphaTesting(h),r&&r.clipPlane&&(s.clipPlane=u)}};l()},t.prototype.markAsDirty=function(e){e&t.TextureDirtyFlag&&this._markAllSubMeshesAsTexturesDirty(),e&t.LightDirtyFlag&&this._markAllSubMeshesAsLightsDirty(),e&t.FresnelDirtyFlag&&this._markAllSubMeshesAsFresnelDirty(),e&t.AttributesDirtyFlag&&this._markAllSubMeshesAsAttributesDirty(),e&t.MiscDirtyFlag&&this._markAllSubMeshesAsMiscDirty(),this.getScene().resetCachedMaterial()},t.prototype._markAllSubMeshesAsDirty=function(e){for(var t=0,i=this.getScene().meshes;t<i.length;t++){var r=i[t];if(r.subMeshes)for(var n=0,o=r.subMeshes;n<o.length;n++){var s=o[n];s.getMaterial()===this&&(s._materialDefines&&e(s._materialDefines))}}},t.prototype._markAllSubMeshesAsImageProcessingDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsImageProcessingDirty()})},t.prototype._markAllSubMeshesAsTexturesDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsTexturesDirty()})},t.prototype._markAllSubMeshesAsFresnelDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsFresnelDirty()})},t.prototype._markAllSubMeshesAsLightsDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsLightDirty()})},t.prototype._markAllSubMeshesAsAttributesDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsAttributesDirty()})},t.prototype._markAllSubMeshesAsMiscDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsMiscDirty()})},t.prototype.dispose=function(e,t){this.getScene().stopAnimation(this);var i=this._scene.materials.indexOf(this);for(i>=0&&this._scene.materials.splice(i,1),i=0;i<this._scene.meshes.length;i++){var r=this._scene.meshes[i];if(r.material===this&&(r.material=null,r.geometry)){var n=r.geometry;if(this.storeEffectOnSubMeshes)for(var o=0,s=r.subMeshes;o<s.length;o++){var a=s[o];n._releaseVertexArrayObject(a._materialEffect),e&&a._materialEffect&&this._scene.getEngine()._releaseEffect(a._materialEffect)}else n._releaseVertexArrayObject(this._effect)}}this._uniformBuffer.dispose(),e&&this._effect&&(this.storeEffectOnSubMeshes||this._scene.getEngine()._releaseEffect(this._effect),this._effect=null),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this.onBindObservable.clear(),this.onUnBindObservable.clear()},t.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},t.ParseMultiMaterial=function(t,i){var r=new e.MultiMaterial(t.name,i);r.id=t.id,e.Tags&&e.Tags.AddTagsTo(r,t.tags);for(var n=0;n<t.materials.length;n++){var o=t.materials[n];o?r.subMaterials.push(i.getMaterialByID(o)):r.subMaterials.push(null)}return r},t.Parse=function(t,i,r){if(!t.customType)return e.StandardMaterial.Parse(t,i,r);if("BABYLON.PBRMaterial"!==t.customType||!t.overloadedAlbedo||(t.customType="BABYLON.LegacyPBRMaterial",e.LegacyPBRMaterial))return e.Tools.Instantiate(t.customType).Parse(t,i,r);e.Tools.Error("Your scene is trying to load a legacy version of the PBRMaterial, please, include it from the materials library.")},t._TriangleFillMode=0,t._WireFrameFillMode=1,t._PointFillMode=2,t._ClockWiseSideOrientation=0,t._CounterClockWiseSideOrientation=1,t._TextureDirtyFlag=1,t._LightDirtyFlag=2,t._FresnelDirtyFlag=4,t._AttributesDirtyFlag=8,t._MiscDirtyFlag=16,r([e.serialize()],t.prototype,"id",void 0),r([e.serialize()],t.prototype,"name",void 0),r([e.serialize()],t.prototype,"checkReadyOnEveryCall",void 0),r([e.serialize()],t.prototype,"checkReadyOnlyOnce",void 0),r([e.serialize()],t.prototype,"state",void 0),r([e.serialize()],t.prototype,"alpha",void 0),r([e.serialize("backFaceCulling")],t.prototype,"_backFaceCulling",void 0),r([e.serialize()],t.prototype,"sideOrientation",void 0),r([e.serialize("alphaMode")],t.prototype,"_alphaMode",void 0),r([e.serialize()],t.prototype,"_needDepthPrePass",void 0),r([e.serialize()],t.prototype,"disableDepthWrite",void 0),r([e.serialize()],t.prototype,"forceDepthWrite",void 0),r([e.serialize()],t.prototype,"separateCullingPass",void 0),r([e.serialize("fogEnabled")],t.prototype,"_fogEnabled",void 0),r([e.serialize()],t.prototype,"pointSize",void 0),r([e.serialize()],t.prototype,"zOffset",void 0),r([e.serialize()],t.prototype,"wireframe",null),r([e.serialize()],t.prototype,"pointsCloud",null),r([e.serialize()],t.prototype,"fillMode",null),t}();e.Material=i}(s||(s={}));!function(e){var t=function(){function t(e,t,i){this._engine=e,this._noUBO=!e.supportsUniformBuffers,this._dynamic=i,this._data=t||[],this._uniformLocations={},this._uniformSizes={},this._uniformLocationPointer=0,this._needSync=!1,this._noUBO?(this.updateMatrix3x3=this._updateMatrix3x3ForEffect,this.updateMatrix2x2=this._updateMatrix2x2ForEffect,this.updateFloat=this._updateFloatForEffect,this.updateFloat2=this._updateFloat2ForEffect,this.updateFloat3=this._updateFloat3ForEffect,this.updateFloat4=this._updateFloat4ForEffect,this.updateMatrix=this._updateMatrixForEffect,this.updateVector3=this._updateVector3ForEffect,this.updateVector4=this._updateVector4ForEffect,this.updateColor3=this._updateColor3ForEffect,this.updateColor4=this._updateColor4ForEffect):(this._engine._uniformBuffers.push(this),this.updateMatrix3x3=this._updateMatrix3x3ForUniform,this.updateMatrix2x2=this._updateMatrix2x2ForUniform,this.updateFloat=this._updateFloatForUniform,this.updateFloat2=this._updateFloat2ForUniform,this.updateFloat3=this._updateFloat3ForUniform,this.updateFloat4=this._updateFloat4ForUniform,this.updateMatrix=this._updateMatrixForUniform,this.updateVector3=this._updateVector3ForUniform,this.updateVector4=this._updateVector4ForUniform,this.updateColor3=this._updateColor3ForUniform,this.updateColor4=this._updateColor4ForUniform)}return Object.defineProperty(t.prototype,"useUbo",{get:function(){return!this._noUBO},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isSync",{get:function(){return!this._needSync},enumerable:!0,configurable:!0}),t.prototype.isDynamic=function(){return void 0!==this._dynamic},t.prototype.getData=function(){return this._bufferData},t.prototype.getBuffer=function(){return this._buffer},t.prototype._fillAlignment=function(e){var t;if(t=e<=2?e:4,this._uniformLocationPointer%t!=0){var i=this._uniformLocationPointer;this._uniformLocationPointer+=t-this._uniformLocationPointer%t;for(var r=this._uniformLocationPointer-i,n=0;n<r;n++)this._data.push(0)}},t.prototype.addUniform=function(e,t){if(!this._noUBO&&void 0===this._uniformLocations[e]){var i;if(t instanceof Array)t=(i=t).length;else{t=t,i=[];for(r=0;r<t;r++)i.push(0)}this._fillAlignment(t),this._uniformSizes[e]=t,this._uniformLocations[e]=this._uniformLocationPointer,this._uniformLocationPointer+=t;for(var r=0;r<t;r++)this._data.push(i[r]);this._needSync=!0}},t.prototype.addMatrix=function(e,t){this.addUniform(e,Array.prototype.slice.call(t.toArray()))},t.prototype.addFloat2=function(e,t,i){var r=[t,i];this.addUniform(e,r)},t.prototype.addFloat3=function(e,t,i,r){var n=[t,i,r];this.addUniform(e,n)},t.prototype.addColor3=function(e,t){var i=new Array;t.toArray(i),this.addUniform(e,i)},t.prototype.addColor4=function(e,t,i){var r=new Array;t.toArray(r),r.push(i),this.addUniform(e,r)},t.prototype.addVector3=function(e,t){var i=new Array;t.toArray(i),this.addUniform(e,i)},t.prototype.addMatrix3x3=function(e){this.addUniform(e,12)},t.prototype.addMatrix2x2=function(e){this.addUniform(e,8)},t.prototype.create=function(){this._noUBO||this._buffer||(this._fillAlignment(4),this._bufferData=new Float32Array(this._data),this._rebuild(),this._needSync=!0)},t.prototype._rebuild=function(){this._noUBO||(this._dynamic?this._buffer=this._engine.createDynamicUniformBuffer(this._bufferData):this._buffer=this._engine.createUniformBuffer(this._bufferData))},t.prototype.update=function(){this._buffer?(this._dynamic||this._needSync)&&(this._engine.updateUniformBuffer(this._buffer,this._bufferData),this._needSync=!1):this.create()},t.prototype.updateUniform=function(t,i,r){var n=this._uniformLocations[t];if(void 0===n){if(this._buffer)return void e.Tools.Error("Cannot add an uniform after UBO has been created.");this.addUniform(t,r),n=this._uniformLocations[t]}if(this._buffer||this.create(),this._dynamic)for(s=0;s<r;s++)this._bufferData[n+s]=i[s];else{for(var o=!1,s=0;s<r;s++)this._bufferData[n+s]!==i[s]&&(o=!0,this._bufferData[n+s]=i[s]);this._needSync=this._needSync||o}},t.prototype._updateMatrix3x3ForUniform=function(e,i){for(var r=0;r<3;r++)t._tempBuffer[4*r]=i[3*r],t._tempBuffer[4*r+1]=i[3*r+1],t._tempBuffer[4*r+2]=i[3*r+2],t._tempBuffer[4*r+3]=0;this.updateUniform(e,t._tempBuffer,12)},t.prototype._updateMatrix3x3ForEffect=function(e,t){this._currentEffect.setMatrix3x3(e,t)},t.prototype._updateMatrix2x2ForEffect=function(e,t){this._currentEffect.setMatrix2x2(e,t)},t.prototype._updateMatrix2x2ForUniform=function(e,i){for(var r=0;r<2;r++)t._tempBuffer[4*r]=i[2*r],t._tempBuffer[4*r+1]=i[2*r+1],t._tempBuffer[4*r+2]=0,t._tempBuffer[4*r+3]=0;this.updateUniform(e,t._tempBuffer,8)},t.prototype._updateFloatForEffect=function(e,t){this._currentEffect.setFloat(e,t)},t.prototype._updateFloatForUniform=function(e,i){t._tempBuffer[0]=i,this.updateUniform(e,t._tempBuffer,1)},t.prototype._updateFloat2ForEffect=function(e,t,i,r){void 0===r&&(r=""),this._currentEffect.setFloat2(e+r,t,i)},t.prototype._updateFloat2ForUniform=function(e,i,r,n){void 0===n&&(n=""),t._tempBuffer[0]=i,t._tempBuffer[1]=r,this.updateUniform(e,t._tempBuffer,2)},t.prototype._updateFloat3ForEffect=function(e,t,i,r,n){void 0===n&&(n=""),this._currentEffect.setFloat3(e+n,t,i,r)},t.prototype._updateFloat3ForUniform=function(e,i,r,n,o){void 0===o&&(o=""),t._tempBuffer[0]=i,t._tempBuffer[1]=r,t._tempBuffer[2]=n,this.updateUniform(e,t._tempBuffer,3)},t.prototype._updateFloat4ForEffect=function(e,t,i,r,n,o){void 0===o&&(o=""),this._currentEffect.setFloat4(e+o,t,i,r,n)},t.prototype._updateFloat4ForUniform=function(e,i,r,n,o,s){void 0===s&&(s=""),t._tempBuffer[0]=i,t._tempBuffer[1]=r,t._tempBuffer[2]=n,t._tempBuffer[3]=o,this.updateUniform(e,t._tempBuffer,4)},t.prototype._updateMatrixForEffect=function(e,t){this._currentEffect.setMatrix(e,t)},t.prototype._updateMatrixForUniform=function(e,t){this.updateUniform(e,t.toArray(),16)},t.prototype._updateVector3ForEffect=function(e,t){this._currentEffect.setVector3(e,t)},t.prototype._updateVector3ForUniform=function(e,i){i.toArray(t._tempBuffer),this.updateUniform(e,t._tempBuffer,3)},t.prototype._updateVector4ForEffect=function(e,t){this._currentEffect.setVector4(e,t)},t.prototype._updateVector4ForUniform=function(e,i){i.toArray(t._tempBuffer),this.updateUniform(e,t._tempBuffer,4)},t.prototype._updateColor3ForEffect=function(e,t,i){void 0===i&&(i=""),this._currentEffect.setColor3(e+i,t)},t.prototype._updateColor3ForUniform=function(e,i,r){void 0===r&&(r=""),i.toArray(t._tempBuffer),this.updateUniform(e,t._tempBuffer,3)},t.prototype._updateColor4ForEffect=function(e,t,i,r){void 0===r&&(r=""),this._currentEffect.setColor4(e+r,t,i)},t.prototype._updateColor4ForUniform=function(e,i,r,n){void 0===n&&(n=""),i.toArray(t._tempBuffer),t._tempBuffer[3]=r,this.updateUniform(e,t._tempBuffer,4)},t.prototype.setTexture=function(e,t){this._currentEffect.setTexture(e,t)},t.prototype.updateUniformDirectly=function(e,t){this.updateUniform(e,t,t.length),this.update()},t.prototype.bindToEffect=function(e,t){this._currentEffect=e,!this._noUBO&&this._buffer&&e.bindUniformBuffer(this._buffer,t)},t.prototype.dispose=function(){if(!this._noUBO){var e=this._engine._uniformBuffers.indexOf(this);-1!==e&&this._engine._uniformBuffers.splice(e,1),this._buffer&&this._engine._releaseBuffer(this._buffer)&&(this._buffer=null)}},t._MAX_UNIFORM_SIZE=256,t._tempBuffer=new Float32Array(t._MAX_UNIFORM_SIZE),t}();e.UniformBuffer=t}(s||(s={}));!function(e){var t=function(e){function t(t,i){var r=e.call(this,t,i)||this;return r.storeEffectOnSubMeshes=!0,r}return n(t,e),t.prototype.getEffect=function(){return this._activeEffect},t.prototype.isReady=function(e,t){return!!e&&(!e.subMeshes||0===e.subMeshes.length||this.isReadyForSubMesh(e,e.subMeshes[0],t))},t.prototype.bindOnlyWorldMatrix=function(e){this._activeEffect.setMatrix("world",e)},t.prototype.bind=function(e,t){t&&this.bindForSubMesh(e,t,t.subMeshes[0])},t.prototype._afterBind=function(t,i){void 0===i&&(i=null),e.prototype._afterBind.call(this,t),this.getScene()._cachedEffect=i},t.prototype._mustRebind=function(e,t,i){return void 0===i&&(i=1),e.isCachedMaterialInvalid(this,t,i)},t}(e.Material);e.PushMaterial=t}(s||(s={}));!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.TangentKind:this.tangents=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){return this._applyTo(e,t),this},t.prototype.applyToGeometry=function(e,t){return this._applyTo(e,t),this},t.prototype.updateMesh=function(e,t,i){return this._update(e),this},t.prototype.updateGeometry=function(e,t,i){return this._update(e),this},t.prototype._applyTo=function(t,i){return void 0===i&&(i=!1),this.positions&&t.setVerticesData(e.VertexBuffer.PositionKind,this.positions,i),this.normals&&t.setVerticesData(e.VertexBuffer.NormalKind,this.normals,i),this.tangents&&t.setVerticesData(e.VertexBuffer.TangentKind,this.tangents,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,null,i),this},t.prototype._update=function(t,i,r){return this.positions&&t.updateVerticesData(e.VertexBuffer.PositionKind,this.positions,i,r),this.normals&&t.updateVerticesData(e.VertexBuffer.NormalKind,this.normals,i,r),this.tangents&&t.updateVerticesData(e.VertexBuffer.TangentKind,this.tangents,i,r),this.uvs&&t.updateVerticesData(e.VertexBuffer.UVKind,this.uvs,i,r),this.uvs2&&t.updateVerticesData(e.VertexBuffer.UV2Kind,this.uvs2,i,r),this.uvs3&&t.updateVerticesData(e.VertexBuffer.UV3Kind,this.uvs3,i,r),this.uvs4&&t.updateVerticesData(e.VertexBuffer.UV4Kind,this.uvs4,i,r),this.uvs5&&t.updateVerticesData(e.VertexBuffer.UV5Kind,this.uvs5,i,r),this.uvs6&&t.updateVerticesData(e.VertexBuffer.UV6Kind,this.uvs6,i,r),this.colors&&t.updateVerticesData(e.VertexBuffer.ColorKind,this.colors,i,r),this.matricesIndices&&t.updateVerticesData(e.VertexBuffer.MatricesIndicesKind,this.matricesIndices,i,r),this.matricesWeights&&t.updateVerticesData(e.VertexBuffer.MatricesWeightsKind,this.matricesWeights,i,r),this.matricesIndicesExtra&&t.updateVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,this.matricesIndicesExtra,i,r),this.matricesWeightsExtra&&t.updateVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,this.matricesWeightsExtra,i,r),this.indices&&t.setIndices(this.indices,null),this},t.prototype.transform=function(t){var i,r=e.Vector3.Zero();if(this.positions){var n=e.Vector3.Zero();for(i=0;i<this.positions.length;i+=3)e.Vector3.FromArrayToRef(this.positions,i,n),e.Vector3.TransformCoordinatesToRef(n,t,r),this.positions[i]=r.x,this.positions[i+1]=r.y,this.positions[i+2]=r.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,r),this.normals[i]=r.x,this.normals[i+1]=r.y,this.normals[i+2]=r.z}if(this.tangents){var s=e.Vector4.Zero(),a=e.Vector4.Zero();for(i=0;i<this.tangents.length;i+=4)e.Vector4.FromArrayToRef(this.tangents,i,s),e.Vector4.TransformNormalToRef(s,t,a),this.tangents[i]=a.x,this.tangents[i+1]=a.y,this.tangents[i+2]=a.z,this.tangents[i+3]=a.w}return this},t.prototype.merge=function(e,t){if(t=t||{},e.indices){this.indices||(this.indices=[]);for(var i=this.positions?this.positions.length/3:0,r=0;r<e.indices.length;r++)this.indices.push(e.indices[r]+i)}if(this.positions=this._mergeElement(this.positions,e.positions),!this.positions)return this;var n=this.positions.length/3;return this.normals=this._mergeElement(this.normals,e.normals,3*n),this.tangents=this._mergeElement(this.tangents,e.tangents,n*(t.tangentLength||4)),this.uvs=this._mergeElement(this.uvs,e.uvs,2*n),this.uvs2=this._mergeElement(this.uvs2,e.uvs2,2*n),this.uvs3=this._mergeElement(this.uvs3,e.uvs3,2*n),this.uvs4=this._mergeElement(this.uvs4,e.uvs4,2*n),this.uvs5=this._mergeElement(this.uvs5,e.uvs5,2*n),this.uvs6=this._mergeElement(this.uvs6,e.uvs6,2*n),this.colors=this._mergeElement(this.colors,e.colors,4*n),this.matricesIndices=this._mergeElement(this.matricesIndices,e.matricesIndices,4*n),this.matricesWeights=this._mergeElement(this.matricesWeights,e.matricesWeights,4*n),this.matricesIndicesExtra=this._mergeElement(this.matricesIndicesExtra,e.matricesIndicesExtra,4*n),this.matricesWeightsExtra=this._mergeElement(this.matricesWeightsExtra,e.matricesWeightsExtra,4*n),this},t.prototype._mergeElement=function(e,t,i){if(void 0===i&&(i=0),!t&&!e)return null;if(!t)return this._mergeElement(e,new Float32Array(e.length),i);if(!e)return 0===i||i===t.length?t:this._mergeElement(new Float32Array(i-t.length),t,i);var r=t.length+e.length,n=e instanceof Float32Array,o=t instanceof Float32Array;if(n){var s=new Float32Array(r);return s.set(e),s.set(t,e.length),s}if(o){for(var a=e.slice(0),l=0,r=t.length;l<r;l++)a.push(t[l]);return a}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.tangents&&(e.tangents=this.tangents),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,r){return t._ExtractFrom(e,i,r)},t.ExtractFromGeometry=function(e,i,r){return t._ExtractFrom(e,i,r)},t._ExtractFrom=function(i,r,n){var o=new t;return i.isVerticesDataPresent(e.VertexBuffer.PositionKind)&&(o.positions=i.getVerticesData(e.VertexBuffer.PositionKind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(o.normals=i.getVerticesData(e.VertexBuffer.NormalKind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.TangentKind)&&(o.tangents=i.getVerticesData(e.VertexBuffer.TangentKind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(o.uvs=i.getVerticesData(e.VertexBuffer.UVKind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(o.uvs2=i.getVerticesData(e.VertexBuffer.UV2Kind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.UV3Kind)&&(o.uvs3=i.getVerticesData(e.VertexBuffer.UV3Kind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.UV4Kind)&&(o.uvs4=i.getVerticesData(e.VertexBuffer.UV4Kind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.UV5Kind)&&(o.uvs5=i.getVerticesData(e.VertexBuffer.UV5Kind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.UV6Kind)&&(o.uvs6=i.getVerticesData(e.VertexBuffer.UV6Kind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(o.colors=i.getVerticesData(e.VertexBuffer.ColorKind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&(o.matricesIndices=i.getVerticesData(e.VertexBuffer.MatricesIndicesKind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)&&(o.matricesWeights=i.getVerticesData(e.VertexBuffer.MatricesWeightsKind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesExtraKind)&&(o.matricesIndicesExtra=i.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,r,n)),i.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsExtraKind)&&(o.matricesWeightsExtra=i.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,r,n)),o.indices=i.getIndices(r),o},t.CreateRibbon=function(i){var r=i.pathArray,n=i.closeArray||!1,o=i.closePath||!1,s=i.invertUV||!1,a=Math.floor(r[0].length/2),l=i.offset||a;l=l>a?a:Math.floor(l);var h,u,c,f,p=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,d=i.uvs,m=i.colors,g=[],v=[],_=[],y=[],x=[],b=[],T=[],E=[],A=[],P=[];if(r.length<2){var S=[],M=[];for(c=0;c<r[0].length-l;c++)S.push(r[0][c]),M.push(r[0][c+l]);r=[S,M]}var C,R,I=0,O=o?1:0;h=r[0].length;var D;for(u=0;u<r.length;u++){for(T[u]=0,x[u]=[0],h=h<(R=(C=r[u]).length)?h:R,f=0;f<R;)g.push(C[f].x,C[f].y,C[f].z),f>0&&(D=C[f].subtract(C[f-1]).length()+T[u],x[u].push(D),T[u]=D),f++;o&&(f--,g.push(C[0].x,C[0].y,C[0].z),D=C[f].subtract(C[0]).length()+T[u],x[u].push(D),T[u]=D),A[u]=R+O,P[u]=I,I+=R+O}var w,L,F=null,N=null;for(c=0;c<h+O;c++){for(E[c]=0,b[c]=[0],u=0;u<r.length-1;u++)w=r[u],L=r[u+1],c===h?(F=w[0],N=L[0]):(F=w[c],N=L[c]),D=N.subtract(F).length()+E[c],b[c].push(D),E[c]=D;n&&N&&F&&(w=r[u],L=r[0],c===h&&(N=L[0]),D=N.subtract(F).length()+E[c],E[c]=D)}var B,V;if(d)for(u=0;u<d.length;u++)y.push(d[u].x,d[u].y);else for(u=0;u<r.length;u++)for(c=0;c<h+O;c++)B=0!=T[u]?x[u][c]/T[u]:0,V=0!=E[c]?b[c][u]/E[c]:0,s?y.push(V,B):y.push(B,V);for(var U=0,z=A[u=0]-1,k=A[u+1]-1,G=z<k?z:k,H=P[1]-P[0],W=n?A.length:A.length-1;U<=G&&u<W;)v.push(U,U+H,U+1),v.push(U+H+1,U+1,U+H),(U+=1)===G&&(++u===A.length-1?(H=P[0]-P[u],z=A[u]-1,k=A[0]-1):(H=P[u+1]-P[u],z=A[u]-1,k=A[u+1]-1),U=P[u],G=z<k?z+U:k+U);if(t.ComputeNormals(g,v,_),o){var j=0,X=0;for(u=0;u<r.length;u++)j=3*P[u],X=u+1<r.length?3*(P[u+1]-1):_.length-3,_[j]=.5*(_[j]+_[X]),_[j+1]=.5*(_[j+1]+_[X+1]),_[j+2]=.5*(_[j+2]+_[X+2]),_[X]=_[j],_[X+1]=_[j+1],_[X+2]=_[j+2]}t._ComputeSides(p,g,v,_,y,i.frontUVs,i.backUVs);var Y=null;if(m){Y=new Float32Array(4*m.length);for(var K=0;K<m.length;K++)Y[4*K]=m[K].r,Y[4*K+1]=m[K].g,Y[4*K+2]=m[K].b,Y[4*K+3]=m[K].a}var Q=new t,Z=new Float32Array(g),q=new Float32Array(_),J=new Float32Array(y);return Q.indices=v,Q.positions=Z,Q.normals=q,Q.uvs=J,Y&&Q.set(Y,e.VertexBuffer.ColorKind),o&&(Q._idx=P),Q},t.CreateBox=function(i){for(var r=[new e.Vector3(0,0,1),new e.Vector3(0,0,-1),new e.Vector3(1,0,0),new e.Vector3(-1,0,0),new e.Vector3(0,1,0),new e.Vector3(0,-1,0)],n=[],o=[],s=[],a=[],l=i.width||i.size||1,h=i.height||i.size||1,u=i.depth||i.size||1,c=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,f=i.faceUV||new Array(6),p=i.faceColors,d=[],m=0;m<6;m++)void 0===f[m]&&(f[m]=new e.Vector4(0,0,1,1)),p&&void 0===p[m]&&(p[m]=new e.Color4(1,1,1,1));for(var g=new e.Vector3(l/2,h/2,u/2),v=0;v<r.length;v++){var _=r[v],y=new e.Vector3(_.y,_.z,_.x),x=e.Vector3.Cross(_,y),b=o.length/3;n.push(b),n.push(b+1),n.push(b+2),n.push(b),n.push(b+2),n.push(b+3);var T=_.subtract(y).subtract(x).multiply(g);o.push(T.x,T.y,T.z),s.push(_.x,_.y,_.z),a.push(f[v].z,f[v].w),p&&d.push(p[v].r,p[v].g,p[v].b,p[v].a),T=_.subtract(y).add(x).multiply(g),o.push(T.x,T.y,T.z),s.push(_.x,_.y,_.z),a.push(f[v].x,f[v].w),p&&d.push(p[v].r,p[v].g,p[v].b,p[v].a),T=_.add(y).add(x).multiply(g),o.push(T.x,T.y,T.z),s.push(_.x,_.y,_.z),a.push(f[v].x,f[v].y),p&&d.push(p[v].r,p[v].g,p[v].b,p[v].a),T=_.add(y).subtract(x).multiply(g),o.push(T.x,T.y,T.z),s.push(_.x,_.y,_.z),a.push(f[v].z,f[v].y),p&&d.push(p[v].r,p[v].g,p[v].b,p[v].a)}t._ComputeSides(c,o,n,s,a,i.frontUVs,i.backUVs);var E=new t;if(E.indices=n,E.positions=o,E.normals=s,E.uvs=a,p){var A=c===e.Mesh.DOUBLESIDE?d.concat(d):d;E.colors=A}return E},t.CreateSphere=function(i){for(var r=i.segments||32,n=i.diameterX||i.diameter||1,o=i.diameterY||i.diameter||1,s=i.diameterZ||i.diameter||1,a=i.arc&&(i.arc<=0||i.arc>1)?1:i.arc||1,l=i.slice&&i.slice<=0?1:i.slice||1,h=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,u=new e.Vector3(n/2,o/2,s/2),c=2+r,f=2*c,p=[],d=[],m=[],g=[],v=0;v<=c;v++){for(var _=v/c,y=_*Math.PI*l,x=0;x<=f;x++){var b=x/f,T=b*Math.PI*2*a,E=e.Matrix.RotationZ(-y),A=e.Matrix.RotationY(T),P=e.Vector3.TransformCoordinates(e.Vector3.Up(),E),S=e.Vector3.TransformCoordinates(P,A),M=S.multiply(u),C=S.divide(u).normalize();d.push(M.x,M.y,M.z),m.push(C.x,C.y,C.z),g.push(b,_)}if(v>0)for(var R=d.length/3,I=R-2*(f+1);I+f+2<R;I++)p.push(I),p.push(I+1),p.push(I+f+1),p.push(I+f+1),p.push(I+1),p.push(I+f+2)}t._ComputeSides(h,d,p,m,g,i.frontUVs,i.backUVs);var O=new t;return O.indices=p,O.positions=d,O.normals=m,O.uvs=g,O},t.CreateCylinder=function(i){var r,n=i.height||2,o=0===i.diameterTop?0:i.diameterTop||i.diameter||1,s=0===i.diameterBottom?0:i.diameterBottom||i.diameter||1,a=i.tessellation||24,l=i.subdivisions||1,h=!!i.hasRings,u=!!i.enclose,c=i.arc&&(i.arc<=0||i.arc>1)?1:i.arc||1,f=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,p=i.faceUV||new Array(3),d=i.faceColors,m=2+(1+(1!==c&&u?2:0))*(h?l:1);for(r=0;r<m;r++)d&&void 0===d[r]&&(d[r]=new e.Color4(1,1,1,1));for(r=0;r<m;r++)p&&void 0===p[r]&&(p[r]=new e.Vector4(0,0,1,1));var g,v,_,y,x,b,T=new Array,E=new Array,A=new Array,P=new Array,S=new Array,M=2*Math.PI*c/a,C=(s-o)/2/n,R=e.Vector3.Zero(),I=e.Vector3.Zero(),O=e.Vector3.Zero(),D=e.Vector3.Zero(),w=e.Vector3.Zero(),L=e.Axis.Y,F=1,N=1,B=0,V=0;for(y=0;y<=l;y++)for(_=((v=y/l)*(o-s)+s)/2,F=h&&0!==y&&y!==l?2:1,b=0;b<F;b++){for(h&&(N+=b),u&&(N+=2*b),x=0;x<=a;x++)g=x*M,R.x=Math.cos(-g)*_,R.y=-n/2+v*n,R.z=Math.sin(-g)*_,0===o&&y===l?(I.x=A[A.length-3*(a+1)],I.y=A[A.length-3*(a+1)+1],I.z=A[A.length-3*(a+1)+2]):(I.x=R.x,I.z=R.z,I.y=Math.sqrt(I.x*I.x+I.z*I.z)*C,I.normalize()),0===x&&(O.copyFrom(R),D.copyFrom(I)),E.push(R.x,R.y,R.z),A.push(I.x,I.y,I.z),V=h?B!==N?p[N].y:p[N].w:p[N].y+(p[N].w-p[N].y)*v,P.push(p[N].x+(p[N].z-p[N].x)*x/a,V),d&&S.push(d[N].r,d[N].g,d[N].b,d[N].a);1!==c&&u&&(E.push(R.x,R.y,R.z),E.push(0,R.y,0),E.push(0,R.y,0),E.push(O.x,O.y,O.z),e.Vector3.CrossToRef(L,I,w),w.normalize(),A.push(w.x,w.y,w.z,w.x,w.y,w.z),e.Vector3.CrossToRef(D,L,w),w.normalize(),A.push(w.x,w.y,w.z,w.x,w.y,w.z),V=h?B!==N?p[N+1].y:p[N+1].w:p[N+1].y+(p[N+1].w-p[N+1].y)*v,P.push(p[N+1].x,V),P.push(p[N+1].z,V),V=h?B!==N?p[N+2].y:p[N+2].w:p[N+2].y+(p[N+2].w-p[N+2].y)*v,P.push(p[N+2].x,V),P.push(p[N+2].z,V),d&&(S.push(d[N+1].r,d[N+1].g,d[N+1].b,d[N+1].a),S.push(d[N+1].r,d[N+1].g,d[N+1].b,d[N+1].a),S.push(d[N+2].r,d[N+2].g,d[N+2].b,d[N+2].a),S.push(d[N+2].r,d[N+2].g,d[N+2].b,d[N+2].a))),B!==N&&(B=N)}var U=1!==c&&u?a+4:a;for(y=0,N=0;N<l;N++){var z=0,k=0,G=0,H=0;for(x=0;x<a;x++)z=y*(U+1)+x,k=(y+1)*(U+1)+x,G=y*(U+1)+(x+1),H=(y+1)*(U+1)+(x+1),T.push(z,k,G),T.push(H,G,k);1!==c&&u&&(T.push(z+2,k+2,G+2),T.push(H+2,G+2,k+2),T.push(z+4,k+4,G+4),T.push(H+4,G+4,k+4)),y=h?y+2:y+1}var W=function(t){var i=t?o/2:s/2;if(0!==i){var r,l,h,u=t?p[m-1]:p[0],f=null;d&&(f=t?d[m-1]:d[0]);var g=E.length/3,v=t?n/2:-n/2,_=new e.Vector3(0,v,0);E.push(_.x,_.y,_.z),A.push(0,t?1:-1,0),P.push(u.x+.5*(u.z-u.x),u.y+.5*(u.w-u.y)),f&&S.push(f.r,f.g,f.b,f.a);var y=new e.Vector2(.5,.5);for(h=0;h<=a;h++){r=2*Math.PI*h*c/a;var x=Math.cos(-r),b=Math.sin(-r);l=new e.Vector3(x*i,v,b*i);var M=new e.Vector2(x*y.x+.5,b*y.y+.5);E.push(l.x,l.y,l.z),A.push(0,t?1:-1,0),P.push(u.x+(u.z-u.x)*M.x,u.y+(u.w-u.y)*M.y),f&&S.push(f.r,f.g,f.b,f.a)}for(h=0;h<a;h++)t?(T.push(g),T.push(g+(h+2)),T.push(g+(h+1))):(T.push(g),T.push(g+(h+1)),T.push(g+(h+2)))}};W(!1),W(!0),t._ComputeSides(f,E,T,A,P,i.frontUVs,i.backUVs);var j=new t;return j.indices=T,j.positions=E,j.normals=A,j.uvs=P,d&&(j.colors=S),j},t.CreateTorus=function(i){for(var r=[],n=[],o=[],s=[],a=i.diameter||1,l=i.thickness||.5,h=i.tessellation||16,u=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,c=h+1,f=0;f<=h;f++)for(var p=f/h,d=f*Math.PI*2/h-Math.PI/2,m=e.Matrix.Translation(a/2,0,0).multiply(e.Matrix.RotationY(d)),g=0;g<=h;g++){var v=1-g/h,_=g*Math.PI*2/h+Math.PI,y=Math.cos(_),x=Math.sin(_),b=new e.Vector3(y,x,0),T=b.scale(l/2),E=new e.Vector2(p,v);T=e.Vector3.TransformCoordinates(T,m),b=e.Vector3.TransformNormal(b,m),n.push(T.x,T.y,T.z),o.push(b.x,b.y,b.z),s.push(E.x,E.y);var A=(f+1)%c,P=(g+1)%c;r.push(f*c+g),r.push(f*c+P),r.push(A*c+g),r.push(f*c+P),r.push(A*c+P),r.push(A*c+g)}t._ComputeSides(u,n,r,o,s,i.frontUVs,i.backUVs);var S=new t;return S.indices=r,S.positions=n,S.normals=o,S.uvs=s,S},t.CreateLineSystem=function(e){for(var i=[],r=[],n=e.lines,o=0,s=0;s<n.length;s++)for(var a=n[s],l=0;l<a.length;l++)r.push(a[l].x,a[l].y,a[l].z),l>0&&(i.push(o-1),i.push(o)),o++;var h=new t;return h.indices=i,h.positions=r,h},t.CreateDashedLines=function(i){var r=i.dashSize||3,n=i.gapSize||1,o=i.dashNb||200,s=i.points,a=new Array,l=new Array,h=e.Vector3.Zero(),u=0,c=0,f=0,p=0,d=0,m=0,g=0;for(g=0;g<s.length-1;g++)s[g+1].subtractToRef(s[g],h),u+=h.length();for(p=r*(f=u/o)/(r+n),g=0;g<s.length-1;g++){s[g+1].subtractToRef(s[g],h),c=Math.floor(h.length()/f),h.normalize();for(var v=0;v<c;v++)d=f*v,a.push(s[g].x+d*h.x,s[g].y+d*h.y,s[g].z+d*h.z),a.push(s[g].x+(d+p)*h.x,s[g].y+(d+p)*h.y,s[g].z+(d+p)*h.z),l.push(m,m+1),m+=2}var _=new t;return _.positions=a,_.indices=l,_},t.CreateGround=function(i){var r,n,o=[],s=[],a=[],l=[],h=i.width||1,u=i.height||1,c=i.subdivisionsX||i.subdivisions||1,f=i.subdivisionsY||i.subdivisions||1;for(r=0;r<=f;r++)for(n=0;n<=c;n++){var p=new e.Vector3(n*h/c-h/2,0,(f-r)*u/f-u/2),d=new e.Vector3(0,1,0);s.push(p.x,p.y,p.z),a.push(d.x,d.y,d.z),l.push(n/c,1-r/f)}for(r=0;r<f;r++)for(n=0;n<c;n++)o.push(n+1+(r+1)*(c+1)),o.push(n+1+r*(c+1)),o.push(n+r*(c+1)),o.push(n+(r+1)*(c+1)),o.push(n+1+(r+1)*(c+1)),o.push(n+r*(c+1));var m=new t;return m.indices=o,m.positions=s,m.normals=a,m.uvs=l,m},t.CreateTiledGround=function(i){var r,n,o,s,a=i.xmin||-1,l=i.zmin||-1,h=i.xmax||1,u=i.zmax||1,c=i.subdivisions||{w:1,h:1},f=i.precision||{w:1,h:1},p=new Array,d=new Array,m=new Array,g=new Array;c.h=c.h<1?1:c.h,c.w=c.w<1?1:c.w,f.w=f.w<1?1:f.w,f.h=f.h<1?1:f.h;var v={w:(h-a)/c.w,h:(u-l)/c.h};for(o=0;o<c.h;o++)for(s=0;s<c.w;s++)!function(t,i,o,s){var a=d.length/3,l=f.w+1;for(r=0;r<f.h;r++)for(n=0;n<f.w;n++){var h=[a+n+r*l,a+(n+1)+r*l,a+(n+1)+(r+1)*l,a+n+(r+1)*l];p.push(h[1]),p.push(h[2]),p.push(h[3]),p.push(h[0]),p.push(h[1]),p.push(h[3])}var u=e.Vector3.Zero(),c=new e.Vector3(0,1,0);for(r=0;r<=f.h;r++)for(u.z=r*(s-i)/f.h+i,n=0;n<=f.w;n++)u.x=n*(o-t)/f.w+t,u.y=0,d.push(u.x,u.y,u.z),m.push(c.x,c.y,c.z),g.push(n/f.w,r/f.h)}(a+s*v.w,l+o*v.h,a+(s+1)*v.w,l+(o+1)*v.h);var _=new t;return _.indices=p,_.positions=d,_.normals=m,_.uvs=g,_},t.CreateGroundFromHeightMap=function(i){var r,n,o=[],s=[],a=[],l=[],h=i.colorFilter||new e.Color3(.3,.59,.11);for(r=0;r<=i.subdivisions;r++)for(n=0;n<=i.subdivisions;n++){var u=new e.Vector3(n*i.width/i.subdivisions-i.width/2,0,(i.subdivisions-r)*i.height/i.subdivisions-i.height/2),c=4*(((u.x+i.width/2)/i.width*(i.bufferWidth-1)|0)+((1-(u.z+i.height/2)/i.height)*(i.bufferHeight-1)|0)*i.bufferWidth),f=i.buffer[c]/255,p=i.buffer[c+1]/255,d=i.buffer[c+2]/255,m=f*h.r+p*h.g+d*h.b;u.y=i.minHeight+(i.maxHeight-i.minHeight)*m,s.push(u.x,u.y,u.z),a.push(0,0,0),l.push(n/i.subdivisions,1-r/i.subdivisions)}for(r=0;r<i.subdivisions;r++)for(n=0;n<i.subdivisions;n++)o.push(n+1+(r+1)*(i.subdivisions+1)),o.push(n+1+r*(i.subdivisions+1)),o.push(n+r*(i.subdivisions+1)),o.push(n+(r+1)*(i.subdivisions+1)),o.push(n+1+(r+1)*(i.subdivisions+1)),o.push(n+r*(i.subdivisions+1));t.ComputeNormals(s,o,a);var g=new t;return g.indices=o,g.positions=s,g.normals=a,g.uvs=l,g},t.CreatePlane=function(i){var r=[],n=[],o=[],s=[],a=i.width||i.size||1,l=i.height||i.size||1,h=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,u=a/2,c=l/2;n.push(-u,-c,0),o.push(0,0,-1),s.push(0,0),n.push(u,-c,0),o.push(0,0,-1),s.push(1,0),n.push(u,c,0),o.push(0,0,-1),s.push(1,1),n.push(-u,c,0),o.push(0,0,-1),s.push(0,1),r.push(0),r.push(1),r.push(2),r.push(0),r.push(2),r.push(3),t._ComputeSides(h,n,r,o,s,i.frontUVs,i.backUVs);var f=new t;return f.indices=r,f.positions=n,f.normals=o,f.uvs=s,f},t.CreateDisc=function(i){var r=new Array,n=new Array,o=new Array,s=new Array,a=i.radius||.5,l=i.tessellation||64,h=i.arc&&(i.arc<=0||i.arc>1)?1:i.arc||1,u=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE;r.push(0,0,0),s.push(.5,.5);for(var c=2*Math.PI*h,f=c/l,p=0;p<c;p+=f){var d=Math.cos(p),m=Math.sin(p),g=(d+1)/2,v=(1-m)/2;r.push(a*d,a*m,0),s.push(g,v)}1===h&&(r.push(r[3],r[4],r[5]),s.push(s[2],s[3]));for(var _=r.length/3,y=1;y<_-1;y++)n.push(y+1,0,y);t.ComputeNormals(r,n,o),t._ComputeSides(u,r,n,o,s,i.frontUVs,i.backUVs);var x=new t;return x.indices=n,x.positions=r,x.normals=o,x.uvs=s,x},t.CreatePolygon=function(i,r,n,o,s,a){for(var l=n||new Array(3),h=o,u=[],c=0;c<3;c++)void 0===l[c]&&(l[c]=new e.Vector4(0,0,1,1)),h&&void 0===h[c]&&(h[c]=new e.Color4(1,1,1,1));for(var f=i.getVerticesData(e.VertexBuffer.PositionKind),p=i.getVerticesData(e.VertexBuffer.NormalKind),d=i.getVerticesData(e.VertexBuffer.UVKind),m=i.getIndices(),g=0,v=0,_=0;_<p.length;_+=3)Math.abs(p[_+1])<.001&&(v=1),Math.abs(p[_+1]-1)<.001&&(v=0),Math.abs(p[_+1]+1)<.001&&(v=2),d[2*(g=_/3)]=(1-d[2*g])*l[v].x+d[2*g]*l[v].z,d[2*g+1]=(1-d[2*g+1])*l[v].y+d[2*g+1]*l[v].w,h&&u.push(h[v].r,h[v].g,h[v].b,h[v].a);t._ComputeSides(r,f,m,p,d,s,a);var y=new t;if(y.indices=m,y.positions=f,y.normals=p,y.uvs=d,h){var x=r===e.Mesh.DOUBLESIDE?u.concat(u):u;y.colors=x}return y},t.CreateIcoSphere=function(i){var r,n=i.sideOrientation||e.Mesh.DEFAULTSIDE,o=i.radius||1,s=void 0===i.flat||i.flat,a=i.subdivisions||4,l=i.radiusX||o,h=i.radiusY||o,u=i.radiusZ||o,c=(1+Math.sqrt(5))/2,f=[-1,c,-0,1,c,0,-1,-c,0,1,-c,0,0,-1,-c,0,1,-c,0,-1,c,0,1,c,c,0,1,c,0,-1,-c,0,1,-c,0,-1],p=[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],d=[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=[0,0,0,0,1,0,0,1,1,0,0,0,1,1,0,0,1,1,1,0],v=new Array,_=new Array,y=new Array,x=new Array,b=0,T=new Array(3),E=new Array(3);for(r=0;r<3;r++)T[r]=e.Vector3.Zero(),E[r]=e.Vector2.Zero();for(var A=0;A<20;A++){for(r=0;r<3;r++){var P=p[3*A+r];T[r].copyFromFloats(f[3*d[P]],f[3*d[P]+1],f[3*d[P]+2]),T[r].normalize().scaleInPlace(o),E[r].copyFromFloats(m[2*P]*(138/1024)+60/1024+g[A]*(-40/1024),m[2*P+1]*(239/1024)+26/1024+g[A]*(20/1024))}for(var S=function(t,i,r,n){var o=e.Vector3.Lerp(T[0],T[2],i/a),c=e.Vector3.Lerp(T[1],T[2],i/a),f=a===i?T[2]:e.Vector3.Lerp(o,c,t/(a-i));f.normalize();var p;if(s){var d=e.Vector3.Lerp(T[0],T[2],n/a),m=e.Vector3.Lerp(T[1],T[2],n/a);p=e.Vector3.Lerp(d,m,r/(a-n))}else p=new e.Vector3(f.x,f.y,f.z);p.x/=l,p.y/=h,p.z/=u,p.normalize();var g=e.Vector2.Lerp(E[0],E[2],i/a),A=e.Vector2.Lerp(E[1],E[2],i/a),P=a===i?E[2]:e.Vector2.Lerp(g,A,t/(a-i));_.push(f.x*l,f.y*h,f.z*u),y.push(p.x,p.y,p.z),x.push(P.x,P.y),v.push(b),b++},M=0;M<a;M++)for(var C=0;C+M<a;C++)S(C,M,C+1/3,M+1/3),S(C+1,M,C+1/3,M+1/3),S(C,M+1,C+1/3,M+1/3),C+M+1<a&&(S(C+1,M,C+2/3,M+2/3),S(C+1,M+1,C+2/3,M+2/3),S(C,M+1,C+2/3,M+2/3))}t._ComputeSides(n,_,v,y,x,i.frontUVs,i.backUVs);var R=new t;return R.indices=v,R.positions=_,R.normals=y,R.uvs=x,R},t.CreatePolyhedron=function(i){var r=[];r[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]]},r[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]]},r[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]]},r[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]]},r[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]]},r[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]]},r[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]]},r[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]]},r[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]]},r[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]]},r[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]]},r[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]]},r[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]]},r[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]]},r[14]={vertex:[[-.93465,.300459,-.271185],[-.838689,-.260219,-.516017],[-.711319,.717591,.128359],[-.710334,-.156922,.080946],[-.599799,.556003,-.725148],[-.503838,-.004675,-.969981],[-.487004,.26021,.48049],[-.460089,-.750282,-.512622],[-.376468,.973135,-.325605],[-.331735,-.646985,.084342],[-.254001,.831847,.530001],[-.125239,-.494738,-.966586],[.029622,.027949,.730817],[.056536,-.982543,-.262295],[.08085,1.087391,.076037],[.125583,-.532729,.485984],[.262625,.599586,.780328],[.391387,-.726999,-.716259],[.513854,-.868287,.139347],[.597475,.85513,.326364],[.641224,.109523,.783723],[.737185,-.451155,.538891],[.848705,-.612742,-.314616],[.976075,.365067,.32976],[1.072036,-.19561,.084927]],face:[[15,18,21],[12,20,16],[6,10,2],[3,0,1],[9,7,13],[2,8,4,0],[0,4,5,1],[1,5,11,7],[7,11,17,13],[13,17,22,18],[18,22,24,21],[21,24,23,20],[20,23,19,16],[16,19,14,10],[10,14,8,2],[15,9,13,18],[12,15,21,20],[6,12,16,10],[3,6,2,0],[9,3,1,7],[9,15,12,6,3],[22,17,11,5,4,8,14,19,23,24]]};var n,o,s,a,l,h,u=i.type&&(i.type<0||i.type>=r.length)?0:i.type||0,c=i.size,f=i.sizeX||c||1,p=i.sizeY||c||1,d=i.sizeZ||c||1,m=i.custom||r[u],g=m.face.length,v=i.faceUV||new Array(g),_=i.faceColors,y=void 0===i.flat||i.flat,x=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,b=new Array,T=new Array,E=new Array,A=new Array,P=new Array,S=0,M=0,C=new Array,R=0,I=0;if(y)for(I=0;I<g;I++)_&&void 0===_[I]&&(_[I]=new e.Color4(1,1,1,1)),v&&void 0===v[I]&&(v[I]=new e.Vector4(0,0,1,1));if(y)for(I=0;I<g;I++){var O=m.face[I].length;for(s=2*Math.PI/O,a=.5*Math.tan(s/2),l=.5,R=0;R<O;R++)b.push(m.vertex[m.face[I][R]][0]*f,m.vertex[m.face[I][R]][1]*p,m.vertex[m.face[I][R]][2]*d),C.push(S),S++,n=v[I].x+(v[I].z-v[I].x)*(.5+a),o=v[I].y+(v[I].w-v[I].y)*(l-.5),A.push(n,o),h=a*Math.cos(s)-l*Math.sin(s),l=a*Math.sin(s)+l*Math.cos(s),a=h,_&&P.push(_[I].r,_[I].g,_[I].b,_[I].a);for(R=0;R<O-2;R++)T.push(C[0+M],C[R+2+M],C[R+1+M]);M+=O}else{for(R=0;R<m.vertex.length;R++)b.push(m.vertex[R][0]*f,m.vertex[R][1]*p,m.vertex[R][2]*d),A.push(0,0);for(I=0;I<g;I++)for(R=0;R<m.face[I].length-2;R++)T.push(m.face[I][0],m.face[I][R+2],m.face[I][R+1])}t.ComputeNormals(b,T,E),t._ComputeSides(x,b,T,E,A,i.frontUVs,i.backUVs);var D=new t;return D.positions=b,D.indices=T,D.normals=E,D.uvs=A,_&&y&&(D.colors=P),D},t.CreateTorusKnot=function(i){var r,n,o=new Array,s=new Array,a=new Array,l=new Array,h=i.radius||2,u=i.tube||.5,c=i.radialSegments||32,f=i.tubularSegments||32,p=i.p||2,d=i.q||3,m=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,g=function(t){var i=Math.cos(t),r=Math.sin(t),n=d/p*t,o=Math.cos(n),s=h*(2+o)*.5*i,a=h*(2+o)*r*.5,l=h*Math.sin(n)*.5;return new e.Vector3(s,a,l)};for(r=0;r<=c;r++){var v=r%c/c*2*p*Math.PI,_=g(v),y=g(v+.01),x=y.subtract(_),b=y.add(_),T=e.Vector3.Cross(x,b);for(b=e.Vector3.Cross(T,x),T.normalize(),b.normalize(),n=0;n<f;n++){var E=n%f/f*2*Math.PI,A=-u*Math.cos(E),P=u*Math.sin(E);s.push(_.x+A*b.x+P*T.x),s.push(_.y+A*b.y+P*T.y),s.push(_.z+A*b.z+P*T.z),l.push(r/c),l.push(n/f)}}for(r=0;r<c;r++)for(n=0;n<f;n++){var S=(n+1)%f,M=r*f+n,C=(r+1)*f+n,R=(r+1)*f+S,I=r*f+S;o.push(I),o.push(C),o.push(M),o.push(I),o.push(R),o.push(C)}t.ComputeNormals(s,o,a),t._ComputeSides(m,s,o,a,l,i.frontUVs,i.backUVs);var O=new t;return O.indices=o,O.positions=s,O.normals=a,O.uvs=l,O},t.ComputeNormals=function(t,i,r,n){var o=0,s=0,a=0,l=0,h=0,u=0,c=0,f=0,p=0,d=0,m=0,g=0,v=0,_=0,y=0,x=0,b=0,T=0,E=0,A=0,P=!1,S=!1,M=!1,C=!1,R=1,I=0,O=null;if(n&&(P=!!n.facetNormals,S=!!n.facetPositions,M=!!n.facetPartitioning,R=!0===n.useRightHandedSystem?-1:1,I=n.ratio||0,C=!!n.depthSort,O=n.distanceTo,C)){void 0===O&&(O=e.Vector3.Zero());var D=n.depthSortedFacets}var w=0,L=0,F=0,N=0;if(M&&n&&n.bbSize){var B=0,V=0,U=0,z=0,k=0,G=0,H=0,W=0,j=0,X=0,Y=0,K=0,Q=0,Z=0,q=0,J=0,$=n.bbSize.x>n.bbSize.y?n.bbSize.x:n.bbSize.y;$=$>n.bbSize.z?$:n.bbSize.z,w=n.subDiv.X*I/n.bbSize.x,L=n.subDiv.Y*I/n.bbSize.y,F=n.subDiv.Z*I/n.bbSize.z,N=n.subDiv.max*n.subDiv.max,n.facetPartitioning.length=0}for(o=0;o<t.length;o++)r[o]=0;var ee=i.length/3;for(o=0;o<ee;o++){if(g=3*i[3*o],v=g+1,_=g+2,y=3*i[3*o+1],x=y+1,b=y+2,T=3*i[3*o+2],E=T+1,A=T+2,s=t[g]-t[y],a=t[v]-t[x],l=t[_]-t[b],h=t[T]-t[y],u=t[E]-t[x],c=t[A]-t[b],f=R*(a*c-l*u),p=R*(l*h-s*c),d=R*(s*u-a*h),m=Math.sqrt(f*f+p*p+d*d),m=0===m?1:m,f/=m,p/=m,d/=m,P&&n&&(n.facetNormals[o].x=f,n.facetNormals[o].y=p,n.facetNormals[o].z=d),S&&n&&(n.facetPositions[o].x=(t[g]+t[y]+t[T])/3,n.facetPositions[o].y=(t[v]+t[x]+t[E])/3,n.facetPositions[o].z=(t[_]+t[b]+t[A])/3),M&&n&&(B=Math.floor((n.facetPositions[o].x-n.bInfo.minimum.x*I)*w),V=Math.floor((n.facetPositions[o].y-n.bInfo.minimum.y*I)*L),U=Math.floor((n.facetPositions[o].z-n.bInfo.minimum.z*I)*F),z=Math.floor((t[g]-n.bInfo.minimum.x*I)*w),k=Math.floor((t[v]-n.bInfo.minimum.y*I)*L),G=Math.floor((t[_]-n.bInfo.minimum.z*I)*F),H=Math.floor((t[y]-n.bInfo.minimum.x*I)*w),W=Math.floor((t[x]-n.bInfo.minimum.y*I)*L),j=Math.floor((t[b]-n.bInfo.minimum.z*I)*F),X=Math.floor((t[T]-n.bInfo.minimum.x*I)*w),Y=Math.floor((t[E]-n.bInfo.minimum.y*I)*L),K=Math.floor((t[A]-n.bInfo.minimum.z*I)*F),Z=z+n.subDiv.max*k+N*G,q=H+n.subDiv.max*W+N*j,J=X+n.subDiv.max*Y+N*K,Q=B+n.subDiv.max*V+N*U,n.facetPartitioning[Q]=n.facetPartitioning[Q]?n.facetPartitioning[Q]:new Array,n.facetPartitioning[Z]=n.facetPartitioning[Z]?n.facetPartitioning[Z]:new Array,n.facetPartitioning[q]=n.facetPartitioning[q]?n.facetPartitioning[q]:new Array,n.facetPartitioning[J]=n.facetPartitioning[J]?n.facetPartitioning[J]:new Array,n.facetPartitioning[Z].push(o),q!=Z&&n.facetPartitioning[q].push(o),J!=q&&J!=Z&&n.facetPartitioning[J].push(o),Q!=Z&&Q!=q&&Q!=J&&n.facetPartitioning[Q].push(o)),C&&n&&n.facetPositions){var te=D[o];te.ind=3*o,te.sqDistance=e.Vector3.DistanceSquared(n.facetPositions[o],O)}r[g]+=f,r[v]+=p,r[_]+=d,r[y]+=f,r[x]+=p,r[b]+=d,r[T]+=f,r[E]+=p,r[A]+=d}for(o=0;o<r.length/3;o++)f=r[3*o],p=r[3*o+1],d=r[3*o+2],f/=m=0===(m=Math.sqrt(f*f+p*p+d*d))?1:m,p/=m,d/=m,r[3*o]=f,r[3*o+1]=p,r[3*o+2]=d},t._ComputeSides=function(t,i,r,n,o,s,a){var l,h,u=r.length,c=n.length;switch(t=t||e.Mesh.DEFAULTSIDE){case e.Mesh.FRONTSIDE:break;case e.Mesh.BACKSIDE:var f;for(l=0;l<u;l+=3)f=r[l],r[l]=r[l+2],r[l+2]=f;for(h=0;h<c;h++)n[h]=-n[h];break;case e.Mesh.DOUBLESIDE:for(var p=i.length,d=p/3,m=0;m<p;m++)i[p+m]=i[m];for(l=0;l<u;l+=3)r[l+u]=r[l+2]+d,r[l+1+u]=r[l+1]+d,r[l+2+u]=r[l]+d;for(h=0;h<c;h++)n[c+h]=-n[h];var g=o.length,v=0;for(v=0;v<g;v++)o[v+g]=o[v];for(s=s||new e.Vector4(0,0,1,1),a=a||new e.Vector4(0,0,1,1),v=0,l=0;l<g/2;l++)o[v]=s.x+(s.z-s.x)*o[v],o[v+1]=s.y+(s.w-s.y)*o[v+1],o[v+g]=a.x+(a.z-a.x)*o[v+g],o[v+g+1]=a.y+(a.w-a.y)*o[v+g+1],v+=2}},t.ImportVertexData=function(i,r){var n=new t,o=i.positions;o&&n.set(o,e.VertexBuffer.PositionKind);var s=i.normals;s&&n.set(s,e.VertexBuffer.NormalKind);var a=i.tangents;a&&n.set(a,e.VertexBuffer.TangentKind);var l=i.uvs;l&&n.set(l,e.VertexBuffer.UVKind);var h=i.uv2s;h&&n.set(h,e.VertexBuffer.UV2Kind);var u=i.uv3s;u&&n.set(u,e.VertexBuffer.UV3Kind);var c=i.uv4s;c&&n.set(c,e.VertexBuffer.UV4Kind);var f=i.uv5s;f&&n.set(f,e.VertexBuffer.UV5Kind);var p=i.uv6s;p&&n.set(p,e.VertexBuffer.UV6Kind);var d=i.colors;d&&n.set(e.Color4.CheckColors4(d,o.length/3),e.VertexBuffer.ColorKind);var m=i.matricesIndices;m&&n.set(m,e.VertexBuffer.MatricesIndicesKind);var g=i.matricesWeights;g&&n.set(g,e.VertexBuffer.MatricesWeightsKind);var v=i.indices;v&&(n.indices=v),r.setAllVerticesData(n,i.updatable)},t}();e.VertexData=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n,o){void 0===n&&(n=!1),void 0===o&&(o=null),this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this._totalVertices=0,this._isDisposed=!1,this._indexBufferIsUpdatable=!1,this.id=t,this._engine=i.getEngine(),this._meshes=[],this._scene=i,this._vertexBuffers={},this._indices=[],this._updatable=n,r?this.setAllVerticesData(r,n):(this._totalVertices=0,this._indices=[]),this._engine.getCaps().vertexArrayObject&&(this._vertexArrayObjects={}),o&&("LinesMesh"===o.getClassName()&&(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.updateBoundingInfo(!0,null))},enumerable:!0,configurable:!0}),t.CreateGeometryForMesh=function(e){var i=new t(t.RandomId(),e.getScene());return i.applyToMesh(e),i},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},Object.defineProperty(t.prototype,"doNotSerialize",{get:function(){for(var e=0;e<this._meshes.length;e++)if(!this._meshes[e].doNotSerialize)return!1;return!0},enumerable:!0,configurable:!0}),t.prototype._rebuild=function(){this._vertexArrayObjects&&(this._vertexArrayObjects={}),0!==this._meshes.length&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices));for(var e in this._vertexBuffers)this._vertexBuffers[e]._rebuild()},t.prototype.setAllVerticesData=function(e,t){e.applyToGeometry(this,t),this.notifyUpdate()},t.prototype.setVerticesData=function(t,i,r,n){void 0===r&&(r=!1);var o=new e.VertexBuffer(this._engine,i,t,r,0===this._meshes.length,n);this.setVerticesBuffer(o)},t.prototype.removeVerticesData=function(e){this._vertexBuffers[e]&&(this._vertexBuffers[e].dispose(),delete this._vertexBuffers[e])},t.prototype.setVerticesBuffer=function(t){var i=t.getKind();if(this._vertexBuffers[i]&&this._vertexBuffers[i].dispose(),this._vertexBuffers[i]=t,i===e.VertexBuffer.PositionKind){var r=t.getData(),n=t.getStrideSize();this._totalVertices=r.length/n,this.updateExtend(r,n),this._resetPointsArrayCache();for(var o=this._meshes,s=o.length,a=0;a<s;a++){var l=o[a];l._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),l._createGlobalSubMesh(!1),l.computeWorldMatrix(!0)}}this.notifyUpdate(i),this._vertexArrayObjects&&(this._disposeVertexArrayObjects(),this._vertexArrayObjects={})},t.prototype.updateVerticesDataDirectly=function(e,t,i){var r=this.getVertexBuffer(e);r&&(r.updateDirectly(t,i),this.notifyUpdate(e))},t.prototype.updateVerticesData=function(t,i,r){void 0===r&&(r=!1);var n=this.getVertexBuffer(t);if(n){if(n.update(i),t===e.VertexBuffer.PositionKind){var o=n.getStrideSize();this._totalVertices=i.length/o,this.updateBoundingInfo(r,i)}this.notifyUpdate(t)}},t.prototype.updateBoundingInfo=function(t,i){t&&this.updateExtend(i);var r=this._meshes,n=r.length;this._resetPointsArrayCache();for(var o=0;o<n;o++){var s=r[o];if(t){s._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum);for(var a=0;a<s.subMeshes.length;a++)s.subMeshes[a].refreshBoundingInfo()}}},t.prototype._bind=function(e,t){if(e){void 0===t&&(t=this._indexBuffer);var i=this.getVertexBuffers();i&&(t==this._indexBuffer&&this._vertexArrayObjects?(this._vertexArrayObjects[e.key]||(this._vertexArrayObjects[e.key]=this._engine.recordVertexArrayObject(i,t,e)),this._engine.bindVertexArrayObject(this._vertexArrayObjects[e.key],t)):this._engine.bindBuffers(i,t,e))}},t.prototype.getTotalVertices=function(){return this.isReady()?this._totalVertices:0},t.prototype.getVerticesData=function(e,t,i){var r=this.getVertexBuffer(e);if(!r)return null;var n=r.getData();if(i||t&&1!==this._meshes.length){for(var o=n.length,s=[],a=0;a<o;a++)s.push(n[a]);return s}return n},t.prototype.isVertexBufferUpdatable=function(e){var t=this._vertexBuffers[e];return!!t&&t.isUpdatable()},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)},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.updateIndices=function(e,t){this._indexBuffer&&(this._indexBufferIsUpdatable?this._engine.updateDynamicIndexBuffer(this._indexBuffer,e,t):this.setIndices(e,null,!0))},t.prototype.setIndices=function(e,t,i){void 0===t&&(t=null),void 0===i&&(i=!1),this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._disposeVertexArrayObjects(),this._indices=e,this._indexBufferIsUpdatable=i,0!==this._meshes.length&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices,i)),void 0!=t&&(this._totalVertices=t);for(var r=this._meshes,n=r.length,o=0;o<n;o++)r[o]._createGlobalSubMesh(!0);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,r=[],n=0;n<i;n++)r.push(t[n]);return r}return t},t.prototype.getIndexBuffer=function(){return this.isReady()?this._indexBuffer:null},t.prototype._releaseVertexArrayObject=function(e){void 0===e&&(e=null),e&&this._vertexArrayObjects&&this._vertexArrayObjects[e.key]&&(this._engine.releaseVertexArrayObject(this._vertexArrayObjects[e.key]),delete this._vertexArrayObjects[e.key])},t.prototype.releaseForMesh=function(e,t){var i=this._meshes,r=i.indexOf(e);-1!==r&&(i.splice(r,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,i){void 0===t&&(t=null),t||(t=this._vertexBuffers[e.VertexBuffer.PositionKind].getData()),this._extend=e.Tools.ExtractMinAndMax(t,0,this._totalVertices,this.boundingBias,i)},t.prototype._applyToMesh=function(t){var i=this._meshes.length;for(var r in this._vertexBuffers){1===i&&this._vertexBuffers[r].create();var n=this._vertexBuffers[r].getBuffer();n&&(n.references=i),r===e.VertexBuffer.PositionKind&&(this._extend||this.updateExtend(this._vertexBuffers[r].getData()),t._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),t._createGlobalSubMesh(!1),t._updateBoundingInfo())}1===i&&this._indices&&this._indices.length>0&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),this._indexBuffer&&(this._indexBuffer.references=i)},t.prototype.notifyUpdate=function(e){this.onGeometryUpdated&&this.onGeometryUpdated(this,e);for(var t=0,i=this._meshes;t<i.length;t++)i[t]._markSubMeshesAsAttributesDirty()},t.prototype.load=function(t,i){this.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADING&&(this.isReady()?i&&i():(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,this._queueLoad(t,i)))},t.prototype._queueLoad=function(t,i){var r=this;this.delayLoadingFile&&(t._addPendingData(this),e.Tools.LoadFile(this.delayLoadingFile,function(n){if(r._delayLoadingFunction){r._delayLoadingFunction(JSON.parse(n),r),r.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,r._delayInfo=[],t._removePendingData(r);for(var o=r._meshes,s=o.length,a=0;a<s;a++)r._applyToMesh(o[a]);i&&i()}},function(){},t.database))},t.prototype.toLeftHanded=function(){var t=this.getIndices(!1);if(null!=t&&t.length>0){for(o=0;o<t.length;o+=3){var i=t[o+0];t[o+0]=t[o+2],t[o+2]=i}this.setIndices(t)}var r=this.getVerticesData(e.VertexBuffer.PositionKind,!1);if(null!=r&&r.length>0){for(o=0;o<r.length;o+=3)r[o+2]=-r[o+2];this.setVerticesData(e.VertexBuffer.PositionKind,r,!1)}var n=this.getVerticesData(e.VertexBuffer.NormalKind,!1);if(null!=n&&n.length>0){for(var o=0;o<n.length;o+=3)n[o+2]=-n[o+2];this.setVerticesData(e.VertexBuffer.NormalKind,n,!1)}},t.prototype._resetPointsArrayCache=function(){this._positions=null},t.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},t.prototype.isDisposed=function(){return this._isDisposed},t.prototype._disposeVertexArrayObjects=function(){if(this._vertexArrayObjects){for(var e in this._vertexArrayObjects)this._engine.releaseVertexArrayObject(this._vertexArrayObjects[e]);this._vertexArrayObjects={}}},t.prototype.dispose=function(){var t,i=this._meshes,r=i.length;for(t=0;t<r;t++)this.releaseForMesh(i[t]);this._meshes=[],this._disposeVertexArrayObjects();for(var n in this._vertexBuffers)this._vertexBuffers[n].dispose();this._vertexBuffers={},this._totalVertices=0,this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indexBuffer=null,this._indices=[],this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this.delayLoadingFile=null,this._delayLoadingFunction=null,this._delayInfo=[],this._boundingInfo=null,this._scene.removeGeometry(this),this._isDisposed=!0},t.prototype.copy=function(i){var r=new e.VertexData;r.indices=[];var n=this.getIndices();if(n)for(var o=0;o<n.length;o++)r.indices.push(n[o]);var s,a=!1,l=!1;for(s in this._vertexBuffers){var h=this.getVerticesData(s);if(h instanceof Float32Array?r.set(new Float32Array(h),s):r.set(h.slice(0),s),!l){var u=this.getVertexBuffer(s);u&&(l=!(a=u.isUpdatable()))}}var c=new t(i,this._scene,r,a);c.delayLoadState=this.delayLoadState,c.delayLoadingFile=this.delayLoadingFile,c._delayLoadingFunction=this._delayLoadingFunction;for(s in this._delayInfo)c._delayInfo=c._delayInfo||[],c._delayInfo.push(s);return c._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),c},t.prototype.serialize=function(){var t={};return t.id=this.id,t.updatable=this._updatable,e.Tags&&e.Tags.HasTags(this)&&(t.tags=e.Tags.GetTags(this)),t},t.prototype.toNumberArray=function(e){return Array.isArray(e)?e:Array.prototype.slice.call(e)},t.prototype.serializeVerticeData=function(){var t=this.serialize();return this.isVerticesDataPresent(e.VertexBuffer.PositionKind)&&(t.positions=this.toNumberArray(this.getVerticesData(e.VertexBuffer.PositionKind)),this.isVertexBufferUpdatable(e.VertexBuffer.PositionKind)&&(t.positions._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(t.normals=this.toNumberArray(this.getVerticesData(e.VertexBuffer.NormalKind)),this.isVertexBufferUpdatable(e.VertexBuffer.NormalKind)&&(t.normals._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(t.uvs=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UVKind)),this.isVertexBufferUpdatable(e.VertexBuffer.UVKind)&&(t.uvs._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(t.uv2s=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UV2Kind)),this.isVertexBufferUpdatable(e.VertexBuffer.UV2Kind)&&(t.uv2s._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UV3Kind)&&(t.uv3s=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UV3Kind)),this.isVertexBufferUpdatable(e.VertexBuffer.UV3Kind)&&(t.uv3s._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UV4Kind)&&(t.uv4s=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UV4Kind)),this.isVertexBufferUpdatable(e.VertexBuffer.UV4Kind)&&(t.uv4s._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UV5Kind)&&(t.uv5s=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UV5Kind)),this.isVertexBufferUpdatable(e.VertexBuffer.UV5Kind)&&(t.uv5s._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UV6Kind)&&(t.uv6s=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UV6Kind)),this.isVertexBufferUpdatable(e.VertexBuffer.UV6Kind)&&(t.uv6s._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(t.colors=this.toNumberArray(this.getVerticesData(e.VertexBuffer.ColorKind)),this.isVertexBufferUpdatable(e.VertexBuffer.ColorKind)&&(t.colors._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&(t.matricesIndices=this.toNumberArray(this.getVerticesData(e.VertexBuffer.MatricesIndicesKind)),t.matricesIndices._isExpanded=!0,this.isVertexBufferUpdatable(e.VertexBuffer.MatricesIndicesKind)&&(t.matricesIndices._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)&&(t.matricesWeights=this.toNumberArray(this.getVerticesData(e.VertexBuffer.MatricesWeightsKind)),this.isVertexBufferUpdatable(e.VertexBuffer.MatricesWeightsKind)&&(t.matricesWeights._updatable=!0)),t.indices=this.toNumberArray(this.getIndices()),t},t.ExtractFromMesh=function(e,t){var i=e._geometry;return i?i.copy(t):null},t.RandomId=function(){return e.Tools.RandomId()},t.ImportGeometry=function(i,r){var n=r.getScene(),o=i.geometryId;if(o){var s=n.getGeometryByID(o);s&&s.applyToMesh(r)}else if(i instanceof ArrayBuffer){var a=r._binaryInfo;if(a.positionsAttrDesc&&a.positionsAttrDesc.count>0){var l=new Float32Array(i,a.positionsAttrDesc.offset,a.positionsAttrDesc.count);r.setVerticesData(e.VertexBuffer.PositionKind,l,!1)}if(a.normalsAttrDesc&&a.normalsAttrDesc.count>0){var h=new Float32Array(i,a.normalsAttrDesc.offset,a.normalsAttrDesc.count);r.setVerticesData(e.VertexBuffer.NormalKind,h,!1)}if(a.uvsAttrDesc&&a.uvsAttrDesc.count>0){var u=new Float32Array(i,a.uvsAttrDesc.offset,a.uvsAttrDesc.count);r.setVerticesData(e.VertexBuffer.UVKind,u,!1)}if(a.uvs2AttrDesc&&a.uvs2AttrDesc.count>0){var c=new Float32Array(i,a.uvs2AttrDesc.offset,a.uvs2AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV2Kind,c,!1)}if(a.uvs3AttrDesc&&a.uvs3AttrDesc.count>0){var f=new Float32Array(i,a.uvs3AttrDesc.offset,a.uvs3AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV3Kind,f,!1)}if(a.uvs4AttrDesc&&a.uvs4AttrDesc.count>0){var p=new Float32Array(i,a.uvs4AttrDesc.offset,a.uvs4AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV4Kind,p,!1)}if(a.uvs5AttrDesc&&a.uvs5AttrDesc.count>0){var d=new Float32Array(i,a.uvs5AttrDesc.offset,a.uvs5AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV5Kind,d,!1)}if(a.uvs6AttrDesc&&a.uvs6AttrDesc.count>0){var m=new Float32Array(i,a.uvs6AttrDesc.offset,a.uvs6AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV6Kind,m,!1)}if(a.colorsAttrDesc&&a.colorsAttrDesc.count>0){var g=new Float32Array(i,a.colorsAttrDesc.offset,a.colorsAttrDesc.count);r.setVerticesData(e.VertexBuffer.ColorKind,g,!1,a.colorsAttrDesc.stride)}if(a.matricesIndicesAttrDesc&&a.matricesIndicesAttrDesc.count>0){var v=new Int32Array(i,a.matricesIndicesAttrDesc.offset,a.matricesIndicesAttrDesc.count);r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,v,!1)}if(a.matricesWeightsAttrDesc&&a.matricesWeightsAttrDesc.count>0){var _=new Float32Array(i,a.matricesWeightsAttrDesc.offset,a.matricesWeightsAttrDesc.count);r.setVerticesData(e.VertexBuffer.MatricesWeightsKind,_,!1)}if(a.indicesAttrDesc&&a.indicesAttrDesc.count>0){var y=new Int32Array(i,a.indicesAttrDesc.offset,a.indicesAttrDesc.count);r.setIndices(y,null)}if(a.subMeshesAttrDesc&&a.subMeshesAttrDesc.count>0){var x=new Int32Array(i,a.subMeshesAttrDesc.offset,5*a.subMeshesAttrDesc.count);r.subMeshes=[];for(M=0;M<a.subMeshesAttrDesc.count;M++){var b=x[5*M+0],T=x[5*M+1],E=x[5*M+2],A=x[5*M+3],P=x[5*M+4];e.SubMesh.AddToMesh(b,T,E,A,P,r)}}}else if(i.positions&&i.normals&&i.indices){if(r.setVerticesData(e.VertexBuffer.PositionKind,i.positions,i.positions._updatable),r.setVerticesData(e.VertexBuffer.NormalKind,i.normals,i.normals._updatable),i.uvs&&r.setVerticesData(e.VertexBuffer.UVKind,i.uvs,i.uvs._updatable),i.uvs2&&r.setVerticesData(e.VertexBuffer.UV2Kind,i.uvs2,i.uvs2._updatable),i.uvs3&&r.setVerticesData(e.VertexBuffer.UV3Kind,i.uvs3,i.uvs3._updatable),i.uvs4&&r.setVerticesData(e.VertexBuffer.UV4Kind,i.uvs4,i.uvs4._updatable),i.uvs5&&r.setVerticesData(e.VertexBuffer.UV5Kind,i.uvs5,i.uvs5._updatable),i.uvs6&&r.setVerticesData(e.VertexBuffer.UV6Kind,i.uvs6,i.uvs6._updatable),i.colors&&r.setVerticesData(e.VertexBuffer.ColorKind,e.Color4.CheckColors4(i.colors,i.positions.length/3),i.colors._updatable),i.matricesIndices)if(i.matricesIndices._isExpanded)delete i.matricesIndices._isExpanded,r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,i.matricesIndices,i.matricesIndices._updatable);else{for(var S=[],M=0;M<i.matricesIndices.length;M++){C=i.matricesIndices[M];S.push(255&C),S.push((65280&C)>>8),S.push((16711680&C)>>16),S.push(C>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,S,i.matricesIndices._updatable)}if(i.matricesIndicesExtra)if(i.matricesIndicesExtra._isExpanded)delete i.matricesIndices._isExpanded,r.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,i.matricesIndicesExtra,i.matricesIndicesExtra._updatable);else{for(var S=[],M=0;M<i.matricesIndicesExtra.length;M++){var C=i.matricesIndicesExtra[M];S.push(255&C),S.push((65280&C)>>8),S.push((16711680&C)>>16),S.push(C>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,S,i.matricesIndicesExtra._updatable)}i.matricesWeights&&(t._CleanMatricesWeights(i,r),r.setVerticesData(e.VertexBuffer.MatricesWeightsKind,i.matricesWeights,i.matricesWeights._updatable)),i.matricesWeightsExtra&&r.setVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,i.matricesWeightsExtra,i.matricesWeights._updatable),r.setIndices(i.indices,null)}if(i.subMeshes){r.subMeshes=[];for(var R=0;R<i.subMeshes.length;R++){var I=i.subMeshes[R];e.SubMesh.AddToMesh(I.materialIndex,I.verticesStart,I.verticesCount,I.indexStart,I.indexCount,r)}}r._shouldGenerateFlatShading&&(r.convertToFlatShadedMesh(),delete r._shouldGenerateFlatShading),r.computeWorldMatrix(!0),n._selectionOctree&&n._selectionOctree.addMesh(r)},t._CleanMatricesWeights=function(t,i){if(e.SceneLoader.CleanBoneMatrixWeights){var r=0;if(t.skeletonId>-1){var n=i.getScene().getLastSkeletonByID(t.skeletonId);if(n){r=n.bones.length;for(var o=i.getVerticesData(e.VertexBuffer.MatricesIndicesKind),s=i.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind),a=t.matricesWeights,l=t.matricesWeightsExtra,h=t.numBoneInfluencer,u=a.length,c=0;c<u;c+=4){for(var f=0,p=-1,d=0;d<4;d++)f+=m=a[c+d],m<.001&&p<0&&(p=d);if(l)for(d=0;d<4;d++){var m=l[c+d];f+=m,m<.001&&p<0&&(p=d+4)}if((p<0||p>h-1)&&(p=h-1),f>.001){for(var g=1/f,d=0;d<4;d++)a[c+d]*=g;if(l)for(d=0;d<4;d++)l[c+d]*=g}else p>=4?(l[c+p-4]=1-f,s[c+p-4]=r):(a[c+p]=1-f,o[c+p]=r)}i.setVerticesData(e.VertexBuffer.MatricesIndicesKind,o),t.matricesWeightsExtra&&i.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,s)}}}},t.Parse=function(i,r,n){if(r.getGeometryByID(i.id))return null;var o=new t(i.id,r,void 0,i.updatable);return e.Tags&&e.Tags.AddTagsTo(o,i.tags),i.delayLoadingFile?(o.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,o.delayLoadingFile=n+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),r.pushGeometry(o,!0),o},t}();e.Geometry=t,function(t){!function(i){var r=function(e){function t(t,i,r,n){void 0===r&&(r=!1),void 0===n&&(n=null);var o=e.call(this,t,i,void 0,!1,n)||this;return o._canBeRegenerated=r,o._beingRegenerated=!0,o.regenerate(),o._beingRegenerated=!1,o}return n(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,r){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=r;var o=function(t){function i(i,r,n,o,s,a,l,h,u){void 0===u&&(u=e.Mesh.DEFAULTSIDE);var c=t.call(this,i,r,l,h)||this;return c.pathArray=n,c.closeArray=o,c.closePath=s,c.offset=a,c.side=u,c}return n(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(),void 0,this.side)},i}(r);i.Ribbon=o;var s=function(i){function r(t,r,n,o,s,a){void 0===s&&(s=null),void 0===a&&(a=e.Mesh.DEFAULTSIDE);var l=i.call(this,t,r,o,s)||this;return l.size=n,l.side=a,l}return n(r,i),r.prototype._regenerateVertexData=function(){return e.VertexData.CreateBox({size:this.size,sideOrientation:this.side})},r.prototype.copy=function(e){return new r(e,this.getScene(),this.size,this.canBeRegenerated(),void 0,this.side)},r.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.size=this.size,e},r.Parse=function(i,r){if(r.getGeometryByID(i.id))return null;var n=new t.Primitives.Box(i.id,r,i.size,i.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,i.tags),r.pushGeometry(n,!0),n},r}(r);i.Box=s;var a=function(i){function r(t,r,n,o,s,a,l){void 0===a&&(a=null),void 0===l&&(l=e.Mesh.DEFAULTSIDE);var h=i.call(this,t,r,s,a)||this;return h.segments=n,h.diameter=o,h.side=l,h}return n(r,i),r.prototype._regenerateVertexData=function(){return e.VertexData.CreateSphere({segments:this.segments,diameter:this.diameter,sideOrientation:this.side})},r.prototype.copy=function(e){return new r(e,this.getScene(),this.segments,this.diameter,this.canBeRegenerated(),null,this.side)},r.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.segments=this.segments,e.diameter=this.diameter,e},r.Parse=function(i,r){if(r.getGeometryByID(i.id))return null;var n=new t.Primitives.Sphere(i.id,r,i.segments,i.diameter,i.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,i.tags),r.pushGeometry(n,!0),n},r}(r);i.Sphere=a;var l=function(t){function i(i,r,n,o,s,a,l){void 0===a&&(a=null),void 0===l&&(l=e.Mesh.DEFAULTSIDE);var h=t.call(this,i,r,s,a)||this;return h.radius=n,h.tessellation=o,h.side=l,h}return n(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}(r);i.Disc=l;var h=function(i){function r(t,r,n,o,s,a,l,h,u,c){void 0===l&&(l=1),void 0===u&&(u=null),void 0===c&&(c=e.Mesh.DEFAULTSIDE);var f=i.call(this,t,r,h,u)||this;return f.height=n,f.diameterTop=o,f.diameterBottom=s,f.tessellation=a,f.subdivisions=l,f.side=c,f}return n(r,i),r.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})},r.prototype.copy=function(e){return new r(e,this.getScene(),this.height,this.diameterTop,this.diameterBottom,this.tessellation,this.subdivisions,this.canBeRegenerated(),null,this.side)},r.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},r.Parse=function(i,r){if(r.getGeometryByID(i.id))return null;var n=new t.Primitives.Cylinder(i.id,r,i.height,i.diameterTop,i.diameterBottom,i.tessellation,i.subdivisions,i.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,i.tags),r.pushGeometry(n,!0),n},r}(r);i.Cylinder=h;var u=function(i){function r(t,r,n,o,s,a,l,h){void 0===l&&(l=null),void 0===h&&(h=e.Mesh.DEFAULTSIDE);var u=i.call(this,t,r,a,l)||this;return u.diameter=n,u.thickness=o,u.tessellation=s,u.side=h,u}return n(r,i),r.prototype._regenerateVertexData=function(){return e.VertexData.CreateTorus({diameter:this.diameter,thickness:this.thickness,tessellation:this.tessellation,sideOrientation:this.side})},r.prototype.copy=function(e){return new r(e,this.getScene(),this.diameter,this.thickness,this.tessellation,this.canBeRegenerated(),null,this.side)},r.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.diameter=this.diameter,e.thickness=this.thickness,e.tessellation=this.tessellation,e},r.Parse=function(i,r){if(r.getGeometryByID(i.id))return null;var n=new t.Primitives.Torus(i.id,r,i.diameter,i.thickness,i.tessellation,i.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,i.tags),r.pushGeometry(n,!0),n},r}(r);i.Torus=u;var c=function(i){function r(e,t,r,n,o,s,a){void 0===a&&(a=null);var l=i.call(this,e,t,s,a)||this;return l.width=r,l.height=n,l.subdivisions=o,l}return n(r,i),r.prototype._regenerateVertexData=function(){return e.VertexData.CreateGround({width:this.width,height:this.height,subdivisions:this.subdivisions})},r.prototype.copy=function(e){return new r(e,this.getScene(),this.width,this.height,this.subdivisions,this.canBeRegenerated(),null)},r.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.width=this.width,e.height=this.height,e.subdivisions=this.subdivisions,e},r.Parse=function(i,r){if(r.getGeometryByID(i.id))return null;var n=new t.Primitives.Ground(i.id,r,i.width,i.height,i.subdivisions,i.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,i.tags),r.pushGeometry(n,!0),n},r}(r);i.Ground=c;var f=function(t){function i(e,i,r,n,o,s,a,l,h,u){void 0===u&&(u=null);var c=t.call(this,e,i,h,u)||this;return c.xmin=r,c.zmin=n,c.xmax=o,c.zmax=s,c.subdivisions=a,c.precision=l,c}return n(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}(r);i.TiledGround=f;var p=function(i){function r(t,r,n,o,s,a){void 0===s&&(s=null),void 0===a&&(a=e.Mesh.DEFAULTSIDE);var l=i.call(this,t,r,o,s)||this;return l.size=n,l.side=a,l}return n(r,i),r.prototype._regenerateVertexData=function(){return e.VertexData.CreatePlane({size:this.size,sideOrientation:this.side})},r.prototype.copy=function(e){return new r(e,this.getScene(),this.size,this.canBeRegenerated(),null,this.side)},r.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.size=this.size,e},r.Parse=function(i,r){if(r.getGeometryByID(i.id))return null;var n=new t.Primitives.Plane(i.id,r,i.size,i.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,i.tags),r.pushGeometry(n,!0),n},r}(r);i.Plane=p;var d=function(i){function r(t,r,n,o,s,a,l,h,u,c,f){void 0===c&&(c=null),void 0===f&&(f=e.Mesh.DEFAULTSIDE);var p=i.call(this,t,r,u,c)||this;return p.radius=n,p.tube=o,p.radialSegments=s,p.tubularSegments=a,p.p=l,p.q=h,p.side=f,p}return n(r,i),r.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})},r.prototype.copy=function(e){return new r(e,this.getScene(),this.radius,this.tube,this.radialSegments,this.tubularSegments,this.p,this.q,this.canBeRegenerated(),null,this.side)},r.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},r.Parse=function(i,r){if(r.getGeometryByID(i.id))return null;var n=new t.Primitives.TorusKnot(i.id,r,i.radius,i.tube,i.radialSegments,i.tubularSegments,i.p,i.q,i.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,i.tags),r.pushGeometry(n,!0),n},r}(r);i.TorusKnot=d}(t.Primitives||(t.Primitives={}))}(t=e.Geometry||(e.Geometry={}))}(s||(s={}));!function(e){var t=function(){function t(e){this._vertexBuffers={},this._scene=e}return t.prototype._prepareBuffers=function(){if(!this._vertexBuffers[e.VertexBuffer.PositionKind]){var t=[];t.push(1,1),t.push(-1,1),t.push(-1,-1),t.push(1,-1),this._vertexBuffers[e.VertexBuffer.PositionKind]=new e.VertexBuffer(this._scene.getEngine(),t,e.VertexBuffer.PositionKind,!1,!1,2),this._buildIndexBuffer()}},t.prototype._buildIndexBuffer=function(){var e=[];e.push(0),e.push(1),e.push(2),e.push(0),e.push(2),e.push(3),this._indexBuffer=this._scene.getEngine().createIndexBuffer(e)},t.prototype._rebuild=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&(t._rebuild(),this._buildIndexBuffer())},t.prototype._prepareFrame=function(e,t){void 0===e&&(e=null),void 0===t&&(t=null);var i=this._scene.activeCamera;return!!i&&(!(!(t=t||i._postProcesses)||0===t.length||!this._scene.postProcessesEnabled)&&(t[0].activate(i,e,null!==t&&void 0!==t),!0))},t.prototype.directRender=function(e,t,i){if(void 0===t&&(t=null),void 0===i&&(i=!1),this._scene.activeCamera){for(var r=this._scene.getEngine(),n=0;n<e.length;n++){n<e.length-1?e[n+1].activate(this._scene.activeCamera,t):t?r.bindFramebuffer(t,0,void 0,void 0,i):r.restoreDefaultFramebuffer();var o=e[n],s=o.apply();s&&(o.onBeforeRenderObservable.notifyObservers(s),this._prepareBuffers(),r.bindBuffers(this._vertexBuffers,this._indexBuffer,s),r.draw(!0,0,6),o.onAfterRenderObservable.notifyObservers(s))}r.setDepthBuffer(!0),r.setDepthWrite(!0)}},t.prototype._finalizeFrame=function(t,i,r,n,o){void 0===o&&(o=!1);var s=this._scene.activeCamera;if(s&&0!==(n=n||s._postProcesses).length&&this._scene.postProcessesEnabled){for(var a=this._scene.getEngine(),l=0,h=n.length;l<h&&(l<h-1?n[l+1].activate(s,i):i?a.bindFramebuffer(i,r,void 0,void 0,o):a.restoreDefaultFramebuffer(),!t);l++){var u=n[l],c=u.apply();c&&(u.onBeforeRenderObservable.notifyObservers(c),this._prepareBuffers(),a.bindBuffers(this._vertexBuffers,this._indexBuffer,c),a.draw(!0,0,6),u.onAfterRenderObservable.notifyObservers(c))}a.setDepthBuffer(!0),a.setDepthWrite(!0),a.setAlphaMode(e.Engine.ALPHA_DISABLE)}},t.prototype.dispose=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&(t.dispose(),this._vertexBuffers[e.VertexBuffer.PositionKind]=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null)},t}();e.PostProcessManager=t}(s||(s={}));!function(e){var t=function(){function t(e){void 0===e&&(e=30),this._enabled=!0,this._rollingFrameTime=new i(e)}return t.prototype.sampleFrame=function(t){if(void 0===t&&(t=e.Tools.Now),this._enabled){if(null!=this._lastFrameTimeMs){var i=t-this._lastFrameTimeMs;this._rollingFrameTime.add(i)}this._lastFrameTimeMs=t}},Object.defineProperty(t.prototype,"averageFrameTime",{get:function(){return this._rollingFrameTime.average},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"averageFrameTimeVariance",{get:function(){return this._rollingFrameTime.variance},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"instantaneousFrameTime",{get:function(){return this._rollingFrameTime.history(0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"averageFPS",{get:function(){return 1e3/this._rollingFrameTime.average},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"instantaneousFPS",{get:function(){var e=this._rollingFrameTime.history(0);return 0===e?0:1e3/e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isSaturated",{get:function(){return this._rollingFrameTime.isSaturated()},enumerable:!0,configurable:!0}),t.prototype.enable=function(){this._enabled=!0},t.prototype.disable=function(){this._enabled=!1,this._lastFrameTimeMs=null,this._lastChangeTimeMs=null},Object.defineProperty(t.prototype,"isEnabled",{get:function(){return this._enabled},enumerable:!0,configurable:!0}),t.prototype.reset=function(){this._lastFrameTimeMs=null,this._lastChangeTimeMs=null,this._rollingFrameTime.reset()},t}();e.PerformanceMonitor=t;var i=function(){function e(e){this._samples=new Array(e),this.reset()}return e.prototype.add=function(e){var t;if(this.isSaturated()){var i=this._samples[this._pos];t=i-this.average,this.average-=t/(this._sampleCount-1),this._m2-=t*(i-this.average)}else this._sampleCount++;t=e-this.average,this.average+=t/this._sampleCount,this._m2+=t*(e-this.average),this.variance=this._m2/(this._sampleCount-1),this._samples[this._pos]=e,this._pos++,this._pos%=this._samples.length},e.prototype.history=function(e){if(e>=this._sampleCount||e>=this._samples.length)return 0;var t=this._wrapPosition(this._pos-1);return this._samples[this._wrapPosition(t-e)]},e.prototype.isSaturated=function(){return this._sampleCount>=this._samples.length},e.prototype.reset=function(){this.average=0,this.variance=0,this._sampleCount=0,this._pos=0,this._m2=0},e.prototype._wrapPosition=function(e){var t=this._samples.length;return(e%t+t)%t},e}();e.RollingAverage=i}(s||(s={}));!function(e){var t=function(){function t(){this.colorCurves=new e.ColorCurves,this._colorCurvesEnabled=!1,this._colorGradingEnabled=!1,this._colorGradingWithGreenDepth=!0,this._colorGradingBGR=!0,this._exposure=1,this._toneMappingEnabled=!1,this._contrast=1,this.vignetteStretch=0,this.vignetteCentreX=0,this.vignetteCentreY=0,this.vignetteWeight=1.5,this.vignetteColor=new e.Color4(0,0,0,0),this.vignetteCameraFov=.5,this._vignetteBlendMode=t.VIGNETTEMODE_MULTIPLY,this._vignetteEnabled=!1,this._applyByPostProcess=!1,this.onUpdateParameters=new e.Observable}return Object.defineProperty(t.prototype,"colorCurvesEnabled",{get:function(){return this._colorCurvesEnabled},set:function(e){this._colorCurvesEnabled!==e&&(this._colorCurvesEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"colorGradingEnabled",{get:function(){return this._colorGradingEnabled},set:function(e){this._colorGradingEnabled!==e&&(this._colorGradingEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"colorGradingWithGreenDepth",{get:function(){return this._colorGradingWithGreenDepth},set:function(e){this._colorGradingWithGreenDepth!==e&&(this._colorGradingWithGreenDepth=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"colorGradingBGR",{get:function(){return this._colorGradingBGR},set:function(e){this._colorGradingBGR!==e&&(this._colorGradingBGR=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exposure",{get:function(){return this._exposure},set:function(e){this._exposure!==e&&(this._exposure=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"toneMappingEnabled",{get:function(){return this._toneMappingEnabled},set:function(e){this._toneMappingEnabled!==e&&(this._toneMappingEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"contrast",{get:function(){return this._contrast},set:function(e){this._contrast!==e&&(this._contrast=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteBlendMode",{get:function(){return this._vignetteBlendMode},set:function(e){this._vignetteBlendMode!==e&&(this._vignetteBlendMode=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteEnabled",{get:function(){return this._vignetteEnabled},set:function(e){this._vignetteEnabled!==e&&(this._vignetteEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"applyByPostProcess",{get:function(){return this._applyByPostProcess},set:function(e){this._applyByPostProcess!==e&&(this._applyByPostProcess=e,this._updateParameters())},enumerable:!0,configurable:!0}),t.prototype._updateParameters=function(){this.onUpdateParameters.notifyObservers(this)},t.prototype.getClassName=function(){return"ImageProcessingConfiguration"},t.PrepareUniforms=function(t,i){i.EXPOSURE&&t.push("exposureLinear"),i.CONTRAST&&t.push("contrast"),i.COLORGRADING&&t.push("colorTransformSettings"),i.VIGNETTE&&(t.push("vInverseScreenSize"),t.push("vignetteSettings1"),t.push("vignetteSettings2")),i.COLORCURVES&&e.ColorCurves.PrepareUniforms(t)},t.PrepareSamplers=function(e,t){t.COLORGRADING&&e.push("txColorTransform")},t.prototype.prepareDefines=function(e,i){if(void 0===i&&(i=!1),i!==this.applyByPostProcess)return e.VIGNETTE=!1,e.TONEMAPPING=!1,e.CONTRAST=!1,e.EXPOSURE=!1,e.COLORCURVES=!1,e.COLORGRADING=!1,e.COLORGRADING3D=!1,e.IMAGEPROCESSING=!1,void(e.IMAGEPROCESSINGPOSTPROCESS=this.applyByPostProcess);e.VIGNETTE=this.vignetteEnabled,e.VIGNETTEBLENDMODEMULTIPLY=this.vignetteBlendMode===t._VIGNETTEMODE_MULTIPLY,e.VIGNETTEBLENDMODEOPAQUE=!e.VIGNETTEBLENDMODEMULTIPLY,e.TONEMAPPING=this.toneMappingEnabled,e.CONTRAST=1!==this.contrast,e.EXPOSURE=1!==this.exposure,e.COLORCURVES=this.colorCurvesEnabled&&!!this.colorCurves,e.COLORGRADING=this.colorGradingEnabled&&!!this.colorGradingTexture,e.COLORGRADING?e.COLORGRADING3D=this.colorGradingTexture.is3D:e.COLORGRADING3D=!1,e.SAMPLER3DGREENDEPTH=this.colorGradingWithGreenDepth,e.SAMPLER3DBGRMAP=this.colorGradingBGR,e.IMAGEPROCESSINGPOSTPROCESS=this.applyByPostProcess,e.IMAGEPROCESSING=e.VIGNETTE||e.TONEMAPPING||e.CONTRAST||e.EXPOSURE||e.COLORCURVES||e.COLORGRADING},t.prototype.isReady=function(){return!this.colorGradingEnabled||!this.colorGradingTexture||this.colorGradingTexture.isReady()},t.prototype.bind=function(t,i){if(void 0===i&&(i=1),this._colorCurvesEnabled&&this.colorCurves&&e.ColorCurves.Bind(this.colorCurves,t),this._vignetteEnabled){var r=1/t.getEngine().getRenderWidth(),n=1/t.getEngine().getRenderHeight();t.setFloat2("vInverseScreenSize",r,n);var o=Math.tan(.5*this.vignetteCameraFov),s=o*i,a=Math.sqrt(s*o);s=e.Tools.Mix(s,a,this.vignetteStretch),o=e.Tools.Mix(o,a,this.vignetteStretch),t.setFloat4("vignetteSettings1",s,o,-s*this.vignetteCentreX,-o*this.vignetteCentreY);var l=-2*this.vignetteWeight;t.setFloat4("vignetteSettings2",this.vignetteColor.r,this.vignetteColor.g,this.vignetteColor.b,l)}if(t.setFloat("exposureLinear",this.exposure),t.setFloat("contrast",this.contrast),this.colorGradingTexture){t.setTexture("txColorTransform",this.colorGradingTexture);var h=this.colorGradingTexture.getSize().height;t.setFloat4("colorTransformSettings",(h-1)/h,.5/h,h,this.colorGradingTexture.level)}},t.prototype.clone=function(){return e.SerializationHelper.Clone(function(){return new t},this)},t.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},t.Parse=function(i){return e.SerializationHelper.Parse(function(){return new t},i,null,null)},Object.defineProperty(t,"VIGNETTEMODE_MULTIPLY",{get:function(){return this._VIGNETTEMODE_MULTIPLY},enumerable:!0,configurable:!0}),Object.defineProperty(t,"VIGNETTEMODE_OPAQUE",{get:function(){return this._VIGNETTEMODE_OPAQUE},enumerable:!0,configurable:!0}),t._VIGNETTEMODE_MULTIPLY=0,t._VIGNETTEMODE_OPAQUE=1,r([e.serializeAsColorCurves()],t.prototype,"colorCurves",void 0),r([e.serialize()],t.prototype,"_colorCurvesEnabled",void 0),r([e.serializeAsTexture()],t.prototype,"colorGradingTexture",void 0),r([e.serialize()],t.prototype,"_colorGradingEnabled",void 0),r([e.serialize()],t.prototype,"_colorGradingWithGreenDepth",void 0),r([e.serialize()],t.prototype,"_colorGradingBGR",void 0),r([e.serialize()],t.prototype,"_exposure",void 0),r([e.serialize()],t.prototype,"_toneMappingEnabled",void 0),r([e.serialize()],t.prototype,"_contrast",void 0),r([e.serialize()],t.prototype,"vignetteStretch",void 0),r([e.serialize()],t.prototype,"vignetteCentreX",void 0),r([e.serialize()],t.prototype,"vignetteCentreY",void 0),r([e.serialize()],t.prototype,"vignetteWeight",void 0),r([e.serializeAsColor4()],t.prototype,"vignetteColor",void 0),r([e.serialize()],t.prototype,"vignetteCameraFov",void 0),r([e.serialize()],t.prototype,"_vignetteBlendMode",void 0),r([e.serialize()],t.prototype,"_vignetteEnabled",void 0),r([e.serialize()],t.prototype,"_applyByPostProcess",void 0),t}();e.ImageProcessingConfiguration=t}(s||(s={}));!function(e){var t=function(t){function i(i,r){var n=t.call(this,r)||this;return i?(n._engine=r.getEngine(),n._textureMatrix=e.Matrix.Identity(),n.name=i,n.url=i,n.hasAlpha=!1,n.isCube=!1,n.is3D=n._engine.webGLVersion>1,n.wrapU=e.Texture.CLAMP_ADDRESSMODE,n.wrapV=e.Texture.CLAMP_ADDRESSMODE,n.wrapR=e.Texture.CLAMP_ADDRESSMODE,n.anisotropicFilteringLevel=1,n._texture=n._getFromCache(i,!0),n._texture||(r.useDelayedTextureLoading?n.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:n.loadTexture()),n):n}return n(i,t),i.prototype.getTextureMatrix=function(){return this._textureMatrix},i.prototype.load3dlTexture=function(){var t,r=this._engine;t=1===r.webGLVersion?r.createRawTexture(null,1,1,e.Engine.TEXTUREFORMAT_RGBA,!1,!1,e.Texture.BILINEAR_SAMPLINGMODE):r.createRawTexture3D(null,1,1,1,e.Engine.TEXTUREFORMAT_RGBA,!1,!1,e.Texture.BILINEAR_SAMPLINGMODE),this._texture=t;return e.Tools.LoadFile(this.url,function(n){for(var o,s=null,a=null,l=n.split("\n"),h=0,u=0,c=0,f=0,p=0,d=0;d<l.length;d++)if(o=l[d],i._noneEmptyLineRegex.test(o)&&0!==o.indexOf("#")){var m=o.split(" ");if(0!==h){if(0!=h){var g=Math.max(parseInt(m[0]),0),v=Math.max(parseInt(m[1]),0),_=Math.max(parseInt(m[2]),0);p=Math.max(g,p),p=Math.max(v,p),p=Math.max(_,p);var y=4*(u+f*h+c*h*h);a&&(a[y+0]=g,a[y+1]=v,a[y+2]=_),++f%h==0&&(f=0,++c%h==0&&(u++,c=0))}}else h=m.length,s=new Uint8Array(h*h*h*4),a=new Float32Array(h*h*h*4)}if(a&&s)for(d=0;d<a.length;d++)if(d>0&&(d+1)%4==0)s[d]=255;else{var x=a[d];s[d]=x/p*255}t.is3D?(t.updateSize(h,h,h),r.updateRawTexture3D(t,s,e.Engine.TEXTUREFORMAT_RGBA,!1)):(t.updateSize(h*h,h),r.updateRawTexture(t,s,e.Engine.TEXTUREFORMAT_RGBA,!1))}),this._texture},i.prototype.loadTexture=function(){this.url&&this.url.toLocaleLowerCase().indexOf(".3dl")==this.url.length-4&&this.load3dlTexture()},i.prototype.clone=function(){var e=new i(this.url,this.getScene());return e.level=this.level,e},i.prototype.delayLoad=function(){this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,!0),this._texture||this.loadTexture())},i.Parse=function(t,i,r){var n=null;return t.name&&!t.isRenderTarget&&((n=new e.ColorGradingTexture(t.name,i)).name=t.name,n.level=t.level),n},i.prototype.serialize=function(){if(!this.name)return null;var e={};return e.name=this.name,e.level=this.level,e.customType="BABYLON.ColorGradingTexture",e},i._noneEmptyLineRegex=/\S+/,i}(e.BaseTexture);e.ColorGradingTexture=t}(s||(s={}));!function(e){var t=function(){function t(){this._dirty=!0,this._tempColor=new e.Color4(0,0,0,0),this._globalCurve=new e.Color4(0,0,0,0),this._highlightsCurve=new e.Color4(0,0,0,0),this._midtonesCurve=new e.Color4(0,0,0,0),this._shadowsCurve=new e.Color4(0,0,0,0),this._positiveCurve=new e.Color4(0,0,0,0),this._negativeCurve=new e.Color4(0,0,0,0),this._globalHue=30,this._globalDensity=0,this._globalSaturation=0,this._globalExposure=0,this._highlightsHue=30,this._highlightsDensity=0,this._highlightsSaturation=0,this._highlightsExposure=0,this._midtonesHue=30,this._midtonesDensity=0,this._midtonesSaturation=0,this._midtonesExposure=0,this._shadowsHue=30,this._shadowsDensity=0,this._shadowsSaturation=0,this._shadowsExposure=0}return Object.defineProperty(t.prototype,"globalHue",{get:function(){return this._globalHue},set:function(e){this._globalHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"globalDensity",{get:function(){return this._globalDensity},set:function(e){this._globalDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"globalSaturation",{get:function(){return this._globalSaturation},set:function(e){this._globalSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"highlightsHue",{get:function(){return this._highlightsHue},set:function(e){this._highlightsHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"highlightsDensity",{get:function(){return this._highlightsDensity},set:function(e){this._highlightsDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"highlightsSaturation",{get:function(){return this._highlightsSaturation},set:function(e){this._highlightsSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"highlightsExposure",{get:function(){return this._highlightsExposure},set:function(e){this._highlightsExposure=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"midtonesHue",{get:function(){return this._midtonesHue},set:function(e){this._midtonesHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"midtonesDensity",{get:function(){return this._midtonesDensity},set:function(e){this._midtonesDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"midtonesSaturation",{get:function(){return this._midtonesSaturation},set:function(e){this._midtonesSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"midtonesExposure",{get:function(){return this._midtonesExposure},set:function(e){this._midtonesExposure=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowsHue",{get:function(){return this._shadowsHue},set:function(e){this._shadowsHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowsDensity",{get:function(){return this._shadowsDensity},set:function(e){this._shadowsDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowsSaturation",{get:function(){return this._shadowsSaturation},set:function(e){this._shadowsSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowsExposure",{get:function(){return this._shadowsExposure},set:function(e){this._shadowsExposure=e,this._dirty=!0},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"ColorCurves"},t.Bind=function(e,t,i,r,n){void 0===i&&(i="vCameraColorCurvePositive"),void 0===r&&(r="vCameraColorCurveNeutral"),void 0===n&&(n="vCameraColorCurveNegative"),e._dirty&&(e._dirty=!1,e.getColorGradingDataToRef(e._globalHue,e._globalDensity,e._globalSaturation,e._globalExposure,e._globalCurve),e.getColorGradingDataToRef(e._highlightsHue,e._highlightsDensity,e._highlightsSaturation,e._highlightsExposure,e._tempColor),e._tempColor.multiplyToRef(e._globalCurve,e._highlightsCurve),e.getColorGradingDataToRef(e._midtonesHue,e._midtonesDensity,e._midtonesSaturation,e._midtonesExposure,e._tempColor),e._tempColor.multiplyToRef(e._globalCurve,e._midtonesCurve),e.getColorGradingDataToRef(e._shadowsHue,e._shadowsDensity,e._shadowsSaturation,e._shadowsExposure,e._tempColor),e._tempColor.multiplyToRef(e._globalCurve,e._shadowsCurve),e._highlightsCurve.subtractToRef(e._midtonesCurve,e._positiveCurve),e._midtonesCurve.subtractToRef(e._shadowsCurve,e._negativeCurve)),t&&(t.setFloat4(i,e._positiveCurve.r,e._positiveCurve.g,e._positiveCurve.b,e._positiveCurve.a),t.setFloat4(r,e._midtonesCurve.r,e._midtonesCurve.g,e._midtonesCurve.b,e._midtonesCurve.a),t.setFloat4(n,e._negativeCurve.r,e._negativeCurve.g,e._negativeCurve.b,e._negativeCurve.a))},t.PrepareUniforms=function(e){e.push("vCameraColorCurveNeutral","vCameraColorCurvePositive","vCameraColorCurveNegative")},t.prototype.getColorGradingDataToRef=function(e,i,r,n,o){null!=e&&(e=t.clamp(e,0,360),i=t.clamp(i,-100,100),r=t.clamp(r,-100,100),n=t.clamp(n,-100,100),i=t.applyColorGradingSliderNonlinear(i),i*=.5,n=t.applyColorGradingSliderNonlinear(n),i<0&&(i*=-1,e=(e+180)%360),t.fromHSBToRef(e,i,50+.25*n,o),o.scaleToRef(2,o),o.a=1+.01*r)},t.applyColorGradingSliderNonlinear=function(e){e/=100;var t=Math.abs(e);return t=Math.pow(t,2),e<0&&(t*=-1),t*=100},t.fromHSBToRef=function(e,i,r,n){var o=t.clamp(e,0,360),s=t.clamp(i/100,0,1),a=t.clamp(r/100,0,1);if(0===s)n.r=a,n.g=a,n.b=a;else{o/=60;var l=Math.floor(o),h=o-l,u=a*(1-s),c=a*(1-s*h),f=a*(1-s*(1-h));switch(l){case 0:n.r=a,n.g=f,n.b=u;break;case 1:n.r=c,n.g=a,n.b=u;break;case 2:n.r=u,n.g=a,n.b=f;break;case 3:n.r=u,n.g=c,n.b=a;break;case 4:n.r=f,n.g=u,n.b=a;break;default:n.r=a,n.g=u,n.b=c}}n.a=1},t.clamp=function(e,t,i){return Math.min(Math.max(e,t),i)},t.prototype.clone=function(){return e.SerializationHelper.Clone(function(){return new t},this)},t.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},t.Parse=function(i){return e.SerializationHelper.Parse(function(){return new t},i,null,null)},r([e.serialize()],t.prototype,"_globalHue",void 0),r([e.serialize()],t.prototype,"_globalDensity",void 0),r([e.serialize()],t.prototype,"_globalSaturation",void 0),r([e.serialize()],t.prototype,"_globalExposure",void 0),r([e.serialize()],t.prototype,"_highlightsHue",void 0),r([e.serialize()],t.prototype,"_highlightsDensity",void 0),r([e.serialize()],t.prototype,"_highlightsSaturation",void 0),r([e.serialize()],t.prototype,"_highlightsExposure",void 0),r([e.serialize()],t.prototype,"_midtonesHue",void 0),r([e.serialize()],t.prototype,"_midtonesDensity",void 0),r([e.serialize()],t.prototype,"_midtonesSaturation",void 0),r([e.serialize()],t.prototype,"_midtonesExposure",void 0),t}();e.ColorCurves=t}(s||(s={}));!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.MAINUV1=!1,t.MAINUV2=!1,t.DIFFUSE=!1,t.DIFFUSEDIRECTUV=0,t.AMBIENT=!1,t.AMBIENTDIRECTUV=0,t.OPACITY=!1,t.OPACITYDIRECTUV=0,t.OPACITYRGB=!1,t.REFLECTION=!1,t.EMISSIVE=!1,t.EMISSIVEDIRECTUV=0,t.SPECULAR=!1,t.SPECULARDIRECTUV=0,t.BUMP=!1,t.BUMPDIRECTUV=0,t.PARALLAX=!1,t.PARALLAXOCCLUSION=!1,t.SPECULAROVERALPHA=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.ALPHAFROMDIFFUSE=!1,t.POINTSIZE=!1,t.FOG=!1,t.SPECULARTERM=!1,t.DIFFUSEFRESNEL=!1,t.OPACITYFRESNEL=!1,t.REFLECTIONFRESNEL=!1,t.REFRACTIONFRESNEL=!1,t.EMISSIVEFRESNEL=!1,t.FRESNEL=!1,t.NORMAL=!1,t.UV1=!1,t.UV2=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.GLOSSINESS=!1,t.ROUGHNESS=!1,t.EMISSIVEASILLUMINATION=!1,t.LINKEMISSIVEWITHDIFFUSE=!1,t.REFLECTIONFRESNELFROMSPECULAR=!1,t.LIGHTMAP=!1,t.LIGHTMAPDIRECTUV=0,t.USELIGHTMAPASSHADOWMAP=!1,t.REFLECTIONMAP_3D=!1,t.REFLECTIONMAP_SPHERICAL=!1,t.REFLECTIONMAP_PLANAR=!1,t.REFLECTIONMAP_CUBIC=!1,t.REFLECTIONMAP_PROJECTION=!1,t.REFLECTIONMAP_SKYBOX=!1,t.REFLECTIONMAP_EXPLICIT=!1,t.REFLECTIONMAP_EQUIRECTANGULAR=!1,t.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!1,t.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!1,t.INVERTCUBICMAP=!1,t.LOGARITHMICDEPTH=!1,t.REFRACTION=!1,t.REFRACTIONMAP_3D=!1,t.REFLECTIONOVERALPHA=!1,t.TWOSIDEDLIGHTING=!1,t.SHADOWFLOAT=!1,t.MORPHTARGETS=!1,t.MORPHTARGETS_NORMAL=!1,t.MORPHTARGETS_TANGENT=!1,t.NUM_MORPH_INFLUENCERS=0,t.NONUNIFORMSCALING=!1,t.PREMULTIPLYALPHA=!1,t.IMAGEPROCESSING=!1,t.VIGNETTE=!1,t.VIGNETTEBLENDMODEMULTIPLY=!1,t.VIGNETTEBLENDMODEOPAQUE=!1,t.TONEMAPPING=!1,t.CONTRAST=!1,t.COLORCURVES=!1,t.COLORGRADING=!1,t.COLORGRADING3D=!1,t.SAMPLER3DGREENDEPTH=!1,t.SAMPLER3DBGRMAP=!1,t.IMAGEPROCESSINGPOSTPROCESS=!1,t.EXPOSURE=!1,t.rebuild(),t}return n(t,e),t.prototype.setReflectionMode=function(e){for(var t=0,i=["REFLECTIONMAP_CUBIC","REFLECTIONMAP_EXPLICIT","REFLECTIONMAP_PLANAR","REFLECTIONMAP_PROJECTION","REFLECTIONMAP_PROJECTION","REFLECTIONMAP_SKYBOX","REFLECTIONMAP_SPHERICAL","REFLECTIONMAP_EQUIRECTANGULAR","REFLECTIONMAP_EQUIRECTANGULAR_FIXED","REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED"];t<i.length;t++){var r=i[t];this[r]=r===e}},t}(e.MaterialDefines);e.StandardMaterialDefines=t;var i=function(i){function o(t,r){var n=i.call(this,t,r)||this;return n.ambientColor=new e.Color3(0,0,0),n.diffuseColor=new e.Color3(1,1,1),n.specularColor=new e.Color3(1,1,1),n.emissiveColor=new e.Color3(0,0,0),n.specularPower=64,n._useAlphaFromDiffuseTexture=!1,n._useEmissiveAsIllumination=!1,n._linkEmissiveWithDiffuse=!1,n._useSpecularOverAlpha=!1,n._useReflectionOverAlpha=!1,n._disableLighting=!1,n._useParallax=!1,n._useParallaxOcclusion=!1,n.parallaxScaleBias=.05,n._roughness=0,n.indexOfRefraction=.98,n.invertRefractionY=!0,n._useLightmapAsShadowmap=!1,n._useReflectionFresnelFromSpecular=!1,n._useGlossinessFromSpecularMapAlpha=!1,n._maxSimultaneousLights=4,n._invertNormalMapX=!1,n._invertNormalMapY=!1,n._twoSidedLighting=!1,n._renderTargets=new e.SmartArray(16),n._worldViewProjectionMatrix=e.Matrix.Zero(),n._globalAmbientColor=new e.Color3(0,0,0),n._attachImageProcessingConfiguration(null),n.getRenderTargetTextures=function(){return n._renderTargets.reset(),o.ReflectionTextureEnabled&&n._reflectionTexture&&n._reflectionTexture.isRenderTarget&&n._renderTargets.push(n._reflectionTexture),o.RefractionTextureEnabled&&n._refractionTexture&&n._refractionTexture.isRenderTarget&&n._renderTargets.push(n._refractionTexture),n._renderTargets},n}return n(o,i),Object.defineProperty(o.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},set:function(e){this._attachImageProcessingConfiguration(e),this._markAllSubMeshesAsTexturesDirty()},enumerable:!0,configurable:!0}),o.prototype._attachImageProcessingConfiguration=function(e){var t=this;e!==this._imageProcessingConfiguration&&(this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),this._imageProcessingConfiguration=e||this.getScene().imageProcessingConfiguration,this._imageProcessingObserver=this._imageProcessingConfiguration.onUpdateParameters.add(function(e){t._markAllSubMeshesAsImageProcessingDirty()}))},Object.defineProperty(o.prototype,"cameraColorCurvesEnabled",{get:function(){return this.imageProcessingConfiguration.colorCurvesEnabled},set:function(e){this.imageProcessingConfiguration.colorCurvesEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraColorGradingEnabled",{get:function(){return this.imageProcessingConfiguration.colorGradingEnabled},set:function(e){this.imageProcessingConfiguration.colorGradingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraToneMappingEnabled",{get:function(){return this._imageProcessingConfiguration.toneMappingEnabled},set:function(e){this._imageProcessingConfiguration.toneMappingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraExposure",{get:function(){return this._imageProcessingConfiguration.exposure},set:function(e){this._imageProcessingConfiguration.exposure=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraContrast",{get:function(){return this._imageProcessingConfiguration.contrast},set:function(e){this._imageProcessingConfiguration.contrast=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraColorGradingTexture",{get:function(){return this._imageProcessingConfiguration.colorGradingTexture},set:function(e){this._imageProcessingConfiguration.colorGradingTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraColorCurves",{get:function(){return this._imageProcessingConfiguration.colorCurves},set:function(e){this._imageProcessingConfiguration.colorCurves=e},enumerable:!0,configurable:!0}),o.prototype.getClassName=function(){return"StandardMaterial"},Object.defineProperty(o.prototype,"useLogarithmicDepth",{get:function(){return this._useLogarithmicDepth},set:function(e){this._useLogarithmicDepth=e&&this.getScene().getEngine().getCaps().fragmentDepthSupported,this._markAllSubMeshesAsMiscDirty()},enumerable:!0,configurable:!0}),o.prototype.needAlphaBlending=function(){return this.alpha<1||null!=this._opacityTexture||this._shouldUseAlphaFromDiffuseTexture()||this._opacityFresnelParameters&&this._opacityFresnelParameters.isEnabled},o.prototype.needAlphaTesting=function(){return null!=this._diffuseTexture&&this._diffuseTexture.hasAlpha},o.prototype._shouldUseAlphaFromDiffuseTexture=function(){return null!=this._diffuseTexture&&this._diffuseTexture.hasAlpha&&this._useAlphaFromDiffuseTexture},o.prototype.getAlphaTestTexture=function(){return this._diffuseTexture},o.prototype.isReadyForSubMesh=function(i,r,n){if(void 0===n&&(n=!1),r.effect&&this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var s=this.getScene(),a=r._materialDefines;if(!this.checkReadyOnEveryCall&&r.effect&&a._renderId===s.getRenderId())return!0;var l=s.getEngine();if(a._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,a,!0,this._maxSimultaneousLights,this._disableLighting),a._areTexturesDirty){if(a._needUVs=!1,a.MAINUV1=!1,a.MAINUV2=!1,s.texturesEnabled){if(this._diffuseTexture&&o.DiffuseTextureEnabled){if(!this._diffuseTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._diffuseTexture,a,"DIFFUSE")}else a.DIFFUSE=!1;if(this._ambientTexture&&o.AmbientTextureEnabled){if(!this._ambientTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._ambientTexture,a,"AMBIENT")}else a.AMBIENT=!1;if(this._opacityTexture&&o.OpacityTextureEnabled){if(!this._opacityTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._opacityTexture,a,"OPACITY"),a.OPACITYRGB=this._opacityTexture.getAlphaFromRGB}else a.OPACITY=!1;if(this._reflectionTexture&&o.ReflectionTextureEnabled){if(!this._reflectionTexture.isReadyOrNotBlocking())return!1;switch(a._needNormals=!0,a.REFLECTION=!0,a.ROUGHNESS=this._roughness>0,a.REFLECTIONOVERALPHA=this._useReflectionOverAlpha,a.INVERTCUBICMAP=this._reflectionTexture.coordinatesMode===e.Texture.INVCUBIC_MODE,a.REFLECTIONMAP_3D=this._reflectionTexture.isCube,this._reflectionTexture.coordinatesMode){case e.Texture.CUBIC_MODE:case e.Texture.INVCUBIC_MODE:a.setReflectionMode("REFLECTIONMAP_CUBIC");break;case e.Texture.EXPLICIT_MODE:a.setReflectionMode("REFLECTIONMAP_EXPLICIT");break;case e.Texture.PLANAR_MODE:a.setReflectionMode("REFLECTIONMAP_PLANAR");break;case e.Texture.PROJECTION_MODE:a.setReflectionMode("REFLECTIONMAP_PROJECTION");break;case e.Texture.SKYBOX_MODE:a.setReflectionMode("REFLECTIONMAP_SKYBOX");break;case e.Texture.SPHERICAL_MODE:a.setReflectionMode("REFLECTIONMAP_SPHERICAL");break;case e.Texture.EQUIRECTANGULAR_MODE:a.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR");break;case e.Texture.FIXED_EQUIRECTANGULAR_MODE:a.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR_FIXED");break;case e.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:a.setReflectionMode("REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED")}}else a.REFLECTION=!1;if(this._emissiveTexture&&o.EmissiveTextureEnabled){if(!this._emissiveTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._emissiveTexture,a,"EMISSIVE")}else a.EMISSIVE=!1;if(this._lightmapTexture&&o.LightmapTextureEnabled){if(!this._lightmapTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._lightmapTexture,a,"LIGHTMAP"),a.USELIGHTMAPASSHADOWMAP=this._useLightmapAsShadowmap}else a.LIGHTMAP=!1;if(this._specularTexture&&o.SpecularTextureEnabled){if(!this._specularTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._specularTexture,a,"SPECULAR"),a.GLOSSINESS=this._useGlossinessFromSpecularMapAlpha}else a.SPECULAR=!1;if(s.getEngine().getCaps().standardDerivatives&&this._bumpTexture&&o.BumpTextureEnabled){if(!this._bumpTexture.isReady())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture,a,"BUMP"),a.PARALLAX=this._useParallax,a.PARALLAXOCCLUSION=this._useParallaxOcclusion}else a.BUMP=!1;if(this._refractionTexture&&o.RefractionTextureEnabled){if(!this._refractionTexture.isReadyOrNotBlocking())return!1;a._needUVs=!0,a.REFRACTION=!0,a.REFRACTIONMAP_3D=this._refractionTexture.isCube}else a.REFRACTION=!1;a.TWOSIDEDLIGHTING=!this._backFaceCulling&&this._twoSidedLighting}else a.DIFFUSE=!1,a.AMBIENT=!1,a.OPACITY=!1,a.REFLECTION=!1,a.EMISSIVE=!1,a.LIGHTMAP=!1,a.BUMP=!1,a.REFRACTION=!1;a.ALPHAFROMDIFFUSE=this._shouldUseAlphaFromDiffuseTexture(),a.EMISSIVEASILLUMINATION=this._useEmissiveAsIllumination,a.LINKEMISSIVEWITHDIFFUSE=this._linkEmissiveWithDiffuse,a.SPECULAROVERALPHA=this._useSpecularOverAlpha,a.PREMULTIPLYALPHA=this.alphaMode===e.Engine.ALPHA_PREMULTIPLIED||this.alphaMode===e.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF}if(a._areImageProcessingDirty){if(!this._imageProcessingConfiguration.isReady())return!1;this._imageProcessingConfiguration.prepareDefines(a)}if(a._areFresnelDirty&&(o.FresnelEnabled?(this._diffuseFresnelParameters||this._opacityFresnelParameters||this._emissiveFresnelParameters||this._refractionFresnelParameters||this._reflectionFresnelParameters)&&(a.DIFFUSEFRESNEL=this._diffuseFresnelParameters&&this._diffuseFresnelParameters.isEnabled,a.OPACITYFRESNEL=this._opacityFresnelParameters&&this._opacityFresnelParameters.isEnabled,a.REFLECTIONFRESNEL=this._reflectionFresnelParameters&&this._reflectionFresnelParameters.isEnabled,a.REFLECTIONFRESNELFROMSPECULAR=this._useReflectionFresnelFromSpecular,a.REFRACTIONFRESNEL=this._refractionFresnelParameters&&this._refractionFresnelParameters.isEnabled,a.EMISSIVEFRESNEL=this._emissiveFresnelParameters&&this._emissiveFresnelParameters.isEnabled,a._needNormals=!0,a.FRESNEL=!0):a.FRESNEL=!1),e.MaterialHelper.PrepareDefinesForMisc(i,s,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,a),e.MaterialHelper.PrepareDefinesForAttributes(i,a,!0,!0,!0),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,l,a,n),a.isDirty){a.markAsProcessed(),s.resetCachedMaterial();var h=new e.EffectFallbacks;a.REFLECTION&&h.addFallback(0,"REFLECTION"),a.SPECULAR&&h.addFallback(0,"SPECULAR"),a.BUMP&&h.addFallback(0,"BUMP"),a.PARALLAX&&h.addFallback(1,"PARALLAX"),a.PARALLAXOCCLUSION&&h.addFallback(0,"PARALLAXOCCLUSION"),a.SPECULAROVERALPHA&&h.addFallback(0,"SPECULAROVERALPHA"),a.FOG&&h.addFallback(1,"FOG"),a.POINTSIZE&&h.addFallback(0,"POINTSIZE"),a.LOGARITHMICDEPTH&&h.addFallback(0,"LOGARITHMICDEPTH"),e.MaterialHelper.HandleFallbacksForShadows(a,h,this._maxSimultaneousLights),a.SPECULARTERM&&h.addFallback(0,"SPECULARTERM"),a.DIFFUSEFRESNEL&&h.addFallback(1,"DIFFUSEFRESNEL"),a.OPACITYFRESNEL&&h.addFallback(2,"OPACITYFRESNEL"),a.REFLECTIONFRESNEL&&h.addFallback(3,"REFLECTIONFRESNEL"),a.EMISSIVEFRESNEL&&h.addFallback(4,"EMISSIVEFRESNEL"),a.FRESNEL&&h.addFallback(4,"FRESNEL");var u=[e.VertexBuffer.PositionKind];a.NORMAL&&u.push(e.VertexBuffer.NormalKind),a.UV1&&u.push(e.VertexBuffer.UVKind),a.UV2&&u.push(e.VertexBuffer.UV2Kind),a.VERTEXCOLOR&&u.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(u,i,a,h),e.MaterialHelper.PrepareAttributesForInstances(u,a),e.MaterialHelper.PrepareAttributesForMorphTargets(u,i,a);var c="default",f=["world","view","viewProjection","vEyePosition","vLightsType","vAmbientColor","vDiffuseColor","vSpecularColor","vEmissiveColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","vAmbientInfos","vOpacityInfos","vReflectionInfos","vEmissiveInfos","vSpecularInfos","vBumpInfos","vLightmapInfos","vRefractionInfos","mBones","vClipPlane","diffuseMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","specularMatrix","bumpMatrix","lightmapMatrix","refractionMatrix","diffuseLeftColor","diffuseRightColor","opacityParts","reflectionLeftColor","reflectionRightColor","emissiveLeftColor","emissiveRightColor","refractionLeftColor","refractionRightColor","logarithmicDepthConstant","vTangentSpaceParams"],p=["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","lightmapSampler","refractionCubeSampler","refraction2DSampler"],d=["Material","Scene"];e.ImageProcessingConfiguration.PrepareUniforms(f,a),e.ImageProcessingConfiguration.PrepareSamplers(p,a),e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:f,uniformBuffersNames:d,samplers:p,defines:a,maxSimultaneousLights:this._maxSimultaneousLights}),this.customShaderNameResolve&&(c=this.customShaderNameResolve(c,f,d,p,a));var m=a.toString();r.setEffect(s.getEngine().createEffect(c,{attributes:u,uniformsNames:f,uniformBuffersNames:d,samplers:p,defines:m,fallbacks:h,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights,maxSimultaneousMorphTargets:a.NUM_MORPH_INFLUENCERS}},l),a),this.buildUniformLayout()}return!(!r.effect||!r.effect.isReady())&&(a._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,!0)},o.prototype.buildUniformLayout=function(){this._uniformBuffer.addUniform("diffuseLeftColor",4),this._uniformBuffer.addUniform("diffuseRightColor",4),this._uniformBuffer.addUniform("opacityParts",4),this._uniformBuffer.addUniform("reflectionLeftColor",4),this._uniformBuffer.addUniform("reflectionRightColor",4),this._uniformBuffer.addUniform("refractionLeftColor",4),this._uniformBuffer.addUniform("refractionRightColor",4),this._uniformBuffer.addUniform("emissiveLeftColor",4),this._uniformBuffer.addUniform("emissiveRightColor",4),this._uniformBuffer.addUniform("vDiffuseInfos",2),this._uniformBuffer.addUniform("vAmbientInfos",2),this._uniformBuffer.addUniform("vOpacityInfos",2),this._uniformBuffer.addUniform("vReflectionInfos",2),this._uniformBuffer.addUniform("vEmissiveInfos",2),this._uniformBuffer.addUniform("vLightmapInfos",2),this._uniformBuffer.addUniform("vSpecularInfos",2),this._uniformBuffer.addUniform("vBumpInfos",3),this._uniformBuffer.addUniform("diffuseMatrix",16),this._uniformBuffer.addUniform("ambientMatrix",16),this._uniformBuffer.addUniform("opacityMatrix",16),this._uniformBuffer.addUniform("reflectionMatrix",16),this._uniformBuffer.addUniform("emissiveMatrix",16),this._uniformBuffer.addUniform("lightmapMatrix",16),this._uniformBuffer.addUniform("specularMatrix",16),this._uniformBuffer.addUniform("bumpMatrix",16),this._uniformBuffer.addUniform("vTangentSpaceParams",2),this._uniformBuffer.addUniform("refractionMatrix",16),this._uniformBuffer.addUniform("vRefractionInfos",4),this._uniformBuffer.addUniform("vSpecularColor",4),this._uniformBuffer.addUniform("vEmissiveColor",3),this._uniformBuffer.addUniform("vDiffuseColor",4),this._uniformBuffer.addUniform("pointSize",1),this._uniformBuffer.create()},o.prototype.unbind=function(){this._activeEffect&&(this._reflectionTexture&&this._reflectionTexture.isRenderTarget&&this._activeEffect.setTexture("reflection2DSampler",null),this._refractionTexture&&this._refractionTexture.isRenderTarget&&this._activeEffect.setTexture("refraction2DSampler",null)),i.prototype.unbind.call(this)},o.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),s=r._materialDefines;if(s){var a=r.effect;if(a){this._activeEffect=a,this.bindOnlyWorldMatrix(t);var l=this._mustRebind(n,a,i.visibility);if(e.MaterialHelper.BindBonesParameters(i,a),l){if(this._uniformBuffer.bindToEffect(a,"Material"),this.bindViewProjection(a),!this._uniformBuffer.useUbo||!this.isFrozen||!this._uniformBuffer.isSync){if(o.FresnelEnabled&&s.FRESNEL&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("diffuseLeftColor",this.diffuseFresnelParameters.leftColor,this.diffuseFresnelParameters.power),this._uniformBuffer.updateColor4("diffuseRightColor",this.diffuseFresnelParameters.rightColor,this.diffuseFresnelParameters.bias)),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&this._uniformBuffer.updateColor4("opacityParts",new e.Color3(this.opacityFresnelParameters.leftColor.toLuminance(),this.opacityFresnelParameters.rightColor.toLuminance(),this.opacityFresnelParameters.bias),this.opacityFresnelParameters.power),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("reflectionLeftColor",this.reflectionFresnelParameters.leftColor,this.reflectionFresnelParameters.power),this._uniformBuffer.updateColor4("reflectionRightColor",this.reflectionFresnelParameters.rightColor,this.reflectionFresnelParameters.bias)),this.refractionFresnelParameters&&this.refractionFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("refractionLeftColor",this.refractionFresnelParameters.leftColor,this.refractionFresnelParameters.power),this._uniformBuffer.updateColor4("refractionRightColor",this.refractionFresnelParameters.rightColor,this.refractionFresnelParameters.bias)),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("emissiveLeftColor",this.emissiveFresnelParameters.leftColor,this.emissiveFresnelParameters.power),this._uniformBuffer.updateColor4("emissiveRightColor",this.emissiveFresnelParameters.rightColor,this.emissiveFresnelParameters.bias))),n.texturesEnabled&&(this._diffuseTexture&&o.DiffuseTextureEnabled&&(this._uniformBuffer.updateFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),e.MaterialHelper.BindTextureMatrix(this._diffuseTexture,this._uniformBuffer,"diffuse")),this._ambientTexture&&o.AmbientTextureEnabled&&(this._uniformBuffer.updateFloat2("vAmbientInfos",this._ambientTexture.coordinatesIndex,this._ambientTexture.level),e.MaterialHelper.BindTextureMatrix(this._ambientTexture,this._uniformBuffer,"ambient")),this._opacityTexture&&o.OpacityTextureEnabled&&(this._uniformBuffer.updateFloat2("vOpacityInfos",this._opacityTexture.coordinatesIndex,this._opacityTexture.level),e.MaterialHelper.BindTextureMatrix(this._opacityTexture,this._uniformBuffer,"opacity")),this._reflectionTexture&&o.ReflectionTextureEnabled&&(this._uniformBuffer.updateFloat2("vReflectionInfos",this._reflectionTexture.level,this.roughness),this._uniformBuffer.updateMatrix("reflectionMatrix",this._reflectionTexture.getReflectionTextureMatrix())),this._emissiveTexture&&o.EmissiveTextureEnabled&&(this._uniformBuffer.updateFloat2("vEmissiveInfos",this._emissiveTexture.coordinatesIndex,this._emissiveTexture.level),e.MaterialHelper.BindTextureMatrix(this._emissiveTexture,this._uniformBuffer,"emissive")),this._lightmapTexture&&o.LightmapTextureEnabled&&(this._uniformBuffer.updateFloat2("vLightmapInfos",this._lightmapTexture.coordinatesIndex,this._lightmapTexture.level),e.MaterialHelper.BindTextureMatrix(this._lightmapTexture,this._uniformBuffer,"lightmap")),this._specularTexture&&o.SpecularTextureEnabled&&(this._uniformBuffer.updateFloat2("vSpecularInfos",this._specularTexture.coordinatesIndex,this._specularTexture.level),e.MaterialHelper.BindTextureMatrix(this._specularTexture,this._uniformBuffer,"specular")),this._bumpTexture&&n.getEngine().getCaps().standardDerivatives&&o.BumpTextureEnabled&&(this._uniformBuffer.updateFloat3("vBumpInfos",this._bumpTexture.coordinatesIndex,1/this._bumpTexture.level,this.parallaxScaleBias),e.MaterialHelper.BindTextureMatrix(this._bumpTexture,this._uniformBuffer,"bump"),n._mirroredCameraPosition?this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?1:-1,this._invertNormalMapY?1:-1):this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?-1:1,this._invertNormalMapY?-1:1)),this._refractionTexture&&o.RefractionTextureEnabled)){h=1;this._refractionTexture.isCube||(this._uniformBuffer.updateMatrix("refractionMatrix",this._refractionTexture.getReflectionTextureMatrix()),this._refractionTexture.depth&&(h=this._refractionTexture.depth)),this._uniformBuffer.updateFloat4("vRefractionInfos",this._refractionTexture.level,this.indexOfRefraction,h,this.invertRefractionY?-1:1)}this.pointsCloud&&this._uniformBuffer.updateFloat("pointSize",this.pointSize),s.SPECULARTERM&&this._uniformBuffer.updateColor4("vSpecularColor",this.specularColor,this.specularPower),this._uniformBuffer.updateColor3("vEmissiveColor",this.emissiveColor),this._uniformBuffer.updateColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility)}if(n.texturesEnabled&&(this._diffuseTexture&&o.DiffuseTextureEnabled&&a.setTexture("diffuseSampler",this._diffuseTexture),this._ambientTexture&&o.AmbientTextureEnabled&&a.setTexture("ambientSampler",this._ambientTexture),this._opacityTexture&&o.OpacityTextureEnabled&&a.setTexture("opacitySampler",this._opacityTexture),this._reflectionTexture&&o.ReflectionTextureEnabled&&(this._reflectionTexture.isCube?a.setTexture("reflectionCubeSampler",this._reflectionTexture):a.setTexture("reflection2DSampler",this._reflectionTexture)),this._emissiveTexture&&o.EmissiveTextureEnabled&&a.setTexture("emissiveSampler",this._emissiveTexture),this._lightmapTexture&&o.LightmapTextureEnabled&&a.setTexture("lightmapSampler",this._lightmapTexture),this._specularTexture&&o.SpecularTextureEnabled&&a.setTexture("specularSampler",this._specularTexture),this._bumpTexture&&n.getEngine().getCaps().standardDerivatives&&o.BumpTextureEnabled&&a.setTexture("bumpSampler",this._bumpTexture),this._refractionTexture&&o.RefractionTextureEnabled)){var h=1;this._refractionTexture.isCube?a.setTexture("refractionCubeSampler",this._refractionTexture):a.setTexture("refraction2DSampler",this._refractionTexture)}e.MaterialHelper.BindClipPlane(a,n),n.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor),e.MaterialHelper.BindEyePosition(a,n),a.setColor3("vAmbientColor",this._globalAmbientColor)}!l&&this.isFrozen||(n.lightsEnabled&&!this._disableLighting&&e.MaterialHelper.BindLights(n,i,a,s,this._maxSimultaneousLights),(n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE||this._reflectionTexture||this._refractionTexture)&&this.bindView(a),e.MaterialHelper.BindFogParameters(n,i,a),s.NUM_MORPH_INFLUENCERS&&e.MaterialHelper.BindMorphTargetParameters(i,a),e.MaterialHelper.BindLogDepth(s,a,n),this._imageProcessingConfiguration.bind(this._activeEffect)),this._uniformBuffer.update(),this._afterBind(i,this._activeEffect)}}},o.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},o.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._diffuseTexture&&e.push(this._diffuseTexture),this._ambientTexture&&e.push(this._ambientTexture),this._opacityTexture&&e.push(this._opacityTexture),this._reflectionTexture&&e.push(this._reflectionTexture),this._emissiveTexture&&e.push(this._emissiveTexture),this._specularTexture&&e.push(this._specularTexture),this._bumpTexture&&e.push(this._bumpTexture),this._lightmapTexture&&e.push(this._lightmapTexture),this._refractionTexture&&e.push(this._refractionTexture),e},o.prototype.hasTexture=function(e){return!!i.prototype.hasTexture.call(this,e)||(this._diffuseTexture===e||(this._ambientTexture===e||(this._opacityTexture===e||(this._reflectionTexture===e||(this._emissiveTexture===e||(this._specularTexture===e||(this._bumpTexture===e||(this._lightmapTexture===e||this._refractionTexture===e))))))))},o.prototype.dispose=function(e,t){t&&(this._diffuseTexture&&this._diffuseTexture.dispose(),this._ambientTexture&&this._ambientTexture.dispose(),this._opacityTexture&&this._opacityTexture.dispose(),this._reflectionTexture&&this._reflectionTexture.dispose(),this._emissiveTexture&&this._emissiveTexture.dispose(),this._specularTexture&&this._specularTexture.dispose(),this._bumpTexture&&this._bumpTexture.dispose(),this._lightmapTexture&&this._lightmapTexture.dispose(),this._refractionTexture&&this._refractionTexture.dispose()),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),i.prototype.dispose.call(this,e,t)},o.prototype.clone=function(t){var i=this,r=e.SerializationHelper.Clone(function(){return new o(t,i.getScene())},this);return r.name=t,r.id=t,r},o.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},o.Parse=function(t,i,r){return e.SerializationHelper.Parse(function(){return new o(t.name,i)},t,i,r)},Object.defineProperty(o,"DiffuseTextureEnabled",{get:function(){return o._DiffuseTextureEnabled},set:function(t){o._DiffuseTextureEnabled!==t&&(o._DiffuseTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(o,"AmbientTextureEnabled",{get:function(){return o._AmbientTextureEnabled},set:function(t){o._AmbientTextureEnabled!==t&&(o._AmbientTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(o,"OpacityTextureEnabled",{get:function(){return o._OpacityTextureEnabled},set:function(t){o._OpacityTextureEnabled!==t&&(o._OpacityTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ReflectionTextureEnabled",{get:function(){return o._ReflectionTextureEnabled},set:function(t){o._ReflectionTextureEnabled!==t&&(o._ReflectionTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(o,"EmissiveTextureEnabled",{get:function(){return o._EmissiveTextureEnabled},set:function(t){o._EmissiveTextureEnabled!==t&&(o._EmissiveTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(o,"SpecularTextureEnabled",{get:function(){return o._SpecularTextureEnabled},set:function(t){o._SpecularTextureEnabled!==t&&(o._SpecularTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(o,"BumpTextureEnabled",{get:function(){return o._BumpTextureEnabled},set:function(t){o._BumpTextureEnabled!==t&&(o._BumpTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(o,"LightmapTextureEnabled",{get:function(){return o._LightmapTextureEnabled},set:function(t){o._LightmapTextureEnabled!==t&&(o._LightmapTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(o,"RefractionTextureEnabled",{get:function(){return o._RefractionTextureEnabled},set:function(t){o._RefractionTextureEnabled!==t&&(o._RefractionTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ColorGradingTextureEnabled",{get:function(){return o._ColorGradingTextureEnabled},set:function(t){o._ColorGradingTextureEnabled!==t&&(o._ColorGradingTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(o,"FresnelEnabled",{get:function(){return o._FresnelEnabled},set:function(t){o._FresnelEnabled!==t&&(o._FresnelEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.FresnelDirtyFlag))},enumerable:!0,configurable:!0}),o._DiffuseTextureEnabled=!0,o._AmbientTextureEnabled=!0,o._OpacityTextureEnabled=!0,o._ReflectionTextureEnabled=!0,o._EmissiveTextureEnabled=!0,o._SpecularTextureEnabled=!0,o._BumpTextureEnabled=!0,o._LightmapTextureEnabled=!0,o._RefractionTextureEnabled=!0,o._ColorGradingTextureEnabled=!0,o._FresnelEnabled=!0,r([e.serializeAsTexture("diffuseTexture")],o.prototype,"_diffuseTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"diffuseTexture",void 0),r([e.serializeAsTexture("ambientTexture")],o.prototype,"_ambientTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"ambientTexture",void 0),r([e.serializeAsTexture("opacityTexture")],o.prototype,"_opacityTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"opacityTexture",void 0),r([e.serializeAsTexture("reflectionTexture")],o.prototype,"_reflectionTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"reflectionTexture",void 0),r([e.serializeAsTexture("emissiveTexture")],o.prototype,"_emissiveTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"emissiveTexture",void 0),r([e.serializeAsTexture("specularTexture")],o.prototype,"_specularTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"specularTexture",void 0),r([e.serializeAsTexture("bumpTexture")],o.prototype,"_bumpTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"bumpTexture",void 0),r([e.serializeAsTexture("lightmapTexture")],o.prototype,"_lightmapTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"lightmapTexture",void 0),r([e.serializeAsTexture("refractionTexture")],o.prototype,"_refractionTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"refractionTexture",void 0),r([e.serializeAsColor3("ambient")],o.prototype,"ambientColor",void 0),r([e.serializeAsColor3("diffuse")],o.prototype,"diffuseColor",void 0),r([e.serializeAsColor3("specular")],o.prototype,"specularColor",void 0),r([e.serializeAsColor3("emissive")],o.prototype,"emissiveColor",void 0),r([e.serialize()],o.prototype,"specularPower",void 0),r([e.serialize("useAlphaFromDiffuseTexture")],o.prototype,"_useAlphaFromDiffuseTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"useAlphaFromDiffuseTexture",void 0),r([e.serialize("useEmissiveAsIllumination")],o.prototype,"_useEmissiveAsIllumination",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"useEmissiveAsIllumination",void 0),r([e.serialize("linkEmissiveWithDiffuse")],o.prototype,"_linkEmissiveWithDiffuse",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"linkEmissiveWithDiffuse",void 0),r([e.serialize("useSpecularOverAlpha")],o.prototype,"_useSpecularOverAlpha",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"useSpecularOverAlpha",void 0),r([e.serialize("useReflectionOverAlpha")],o.prototype,"_useReflectionOverAlpha",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"useReflectionOverAlpha",void 0),r([e.serialize("disableLighting")],o.prototype,"_disableLighting",void 0),r([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],o.prototype,"disableLighting",void 0),r([e.serialize("useParallax")],o.prototype,"_useParallax",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"useParallax",void 0),r([e.serialize("useParallaxOcclusion")],o.prototype,"_useParallaxOcclusion",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"useParallaxOcclusion",void 0),r([e.serialize()],o.prototype,"parallaxScaleBias",void 0),r([e.serialize("roughness")],o.prototype,"_roughness",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"roughness",void 0),r([e.serialize()],o.prototype,"indexOfRefraction",void 0),r([e.serialize()],o.prototype,"invertRefractionY",void 0),r([e.serialize("useLightmapAsShadowmap")],o.prototype,"_useLightmapAsShadowmap",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"useLightmapAsShadowmap",void 0),r([e.serializeAsFresnelParameters("diffuseFresnelParameters")],o.prototype,"_diffuseFresnelParameters",void 0),r([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],o.prototype,"diffuseFresnelParameters",void 0),r([e.serializeAsFresnelParameters("opacityFresnelParameters")],o.prototype,"_opacityFresnelParameters",void 0),r([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],o.prototype,"opacityFresnelParameters",void 0),r([e.serializeAsFresnelParameters("reflectionFresnelParameters")],o.prototype,"_reflectionFresnelParameters",void 0),r([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],o.prototype,"reflectionFresnelParameters",void 0),r([e.serializeAsFresnelParameters("refractionFresnelParameters")],o.prototype,"_refractionFresnelParameters",void 0),r([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],o.prototype,"refractionFresnelParameters",void 0),r([e.serializeAsFresnelParameters("emissiveFresnelParameters")],o.prototype,"_emissiveFresnelParameters",void 0),r([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],o.prototype,"emissiveFresnelParameters",void 0),r([e.serialize("useReflectionFresnelFromSpecular")],o.prototype,"_useReflectionFresnelFromSpecular",void 0),r([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],o.prototype,"useReflectionFresnelFromSpecular",void 0),r([e.serialize("useGlossinessFromSpecularMapAlpha")],o.prototype,"_useGlossinessFromSpecularMapAlpha",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"useGlossinessFromSpecularMapAlpha",void 0),r([e.serialize("maxSimultaneousLights")],o.prototype,"_maxSimultaneousLights",void 0),r([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],o.prototype,"maxSimultaneousLights",void 0),r([e.serialize("invertNormalMapX")],o.prototype,"_invertNormalMapX",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"invertNormalMapX",void 0),r([e.serialize("invertNormalMapY")],o.prototype,"_invertNormalMapY",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"invertNormalMapY",void 0),r([e.serialize("twoSidedLighting")],o.prototype,"_twoSidedLighting",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"twoSidedLighting",void 0),r([e.serialize()],o.prototype,"useLogarithmicDepth",null),o}(e.PushMaterial);e.StandardMaterial=i}(s||(s={}));!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.PBR=!0,t.MAINUV1=!1,t.MAINUV2=!1,t.UV1=!1,t.UV2=!1,t.ALBEDO=!1,t.ALBEDODIRECTUV=0,t.VERTEXCOLOR=!1,t.AMBIENT=!1,t.AMBIENTDIRECTUV=0,t.AMBIENTINGRAYSCALE=!1,t.OPACITY=!1,t.VERTEXALPHA=!1,t.OPACITYDIRECTUV=0,t.OPACITYRGB=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.ALPHABLEND=!1,t.ALPHAFROMALBEDO=!1,t.ALPHATESTVALUE=.5,t.SPECULAROVERALPHA=!1,t.RADIANCEOVERALPHA=!1,t.ALPHAFRESNEL=!1,t.PREMULTIPLYALPHA=!1,t.EMISSIVE=!1,t.EMISSIVEDIRECTUV=0,t.REFLECTIVITY=!1,t.REFLECTIVITYDIRECTUV=0,t.SPECULARTERM=!1,t.MICROSURFACEFROMREFLECTIVITYMAP=!1,t.MICROSURFACEAUTOMATIC=!1,t.LODBASEDMICROSFURACE=!1,t.MICROSURFACEMAP=!1,t.MICROSURFACEMAPDIRECTUV=0,t.METALLICWORKFLOW=!1,t.ROUGHNESSSTOREINMETALMAPALPHA=!1,t.ROUGHNESSSTOREINMETALMAPGREEN=!1,t.METALLNESSSTOREINMETALMAPBLUE=!1,t.AOSTOREINMETALMAPRED=!1,t.ENVIRONMENTBRDF=!1,t.NORMAL=!1,t.TANGENT=!1,t.BUMP=!1,t.BUMPDIRECTUV=0,t.PARALLAX=!1,t.PARALLAXOCCLUSION=!1,t.NORMALXYSCALE=!0,t.LIGHTMAP=!1,t.LIGHTMAPDIRECTUV=0,t.USELIGHTMAPASSHADOWMAP=!1,t.REFLECTION=!1,t.REFLECTIONMAP_3D=!1,t.REFLECTIONMAP_SPHERICAL=!1,t.REFLECTIONMAP_PLANAR=!1,t.REFLECTIONMAP_CUBIC=!1,t.REFLECTIONMAP_PROJECTION=!1,t.REFLECTIONMAP_SKYBOX=!1,t.REFLECTIONMAP_EXPLICIT=!1,t.REFLECTIONMAP_EQUIRECTANGULAR=!1,t.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!1,t.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!1,t.INVERTCUBICMAP=!1,t.USESPHERICALFROMREFLECTIONMAP=!1,t.USESPHERICALINVERTEX=!1,t.REFLECTIONMAP_OPPOSITEZ=!1,t.LODINREFLECTIONALPHA=!1,t.GAMMAREFLECTION=!1,t.REFRACTION=!1,t.REFRACTIONMAP_3D=!1,t.REFRACTIONMAP_OPPOSITEZ=!1,t.LODINREFRACTIONALPHA=!1,t.GAMMAREFRACTION=!1,t.LINKREFRACTIONTOTRANSPARENCY=!1,t.INSTANCES=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.NONUNIFORMSCALING=!1,t.MORPHTARGETS=!1,t.MORPHTARGETS_NORMAL=!1,t.MORPHTARGETS_TANGENT=!1,t.NUM_MORPH_INFLUENCERS=0,t.IMAGEPROCESSING=!1,t.VIGNETTE=!1,t.VIGNETTEBLENDMODEMULTIPLY=!1,t.VIGNETTEBLENDMODEOPAQUE=!1,t.TONEMAPPING=!1,t.CONTRAST=!1,t.COLORCURVES=!1,t.COLORGRADING=!1,t.COLORGRADING3D=!1,t.SAMPLER3DGREENDEPTH=!1,t.SAMPLER3DBGRMAP=!1,t.IMAGEPROCESSINGPOSTPROCESS=!1,t.EXPOSURE=!1,t.USEPHYSICALLIGHTFALLOFF=!1,t.TWOSIDEDLIGHTING=!1,t.SHADOWFLOAT=!1,t.CLIPPLANE=!1,t.POINTSIZE=!1,t.FOG=!1,t.LOGARITHMICDEPTH=!1,t.FORCENORMALFORWARD=!1,t.rebuild(),t}return n(t,e),t.prototype.reset=function(){e.prototype.reset.call(this),this.ALPHATESTVALUE=.5,this.PBR=!0},t}(e.MaterialDefines),i=function(i){function o(t,r){var n=i.call(this,t,r)||this;return n._directIntensity=1,n._emissiveIntensity=1,n._environmentIntensity=1,n._specularIntensity=1,n._lightingInfos=new e.Vector4(n._directIntensity,n._emissiveIntensity,n._environmentIntensity,n._specularIntensity),n._disableBumpMap=!1,n._ambientTextureStrength=1,n._ambientColor=new e.Color3(0,0,0),n._albedoColor=new e.Color3(1,1,1),n._reflectivityColor=new e.Color3(1,1,1),n._reflectionColor=new e.Color3(1,1,1),n._emissiveColor=new e.Color3(0,0,0),n._microSurface=.9,n._indexOfRefraction=.66,n._invertRefractionY=!1,n._linkRefractionWithTransparency=!1,n._useLightmapAsShadowmap=!1,n._useAlphaFromAlbedoTexture=!1,n._useSpecularOverAlpha=!0,n._useMicroSurfaceFromReflectivityMapAlpha=!1,n._useRoughnessFromMetallicTextureAlpha=!0,n._useRoughnessFromMetallicTextureGreen=!1,n._useMetallnessFromMetallicTextureBlue=!1,n._useAmbientOcclusionFromMetallicTextureRed=!1,n._useAmbientInGrayScale=!1,n._useAutoMicroSurfaceFromReflectivityMap=!1,n._usePhysicalLightFalloff=!0,n._useRadianceOverAlpha=!0,n._useParallax=!1,n._useParallaxOcclusion=!1,n._parallaxScaleBias=.05,n._disableLighting=!1,n._maxSimultaneousLights=4,n._invertNormalMapX=!1,n._invertNormalMapY=!1,n._twoSidedLighting=!1,n._alphaCutOff=.4,n._forceAlphaTest=!1,n._useAlphaFresnel=!1,n._transparencyMode=null,n._environmentBRDFTexture=null,n._forceIrradianceInFragment=!1,n._forceNormalForward=!1,n._renderTargets=new e.SmartArray(16),n._globalAmbientColor=new e.Color3(0,0,0),n._attachImageProcessingConfiguration(null),n.getRenderTargetTextures=function(){return n._renderTargets.reset(),e.StandardMaterial.ReflectionTextureEnabled&&n._reflectionTexture&&n._reflectionTexture.isRenderTarget&&n._renderTargets.push(n._reflectionTexture),e.StandardMaterial.RefractionTextureEnabled&&n._refractionTexture&&n._refractionTexture.isRenderTarget&&n._renderTargets.push(n._refractionTexture),n._renderTargets},n._environmentBRDFTexture=e.TextureTools.GetEnvironmentBRDFTexture(r),n}return n(o,i),o.prototype._attachImageProcessingConfiguration=function(e){var t=this;e!==this._imageProcessingConfiguration&&(this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),this._imageProcessingConfiguration=e||this.getScene().imageProcessingConfiguration,this._imageProcessingObserver=this._imageProcessingConfiguration.onUpdateParameters.add(function(e){t._markAllSubMeshesAsImageProcessingDirty()}))},o.prototype.getClassName=function(){return"PBRBaseMaterial"},Object.defineProperty(o.prototype,"useLogarithmicDepth",{get:function(){return this._useLogarithmicDepth},set:function(e){this._useLogarithmicDepth=e&&this.getScene().getEngine().getCaps().fragmentDepthSupported},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"transparencyMode",{get:function(){return this._transparencyMode},set:function(t){this._transparencyMode!==t&&(this._transparencyMode=t,this._forceAlphaTest=t===e.PBRMaterial.PBRMATERIAL_ALPHATESTANDBLEND,this._markAllSubMeshesAsTexturesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"_disableAlphaBlending",{get:function(){return this._linkRefractionWithTransparency||this._transparencyMode===e.PBRMaterial.PBRMATERIAL_OPAQUE||this._transparencyMode===e.PBRMaterial.PBRMATERIAL_ALPHATEST},enumerable:!0,configurable:!0}),o.prototype.needAlphaBlending=function(){return!this._disableAlphaBlending&&(this.alpha<1||null!=this._opacityTexture||this._shouldUseAlphaFromAlbedoTexture())},o.prototype.needAlphaBlendingForMesh=function(e){return!this._disableAlphaBlending&&i.prototype.needAlphaBlendingForMesh.call(this,e)},o.prototype.needAlphaTesting=function(){return!!this._forceAlphaTest||!this._linkRefractionWithTransparency&&(null!=this._albedoTexture&&this._albedoTexture.hasAlpha&&this._transparencyMode===e.PBRMaterial.PBRMATERIAL_ALPHATEST)},o.prototype._shouldUseAlphaFromAlbedoTexture=function(){return null!=this._albedoTexture&&this._albedoTexture.hasAlpha&&this._useAlphaFromAlbedoTexture&&this._transparencyMode!==e.PBRMaterial.PBRMATERIAL_OPAQUE},o.prototype.getAlphaTestTexture=function(){return this._albedoTexture},o.prototype.isReadyForSubMesh=function(i,r,n){var o=this;if(r.effect&&this.isFrozen&&this._wasPreviouslyReady)return!0;r._materialDefines||(r._materialDefines=new t);var s=this.getScene(),a=r._materialDefines;if(!this.checkReadyOnEveryCall&&r.effect&&a._renderId===s.getRenderId())return!0;var l=s.getEngine();if(e.MaterialHelper.PrepareDefinesForLights(s,i,a,!0,this._maxSimultaneousLights,this._disableLighting),a._needNormals=!0,a._areTexturesDirty){if(a._needUVs=!1,s.texturesEnabled){if(s.getEngine().getCaps().textureLOD&&(a.LODBASEDMICROSFURACE=!0),this._albedoTexture&&e.StandardMaterial.DiffuseTextureEnabled){if(!this._albedoTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._albedoTexture,a,"ALBEDO")}else a.ALBEDO=!1;if(this._ambientTexture&&e.StandardMaterial.AmbientTextureEnabled){if(!this._ambientTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._ambientTexture,a,"AMBIENT"),a.AMBIENTINGRAYSCALE=this._useAmbientInGrayScale}else a.AMBIENT=!1;if(this._opacityTexture&&e.StandardMaterial.OpacityTextureEnabled){if(!this._opacityTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._opacityTexture,a,"OPACITY"),a.OPACITYRGB=this._opacityTexture.getAlphaFromRGB}else a.OPACITY=!1;var h=this._getReflectionTexture();if(h&&e.StandardMaterial.ReflectionTextureEnabled){if(!h.isReadyOrNotBlocking())return!1;switch(a.REFLECTION=!0,a.GAMMAREFLECTION=h.gammaSpace,a.REFLECTIONMAP_OPPOSITEZ=this.getScene().useRightHandedSystem?!h.invertZ:h.invertZ,a.LODINREFLECTIONALPHA=h.lodLevelInAlpha,h.coordinatesMode===e.Texture.INVCUBIC_MODE&&(a.INVERTCUBICMAP=!0),a.REFLECTIONMAP_3D=h.isCube,h.coordinatesMode){case e.Texture.CUBIC_MODE:case e.Texture.INVCUBIC_MODE:a.REFLECTIONMAP_CUBIC=!0;break;case e.Texture.EXPLICIT_MODE:a.REFLECTIONMAP_EXPLICIT=!0;break;case e.Texture.PLANAR_MODE:a.REFLECTIONMAP_PLANAR=!0;break;case e.Texture.PROJECTION_MODE:a.REFLECTIONMAP_PROJECTION=!0;break;case e.Texture.SKYBOX_MODE:a.REFLECTIONMAP_SKYBOX=!0;break;case e.Texture.SPHERICAL_MODE:a.REFLECTIONMAP_SPHERICAL=!0;break;case e.Texture.EQUIRECTANGULAR_MODE:a.REFLECTIONMAP_EQUIRECTANGULAR=!0;break;case e.Texture.FIXED_EQUIRECTANGULAR_MODE:a.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!0;break;case e.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:a.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!0}h.coordinatesMode!==e.Texture.SKYBOX_MODE&&h.sphericalPolynomial&&(a.USESPHERICALFROMREFLECTIONMAP=!0,this._forceIrradianceInFragment||s.getEngine().getCaps().maxVaryingVectors<=8?a.USESPHERICALINVERTEX=!1:a.USESPHERICALINVERTEX=!0)}else a.REFLECTION=!1,a.REFLECTIONMAP_3D=!1,a.REFLECTIONMAP_SPHERICAL=!1,a.REFLECTIONMAP_PLANAR=!1,a.REFLECTIONMAP_CUBIC=!1,a.REFLECTIONMAP_PROJECTION=!1,a.REFLECTIONMAP_SKYBOX=!1,a.REFLECTIONMAP_EXPLICIT=!1,a.REFLECTIONMAP_EQUIRECTANGULAR=!1,a.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!1,a.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!1,a.INVERTCUBICMAP=!1,a.USESPHERICALFROMREFLECTIONMAP=!1,a.USESPHERICALINVERTEX=!1,a.REFLECTIONMAP_OPPOSITEZ=!1,a.LODINREFLECTIONALPHA=!1,a.GAMMAREFLECTION=!1;if(this._lightmapTexture&&e.StandardMaterial.LightmapTextureEnabled){if(!this._lightmapTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._lightmapTexture,a,"LIGHTMAP"),a.USELIGHTMAPASSHADOWMAP=this._useLightmapAsShadowmap}else a.LIGHTMAP=!1;if(this._emissiveTexture&&e.StandardMaterial.EmissiveTextureEnabled){if(!this._emissiveTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._emissiveTexture,a,"EMISSIVE")}else a.EMISSIVE=!1;if(e.StandardMaterial.SpecularTextureEnabled){if(this._metallicTexture){if(!this._metallicTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._metallicTexture,a,"REFLECTIVITY"),a.METALLICWORKFLOW=!0,a.ROUGHNESSSTOREINMETALMAPALPHA=this._useRoughnessFromMetallicTextureAlpha,a.ROUGHNESSSTOREINMETALMAPGREEN=!this._useRoughnessFromMetallicTextureAlpha&&this._useRoughnessFromMetallicTextureGreen,a.METALLNESSSTOREINMETALMAPBLUE=this._useMetallnessFromMetallicTextureBlue,a.AOSTOREINMETALMAPRED=this._useAmbientOcclusionFromMetallicTextureRed}else if(this._reflectivityTexture){if(!this._reflectivityTexture.isReadyOrNotBlocking())return!1;a.METALLICWORKFLOW=!1,e.MaterialHelper.PrepareDefinesForMergedUV(this._reflectivityTexture,a,"REFLECTIVITY"),a.MICROSURFACEFROMREFLECTIVITYMAP=this._useMicroSurfaceFromReflectivityMapAlpha,a.MICROSURFACEAUTOMATIC=this._useAutoMicroSurfaceFromReflectivityMap}else a.METALLICWORKFLOW=!1,a.REFLECTIVITY=!1;if(this._microSurfaceTexture){if(!this._microSurfaceTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._microSurfaceTexture,a,"MICROSURFACEMAP")}else a.MICROSURFACEMAP=!1}else a.REFLECTIVITY=!1,a.MICROSURFACEMAP=!1;if(s.getEngine().getCaps().standardDerivatives&&this._bumpTexture&&e.StandardMaterial.BumpTextureEnabled&&!this._disableBumpMap){if(!this._bumpTexture.isReady())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture,a,"BUMP"),this._useParallax&&this._albedoTexture&&e.StandardMaterial.DiffuseTextureEnabled?(a.PARALLAX=!0,a.PARALLAXOCCLUSION=!!this._useParallaxOcclusion):a.PARALLAX=!1}else a.BUMP=!1;var u=this._getRefractionTexture();if(u&&e.StandardMaterial.RefractionTextureEnabled){if(!u.isReadyOrNotBlocking())return!1;a.REFRACTION=!0,a.REFRACTIONMAP_3D=u.isCube,a.GAMMAREFRACTION=u.gammaSpace,a.REFRACTIONMAP_OPPOSITEZ=h.invertZ,a.LODINREFRACTIONALPHA=h.lodLevelInAlpha,this._linkRefractionWithTransparency&&(a.LINKREFRACTIONTOTRANSPARENCY=!0)}else a.REFRACTION=!1;if(this._environmentBRDFTexture&&e.StandardMaterial.ReflectionTextureEnabled){if(!this._environmentBRDFTexture.isReady())return!1;a.ENVIRONMENTBRDF=!0}else a.ENVIRONMENTBRDF=!1;this._shouldUseAlphaFromAlbedoTexture()?a.ALPHAFROMALBEDO=!0:a.ALPHAFROMALBEDO=!1}a.SPECULAROVERALPHA=this._useSpecularOverAlpha,a.USEPHYSICALLIGHTFALLOFF=this._usePhysicalLightFalloff,a.RADIANCEOVERALPHA=this._useRadianceOverAlpha,void 0!==this._metallic&&null!==this._metallic||void 0!==this._roughness&&null!==this._roughness?a.METALLICWORKFLOW=!0:a.METALLICWORKFLOW=!1,!this.backFaceCulling&&this._twoSidedLighting?a.TWOSIDEDLIGHTING=!0:a.TWOSIDEDLIGHTING=!1,a.ALPHATESTVALUE=this._alphaCutOff,a.PREMULTIPLYALPHA=this.alphaMode===e.Engine.ALPHA_PREMULTIPLIED||this.alphaMode===e.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF,a.ALPHABLEND=this.needAlphaBlendingForMesh(i),a.ALPHAFRESNEL=this._useAlphaFresnel}if(a._areImageProcessingDirty){if(!this._imageProcessingConfiguration.isReady())return!1;this._imageProcessingConfiguration.prepareDefines(a)}if(a.FORCENORMALFORWARD=this._forceNormalForward,e.MaterialHelper.PrepareDefinesForMisc(i,s,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,a),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,l,a,!!n,this._forceAlphaTest),e.MaterialHelper.PrepareDefinesForAttributes(i,a,!0,!0,!0,this._transparencyMode!==e.PBRMaterial.PBRMATERIAL_OPAQUE)&&i&&(s.getEngine().getCaps().standardDerivatives||i.isVerticesDataPresent(e.VertexBuffer.NormalKind)||(i.createNormals(!0),e.Tools.Warn("PBRMaterial: Normals have been created for the mesh: "+i.name))),a.isDirty){a.markAsProcessed(),s.resetCachedMaterial();var c=new e.EffectFallbacks,f=0;a.USESPHERICALINVERTEX&&c.addFallback(f++,"USESPHERICALINVERTEX"),a.FOG&&c.addFallback(f,"FOG"),a.POINTSIZE&&c.addFallback(f,"POINTSIZE"),a.LOGARITHMICDEPTH&&c.addFallback(f,"LOGARITHMICDEPTH"),a.PARALLAX&&c.addFallback(f,"PARALLAX"),a.PARALLAXOCCLUSION&&c.addFallback(f++,"PARALLAXOCCLUSION"),a.ENVIRONMENTBRDF&&c.addFallback(f++,"ENVIRONMENTBRDF"),a.TANGENT&&c.addFallback(f++,"TANGENT"),a.BUMP&&c.addFallback(f++,"BUMP"),f=e.MaterialHelper.HandleFallbacksForShadows(a,c,this._maxSimultaneousLights,f++),a.SPECULARTERM&&c.addFallback(f++,"SPECULARTERM"),a.USESPHERICALFROMREFLECTIONMAP&&c.addFallback(f++,"USESPHERICALFROMREFLECTIONMAP"),a.LIGHTMAP&&c.addFallback(f++,"LIGHTMAP"),a.NORMAL&&c.addFallback(f++,"NORMAL"),a.AMBIENT&&c.addFallback(f++,"AMBIENT"),a.EMISSIVE&&c.addFallback(f++,"EMISSIVE"),a.VERTEXCOLOR&&c.addFallback(f++,"VERTEXCOLOR"),a.NUM_BONE_INFLUENCERS>0&&c.addCPUSkinningFallback(f++,i),a.MORPHTARGETS&&c.addFallback(f++,"MORPHTARGETS");var p=[e.VertexBuffer.PositionKind];a.NORMAL&&p.push(e.VertexBuffer.NormalKind),a.TANGENT&&p.push(e.VertexBuffer.TangentKind),a.UV1&&p.push(e.VertexBuffer.UVKind),a.UV2&&p.push(e.VertexBuffer.UV2Kind),a.VERTEXCOLOR&&p.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(p,i,a,c),e.MaterialHelper.PrepareAttributesForInstances(p,a),e.MaterialHelper.PrepareAttributesForMorphTargets(p,i,a);var d=["world","view","viewProjection","vEyePosition","vLightsType","vAmbientColor","vAlbedoColor","vReflectivityColor","vEmissiveColor","vReflectionColor","vFogInfos","vFogColor","pointSize","vAlbedoInfos","vAmbientInfos","vOpacityInfos","vReflectionInfos","vEmissiveInfos","vReflectivityInfos","vMicroSurfaceSamplerInfos","vBumpInfos","vLightmapInfos","vRefractionInfos","mBones","vClipPlane","albedoMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","reflectivityMatrix","microSurfaceSamplerMatrix","bumpMatrix","lightmapMatrix","refractionMatrix","vLightingIntensity","logarithmicDepthConstant","vSphericalX","vSphericalY","vSphericalZ","vSphericalXX","vSphericalYY","vSphericalZZ","vSphericalXY","vSphericalYZ","vSphericalZX","vReflectionMicrosurfaceInfos","vRefractionMicrosurfaceInfos","vTangentSpaceParams"],m=["albedoSampler","reflectivitySampler","ambientSampler","emissiveSampler","bumpSampler","lightmapSampler","opacitySampler","refractionSampler","refractionSamplerLow","refractionSamplerHigh","reflectionSampler","reflectionSamplerLow","reflectionSamplerHigh","microSurfaceSampler","environmentBrdfSampler"],g=["Material","Scene"];e.ImageProcessingConfiguration.PrepareUniforms(d,a),e.ImageProcessingConfiguration.PrepareSamplers(m,a),e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:d,uniformBuffersNames:g,samplers:m,defines:a,maxSimultaneousLights:this._maxSimultaneousLights});var v=function(e){o.onCompiled&&o.onCompiled(e),o.bindSceneUniformBuffer(e,s.getSceneUniformBuffer())},_=a.toString();r.setEffect(s.getEngine().createEffect("pbr",{attributes:p,uniformsNames:d,uniformBuffersNames:g,samplers:m,defines:_,fallbacks:c,onCompiled:v,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights,maxSimultaneousMorphTargets:a.NUM_MORPH_INFLUENCERS}},l),a),this.buildUniformLayout()}return!(!r.effect||!r.effect.isReady())&&(a._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,!0)},o.prototype.buildUniformLayout=function(){this._uniformBuffer.addUniform("vAlbedoInfos",2),this._uniformBuffer.addUniform("vAmbientInfos",3),this._uniformBuffer.addUniform("vOpacityInfos",2),this._uniformBuffer.addUniform("vEmissiveInfos",2),this._uniformBuffer.addUniform("vLightmapInfos",2),this._uniformBuffer.addUniform("vReflectivityInfos",3),this._uniformBuffer.addUniform("vMicroSurfaceSamplerInfos",2),this._uniformBuffer.addUniform("vRefractionInfos",4),this._uniformBuffer.addUniform("vReflectionInfos",2),this._uniformBuffer.addUniform("vBumpInfos",3),this._uniformBuffer.addUniform("albedoMatrix",16),this._uniformBuffer.addUniform("ambientMatrix",16),this._uniformBuffer.addUniform("opacityMatrix",16),this._uniformBuffer.addUniform("emissiveMatrix",16),this._uniformBuffer.addUniform("lightmapMatrix",16),this._uniformBuffer.addUniform("reflectivityMatrix",16),this._uniformBuffer.addUniform("microSurfaceSamplerMatrix",16),this._uniformBuffer.addUniform("bumpMatrix",16),this._uniformBuffer.addUniform("vTangentSpaceParams",2),this._uniformBuffer.addUniform("refractionMatrix",16),this._uniformBuffer.addUniform("reflectionMatrix",16),this._uniformBuffer.addUniform("vReflectionColor",3),this._uniformBuffer.addUniform("vAlbedoColor",4),this._uniformBuffer.addUniform("vLightingIntensity",4),this._uniformBuffer.addUniform("vRefractionMicrosurfaceInfos",3),this._uniformBuffer.addUniform("vReflectionMicrosurfaceInfos",3),this._uniformBuffer.addUniform("vReflectivityColor",4),this._uniformBuffer.addUniform("vEmissiveColor",3),this._uniformBuffer.addUniform("pointSize",1),this._uniformBuffer.create()},o.prototype.unbind=function(){this._reflectionTexture&&this._reflectionTexture.isRenderTarget&&this._uniformBuffer.setTexture("reflectionSampler",null),this._refractionTexture&&this._refractionTexture.isRenderTarget&&this._uniformBuffer.setTexture("refractionSampler",null),i.prototype.unbind.call(this)},o.prototype.bindOnlyWorldMatrix=function(e){this._activeEffect.setMatrix("world",e)},o.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;if(s){this._activeEffect=s,this.bindOnlyWorldMatrix(t);var a=this._mustRebind(n,s,i.visibility);e.MaterialHelper.BindBonesParameters(i,this._activeEffect);var l=null;if(a){this._uniformBuffer.bindToEffect(s,"Material"),this.bindViewProjection(s),l=this._getReflectionTexture();var h=this._getRefractionTexture();if(!this._uniformBuffer.useUbo||!this.isFrozen||!this._uniformBuffer.isSync){if(n.texturesEnabled){if(this._albedoTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._uniformBuffer.updateFloat2("vAlbedoInfos",this._albedoTexture.coordinatesIndex,this._albedoTexture.level),e.MaterialHelper.BindTextureMatrix(this._albedoTexture,this._uniformBuffer,"albedo")),this._ambientTexture&&e.StandardMaterial.AmbientTextureEnabled&&(this._uniformBuffer.updateFloat3("vAmbientInfos",this._ambientTexture.coordinatesIndex,this._ambientTexture.level,this._ambientTextureStrength),e.MaterialHelper.BindTextureMatrix(this._ambientTexture,this._uniformBuffer,"ambient")),this._opacityTexture&&e.StandardMaterial.OpacityTextureEnabled&&(this._uniformBuffer.updateFloat2("vOpacityInfos",this._opacityTexture.coordinatesIndex,this._opacityTexture.level),e.MaterialHelper.BindTextureMatrix(this._opacityTexture,this._uniformBuffer,"opacity")),l&&e.StandardMaterial.ReflectionTextureEnabled){this._uniformBuffer.updateMatrix("reflectionMatrix",l.getReflectionTextureMatrix()),this._uniformBuffer.updateFloat2("vReflectionInfos",l.level,0);var u=l.sphericalPolynomial;o.USESPHERICALFROMREFLECTIONMAP&&u&&(this._activeEffect.setFloat3("vSphericalX",u.x.x,u.x.y,u.x.z),this._activeEffect.setFloat3("vSphericalY",u.y.x,u.y.y,u.y.z),this._activeEffect.setFloat3("vSphericalZ",u.z.x,u.z.y,u.z.z),this._activeEffect.setFloat3("vSphericalXX_ZZ",u.xx.x-u.zz.x,u.xx.y-u.zz.y,u.xx.z-u.zz.z),this._activeEffect.setFloat3("vSphericalYY_ZZ",u.yy.x-u.zz.x,u.yy.y-u.zz.y,u.yy.z-u.zz.z),this._activeEffect.setFloat3("vSphericalZZ",u.zz.x,u.zz.y,u.zz.z),this._activeEffect.setFloat3("vSphericalXY",u.xy.x,u.xy.y,u.xy.z),this._activeEffect.setFloat3("vSphericalYZ",u.yz.x,u.yz.y,u.yz.z),this._activeEffect.setFloat3("vSphericalZX",u.zx.x,u.zx.y,u.zx.z)),this._uniformBuffer.updateFloat3("vReflectionMicrosurfaceInfos",l.getSize().width,l.lodGenerationScale,l.lodGenerationOffset)}if(this._emissiveTexture&&e.StandardMaterial.EmissiveTextureEnabled&&(this._uniformBuffer.updateFloat2("vEmissiveInfos",this._emissiveTexture.coordinatesIndex,this._emissiveTexture.level),e.MaterialHelper.BindTextureMatrix(this._emissiveTexture,this._uniformBuffer,"emissive")),this._lightmapTexture&&e.StandardMaterial.LightmapTextureEnabled&&(this._uniformBuffer.updateFloat2("vLightmapInfos",this._lightmapTexture.coordinatesIndex,this._lightmapTexture.level),e.MaterialHelper.BindTextureMatrix(this._lightmapTexture,this._uniformBuffer,"lightmap")),e.StandardMaterial.SpecularTextureEnabled&&(this._metallicTexture?(this._uniformBuffer.updateFloat3("vReflectivityInfos",this._metallicTexture.coordinatesIndex,this._metallicTexture.level,this._ambientTextureStrength),e.MaterialHelper.BindTextureMatrix(this._metallicTexture,this._uniformBuffer,"reflectivity")):this._reflectivityTexture&&(this._uniformBuffer.updateFloat3("vReflectivityInfos",this._reflectivityTexture.coordinatesIndex,this._reflectivityTexture.level,1),e.MaterialHelper.BindTextureMatrix(this._reflectivityTexture,this._uniformBuffer,"reflectivity")),this._microSurfaceTexture&&(this._uniformBuffer.updateFloat2("vMicroSurfaceSamplerInfos",this._microSurfaceTexture.coordinatesIndex,this._microSurfaceTexture.level),e.MaterialHelper.BindTextureMatrix(this._microSurfaceTexture,this._uniformBuffer,"microSurfaceSampler"))),this._bumpTexture&&n.getEngine().getCaps().standardDerivatives&&e.StandardMaterial.BumpTextureEnabled&&!this._disableBumpMap&&(this._uniformBuffer.updateFloat3("vBumpInfos",this._bumpTexture.coordinatesIndex,this._bumpTexture.level,this._parallaxScaleBias),e.MaterialHelper.BindTextureMatrix(this._bumpTexture,this._uniformBuffer,"bump"),n._mirroredCameraPosition?this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?1:-1,this._invertNormalMapY?1:-1):this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?-1:1,this._invertNormalMapY?-1:1)),h&&e.StandardMaterial.RefractionTextureEnabled){this._uniformBuffer.updateMatrix("refractionMatrix",h.getReflectionTextureMatrix());var c=1;h.isCube||h.depth&&(c=h.depth),this._uniformBuffer.updateFloat4("vRefractionInfos",h.level,this._indexOfRefraction,c,this._invertRefractionY?-1:1),this._uniformBuffer.updateFloat3("vRefractionMicrosurfaceInfos",h.getSize().width,h.lodGenerationScale,h.lodGenerationOffset)}}this.pointsCloud&&this._uniformBuffer.updateFloat("pointSize",this.pointSize),o.METALLICWORKFLOW?(e.PBRMaterial._scaledReflectivity.r=void 0===this._metallic||null===this._metallic?1:this._metallic,e.PBRMaterial._scaledReflectivity.g=void 0===this._roughness||null===this._roughness?1:this._roughness,this._uniformBuffer.updateColor4("vReflectivityColor",e.PBRMaterial._scaledReflectivity,0)):this._uniformBuffer.updateColor4("vReflectivityColor",this._reflectivityColor,this._microSurface),this._uniformBuffer.updateColor3("vEmissiveColor",this._emissiveColor),this._uniformBuffer.updateColor3("vReflectionColor",this._reflectionColor),this._uniformBuffer.updateColor4("vAlbedoColor",this._albedoColor,this.alpha*i.visibility),this._lightingInfos.x=this._directIntensity,this._lightingInfos.y=this._emissiveIntensity,this._lightingInfos.z=this._environmentIntensity,this._lightingInfos.w=this._specularIntensity,this._uniformBuffer.updateVector4("vLightingIntensity",this._lightingInfos)}n.texturesEnabled&&(this._albedoTexture&&e.StandardMaterial.DiffuseTextureEnabled&&this._uniformBuffer.setTexture("albedoSampler",this._albedoTexture),this._ambientTexture&&e.StandardMaterial.AmbientTextureEnabled&&this._uniformBuffer.setTexture("ambientSampler",this._ambientTexture),this._opacityTexture&&e.StandardMaterial.OpacityTextureEnabled&&this._uniformBuffer.setTexture("opacitySampler",this._opacityTexture),l&&e.StandardMaterial.ReflectionTextureEnabled&&(o.LODBASEDMICROSFURACE?this._uniformBuffer.setTexture("reflectionSampler",l):(this._uniformBuffer.setTexture("reflectionSampler",l._lodTextureMid||l),this._uniformBuffer.setTexture("reflectionSamplerLow",l._lodTextureLow||l),this._uniformBuffer.setTexture("reflectionSamplerHigh",l._lodTextureHigh||l))),o.ENVIRONMENTBRDF&&this._uniformBuffer.setTexture("environmentBrdfSampler",this._environmentBRDFTexture),h&&e.StandardMaterial.RefractionTextureEnabled&&(o.LODBASEDMICROSFURACE?this._uniformBuffer.setTexture("refractionSampler",h):(this._uniformBuffer.setTexture("refractionSampler",h._lodTextureMid||h),this._uniformBuffer.setTexture("refractionSamplerLow",h._lodTextureLow||h),this._uniformBuffer.setTexture("refractionSamplerHigh",h._lodTextureHigh||h))),this._emissiveTexture&&e.StandardMaterial.EmissiveTextureEnabled&&this._uniformBuffer.setTexture("emissiveSampler",this._emissiveTexture),this._lightmapTexture&&e.StandardMaterial.LightmapTextureEnabled&&this._uniformBuffer.setTexture("lightmapSampler",this._lightmapTexture),e.StandardMaterial.SpecularTextureEnabled&&(this._metallicTexture?this._uniformBuffer.setTexture("reflectivitySampler",this._metallicTexture):this._reflectivityTexture&&this._uniformBuffer.setTexture("reflectivitySampler",this._reflectivityTexture),this._microSurfaceTexture&&this._uniformBuffer.setTexture("microSurfaceSampler",this._microSurfaceTexture)),this._bumpTexture&&n.getEngine().getCaps().standardDerivatives&&e.StandardMaterial.BumpTextureEnabled&&!this._disableBumpMap&&this._uniformBuffer.setTexture("bumpSampler",this._bumpTexture)),e.MaterialHelper.BindClipPlane(this._activeEffect,n),n.ambientColor.multiplyToRef(this._ambientColor,this._globalAmbientColor);var f=n._forcedViewPosition?n._forcedViewPosition:n._mirroredCameraPosition?n._mirroredCameraPosition:n.activeCamera.globalPosition,p=n.useRightHandedSystem===(null!=n._mirroredCameraPosition);s.setFloat4("vEyePosition",f.x,f.y,f.z,p?-1:1),s.setColor3("vAmbientColor",this._globalAmbientColor)}!a&&this.isFrozen||(n.lightsEnabled&&!this._disableLighting&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o,this._maxSimultaneousLights,this._usePhysicalLightFalloff),(n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE||l)&&this.bindView(s),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),o.NUM_MORPH_INFLUENCERS&&e.MaterialHelper.BindMorphTargetParameters(i,this._activeEffect),this._imageProcessingConfiguration.bind(this._activeEffect),e.MaterialHelper.BindLogDepth(o,this._activeEffect,n)),this._uniformBuffer.update(),this._afterBind(i)}}},o.prototype.getAnimatables=function(){var e=[];return this._albedoTexture&&this._albedoTexture.animations&&this._albedoTexture.animations.length>0&&e.push(this._albedoTexture),this._ambientTexture&&this._ambientTexture.animations&&this._ambientTexture.animations.length>0&&e.push(this._ambientTexture),this._opacityTexture&&this._opacityTexture.animations&&this._opacityTexture.animations.length>0&&e.push(this._opacityTexture),this._reflectionTexture&&this._reflectionTexture.animations&&this._reflectionTexture.animations.length>0&&e.push(this._reflectionTexture),this._emissiveTexture&&this._emissiveTexture.animations&&this._emissiveTexture.animations.length>0&&e.push(this._emissiveTexture),this._metallicTexture&&this._metallicTexture.animations&&this._metallicTexture.animations.length>0?e.push(this._metallicTexture):this._reflectivityTexture&&this._reflectivityTexture.animations&&this._reflectivityTexture.animations.length>0&&e.push(this._reflectivityTexture),this._bumpTexture&&this._bumpTexture.animations&&this._bumpTexture.animations.length>0&&e.push(this._bumpTexture),this._lightmapTexture&&this._lightmapTexture.animations&&this._lightmapTexture.animations.length>0&&e.push(this._lightmapTexture),this._refractionTexture&&this._refractionTexture.animations&&this._refractionTexture.animations.length>0&&e.push(this._refractionTexture),e},o.prototype._getReflectionTexture=function(){return this._reflectionTexture?this._reflectionTexture:this.getScene().environmentTexture},o.prototype._getRefractionTexture=function(){return this._refractionTexture?this._refractionTexture:this._linkRefractionWithTransparency?this.getScene().environmentTexture:null},o.prototype.dispose=function(e,t){t&&(this._albedoTexture&&this._albedoTexture.dispose(),this._ambientTexture&&this._ambientTexture.dispose(),this._opacityTexture&&this._opacityTexture.dispose(),this._reflectionTexture&&this._reflectionTexture.dispose(),this._environmentBRDFTexture&&this.getScene()._environmentBRDFTexture!==this._environmentBRDFTexture&&this._environmentBRDFTexture.dispose(),this._emissiveTexture&&this._emissiveTexture.dispose(),this._metallicTexture&&this._metallicTexture.dispose(),this._reflectivityTexture&&this._reflectivityTexture.dispose(),this._bumpTexture&&this._bumpTexture.dispose(),this._lightmapTexture&&this._lightmapTexture.dispose(),this._refractionTexture&&this._refractionTexture.dispose()),this._renderTargets.dispose(),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),i.prototype.dispose.call(this,e,t)},o._scaledReflectivity=new e.Color3,r([e.serializeAsImageProcessingConfiguration()],o.prototype,"_imageProcessingConfiguration",void 0),r([e.serialize()],o.prototype,"useLogarithmicDepth",null),r([e.serialize()],o.prototype,"transparencyMode",null),o}(e.PushMaterial);e.PBRBaseMaterial=i}(s||(s={}));!function(e){!function(t){var i=function(t){function i(i,r){var n=t.call(this,i,r)||this;return n.maxSimultaneousLights=4,n.disableLighting=!1,n.invertNormalMapX=!1,n.invertNormalMapY=!1,n.emissiveColor=new e.Color3(0,0,0),n.occlusionStrength=1,n._transparencyMode=e.PBRMaterial.PBRMATERIAL_OPAQUE,n._useAlphaFromAlbedoTexture=!0,n._useAmbientInGrayScale=!0,n}return n(i,t),Object.defineProperty(i.prototype,"doubleSided",{get:function(){return this._twoSidedLighting},set:function(e){this._twoSidedLighting!==e&&(this._twoSidedLighting=e,this.backFaceCulling=!e,this._markAllSubMeshesAsTexturesDirty())},enumerable:!0,configurable:!0}),i.prototype.getActiveTextures=function(){var e=t.prototype.getActiveTextures.call(this);return this.environmentTexture&&e.push(this.environmentTexture),this.normalTexture&&e.push(this.normalTexture),this.emissiveTexture&&e.push(this.emissiveTexture),this.occlusionTexture&&e.push(this.occlusionTexture),e},i.prototype.getClassName=function(){return"PBRBaseSimpleMaterial"},r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsLightsDirty")],i.prototype,"maxSimultaneousLights",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsLightsDirty")],i.prototype,"disableLighting",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_reflectionTexture")],i.prototype,"environmentTexture",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"invertNormalMapX",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"invertNormalMapY",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_bumpTexture")],i.prototype,"normalTexture",void 0),r([e.serializeAsColor3("emissive"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"emissiveColor",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"emissiveTexture",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_ambientTextureStrength")],i.prototype,"occlusionStrength",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_ambientTexture")],i.prototype,"occlusionTexture",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_alphaCutOff")],i.prototype,"alphaCutOff",void 0),r([e.serialize()],i.prototype,"doubleSided",null),i}(e.PBRBaseMaterial);t.PBRBaseSimpleMaterial=i}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){var t=function(t){function i(i,r){var n=t.call(this,i,r)||this;return n.directIntensity=1,n.emissiveIntensity=1,n.environmentIntensity=1,n.specularIntensity=1,n.disableBumpMap=!1,n.ambientTextureStrength=1,n.ambientColor=new e.Color3(0,0,0),n.albedoColor=new e.Color3(1,1,1),n.reflectivityColor=new e.Color3(1,1,1),n.reflectionColor=new e.Color3(1,1,1),n.emissiveColor=new e.Color3(0,0,0),n.microSurface=1,n.indexOfRefraction=.66,n.invertRefractionY=!1,n.linkRefractionWithTransparency=!1,n.useLightmapAsShadowmap=!1,n.useAlphaFromAlbedoTexture=!1,n.forceAlphaTest=!1,n.alphaCutOff=.4,n.useSpecularOverAlpha=!0,n.useMicroSurfaceFromReflectivityMapAlpha=!1,n.useRoughnessFromMetallicTextureAlpha=!0,n.useRoughnessFromMetallicTextureGreen=!1,n.useMetallnessFromMetallicTextureBlue=!1,n.useAmbientOcclusionFromMetallicTextureRed=!1,n.useAmbientInGrayScale=!1,n.useAutoMicroSurfaceFromReflectivityMap=!1,n.usePhysicalLightFalloff=!0,n.useRadianceOverAlpha=!0,n.useParallax=!1,n.useParallaxOcclusion=!1,n.parallaxScaleBias=.05,n.disableLighting=!1,n.forceIrradianceInFragment=!1,n.maxSimultaneousLights=4,n.invertNormalMapX=!1,n.invertNormalMapY=!1,n.twoSidedLighting=!1,n.useAlphaFresnel=!1,n.environmentBRDFTexture=null,n.forceNormalForward=!1,n._environmentBRDFTexture=e.TextureTools.GetEnvironmentBRDFTexture(r),n}return n(i,t),Object.defineProperty(i,"PBRMATERIAL_OPAQUE",{get:function(){return this._PBRMATERIAL_OPAQUE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PBRMATERIAL_ALPHATEST",{get:function(){return this._PBRMATERIAL_ALPHATEST},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PBRMATERIAL_ALPHABLEND",{get:function(){return this._PBRMATERIAL_ALPHABLEND},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PBRMATERIAL_ALPHATESTANDBLEND",{get:function(){return this._PBRMATERIAL_ALPHATESTANDBLEND},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},set:function(e){this._attachImageProcessingConfiguration(e),this._markAllSubMeshesAsTexturesDirty()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraColorCurvesEnabled",{get:function(){return this.imageProcessingConfiguration.colorCurvesEnabled},set:function(e){this.imageProcessingConfiguration.colorCurvesEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraColorGradingEnabled",{get:function(){return this.imageProcessingConfiguration.colorGradingEnabled},set:function(e){this.imageProcessingConfiguration.colorGradingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraToneMappingEnabled",{get:function(){return this._imageProcessingConfiguration.toneMappingEnabled},set:function(e){this._imageProcessingConfiguration.toneMappingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraExposure",{get:function(){return this._imageProcessingConfiguration.exposure},set:function(e){this._imageProcessingConfiguration.exposure=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraContrast",{get:function(){return this._imageProcessingConfiguration.contrast},set:function(e){this._imageProcessingConfiguration.contrast=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraColorGradingTexture",{get:function(){return this._imageProcessingConfiguration.colorGradingTexture},set:function(e){this._imageProcessingConfiguration.colorGradingTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraColorCurves",{get:function(){return this._imageProcessingConfiguration.colorCurves},set:function(e){this._imageProcessingConfiguration.colorCurves=e},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"PBRMaterial"},i.prototype.getActiveTextures=function(){var e=t.prototype.getActiveTextures.call(this);return this._albedoTexture&&e.push(this._albedoTexture),this._ambientTexture&&e.push(this._ambientTexture),this._opacityTexture&&e.push(this._opacityTexture),this._reflectionTexture&&e.push(this._reflectionTexture),this._emissiveTexture&&e.push(this._emissiveTexture),this._reflectivityTexture&&e.push(this._reflectivityTexture),this._metallicTexture&&e.push(this._metallicTexture),this._microSurfaceTexture&&e.push(this._microSurfaceTexture),this._bumpTexture&&e.push(this._bumpTexture),this._lightmapTexture&&e.push(this._lightmapTexture),this._refractionTexture&&e.push(this._refractionTexture),e},i.prototype.hasTexture=function(e){return!!t.prototype.hasTexture.call(this,e)||(this._albedoTexture===e||(this._ambientTexture===e||(this._opacityTexture===e||(this._reflectionTexture===e||(this._reflectivityTexture===e||(this._metallicTexture===e||(this._microSurfaceTexture===e||(this._bumpTexture===e||(this._lightmapTexture===e||this._refractionTexture===e)))))))))},i.prototype.clone=function(t){var r=this,n=e.SerializationHelper.Clone(function(){return new i(t,r.getScene())},this);return n.id=t,n.name=t,n},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.PBRMaterial",t},i.Parse=function(t,r,n){return e.SerializationHelper.Parse(function(){return new i(t.name,r)},t,r,n)},i._PBRMATERIAL_OPAQUE=0,i._PBRMATERIAL_ALPHATEST=1,i._PBRMATERIAL_ALPHABLEND=2,i._PBRMATERIAL_ALPHATESTANDBLEND=3,r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"directIntensity",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"emissiveIntensity",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"environmentIntensity",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"specularIntensity",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"disableBumpMap",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"albedoTexture",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"ambientTexture",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"ambientTextureStrength",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"opacityTexture",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"reflectionTexture",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"emissiveTexture",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"reflectivityTexture",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"metallicTexture",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"metallic",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"roughness",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"microSurfaceTexture",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"bumpTexture",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty",null)],i.prototype,"lightmapTexture",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"refractionTexture",void 0),r([e.serializeAsColor3("ambient"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"ambientColor",void 0),r([e.serializeAsColor3("albedo"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"albedoColor",void 0),r([e.serializeAsColor3("reflectivity"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"reflectivityColor",void 0),r([e.serializeAsColor3("reflection"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"reflectionColor",void 0),r([e.serializeAsColor3("emissive"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"emissiveColor",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"microSurface",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"indexOfRefraction",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"invertRefractionY",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"linkRefractionWithTransparency",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useLightmapAsShadowmap",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useAlphaFromAlbedoTexture",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"forceAlphaTest",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"alphaCutOff",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useSpecularOverAlpha",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useMicroSurfaceFromReflectivityMapAlpha",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useRoughnessFromMetallicTextureAlpha",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useRoughnessFromMetallicTextureGreen",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useMetallnessFromMetallicTextureBlue",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useAmbientOcclusionFromMetallicTextureRed",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useAmbientInGrayScale",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useAutoMicroSurfaceFromReflectivityMap",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"usePhysicalLightFalloff",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useRadianceOverAlpha",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useParallax",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useParallaxOcclusion",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"parallaxScaleBias",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsLightsDirty")],i.prototype,"disableLighting",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"forceIrradianceInFragment",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsLightsDirty")],i.prototype,"maxSimultaneousLights",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"invertNormalMapX",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"invertNormalMapY",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"twoSidedLighting",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useAlphaFresnel",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"environmentBRDFTexture",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"forceNormalForward",void 0),i}(e.PBRBaseMaterial);e.PBRMaterial=t}(s||(s={}));!function(e){var t=function(t){function i(e,i){var r=t.call(this,e,i)||this;return r._useRoughnessFromMetallicTextureAlpha=!1,r._useRoughnessFromMetallicTextureGreen=!0,r._useMetallnessFromMetallicTextureBlue=!0,r}return n(i,t),i.prototype.getClassName=function(){return"PBRMetallicRoughnessMaterial"},i.prototype.getActiveTextures=function(){var e=t.prototype.getActiveTextures.call(this);return this.baseTexture&&e.push(this.baseTexture),this.metallicRoughnessTexture&&e.push(this.metallicRoughnessTexture),e},i.prototype.hasTexture=function(e){return!!t.prototype.hasTexture.call(this,e)||(this.baseTexture===e||this.metallicRoughnessTexture===e)},i.prototype.clone=function(t){var r=this,n=e.SerializationHelper.Clone(function(){return new i(t,r.getScene())},this);return n.id=t,n.name=t,n},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.PBRMetallicRoughnessMaterial",t},i.Parse=function(t,r,n){return e.SerializationHelper.Parse(function(){return new i(t.name,r)},t,r,n)},r([e.serializeAsColor3(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoColor")],i.prototype,"baseColor",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoTexture")],i.prototype,"baseTexture",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"metallic",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"roughness",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_metallicTexture")],i.prototype,"metallicRoughnessTexture",void 0),i}(e.Internals.PBRBaseSimpleMaterial);e.PBRMetallicRoughnessMaterial=t}(s||(s={}));!function(e){var t=function(t){function i(e,i){var r=t.call(this,e,i)||this;return r._useMicroSurfaceFromReflectivityMapAlpha=!0,r}return n(i,t),i.prototype.getClassName=function(){return"PBRSpecularGlossinessMaterial"},i.prototype.getActiveTextures=function(){var e=t.prototype.getActiveTextures.call(this);return this.diffuseTexture&&e.push(this.diffuseTexture),this.specularGlossinessTexture&&e.push(this.specularGlossinessTexture),e},i.prototype.hasTexture=function(e){return!!t.prototype.hasTexture.call(this,e)||(this.diffuseTexture===e||this.specularGlossinessTexture===e)},i.prototype.clone=function(t){var r=this,n=e.SerializationHelper.Clone(function(){return new i(t,r.getScene())},this);return n.id=t,n.name=t,n},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.PBRSpecularGlossinessMaterial",t},i.Parse=function(t,r,n){return e.SerializationHelper.Parse(function(){return new i(t.name,r)},t,r,n)},r([e.serializeAsColor3("diffuse"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoColor")],i.prototype,"diffuseColor",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoTexture")],i.prototype,"diffuseTexture",void 0),r([e.serializeAsColor3("specular"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_reflectivityColor")],i.prototype,"specularColor",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_microSurface")],i.prototype,"glossiness",void 0),r([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_reflectivityTexture")],i.prototype,"specularGlossinessTexture",void 0),i}(e.Internals.PBRBaseSimpleMaterial);e.PBRSpecularGlossinessMaterial=t}(s||(s={}));!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();this.attached[i]?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))),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),i.camera=null,delete this.attached[t],this.rebuildInputCheck())}},t.prototype.removeByType=function(e){for(var t in this.attached){var i=this.attached[t];i.getClassName()===e&&(i.detachControl(this.attachedElement),i.camera=null,delete this.attached[t],this.rebuildInputCheck())}},t.prototype._addCheckInputs=function(e){var t=this.checkInputs;return function(){t(),e()}},t.prototype.attachInput=function(e){this.attachedElement&&e.attachControl(this.attachedElement,this.noPreventDefault)},t.prototype.attachElement=function(t,i){if(void 0===i&&(i=!1),!this.attachedElement){i=!e.Camera.ForceAttachControlToAlwaysPreventDefault&&i,this.attachedElement=t,this.noPreventDefault=i;for(var r in this.attached)this.attached[r].attachControl(t,i)}},t.prototype.detachElement=function(e,t){if(void 0===t&&(t=!1),this.attachedElement===e){for(var i in this.attached)this.attached[i].detachControl(e),t&&(this.attached[i].camera=null);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,!0),this.attached={},this.attachedElement=null,this.checkInputs=function(){}},t.prototype.serialize=function(t){var i={};for(var r in this.attached){var n=this.attached[r],o=e.SerializationHelper.Serialize(n);i[n.getClassName()]=o}t.inputsmgr=i},t.prototype.parse=function(t){var i=t.inputsmgr;if(i){this.clear();for(var r in i)if(s=e.CameraInputTypes[r]){var n=i[r],o=e.SerializationHelper.Parse(function(){return new s},n,null);this.add(o)}}else for(var r in this.attached){var s=e.CameraInputTypes[this.attached[r].getClassName()];if(s){o=e.SerializationHelper.Parse(function(){return new s},t,null);this.remove(this.attached[r]),this.add(o)}}},t}();e.CameraInputsManager=t}(s||(s={}));!function(e){var t=function(){function t(e){void 0===e&&(e=!0),this.touchEnabled=e,this.buttons=[0,1,2],this.angularSensibility=2e3,this.previousPosition=null}return t.prototype.attachControl=function(t,i){var r=this,n=this.camera.getEngine();this._pointerInput||(this._pointerInput=function(o,s){var a=o.event;if(!n.isInVRExclusivePointerMode&&(r.touchEnabled||"touch"!==a.pointerType)&&(o.type===e.PointerEventTypes.POINTERMOVE||-1!==r.buttons.indexOf(a.button))){var l=a.srcElement||a.target;if(o.type===e.PointerEventTypes.POINTERDOWN&&l){try{l.setPointerCapture(a.pointerId)}catch(e){}r.previousPosition={x:a.clientX,y:a.clientY},i||(a.preventDefault(),t.focus())}else if(o.type===e.PointerEventTypes.POINTERUP&&l){try{l.releasePointerCapture(a.pointerId)}catch(e){}r.previousPosition=null,i||a.preventDefault()}else if(o.type===e.PointerEventTypes.POINTERMOVE){if(!r.previousPosition||n.isPointerLock)return;var h=a.clientX-r.previousPosition.x,u=a.clientY-r.previousPosition.y;r.camera.getScene().useRightHandedSystem?r.camera.cameraRotation.y-=h/r.angularSensibility:r.camera.cameraRotation.y+=h/r.angularSensibility,r.camera.cameraRotation.x+=u/r.angularSensibility,r.previousPosition={x:a.clientX,y:a.clientY},i||a.preventDefault()}}}),this._onMouseMove=function(e){if(n.isPointerLock&&!n.isInVRExclusivePointerMode){var t=e.movementX||e.mozMovementX||e.webkitMovementX||e.msMovementX||0,o=e.movementY||e.mozMovementY||e.webkitMovementY||e.msMovementY||0;r.camera.getScene().useRightHandedSystem?r.camera.cameraRotation.y-=t/r.angularSensibility:r.camera.cameraRotation.y+=t/r.angularSensibility,r.camera.cameraRotation.x+=o/r.angularSensibility,r.previousPosition=null,i||e.preventDefault()}},this._observer=this.camera.getScene().onPointerObservable.add(this._pointerInput,e.PointerEventTypes.POINTERDOWN|e.PointerEventTypes.POINTERUP|e.PointerEventTypes.POINTERMOVE),t.addEventListener("mousemove",this._onMouseMove,!1)},t.prototype.detachControl=function(e){this._observer&&e&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._onMouseMove&&e.removeEventListener("mousemove",this._onMouseMove),this._observer=null,this._onMouseMove=null,this.previousPosition=null)},t.prototype.getClassName=function(){return"FreeCameraMouseInput"},t.prototype.getSimpleName=function(){return"mouse"},r([e.serialize()],t.prototype,"buttons",void 0),r([e.serialize()],t.prototype,"angularSensibility",void 0),t}();e.FreeCameraMouseInput=t,e.CameraInputTypes.FreeCameraMouseInput=t}(s||(s={}));!function(e){var t=function(){function t(){this._keys=new Array,this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39]}return t.prototype.attachControl=function(t,i){var r=this;this._onCanvasBlurObserver||(this._scene=this.camera.getScene(),this._engine=this._scene.getEngine(),this._onCanvasBlurObserver=this._engine.onCanvasBlurObservable.add(function(){r._keys=[]}),this._onKeyboardObserver=this._scene.onKeyboardObservable.add(function(t){var n=t.event;if(t.type===e.KeyboardEventTypes.KEYDOWN)-1===r.keysUp.indexOf(n.keyCode)&&-1===r.keysDown.indexOf(n.keyCode)&&-1===r.keysLeft.indexOf(n.keyCode)&&-1===r.keysRight.indexOf(n.keyCode)||(-1===(o=r._keys.indexOf(n.keyCode))&&r._keys.push(n.keyCode),i||n.preventDefault());else if(-1!==r.keysUp.indexOf(n.keyCode)||-1!==r.keysDown.indexOf(n.keyCode)||-1!==r.keysLeft.indexOf(n.keyCode)||-1!==r.keysRight.indexOf(n.keyCode)){var o=r._keys.indexOf(n.keyCode);o>=0&&r._keys.splice(o,1),i||n.preventDefault()}}))},t.prototype.detachControl=function(e){this._scene&&(this._onKeyboardObserver&&this._scene.onKeyboardObservable.remove(this._onKeyboardObserver),this._onCanvasBlurObserver&&this._engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver),this._onKeyboardObserver=null,this._onCanvasBlurObserver=null),this._keys=[]},t.prototype.checkInputs=function(){if(this._onKeyboardObserver)for(var t=this.camera,i=0;i<this._keys.length;i++){var r=this._keys[i],n=t._computeLocalCameraSpeed();-1!==this.keysLeft.indexOf(r)?t._localDirection.copyFromFloats(-n,0,0):-1!==this.keysUp.indexOf(r)?t._localDirection.copyFromFloats(0,0,n):-1!==this.keysRight.indexOf(r)?t._localDirection.copyFromFloats(n,0,0):-1!==this.keysDown.indexOf(r)&&t._localDirection.copyFromFloats(0,0,-n),t.getScene().useRightHandedSystem&&(t._localDirection.z*=-1),t.getViewMatrix().invertToRef(t._cameraTransformMatrix),e.Vector3.TransformNormalToRef(t._localDirection,t._cameraTransformMatrix,t._transformedDirection),t.cameraDirection.addInPlace(t._transformedDirection)}},t.prototype.getClassName=function(){return"FreeCameraKeyboardMoveInput"},t.prototype._onLostFocus=function(e){this._keys=[]},t.prototype.getSimpleName=function(){return"keyboard"},r([e.serialize()],t.prototype,"keysUp",void 0),r([e.serialize()],t.prototype,"keysDown",void 0),r([e.serialize()],t.prototype,"keysLeft",void 0),r([e.serialize()],t.prototype,"keysRight",void 0),t}();e.FreeCameraKeyboardMoveInput=t,e.CameraInputTypes.FreeCameraKeyboardMoveInput=t}(s||(s={}));!function(e){var t=function(t){function i(e){return t.call(this,e)||this}return n(i,t),i.prototype.addKeyboard=function(){return this.add(new e.FreeCameraKeyboardMoveInput),this},i.prototype.addMouse=function(t){return void 0===t&&(t=!0),this.add(new e.FreeCameraMouseInput(t)),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.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}(s||(s={}));!function(e){var t=function(t){function i(i,r,n){var o=t.call(this,i,r,n)||this;return o.cameraDirection=new e.Vector3(0,0,0),o.cameraRotation=new e.Vector2(0,0),o.rotation=new e.Vector3(0,0,0),o.speed=2,o.noRotationConstraint=!1,o.lockedTarget=null,o._currentTarget=e.Vector3.Zero(),o._viewMatrix=e.Matrix.Zero(),o._camMatrix=e.Matrix.Zero(),o._cameraTransformMatrix=e.Matrix.Zero(),o._cameraRotationMatrix=e.Matrix.Zero(),o._referencePoint=new e.Vector3(0,0,1),o._defaultUpVector=new e.Vector3(0,1,0),o._transformedReferencePoint=e.Vector3.Zero(),o._lookAtTemp=e.Matrix.Zero(),o._tempMatrix=e.Matrix.Zero(),o}return n(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.absolutePosition&&this.lockedTarget.computeWorldMatrix(),this.lockedTarget.absolutePosition||this.lockedTarget):null},i.prototype.storeState=function(){return this._storedPosition=this.position.clone(),this._storedRotation=this.rotation.clone(),this.rotationQuaternion&&(this._storedRotationQuaternion=this.rotationQuaternion.clone()),t.prototype.storeState.call(this)},i.prototype._restoreStateValues=function(){return!!t.prototype._restoreStateValues.call(this)&&(this.position=this._storedPosition.clone(),this.rotation=this._storedRotation.clone(),this.rotationQuaternion&&(this.rotationQuaternion=this._storedRotationQuaternion.clone()),this.cameraDirection.copyFromFloats(0,0,0),this.cameraRotation.copyFromFloats(0,0),!0)},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),this._cache.rotationQuaternion=new e.Quaternion(Number.MAX_VALUE,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),this.rotationQuaternion&&this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion)},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.rotationQuaternion?this.rotationQuaternion.equals(this._cache.rotationQuaternion):this._cache.rotation.equals(this.rotation))},i.prototype._computeLocalCameraSpeed=function(){var e=this.getEngine();return this.speed*Math.sqrt(e.getDeltaTime()/(100*e.getFps()))},i.prototype.setTarget=function(t){this.upVector.normalize(),e.Matrix.LookAtLHToRef(this.position,t,this._defaultUpVector,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=0,isNaN(this.rotation.x)&&(this.rotation.x=0),isNaN(this.rotation.y)&&(this.rotation.y=0),isNaN(this.rotation.z)&&(this.rotation.z=0),this.rotationQuaternion&&e.Quaternion.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this.rotationQuaternion)},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(){if(this.parent)return this.parent.getWorldMatrix().invertToRef(e.Tmp.Matrix[0]),e.Vector3.TransformNormalToRef(this.cameraDirection,e.Tmp.Matrix[0],e.Tmp.Vector3[0]),void this.position.addInPlace(e.Tmp.Vector3[0]);this.position.addInPlace(this.cameraDirection)},i.prototype._checkInputs=function(){var i=this._decideIfNeedsToMove(),r=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(i&&this._updatePosition(),r&&(this.rotation.x+=this.cameraRotation.x,this.rotation.y+=this.cameraRotation.y,this.rotationQuaternion&&this.rotation.lengthSquared()&&e.Quaternion.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this.rotationQuaternion),!this.noRotationConstraint)){var n=Math.PI/2*.95;this.rotation.x>n&&(this.rotation.x=n),this.rotation.x<-n&&(this.rotation.x=-n)}i&&(Math.abs(this.cameraDirection.x)<this.speed*e.Epsilon&&(this.cameraDirection.x=0),Math.abs(this.cameraDirection.y)<this.speed*e.Epsilon&&(this.cameraDirection.y=0),Math.abs(this.cameraDirection.z)<this.speed*e.Epsilon&&(this.cameraDirection.z=0),this.cameraDirection.scaleInPlace(this.inertia)),r&&(Math.abs(this.cameraRotation.x)<this.speed*e.Epsilon&&(this.cameraRotation.x=0),Math.abs(this.cameraRotation.y)<this.speed*e.Epsilon&&(this.cameraRotation.y=0),this.cameraRotation.scaleInPlace(this.inertia)),t.prototype._checkInputs.call(this)},i.prototype._updateCameraRotationMatrix=function(){this.rotationQuaternion?this.rotationQuaternion.toRotationMatrix(this._cameraRotationMatrix):e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),e.Vector3.TransformNormalToRef(this._defaultUpVector,this._cameraRotationMatrix,this.upVector)},i.prototype._getViewMatrix=function(){if(this.lockedTarget){var t=this._getLockedTargetPosition();t&&this._currentTarget.copyFrom(t)}else this._updateCameraRotationMatrix(),e.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),this.position.addToRef(this._transformedReferencePoint,this._currentTarget);return this.getScene().useRightHandedSystem?e.Matrix.LookAtRHToRef(this.position,this._currentTarget,this.upVector,this._viewMatrix):e.Matrix.LookAtLHToRef(this.position,this._currentTarget,this.upVector,this._viewMatrix),this._viewMatrix},i.prototype.createRigCamera=function(t,r){if(this.cameraRigMode!==e.Camera.RIG_MODE_NONE){var n=new i(t,this.position.clone(),this.getScene());return this.cameraRigMode!==e.Camera.RIG_MODE_VR&&this.cameraRigMode!==e.Camera.RIG_MODE_WEBVR||(this.rotationQuaternion||(this.rotationQuaternion=new e.Quaternion),n._cameraRigParams={},n.rotationQuaternion=new e.Quaternion),n}return null},i.prototype._updateRigCameras=function(){var i=this._rigCameras[0],r=this._rigCameras[1];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:var n=this.cameraRigMode===e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED?1:-1,o=this.cameraRigMode===e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED?-1:1;this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle*n,i.position),this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle*o,r.position),i.setTarget(this.getTarget()),r.setTarget(this.getTarget());break;case e.Camera.RIG_MODE_VR:i.rotationQuaternion?(i.rotationQuaternion.copyFrom(this.rotationQuaternion),r.rotationQuaternion.copyFrom(this.rotationQuaternion)):(i.rotation.copyFrom(this.rotation),r.rotation.copyFrom(this.rotation)),i.position.copyFrom(this.position),r.position.copyFrom(this.position)}t.prototype._updateRigCameras.call(this)},i.prototype._getRigCamPosition=function(t,i){this._rigCamTransformMatrix||(this._rigCamTransformMatrix=new e.Matrix);var r=this.getTarget();e.Matrix.Translation(-r.x,-r.y,-r.z).multiplyToRef(e.Matrix.RotationY(t),this._rigCamTransformMatrix),this._rigCamTransformMatrix=this._rigCamTransformMatrix.multiply(e.Matrix.Translation(r.x,r.y,r.z)),e.Vector3.TransformCoordinatesToRef(this.position,this._rigCamTransformMatrix,i)},i.prototype.getClassName=function(){return"TargetCamera"},r([e.serializeAsVector3()],i.prototype,"rotation",void 0),r([e.serialize()],i.prototype,"speed",void 0),r([e.serializeAsMeshReference("lockedTargetId")],i.prototype,"lockedTarget",void 0),i}(e.Camera);e.TargetCamera=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n){var o=t.call(this,i,r,n)||this;return o.ellipsoid=new e.Vector3(.5,1,.5),o.checkCollisions=!1,o.applyGravity=!1,o._needMoveForGravity=!1,o._oldPosition=e.Vector3.Zero(),o._diffPosition=e.Vector3.Zero(),o._newPosition=e.Vector3.Zero(),o._collisionMask=-1,o._onCollisionPositionChange=function(t,i,r){void 0===r&&(r=null),o.getScene().workerCollisions&&i.multiplyInPlace(o._collider.radius);!function(t){o._newPosition.copyFrom(t),o._newPosition.subtractToRef(o._oldPosition,o._diffPosition),o._diffPosition.length()>e.Engine.CollisionsEpsilon&&(o.position.addInPlace(o._diffPosition),o.onCollide&&r&&o.onCollide(r))}(i)},o.inputs=new e.FreeCameraInputsManager(o),o.inputs.addKeyboard().addMouse(),o}return n(i,t),Object.defineProperty(i.prototype,"angularSensibility",{get:function(){var e=this.inputs.attached.mouse;return e?e.angularSensibility: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:[]},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:[]},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:[]},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:[]},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)},Object.defineProperty(i.prototype,"collisionMask",{get:function(){return this._collisionMask},set:function(e){this._collisionMask=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),i.prototype._collideWithWorld=function(t){(this.parent?e.Vector3.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position).subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._collider||(this._collider=new e.Collider),this._collider.radius=this.ellipsoid,this._collider.collisionMask=this._collisionMask;var i=t;this.applyGravity&&(i=t.add(this.getScene().gravity)),this.getScene().collisionCoordinator.getNewPosition(this._oldPosition,i,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId)},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):t.prototype._updatePosition.call(this)},i.prototype.dispose=function(){this.inputs.clear(),t.prototype.dispose.call(this)},i.prototype.getClassName=function(){return"FreeCamera"},r([e.serializeAsVector3()],i.prototype,"ellipsoid",void 0),r([e.serialize()],i.prototype,"checkCollisions",void 0),r([e.serialize()],i.prototype,"applyGravity",void 0),i}(e.TargetCamera);e.FreeCamera=t}(s||(s={}));!function(e){var t=function(){function t(){this._keys=new Array,this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39],this.keysReset=[220],this.panningSensibility=50,this.zoomingSensibility=25,this.useAltToZoom=!0}return t.prototype.attachControl=function(t,i){var r=this;this._onCanvasBlurObserver||(this._scene=this.camera.getScene(),this._engine=this._scene.getEngine(),this._onCanvasBlurObserver=this._engine.onCanvasBlurObservable.add(function(){r._keys=[]}),this._onKeyboardObserver=this._scene.onKeyboardObservable.add(function(t){var n=t.event;if(t.type===e.KeyboardEventTypes.KEYDOWN)r._ctrlPressed=n.ctrlKey,r._altPressed=n.altKey,-1===r.keysUp.indexOf(n.keyCode)&&-1===r.keysDown.indexOf(n.keyCode)&&-1===r.keysLeft.indexOf(n.keyCode)&&-1===r.keysRight.indexOf(n.keyCode)&&-1===r.keysReset.indexOf(n.keyCode)||(-1===(o=r._keys.indexOf(n.keyCode))&&r._keys.push(n.keyCode),n.preventDefault&&(i||n.preventDefault()));else if(-1!==r.keysUp.indexOf(n.keyCode)||-1!==r.keysDown.indexOf(n.keyCode)||-1!==r.keysLeft.indexOf(n.keyCode)||-1!==r.keysRight.indexOf(n.keyCode)||-1!==r.keysReset.indexOf(n.keyCode)){var o=r._keys.indexOf(n.keyCode);o>=0&&r._keys.splice(o,1),n.preventDefault&&(i||n.preventDefault())}}))},t.prototype.detachControl=function(e){this._scene&&(this._onKeyboardObserver&&this._scene.onKeyboardObservable.remove(this._onKeyboardObserver),this._onCanvasBlurObserver&&this._engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver),this._onKeyboardObserver=null,this._onCanvasBlurObserver=null),this._keys=[]},t.prototype.checkInputs=function(){if(this._onKeyboardObserver)for(var e=this.camera,t=0;t<this._keys.length;t++){var i=this._keys[t];-1!==this.keysLeft.indexOf(i)?this._ctrlPressed&&this.camera._useCtrlForPanning?e.inertialPanningX-=1/this.panningSensibility:e.inertialAlphaOffset-=.01:-1!==this.keysUp.indexOf(i)?this._ctrlPressed&&this.camera._useCtrlForPanning?e.inertialPanningY+=1/this.panningSensibility:this._altPressed&&this.useAltToZoom?e.inertialRadiusOffset+=1/this.zoomingSensibility:e.inertialBetaOffset-=.01:-1!==this.keysRight.indexOf(i)?this._ctrlPressed&&this.camera._useCtrlForPanning?e.inertialPanningX+=1/this.panningSensibility:e.inertialAlphaOffset+=.01:-1!==this.keysDown.indexOf(i)?this._ctrlPressed&&this.camera._useCtrlForPanning?e.inertialPanningY-=1/this.panningSensibility:this._altPressed&&this.useAltToZoom?e.inertialRadiusOffset-=1/this.zoomingSensibility:e.inertialBetaOffset+=.01:-1!==this.keysReset.indexOf(i)&&e.restoreState()}},t.prototype.getClassName=function(){return"ArcRotateCameraKeyboardMoveInput"},t.prototype.getSimpleName=function(){return"keyboard"},r([e.serialize()],t.prototype,"keysUp",void 0),r([e.serialize()],t.prototype,"keysDown",void 0),r([e.serialize()],t.prototype,"keysLeft",void 0),r([e.serialize()],t.prototype,"keysRight",void 0),r([e.serialize()],t.prototype,"keysReset",void 0),r([e.serialize()],t.prototype,"panningSensibility",void 0),r([e.serialize()],t.prototype,"zoomingSensibility",void 0),r([e.serialize()],t.prototype,"useAltToZoom",void 0),t}();e.ArcRotateCameraKeyboardMoveInput=t,e.CameraInputTypes.ArcRotateCameraKeyboardMoveInput=t}(s||(s={}));!function(e){var t=function(){function t(){this.wheelPrecision=3,this.wheelDeltaPercentage=0}return t.prototype.attachControl=function(t,i){var r=this;this._wheel=function(t,n){if(t.type===e.PointerEventTypes.POINTERWHEEL){var o=t.event,s=0;o.wheelDelta?s=r.wheelDeltaPercentage?.01*o.wheelDelta*r.camera.radius*r.wheelDeltaPercentage:o.wheelDelta/(40*r.wheelPrecision):o.detail&&(s=-o.detail/r.wheelPrecision),s&&(r.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.getClassName=function(){return"ArcRotateCameraMouseWheelInput"},t.prototype.getSimpleName=function(){return"mousewheel"},r([e.serialize()],t.prototype,"wheelPrecision",void 0),r([e.serialize()],t.prototype,"wheelDeltaPercentage",void 0),t}();e.ArcRotateCameraMouseWheelInput=t,e.CameraInputTypes.ArcRotateCameraMouseWheelInput=t}(s||(s={}));!function(e){var t=function(){function t(){this.buttons=[0,1,2],this.angularSensibilityX=1e3,this.angularSensibilityY=1e3,this.pinchPrecision=12,this.pinchDeltaPercentage=0,this.panningSensibility=1e3,this.multiTouchPanning=!0,this.multiTouchPanAndZoom=!0,this._isPanClick=!1,this.pinchInwards=!0}return t.prototype.attachControl=function(t,i){var r,n=this,o=this.camera.getEngine(),s=null,a=null,l=0,h=0,u=0,c={x:0,y:0,isPaning:!1,isPinching:!1};this._pointerInput=function(f,p){var d=f.event,m="touch"===f.event.pointerType;if(!o.isInVRExclusivePointerMode&&(f.type===e.PointerEventTypes.POINTERMOVE||-1!==n.buttons.indexOf(d.button))){var g=d.srcElement||d.target;if(f.type===e.PointerEventTypes.POINTERDOWN&&g){try{g.setPointerCapture(d.pointerId)}catch(e){}n._isPanClick=d.button===n.camera._panningMouseButton,r={x:d.clientX,y:d.clientY,pointerId:d.pointerId,type:d.pointerType},null===s?s=r:null===a&&(a=r),i||(d.preventDefault(),t.focus())}else if(f.type===e.PointerEventTypes.POINTERDOUBLETAP)n.camera.restoreState();else if(f.type===e.PointerEventTypes.POINTERUP&&g){try{g.releasePointerCapture(d.pointerId)}catch(e){}r=null,l=0,c.isPaning=!1,c.isPinching=!1,u=0,h=0,m||(a=null),o.badOS?s=a=null:a&&s&&s.pointerId==d.pointerId?(s=a,a=null,r={x:s.x,y:s.y,pointerId:s.pointerId,type:d.pointerType}):s&&a&&a.pointerId==d.pointerId?(a=null,r={x:s.x,y:s.y,pointerId:s.pointerId,type:d.pointerType}):s=a=null,i||d.preventDefault()}else if(f.type===e.PointerEventTypes.POINTERMOVE)if(i||d.preventDefault(),s&&null===a&&r){if(0!==n.panningSensibility&&(d.ctrlKey&&n.camera._useCtrlForPanning||n._isPanClick))n.camera.inertialPanningX+=-(d.clientX-r.x)/n.panningSensibility,n.camera.inertialPanningY+=(d.clientY-r.y)/n.panningSensibility;else{var v=d.clientX-r.x,_=d.clientY-r.y;n.camera.inertialAlphaOffset-=v/n.angularSensibilityX,n.camera.inertialBetaOffset-=_/n.angularSensibilityY}r.x=d.clientX,r.y=d.clientY}else if(s&&a){var y=s.pointerId===d.pointerId?s:a;y.x=d.clientX,y.y=d.clientY;var x=n.pinchInwards?1:-1,b=s.x-a.x,T=s.y-a.y,E=b*b+T*T,A=Math.sqrt(E);if(0===l)return h=A,l=E,c.x=(s.x+a.x)/2,void(c.y=(s.y+a.y)/2);if(n.multiTouchPanAndZoom){if(n.pinchDeltaPercentage?n.camera.inertialRadiusOffset+=.001*(E-l)*n.camera.radius*n.pinchDeltaPercentage:n.camera.inertialRadiusOffset+=(E-l)/(n.pinchPrecision*((n.angularSensibilityX+n.angularSensibilityY)/2)*x),0!==n.panningSensibility){var P=(s.x+a.x)/2,S=(s.y+a.y)/2,M=P-c.x,C=S-c.y;c.x=P,c.y=S,n.camera.inertialPanningX+=-M/n.panningSensibility,n.camera.inertialPanningY+=C/n.panningSensibility}}else{if(u++,c.isPinching||u<20&&Math.abs(A-h)>n.camera.pinchToPanMaxDistance)n.pinchDeltaPercentage?n.camera.inertialRadiusOffset+=.001*(E-l)*n.camera.radius*n.pinchDeltaPercentage:n.camera.inertialRadiusOffset+=(E-l)/(n.pinchPrecision*((n.angularSensibilityX+n.angularSensibilityY)/2)*x),c.isPaning=!1,c.isPinching=!0;else if(r&&r.pointerId===y.pointerId&&0!==n.panningSensibility&&n.multiTouchPanning){if(!c.isPaning)return c.isPaning=!0,c.isPinching=!1,c.x=y.x,void(c.y=y.y);n.camera.inertialPanningX+=-(y.x-c.x)/n.panningSensibility,n.camera.inertialPanningY+=(y.y-c.y)/n.panningSensibility}r&&r.pointerId===d.pointerId&&(c.x=y.x,c.y=y.y)}l=E}}},this._observer=this.camera.getScene().onPointerObservable.add(this._pointerInput,e.PointerEventTypes.POINTERDOWN|e.PointerEventTypes.POINTERUP|e.PointerEventTypes.POINTERMOVE|e.PointerEventTypes._POINTERDOUBLETAP),this._onContextMenu=function(e){e.preventDefault()},this.camera._useCtrlForPanning||t.addEventListener("contextmenu",this._onContextMenu,!1),this._onLostFocus=function(){s=a=null,l=0,c.isPaning=!1,c.isPinching=!1,u=0,r=null,h=0},this._onMouseMove=function(e){if(o.isPointerLock){var t=e.movementX||e.mozMovementX||e.webkitMovementX||e.msMovementX||0,r=e.movementY||e.mozMovementY||e.webkitMovementY||e.msMovementY||0;n.camera.inertialAlphaOffset-=t/n.angularSensibilityX,n.camera.inertialBetaOffset-=r/n.angularSensibilityY,i||e.preventDefault()}},this._onGestureStart=function(e){void 0!==window.MSGesture&&(n._MSGestureHandler||(n._MSGestureHandler=new MSGesture,n._MSGestureHandler.target=t),n._MSGestureHandler.addPointer(e.pointerId))},this._onGesture=function(e){n.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:"blur",handler:this._onLostFocus}])},t.prototype.detachControl=function(t){this._onLostFocus&&e.Tools.UnregisterTopRootEvents([{name:"blur",handler:this._onLostFocus}]),t&&this._observer&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._observer=null,this._onContextMenu&&t.removeEventListener("contextmenu",this._onContextMenu),this._onMouseMove&&t.removeEventListener("mousemove",this._onMouseMove),this._onGestureStart&&t.removeEventListener("MSPointerDown",this._onGestureStart),this._onGesture&&t.removeEventListener("MSGestureChange",this._onGesture),this._isPanClick=!1,this.pinchInwards=!0,this._onMouseMove=null,this._onGestureStart=null,this._onGesture=null,this._MSGestureHandler=null,this._onLostFocus=null,this._onContextMenu=null)},t.prototype.getClassName=function(){return"ArcRotateCameraPointersInput"},t.prototype.getSimpleName=function(){return"pointers"},r([e.serialize()],t.prototype,"buttons",void 0),r([e.serialize()],t.prototype,"angularSensibilityX",void 0),r([e.serialize()],t.prototype,"angularSensibilityY",void 0),r([e.serialize()],t.prototype,"pinchPrecision",void 0),r([e.serialize()],t.prototype,"pinchDeltaPercentage",void 0),r([e.serialize()],t.prototype,"panningSensibility",void 0),r([e.serialize()],t.prototype,"multiTouchPanning",void 0),r([e.serialize()],t.prototype,"multiTouchPanAndZoom",void 0),t}();e.ArcRotateCameraPointersInput=t,e.CameraInputTypes.ArcRotateCameraPointersInput=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a){var l=t.call(this,i,e.Vector3.Zero(),a)||this;return l.inertialAlphaOffset=0,l.inertialBetaOffset=0,l.inertialRadiusOffset=0,l.lowerAlphaLimit=null,l.upperAlphaLimit=null,l.lowerBetaLimit=.01,l.upperBetaLimit=Math.PI,l.lowerRadiusLimit=null,l.upperRadiusLimit=null,l.inertialPanningX=0,l.inertialPanningY=0,l.pinchToPanMaxDistance=20,l.panningDistanceLimit=null,l.panningOriginTarget=e.Vector3.Zero(),l.panningInertia=.9,l.zoomOnFactor=1,l.targetScreenOffset=e.Vector2.Zero(),l.allowUpsideDown=!0,l._viewMatrix=new e.Matrix,l.panningAxis=new e.Vector3(1,1,0),l.onMeshTargetChangedObservable=new e.Observable,l.checkCollisions=!1,l.collisionRadius=new e.Vector3(.5,.5,.5),l._previousPosition=e.Vector3.Zero(),l._collisionVelocity=e.Vector3.Zero(),l._newPosition=e.Vector3.Zero(),l._onCollisionPositionChange=function(t,i,r){void 0===r&&(r=null),l.getScene().workerCollisions&&l.checkCollisions&&i.multiplyInPlace(l._collider.radius),r?(l.setPosition(i),l.onCollide&&l.onCollide(r)):l._previousPosition.copyFrom(l.position);var n=Math.cos(l.alpha),o=Math.sin(l.alpha),s=Math.cos(l.beta),a=Math.sin(l.beta);0===a&&(a=1e-4);var h=l._getTargetPosition();h.addToRef(new e.Vector3(l.radius*n*a,l.radius*s,l.radius*o*a),l._newPosition),l.position.copyFrom(l._newPosition);var u=l.upVector;l.allowUpsideDown&&l.beta<0&&(u=(u=u.clone()).negate()),e.Matrix.LookAtLHToRef(l.position,h,u,l._viewMatrix),l._viewMatrix.m[12]+=l.targetScreenOffset.x,l._viewMatrix.m[13]+=l.targetScreenOffset.y,l._collisionTriggered=!1},l._target=e.Vector3.Zero(),s&&l.setTarget(s),l.alpha=r,l.beta=n,l.radius=o,l.getViewMatrix(),l.inputs=new e.ArcRotateCameraInputsManager(l),l.inputs.addKeyboard().addMouseWheel().addPointers(),l}return n(i,t),Object.defineProperty(i.prototype,"target",{get:function(){return this._target},set:function(e){this.setTarget(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"angularSensibilityX",{get:function(){var e=this.inputs.attached.pointers;return e?e.angularSensibilityX: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: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:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.pinchPrecision=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"pinchDeltaPercentage",{get:function(){var e=this.inputs.attached.pointers;return e?e.pinchDeltaPercentage:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.pinchDeltaPercentage=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"panningSensibility",{get:function(){var e=this.inputs.attached.pointers;return e?e.panningSensibility: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:[]},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:[]},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:[]},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:[]},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:0},set:function(e){var t=this.inputs.attached.mousewheel;t&&(t.wheelPrecision=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"wheelDeltaPercentage",{get:function(){var e=this.inputs.attached.mousewheel;return e?e.wheelDeltaPercentage:0},set:function(e){var t=this.inputs.attached.mousewheel;t&&(t.wheelDeltaPercentage=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"bouncingBehavior",{get:function(){return this._bouncingBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"useBouncingBehavior",{get:function(){return null!=this._bouncingBehavior},set:function(t){t!==this.useBouncingBehavior&&(t?(this._bouncingBehavior=new e.BouncingBehavior,this.addBehavior(this._bouncingBehavior)):this._bouncingBehavior&&(this.removeBehavior(this._bouncingBehavior),this._bouncingBehavior=null))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"framingBehavior",{get:function(){return this._framingBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"useFramingBehavior",{get:function(){return null!=this._framingBehavior},set:function(t){t!==this.useFramingBehavior&&(t?(this._framingBehavior=new e.FramingBehavior,this.addBehavior(this._framingBehavior)):this._framingBehavior&&(this.removeBehavior(this._framingBehavior),this._framingBehavior=null))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"autoRotationBehavior",{get:function(){return this._autoRotationBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"useAutoRotationBehavior",{get:function(){return null!=this._autoRotationBehavior},set:function(t){t!==this.useAutoRotationBehavior&&(t?(this._autoRotationBehavior=new e.AutoRotationBehavior,this.addBehavior(this._autoRotationBehavior)):this._autoRotationBehavior&&(this.removeBehavior(this._autoRotationBehavior),this._autoRotationBehavior=null))},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(){if(this._targetHost&&this._targetHost.getAbsolutePosition){var e=this._targetHost.getAbsolutePosition();this._targetBoundingCenter?e.addToRef(this._targetBoundingCenter,this._target):this._target.copyFrom(e)}var t=this._getLockedTargetPosition();return t||this._target},i.prototype.storeState=function(){return this._storedAlpha=this.alpha,this._storedBeta=this.beta,this._storedRadius=this.radius,this._storedTarget=this._getTargetPosition().clone(),t.prototype.storeState.call(this)},i.prototype._restoreStateValues=function(){return!!t.prototype._restoreStateValues.call(this)&&(this.alpha=this._storedAlpha,this.beta=this._storedBeta,this.radius=this._storedRadius,this.setTarget(this._storedTarget.clone()),this.inertialAlphaOffset=0,this.inertialBetaOffset=0,this.inertialRadiusOffset=0,this.inertialPanningX=0,this.inertialPanningY=0,!0)},i.prototype._isSynchronizedViewMatrix=function(){return!!t.prototype._isSynchronizedViewMatrix.call(this)&&(this._cache._target.equals(this._getTargetPosition())&&this._cache.alpha===this.alpha&&this._cache.beta===this.beta&&this._cache.radius===this.radius&&this._cache.targetScreenOffset.equals(this.targetScreenOffset))},i.prototype.attachControl=function(e,t,i,r){var n=this;void 0===i&&(i=!0),void 0===r&&(r=2),this._useCtrlForPanning=i,this._panningMouseButton=r,this.inputs.attachElement(e,t),this._reset=function(){n.inertialAlphaOffset=0,n.inertialBetaOffset=0,n.inertialRadiusOffset=0,n.inertialPanningX=0,n.inertialPanningY=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.getScene().useRightHandedSystem?this.alpha-=this.beta<=0?-this.inertialAlphaOffset:this.inertialAlphaOffset: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)<this.speed*e.Epsilon&&(this.inertialRadiusOffset=0)),0===this.inertialPanningX&&0===this.inertialPanningY||(this._localDirection||(this._localDirection=e.Vector3.Zero(),this._transformedDirection=e.Vector3.Zero()),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._targetHost||(this.panningDistanceLimit?(this._transformedDirection.addInPlace(this._target),e.Vector3.DistanceSquared(this._transformedDirection,this.panningOriginTarget)<=this.panningDistanceLimit*this.panningDistanceLimit&&this._target.copyFrom(this._transformedDirection)):this._target.addInPlace(this._transformedDirection)),this.inertialPanningX*=this.panningInertia,this.inertialPanningY*=this.panningInertia,Math.abs(this.inertialPanningX)<this.speed*e.Epsilon&&(this.inertialPanningX=0),Math.abs(this.inertialPanningY)<this.speed*e.Epsilon&&(this.inertialPanningY=0)),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(),0===this.radius&&(this.radius=1e-4),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.copyFrom(e),this.rebuildAnglesAndRadius())},i.prototype.setTarget=function(e,t,i){if(void 0===t&&(t=!1),void 0===i&&(i=!1),e.getBoundingInfo)this._targetBoundingCenter=t?e.getBoundingInfo().boundingBox.centerWorld.clone():null,this._targetHost=e,this._target=this._getTargetPosition(),this.onMeshTargetChangedObservable.notifyObservers(this._targetHost);else{var r=e,n=this._getTargetPosition();if(n&&!i&&n.equals(r))return;this._targetHost=null,this._target=r,this._targetBoundingCenter=null,this.onMeshTargetChangedObservable.notifyObservers(null)}this.rebuildAnglesAndRadius()},i.prototype._getViewMatrix=function(){var t=Math.cos(this.alpha),i=Math.sin(this.alpha),r=Math.cos(this.beta),n=Math.sin(this.beta);0===n&&(n=1e-4);var o=this._getTargetPosition();if(o.addToRef(new e.Vector3(this.radius*t*n,this.radius*r,this.radius*i*n),this._newPosition),this.getScene().collisionsEnabled&&this.checkCollisions)this._collider||(this._collider=new e.Collider),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&&n<0&&(s=(s=s.clone()).negate()),this.getScene().useRightHandedSystem?e.Matrix.LookAtRHToRef(this.position,o,s,this._viewMatrix):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._currentTarget=o,this._viewMatrix},i.prototype.zoomOn=function(t,i){void 0===i&&(i=!1),t=t||this.getScene().meshes;var r=e.Mesh.MinMax(t),n=e.Vector3.Distance(r.min,r.max);this.radius=n*this.zoomOnFactor,this.focusOn({min:r.min,max:r.max,distance:n},i)},i.prototype.focusOn=function(t,i){void 0===i&&(i=!1);var r,n;if(void 0===t.min){var o=t||this.getScene().meshes;r=e.Mesh.MinMax(o),n=e.Vector3.Distance(r.min,r.max)}else{var s=t;r=s,n=s.distance}this._target=e.Mesh.Center(r),i||(this.maxZ=2*n)},i.prototype.createRigCamera=function(t,r){var n=0;switch(this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:n=this._cameraRigParams.stereoHalfAngle*(0===r?1:-1);break;case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:n=this._cameraRigParams.stereoHalfAngle*(0===r?-1:1)}var o=new i(t,this.alpha+n,this.beta,this.radius,this._target,this.getScene());return o._cameraRigParams={},o},i.prototype._updateRigCameras=function(){var i=this._rigCameras[0],r=this._rigCameras[1];switch(i.beta=r.beta=this.beta,i.radius=r.radius=this.radius,this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:i.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle,r.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle;break;case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:i.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle,r.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle}t.prototype._updateRigCameras.call(this)},i.prototype.dispose=function(){this.inputs.clear(),t.prototype.dispose.call(this)},i.prototype.getClassName=function(){return"ArcRotateCamera"},r([e.serialize()],i.prototype,"alpha",void 0),r([e.serialize()],i.prototype,"beta",void 0),r([e.serialize()],i.prototype,"radius",void 0),r([e.serializeAsVector3("target")],i.prototype,"_target",void 0),r([e.serialize()],i.prototype,"inertialAlphaOffset",void 0),r([e.serialize()],i.prototype,"inertialBetaOffset",void 0),r([e.serialize()],i.prototype,"inertialRadiusOffset",void 0),r([e.serialize()],i.prototype,"lowerAlphaLimit",void 0),r([e.serialize()],i.prototype,"upperAlphaLimit",void 0),r([e.serialize()],i.prototype,"lowerBetaLimit",void 0),r([e.serialize()],i.prototype,"upperBetaLimit",void 0),r([e.serialize()],i.prototype,"lowerRadiusLimit",void 0),r([e.serialize()],i.prototype,"upperRadiusLimit",void 0),r([e.serialize()],i.prototype,"inertialPanningX",void 0),r([e.serialize()],i.prototype,"inertialPanningY",void 0),r([e.serialize()],i.prototype,"pinchToPanMaxDistance",void 0),r([e.serialize()],i.prototype,"panningDistanceLimit",void 0),r([e.serializeAsVector3()],i.prototype,"panningOriginTarget",void 0),r([e.serialize()],i.prototype,"panningInertia",void 0),r([e.serialize()],i.prototype,"zoomOnFactor",void 0),r([e.serialize()],i.prototype,"allowUpsideDown",void 0),i}(e.TargetCamera);e.ArcRotateCamera=t}(s||(s={}));!function(e){var t=function(t){function i(e){return t.call(this,e)||this}return n(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}(s||(s={}));!function(e){var t=function(t){function i(i,r,n){var o=t.call(this,i,n)||this;return o.groundColor=new e.Color3(0,0,0),o.direction=r||e.Vector3.Up(),o}return n(i,t),i.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("vLightGround",3),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},i.prototype.getClassName=function(){return"HemisphericLight"},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){var r=e.Vector3.Normalize(this.direction);return this._uniformBuffer.updateFloat4("vLightData",r.x,r.y,r.z,0,i),this._uniformBuffer.updateColor3("vLightGround",this.groundColor.scale(this.intensity),i),this},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._worldMatrix},i.prototype.getTypeID=function(){return e.Light.LIGHTTYPEID_HEMISPHERICLIGHT},r([e.serializeAsColor3()],i.prototype,"groundColor",void 0),r([e.serializeAsVector3()],i.prototype,"direction",void 0),i}(e.Light);e.HemisphericLight=t}(s||(s={}));!function(e){var t=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e._needProjectionMatrixCompute=!0,e}return n(i,t),Object.defineProperty(i.prototype,"direction",{get:function(){return this._direction},set:function(e){this._direction=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"shadowMinZ",{get:function(){return this._shadowMinZ},set:function(e){this._shadowMinZ=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"shadowMaxZ",{get:function(){return this._shadowMaxZ},set:function(e){this._shadowMaxZ=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),i.prototype.computeTransformedInformation=function(){return!(!this.parent||!this.parent.getWorldMatrix)&&(this.transformedPosition||(this.transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),this.direction&&(this.transformedDirection||(this.transformedDirection=e.Vector3.Zero()),e.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this.transformedDirection)),!0)},i.prototype.getDepthScale=function(){return 50},i.prototype.getShadowDirection=function(e){return this.transformedDirection?this.transformedDirection:this.direction},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.getRotation=function(){this.direction.normalize();var t=e.Vector3.Cross(this.direction,e.Axis.Y),i=e.Vector3.Cross(t,this.direction);return e.Vector3.RotationFromAxis(t,i,this.direction)},i.prototype.needCube=function(){return!1},i.prototype.needProjectionMatrixCompute=function(){return this._needProjectionMatrixCompute},i.prototype.forceProjectionMatrixCompute=function(){this._needProjectionMatrixCompute=!0},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.getDepthMinZ=function(e){return void 0!==this.shadowMinZ?this.shadowMinZ:e.minZ},i.prototype.getDepthMaxZ=function(e){return void 0!==this.shadowMaxZ?this.shadowMaxZ:e.maxZ},i.prototype.setShadowProjectionMatrix=function(e,t,i){return this.customProjectionMatrixBuilder?this.customProjectionMatrixBuilder(t,i,e):this._setDefaultShadowProjectionMatrix(e,t,i),this},r([e.serializeAsVector3()],i.prototype,"position",void 0),r([e.serializeAsVector3()],i.prototype,"direction",null),r([e.serialize()],i.prototype,"shadowMinZ",null),r([e.serialize()],i.prototype,"shadowMaxZ",null),i}(e.Light);e.ShadowLight=t}(s||(s={}));!function(e){var t=function(t){function i(e,i,r){var n=t.call(this,e,r)||this;return n._shadowAngle=Math.PI/2,n.position=i,n}return n(i,t),Object.defineProperty(i.prototype,"shadowAngle",{get:function(){return this._shadowAngle},set:function(e){this._shadowAngle=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"direction",{get:function(){return this._direction},set:function(e){var t=this.needCube();this._direction=e,this.needCube()!==t&&this._shadowGenerator&&this._shadowGenerator.recreateShadowMap()},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"PointLight"},i.prototype.getTypeID=function(){return e.Light.LIGHTTYPEID_POINTLIGHT},i.prototype.needCube=function(){return!this.direction},i.prototype.getShadowDirection=function(i){if(this.direction)return t.prototype.getShadowDirection.call(this,i);switch(i){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._setDefaultShadowProjectionMatrix=function(t,i,r){var n=this.getScene().activeCamera;n&&e.Matrix.PerspectiveFovLHToRef(this.shadowAngle,1,this.getDepthMinZ(n),this.getDepthMaxZ(n),t)},i.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},i.prototype.transferToEffect=function(e,t){return this.computeTransformedInformation()?(this._uniformBuffer.updateFloat4("vLightData",this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,0,t),this):(this._uniformBuffer.updateFloat4("vLightData",this.position.x,this.position.y,this.position.z,0,t),this)},r([e.serialize()],i.prototype,"shadowAngle",null),i}(e.ShadowLight);e.PointLight=t}(s||(s={}));!function(e){var t=function(t){function i(e,i,r){var n=t.call(this,e,r)||this;return n._shadowFrustumSize=0,n._shadowOrthoScale=.5,n.autoUpdateExtends=!0,n._orthoLeft=Number.MAX_VALUE,n._orthoRight=Number.MIN_VALUE,n._orthoTop=Number.MIN_VALUE,n._orthoBottom=Number.MAX_VALUE,n.position=i.scale(-1),n.direction=i,n}return n(i,t),Object.defineProperty(i.prototype,"shadowFrustumSize",{get:function(){return this._shadowFrustumSize},set:function(e){this._shadowFrustumSize=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"shadowOrthoScale",{get:function(){return this._shadowOrthoScale},set:function(e){this._shadowOrthoScale=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"DirectionalLight"},i.prototype.getTypeID=function(){return e.Light.LIGHTTYPEID_DIRECTIONALLIGHT},i.prototype._setDefaultShadowProjectionMatrix=function(e,t,i){this.shadowFrustumSize>0?this._setDefaultFixedFrustumShadowProjectionMatrix(e,t):this._setDefaultAutoExtendShadowProjectionMatrix(e,t,i)},i.prototype._setDefaultFixedFrustumShadowProjectionMatrix=function(t,i){var r=this.getScene().activeCamera;r&&e.Matrix.OrthoLHToRef(this.shadowFrustumSize,this.shadowFrustumSize,void 0!==this.shadowMinZ?this.shadowMinZ:r.minZ,void 0!==this.shadowMaxZ?this.shadowMaxZ:r.maxZ,t)},i.prototype._setDefaultAutoExtendShadowProjectionMatrix=function(t,i,r){var n=this.getScene().activeCamera;if(n){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<r.length;s++){var a=r[s];if(a){var l=a.getBoundingInfo();if(l)for(var h=l.boundingBox,u=0;u<h.vectorsWorld.length;u++)e.Vector3.TransformCoordinatesToRef(h.vectorsWorld[u],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 c=this._orthoRight-this._orthoLeft,f=this._orthoTop-this._orthoBottom;e.Matrix.OrthoOffCenterLHToRef(this._orthoLeft-c*this.shadowOrthoScale,this._orthoRight+c*this.shadowOrthoScale,this._orthoBottom-f*this.shadowOrthoScale,this._orthoTop+f*this.shadowOrthoScale,void 0!==this.shadowMinZ?this.shadowMinZ:n.minZ,void 0!==this.shadowMaxZ?this.shadowMaxZ:n.maxZ,t)}},i.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},i.prototype.transferToEffect=function(e,t){return this.computeTransformedInformation()?(this._uniformBuffer.updateFloat4("vLightData",this.transformedDirection.x,this.transformedDirection.y,this.transformedDirection.z,1,t),this):(this._uniformBuffer.updateFloat4("vLightData",this.direction.x,this.direction.y,this.direction.z,1,t),this)},i.prototype.getDepthMinZ=function(e){return 1},i.prototype.getDepthMaxZ=function(e){return 1},r([e.serialize()],i.prototype,"shadowFrustumSize",null),r([e.serialize()],i.prototype,"shadowOrthoScale",null),r([e.serialize()],i.prototype,"autoUpdateExtends",void 0),i}(e.ShadowLight);e.DirectionalLight=t}(s||(s={}));!function(e){var t=function(t){function i(e,i,r,n,o,s){var a=t.call(this,e,s)||this;return a.position=i,a.direction=r,a.angle=n,a.exponent=o,a}return n(i,t),Object.defineProperty(i.prototype,"angle",{get:function(){return this._angle},set:function(e){this._angle=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"shadowAngleScale",{get:function(){return this._shadowAngleScale},set:function(e){this._shadowAngleScale=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"SpotLight"},i.prototype.getTypeID=function(){return e.Light.LIGHTTYPEID_SPOTLIGHT},i.prototype._setDefaultShadowProjectionMatrix=function(t,i,r){var n=this.getScene().activeCamera;if(n){this._shadowAngleScale=this._shadowAngleScale||1;var o=this._shadowAngleScale*this._angle;e.Matrix.PerspectiveFovLHToRef(o,1,this.getDepthMinZ(n),this.getDepthMaxZ(n),t)}},i.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("vLightDirection",3),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},i.prototype.transferToEffect=function(t,i){var r;return this.computeTransformedInformation()?(this._uniformBuffer.updateFloat4("vLightData",this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,this.exponent,i),r=e.Vector3.Normalize(this.transformedDirection)):(this._uniformBuffer.updateFloat4("vLightData",this.position.x,this.position.y,this.position.z,this.exponent,i),r=e.Vector3.Normalize(this.direction)),this._uniformBuffer.updateFloat4("vLightDirection",r.x,r.y,r.z,Math.cos(.5*this.angle),i),this},r([e.serialize()],i.prototype,"angle",null),r([e.serialize()],i.prototype,"shadowAngleScale",null),r([e.serialize()],i.prototype,"exponent",void 0),i}(e.ShadowLight);e.SpotLight=t}(s||(s={}));!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(){return function(e,t,i){this.frame=e,this.action=t,this.onlyOnce=i,this.isDone=!1}}();e.AnimationEvent=i;var r=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.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=r;var n=function(){function i(e,t,r,n,o,s){this.name=e,this.targetProperty=t,this.framePerSecond=r,this.dataType=n,this.loopMode=o,this.enableBlending=s,this._runtimeAnimations=new Array,this._events=new Array,this.blendingSpeed=.01,this._ranges={},this.targetPropertyPath=t.split("."),this.dataType=n,this.loopMode=void 0===o?i.ANIMATIONLOOPMODE_CYCLE:o}return i._PrepareAnimation=function(t,r,n,o,s,a,l,h){var u=void 0;if(!isNaN(parseFloat(s))&&isFinite(s)?u=i.ANIMATIONTYPE_FLOAT:s instanceof e.Quaternion?u=i.ANIMATIONTYPE_QUATERNION:s instanceof e.Vector3?u=i.ANIMATIONTYPE_VECTOR3:s instanceof e.Vector2?u=i.ANIMATIONTYPE_VECTOR2:s instanceof e.Color3?u=i.ANIMATIONTYPE_COLOR3:s instanceof e.Size&&(u=i.ANIMATIONTYPE_SIZE),void 0==u)return null;var c=new i(t,r,n,u,l),f=[{frame:0,value:s},{frame:o,value:a}];return c.setKeys(f),void 0!==h&&c.setEasingFunction(h),c},i.CreateAnimation=function(t,i,r,n){var o=new e.Animation(t+"Animation",t,r,i,e.Animation.ANIMATIONLOOPMODE_CONSTANT);return o.setEasingFunction(n),o},i.CreateAndStartAnimation=function(e,t,r,n,o,s,a,l,h,u){var c=i._PrepareAnimation(e,r,n,o,s,a,l,h);return c?t.getScene().beginDirectAnimation(t,[c],0,o,1===c.loopMode,1,u):null},i.CreateMergeAndStartAnimation=function(e,t,r,n,o,s,a,l,h,u){var c=i._PrepareAnimation(e,r,n,o,s,a,l,h);return c?(t.animations.push(c),t.getScene().beginAnimation(t,0,o,1===c.loopMode,1,u)):null},i.TransitionTo=function(e,t,i,r,n,o,s,a){if(void 0===a&&(a=null),s<=0)return i[e]=t,a&&a(),null;var l=n*(s/1e3);o.setKeys([{frame:0,value:i[e].clone?i[e].clone():i[e]},{frame:l,value:t}]),i.animations||(i.animations=[]),i.animations.push(o);var h=r.beginAnimation(i,0,l,!1);return h.onAnimationEnd=a,h},Object.defineProperty(i.prototype,"runtimeAnimations",{get:function(){return this._runtimeAnimations},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"hasRunningRuntimeAnimations",{get:function(){for(var e=0,t=this._runtimeAnimations;e<t.length;e++)if(!t[e].isStopped)return!0;return!1},enumerable:!0,configurable:!0}),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 r in this._ranges)i&&(t+=", ",i=!1),t+=r;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.getEvents=function(){return this._events},i.prototype.createRange=function(e,i,r){this._ranges[e]||(this._ranges[e]=new t(e,i,r))},i.prototype.deleteRange=function(e,t){void 0===t&&(t=!0);var i=this._ranges[e];if(i){if(t)for(var r=i.from,n=i.to,o=this._keys.length-1;o>=0;o--)this._keys[o].frame>=r&&this._keys[o].frame<=n&&this._keys.splice(o,1);this._ranges[e]=null}},i.prototype.getRange=function(e){return this._ranges[e]},i.prototype.getKeys=function(){return this._keys},i.prototype.getHighestFrame=function(){for(var e=0,t=0,i=this._keys.length;t<i;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(t,i,r){return e.Scalar.Lerp(t,i,r)},i.prototype.floatInterpolateFunctionWithTangents=function(t,i,r,n,o){return e.Scalar.Hermite(t,i,r,n,o)},i.prototype.quaternionInterpolateFunction=function(t,i,r){return e.Quaternion.Slerp(t,i,r)},i.prototype.quaternionInterpolateFunctionWithTangents=function(t,i,r,n,o){return e.Quaternion.Hermite(t,i,r,n,o).normalize()},i.prototype.vector3InterpolateFunction=function(t,i,r){return e.Vector3.Lerp(t,i,r)},i.prototype.vector3InterpolateFunctionWithTangents=function(t,i,r,n,o){return e.Vector3.Hermite(t,i,r,n,o)},i.prototype.vector2InterpolateFunction=function(t,i,r){return e.Vector2.Lerp(t,i,r)},i.prototype.vector2InterpolateFunctionWithTangents=function(t,i,r,n,o){return e.Vector2.Hermite(t,i,r,n,o)},i.prototype.sizeInterpolateFunction=function(t,i,r){return e.Size.Lerp(t,i,r)},i.prototype.color3InterpolateFunction=function(t,i,r){return e.Color3.Lerp(t,i,r)},i.prototype.matrixInterpolateFunction=function(t,i,r){return e.Matrix.Lerp(t,i,r)},i.prototype.clone=function(){var e=new i(this.name,this.targetPropertyPath.join("."),this.framePerSecond,this.dataType,this.loopMode);if(e.enableBlending=this.enableBlending,e.blendingSpeed=this.blendingSpeed,this._keys&&e.setKeys(this._keys),this._ranges){e._ranges={};for(var t in this._ranges){var r=this._ranges[t];r&&(e._ranges[t]=r.clone())}}return e},i.prototype.setKeys=function(e){this._keys=e.slice(0)},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,e.enableBlending=this.enableBlending,e.blendingSpeed=this.blendingSpeed;var t=this.dataType;e.keys=[];for(var r=this.getKeys(),n=0;n<r.length;n++){var o=r[n],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 l=this._ranges[a];if(l){var h={};h.name=a,h.from=l.from,h.to=l.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_SIZE",{get:function(){return i._ANIMATIONTYPE_SIZE},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){var r,n,o=new i(t.name,t.property,t.framePerSecond,t.dataType,t.loopBehavior),s=t.dataType,a=[];for(t.enableBlending&&(o.enableBlending=t.enableBlending),t.blendingSpeed&&(o.blendingSpeed=t.blendingSpeed),n=0;n<t.keys.length;n++){var l,h,u=t.keys[n];switch(s){case i.ANIMATIONTYPE_FLOAT:r=u.values[0],u.values.length>=1&&(l=u.values[1]),u.values.length>=2&&(h=u.values[2]);break;case i.ANIMATIONTYPE_QUATERNION:if(r=e.Quaternion.FromArray(u.values),u.values.length>=8){var c=e.Quaternion.FromArray(u.values.slice(4,8));c.equals(e.Quaternion.Zero())||(l=c)}if(u.values.length>=12){var f=e.Quaternion.FromArray(u.values.slice(8,12));f.equals(e.Quaternion.Zero())||(h=f)}break;case i.ANIMATIONTYPE_MATRIX:r=e.Matrix.FromArray(u.values);break;case i.ANIMATIONTYPE_COLOR3:r=e.Color3.FromArray(u.values);break;case i.ANIMATIONTYPE_VECTOR3:default:r=e.Vector3.FromArray(u.values)}var p={};p.frame=u.frame,p.value=r,void 0!=l&&(p.inTangent=l),void 0!=h&&(p.outTangent=h),a.push(p)}if(o.setKeys(a),t.ranges)for(n=0;n<t.ranges.length;n++)r=t.ranges[n],o.createRange(r.name,r.from,r.to);return o},i.AppendSerializedAnimations=function(e,t){if(e.animations){t.animations=[];for(var i=0;i<e.animations.length;i++){var r=e.animations[i];t.animations.push(r.serialize())}}},i.AllowMatricesInterpolation=!1,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._ANIMATIONTYPE_SIZE=6,i._ANIMATIONLOOPMODE_RELATIVE=0,i._ANIMATIONLOOPMODE_CYCLE=1,i._ANIMATIONLOOPMODE_CONSTANT=2,i}();e.Animation=n}(s||(s={}));!function(e){var t=function(){function t(e,t){this._offsetsCache={},this._highLimitsCache={},this._stopped=!1,this._blendingFactor=0,this._ratioOffset=0,this._animation=t,this._target=e,t._runtimeAnimations.push(this)}return Object.defineProperty(t.prototype,"animation",{get:function(){return this._animation},enumerable:!0,configurable:!0}),t.prototype.reset=function(){this._offsetsCache={},this._highLimitsCache={},this.currentFrame=0,this._blendingFactor=0,this._originalBlendValue=null},t.prototype.isStopped=function(){return this._stopped},t.prototype.dispose=function(){var e=this._animation.runtimeAnimations.indexOf(this);e>-1&&this._animation.runtimeAnimations.splice(e,1)},t.prototype._getKeyValue=function(e){return"function"==typeof e?e():e},t.prototype._interpolate=function(t,i,r,n,o){if(r===e.Animation.ANIMATIONLOOPMODE_CONSTANT&&i>0)return o.clone?o.clone():o;this.currentFrame=t;var s=this._animation.getKeys(),a=Math.max(0,Math.min(s.length-1,Math.floor(s.length*(t-s[0].frame)/(s[s.length-1].frame-s[0].frame))-1));if(s[a].frame>=t)for(;a-1>=0&&s[a].frame>=t;)a--;for(var l=a;l<s.length;l++){var h=s[l+1];if(h.frame>=t){var u=s[l],c=this._getKeyValue(u.value),f=this._getKeyValue(h.value),p=void 0!==u.outTangent&&void 0!==h.inTangent,d=h.frame-u.frame,m=(t-u.frame)/d,g=this._animation.getEasingFunction();switch(null!=g&&(m=g.ease(m)),this._animation.dataType){case e.Animation.ANIMATIONTYPE_FLOAT:var v=p?this._animation.floatInterpolateFunctionWithTangents(c,u.outTangent*d,f,h.inTangent*d,m):this._animation.floatInterpolateFunction(c,f,m);switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return v;case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return n*i+v}break;case e.Animation.ANIMATIONTYPE_QUATERNION:var _=p?this._animation.quaternionInterpolateFunctionWithTangents(c,u.outTangent.scale(d),f,h.inTangent.scale(d),m):this._animation.quaternionInterpolateFunction(c,f,m);switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return _;case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return _.add(n.scale(i))}return _;case e.Animation.ANIMATIONTYPE_VECTOR3:var y=p?this._animation.vector3InterpolateFunctionWithTangents(c,u.outTangent.scale(d),f,h.inTangent.scale(d),m):this._animation.vector3InterpolateFunction(c,f,m);switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return y;case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return y.add(n.scale(i))}case e.Animation.ANIMATIONTYPE_VECTOR2:var x=p?this._animation.vector2InterpolateFunctionWithTangents(c,u.outTangent.scale(d),f,h.inTangent.scale(d),m):this._animation.vector2InterpolateFunction(c,f,m);switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return x;case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return x.add(n.scale(i))}case e.Animation.ANIMATIONTYPE_SIZE:switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return this._animation.sizeInterpolateFunction(c,f,m);case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return this._animation.sizeInterpolateFunction(c,f,m).add(n.scale(i))}case e.Animation.ANIMATIONTYPE_COLOR3:switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return this._animation.color3InterpolateFunction(c,f,m);case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return this._animation.color3InterpolateFunction(c,f,m).add(n.scale(i))}case e.Animation.ANIMATIONTYPE_MATRIX:switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:if(e.Animation.AllowMatricesInterpolation)return this._animation.matrixInterpolateFunction(c,f,m);case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return c}}break}}return this._getKeyValue(s[s.length-1].value)},t.prototype.setValue=function(t,i){void 0===i&&(i=!1);var r,n,o=this._animation.targetPropertyPath;if(o.length>1){for(var s=this._target[o[0]],a=1;a<o.length-1;a++)s=s[o[a]];r=o[o.length-1],n=s}else r=o[0],n=this._target;this._animation.enableBlending&&this._blendingFactor<=1?(this._originalBlendValue||(n[r].clone?this._originalBlendValue=n[r].clone():this._originalBlendValue=n[r]),this._originalBlendValue.prototype?this._originalBlendValue.prototype.Lerp?n[r]=this._originalBlendValue.construtor.prototype.Lerp(t,this._originalBlendValue,this._blendingFactor):n[r]=t:this._originalBlendValue.m?n[r]=e.Matrix.Lerp(this._originalBlendValue,t,this._blendingFactor):n[r]=this._originalBlendValue*(1-this._blendingFactor)+this._blendingFactor*t,this._blendingFactor+=this._animation.blendingSpeed):n[r]=t,this._target.markAsDirty&&this._target.markAsDirty(this._animation.targetProperty)},t.prototype.goToFrame=function(e){var t=this._animation.getKeys();e<t[0].frame?e=t[0].frame:e>t[t.length-1].frame&&(e=t[t.length-1].frame);var i=this._interpolate(e,0,this._animation.loopMode);this.setValue(i)},t.prototype._prepareForSpeedRatioChange=function(e){var t=this._previousDelay*(this._animation.framePerSecond*e)/1e3;this._ratioOffset=this._previousRatio-t},t.prototype.animate=function(t,i,r,n,o,s){void 0===s&&(s=!1);var a=this._animation.targetPropertyPath;if(!a||a.length<1)return this._stopped=!0,!1;var l=!0,h=this._animation.getKeys();if(0!==h[0].frame){var u={frame:0,value:h[0].value};h.splice(0,0,u)}(i<h[0].frame||i>h[h.length-1].frame)&&(i=h[0].frame),(r<h[0].frame||r>h[h.length-1].frame)&&(r=h[h.length-1].frame),i===r&&(i>h[0].frame?i--:r<h[h.length-1].frame&&r++);var c,f=r-i,p=t*(this._animation.framePerSecond*o)/1e3+this._ratioOffset,d=0;if(this._previousDelay=t,this._previousRatio=p,(r>i&&p>f||i>r&&p<f)&&!n)l=!1,d=this._getKeyValue(h[h.length-1].value);else if(this._animation.loopMode!==e.Animation.ANIMATIONLOOPMODE_CYCLE){var m=r.toString()+i.toString();if(!this._offsetsCache[m]){var g=this._interpolate(i,0,e.Animation.ANIMATIONLOOPMODE_CYCLE),v=this._interpolate(r,0,e.Animation.ANIMATIONLOOPMODE_CYCLE);switch(this._animation.dataType){case e.Animation.ANIMATIONTYPE_FLOAT:this._offsetsCache[m]=v-g;break;case e.Animation.ANIMATIONTYPE_QUATERNION:this._offsetsCache[m]=v.subtract(g);break;case e.Animation.ANIMATIONTYPE_VECTOR3:this._offsetsCache[m]=v.subtract(g);case e.Animation.ANIMATIONTYPE_VECTOR2:this._offsetsCache[m]=v.subtract(g);case e.Animation.ANIMATIONTYPE_SIZE:this._offsetsCache[m]=v.subtract(g);case e.Animation.ANIMATIONTYPE_COLOR3:this._offsetsCache[m]=v.subtract(g)}this._highLimitsCache[m]=v}d=this._highLimitsCache[m],c=this._offsetsCache[m]}if(void 0===c)switch(this._animation.dataType){case e.Animation.ANIMATIONTYPE_FLOAT:c=0;break;case e.Animation.ANIMATIONTYPE_QUATERNION:c=new e.Quaternion(0,0,0,0);break;case e.Animation.ANIMATIONTYPE_VECTOR3:c=e.Vector3.Zero();break;case e.Animation.ANIMATIONTYPE_VECTOR2:c=e.Vector2.Zero();break;case e.Animation.ANIMATIONTYPE_SIZE:c=e.Size.Zero();break;case e.Animation.ANIMATIONTYPE_COLOR3:c=e.Color3.Black()}var _=p/f>>0,y=l?i+p%f:r,x=this._interpolate(y,_,this._animation.loopMode,c,d);this.setValue(x);for(var b=this._animation.getEvents(),T=0;T<b.length;T++)if(f>0&&y>=b[T].frame&&b[T].frame>=i||f<0&&y<=b[T].frame&&b[T].frame<=i){var E=b[T];E.isDone||(E.onlyOnce&&(b.splice(T,1),T--),E.isDone=!0,E.action())}else b[T].isDone&&!b[T].onlyOnce&&(b[T].isDone=!1);return l||(this._stopped=!0),l},t}();e.RuntimeAnimation=t}(s||(s={}));!function(e){var t=function(){function t(e,t,i,r,n,o,s,a){void 0===i&&(i=0),void 0===r&&(r=100),void 0===n&&(n=!1),void 0===o&&(o=1),this.target=t,this.fromFrame=i,this.toFrame=r,this.loopAnimation=n,this.onAnimationEnd=s,this._localDelayOffset=null,this._pausedDelay=null,this._runtimeAnimations=new Array,this._paused=!1,this._speedRatio=1,this.animationStarted=!1,a&&this.appendAnimations(t,a),this._speedRatio=o,this._scene=e,e._activeAnimatables.push(this)}return Object.defineProperty(t.prototype,"speedRatio",{get:function(){return this._speedRatio},set:function(e){for(var t=0;t<this._runtimeAnimations.length;t++)this._runtimeAnimations[t]._prepareForSpeedRatioChange(e);this._speedRatio=e},enumerable:!0,configurable:!0}),t.prototype.getAnimations=function(){return this._runtimeAnimations},t.prototype.appendAnimations=function(t,i){for(var r=0;r<i.length;r++){var n=i[r];this._runtimeAnimations.push(new e.RuntimeAnimation(t,n))}},t.prototype.getAnimationByTargetProperty=function(e){for(var t=this._runtimeAnimations,i=0;i<t.length;i++)if(t[i].animation.targetProperty===e)return t[i].animation;return null},t.prototype.getRuntimeAnimationByTargetProperty=function(e){for(var t=this._runtimeAnimations,i=0;i<t.length;i++)if(t[i].animation.targetProperty===e)return t[i];return null},t.prototype.reset=function(){for(var e=this._runtimeAnimations,t=0;t<e.length;t++)e[t].reset();this._localDelayOffset=null,this._pausedDelay=null},t.prototype.enableBlending=function(e){for(var t=this._runtimeAnimations,i=0;i<t.length;i++)t[i].animation.enableBlending=!0,t[i].animation.blendingSpeed=e},t.prototype.disableBlending=function(){for(var e=this._runtimeAnimations,t=0;t<e.length;t++)e[t].animation.enableBlending=!1},t.prototype.goToFrame=function(e){var t=this._runtimeAnimations;if(t[0]){var i=t[0].animation.framePerSecond,r=1e3*(e-t[0].currentFrame)/i;null===this._localDelayOffset&&(this._localDelayOffset=0),this._localDelayOffset-=r}for(var n=0;n<t.length;n++)t[n].goToFrame(e)},t.prototype.pause=function(){this._paused||(this._paused=!0)},t.prototype.restart=function(){this._paused=!1},t.prototype.stop=function(e){if(e){var t=this._scene._activeAnimatables.indexOf(this);if(t>-1){for(r=(i=this._runtimeAnimations).length-1;r>=0;r--)"string"==typeof e&&i[r].animation.name!=e||(i[r].dispose(),i.splice(r,1));0==i.length&&(this._scene._activeAnimatables.splice(t,1),this.onAnimationEnd&&this.onAnimationEnd())}}else if((r=this._scene._activeAnimatables.indexOf(this))>-1){this._scene._activeAnimatables.splice(r,1);for(var i=this._runtimeAnimations,r=0;r<i.length;r++)i[r].dispose();this.onAnimationEnd&&this.onAnimationEnd()}},t.prototype._animate=function(e){if(this._paused)return this.animationStarted=!1,null===this._pausedDelay&&(this._pausedDelay=e),!0;null===this._localDelayOffset?this._localDelayOffset=e:null!==this._pausedDelay&&(this._localDelayOffset+=e-this._pausedDelay,this._pausedDelay=null);var t,i=!1,r=this._runtimeAnimations;for(t=0;t<r.length;t++){var n=r[t].animate(e-this._localDelayOffset,this.fromFrame,this.toFrame,this.loopAnimation,this._speedRatio);i=i||n}if(this.animationStarted=i,!i)for(t=this._scene._activeAnimatables.indexOf(this),this._scene._activeAnimatables.splice(t,1),t=0;t<r.length;t++)r[t].dispose();return!i&&this.onAnimationEnd&&(this.onAnimationEnd(),this.onAnimationEnd=null),i},t}();e.Animatable=t}(s||(s={}));!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(){return null!==e&&e.apply(this,arguments)||this}return n(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 r=function(e){function t(t){void 0===t&&(t=1);var i=e.call(this)||this;return i.amplitude=t,i}return n(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=r;var o=function(e){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=2);var r=e.call(this)||this;return r.bounces=t,r.bounciness=i,r}return n(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.bounces),i=this.bounciness;i<=1&&(i=1.001);var r=Math.pow(i,t),n=1-i,o=(1-r)/n+.5*r,s=e*o,a=Math.log(-s*(1-i)+1)/Math.log(i),l=Math.floor(a),h=l+1,u=(1-Math.pow(i,l))/(n*o),c=.5*(u+(1-Math.pow(i,h))/(n*o)),f=e-c,p=c-u;return-Math.pow(1/i,t-l)/(p*p)*(f-p)*(f+p)},t}(t);e.BounceEase=o;var s=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.easeInCore=function(e){return e*e*e},t}(t);e.CubicEase=s;var a=function(e){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=3);var r=e.call(this)||this;return r.oscillations=t,r.springiness=i,r}return n(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.oscillations),i=Math.max(0,this.springiness);return(0==i?e:(Math.exp(i*e)-1)/(Math.exp(i)-1))*Math.sin((6.283185307179586*t+1.5707963267948966)*e)},t}(t);e.ElasticEase=a;var l=function(e){function t(t){void 0===t&&(t=2);var i=e.call(this)||this;return i.exponent=t,i}return n(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=l;var h=function(e){function t(t){void 0===t&&(t=2);var i=e.call(this)||this;return i.power=t,i}return n(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 u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.easeInCore=function(e){return e*e},t}(t);e.QuadraticEase=u;var c=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.easeInCore=function(e){return e*e*e*e},t}(t);e.QuarticEase=c;var f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.easeInCore=function(e){return e*e*e*e*e},t}(t);e.QuinticEase=f;var p=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.easeInCore=function(e){return 1-Math.sin(1.5707963267948966*(1-e))},t}(t);e.SineEase=p;var d=function(t){function i(e,i,r,n){void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=1),void 0===n&&(n=1);var o=t.call(this)||this;return o.x1=e,o.y1=i,o.x2=r,o.y2=n,o}return n(i,t),i.prototype.easeInCore=function(t){return e.BezierCurve.interpolate(t,this.x1,this.y1,this.x2,this.y2)},i}(t);e.BezierCurveEase=d}(s||(s={}));!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.prototype.serialize=function(){},e.prototype._serialize=function(e){return{type:2,children:[],name:e.name,properties:e.properties}},e}();e.Condition=t;var i=function(t){function i(e,r,n,o,s){void 0===s&&(s=i.IsEqual);var a=t.call(this,e)||this;return a.propertyPath=n,a.value=o,a.operator=s,a._target=r,a._effectiveTarget=a._getEffectiveTarget(r,a.propertyPath),a._property=a._getProperty(a.propertyPath),a}return n(i,t),Object.defineProperty(i,"IsEqual",{get:function(){return i._IsEqual},enumerable:!0,configurable:!0}),Object.defineProperty(i,"IsDifferent",{get:function(){return i._IsDifferent},enumerable:!0,configurable:!0}),Object.defineProperty(i,"IsGreater",{get:function(){return i._IsGreater},enumerable:!0,configurable:!0}),Object.defineProperty(i,"IsLesser",{get:function(){return i._IsLesser},enumerable:!0,configurable:!0}),i.prototype.isValid=function(){switch(this.operator){case i.IsGreater:return this._effectiveTarget[this._property]>this.value;case i.IsLesser:return this._effectiveTarget[this._property]<this.value;case i.IsEqual:case i.IsDifferent:var e;return e=this.value.equals?this.value.equals(this._effectiveTarget[this._property]):this.value===this._effectiveTarget[this._property],this.operator===i.IsEqual?e:!e}return!1},i.prototype.serialize=function(){return this._serialize({name:"ValueCondition",properties:[e.Action._GetTargetProperty(this._target),{name:"propertyPath",value:this.propertyPath},{name:"value",value:e.Action._SerializeValueAsString(this.value)},{name:"operator",value:i.GetOperatorName(this.operator)}]})},i.GetOperatorName=function(e){switch(e){case i._IsEqual:return"IsEqual";case i._IsDifferent:return"IsDifferent";case i._IsGreater:return"IsGreater";case i._IsLesser:return"IsLesser";default:return""}},i._IsEqual=0,i._IsDifferent=1,i._IsGreater=2,i._IsLesser=3,i}(t);e.ValueCondition=i;var r=function(e){function t(t,i){var r=e.call(this,t)||this;return r.predicate=i,r}return n(t,e),t.prototype.isValid=function(){return this.predicate()},t}(t);e.PredicateCondition=r;var o=function(t){function i(e,i,r){var n=t.call(this,e)||this;return n.value=r,n._target=i,n}return n(i,t),i.prototype.isValid=function(){return this._target.state===this.value},i.prototype.serialize=function(){return this._serialize({name:"StateCondition",properties:[e.Action._GetTargetProperty(this._target),{name:"value",value:this.value}]})},i}(t);e.StateCondition=o}(s||(s={}));!function(e){var t=function(){function t(t,i){this.triggerOptions=t,this.onBeforeExecuteObservable=new e.Observable,t.parameter?(this.trigger=t.trigger,this._triggerParameter=t.parameter):this.trigger=t,this._nextActiveAction=this,this._condition=i}return t.prototype._prepare=function(){},t.prototype.getTriggerParameter=function(){return this._triggerParameter},t.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.onBeforeExecuteObservable.notifyObservers(this),this._nextActiveAction.execute(e),this.skipToNextActiveAction()},t.prototype.execute=function(e){},t.prototype.skipToNextActiveAction=function(){this._nextActiveAction._child?(this._nextActiveAction._child._actionManager||(this._nextActiveAction._child._actionManager=this._actionManager),this._nextActiveAction=this._nextActiveAction._child):this._nextActiveAction=this},t.prototype.then=function(e){return this._child=e,e._actionManager=this._actionManager,e._prepare(),e},t.prototype._getProperty=function(e){return this._actionManager._getProperty(e)},t.prototype._getEffectiveTarget=function(e,t){return this._actionManager._getEffectiveTarget(e,t)},t.prototype.serialize=function(e){},t.prototype._serialize=function(e,t){var i={type:1,children:[],name:e.name,properties:e.properties||[]};if(this._child&&this._child.serialize(i),this._condition){var r=this._condition.serialize();return r.children.push(i),t&&t.children.push(r),r}return t&&t.children.push(i),i},t._SerializeValueAsString=function(t){return"number"==typeof t?t.toString():"boolean"==typeof t?t?"true":"false":t instanceof e.Vector2?t.x+", "+t.y:t instanceof e.Vector3?t.x+", "+t.y+", "+t.z:t instanceof e.Color3?t.r+", "+t.g+", "+t.b:t instanceof e.Color4?t.r+", "+t.g+", "+t.b+", "+t.a:t},t._GetTargetProperty=function(t){return{name:"target",targetType:t instanceof e.Mesh?"MeshProperties":t instanceof e.Light?"LightProperties":t instanceof e.Camera?"CameraProperties":"SceneProperties",value:t instanceof e.Scene?"Scene":t.name}},t}();e.Action=t}(s||(s={}));!function(e){var t=function(){function e(e,t,i,r,n,o){this.source=e,this.pointerX=t,this.pointerY=i,this.meshUnderPointer=r,this.sourceEvent=n,this.additionalData=o}return e.CreateNew=function(t,i,r){var n=t.getScene();return new e(t,n.pointerX,n.pointerY,n.meshUnderPointer,i,r)},e.CreateNewFromSprite=function(t,i,r,n){return new e(t,i.pointerX,i.pointerY,i.meshUnderPointer,r,n)},e.CreateNewFromScene=function(t,i){return new e(null,t.pointerX,t.pointerY,t.meshUnderPointer,i)},e.CreateNewFromPrimitive=function(t,i,r,n){return new e(t,i.x,i.y,null,r,n)},e}();e.ActionEvent=t;var i=function(){function t(e){this.actions=new Array,this.hoverCursor="",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,"OnDoublePickTrigger",{get:function(){return t._OnDoublePickTrigger},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(){for(var e=this._scene._actionManagers.indexOf(this),i=0;i<this.actions.length;i++){var r=this.actions[i];t.Triggers[r.trigger]--,0===t.Triggers[r.trigger]&&delete t.Triggers[r.trigger]}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++)if(this.actions[t].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}),Object.defineProperty(t,"HasTriggers",{get:function(){for(var e in t.Triggers)if(t.Triggers.hasOwnProperty(e))return!0;return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t,"HasPickTriggers",{get:function(){for(var e in t.Triggers)if(t.Triggers.hasOwnProperty(e)){var i=parseInt(e);if(i>=t._OnPickTrigger&&i<=t._OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),t.HasSpecificTrigger=function(e){for(var i in t.Triggers)if(t.Triggers.hasOwnProperty(i)&&parseInt(i)===e)return!0;return!1},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),t.Triggers[i.trigger]?t.Triggers[i.trigger]++:t.Triggers[i.trigger]=1,i._actionManager=this,i._prepare(),i)},t.prototype.processTrigger=function(e,i){for(var r=0;r<this.actions.length;r++){var n=this.actions[r];if(n.trigger===e){if(i&&(e===t.OnKeyUpTrigger||e===t.OnKeyDownTrigger)){var o=n.getTriggerParameter();if(o&&o!==i.sourceEvent.keyCode){if(!o.toLowerCase)continue;var s=o.toLowerCase();if(s!==i.sourceEvent.key){var a=i.sourceEvent.charCode?i.sourceEvent.charCode:i.sourceEvent.keyCode;if(String.fromCharCode(a).toLowerCase()!==s)continue}}}n._executeCurrent(i)}}},t.prototype._getEffectiveTarget=function(e,t){for(var i=t.split("."),r=0;r<i.length-1;r++)e=e[i[r]];return e},t.prototype._getProperty=function(e){var t=e.split(".");return t[t.length-1]},t.prototype.serialize=function(i){for(var r={children:new Array,name:i,type:3,properties:new Array},n=0;n<this.actions.length;n++){var o={type:0,children:new Array,name:t.GetTriggerName(this.actions[n].trigger),properties:new Array},s=this.actions[n].triggerOptions;if(s&&"number"!=typeof s)if(s.parameter instanceof e.Node)o.properties.push(e.Action._GetTargetProperty(s.parameter));else{var a={};e.Tools.DeepCopy(s.parameter,a,["mesh"]),s.parameter.mesh&&(a._meshId=s.parameter.mesh.id),o.properties.push({name:"parameter",targetType:null,value:a})}this.actions[n].serialize(o),r.children.push(o)}return r},t.Parse=function(i,r,n){var o=new e.ActionManager(n);null===r?n.actionManager=o:r.actionManager=o;for(var s=function(t,i){var r=Object.create(e.Tools.Instantiate("BABYLON."+t).prototype);return r.constructor.apply(r,i),r},a=function(t,i,r,n){if(null===n){var o=parseFloat(i);return"true"===i||"false"===i?"true"===i:isNaN(o)?i:o}for(var s=n.split("."),a=i.split(","),l=0;l<s.length;l++)r=r[s[l]];if("boolean"==typeof r)return"true"===a[0];if("string"==typeof r)return a[0];for(var h=new Array,l=0;l<a.length;l++)h.push(parseFloat(a[l]));return r instanceof e.Vector3?e.Vector3.FromArray(h):r instanceof e.Vector4?e.Vector4.FromArray(h):r instanceof e.Color3?e.Color3.FromArray(h):r instanceof e.Color4?e.Color4.FromArray(h):parseFloat(a[0])},l=function(i,r,h,u,c){if(void 0===c&&(c=null),!i.detached){var f=new Array,p=null,d=null,m=i.combine&&i.combine.length>0;if(2===i.type?f.push(o):f.push(r),m){for(var g=new Array,v=0;v<i.combine.length;v++)l(i.combine[v],t.NothingTrigger,h,u,g);f.push(g)}else for(A=0;A<i.properties.length;A++){var _=i.properties[A].value,y=i.properties[A].name,x=i.properties[A].targetType;"target"===y?_=p=null!==x&&"SceneProperties"===x?n:n.getNodeByName(_):"parent"===y?_=n.getNodeByName(_):"sound"===y?_=n.getSoundByName(_):"propertyPath"!==y?_=2===i.type&&"operator"===y?e.ValueCondition[_]:a(0,_,p,"value"===y?d:null):d=_,f.push(_)}if(null===c?f.push(h):f.push(null),"InterpolateValueAction"===i.name){var b=f[f.length-2];f[f.length-1]=b,f[f.length-2]=h}var T=s(i.name,f);if(T instanceof e.Condition&&null!==h){var E=new e.DoNothingAction(r,h);u?u.then(E):o.registerAction(E),u=E}null===c?T instanceof e.Condition?(h=T,T=u):(h=null,u?u.then(T):o.registerAction(T)):c.push(T);for(var A=0;A<i.children.length;A++)l(i.children[A],r,h,T,null)}},h=0;h<i.children.length;h++){var u,c=i.children[h];if(c.properties.length>0){var f=c.properties[0].value,p=null===c.properties[0].targetType?f:n.getMeshByName(f);p._meshId&&(p.mesh=n.getMeshByID(p._meshId)),u={trigger:t[c.name],parameter:p}}else u=t[c.name];for(var d=0;d<c.children.length;d++)c.detached||l(c.children[d],u,null,null)}},t.GetTriggerName=function(e){switch(e){case 0:return"NothingTrigger";case 1:return"OnPickTrigger";case 2:return"OnLeftPickTrigger";case 3:return"OnRightPickTrigger";case 4:return"OnCenterPickTrigger";case 5:return"OnPickDownTrigger";case 6:return"OnPickUpTrigger";case 7:return"OnLongPressTrigger";case 8:return"OnPointerOverTrigger";case 9:return"OnPointerOutTrigger";case 10:return"OnEveryFrameTrigger";case 11:return"OnIntersectionEnterTrigger";case 12:return"OnIntersectionExitTrigger";case 13:return"OnKeyDownTrigger";case 14:return"OnKeyUpTrigger";case 15:return"OnPickOutTrigger";default:return""}},t._NothingTrigger=0,t._OnPickTrigger=1,t._OnLeftPickTrigger=2,t._OnRightPickTrigger=3,t._OnCenterPickTrigger=4,t._OnPickDownTrigger=5,t._OnDoublePickTrigger=6,t._OnPickUpTrigger=7,t._OnLongPressTrigger=8,t._OnPointerOverTrigger=9,t._OnPointerOutTrigger=10,t._OnEveryFrameTrigger=11,t._OnIntersectionEnterTrigger=12,t._OnIntersectionExitTrigger=13,t._OnKeyDownTrigger=14,t._OnKeyUpTrigger=15,t._OnPickOutTrigger=16,t.Triggers={},t}();e.ActionManager=i}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l,h){void 0===s&&(s=1e3);var u=t.call(this,i,a)||this;return u.propertyPath=n,u.value=o,u.duration=s,u.stopOtherAnimations=l,u.onInterpolationDone=h,u.onInterpolationDoneObservable=new e.Observable,u._target=u._effectiveTarget=r,u}return n(i,t),i.prototype._prepare=function(){this._effectiveTarget=this._getEffectiveTarget(this._effectiveTarget,this.propertyPath),this._property=this._getProperty(this.propertyPath)},i.prototype.execute=function(){var t,i=this,r=this._actionManager.getScene(),n=[{frame:0,value:this._effectiveTarget[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 o=new e.Animation("InterpolateValueAction",this._property,1e3/this.duration*100,t,e.Animation.ANIMATIONLOOPMODE_CONSTANT);o.setKeys(n),this.stopOtherAnimations&&r.stopAnimation(this._effectiveTarget);r.beginDirectAnimation(this._effectiveTarget,[o],0,100,!1,1,function(){i.onInterpolationDoneObservable.notifyObservers(i),i.onInterpolationDone&&i.onInterpolationDone()})},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"InterpolateValueAction",properties:[e.Action._GetTargetProperty(this._target),{name:"propertyPath",value:this.propertyPath},{name:"value",value:e.Action._SerializeValueAsString(this.value)},{name:"duration",value:e.Action._SerializeValueAsString(this.duration)},{name:"stopOtherAnimations",value:e.Action._SerializeValueAsString(this.stopOtherAnimations)||!1}]},i)},i}(e.Action);e.InterpolateValueAction=t}(s||(s={}));!function(e){var t=function(t){function i(e,i,r,n){var o=t.call(this,e,n)||this;return o.propertyPath=r,o._target=o._effectiveTarget=i,o}return n(i,t),i.prototype._prepare=function(){this._effectiveTarget=this._getEffectiveTarget(this._effectiveTarget,this.propertyPath),this._property=this._getProperty(this.propertyPath)},i.prototype.execute=function(){this._effectiveTarget[this._property]=!this._effectiveTarget[this._property]},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"SwitchBooleanAction",properties:[e.Action._GetTargetProperty(this._target),{name:"propertyPath",value:this.propertyPath}]},i)},i}(e.Action);e.SwitchBooleanAction=t;var i=function(t){function i(e,i,r,n){var o=t.call(this,e,n)||this;return o.value=r,o._target=i,o}return n(i,t),i.prototype.execute=function(){this._target.state=this.value},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"SetStateAction",properties:[e.Action._GetTargetProperty(this._target),{name:"value",value:this.value}]},i)},i}(e.Action);e.SetStateAction=i;var r=function(t){function i(e,i,r,n,o){var s=t.call(this,e,o)||this;return s.propertyPath=r,s.value=n,s._target=s._effectiveTarget=i,s}return n(i,t),i.prototype._prepare=function(){this._effectiveTarget=this._getEffectiveTarget(this._effectiveTarget,this.propertyPath),this._property=this._getProperty(this.propertyPath)},i.prototype.execute=function(){this._effectiveTarget[this._property]=this.value,this._target.markAsDirty&&this._target.markAsDirty(this._property)},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"SetValueAction",properties:[e.Action._GetTargetProperty(this._target),{name:"propertyPath",value:this.propertyPath},{name:"value",value:e.Action._SerializeValueAsString(this.value)}]},i)},i}(e.Action);e.SetValueAction=r;var o=function(t){function i(e,i,r,n,o){var s=t.call(this,e,o)||this;return s.propertyPath=r,s.value=n,s._target=s._effectiveTarget=i,s}return n(i,t),i.prototype._prepare=function(){this._effectiveTarget=this._getEffectiveTarget(this._effectiveTarget,this.propertyPath),this._property=this._getProperty(this.propertyPath),"number"!=typeof this._effectiveTarget[this._property]&&e.Tools.Warn("Warning: IncrementValueAction can only be used with number values")},i.prototype.execute=function(){this._effectiveTarget[this._property]+=this.value,this._target.markAsDirty&&this._target.markAsDirty(this._property)},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"IncrementValueAction",properties:[e.Action._GetTargetProperty(this._target),{name:"propertyPath",value:this.propertyPath},{name:"value",value:e.Action._SerializeValueAsString(this.value)}]},i)},i}(e.Action);e.IncrementValueAction=o;var s=function(t){function i(e,i,r,n,o,s){var a=t.call(this,e,s)||this;return a.from=r,a.to=n,a.loop=o,a._target=i,a}return n(i,t),i.prototype._prepare=function(){},i.prototype.execute=function(){this._actionManager.getScene().beginAnimation(this._target,this.from,this.to,this.loop)},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"PlayAnimationAction",properties:[e.Action._GetTargetProperty(this._target),{name:"from",value:String(this.from)},{name:"to",value:String(this.to)},{name:"loop",value:e.Action._SerializeValueAsString(this.loop)||!1}]},i)},i}(e.Action);e.PlayAnimationAction=s;var a=function(t){function i(e,i,r){var n=t.call(this,e,r)||this;return n._target=i,n}return n(i,t),i.prototype._prepare=function(){},i.prototype.execute=function(){this._actionManager.getScene().stopAnimation(this._target)},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"StopAnimationAction",properties:[e.Action._GetTargetProperty(this._target)]},i)},i}(e.Action);e.StopAnimationAction=a;var l=function(t){function i(i,r){return void 0===i&&(i=e.ActionManager.NothingTrigger),t.call(this,i,r)||this}return n(i,t),i.prototype.execute=function(){},i.prototype.serialize=function(e){return t.prototype._serialize.call(this,{name:"DoNothingAction",properties:[]},e)},i}(e.Action);e.DoNothingAction=l;var h=function(e){function t(t,i,r){var n=e.call(this,t,r)||this;return n.children=i,n}return n(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.prototype.serialize=function(t){for(var i=e.prototype._serialize.call(this,{name:"CombineAction",properties:[],combine:[]},t),r=0;r<this.children.length;r++)i.combine.push(this.children[r].serialize(null));return i},t}(e.Action);e.CombineAction=h;var u=function(e){function t(t,i,r){var n=e.call(this,t,r)||this;return n.func=i,n}return n(t,e),t.prototype.execute=function(e){this.func(e)},t}(e.Action);e.ExecuteCodeAction=u;var c=function(t){function i(e,i,r,n){var o=t.call(this,e,n)||this;return o._target=i,o._parent=r,o}return n(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.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"SetParentAction",properties:[e.Action._GetTargetProperty(this._target),e.Action._GetTargetProperty(this._parent)]},i)},i}(e.Action);e.SetParentAction=c;var f=function(e){function t(t,i,r){var n=e.call(this,t,r)||this;return n._sound=i,n}return n(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){void 0!==this._sound&&this._sound.play()},t.prototype.serialize=function(t){return e.prototype._serialize.call(this,{name:"PlaySoundAction",properties:[{name:"sound",value:this._sound.name}]},t)},t}(e.Action);e.PlaySoundAction=f;var p=function(e){function t(t,i,r){var n=e.call(this,t,r)||this;return n._sound=i,n}return n(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){void 0!==this._sound&&this._sound.stop()},t.prototype.serialize=function(t){return e.prototype._serialize.call(this,{name:"StopSoundAction",properties:[{name:"sound",value:this._sound.name}]},t)},t}(e.Action);e.StopSoundAction=p}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n,o,s,a){if(void 0===s&&(s=.01),void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE),this.name=t,this.sprites=new Array,this.renderingGroupId=0,this.layerMask=268435455,this.fogEnabled=!0,this.isPickable=!1,this.onDisposeObservable=new e.Observable,this._vertexBuffers={},this._capacity=r,this._spriteTexture=new e.Texture(i,o,!0,!1,a),this._spriteTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._spriteTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,n.width&&n.height)this.cellWidth=n.width,this.cellHeight=n.height;else{if(void 0===n)return;this.cellWidth=n,this.cellHeight=n}this._epsilon=s,this._scene=o,this._scene.spriteManagers.push(this);for(var l=[],h=0,u=0;u<r;u++)l.push(h),l.push(h+1),l.push(h+2),l.push(h),l.push(h+2),l.push(h+3),h+=4;this._indexBuffer=o.getEngine().createIndexBuffer(l),this._vertexData=new Float32Array(16*r*4),this._buffer=new e.Buffer(o.getEngine(),this._vertexData,!0,16);var c=this._buffer.createVertexBuffer(e.VertexBuffer.PositionKind,0,4),f=this._buffer.createVertexBuffer("options",4,4),p=this._buffer.createVertexBuffer("cellInfo",8,4),d=this._buffer.createVertexBuffer(e.VertexBuffer.ColorKind,12,4);this._vertexBuffers[e.VertexBuffer.PositionKind]=c,this._vertexBuffers.options=f,this._vertexBuffers.cellInfo=p,this._vertexBuffers[e.VertexBuffer.ColorKind]=d,this._effectBase=this._scene.getEngine().createEffect("sprites",[e.VertexBuffer.PositionKind,"options","cellInfo",e.VertexBuffer.ColorKind],["view","projection","textureInfos","alphaTest"],["diffuseSampler"],""),this._effectFog=this._scene.getEngine().createEffect("sprites",[e.VertexBuffer.PositionKind,"options","cellInfo",e.VertexBuffer.ColorKind],["view","projection","textureInfos","alphaTest","vFogInfos","vFogColor"],["diffuseSampler"],"#define FOG")}return Object.defineProperty(t.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),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,r,n){var o=16*e;0===i?i=this._epsilon:1===i&&(i=1-this._epsilon),0===r?r=this._epsilon:1===r&&(r=1-this._epsilon),this._vertexData[o]=t.position.x,this._vertexData[o+1]=t.position.y,this._vertexData[o+2]=t.position.z,this._vertexData[o+3]=t.angle,this._vertexData[o+4]=t.width,this._vertexData[o+5]=t.height,this._vertexData[o+6]=i,this._vertexData[o+7]=r,this._vertexData[o+8]=t.invertU?1:0,this._vertexData[o+9]=t.invertV?1:0;var s=t.cellIndex/n>>0;this._vertexData[o+10]=t.cellIndex-s*n,this._vertexData[o+11]=s,this._vertexData[o+12]=t.color.r,this._vertexData[o+13]=t.color.g,this._vertexData[o+14]=t.color.b,this._vertexData[o+15]=t.color.a},t.prototype.intersects=function(t,i,r,n){for(var o=Math.min(this._capacity,this.sprites.length),s=e.Vector3.Zero(),a=e.Vector3.Zero(),l=Number.MAX_VALUE,h=null,u=e.Vector3.Zero(),c=i.getViewMatrix(),f=0;f<o;f++){var p=this.sprites[f];if(p){if(r){if(!r(p))continue}else if(!p.isPickable)continue;if(e.Vector3.TransformCoordinatesToRef(p.position,c,u),s.copyFromFloats(u.x-p.width/2,u.y-p.height/2,u.z),a.copyFromFloats(u.x+p.width/2,u.y+p.height/2,u.z),t.intersectsBoxMinMax(s,a)){var d=e.Vector3.Distance(u,t.origin);if(l>d&&(l=d,h=p,n))break}}}if(h){var m=new e.PickingInfo;return m.hit=!0,m.pickedSprite=h,m.distance=l,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(),r=t.getDeltaTime(),n=Math.min(this._capacity,this.sprites.length),o=i.width/this.cellWidth,s=0,a=0;a<n;a++){var l=this.sprites[a];l&&(l._animate(r),this._appendSpriteVertex(s++,l,0,0,o),this._appendSpriteVertex(s++,l,1,0,o),this._appendSpriteVertex(s++,l,1,1,o),this._appendSpriteVertex(s++,l,0,1,o))}this._buffer.update(this._vertexData);var h=this._effectBase;this._scene.fogEnabled&&this._scene.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(h=this._effectFog),t.enableEffect(h);var u=this._scene.getViewMatrix();h.setTexture("diffuseSampler",this._spriteTexture),h.setMatrix("view",u),h.setMatrix("projection",this._scene.getProjectionMatrix()),h.setFloat2("textureInfos",this.cellWidth/i.width,this.cellHeight/i.height),this._scene.fogEnabled&&this._scene.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(h.setFloat4("vFogInfos",this._scene.fogMode,this._scene.fogStart,this._scene.fogEnd,this._scene.fogDensity),h.setColor3("vFogColor",this._scene.fogColor)),t.bindBuffers(this._vertexBuffers,this._indexBuffer,h),t.setDepthFunctionToLessOrEqual(),h.setBool("alphaTest",!0),t.setColorWrite(!1),t.draw(!0,0,6*n),t.setColorWrite(!0),h.setBool("alphaTest",!1),t.setAlphaMode(e.Engine.ALPHA_COMBINE),t.draw(!0,0,6*n),t.setAlphaMode(e.Engine.ALPHA_DISABLE)}},t.prototype.dispose=function(){this._buffer&&(this._buffer.dispose(),this._buffer=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.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},t}();e.SpriteManager=t}(s||(s={}));!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._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,r,n){this._fromIndex=e,this._toIndex=t,this._loopAnimation=i,this._delay=r,this._animationStarted=!0,this._direction=e<t?1:-1,this.cellIndex=e,this._time=0,this._onAnimationEnd=n},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.cellIndex=this._toIndex,this._animationStarted=!1,this._onAnimationEnd&&this._onAnimationEnd(),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}(s||(s={}));!function(e){var t=function(){return function(e,t,i){this.bu=e,this.bv=t,this.distance=i,this.faceId=0,this.subMeshId=0}}();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 r=this.pickedMesh.getIndices();if(!r)return null;var n;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]),l=e.Vector3.FromArray(o,3*r[3*this.faceId+2]);s=s.scale(this.bu),a=a.scale(this.bv),l=l.scale(1-this.bu-this.bv),n=new e.Vector3(s.x+a.x+l.x,s.y+a.y+l.y,s.z+a.z+l.z)}else{var h=this.pickedMesh.getVerticesData(e.VertexBuffer.PositionKind),u=e.Vector3.FromArray(h,3*r[3*this.faceId]),c=e.Vector3.FromArray(h,3*r[3*this.faceId+1]),f=e.Vector3.FromArray(h,3*r[3*this.faceId+2]),p=u.subtract(c),d=f.subtract(c);n=e.Vector3.Cross(p,d)}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();if(!t)return null;var i=this.pickedMesh.getVerticesData(e.VertexBuffer.UVKind);if(!i)return null;var r=e.Vector2.FromArray(i,2*t[3*this.faceId]),n=e.Vector2.FromArray(i,2*t[3*this.faceId+1]),o=e.Vector2.FromArray(i,2*t[3*this.faceId+2]);return r=r.scale(1-this.bu-this.bv),n=n.scale(this.bu),o=o.scale(this.bv),new e.Vector2(r.x+n.x+o.x,r.y+n.y+o.y)},t}();e.PickingInfo=i}(s||(s={}));!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,r,n,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,r=(e.x-this.origin.x)*i,(n=(t.x-this.origin.x)*i)===-1/0&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,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,r=(e.y-this.origin.y)*i,(n=(t.y-this.origin.y)*i)===-1/0&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,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,r=(e.z-this.origin.z)*i,(n=(t.z-this.origin.z)*i)===-1/0&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,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,r=e.center.z-this.origin.z,n=t*t+i*i+r*r,o=e.radius*e.radius;if(n<=o)return!0;var s=t*this.direction.x+i*this.direction.y+r*this.direction.z;return!(s<0)&&n-s*s<=o},t.prototype.intersectsTriangle=function(t,i,r){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),r.subtractToRef(t,this._edge2),e.Vector3.CrossToRef(this.direction,this._edge2,this._pvec);var n=e.Vector3.Dot(this._edge1,this._pvec);if(0===n)return null;var o=1/n;this.origin.subtractToRef(t,this._tvec);var s=e.Vector3.Dot(this._tvec,this._pvec)*o;if(s<0||s>1)return null;e.Vector3.CrossToRef(this._tvec,this._edge1,this._qvec);var a=e.Vector3.Dot(this.direction,this._qvec)*o;if(a<0||s+a>1)return null;var l=e.Vector3.Dot(this._edge2,this._qvec)*o;return l>this.length?null:new e.IntersectionInfo(s,a,l)},t.prototype.intersectsPlane=function(t){var i,r=e.Vector3.Dot(t.normal,this.direction);if(Math.abs(r)<9.99999997475243e-7)return null;var n=e.Vector3.Dot(t.normal,this.origin);return(i=(-t.d-n)/r)<0?i<-9.99999997475243e-7?null:0:i},t.prototype.intersectsMesh=function(i,r){var n=e.Tmp.Matrix[0];return i.getWorldMatrix().invertToRef(n),this._tmpRay?t.TransformToRef(this,n,this._tmpRay):this._tmpRay=t.Transform(this,n),i.intersects(this._tmpRay,r)},t.prototype.intersectsMeshes=function(e,t,i){i?i.length=0:i=[];for(var r=0;r<e.length;r++){var n=this.intersectsMesh(e[r],t);n.hit&&i.push(n)}return i.sort(this._comparePickingInfo),i},t.prototype._comparePickingInfo=function(e,t){return e.distance<t.distance?-1:e.distance>t.distance?1:0},t.prototype.intersectionSegment=function(i,r,n){var o,s,a,l,h=this.origin.add(this.direction.multiplyByFloats(t.rayl,t.rayl,t.rayl)),u=r.subtract(i),c=h.subtract(this.origin),f=i.subtract(this.origin),p=e.Vector3.Dot(u,u),d=e.Vector3.Dot(u,c),m=e.Vector3.Dot(c,c),g=e.Vector3.Dot(u,f),v=e.Vector3.Dot(c,f),_=p*m-d*d,y=_,x=_;_<t.smallnum?(s=0,y=1,l=v,x=m):(l=p*v-d*g,(s=d*v-m*g)<0?(s=0,l=v,x=m):s>y&&(s=y,l=v+d,x=m)),l<0?(l=0,-g<0?s=0:-g>p?s=y:(s=-g,y=p)):l>x&&(l=x,-g+d<0?s=0:-g+d>p?s=y:(s=-g+d,y=p)),o=Math.abs(s)<t.smallnum?0:s/y,a=Math.abs(l)<t.smallnum?0:l/x;var b=c.multiplyByFloats(a,a,a),T=f.add(u.multiplyByFloats(o,o,o)).subtract(b);return a>0&&a<=this.length&&T.lengthSquared()<n*n?b.length():-1},t.CreateNew=function(i,r,n,o,s,a,l){var h=e.Vector3.Unproject(new e.Vector3(i,r,0),n,o,s,a,l),u=e.Vector3.Unproject(new e.Vector3(i,r,1),n,o,s,a,l).subtract(h);return u.normalize(),new t(h,u)},t.CreateNewFromTo=function(i,r,n){void 0===n&&(n=e.Matrix.Identity());var o=r.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),n)},t.Transform=function(i,r){var n=new t(new e.Vector3(0,0,0),new e.Vector3(0,0,0));return t.TransformToRef(i,r,n),n},t.TransformToRef=function(t,i,r){e.Vector3.TransformCoordinatesToRef(t.origin,i,r.origin),e.Vector3.TransformNormalToRef(t.direction,i,r.direction),r.length=t.length;var n=r.direction,o=n.length();if(0!==o&&1!==o){var s=1/o;n.x*=s,n.y*=s,n.z*=s,r.length*=o}},t.smallnum=1e-8,t.rayl=1e9,t}();e.Ray=t}(s||(s={}));!function(e){var t=function(e,t,i,r){return!(e.x>i.x+r)&&(!(i.x-r>t.x)&&(!(e.y>i.y+r)&&(!(i.y-r>t.y)&&(!(e.z>i.z+r)&&!(i.z-r>t.z)))))},i=function(){var e={root:0,found:!1};return function(t,i,r,n){e.root=0,e.found=!1;var o=i*i-4*t*r;if(o<0)return e;var s=Math.sqrt(o),a=(-i-s)/(2*t),l=(-i+s)/(2*t);if(a>l){var h=l;l=a,a=h}return a>0&&a<n?(e.root=a,e.found=!0,e):l>0&&l<n?(e.root=l,e.found=!0,e):e}}(),r=function(){function r(){this.radius=e.Vector3.One(),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(),this._collisionMask=-1}return Object.defineProperty(r.prototype,"collisionMask",{get:function(){return this._collisionMask},set:function(e){this._collisionMask=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),r.prototype._initialize=function(t,i,r){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=r,this.collisionFound=!1},r.prototype._checkPointInTriangle=function(t,i,r,n,o){i.subtractToRef(t,this._tempVector),r.subtractToRef(t,this._tempVector2),e.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var s=e.Vector3.Dot(this._tempVector4,o);return!(s<0)&&(n.subtractToRef(t,this._tempVector3),e.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),!((s=e.Vector3.Dot(this._tempVector4,o))<0)&&(e.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),(s=e.Vector3.Dot(this._tempVector4,o))>=0))},r.prototype._canDoCollision=function(i,r,n,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+r)&&!!t(n,o,this.basePointWorld,this.velocityWorldLength+a)},r.prototype._testTriangle=function(t,r,n,o,s,a){var l,h=!1;r||(r=[]),r[t]||(r[t]=new e.Plane(0,0,0,0),r[t].copyFromPoints(n,o,s));var u=r[t];if(a||u.isFrontFacingTo(this.normalizedVelocity,0)){var c=u.signedDistanceTo(this.basePoint),f=e.Vector3.Dot(u.normal,this.velocity);if(0==f){if(Math.abs(c)>=1)return;h=!0,l=0}else{var p=(1-c)/f;if((l=(-1-c)/f)>p){var d=p;p=l,l=d}if(l>1||p<0)return;l<0&&(l=0),l>1&&(l=1)}this._collisionPoint.copyFromFloats(0,0,0);var m=!1,g=1;if(h||(this.basePoint.subtractToRef(u.normal,this._planeIntersectionPoint),this.velocity.scaleToRef(l,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,n,o,s,u.normal)&&(m=!0,g=l,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!m){var v=this.velocity.lengthSquared(),_=v;this.basePoint.subtractToRef(n,this._tempVector);var y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=i(_,y,x,g);b.found&&(g=b.root,m=!0,this._collisionPoint.copyFrom(n)),this.basePoint.subtractToRef(o,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,(b=i(_,y,x,g)).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(_,y,x,g)).found&&(g=b.root,m=!0,this._collisionPoint.copyFrom(s)),o.subtractToRef(n,this._edge),n.subtractToRef(this.basePoint,this._baseToVertex);var T=this._edge.lengthSquared(),E=e.Vector3.Dot(this._edge,this.velocity),A=e.Vector3.Dot(this._edge,this._baseToVertex);if(_=T*-v+E*E,y=T*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*E*A,x=T*(1-this._baseToVertex.lengthSquared())+A*A,(b=i(_,y,x,g)).found){var P=(E*b.root-A)/T;P>=0&&P<=1&&(g=b.root,m=!0,this._edge.scaleInPlace(P),n.addToRef(this._edge,this._collisionPoint))}s.subtractToRef(o,this._edge),o.subtractToRef(this.basePoint,this._baseToVertex),T=this._edge.lengthSquared(),E=e.Vector3.Dot(this._edge,this.velocity),A=e.Vector3.Dot(this._edge,this._baseToVertex),_=T*-v+E*E,y=T*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*E*A,x=T*(1-this._baseToVertex.lengthSquared())+A*A,(b=i(_,y,x,g)).found&&(P=(E*b.root-A)/T)>=0&&P<=1&&(g=b.root,m=!0,this._edge.scaleInPlace(P),o.addToRef(this._edge,this._collisionPoint)),n.subtractToRef(s,this._edge),s.subtractToRef(this.basePoint,this._baseToVertex),T=this._edge.lengthSquared(),E=e.Vector3.Dot(this._edge,this.velocity),A=e.Vector3.Dot(this._edge,this._baseToVertex),_=T*-v+E*E,y=T*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*E*A,x=T*(1-this._baseToVertex.lengthSquared())+A*A,(b=i(_,y,x,g)).found&&(P=(E*b.root-A)/T)>=0&&P<=1&&(g=b.root,m=!0,this._edge.scaleInPlace(P),s.addToRef(this._edge,this._collisionPoint))}if(m){var S=g*this.velocity.length();(!this.collisionFound||S<this.nearestDistance)&&(this.intersectionPoint?this.intersectionPoint.copyFrom(this._collisionPoint):this.intersectionPoint=this._collisionPoint.clone(),this.nearestDistance=S,this.collisionFound=!0)}}},r.prototype._collide=function(e,t,i,r,n,o,s){for(var a=r;a<n;a+=3){var l=t[i[a]-o],h=t[i[a+1]-o],u=t[i[a+2]-o];this._testTriangle(a,e,u,h,l,s)}},r.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)},r}();e.Collider=r}(s||(s={}));!function(e){e.CollisionWorker="";var t;!function(e){e[e.INIT=0]="INIT",e[e.UPDATE=1]="UPDATE",e[e.COLLIDE=2]="COLLIDE"}(t=e.WorkerTaskType||(e.WorkerTaskType={}));var i;!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.UNKNOWN_ERROR=1]="UNKNOWN_ERROR"}(i=e.WorkerReplyType||(e.WorkerReplyType={}));var r=function(){function r(){var n=this;this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this.onMeshUpdated=function(e){n._addUpdateMeshesList[e.uniqueId]=r.SerializeMesh(e)},this.onGeometryUpdated=function(e){n._addUpdateGeometriesList[e.id]=r.SerializeGeometry(e)},this._afterRender=function(){if(n._init&&!(0==n._toRemoveGeometryArray.length&&0==n._toRemoveMeshesArray.length&&0==Object.keys(n._addUpdateGeometriesList).length&&0==Object.keys(n._addUpdateMeshesList).length||n._runningUpdated>4)){++n._runningUpdated;var e={updatedMeshes:n._addUpdateMeshesList,updatedGeometries:n._addUpdateGeometriesList,removedGeometries:n._toRemoveGeometryArray,removedMeshes:n._toRemoveMeshesArray},i={payload:e,taskType:t.UPDATE},r=[];for(var o in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(o)&&(r.push(i.payload.updatedGeometries[o].indices.buffer),r.push(i.payload.updatedGeometries[o].normals.buffer),r.push(i.payload.updatedGeometries[o].positions.buffer));n._worker.postMessage(i,r),n._addUpdateMeshesList={},n._addUpdateGeometriesList={},n._toRemoveGeometryArray=[],n._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(r){var o=r.data;if(o.error==i.SUCCESS)switch(o.taskType){case t.INIT:n._init=!0,n._scene.meshes.forEach(function(e){n.onMeshAdded(e)}),n._scene.getGeometries().forEach(function(e){n.onGeometryAdded(e)});break;case t.UPDATE:n._runningUpdated--;break;case t.COLLIDE:n._runningCollisionTask=!1;var s=o.payload;if(!n._collisionsCallbackArray[s.collisionId])return;var a=n._collisionsCallbackArray[s.collisionId];if(a){var l=n._scene.getMeshByUniqueID(s.collidedMeshUniqueId);l&&a(s.collisionId,e.Vector3.FromArray(s.newPosition),l)}n._collisionsCallbackArray[s.collisionId]=null}else e.Tools.Warn("error returned from worker!")},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,this._runningCollisionTask=!1,this._addUpdateMeshesList={},this._addUpdateGeometriesList={},this._toRemoveGeometryArray=[],this._toRemoveMeshesArray=[]}return r.prototype.getNewPosition=function(e,i,r,n,o,s,a){if(this._init&&!this._collisionsCallbackArray[a]&&!this._collisionsCallbackArray[a+1e5]){e.divideToRef(r.radius,this._scaledPosition),i.divideToRef(r.radius,this._scaledVelocity),this._collisionsCallbackArray[a]=s;var l={payload:{collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:r.radius.asArray()},collisionId:a,excludedMeshUniqueId:o?o.uniqueId:null,maximumRetry:n},taskType:t.COLLIDE};this._worker.postMessage(l)}},r.prototype.init=function(i){this._scene=i,this._scene.registerAfterRender(this._afterRender);var r=e.WorkerIncluded?e.Engine.CodeRepository+"Collisions/babylon.collisionWorker.js":URL.createObjectURL(new Blob([e.CollisionWorker],{type:"application/javascript"}));this._worker=new Worker(r),this._worker.onmessage=this._onMessageFromWorker;var n={payload:{},taskType:t.INIT};this._worker.postMessage(n)},r.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},r.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},r.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},r.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},r.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},r.SerializeMesh=function(t){var i=[];t.subMeshes&&(i=t.subMeshes.map(function(e,t){var i=e.getBoundingInfo();return{position:t,verticesStart:e.verticesStart,verticesCount:e.verticesCount,indexStart:e.indexStart,indexCount:e.indexCount,hasMaterial:!!e.getMaterial(),sphereCenter:i.boundingSphere.centerWorld.asArray(),sphereRadius:i.boundingSphere.radiusWorld,boxMinimum:i.boundingBox.minimumWorld.asArray(),boxMaximum:i.boundingBox.maximumWorld.asArray()}}));var r=null;if(t instanceof e.Mesh)r=(n=t.geometry)?n.id:null;else if(t instanceof e.InstancedMesh){var n=t.sourceMesh.geometry;r=n?n.id:null}var o=t.getBoundingInfo();return{uniqueId:t.uniqueId,id:t.id,name:t.name,geometryId:r,sphereCenter:o.boundingSphere.centerWorld.asArray(),sphereRadius:o.boundingSphere.radiusWorld,boxMinimum:o.boundingBox.minimumWorld.asArray(),boxMaximum:o.boundingBox.maximumWorld.asArray(),worldMatrixFromCache:t.worldMatrixFromCache.asArray(),subMeshes:i,checkCollisions:t.checkCollisions}},r.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 Uint32Array(t.getIndices()||[])}},r}();e.CollisionCoordinatorWorker=r;var n=function(){function t(){this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this._finalPosition=e.Vector3.Zero()}return t.prototype.getNewPosition=function(e,t,i,r,n,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,r,this._finalPosition,n),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,r,n,o,s){void 0===s&&(s=null);var a=10*e.Engine.CollisionsEpsilon;if(r.retry>=n)o.copyFrom(t);else{var l=s?s.collisionMask:r.collisionMask;r._initialize(t,i,a);for(var h=0;h<this._scene.meshes.length;h++){var u=this._scene.meshes[h];u.isEnabled()&&u.checkCollisions&&u.subMeshes&&u!==s&&0!=(l&u.collisionGroup)&&u._checkCollision(r)}r.collisionFound?(0===i.x&&0===i.y&&0===i.z||r._getResponse(t,i),i.length()<=a?o.copyFrom(t):(r.retry++,this._collideWithWorld(t,i,r,n,o,s))):t.addToRef(i,o)}},t}();e.CollisionCoordinatorLegacy=n}(s||(s={}));!function(e){var t=function(){function t(t){this.particleSystem=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,this._currentFrameCounter=0,this.cellIndex=0,this.particleSystem.isAnimationSheetEnabled&&(this.cellIndex=this.particleSystem.startSpriteCellID,0==this.particleSystem.spriteCellChangeSpeed?this.updateCellIndex=this.updateCellIndexWithSpeedCalculated:this.updateCellIndex=this.updateCellIndexWithCustomSpeed)}return t.prototype.updateCellIndexWithSpeedCalculated=function(e){var t=(this.lifeTime-this.age)/e/(this.particleSystem.endSpriteCellID+1-this.cellIndex);this._currentFrameCounter+=e,this._currentFrameCounter>=t*e&&(this._currentFrameCounter=0,this.cellIndex++,this.cellIndex>this.particleSystem.endSpriteCellID&&(this.cellIndex=this.particleSystem.endSpriteCellID))},t.prototype.updateCellIndexWithCustomSpeed=function(){this._currentFrameCounter>=this.particleSystem.spriteCellChangeSpeed?(this.cellIndex++,this._currentFrameCounter=0,this.cellIndex>this.particleSystem.endSpriteCellID&&(this.particleSystem.spriteCellLoop?this.cellIndex=this.particleSystem.startSpriteCellID:this.cellIndex=this.particleSystem.endSpriteCellID)):this._currentFrameCounter++},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,e.particleSystem=this.particleSystem,e.cellIndex=this.cellIndex},t}();e.Particle=t}(s||(s={}));!function(e){var t=function(e,t){return e===t?e:Math.random()*(t-e)+e},i=function(){function i(r,n,o,s,a,l){void 0===s&&(s=null),void 0===a&&(a=!1),void 0===l&&(l=.01);var h=this;this.name=r,this._isAnimationSheetEnabled=a,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.customShader=null,this.preventAutoStart=!1,this.onDisposeObservable=new e.Observable,this.onAnimationEnd=null,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._stockParticles=new Array,this._newPartsExcess=0,this._vertexBuffers={},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.startSpriteCellID=0,this.endSpriteCellID=0,this.spriteCellLoop=!0,this.spriteCellChangeSpeed=0,this.spriteCellWidth=0,this.spriteCellHeight=0,this._vertexBufferSize=11,this.appendParticleVertexes=null,this.id=r,this._capacity=n,this._epsilon=l,a&&(this._vertexBufferSize=12),this._scene=o||e.Engine.LastCreatedScene,this._customEffect=s,o.particleSystems.push(this),this._createIndexBuffer(),this._vertexData=new Float32Array(n*this._vertexBufferSize*4),this._vertexBuffer=new e.Buffer(o.getEngine(),this._vertexData,!0,this._vertexBufferSize);var u=this._vertexBuffer.createVertexBuffer(e.VertexBuffer.PositionKind,0,3),c=this._vertexBuffer.createVertexBuffer(e.VertexBuffer.ColorKind,3,4),f=this._vertexBuffer.createVertexBuffer("options",7,4);if(this._isAnimationSheetEnabled){var p=this._vertexBuffer.createVertexBuffer("cellIndex",11,1);this._vertexBuffers.cellIndex=p}this._vertexBuffers[e.VertexBuffer.PositionKind]=u,this._vertexBuffers[e.VertexBuffer.ColorKind]=c,this._vertexBuffers.options=f,this.startDirectionFunction=function(i,r,n,o){var s=t(h.direction1.x,h.direction2.x),a=t(h.direction1.y,h.direction2.y),l=t(h.direction1.z,h.direction2.z);e.Vector3.TransformNormalFromFloatsToRef(s*i,a*i,l*i,r,n)},this.startPositionFunction=function(i,r,n){var o=t(h.minEmitBox.x,h.maxEmitBox.x),s=t(h.minEmitBox.y,h.maxEmitBox.y),a=t(h.minEmitBox.z,h.maxEmitBox.z);e.Vector3.TransformCoordinatesFromFloatsToRef(o,s,a,i,r)},this.updateFunction=function(e){for(var t=0;t<e.length;t++){var i=e[t];i.age+=h._scaledUpdateSpeed,i.age>=i.lifeTime?(h.recycleParticle(i),t--):(i.colorStep.scaleToRef(h._scaledUpdateSpeed,h._scaledColorStep),i.color.addInPlace(h._scaledColorStep),i.color.a<0&&(i.color.a=0),i.angle+=i.angularSpeed*h._scaledUpdateSpeed,i.direction.scaleToRef(h._scaledUpdateSpeed,h._scaledDirection),i.position.addInPlace(h._scaledDirection),h.gravity.scaleToRef(h._scaledUpdateSpeed,h._scaledGravity),i.direction.addInPlace(h._scaledGravity),h._isAnimationSheetEnabled&&i.updateCellIndex(h._scaledUpdateSpeed))}}}return Object.defineProperty(i.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isAnimationSheetEnabled",{get:function(){return this._isAnimationSheetEnabled},enumerable:!0,configurable:!0}),i.prototype._createIndexBuffer=function(){for(var e=[],t=0,i=0;i<this._capacity;i++)e.push(t),e.push(t+1),e.push(t+2),e.push(t),e.push(t+2),e.push(t+3),t+=4;this._indexBuffer=this._scene.getEngine().createIndexBuffer(e)},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,r){var n=e*this._vertexBufferSize;this._vertexData[n]=t.position.x,this._vertexData[n+1]=t.position.y,this._vertexData[n+2]=t.position.z,this._vertexData[n+3]=t.color.r,this._vertexData[n+4]=t.color.g,this._vertexData[n+5]=t.color.b,this._vertexData[n+6]=t.color.a,this._vertexData[n+7]=t.angle,this._vertexData[n+8]=t.size,this._vertexData[n+9]=i,this._vertexData[n+10]=r},i.prototype._appendParticleVertexWithAnimation=function(e,t,i,r){0===i?i=this._epsilon:1===i&&(i=1-this._epsilon),0===r?r=this._epsilon:1===r&&(r=1-this._epsilon);var n=e*this._vertexBufferSize;this._vertexData[n]=t.position.x,this._vertexData[n+1]=t.position.y,this._vertexData[n+2]=t.position.z,this._vertexData[n+3]=t.color.r,this._vertexData[n+4]=t.color.g,this._vertexData[n+5]=t.color.b,this._vertexData[n+6]=t.color.a,this._vertexData[n+7]=t.angle,this._vertexData[n+8]=t.size,this._vertexData[n+9]=i,this._vertexData[n+10]=r,this._vertexData[n+11]=t.cellIndex},i.prototype._update=function(i){this._alive=this.particles.length>0,this.updateFunction(this.particles);var r;if(this.emitter.position)r=this.emitter.getWorldMatrix();else{var n=this.emitter;r=e.Matrix.Translation(n.x,n.y,n.z)}for(var o,s=0;s<i&&this.particles.length!==this._capacity;s++){0!==this._stockParticles.length?((o=this._stockParticles.pop()).age=0,o.cellIndex=this.startSpriteCellID):o=new e.Particle(this),this.particles.push(o);var a=t(this.minEmitPower,this.maxEmitPower);this.startDirectionFunction(a,r,o.direction,o),o.lifeTime=t(this.minLifeTime,this.maxLifeTime),o.size=t(this.minSize,this.maxSize),o.angularSpeed=t(this.minAngularSpeed,this.maxAngularSpeed),this.startPositionFunction(r,o.position,o);var l=t(0,1);e.Color4.LerpToRef(this.color1,this.color2,l,o.color),this.colorDead.subtractToRef(o.color,this._colorDiff),this._colorDiff.scaleToRef(1/o.lifeTime,o.colorStep)}},i.prototype._getEffect=function(){if(this._customEffect)return this._customEffect;var t=[];this._scene.clipPlane&&t.push("#define CLIPPLANE"),this._isAnimationSheetEnabled&&t.push("#define ANIMATESHEET");var i=t.join("\n");if(this._cachedDefines!==i){this._cachedDefines=i;var r,n;this._isAnimationSheetEnabled?(r=[e.VertexBuffer.PositionKind,e.VertexBuffer.ColorKind,"options","cellIndex"],n=["invView","view","projection","particlesInfos","vClipPlane","textureMask"]):(r=[e.VertexBuffer.PositionKind,e.VertexBuffer.ColorKind,"options"],n=["invView","view","projection","vClipPlane","textureMask"]),this._effect=this._scene.getEngine().createEffect("particles",r,n,["diffuseSampler"],i)}return 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.onAnimationEnd&&this.onAnimationEnd(),this.disposeOnStop&&this._scene._toBeDisposed.push(this))),this._isAnimationSheetEnabled?this.appendParticleVertexes=this.appenedParticleVertexesWithSheet:this.appendParticleVertexes=this.appenedParticleVertexesNoSheet;for(var i=0,r=0;r<this.particles.length;r++){var n=this.particles[r];this.appendParticleVertexes(i,n),i+=4}this._vertexBuffer&&this._vertexBuffer.update(this._vertexData)}}},i.prototype.appenedParticleVertexesWithSheet=function(e,t){this._appendParticleVertexWithAnimation(e++,t,0,0),this._appendParticleVertexWithAnimation(e++,t,1,0),this._appendParticleVertexWithAnimation(e++,t,1,1),this._appendParticleVertexWithAnimation(e++,t,0,1)},i.prototype.appenedParticleVertexesNoSheet=function(e,t){this._appendParticleVertex(e++,t,0,0),this._appendParticleVertex(e++,t,1,0),this._appendParticleVertex(e++,t,1,1),this._appendParticleVertex(e++,t,0,1)},i.prototype.rebuild=function(){this._createIndexBuffer(),this._vertexBuffer&&this._vertexBuffer._rebuild()},i.prototype.render=function(){var t=this._getEffect();if(!(this.emitter&&t.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this.particles.length))return 0;var r=this._scene.getEngine();r.enableEffect(t),r.setState(!1);var n=this._scene.getViewMatrix();if(t.setTexture("diffuseSampler",this.particleTexture),t.setMatrix("view",n),t.setMatrix("projection",this._scene.getProjectionMatrix()),this._isAnimationSheetEnabled){var o=this.particleTexture.getBaseSize();t.setFloat3("particlesInfos",this.spriteCellWidth/o.width,this.spriteCellHeight/o.height,o.width/this.spriteCellWidth)}if(t.setFloat4("textureMask",this.textureMask.r,this.textureMask.g,this.textureMask.b,this.textureMask.a),this._scene.clipPlane){var s=this._scene.clipPlane,a=n.clone();a.invert(),t.setMatrix("invView",a),t.setFloat4("vClipPlane",s.normal.x,s.normal.y,s.normal.z,s.d)}return r.bindBuffers(this._vertexBuffers,this._indexBuffer,t),this.blendMode===i.BLENDMODE_ONEONE?r.setAlphaMode(e.Engine.ALPHA_ONEONE):r.setAlphaMode(e.Engine.ALPHA_COMBINE),this.forceDepthWrite&&r.setDepthWrite(!0),r.draw(!0,0,6*this.particles.length),r.setAlphaMode(e.Engine.ALPHA_DISABLE),this.particles.length},i.prototype.dispose=function(){this._vertexBuffer&&(this._vertexBuffer.dispose(),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);e>-1&&this._scene.particleSystems.splice(e,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},i.prototype.clone=function(t,r){var n=null,o=null;if(null!=this.customShader){var s=(o=this.customShader).shaderOptions.defines.length>0?o.shaderOptions.defines.join("\n"):"";n=this._scene.getEngine().createEffectForParticles(o.shaderPath.fragmentElement,o.shaderOptions.uniforms,o.shaderOptions.samplers,s)}var a=new i(t,this._capacity,this._scene,n);return a.customShader=o,e.Tools.DeepCopy(this,a,["particles","customShader"]),void 0===r&&(r=this.emitter),a.emitter=r,this.particleTexture&&(a.particleTexture=new e.Texture(this.particleTexture.url,this._scene)),this.preventAutoStart||a.start(),a},i.prototype.serialize=function(){var t={};if(t.name=this.name,t.id=this.id,this.emitter.position){var i=this.emitter;t.emitterId=i.id}else{var r=this.emitter;t.emitter=r.asArray()}return 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.customShader=this.customShader,t.preventAutoStart=this.preventAutoStart,t},i.Parse=function(t,r,n){var o=t.name,s=null,a=null;if(t.customShader){var l=(a=t.customShader).shaderOptions.defines.length>0?a.shaderOptions.defines.join("\n"):"";s=r.getEngine().createEffectForParticles(a.shaderPath.fragmentElement,a.shaderOptions.uniforms,a.shaderOptions.samplers,l)}var h=new i(o,t.capacity,r,s);if(h.customShader=a,t.id&&(h.id=t.id),t.preventAutoStart&&(h.preventAutoStart=t.preventAutoStart),t.textureName&&(h.particleTexture=new e.Texture(n+t.textureName,r),h.particleTexture.name=t.textureName),t.emitterId?h.emitter=r.getLastMeshByID(t.emitterId):h.emitter=e.Vector3.FromArray(t.emitter),t.animations)for(var u=0;u<t.animations.length;u++){var c=t.animations[u];h.animations.push(e.Animation.Parse(c))}return t.autoAnimate&&r.beginAnimation(h,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,t.autoAnimateSpeed||1),h.minAngularSpeed=t.minAngularSpeed,h.maxAngularSpeed=t.maxAngularSpeed,h.minSize=t.minSize,h.maxSize=t.maxSize,h.minLifeTime=t.minLifeTime,h.maxLifeTime=t.maxLifeTime,h.minEmitPower=t.minEmitPower,h.maxEmitPower=t.maxEmitPower,h.emitRate=t.emitRate,h.minEmitBox=e.Vector3.FromArray(t.minEmitBox),h.maxEmitBox=e.Vector3.FromArray(t.maxEmitBox),h.gravity=e.Vector3.FromArray(t.gravity),h.direction1=e.Vector3.FromArray(t.direction1),h.direction2=e.Vector3.FromArray(t.direction2),h.color1=e.Color4.FromArray(t.color1),h.color2=e.Color4.FromArray(t.color2),h.colorDead=e.Color4.FromArray(t.colorDead),h.updateSpeed=t.updateSpeed,h.targetStopDuration=t.targetStopDuration,h.textureMask=e.Color4.FromArray(t.textureMask),h.blendMode=t.blendMode,h.preventAutoStart||h.start(),h},i.BLENDMODE_ONEONE=0,i.BLENDMODE_STANDARD=1,i}();e.ParticleSystem=i}(s||(s={}));!function(e){var t=function(){function t(t,i,r){this.name=t,this.emitter=null,this.renderingGroupId=0,this.layerMask=268435455,this._updateVertexBuffers={},this._renderVertexBuffers={},this._currentRenderId=-1,this._started=!0,this.onDisposeObservable=new e.Observable,this.id=t,this._scene=r||e.Engine.LastCreatedScene,this._capacity=i,this._engine=this._scene.getEngine(),this._scene.particleSystems.push(this),this._renderEffect=new e.Effect("gpuRenderParticles",["position","age","life","velocity"],[],[],this._scene.getEngine());this._updateEffect=new e.Effect("gpuUpdateParticles",{attributes:["position","age","life","velocity"],uniformsNames:[],uniformBuffersNames:[],samplers:[],defines:"",fallbacks:null,onCompiled:null,onError:null,indexParameters:null,maxSimultaneousLights:0,transformFeedbackVaryings:["outPosition","outAge","outLife","outVelocity"]},this._scene.getEngine())}return t.prototype.isStarted=function(){return this._started},t.prototype.start=function(){this._started=!0},t.prototype.stop=function(){this._started=!1},t.prototype.animate=function(){},t.prototype._initialize=function(){if(!this._renderVAO){for(var t=new Array,i=0;i<this._capacity;i++){t.push(0),t.push(0),t.push(0);var r=1+10*Math.random();t.push(r+1),t.push(r),t.push(0),t.push(0),t.push(0)}this._updateBuffer=new e.Buffer(this._scene.getEngine(),t,!1,0),this._updateVertexBuffers.position=this._updateBuffer.createVertexBuffer("position",0,3,3),this._updateVertexBuffers.age=this._updateBuffer.createVertexBuffer("age",3,1,1),this._updateVertexBuffers.life=this._updateBuffer.createVertexBuffer("life",4,1,1),this._updateVertexBuffers.velocity=this._updateBuffer.createVertexBuffer("velocity",5,3,3),this._updateVAO=this._engine.recordVertexArrayObject(this._updateVertexBuffers,null,this._updateEffect),this._engine.bindArrayBuffer(null),this._renderBuffer=new e.Buffer(this._scene.getEngine(),t,!1,0),this._renderVertexBuffers.position=this._renderBuffer.createVertexBuffer("position",0,3,3),this._renderVertexBuffers.age=this._renderBuffer.createVertexBuffer("age",3,1,1),this._renderVertexBuffers.life=this._renderBuffer.createVertexBuffer("life",4,1,1),this._renderVertexBuffers.velocity=this._renderBuffer.createVertexBuffer("velocity",5,3,3),this._renderVAO=this._engine.recordVertexArrayObject(this._renderVertexBuffers,null,this._renderEffect),this._engine.bindArrayBuffer(null),this._sourceVAO=this._updateVAO,this._targetVAO=this._renderVAO,this._sourceBuffer=this._updateBuffer,this._targetBuffer=this._renderBuffer}},t.prototype.render=function(){if(!this.emitter||!this._updateEffect.isReady()||!this._renderEffect.isReady())return 0;if(this._initialize(),this._currentRenderId===this._scene.getRenderId())return 0;this._currentRenderId=this._scene.getRenderId(),this._engine.enableEffect(this._updateEffect),this._engine.setState(!1),this._engine.bindVertexArrayObject(this._sourceVAO,null),this._engine.bindTransformFeedbackBuffer(this._targetBuffer.getBuffer()),this._engine.setRasterizerState(!1),this._engine.beginTransformFeedback(),this._engine.drawPointClouds(0,this._capacity),this._engine.endTransformFeedback(),this._engine.setRasterizerState(!0),this._engine.bindTransformFeedbackBuffer(null),this._engine.enableEffect(this._renderEffect),this._engine.bindVertexArrayObject(this._targetVAO,null),this._engine.drawPointClouds(0,this._capacity);var e=this._sourceVAO;this._sourceVAO=this._targetVAO,this._targetVAO=e;var t=this._sourceBuffer;return this._sourceBuffer=this._targetBuffer,this._targetBuffer=t,0},t.prototype.rebuild=function(){},t.prototype.dispose=function(){var e=this._scene.particleSystems.indexOf(this);e>-1&&this._scene.particleSystems.splice(e,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},t.prototype.clone=function(e,t){return null},t.prototype.serialize=function(){},t}();e.GPUParticleSystem=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n,o,s,a,l){void 0===l&&(l=null),this.idx=0,this.color=new e.Color4(1,1,1,1),this.position=e.Vector3.Zero(),this.rotation=e.Vector3.Zero(),this.scaling=e.Vector3.One(),this.uvs=new e.Vector4(0,0,1,1),this.velocity=e.Vector3.Zero(),this.pivot=e.Vector3.Zero(),this.alive=!0,this.isVisible=!0,this._pos=0,this._ind=0,this.shapeId=0,this.idxInShape=0,this._stillInvisible=!1,this.idx=t,this._pos=i,this._ind=r,this._model=n,this.shapeId=o,this.idxInShape=s,this._sps=a,l&&(this._modelBoundingInfo=l,this._boundingInfo=new e.BoundingInfo(l.minimum,l.maximum))}return Object.defineProperty(t.prototype,"scale",{get:function(){return this.scaling},set:function(e){this.scaling=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"quaternion",{get:function(){return this.rotationQuaternion},set:function(e){this.rotationQuaternion=e},enumerable:!0,configurable:!0}),t.prototype.intersectsMesh=function(t){return!(!this._boundingInfo||!t._boundingInfo)&&(this._sps._bSphereOnly?e.BoundingSphere.Intersects(this._boundingInfo.boundingSphere,t._boundingInfo.boundingSphere):this._boundingInfo.intersects(t._boundingInfo,!1))},t}();e.SolidParticle=t;var i=function(){return function(e,t,i,r,n,o){this._indicesLength=0,this.shapeID=e,this._shape=t,this._indicesLength=i,this._shapeUV=r,this._positionFunction=n,this._vertexFunction=o}}();e.ModelShape=i;var r=function(){return function(){this.ind=0,this.indicesLength=0,this.sqDistance=0}}();e.DepthSortedParticle=r}(s||(s={}));!function(e){var t=function(){function t(t,i,r){this.particles=new Array,this.nbParticles=0,this.billboard=!1,this.recomputeNormals=!0,this.counter=0,this.vars={},this._positions=new Array,this._indices=new Array,this._normals=new Array,this._colors=new Array,this._uvs=new Array,this._index=0,this._updatable=!0,this._pickable=!1,this._isVisibilityBoxLocked=!1,this._alwaysVisible=!1,this._depthSort=!1,this._shapeCounter=0,this._copy=new e.SolidParticle(0,0,0,null,0,0,this),this._color=new e.Color4(0,0,0,0),this._computeParticleColor=!0,this._computeParticleTexture=!0,this._computeParticleRotation=!0,this._computeParticleVertex=!1,this._computeBoundingBox=!1,this._depthSortParticles=!0,this._cam_axisZ=e.Vector3.Zero(),this._cam_axisY=e.Vector3.Zero(),this._cam_axisX=e.Vector3.Zero(),this._axisZ=e.Axis.Z,this._camDir=e.Vector3.Zero(),this._camInvertedPosition=e.Vector3.Zero(),this._rotMatrix=new e.Matrix,this._invertMatrix=new e.Matrix,this._rotated=e.Vector3.Zero(),this._quaternion=new e.Quaternion,this._vertex=e.Vector3.Zero(),this._normal=e.Vector3.Zero(),this._yaw=0,this._pitch=0,this._roll=0,this._halfroll=0,this._halfpitch=0,this._halfyaw=0,this._sinRoll=0,this._cosRoll=0,this._sinPitch=0,this._cosPitch=0,this._sinYaw=0,this._cosYaw=0,this._mustUnrotateFixedNormals=!1,this._minimum=e.Tmp.Vector3[0],this._maximum=e.Tmp.Vector3[1],this._minBbox=e.Tmp.Vector3[4],this._maxBbox=e.Tmp.Vector3[5],this._particlesIntersect=!1,this._depthSortFunction=function(e,t){return t.sqDistance-e.sqDistance},this._needs32Bits=!1,this._bSphereOnly=!1,this._bSphereRadiusFactor=1,this.name=t,this._scene=i||e.Engine.LastCreatedScene,this._camera=i.activeCamera,this._pickable=!!r&&r.isPickable,this._depthSort=!!r&&r.enableDepthSort,this._particlesIntersect=!!r&&r.particleIntersection,this._bSphereOnly=!!r&&r.boundingSphereOnly,this._bSphereRadiusFactor=r&&r.bSphereRadiusFactor?r.bSphereRadiusFactor:1,r&&r.updatable?this._updatable=r.updatable:this._updatable=!0,this._pickable&&(this.pickedParticles=[]),this._depthSort&&(this.depthSortedParticles=[])}return t.prototype.buildMesh=function(){if(0===this.nbParticles){var t=e.MeshBuilder.CreateDisc("",{radius:1,tessellation:3},this._scene);this.addShape(t,1),t.dispose()}this._indices32=this._needs32Bits?new Uint32Array(this._indices):new Uint16Array(this._indices),this._positions32=new Float32Array(this._positions),this._uvs32=new Float32Array(this._uvs),this._colors32=new Float32Array(this._colors),this.recomputeNormals&&e.VertexData.ComputeNormals(this._positions32,this._indices,this._normals),this._normals32=new Float32Array(this._normals),this._fixedNormal32=new Float32Array(this._normals),this._mustUnrotateFixedNormals&&this._unrotateFixedNormals();var i=new e.VertexData;i.indices=this._indices32,i.set(this._positions32,e.VertexBuffer.PositionKind),i.set(this._normals32,e.VertexBuffer.NormalKind),this._uvs32&&i.set(this._uvs32,e.VertexBuffer.UVKind),this._colors32&&i.set(this._colors32,e.VertexBuffer.ColorKind);var r=new e.Mesh(this.name,this._scene);return i.applyToMesh(r,this._updatable),this.mesh=r,this.mesh.isPickable=this._pickable,this._depthSort||(this._indices=null),this._positions=null,this._normals=null,this._uvs=null,this._colors=null,this._updatable||(this.particles.length=0),r},t.prototype.digest=function(t,i){var r=i&&i.facetNb||1,n=i&&i.number||0,o=i&&i.delta||0,s=t.getVerticesData(e.VertexBuffer.PositionKind),a=t.getIndices(),l=t.getVerticesData(e.VertexBuffer.UVKind),h=t.getVerticesData(e.VertexBuffer.ColorKind),u=t.getVerticesData(e.VertexBuffer.NormalKind),c=0,f=a.length/3;n?(n=n>f?f:n,r=Math.round(f/n),o=0):r=r>f?f:r;for(var p=[],d=[],m=[],g=[],v=e.Tmp.Vector3[0],_=r;c<f;){c>f-(r=_+Math.floor((1+o)*Math.random()))&&(r=f-c),p.length=0,d.length=0,m.length=0,g.length=0;for(var y=0,x=3*c;x<3*(c+r);x++){d.push(y);var b=a[x];p.push(s[3*b],s[3*b+1],s[3*b+2]),l&&m.push(l[2*b],l[2*b+1]),h&&g.push(h[4*b],h[4*b+1],h[4*b+2],h[4*b+3]),y++}var T,E=this.nbParticles,A=this._posToShape(p),P=this._uvsToShapeUV(m);for(T=0;T<A.length;T++)v.addInPlace(A[T]);for(v.scaleInPlace(1/A.length),T=0;T<A.length;T++)A[T].subtractInPlace(v);var S;this._particlesIntersect&&(S=new e.BoundingInfo(v,v));var M=new e.ModelShape(this._shapeCounter,A,3*r,P,null,null),C=this._positions.length,R=this._indices.length;this._meshBuilder(this._index,A,this._positions,d,this._indices,m,this._uvs,g,this._colors,u,this._normals,E,0,null),this._addParticle(E,C,R,M,this._shapeCounter,0,S),this.particles[this.nbParticles].position.addInPlace(v),this._index+=A.length,E++,this.nbParticles++,this._shapeCounter++,c+=r}return this},t.prototype._unrotateFixedNormals=function(){for(var t=0,i=0,r=0;r<this.particles.length;r++){this._particle=this.particles[r],this._shape=this._particle._model._shape,this._particle.rotationQuaternion?this._quaternion.copyFrom(this._particle.rotationQuaternion):(this._yaw=this._particle.rotation.y,this._pitch=this._particle.rotation.x,this._roll=this._particle.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix(),this._rotMatrix.invertToRef(this._invertMatrix);for(var n=0;n<this._shape.length;n++)i=t+3*n,e.Vector3.TransformNormalFromFloatsToRef(this._normals32[i],this._normals32[i+1],this._normals32[i+2],this._invertMatrix,this._normal),this._fixedNormal32[i]=this._normal.x,this._fixedNormal32[i+1]=this._normal.y,this._fixedNormal32[i+2]=this._normal.z;t=i+3}},t.prototype._resetCopy=function(){this._copy.position.x=0,this._copy.position.y=0,this._copy.position.z=0,this._copy.rotation.x=0,this._copy.rotation.y=0,this._copy.rotation.z=0,this._copy.rotationQuaternion=null,this._copy.scaling.x=1,this._copy.scaling.y=1,this._copy.scaling.z=1,this._copy.uvs.x=0,this._copy.uvs.y=0,this._copy.uvs.z=1,this._copy.uvs.w=1,this._copy.color=null},t.prototype._meshBuilder=function(t,i,r,n,o,s,a,l,h,u,c,f,p,d){var m,g=0,v=0,_=0;for(this._resetCopy(),d&&d.positionFunction&&(d.positionFunction(this._copy,f,p),this._mustUnrotateFixedNormals=!0),this._copy.rotationQuaternion?this._quaternion.copyFrom(this._copy.rotationQuaternion):(this._yaw=this._copy.rotation.y,this._pitch=this._copy.rotation.x,this._roll=this._copy.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix(),m=0;m<i.length;m++)this._vertex.x=i[m].x,this._vertex.y=i[m].y,this._vertex.z=i[m].z,d&&d.vertexFunction&&d.vertexFunction(this._copy,this._vertex,m),this._vertex.x*=this._copy.scaling.x,this._vertex.y*=this._copy.scaling.y,this._vertex.z*=this._copy.scaling.z,this._vertex.x+=this._copy.pivot.x,this._vertex.y+=this._copy.pivot.y,this._vertex.z+=this._copy.pivot.z,e.Vector3.TransformCoordinatesToRef(this._vertex,this._rotMatrix,this._rotated),r.push(this._copy.position.x+this._rotated.x,this._copy.position.y+this._rotated.y,this._copy.position.z+this._rotated.z),s&&(a.push((this._copy.uvs.z-this._copy.uvs.x)*s[g]+this._copy.uvs.x,(this._copy.uvs.w-this._copy.uvs.y)*s[g+1]+this._copy.uvs.y),g+=2),this._copy.color?this._color=this._copy.color:l&&void 0!==l[v]?(this._color.r=l[v],this._color.g=l[v+1],this._color.b=l[v+2],this._color.a=l[v+3]):(this._color.r=1,this._color.g=1,this._color.b=1,this._color.a=1),h.push(this._color.r,this._color.g,this._color.b,this._color.a),v+=4,!this.recomputeNormals&&u&&(this._normal.x=u[_],this._normal.y=u[_+1],this._normal.z=u[_+2],e.Vector3.TransformNormalToRef(this._normal,this._rotMatrix,this._normal),c.push(this._normal.x,this._normal.y,this._normal.z),_+=3);for(m=0;m<n.length;m++){var y=t+n[m];o.push(y),y>65535&&(this._needs32Bits=!0)}if(this._pickable){var x=n.length/3;for(m=0;m<x;m++)this.pickedParticles.push({idx:f,faceId:m})}return this._depthSort&&this.depthSortedParticles.push(new e.DepthSortedParticle),this._copy},t.prototype._posToShape=function(t){for(var i=[],r=0;r<t.length;r+=3)i.push(new e.Vector3(t[r],t[r+1],t[r+2]));return i},t.prototype._uvsToShapeUV=function(e){var t=[];if(e)for(var i=0;i<e.length;i++)t.push(e[i]);return t},t.prototype._addParticle=function(t,i,r,n,o,s,a){void 0===a&&(a=null);var l=new e.SolidParticle(t,i,r,n,o,s,this,a);return this.particles.push(l),l},t.prototype.addShape=function(t,i,r){var n,o=t.getVerticesData(e.VertexBuffer.PositionKind),s=t.getIndices(),a=t.getVerticesData(e.VertexBuffer.UVKind),l=t.getVerticesData(e.VertexBuffer.ColorKind),h=t.getVerticesData(e.VertexBuffer.NormalKind);this._particlesIntersect&&(n=t.getBoundingInfo());for(var u,c,f=this._posToShape(o),p=this._uvsToShapeUV(a),d=r?r.positionFunction:null,m=r?r.vertexFunction:null,g=new e.ModelShape(this._shapeCounter,f,s.length,p,d,m),v=this.nbParticles,_=0;_<i;_++){var y=this._positions.length,x=this._indices.length;c=this._meshBuilder(this._index,f,this._positions,s,this._indices,a,this._uvs,l,this._colors,h,this._normals,v,_,r),this._updatable&&((u=this._addParticle(v,y,x,g,this._shapeCounter,_,n)).position.copyFrom(c.position),u.rotation.copyFrom(c.rotation),c.rotationQuaternion&&u.rotationQuaternion&&u.rotationQuaternion.copyFrom(c.rotationQuaternion),c.color&&u.color&&u.color.copyFrom(c.color),u.scaling.copyFrom(c.scaling),u.uvs.copyFrom(c.uvs)),this._index+=f.length,v++}return this.nbParticles+=i,this._shapeCounter++,this._shapeCounter-1},t.prototype._rebuildParticle=function(t){this._resetCopy(),t._model._positionFunction&&t._model._positionFunction(this._copy,t.idx,t.idxInShape),this._copy.rotationQuaternion?this._quaternion.copyFrom(this._copy.rotationQuaternion):(this._yaw=this._copy.rotation.y,this._pitch=this._copy.rotation.x,this._roll=this._copy.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix(),this._shape=t._model._shape;for(var i=0;i<this._shape.length;i++)this._vertex.x=this._shape[i].x,this._vertex.y=this._shape[i].y,this._vertex.z=this._shape[i].z,t._model._vertexFunction&&t._model._vertexFunction(this._copy,this._vertex,i),this._vertex.x*=this._copy.scaling.x,this._vertex.y*=this._copy.scaling.y,this._vertex.z*=this._copy.scaling.z,this._vertex.x+=this._copy.pivot.x,this._vertex.y+=this._copy.pivot.y,this._vertex.z+=this._copy.pivot.z,e.Vector3.TransformCoordinatesToRef(this._vertex,this._rotMatrix,this._rotated),this._positions32[t._pos+3*i]=this._copy.position.x+this._rotated.x,this._positions32[t._pos+3*i+1]=this._copy.position.y+this._rotated.y,this._positions32[t._pos+3*i+2]=this._copy.position.z+this._rotated.z;t.position.x=0,t.position.y=0,t.position.z=0,t.rotation.x=0,t.rotation.y=0,t.rotation.z=0,t.rotationQuaternion=null,t.scaling.x=1,t.scaling.y=1,t.scaling.z=1},t.prototype.rebuildMesh=function(){for(var t=0;t<this.particles.length;t++)this._rebuildParticle(this.particles[t]);return this.mesh.updateVerticesData(e.VertexBuffer.PositionKind,this._positions32,!1,!1),this},t.prototype.setParticles=function(t,i,r){if(void 0===t&&(t=0),void 0===i&&(i=this.nbParticles-1),void 0===r&&(r=!0),!this._updatable)return this;if(this.beforeUpdateParticles(t,i,r),this._cam_axisX.x=1,this._cam_axisX.y=0,this._cam_axisX.z=0,this._cam_axisY.x=0,this._cam_axisY.y=1,this._cam_axisY.z=0,this._cam_axisZ.x=0,this._cam_axisZ.y=0,this._cam_axisZ.z=1,(this.billboard||this._depthSort)&&(this.mesh.computeWorldMatrix(!0),this.mesh._worldMatrix.invertToRef(this._invertMatrix)),this.billboard){this._camera.getDirectionToRef(this._axisZ,this._camDir),e.Vector3.TransformNormalToRef(this._camDir,this._invertMatrix,this._cam_axisZ),this._cam_axisZ.normalize();var n=this._camera.getViewMatrix(!0);e.Vector3.TransformNormalFromFloatsToRef(n.m[1],n.m[5],n.m[9],this._invertMatrix,this._cam_axisY),e.Vector3.CrossToRef(this._cam_axisY,this._cam_axisZ,this._cam_axisX),this._cam_axisY.normalize(),this._cam_axisX.normalize()}this._depthSort&&e.Vector3.TransformCoordinatesToRef(this._camera.globalPosition,this._invertMatrix,this._camInvertedPosition),e.Matrix.IdentityToRef(this._rotMatrix);var o=0,s=0,a=0,l=0,h=0,u=0,c=0;this.mesh.isFacetDataEnabled&&(this._computeBoundingBox=!0),i=i>=this.nbParticles?this.nbParticles-1:i,this._computeBoundingBox&&(0==t&&i==this.nbParticles-1?(e.Vector3.FromFloatsToRef(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,this._minimum),e.Vector3.FromFloatsToRef(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE,this._maximum)):this.mesh._boundingInfo&&(this._minimum.copyFrom(this.mesh._boundingInfo.boundingBox.minimum),this._maximum.copyFrom(this.mesh._boundingInfo.boundingBox.maximum)));var f=(s=this.particles[t]._pos)/3|0;l=4*f,u=2*f;for(var p=t;p<=i;p++){if(this._particle=this.particles[p],this._shape=this._particle._model._shape,this._shapeUV=this._particle._model._shapeUV,this.updateParticle(this._particle),this._depthSort&&this._depthSortParticles){var d=this.depthSortedParticles[p];d.ind=this._particle._ind,d.indicesLength=this._particle._model._indicesLength,d.sqDistance=e.Vector3.DistanceSquared(this._particle.position,this._camInvertedPosition)}if(!this._particle.alive||this._particle._stillInvisible&&!this._particle.isVisible)s+=3*(c=this._shape.length),l+=4*c,u+=2*c;else{if(this._particle.isVisible)for(this._particle._stillInvisible=!1,this.billboard&&(this._particle.rotation.x=0,this._particle.rotation.y=0),(this._computeParticleRotation||this.billboard)&&(this._particle.rotationQuaternion?this._quaternion.copyFrom(this._particle.rotationQuaternion):(this._yaw=this._particle.rotation.y,this._pitch=this._particle.rotation.x,this._roll=this._particle.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix()),c=0;c<this._shape.length;c++)o=s+3*c,a=l+4*c,h=u+2*c,this._vertex.x=this._shape[c].x,this._vertex.y=this._shape[c].y,this._vertex.z=this._shape[c].z,this._computeParticleVertex&&this.updateParticleVertex(this._particle,this._vertex,c),this._vertex.x*=this._particle.scaling.x,this._vertex.y*=this._particle.scaling.y,this._vertex.z*=this._particle.scaling.z,this._vertex.x+=this._particle.pivot.x,this._vertex.y+=this._particle.pivot.y,this._vertex.z+=this._particle.pivot.z,this._rotated.x=this._vertex.x*this._rotMatrix.m[0]+this._vertex.y*this._rotMatrix.m[4]+this._vertex.z*this._rotMatrix.m[8],this._rotated.y=this._vertex.x*this._rotMatrix.m[1]+this._vertex.y*this._rotMatrix.m[5]+this._vertex.z*this._rotMatrix.m[9],this._rotated.z=this._vertex.x*this._rotMatrix.m[2]+this._vertex.y*this._rotMatrix.m[6]+this._vertex.z*this._rotMatrix.m[10],this._positions32[o]=this._particle.position.x+this._cam_axisX.x*this._rotated.x+this._cam_axisY.x*this._rotated.y+this._cam_axisZ.x*this._rotated.z,this._positions32[o+1]=this._particle.position.y+this._cam_axisX.y*this._rotated.x+this._cam_axisY.y*this._rotated.y+this._cam_axisZ.y*this._rotated.z,this._positions32[o+2]=this._particle.position.z+this._cam_axisX.z*this._rotated.x+this._cam_axisY.z*this._rotated.y+this._cam_axisZ.z*this._rotated.z,this._computeBoundingBox&&(this._positions32[o]<this._minimum.x&&(this._minimum.x=this._positions32[o]),this._positions32[o]>this._maximum.x&&(this._maximum.x=this._positions32[o]),this._positions32[o+1]<this._minimum.y&&(this._minimum.y=this._positions32[o+1]),this._positions32[o+1]>this._maximum.y&&(this._maximum.y=this._positions32[o+1]),this._positions32[o+2]<this._minimum.z&&(this._minimum.z=this._positions32[o+2]),this._positions32[o+2]>this._maximum.z&&(this._maximum.z=this._positions32[o+2])),this._computeParticleVertex||(this._normal.x=this._fixedNormal32[o],this._normal.y=this._fixedNormal32[o+1],this._normal.z=this._fixedNormal32[o+2],this._rotated.x=this._normal.x*this._rotMatrix.m[0]+this._normal.y*this._rotMatrix.m[4]+this._normal.z*this._rotMatrix.m[8],this._rotated.y=this._normal.x*this._rotMatrix.m[1]+this._normal.y*this._rotMatrix.m[5]+this._normal.z*this._rotMatrix.m[9],this._rotated.z=this._normal.x*this._rotMatrix.m[2]+this._normal.y*this._rotMatrix.m[6]+this._normal.z*this._rotMatrix.m[10],this._normals32[o]=this._cam_axisX.x*this._rotated.x+this._cam_axisY.x*this._rotated.y+this._cam_axisZ.x*this._rotated.z,this._normals32[o+1]=this._cam_axisX.y*this._rotated.x+this._cam_axisY.y*this._rotated.y+this._cam_axisZ.y*this._rotated.z,this._normals32[o+2]=this._cam_axisX.z*this._rotated.x+this._cam_axisY.z*this._rotated.y+this._cam_axisZ.z*this._rotated.z),this._computeParticleColor&&this._particle.color&&(this._colors32[a]=this._particle.color.r,this._colors32[a+1]=this._particle.color.g,this._colors32[a+2]=this._particle.color.b,this._colors32[a+3]=this._particle.color.a),this._computeParticleTexture&&(this._uvs32[h]=this._shapeUV[2*c]*(this._particle.uvs.z-this._particle.uvs.x)+this._particle.uvs.x,this._uvs32[h+1]=this._shapeUV[2*c+1]*(this._particle.uvs.w-this._particle.uvs.y)+this._particle.uvs.y);else for(this._particle._stillInvisible=!0,c=0;c<this._shape.length;c++)o=s+3*c,a=l+4*c,h=u+2*c,this._positions32[o]=0,this._positions32[o+1]=0,this._positions32[o+2]=0,this._normals32[o]=0,this._normals32[o+1]=0,this._normals32[o+2]=0,this._computeParticleColor&&this._particle.color&&(this._colors32[a]=this._particle.color.r,this._colors32[a+1]=this._particle.color.g,this._colors32[a+2]=this._particle.color.b,this._colors32[a+3]=this._particle.color.a),this._computeParticleTexture&&(this._uvs32[h]=this._shapeUV[2*c]*(this._particle.uvs.z-this._particle.uvs.x)+this._particle.uvs.x,this._uvs32[h+1]=this._shapeUV[2*c+1]*(this._particle.uvs.w-this._particle.uvs.y)+this._particle.uvs.y);if(this._particlesIntersect){var m=this._particle._boundingInfo,g=m.boundingBox,v=m.boundingSphere;if(!this._bSphereOnly){for(var _=0;_<g.vectors.length;_++)this._vertex.x=this._particle._modelBoundingInfo.boundingBox.vectors[_].x*this._particle.scaling.x,this._vertex.y=this._particle._modelBoundingInfo.boundingBox.vectors[_].y*this._particle.scaling.y,this._vertex.z=this._particle._modelBoundingInfo.boundingBox.vectors[_].z*this._particle.scaling.z,this._rotated.x=this._vertex.x*this._rotMatrix.m[0]+this._vertex.y*this._rotMatrix.m[4]+this._vertex.z*this._rotMatrix.m[8],this._rotated.y=this._vertex.x*this._rotMatrix.m[1]+this._vertex.y*this._rotMatrix.m[5]+this._vertex.z*this._rotMatrix.m[9],this._rotated.z=this._vertex.x*this._rotMatrix.m[2]+this._vertex.y*this._rotMatrix.m[6]+this._vertex.z*this._rotMatrix.m[10],g.vectors[_].x=this._particle.position.x+this._cam_axisX.x*this._rotated.x+this._cam_axisY.x*this._rotated.y+this._cam_axisZ.x*this._rotated.z,g.vectors[_].y=this._particle.position.y+this._cam_axisX.y*this._rotated.x+this._cam_axisY.y*this._rotated.y+this._cam_axisZ.y*this._rotated.z,g.vectors[_].z=this._particle.position.z+this._cam_axisX.z*this._rotated.x+this._cam_axisY.z*this._rotated.y+this._cam_axisZ.z*this._rotated.z;g._update(this.mesh._worldMatrix)}this._minBbox.x=this._particle._modelBoundingInfo.minimum.x*this._particle.scaling.x,this._minBbox.y=this._particle._modelBoundingInfo.minimum.y*this._particle.scaling.y,this._minBbox.z=this._particle._modelBoundingInfo.minimum.z*this._particle.scaling.z,this._maxBbox.x=this._particle._modelBoundingInfo.maximum.x*this._particle.scaling.x,this._maxBbox.y=this._particle._modelBoundingInfo.maximum.y*this._particle.scaling.y,this._maxBbox.z=this._particle._modelBoundingInfo.maximum.z*this._particle.scaling.z,v.center.x=this._particle.position.x+.5*(this._minBbox.x+this._maxBbox.x),v.center.y=this._particle.position.y+.5*(this._minBbox.y+this._maxBbox.y),v.center.z=this._particle.position.z+.5*(this._minBbox.z+this._maxBbox.z),v.radius=.5*this._bSphereRadiusFactor*Math.sqrt((this._maxBbox.x-this._minBbox.x)*(this._maxBbox.x-this._minBbox.x)+(this._maxBbox.y-this._minBbox.y)*(this._maxBbox.y-this._minBbox.y)+(this._maxBbox.z-this._minBbox.z)*(this._maxBbox.z-this._minBbox.z)),v._update(this.mesh._worldMatrix)}s=o+3,l=a+4,u=h+2}}if(r){if(this._computeParticleColor&&this.mesh.updateVerticesData(e.VertexBuffer.ColorKind,this._colors32,!1,!1),this._computeParticleTexture&&this.mesh.updateVerticesData(e.VertexBuffer.UVKind,this._uvs32,!1,!1),this.mesh.updateVerticesData(e.VertexBuffer.PositionKind,this._positions32,!1,!1),!this.mesh.areNormalsFrozen||this.mesh.isFacetDataEnabled){if(this._computeParticleVertex||this.mesh.isFacetDataEnabled){var y=this.mesh.isFacetDataEnabled?this.mesh.getFacetDataParameters():null;e.VertexData.ComputeNormals(this._positions32,this._indices,this._normals32,y);for(P=0;P<this._normals32.length;P++)this._fixedNormal32[P]=this._normals32[P]}this.mesh.areNormalsFrozen||this.mesh.updateVerticesData(e.VertexBuffer.NormalKind,this._normals32,!1,!1)}if(this._depthSort&&this._depthSortParticles){this.depthSortedParticles.sort(this._depthSortFunction);var x=this.depthSortedParticles.length,b=0,T=0,E=0,A=0;for(b=0;b<x;b++){T=this.depthSortedParticles[b].indicesLength,E=this.depthSortedParticles[b].ind;for(var P=0;P<T;P++)this._indices32[A]=this._indices[E+P],A++}this.mesh.updateIndices(this._indices32)}}return this._computeBoundingBox&&(this.mesh._boundingInfo=new e.BoundingInfo(this._minimum,this._maximum),this.mesh._boundingInfo.update(this.mesh._worldMatrix)),this.afterUpdateParticles(t,i,r),this},t.prototype._quaternionRotationYPR=function(){this._halfroll=.5*this._roll,this._halfpitch=.5*this._pitch,this._halfyaw=.5*this._yaw,this._sinRoll=Math.sin(this._halfroll),this._cosRoll=Math.cos(this._halfroll),this._sinPitch=Math.sin(this._halfpitch),this._cosPitch=Math.cos(this._halfpitch),this._sinYaw=Math.sin(this._halfyaw),this._cosYaw=Math.cos(this._halfyaw),this._quaternion.x=this._cosYaw*this._sinPitch*this._cosRoll+this._sinYaw*this._cosPitch*this._sinRoll,this._quaternion.y=this._sinYaw*this._cosPitch*this._cosRoll-this._cosYaw*this._sinPitch*this._sinRoll,this._quaternion.z=this._cosYaw*this._cosPitch*this._sinRoll-this._sinYaw*this._sinPitch*this._cosRoll,this._quaternion.w=this._cosYaw*this._cosPitch*this._cosRoll+this._sinYaw*this._sinPitch*this._sinRoll},t.prototype._quaternionToRotationMatrix=function(){this._rotMatrix.m[0]=1-2*(this._quaternion.y*this._quaternion.y+this._quaternion.z*this._quaternion.z),this._rotMatrix.m[1]=2*(this._quaternion.x*this._quaternion.y+this._quaternion.z*this._quaternion.w),this._rotMatrix.m[2]=2*(this._quaternion.z*this._quaternion.x-this._quaternion.y*this._quaternion.w),this._rotMatrix.m[3]=0,this._rotMatrix.m[4]=2*(this._quaternion.x*this._quaternion.y-this._quaternion.z*this._quaternion.w),this._rotMatrix.m[5]=1-2*(this._quaternion.z*this._quaternion.z+this._quaternion.x*this._quaternion.x),this._rotMatrix.m[6]=2*(this._quaternion.y*this._quaternion.z+this._quaternion.x*this._quaternion.w),this._rotMatrix.m[7]=0,this._rotMatrix.m[8]=2*(this._quaternion.z*this._quaternion.x+this._quaternion.y*this._quaternion.w),this._rotMatrix.m[9]=2*(this._quaternion.y*this._quaternion.z-this._quaternion.x*this._quaternion.w),this._rotMatrix.m[10]=1-2*(this._quaternion.y*this._quaternion.y+this._quaternion.x*this._quaternion.x),this._rotMatrix.m[11]=0,this._rotMatrix.m[12]=0,this._rotMatrix.m[13]=0,this._rotMatrix.m[14]=0,this._rotMatrix.m[15]=1},t.prototype.dispose=function(){this.mesh.dispose(),this.vars=null,this._positions=null,this._indices=null,this._normals=null,this._uvs=null,this._colors=null,this._indices32=null,this._positions32=null,this._normals32=null,this._fixedNormal32=null,this._uvs32=null,this._colors32=null,this.pickedParticles=null},t.prototype.refreshVisibleSize=function(){return this._isVisibilityBoxLocked||this.mesh.refreshBoundingInfo(),this},t.prototype.setVisibilityBox=function(t){var i=t/2;this.mesh._boundingInfo=new e.BoundingInfo(new e.Vector3(-i,-i,-i),new e.Vector3(i,i,i))},Object.defineProperty(t.prototype,"isAlwaysVisible",{get:function(){return this._alwaysVisible},set:function(e){this._alwaysVisible=e,this.mesh.alwaysSelectAsActiveMesh=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isVisibilityBoxLocked",{get:function(){return this._isVisibilityBoxLocked},set:function(e){this._isVisibilityBoxLocked=e;var t=this.mesh.getBoundingInfo();t&&(t.isLocked=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"computeParticleRotation",{get:function(){return this._computeParticleRotation},set:function(e){this._computeParticleRotation=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"computeParticleColor",{get:function(){return this._computeParticleColor},set:function(e){this._computeParticleColor=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"computeParticleTexture",{get:function(){return this._computeParticleTexture},set:function(e){this._computeParticleTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"computeParticleVertex",{get:function(){return this._computeParticleVertex},set:function(e){this._computeParticleVertex=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"computeBoundingBox",{get:function(){return this._computeBoundingBox},set:function(e){this._computeBoundingBox=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"depthSortParticles",{get:function(){return this._depthSortParticles},set:function(e){this._depthSortParticles=e},enumerable:!0,configurable:!0}),t.prototype.initParticles=function(){},t.prototype.recycleParticle=function(e){return e},t.prototype.updateParticle=function(e){return e},t.prototype.updateParticleVertex=function(e,t,i){return t},t.prototype.beforeUpdateParticles=function(e,t,i){},t.prototype.afterUpdateParticles=function(e,t,i){},t}();e.SolidParticleSystem=t}(s||(s={}));!function(e){var t=function(t){function i(e,i){var r=t.call(this,e,i)||this;return r.generateOctree=!1,r}return n(i,t),i.prototype.getClassName=function(){return"GroundMesh"},Object.defineProperty(i.prototype,"subdivisions",{get:function(){return Math.min(this._subdivisionsX,this._subdivisionsY)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"subdivisionsX",{get:function(){return this._subdivisionsX},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"subdivisionsY",{get:function(){return this._subdivisionsY},enumerable:!0,configurable:!0}),i.prototype.optimize=function(e,t){void 0===t&&(t=32),this._subdivisionsX=e,this._subdivisionsY=e,this.subdivide(e),this.createOrUpdateSubmeshesOctree(t)},i.prototype.getHeightAtCoordinates=function(t,i){var r=this.getWorldMatrix(),n=e.Tmp.Matrix[5];r.invertToRef(n);var o=e.Tmp.Vector3[8];if(e.Vector3.TransformCoordinatesFromFloatsToRef(t,0,i,n,o),t=o.x,i=o.z,t<this._minX||t>this._maxX||i<this._minZ||i>this._maxZ)return this.position.y;this._heightQuads&&0!=this._heightQuads.length||(this._initHeightQuads(),this._computeHeightQuads());var s=this._getFacetAt(t,i),a=-(s.x*t+s.z*i+s.w)/s.y;return e.Vector3.TransformCoordinatesFromFloatsToRef(0,a,0,r,o),o.y},i.prototype.getNormalAtCoordinates=function(t,i){var r=new e.Vector3(0,1,0);return this.getNormalAtCoordinatesToRef(t,i,r),r},i.prototype.getNormalAtCoordinatesToRef=function(t,i,r){var n=this.getWorldMatrix(),o=e.Tmp.Matrix[5];n.invertToRef(o);var s=e.Tmp.Vector3[8];if(e.Vector3.TransformCoordinatesFromFloatsToRef(t,0,i,o,s),t=s.x,i=s.z,t<this._minX||t>this._maxX||i<this._minZ||i>this._maxZ)return this;this._heightQuads&&0!=this._heightQuads.length||(this._initHeightQuads(),this._computeHeightQuads());var a=this._getFacetAt(t,i);return e.Vector3.TransformNormalFromFloatsToRef(a.x,a.y,a.z,n,r),this},i.prototype.updateCoordinateHeights=function(){return this._heightQuads&&0!=this._heightQuads.length||this._initHeightQuads(),this._computeHeightQuads(),this},i.prototype._getFacetAt=function(e,t){var i=Math.floor((e+this._maxX)*this._subdivisionsX/this._width),r=Math.floor(-(t+this._maxZ)*this._subdivisionsY/this._height+this._subdivisionsY),n=this._heightQuads[r*this._subdivisionsX+i];return t<n.slope.x*e+n.slope.y?n.facet1:n.facet2},i.prototype._initHeightQuads=function(){var t=this._subdivisionsX,i=this._subdivisionsY;this._heightQuads=new Array;for(var r=0;r<i;r++)for(var n=0;n<t;n++){var o={slope:e.Vector2.Zero(),facet1:new e.Vector4(0,0,0,0),facet2:new e.Vector4(0,0,0,0)};this._heightQuads[r*t+n]=o}return this},i.prototype._computeHeightQuads=function(){var t=this.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return this;for(var i=e.Tmp.Vector3[3],r=e.Tmp.Vector3[2],n=e.Tmp.Vector3[1],o=e.Tmp.Vector3[0],s=e.Tmp.Vector3[4],a=e.Tmp.Vector3[5],l=e.Tmp.Vector3[6],h=e.Tmp.Vector3[7],u=e.Tmp.Vector3[8],c=0,f=0,p=0,d=0,m=0,g=0,v=0,_=this._subdivisionsX,y=this._subdivisionsY,x=0;x<y;x++)for(var b=0;b<_;b++){c=3*b,f=x*(_+1)*3,p=(x+1)*(_+1)*3,i.x=t[f+c],i.y=t[f+c+1],i.z=t[f+c+2],r.x=t[f+c+3],r.y=t[f+c+4],r.z=t[f+c+5],n.x=t[p+c],n.y=t[p+c+1],n.z=t[p+c+2],o.x=t[p+c+3],o.y=t[p+c+4],o.z=t[p+c+5],d=(o.z-i.z)/(o.x-i.x),m=i.z-d*i.x,r.subtractToRef(i,s),n.subtractToRef(i,a),o.subtractToRef(i,l),e.Vector3.CrossToRef(l,a,h),e.Vector3.CrossToRef(s,l,u),h.normalize(),u.normalize(),g=-(h.x*i.x+h.y*i.y+h.z*i.z),v=-(u.x*r.x+u.y*r.y+u.z*r.z);var T=this._heightQuads[x*_+b];T.slope.copyFromFloats(d,m),T.facet1.copyFromFloats(h.x,h.y,h.z,g),T.facet2.copyFromFloats(u.x,u.y,u.z,v)}return this},i.prototype.serialize=function(e){t.prototype.serialize.call(this,e),e.subdivisionsX=this._subdivisionsX,e.subdivisionsY=this._subdivisionsY,e.minX=this._minX,e.maxX=this._maxX,e.minZ=this._minZ,e.maxZ=this._maxZ,e.width=this._width,e.height=this._height},i.Parse=function(e,t){var r=new i(e.name,t);return r._subdivisionsX=e.subdivisionsX||1,r._subdivisionsY=e.subdivisionsY||1,r._minX=e.minX,r._maxX=e.maxX,r._minZ=e.minZ,r._maxZ=e.maxZ,r._width=e.width,r._height=e.height,r},i}(e.Mesh);e.GroundMesh=t}(s||(s={}));!function(e){var t=function(t){function i(e,i){var r=t.call(this,e,i.getScene())||this;return i.instances.push(r),r._sourceMesh=i,r.position.copyFrom(i.position),r.rotation.copyFrom(i.rotation),r.scaling.copyFrom(i.scaling),i.rotationQuaternion&&(r.rotationQuaternion=i.rotationQuaternion.clone()),r.infiniteDistance=i.infiniteDistance,r.setPivotMatrix(i.getPivotMatrix()),r.refreshBoundingInfo(),r._syncSubMeshes(),r}return n(i,t),i.prototype.getClassName=function(){return"InstancedMesh"},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.setVerticesData=function(e,t,i,r){return this.sourceMesh&&this.sourceMesh.setVerticesData(e,t,i,r),this.sourceMesh},i.prototype.updateVerticesData=function(e,t,i,r){return this.sourceMesh&&this.sourceMesh.updateVerticesData(e,t,i,r),this.sourceMesh},i.prototype.setIndices=function(e,t){return void 0===t&&(t=null),this.sourceMesh&&this.sourceMesh.setIndices(e,t),this.sourceMesh},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();return t&&(this._boundingInfo=new e.BoundingInfo(t.minimum.clone(),t.maximum.clone())),this._updateBoundingInfo(),this},i.prototype._preActivate=function(){return this._currentLOD&&this._currentLOD._preActivate(),this},i.prototype._activate=function(e){return this._currentLOD&&this._currentLOD._registerInstanceForRenderId(this,e),this},i.prototype.getLOD=function(e){if(!e)return this;var t=this.getBoundingInfo();return t?(this._currentLOD=this.sourceMesh.getLOD(e,t.boundingSphere),this._currentLOD===this.sourceMesh?this:this._currentLOD):this},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);return this},i.prototype._generatePointsArray=function(){return this._sourceMesh._generatePointsArray()},i.prototype.clone=function(t,i,r){var n=this._sourceMesh.createInstance(t);if(e.Tools.DeepCopy(this,n,["name","subMeshes","uniqueId"],[]),this.refreshBoundingInfo(),i&&(n.parent=i),!r)for(var o=0;o<this.getScene().meshes.length;o++){var s=this.getScene().meshes[o];s.parent===this&&s.clone(s.name,n)}return n.computeWorldMatrix(!0),n},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}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a){void 0===r&&(r=null),void 0===n&&(n=null);var l=t.call(this,i,r,n,o,s)||this;l.useVertexColor=a,l.color=new e.Color3(1,1,1),l.alpha=1,o&&(l.color=o.color.clone(),l.alpha=o.alpha,l.useVertexColor=o.useVertexColor),l._intersectionThreshold=.1;var h={attributes:[e.VertexBuffer.PositionKind],uniforms:["world","viewProjection"],needAlphaBlending:!1};return a||(h.uniforms.push("color"),h.needAlphaBlending=!0),l._colorShader=new e.ShaderMaterial("colorShader",l.getScene(),"color",h),l}return n(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}),i.prototype.getClassName=function(){return"LinesMesh"},Object.defineProperty(i.prototype,"material",{get:function(){return this._colorShader},set:function(e){},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"checkCollisions",{get:function(){return!1},enumerable:!0,configurable:!0}),i.prototype.createInstance=function(e){throw new Error("LinesMeshes do not support createInstance.")},i.prototype._bind=function(e,t,i){return this._geometry?(this._geometry._bind(this._colorShader.getEffect()),this.useVertexColor||this._colorShader.setColor4("color",this.color.toColor4(this.alpha)),this):this},i.prototype._draw=function(e,t,i){return this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()?(this.getScene().getEngine().draw(!1,e.indexStart,e.indexCount),this):this},i.prototype.dispose=function(e){this._colorShader.dispose(),t.prototype.dispose.call(this,e)},i.prototype.clone=function(e,t,r){return new i(e,this.getScene(),t,this,r)},i}(e.Mesh);e.LinesMesh=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o){var s=t.call(this,i,r)||this;return s._textures={},s._textureArrays={},s._floats={},s._floatsArrays={},s._colors3={},s._colors3Arrays={},s._colors4={},s._vectors2={},s._vectors3={},s._vectors4={},s._matrices={},s._matrices3x3={},s._matrices2x2={},s._vectors3Arrays={},s._cachedWorldViewMatrix=new e.Matrix,s._shaderPath=n,o.needAlphaBlending=o.needAlphaBlending||!1,o.needAlphaTesting=o.needAlphaTesting||!1,o.attributes=o.attributes||["position","normal","uv"],o.uniforms=o.uniforms||["worldViewProjection"],o.uniformBuffers=o.uniformBuffers||[],o.samplers=o.samplers||[],o.defines=o.defines||[],s._options=o,s}return n(i,t),i.prototype.getClassName=function(){return"ShaderMaterial"},i.prototype.needAlphaBlending=function(){return this._options.needAlphaBlending},i.prototype.needAlphaTesting=function(){return this._options.needAlphaTesting},i.prototype._checkUniform=function(e){-1===this._options.uniforms.indexOf(e)&&this._options.uniforms.push(e)},i.prototype.setTexture=function(e,t){return-1===this._options.samplers.indexOf(e)&&this._options.samplers.push(e),this._textures[e]=t,this},i.prototype.setTextureArray=function(e,t){return-1===this._options.samplers.indexOf(e)&&this._options.samplers.push(e),this._checkUniform(e),this._textureArrays[e]=t,this},i.prototype.setFloat=function(e,t){return this._checkUniform(e),this._floats[e]=t,this},i.prototype.setFloats=function(e,t){return this._checkUniform(e),this._floatsArrays[e]=t,this},i.prototype.setColor3=function(e,t){return this._checkUniform(e),this._colors3[e]=t,this},i.prototype.setColor3Array=function(e,t){return this._checkUniform(e),this._colors3Arrays[e]=t.reduce(function(e,t){return t.toArray(e,e.length),e},[]),this},i.prototype.setColor4=function(e,t){return this._checkUniform(e),this._colors4[e]=t,this},i.prototype.setVector2=function(e,t){return this._checkUniform(e),this._vectors2[e]=t,this},i.prototype.setVector3=function(e,t){return this._checkUniform(e),this._vectors3[e]=t,this},i.prototype.setVector4=function(e,t){return this._checkUniform(e),this._vectors4[e]=t,this},i.prototype.setMatrix=function(e,t){return this._checkUniform(e),this._matrices[e]=t,this},i.prototype.setMatrix3x3=function(e,t){return this._checkUniform(e),this._matrices3x3[e]=t,this},i.prototype.setMatrix2x2=function(e,t){return this._checkUniform(e),this._matrices2x2[e]=t,this},i.prototype.setArray3=function(e,t){return this._checkUniform(e),this._vectors3Arrays[e]=t,this},i.prototype._checkCache=function(e,t,i){return!t||(this._effect&&this._effect.defines.indexOf("#define INSTANCES"),!1)},i.prototype.isReady=function(t,i){var r=this.getScene(),n=r.getEngine();if(!this.checkReadyOnEveryCall&&this._renderId===r.getRenderId()&&this._checkCache(r,t,i))return!0;var o=[],s=[],a=new e.EffectFallbacks;i&&o.push("#define INSTANCES");for(l=0;l<this._options.defines.length;l++)o.push(this._options.defines[l]);for(var l=0;l<this._options.attributes.length;l++)s.push(this._options.attributes[l]);t&&t.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(s.push(e.VertexBuffer.ColorKind),o.push("#define VERTEXCOLOR")),t&&t.useBones&&t.computeBonesUsingShaders&&t.skeleton?(s.push(e.VertexBuffer.MatricesIndicesKind),s.push(e.VertexBuffer.MatricesWeightsKind),t.numBoneInfluencers>4&&(s.push(e.VertexBuffer.MatricesIndicesExtraKind),s.push(e.VertexBuffer.MatricesWeightsExtraKind)),o.push("#define NUM_BONE_INFLUENCERS "+t.numBoneInfluencers),o.push("#define BonesPerMesh "+(t.skeleton.bones.length+1)),a.addCPUSkinningFallback(0,t),-1===this._options.uniforms.indexOf("mBones")&&this._options.uniforms.push("mBones")):o.push("#define NUM_BONE_INFLUENCERS 0");for(var h in this._textures)if(!this._textures[h].isReady())return!1;n.getAlphaTesting()&&o.push("#define ALPHATEST");var u=this._effect,c=o.join("\n");return this._effect=n.createEffect(this._shaderPath,{attributes:s,uniformsNames:this._options.uniforms,uniformBuffersNames:this._options.uniformBuffers,samplers:this._options.samplers,defines:c,fallbacks:a,onCompiled:this.onCompiled,onError:this.onError},n),!!this._effect.isReady()&&(u!==this._effect&&r.resetCachedMaterial(),this._renderId=r.getRenderId(),!0)},i.prototype.bindOnlyWorldMatrix=function(e){var t=this.getScene();this._effect&&(-1!==this._options.uniforms.indexOf("world")&&this._effect.setMatrix("world",e),-1!==this._options.uniforms.indexOf("worldView")&&(e.multiplyToRef(t.getViewMatrix(),this._cachedWorldViewMatrix),this._effect.setMatrix("worldView",this._cachedWorldViewMatrix)),-1!==this._options.uniforms.indexOf("worldViewProjection")&&this._effect.setMatrix("worldViewProjection",e.multiply(t.getTransformMatrix())))},i.prototype.bind=function(t,i){if(this.bindOnlyWorldMatrix(t),this._effect&&this.getScene().getCachedMaterial()!==this){-1!==this._options.uniforms.indexOf("view")&&this._effect.setMatrix("view",this.getScene().getViewMatrix()),-1!==this._options.uniforms.indexOf("projection")&&this._effect.setMatrix("projection",this.getScene().getProjectionMatrix()),-1!==this._options.uniforms.indexOf("viewProjection")&&this._effect.setMatrix("viewProjection",this.getScene().getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._effect);var r;for(r in this._textures)this._effect.setTexture(r,this._textures[r]);for(r in this._textureArrays)this._effect.setTextureArray(r,this._textureArrays[r]);for(r in this._floats)this._effect.setFloat(r,this._floats[r]);for(r in this._floatsArrays)this._effect.setArray(r,this._floatsArrays[r]);for(r in this._colors3)this._effect.setColor3(r,this._colors3[r]);for(r in this._colors3Arrays)this._effect.setArray3(r,this._colors3Arrays[r]);for(r in this._colors4){var n=this._colors4[r];this._effect.setFloat4(r,n.r,n.g,n.b,n.a)}for(r in this._vectors2)this._effect.setVector2(r,this._vectors2[r]);for(r in this._vectors3)this._effect.setVector3(r,this._vectors3[r]);for(r in this._vectors4)this._effect.setVector4(r,this._vectors4[r]);for(r in this._matrices)this._effect.setMatrix(r,this._matrices[r]);for(r in this._matrices3x3)this._effect.setMatrix3x3(r,this._matrices3x3[r]);for(r in this._matrices2x2)this._effect.setMatrix2x2(r,this._matrices2x2[r]);for(r in this._vectors3Arrays)this._effect.setArray3(r,this._vectors3Arrays[r])}this._afterBind(i)},i.prototype.getActiveTextures=function(){var e=t.prototype.getActiveTextures.call(this);for(var i in this._textures)e.push(this._textures[i]);for(var i in this._textureArrays)for(var r=this._textureArrays[i],n=0;n<r.length;n++)e.push(r[n]);return e},i.prototype.hasTexture=function(e){if(t.prototype.hasTexture.call(this,e))return!0;for(var i in this._textures)if(this._textures[i]===e)return!0;for(var i in this._textureArrays)for(var r=this._textureArrays[i],n=0;n<r.length;n++)if(r[n]===e)return!0;return!1},i.prototype.clone=function(e){return new i(e,this.getScene(),this._shaderPath,this._options)},i.prototype.dispose=function(e,i){if(i){var r;for(r in this._textures)this._textures[r].dispose();for(r in this._textureArrays)for(var n=this._textureArrays[r],o=0;o<n.length;o++)n[o].dispose()}this._textures={},t.prototype.dispose.call(this,e,i)},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);t.customType="BABYLON.ShaderMaterial",t.options=this._options,t.shaderPath=this._shaderPath;var i;t.textures={};for(i in this._textures)t.textures[i]=this._textures[i].serialize();t.textureArrays={};for(i in this._textureArrays){t.textureArrays[i]=[];for(var r=this._textureArrays[i],n=0;n<r.length;n++)t.textureArrays[i].push(r[n].serialize())}t.floats={};for(i in this._floats)t.floats[i]=this._floats[i];t.FloatArrays={};for(i in this._floatsArrays)t.FloatArrays[i]=this._floatsArrays[i];t.colors3={};for(i in this._colors3)t.colors3[i]=this._colors3[i].asArray();t.colors3Arrays={};for(i in this._colors3Arrays)t.colors3Arrays[i]=this._colors3Arrays[i];t.colors4={};for(i in this._colors4)t.colors4[i]=this._colors4[i].asArray();t.vectors2={};for(i in this._vectors2)t.vectors2[i]=this._vectors2[i].asArray();t.vectors3={};for(i in this._vectors3)t.vectors3[i]=this._vectors3[i].asArray();t.vectors4={};for(i in this._vectors4)t.vectors4[i]=this._vectors4[i].asArray();t.matrices={};for(i in this._matrices)t.matrices[i]=this._matrices[i].asArray();t.matrices3x3={};for(i in this._matrices3x3)t.matrices3x3[i]=this._matrices3x3[i];t.matrices2x2={};for(i in this._matrices2x2)t.matrices2x2[i]=this._matrices2x2[i];t.vectors3Arrays={};for(i in this._vectors3Arrays)t.vectors3Arrays[i]=this._vectors3Arrays[i];return t},i.Parse=function(t,r,n){var o,s=e.SerializationHelper.Parse(function(){return new i(t.name,r,t.shaderPath,t.options)},t,r,n);for(o in t.textures)s.setTexture(o,e.Texture.Parse(t.textures[o],r,n));for(o in t.textureArrays){for(var a=t.textureArrays[o],l=new Array,h=0;h<a.length;h++)l.push(e.Texture.Parse(a[h],r,n));s.setTextureArray(o,l)}for(o in t.floats)s.setFloat(o,t.floats[o]);for(o in t.floatsArrays)s.setFloats(o,t.floatsArrays[o]);for(o in t.colors3)s.setColor3(o,e.Color3.FromArray(t.colors3[o]));for(o in t.colors3Arrays){var u=t.colors3Arrays[o].reduce(function(e,t,i){return i%3==0?e.push([t]):e[e.length-1].push(t),e},[]).map(function(t){return e.Color3.FromArray(t)});s.setColor3Array(o,u)}for(o in t.colors4)s.setColor4(o,e.Color4.FromArray(t.colors4[o]));for(o in t.vectors2)s.setVector2(o,e.Vector2.FromArray(t.vectors2[o]));for(o in t.vectors3)s.setVector3(o,e.Vector3.FromArray(t.vectors3[o]));for(o in t.vectors4)s.setVector4(o,e.Vector4.FromArray(t.vectors4[o]));for(o in t.matrices)s.setMatrix(o,e.Matrix.FromArray(t.matrices[o]));for(o in t.matrices3x3)s.setMatrix3x3(o,t.matrices3x3[o]);for(o in t.matrices2x2)s.setMatrix2x2(o,t.matrices2x2[o]);for(o in t.vectors3Arrays)s.setArray3(o,t.vectors3Arrays[o]);return s},i}(e.Material);e.ShaderMaterial=t}(s||(s={}));!function(e){var t=function(){function t(){}return t.updateSideOrientation=function(t){return t==e.Mesh.DOUBLESIDE?e.Mesh.DOUBLESIDE:void 0===t||null===t?e.Mesh.FRONTSIDE:t},t.CreateBox=function(i,r,n){void 0===n&&(n=null);var o=new e.Mesh(i,n);return r.sideOrientation=t.updateSideOrientation(r.sideOrientation),o._originalBuilderSideOrientation=r.sideOrientation,e.VertexData.CreateBox(r).applyToMesh(o,r.updatable),o},t.CreateSphere=function(i,r,n){var o=new e.Mesh(i,n);return r.sideOrientation=t.updateSideOrientation(r.sideOrientation),o._originalBuilderSideOrientation=r.sideOrientation,e.VertexData.CreateSphere(r).applyToMesh(o,r.updatable),o},t.CreateDisc=function(i,r,n){void 0===n&&(n=null);var o=new e.Mesh(i,n);return r.sideOrientation=t.updateSideOrientation(r.sideOrientation),o._originalBuilderSideOrientation=r.sideOrientation,e.VertexData.CreateDisc(r).applyToMesh(o,r.updatable),o},t.CreateIcoSphere=function(i,r,n){var o=new e.Mesh(i,n);return r.sideOrientation=t.updateSideOrientation(r.sideOrientation),o._originalBuilderSideOrientation=r.sideOrientation,e.VertexData.CreateIcoSphere(r).applyToMesh(o,r.updatable),o},t.CreateRibbon=function(i,r,n){void 0===n&&(n=null);var o=r.pathArray,s=r.closeArray,a=r.closePath,l=t.updateSideOrientation(r.sideOrientation),h=r.instance,u=r.updatable;if(h){e.Vector3.FromFloatsToRef(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,e.Tmp.Vector3[0]),e.Vector3.FromFloatsToRef(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE,e.Tmp.Vector3[1]);var c=function(t){for(var i=o[0].length,r=0,n=h._originalBuilderSideOrientation===e.Mesh.DOUBLESIDE?2:1,s=1;s<=n;s++)for(var a=0;a<o.length;a++){var l=o[a],u=l.length;i=i<u?i:u;for(var c=0;c<i;)t[r]=l[c].x,t[r+1]=l[c].y,t[r+2]=l[c].z,l[c].x<e.Tmp.Vector3[0].x&&(e.Tmp.Vector3[0].x=l[c].x),l[c].x>e.Tmp.Vector3[1].x&&(e.Tmp.Vector3[1].x=l[c].x),l[c].y<e.Tmp.Vector3[0].y&&(e.Tmp.Vector3[0].y=l[c].y),l[c].y>e.Tmp.Vector3[1].y&&(e.Tmp.Vector3[1].y=l[c].y),l[c].z<e.Tmp.Vector3[0].z&&(e.Tmp.Vector3[0].z=l[c].z),l[c].z>e.Tmp.Vector3[1].z&&(e.Tmp.Vector3[1].z=l[c].z),c++,r+=3;h._closePath&&(t[r]=l[0].x,t[r+1]=l[0].y,t[r+2]=l[0].z,r+=3)}},f=h.getVerticesData(e.VertexBuffer.PositionKind);if(c(f),h._boundingInfo=new e.BoundingInfo(e.Tmp.Vector3[0],e.Tmp.Vector3[1]),h._boundingInfo.update(h._worldMatrix),h.updateVerticesData(e.VertexBuffer.PositionKind,f,!1,!1),r.colors){for(var p=h.getVerticesData(e.VertexBuffer.ColorKind),d=0;d<r.colors.length;d++)p[4*d]=r.colors[d].r,p[4*d+1]=r.colors[d].g,p[4*d+2]=r.colors[d].b,p[4*d+3]=r.colors[d].a;h.updateVerticesData(e.VertexBuffer.ColorKind,p,!1,!1)}if(r.uvs){for(var m=h.getVerticesData(e.VertexBuffer.UVKind),g=0;g<r.uvs.length;g++)m[2*g]=r.uvs[g].x,m[2*g+1]=r.uvs[g].y;h.updateVerticesData(e.VertexBuffer.UVKind,m,!1,!1)}if(!h.areNormalsFrozen||h.isFacetDataEnabled){var v=h.getIndices(),_=h.getVerticesData(e.VertexBuffer.NormalKind),y=h.isFacetDataEnabled?h.getFacetDataParameters():null;if(e.VertexData.ComputeNormals(f,v,_,y),h._closePath)for(var x=0,b=0,T=0;T<o.length;T++)x=3*h._idx[T],b=T+1<o.length?3*(h._idx[T+1]-1):_.length-3,_[x]=.5*(_[x]+_[b]),_[x+1]=.5*(_[x+1]+_[b+1]),_[x+2]=.5*(_[x+2]+_[b+2]),_[b]=_[x],_[b+1]=_[x+1],_[b+2]=_[x+2];h.areNormalsFrozen||h.updateVerticesData(e.VertexBuffer.NormalKind,_,!1,!1)}return h}var E=new e.Mesh(i,n);E._originalBuilderSideOrientation=l;var A=e.VertexData.CreateRibbon(r);return a&&(E._idx=A._idx),E._closePath=a,E._closeArray=s,A.applyToMesh(E,u),E},t.CreateCylinder=function(i,r,n){var o=new e.Mesh(i,n);return r.sideOrientation=t.updateSideOrientation(r.sideOrientation),o._originalBuilderSideOrientation=r.sideOrientation,e.VertexData.CreateCylinder(r).applyToMesh(o,r.updatable),o},t.CreateTorus=function(i,r,n){var o=new e.Mesh(i,n);return r.sideOrientation=t.updateSideOrientation(r.sideOrientation),o._originalBuilderSideOrientation=r.sideOrientation,e.VertexData.CreateTorus(r).applyToMesh(o,r.updatable),o},t.CreateTorusKnot=function(i,r,n){var o=new e.Mesh(i,n);return r.sideOrientation=t.updateSideOrientation(r.sideOrientation),o._originalBuilderSideOrientation=r.sideOrientation,e.VertexData.CreateTorusKnot(r).applyToMesh(o,r.updatable),o},t.CreateLineSystem=function(t,i,r){var n=i.instance,o=i.lines;if(n){var s=function(e){for(var t=0,i=0;i<o.length;i++)for(var r=o[i],n=0;n<r.length;n++)e[t]=r[n].x,e[t+1]=r[n].y,e[t+2]=r[n].z,t+=3};return n.updateMeshPositions(s,!1),n}var a=new e.LinesMesh(t,r);return e.VertexData.CreateLineSystem(i).applyToMesh(a,i.updatable),a},t.CreateLines=function(e,i,r){return void 0===r&&(r=null),t.CreateLineSystem(e,{lines:[i.points],updatable:i.updatable,instance:i.instance},r)},t.CreateDashedLines=function(t,i,r){void 0===r&&(r=null);var n=i.points,o=i.instance,s=i.gapSize||1,a=i.dashSize||3;if(o){var l=function(t){var i=e.Vector3.Zero(),r=t.length/6,s=0,a=0,l=0,h=0,u=0,c=0,f=0,p=0;for(f=0;f<n.length-1;f++)n[f+1].subtractToRef(n[f],i),s+=i.length();for(l=s/r,h=o.dashSize*l/(o.dashSize+o.gapSize),f=0;f<n.length-1;f++)for(n[f+1].subtractToRef(n[f],i),a=Math.floor(i.length()/l),i.normalize(),p=0;p<a&&c<t.length;)u=l*p,t[c]=n[f].x+u*i.x,t[c+1]=n[f].y+u*i.y,t[c+2]=n[f].z+u*i.z,t[c+3]=n[f].x+(u+h)*i.x,t[c+4]=n[f].y+(u+h)*i.y,t[c+5]=n[f].z+(u+h)*i.z,c+=6,p++;for(;c<t.length;)t[c]=n[f].x,t[c+1]=n[f].y,t[c+2]=n[f].z,c+=3};return o.updateMeshPositions(l,!1),o}var h=new e.LinesMesh(t,r);return e.VertexData.CreateDashedLines(i).applyToMesh(h,i.updatable),h.dashSize=a,h.gapSize=s,h},t.ExtrudeShape=function(i,r,n){void 0===n&&(n=null);var o=r.path,s=r.shape,a=r.scale||1,l=r.rotation||0,h=0===r.cap?0:r.cap||e.Mesh.NO_CAP,u=r.updatable,c=t.updateSideOrientation(r.sideOrientation),f=r.instance||null,p=r.invertUV||!1;return t._ExtrudeShapeGeneric(i,s,o,a,l,null,null,!1,!1,h,!1,n,!!u,c,f,p,r.frontUVs||null,r.backUVs||null)},t.ExtrudeShapeCustom=function(i,r,n){var o=r.path,s=r.shape,a=r.scaleFunction||function(){return 1},l=r.rotationFunction||function(){return 0},h=r.ribbonCloseArray||!1,u=r.ribbonClosePath||!1,c=0===r.cap?0:r.cap||e.Mesh.NO_CAP,f=r.updatable,p=t.updateSideOrientation(r.sideOrientation),d=r.instance,m=r.invertUV||!1;return t._ExtrudeShapeGeneric(i,s,o,null,null,a,l,h,u,c,!0,n,!!f,p,d||null,m,r.frontUVs||null,r.backUVs||null)},t.CreateLathe=function(i,r,n){var o,s=r.arc?r.arc<=0||r.arc>1?1:r.arc:1,a=void 0===r.closed||r.closed,l=r.shape,h=r.radius||1,u=r.tessellation||64,c=r.updatable,f=t.updateSideOrientation(r.sideOrientation),p=r.cap||e.Mesh.NO_CAP,d=2*Math.PI,m=new Array,g=r.invertUV||!1,v=0,_=0,y=d/u*s,x=new Array;for(v=0;v<=u;v++){x=[];for(p!=e.Mesh.CAP_START&&p!=e.Mesh.CAP_ALL||(x.push(new e.Vector3(0,l[0].y,0)),x.push(new e.Vector3(Math.cos(v*y)*l[0].x*h,l[0].y,Math.sin(v*y)*l[0].x*h))),_=0;_<l.length;_++)o=new e.Vector3(Math.cos(v*y)*l[_].x*h,l[_].y,Math.sin(v*y)*l[_].x*h),x.push(o);p!=e.Mesh.CAP_END&&p!=e.Mesh.CAP_ALL||(x.push(new e.Vector3(Math.cos(v*y)*l[l.length-1].x*h,l[l.length-1].y,Math.sin(v*y)*l[l.length-1].x*h)),x.push(new e.Vector3(0,l[l.length-1].y,0))),m.push(x)}return t.CreateRibbon(i,{pathArray:m,closeArray:a,sideOrientation:f,updatable:c,invertUV:g,frontUVs:r.frontUVs,backUVs:r.backUVs},n)},t.CreatePlane=function(i,r,n){var o=new e.Mesh(i,n);if(r.sideOrientation=t.updateSideOrientation(r.sideOrientation),o._originalBuilderSideOrientation=r.sideOrientation,e.VertexData.CreatePlane(r).applyToMesh(o,r.updatable),r.sourcePlane){o.translate(r.sourcePlane.normal,r.sourcePlane.d);var s=Math.acos(e.Vector3.Dot(r.sourcePlane.normal,e.Axis.Z)),a=e.Vector3.Cross(e.Axis.Z,r.sourcePlane.normal);o.rotate(a,s)}return o},t.CreateGround=function(t,i,r){var n=new e.GroundMesh(t,r);return n._setReady(!1),n._subdivisionsX=i.subdivisionsX||i.subdivisions||1,n._subdivisionsY=i.subdivisionsY||i.subdivisions||1,n._width=i.width||1,n._height=i.height||1,n._maxX=n._width/2,n._maxZ=n._height/2,n._minX=-n._maxX,n._minZ=-n._maxZ,e.VertexData.CreateGround(i).applyToMesh(n,i.updatable),n._setReady(!0),n},t.CreateTiledGround=function(t,i,r){var n=new e.Mesh(t,r);return e.VertexData.CreateTiledGround(i).applyToMesh(n,i.updatable),n},t.CreateGroundFromHeightMap=function(t,i,r,n){var o=r.width||10,s=r.height||10,a=r.subdivisions||1,l=r.minHeight||0,h=r.maxHeight||1,u=r.colorFilter||new e.Color3(.3,.59,.11),c=r.updatable,f=r.onReady,p=new e.GroundMesh(t,n);p._subdivisionsX=a,p._subdivisionsY=a,p._width=o,p._height=s,p._maxX=p._width/2,p._maxZ=p._height/2,p._minX=-p._maxX,p._minZ=-p._maxZ,p._setReady(!1);return e.Tools.LoadImage(i,function(t){var i=document.createElement("canvas"),r=i.getContext("2d");if(!r)throw new Error("Unable to get 2d context for CreateGroundFromHeightMap");var n=t.width,d=t.height;i.width=n,i.height=d,r.drawImage(t,0,0);var m=r.getImageData(0,0,n,d).data;e.VertexData.CreateGroundFromHeightMap({width:o,height:s,subdivisions:a,minHeight:l,maxHeight:h,colorFilter:u,buffer:m,bufferWidth:n,bufferHeight:d}).applyToMesh(p,c),p._setReady(!0),f&&f(p)},function(){},n.database),p},t.CreatePolygon=function(i,r,n){r.sideOrientation=t.updateSideOrientation(r.sideOrientation);for(var o=r.shape,s=r.holes||[],a=r.depth||0,l=[],h=[],u=0;u<o.length;u++)l[u]=new e.Vector2(o[u].x,o[u].z);l[0].equalsWithEpsilon(l[l.length-1],1e-8)&&l.pop();for(var c=new e.PolygonMeshBuilder(i,l,n),f=0;f<s.length;f++){h=[];for(var p=0;p<s[f].length;p++)h.push(new e.Vector2(s[f][p].x,s[f][p].z));c.addHole(h)}var d=c.build(r.updatable,a);return d._originalBuilderSideOrientation=r.sideOrientation,e.VertexData.CreatePolygon(d,r.sideOrientation,r.faceUV,r.faceColors,r.frontUVs,r.backUVs).applyToMesh(d,r.updatable),d},t.ExtrudePolygon=function(e,i,r){return t.CreatePolygon(e,i,r)},t.CreateTube=function(i,r,n){var o=r.path,s=r.instance,a=1;s&&(a=s.radius),void 0!==r.radius&&(a=r.radius);var l=r.tessellation||64,h=r.radiusFunction||null,u=r.cap||e.Mesh.NO_CAP,c=r.invertUV||!1,f=r.updatable,p=t.updateSideOrientation(r.sideOrientation);r.arc=r.arc&&(r.arc<=0||r.arc>1)?1:r.arc||1;var d,m,g=function(t,i,r,n,o,s,a,l){for(var h,u,c,f,p=i.getTangents(),d=i.getNormals(),m=i.getDistances(),g=2*Math.PI/o*l,v=s||function(){return n},_=e.Tmp.Matrix[0],y=a===e.Mesh._NO_CAP||a===e.Mesh.CAP_END?0:2,x=0;x<t.length;x++){u=v(x,m[x]),h=Array(),c=d[x];for(var b=0;b<o;b++)e.Matrix.RotationAxisToRef(p[x],g*b,_),f=h[b]?h[b]:e.Vector3.Zero(),e.Vector3.TransformCoordinatesToRef(c,_,f),f.scaleInPlace(u).addInPlace(t[x]),h[b]=f;r[y]=h,y++}var T=function(e,i){for(var r=Array(),n=0;n<e;n++)r.push(t[i]);return r};switch(a){case e.Mesh.NO_CAP:break;case e.Mesh.CAP_START:r[0]=T(o,0),r[1]=r[2].slice(0);break;case e.Mesh.CAP_END:r[y]=r[y-1].slice(0),r[y+1]=T(o,t.length-1);break;case e.Mesh.CAP_ALL:r[0]=T(o,0),r[1]=r[2].slice(0),r[y]=r[y-1].slice(0),r[y+1]=T(o,t.length-1)}return r};if(s){var v=r.arc||s.arc;return d=s.path3D.update(o),m=g(o,d,s.pathArray,a,s.tessellation,h,s.cap,v),s=t.CreateRibbon("",{pathArray:m,instance:s}),s.path3D=d,s.pathArray=m,s.arc=v,s.radius=a,s}m=g(o,d=new e.Path3D(o),new Array,a,l,h,u=u<0||u>3?0:u,r.arc);var _=t.CreateRibbon(i,{pathArray:m,closePath:!0,closeArray:!1,updatable:f,sideOrientation:p,invertUV:c,frontUVs:r.frontUVs,backUVs:r.backUVs},n);return _.pathArray=m,_.path3D=d,_.tessellation=l,_.cap=u,_.arc=r.arc,_.radius=a,_},t.CreatePolyhedron=function(i,r,n){var o=new e.Mesh(i,n);return r.sideOrientation=t.updateSideOrientation(r.sideOrientation),o._originalBuilderSideOrientation=r.sideOrientation,e.VertexData.CreatePolyhedron(r).applyToMesh(o,r.updatable),o},t.CreateDecal=function(t,i,r){var n=i.getIndices(),o=i.getVerticesData(e.VertexBuffer.PositionKind),s=i.getVerticesData(e.VertexBuffer.NormalKind),a=r.position||e.Vector3.Zero(),l=r.normal||e.Vector3.Up(),h=r.size||e.Vector3.One(),u=r.angle||0;if(!l){var c=new e.Vector3(0,0,1),f=i.getScene().activeCamera,p=e.Vector3.TransformCoordinates(c,f.getWorldMatrix());l=f.globalPosition.subtract(p)}var d=-Math.atan2(l.z,l.x)-Math.PI/2,m=Math.sqrt(l.x*l.x+l.z*l.z),g=Math.atan2(l.y,m),v=e.Matrix.RotationYawPitchRoll(d,g,u).multiply(e.Matrix.Translation(a.x,a.y,a.z)),_=e.Matrix.Invert(v),y=i.getWorldMatrix().multiply(_),x=new e.VertexData;x.indices=[],x.positions=[],x.normals=[],x.uvs=[];for(var b=0,T=function(t){var i=new e.PositionNormalVertex;if(!n||!o||!s)return i;var r=n[t];return i.position=new e.Vector3(o[3*r],o[3*r+1],o[3*r+2]),i.position=e.Vector3.TransformCoordinates(i.position,y),i.normal=new e.Vector3(s[3*r],s[3*r+1],s[3*r+2]),i.normal=e.Vector3.TransformNormal(i.normal,y),i},E=function(t,i){if(0===t.length)return t;for(var r=.5*Math.abs(e.Vector3.Dot(h,i)),n=function(t,n){var o=e.Vector3.GetClipFactor(t.position,n.position,i,r);return new e.PositionNormalVertex(e.Vector3.Lerp(t.position,n.position,o),e.Vector3.Lerp(t.normal,n.normal,o))},o=new Array,s=0;s<t.length;s+=3){var a,l,u,c=null,f=null,p=null,d=null;switch(a=e.Vector3.Dot(t[s].position,i)-r>0,l=e.Vector3.Dot(t[s+1].position,i)-r>0,u=e.Vector3.Dot(t[s+2].position,i)-r>0,(a?1:0)+(l?1:0)+(u?1:0)){case 0:o.push(t[s]),o.push(t[s+1]),o.push(t[s+2]);break;case 1:if(a&&(c=t[s+1],f=t[s+2],p=n(t[s],c),d=n(t[s],f)),l){c=t[s],f=t[s+2],p=n(t[s+1],c),d=n(t[s+1],f),o.push(p),o.push(f.clone()),o.push(c.clone()),o.push(f.clone()),o.push(p.clone()),o.push(d);break}u&&(c=t[s],f=t[s+1],p=n(t[s+2],c),d=n(t[s+2],f)),c&&f&&p&&d&&(o.push(c.clone()),o.push(f.clone()),o.push(p),o.push(d),o.push(p.clone()),o.push(f.clone()));break;case 2:a||(f=n(c=t[s].clone(),t[s+1]),p=n(c,t[s+2]),o.push(c),o.push(f),o.push(p)),l||(f=n(c=t[s+1].clone(),t[s+2]),p=n(c,t[s]),o.push(c),o.push(f),o.push(p)),u||(f=n(c=t[s+2].clone(),t[s]),p=n(c,t[s+1]),o.push(c),o.push(f),o.push(p))}}return o},A=0;A<n.length;A+=3){var P=new Array;if(P.push(T(A)),P.push(T(A+1)),P.push(T(A+2)),P=E(P,new e.Vector3(1,0,0)),P=E(P,new e.Vector3(-1,0,0)),P=E(P,new e.Vector3(0,1,0)),P=E(P,new e.Vector3(0,-1,0)),P=E(P,new e.Vector3(0,0,1)),0!==(P=E(P,new e.Vector3(0,0,-1))).length)for(var S=0;S<P.length;S++){var M=P[S];x.indices.push(b),M.position.toArray(x.positions,3*b),M.normal.toArray(x.normals,3*b),x.uvs.push(.5+M.position.x/h.x),x.uvs.push(.5+M.position.y/h.y),b++}}var C=new e.Mesh(t,i.getScene());return x.applyToMesh(C),C.position=a.clone(),C.rotation=new e.Vector3(g,d,u),C},t._ExtrudeShapeGeneric=function(i,r,n,o,s,a,l,h,u,c,f,p,d,m,g,v,_,y){var x,b,T=function(t,i,r,n,o,s,a,l,h,u){for(var c=r.getTangents(),f=r.getNormals(),p=r.getBinormals(),d=r.getDistances(),m=0,g=u&&l?l:function(){return null!==s?s:0},v=u&&a?a:function(){return null!==o?o:1},_=h===e.Mesh.NO_CAP||h===e.Mesh.CAP_END?0:2,y=e.Tmp.Matrix[0],x=0;x<i.length;x++){for(var b=new Array,T=g(x,d[x]),E=v(x,d[x]),A=0;A<t.length;A++){e.Matrix.RotationAxisToRef(c[x],m,y);var P=c[x].scale(t[A].z).add(f[x].scale(t[A].x)).add(p[x].scale(t[A].y)),S=b[A]?b[A]:e.Vector3.Zero();e.Vector3.TransformCoordinatesToRef(P,y,S),S.scaleInPlace(E).addInPlace(i[x]),b[A]=S}n[_]=b,m+=T,_++}var M=function(t){var i,r=Array(),n=e.Vector3.Zero();for(i=0;i<t.length;i++)n.addInPlace(t[i]);for(n.scaleInPlace(1/t.length),i=0;i<t.length;i++)r.push(n);return r};switch(h){case e.Mesh.NO_CAP:break;case e.Mesh.CAP_START:n[0]=M(n[2]),n[1]=n[2];break;case e.Mesh.CAP_END:n[_]=n[_-1],n[_+1]=M(n[_-1]);break;case e.Mesh.CAP_ALL:n[0]=M(n[2]),n[1]=n[2],n[_]=n[_-1],n[_+1]=M(n[_-1])}return n};if(g)return x=g.path3D.update(n),b=T(r,n,g.path3D,g.pathArray,o,s,a,l,g.cap,f),g=e.Mesh.CreateRibbon("",b,!1,!1,0,p||void 0,!1,0,g);b=T(r,n,x=new e.Path3D(n),new Array,o,s,a,l,c=c<0||c>3?0:c,f);var E=t.CreateRibbon(i,{pathArray:b,closeArray:h,closePath:u,updatable:d,sideOrientation:m,invertUV:v,frontUVs:_||void 0,backUVs:y||void 0},p);return E.pathArray=b,E.path3D=x,E.cap=c,E},t}();e.MeshBuilder=t}(s||(s={}));!function(e){var t=function(){function t(){this._audioContext=null,this._audioContextInitialized=!1,this.canUseWebAudio=!1,this.WarnedWebAudioUnsupported=!1,this.unlocked=!1,this.isMP3supported=!1,this.isOGGsupported=!1,void 0===window.AudioContext&&void 0===window.webkitAudioContext||(window.AudioContext=window.AudioContext||window.webkitAudioContext,this.canUseWebAudio=!0);var e=document.createElement("audio");try{e&&e.canPlayType&&e.canPlayType('audio/mpeg; codecs="mp3"').replace(/^no$/,"")&&(this.isMP3supported=!0)}catch(e){}try{e&&e.canPlayType&&e.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,"")&&(this.isOGGsupported=!0)}catch(e){}/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(){if(e.audioContext){var i=e.audioContext.createBuffer(1,1,22050),r=e.audioContext.createBufferSource();r.buffer=i,r.connect(e.audioContext.destination),r.start(0),setTimeout(function(){r.playbackState!==r.PLAYING_STATE&&r.playbackState!==r.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._audioContext&&(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._audioContext&&(this._connectedAnalyser=e,this.masterGain.disconnect(),this._connectedAnalyser.connectAudioNodes(this.masterGain,this._audioContext.destination))},t}();e.AudioEngine=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n,o){void 0===n&&(n=null);var s=this;if(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._urlType="Unknown",this.name=t,this._scene=r,this._readyToPlayCallback=n,this._customAttenuationFunction=function(e,t,i,r,n){return t<i?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&&e.Engine.audioEngine.audioContext){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);var a=!0;if(i){"string"==typeof i&&(this._urlType="String"),Array.isArray(i)&&(this._urlType="Array"),i instanceof ArrayBuffer&&(this._urlType="ArrayBuffer");var l=[],h=!1;switch(this._urlType){case"ArrayBuffer":i.byteLength>0&&(h=!0,this._soundLoaded(i));break;case"String":l.push(i);case"Array":0===l.length&&(l=i);for(var u=0;u<l.length;u++){var c=l[u];if(-1!==c.indexOf(".mp3",c.length-4)&&e.Engine.audioEngine.isMP3supported&&(h=!0),-1!==c.indexOf(".ogg",c.length-4)&&e.Engine.audioEngine.isOGGsupported&&(h=!0),-1!==c.indexOf(".wav",c.length-4)&&(h=!0),-1!==c.indexOf("blob:")&&(h=!0),h){this._streaming?(this._htmlAudioElement=new Audio(c),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(c,function(e){s._soundLoaded(e)},void 0,this._scene.database,!0);break}}break;default:a=!1}a?h||(this._isReadyToPlay=!0,this._readyToPlayCallback&&window.setTimeout(function(){s._readyToPlayCallback&&s._readyToPlayCallback()},1e3)):e.Tools.Error("Parameter must be a URL to the sound, an Array of URLs (.mp3 & .ogg) or an ArrayBuffer of the sound.")}}else 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&&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._registerFunc&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._connectedMesh=null))},t.prototype.isReady=function(){return this._isReadyToPlay},t.prototype._soundLoaded=function(t){var i=this;this._isLoaded=!0,e.Engine.audioEngine.audioContext&&e.Engine.audioEngine.audioContext.decodeAudioData(t,function(e){i._audioBuffer=e,i._isReadyToPlay=!0,i.autoplay&&i.play(),i._readyToPlayCallback&&i._readyToPlayCallback()},function(t){e.Tools.Error("Error while decoding audio data for: "+i.name+" / Error: "+t)})},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&&(this._soundSource.playbackRate.value=this._playbackRate)))},t.prototype._createSpatialParameters=function(){e.Engine.audioEngine.canUseWebAudio&&e.Engine.audioEngine.audioContext&&(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._soundPanner&&(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&&(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,r){i<t?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=r,this._isDirectional=!0,this.isPlaying&&this.loop&&(this.stop(),this.play()))},t.prototype.setPosition=function(t){this._position=t,e.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&this._soundPanner&&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(){if(this._connectedMesh&&this._soundPanner){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&&this._soundGain&&this._scene.activeCamera){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,i){var r=this;if(this._isReadyToPlay&&this._scene.audioEnabled&&e.Engine.audioEngine.audioContext)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&&(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(){r._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(){r._onended()},this._soundSource.buffer&&this._soundSource.start(n,this.isPaused?this._startOffset%this._soundSource.buffer.duration:i||0)),this._startTime=n,this.isPlaying=!0,this.isPaused=!1}catch(t){e.Tools.Error("Error while trying to play audio: "+this.name+", "+t.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 if(e.Engine.audioEngine.audioContext&&this._soundSource){var i=t?e.Engine.audioEngine.audioContext.currentTime+t:e.Engine.audioEngine.audioContext.currentTime;this._soundSource.stop(i),this._soundSource.onended=function(){},this.isPaused||(this._startOffset=0)}this.isPlaying=!1}},t.prototype.pause=function(){this.isPlaying&&(this.isPaused=!0,this._streaming?this._htmlAudioElement.pause():e.Engine.audioEngine.audioContext&&(this.stop(0),this._startOffset+=e.Engine.audioEngine.audioContext.currentTime-this._startTime))},t.prototype.setVolume=function(t,i){e.Engine.audioEngine.canUseWebAudio&&this._soundGain&&(i&&e.Engine.audioEngine.audioContext?(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&&(this._soundSource.playbackRate.value=this._playbackRate))},t.prototype.getVolume=function(){return this._volume},t.prototype.attachToMesh=function(e){var t=this;this._connectedMesh&&this._registerFunc&&(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.detachFromMesh=function(){this._connectedMesh&&this._registerFunc&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._registerFunc=null,this._connectedMesh=null)},t.prototype._onRegisterAfterWorldMatrixUpdate=function(t){var i=t.getBoundingInfo();i&&(this.setPosition(i.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?(n._audioBuffer=e.getAudioBuffer(),n._isReadyToPlay=!0,n.autoplay&&n.play()):window.setTimeout(i,300)},r={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},n=new t(this.name+"_cloned",new ArrayBuffer(0),this._scene,null,r);return this.useCustomAttenuation&&n.setAttenuationFunction(this._customAttenuationFunction),n.setPosition(this._position),n.setPlaybackRate(this._playbackRate),i(),n},t.prototype.getAudioBuffer=function(){return this._audioBuffer},t.prototype.serialize=function(){var e={name:this.name,url:this.name,autoplay:this.autoplay,loop:this.loop,volume:this._volume,spatialSound:this.spatialSound,maxDistance:this.maxDistance,rolloffFactor:this.rolloffFactor,refDistance:this.refDistance,distanceModel:this.distanceModel,playbackRate:this._playbackRate,panningModel:this._panningModel,soundTrackId:this.soundTrackId};return this.spatialSound&&(this._connectedMesh&&(e.connectedMeshId=this._connectedMesh.id),e.position=this._position.asArray(),e.refDistance=this.refDistance,e.distanceModel=this.distanceModel,e.isDirectional=this._isDirectional,e.localDirectionToMesh=this._localDirection.asArray(),e.coneInnerAngle=this._coneInnerAngle,e.coneOuterAngle=this._coneOuterAngle,e.coneOuterGain=this._coneOuterGain),e},t.Parse=function(i,r,n,o){var s,a=i.name;s=i.url?n+i.url:n+a;var l,h={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 u=function(){o._isReadyToPlay?(l._audioBuffer=o.getAudioBuffer(),l._isReadyToPlay=!0,l.autoplay&&l.play()):window.setTimeout(u,300)};l=new t(a,new ArrayBuffer(0),r,null,h),u()}else l=new t(a,s,r,function(){r._removePendingData(l)},h),r._addPendingData(l);if(i.position){var c=e.Vector3.FromArray(i.position);l.setPosition(c)}if(i.isDirectional&&(l.setDirectionalCone(i.coneInnerAngle||360,i.coneOuterAngle||360,i.coneOuterGain||0),i.localDirectionToMesh)){var f=e.Vector3.FromArray(i.localDirectionToMesh);l.setLocalDirectionToMesh(f)}if(i.connectedMeshId){var p=r.getMeshByID(i.connectedMeshId);p&&l.attachToMesh(p)}return l},t}();e.Sound=t}(s||(s={}));!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&&e.Engine.audioEngine.audioContext&&(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&&this._outputAudioNode&&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&&(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&&(this._outputAudioNode.disconnect(),this._connectedAnalyser.connectAudioNodes(this._outputAudioNode,e.Engine.audioEngine.masterGain))},t}();e.SoundTrack=t}(s||(s={}));!function(e){var t=function(){function t(t){this.SMOOTHING=.75,this.FFT_SIZE=512,this.BARGRAPHAMPLITUDE=256,this.DEBUGCANVASPOS={x:20,y:20},this.DEBUGCANVASSIZE={width:320,height:200},this._scene=t,this._audioEngine=e.Engine.audioEngine,this._audioEngine.canUseWebAudio&&this._audioEngine.audioContext&&(this._webAudioAnalyser=this._audioEngine.audioContext.createAnalyser(),this._webAudioAnalyser.minDecibels=-140,this._webAudioAnalyser.maxDecibels=0,this._byteFreqs=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._byteTime=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._floatFreqs=new Float32Array(this._webAudioAnalyser.frequencyBinCount))}return t.prototype.getFrequencyBinCount=function(){return this._audioEngine.canUseWebAudio?this._webAudioAnalyser.frequencyBinCount:0},t.prototype.getByteFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteFrequencyData(this._byteFreqs)),this._byteFreqs},t.prototype.getByteTimeDomainData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteTimeDomainData(this._byteTime)),this._byteTime},t.prototype.getFloatFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getFloatFrequencyData(this._floatFreqs)),this._floatFreqs},t.prototype.drawDebugCanvas=function(){var e=this;if(this._audioEngine.canUseWebAudio&&(this._debugCanvas||(this._debugCanvas=document.createElement("canvas"),this._debugCanvas.width=this.DEBUGCANVASSIZE.width,this._debugCanvas.height=this.DEBUGCANVASSIZE.height,this._debugCanvas.style.position="absolute",this._debugCanvas.style.top=this.DEBUGCANVASPOS.y+"px",this._debugCanvas.style.left=this.DEBUGCANVASPOS.x+"px",this._debugCanvasContext=this._debugCanvas.getContext("2d"),document.body.appendChild(this._debugCanvas),this._registerFunc=function(){e.drawDebugCanvas()},this._scene.registerBeforeRender(this._registerFunc)),this._registerFunc&&this._debugCanvasContext)){var t=this.getByteFrequencyData();this._debugCanvasContext.fillStyle="rgb(0, 0, 0)",this._debugCanvasContext.fillRect(0,0,this.DEBUGCANVASSIZE.width,this.DEBUGCANVASSIZE.height);for(var i=0;i<this.getFrequencyBinCount();i++){var r=t[i]/this.BARGRAPHAMPLITUDE,n=this.DEBUGCANVASSIZE.height*r,o=this.DEBUGCANVASSIZE.height-n-1,s=this.DEBUGCANVASSIZE.width/this.getFrequencyBinCount(),a=i/this.getFrequencyBinCount()*360;this._debugCanvasContext.fillStyle="hsl("+a+", 100%, 50%)",this._debugCanvasContext.fillRect(i*s,o,s,n)}}},t.prototype.stopDebugCanvas=function(){this._debugCanvas&&(this._registerFunc&&(this._scene.unregisterBeforeRender(this._registerFunc),this._registerFunc=null),document.body.removeChild(this._debugCanvas),this._debugCanvas=null,this._debugCanvasContext=null)},t.prototype.connectAudioNodes=function(e,t){this._audioEngine.canUseWebAudio&&(e.connect(this._webAudioAnalyser),this._webAudioAnalyser.connect(t))},t.prototype.dispose=function(){this._audioEngine.canUseWebAudio&&this._webAudioAnalyser.disconnect()},t}();e.Analyser=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l,h,u,c){void 0===n&&(n=null),void 0===o&&(o=!1),void 0===s&&(s=null),void 0===a&&(a=null),void 0===l&&(l=null),void 0===h&&(h=e.Engine.TEXTUREFORMAT_RGBA),void 0===u&&(u=!1),void 0===c&&(c=null);var f=t.call(this,r)||this;if(f.coordinatesMode=e.Texture.CUBIC_MODE,f.name=i,f.url=i,f._noMipmap=o,f.hasAlpha=!1,f._format=h,f._prefiltered=u,f.isCube=!0,f._textureMatrix=e.Matrix.Identity(),u&&(f.gammaSpace=!1),!i&&!s)return f;if(f._texture=f._getFromCache(i,o),!s){n||(n=["_px.jpg","_py.jpg","_pz.jpg","_nx.jpg","_ny.jpg","_nz.jpg"]),s=[];for(var p=0;p<n.length;p++)s.push(i+n[p]);f._extensions=n}return f._files=s,f._texture?a&&(f._texture.isReady?e.Tools.SetImmediate(function(){return a()}):f._texture.onLoadedObservable.add(a)):r.useDelayedTextureLoading?f.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:f._texture=u?r.getEngine().createPrefilteredCubeTexture(i,r,f.lodGenerationScale,f.lodGenerationOffset,a,l,h,c):r.getEngine().createCubeTexture(i,r,s,o,a,l,f._format,c),f}return n(i,t),i.CreateFromImages=function(e,t,r){return new i("",t,null,r,e)},i.CreateFromPrefilteredData=function(e,t,r){return void 0===r&&(r=null),new i(e,t,null,!1,null,null,null,void 0,!0,r)},i.prototype.delayLoad=function(){if(this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED){var t=this.getScene();t&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap),this._texture||(this._prefiltered?this._texture=t.getEngine().createPrefilteredCubeTexture(this.url,t,this.lodGenerationScale,this.lodGenerationOffset,void 0,void 0,this._format):this._texture=t.getEngine().createCubeTexture(this.url,t,this._files,this._noMipmap,void 0,void 0,this._format)))}},i.prototype.getReflectionTextureMatrix=function(){return this._textureMatrix},i.prototype.setReflectionTextureMatrix=function(e){this._textureMatrix=e},i.Parse=function(t,i,r){var n=e.SerializationHelper.Parse(function(){return new e.CubeTexture(r+t.name,i,t.extensions)},t,i);if(t.animations)for(var o=0;o<t.animations.length;o++){var s=t.animations[o];n.animations.push(e.Animation.Parse(s))}return n},i.prototype.clone=function(){var t=this;return e.SerializationHelper.Clone(function(){var e=t.getScene();return e?new i(t.url,e,t._extensions,t._noMipmap,t._files):t},this)},i}(e.BaseTexture);e.CubeTexture=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l,h,u,c,f){void 0===s&&(s=!0),void 0===a&&(a=e.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===l&&(l=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===u&&(u=!0),void 0===c&&(c=!1),void 0===f&&(f=!1);var p=t.call(this,null,n,!o)||this;return p.isCube=l,p.renderList=new Array,p.renderParticles=!0,p.renderSprites=!1,p.coordinatesMode=e.Texture.PROJECTION_MODE,p.ignoreCameraViewport=!1,p.onBeforeBindObservable=new e.Observable,p.onAfterUnbindObservable=new e.Observable,p.onBeforeRenderObservable=new e.Observable,p.onAfterRenderObservable=new e.Observable,p.onClearObservable=new e.Observable,p._currentRefreshId=-1,p._refreshRate=1,p._samples=1,(n=p.getScene())?(p._engine=n.getEngine(),p.name=i,p.isRenderTarget=!0,p._initialSizeParameter=r,p._processSizeParameter(r),p._resizeObserver=p.getScene().getEngine().onResizeObservable.add(function(){}),p._generateMipMaps=!!o,p._doNotChangeAspectRatio=s,p._renderingManager=new e.RenderingManager(n),f?p:(p._renderTargetOptions={generateMipMaps:o,type:a,samplingMode:h,generateDepthBuffer:u,generateStencilBuffer:c},h===e.Texture.NEAREST_SAMPLINGMODE&&(p.wrapU=e.Texture.CLAMP_ADDRESSMODE,p.wrapV=e.Texture.CLAMP_ADDRESSMODE),l?(p._texture=n.getEngine().createRenderTargetCubeTexture(p.getRenderSize(),p._renderTargetOptions),p.coordinatesMode=e.Texture.INVCUBIC_MODE,p._textureMatrix=e.Matrix.Identity()):p._texture=n.getEngine().createRenderTargetTexture(p._size,p._renderTargetOptions),p)):p}return n(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}),Object.defineProperty(i.prototype,"onAfterUnbind",{set:function(e){this._onAfterUnbindObserver&&this.onAfterUnbindObservable.remove(this._onAfterUnbindObserver),this._onAfterUnbindObserver=this.onAfterUnbindObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onBeforeRender",{set:function(e){this._onBeforeRenderObserver&&this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver),this._onBeforeRenderObserver=this.onBeforeRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onAfterRender",{set:function(e){this._onAfterRenderObserver&&this.onAfterRenderObservable.remove(this._onAfterRenderObserver),this._onAfterRenderObserver=this.onAfterRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onClear",{set:function(e){this._onClearObserver&&this.onClearObservable.remove(this._onClearObserver),this._onClearObserver=this.onClearObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"renderTargetOptions",{get:function(){return this._renderTargetOptions},enumerable:!0,configurable:!0}),i.prototype._onRatioRescale=function(){this._sizeRatio&&this.resize(this._initialSizeParameter)},i.prototype._processSizeParameter=function(e){e.ratio?(this._sizeRatio=e.ratio,this._size={width:this._bestReflectionRenderTargetDimension(this._engine.getRenderWidth(),this._sizeRatio),height:this._bestReflectionRenderTargetDimension(this._engine.getRenderHeight(),this._sizeRatio)}):this._size=e},Object.defineProperty(i.prototype,"samples",{get:function(){return this._samples},set:function(e){if(this._samples!==e){var t=this.getScene();t&&(this._samples=t.getEngine().updateRenderTargetTextureSampleCount(this._texture,e))}},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.addPostProcess=function(t){if(!this._postProcessManager){var i=this.getScene();if(!i)return;this._postProcessManager=new e.PostProcessManager(i),this._postProcesses=new Array}this._postProcesses.push(t),this._postProcesses[0].autoClear=!1},i.prototype.clearPostProcesses=function(e){if(this._postProcesses){if(e)for(var t=0,i=this._postProcesses;t<i.length;t++)i[t].dispose();this._postProcesses=[]}},i.prototype.removePostProcess=function(e){if(this._postProcesses){var t=this._postProcesses.indexOf(e);-1!==t&&(this._postProcesses.splice(t,1),this._postProcesses.length>0&&(this._postProcesses[0].autoClear=!1))}},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.getRenderSize=function(){return this._size.width?this._size.width:this._size},i.prototype.getRenderWidth=function(){return this._size.width?this._size.width:this._size},i.prototype.getRenderHeight=function(){return this._size.width?this._size.height:this._size},Object.defineProperty(i.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),i.prototype.scale=function(e){var t=this.getRenderSize()*e;this.resize(t)},i.prototype.getReflectionTextureMatrix=function(){return this.isCube?this._textureMatrix:t.prototype.getReflectionTextureMatrix.call(this)},i.prototype.resize=function(e){this.releaseInternalTexture();var t=this.getScene();t&&(this._processSizeParameter(e),this.isCube?this._texture=t.getEngine().createRenderTargetCubeTexture(this.getRenderSize(),this._renderTargetOptions):this._texture=t.getEngine().createRenderTargetTexture(this._size,this._renderTargetOptions))},i.prototype.render=function(e,t){void 0===e&&(e=!1),void 0===t&&(t=!1);var i=this.getScene();if(i){var r=i.getEngine();if(void 0!==this.useCameraPostProcesses&&(e=this.useCameraPostProcesses),this._waitingRenderList){this.renderList=[];for(a=0;a<this._waitingRenderList.length;a++){var n=this._waitingRenderList[a],o=i.getMeshByID(n);o&&this.renderList.push(o)}delete this._waitingRenderList}if(this.renderListPredicate){if(this.renderList?this.renderList.splice(0):this.renderList=[],!(i=this.getScene()))return;for(var s=i.meshes,a=0;a<s.length;a++){var l=s[a];this.renderListPredicate(l)&&this.renderList.push(l)}}this.onBeforeBindObservable.notifyObservers(this);var h;this.activeCamera?(h=this.activeCamera,r.setViewport(this.activeCamera.viewport,this.getRenderWidth(),this.getRenderHeight()),this.activeCamera!==i.activeCamera&&i.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(!0))):(h=i.activeCamera)&&r.setViewport(h.viewport,this.getRenderWidth(),this.getRenderHeight()),this._renderingManager.reset();for(var u=this.renderList?this.renderList:i.getActiveMeshes().data,c=this.renderList?this.renderList.length:i.getActiveMeshes().length,f=i.getRenderId(),p=0;p<c;p++)if(l=u[p]){if(!l.isReady()){this.resetRefreshCounter();continue}l._preActivateForIntermediateRendering(f);var d=void 0;if(d=!(this.renderList||!h)&&0==(l.layerMask&h.layerMask),l.isEnabled()&&l.isVisible&&l.subMeshes&&!d){l._activate(f);for(var m=0;m<l.subMeshes.length;m++){var g=l.subMeshes[m];i._activeIndices.addCount(g.indexCount,!1),this._renderingManager.dispatch(g)}}}for(var v=0;v<i.particleSystems.length;v++){var _=i.particleSystems[v],y=_.emitter;_.isStarted()&&y&&y.position&&y.isEnabled()&&(u.indexOf(y)>=0&&this._renderingManager.dispatchParticles(_))}if(this.isCube)for(var x=0;x<6;x++)this.renderToTarget(x,u,c,e,t),i.incrementRenderId(),i.resetCachedMaterial();else this.renderToTarget(0,u,c,e,t);this.onAfterUnbindObservable.notifyObservers(this),i.activeCamera&&(this.activeCamera&&this.activeCamera!==i.activeCamera&&i.setTransformMatrix(i.activeCamera.getViewMatrix(),i.activeCamera.getProjectionMatrix(!0)),r.setViewport(i.activeCamera.viewport)),i.resetCachedMaterial()}},i.prototype._bestReflectionRenderTargetDimension=function(t,i){var r=t*i,n=e.Tools.NearestPOT(r+16384/(128+r));return Math.min(e.Tools.FloorPOT(t),n)},i.prototype.renderToTarget=function(t,i,r,n,o){var s=this,a=this.getScene();if(a){var l=a.getEngine();this._texture&&(this._postProcessManager?this._postProcessManager._prepareFrame(this._texture,this._postProcesses):n&&a.postProcessManager._prepareFrame(this._texture)||this._texture&&l.bindFramebuffer(this._texture,this.isCube?t:void 0,void 0,void 0,this.ignoreCameraViewport),this.onBeforeRenderObservable.notifyObservers(t),this.onClearObservable.hasObservers()?this.onClearObservable.notifyObservers(l):l.clear(this.clearColor||a.clearColor,!0,!0,!0),this._doNotChangeAspectRatio||a.updateTransformMatrix(!0),this._renderingManager.render(this.customRenderFunction,i,this.renderParticles,this.renderSprites),this._postProcessManager?this._postProcessManager._finalizeFrame(!1,this._texture,t,this._postProcesses,this.ignoreCameraViewport):n&&a.postProcessManager._finalizeFrame(!1,this._texture,t),this._doNotChangeAspectRatio||a.updateTransformMatrix(!0),o&&e.Tools.DumpFramebuffer(this.getRenderWidth(),this.getRenderHeight(),l),this.isCube&&5!==t?this.onAfterRenderObservable.notifyObservers(t):(this.isCube&&5===t&&l.generateMipMapsForCubemap(this._texture),l.unBindFramebuffer(this._texture,this.isCube,function(){s.onAfterRenderObservable.notifyObservers(t)})))}},i.prototype.setRenderingOrder=function(e,t,i,r){void 0===t&&(t=null),void 0===i&&(i=null),void 0===r&&(r=null),this._renderingManager.setRenderingOrder(e,t,i,r)},i.prototype.setRenderingAutoClearDepthStencil=function(e,t){this._renderingManager.setRenderingAutoClearDepthStencil(e,t)},i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this.getScene(),this._renderTargetOptions.generateMipMaps,this._doNotChangeAspectRatio,this._renderTargetOptions.type,this.isCube,this._renderTargetOptions.samplingMode,this._renderTargetOptions.generateDepthBuffer,this._renderTargetOptions.generateStencilBuffer);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.coordinatesMode=this.coordinatesMode,this.renderList&&(t.renderList=this.renderList.slice(0)),t},i.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);if(e.renderTargetSize=this.getRenderSize(),e.renderList=[],this.renderList)for(var i=0;i<this.renderList.length;i++)e.renderList.push(this.renderList[i].id);return e},i.prototype.disposeFramebufferObjects=function(){var e=this.getInternalTexture(),t=this.getScene();e&&t&&t.getEngine()._releaseFramebufferObjects(e)},i.prototype.dispose=function(){this._postProcessManager&&(this._postProcessManager.dispose(),this._postProcessManager=null),this.clearPostProcesses(!0),this._resizeObserver&&(this.getScene().getEngine().onResizeObservable.remove(this._resizeObserver),this._resizeObserver=null),this.renderList=null;var e=this.getScene();if(e){var i=e.customRenderTargets.indexOf(this);i>=0&&e.customRenderTargets.splice(i,1);for(var r=0,n=e.cameras;r<n.length;r++){var o=n[r];(i=o.customRenderTargets.indexOf(this))>=0&&o.customRenderTargets.splice(i,1)}t.prototype.dispose.call(this)}},i.prototype._rebuild=function(){this.refreshRate===i.REFRESHRATE_RENDER_ONCE&&(this.refreshRate=i.REFRESHRATE_RENDER_ONCE),this._postProcessManager&&this._postProcessManager._rebuild()},i._REFRESHRATE_RENDER_ONCE=0,i._REFRESHRATE_RENDER_ONEVERYFRAME=1,i._REFRESHRATE_RENDER_ONEVERYTWOFRAMES=2,i}(e.Texture);e.RenderTargetTexture=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s){var a=this,l=!!(s=s||{}).generateMipMaps&&s.generateMipMaps,h=!!s.generateDepthTexture&&s.generateDepthTexture,u=void 0===s.doNotChangeAspectRatio||s.doNotChangeAspectRatio;if((a=t.call(this,i,r,o,l,u)||this)._engine=o.getEngine(),a.isSupported){for(var c=[],f=[],p=0;p<n;p++)s.types&&s.types[p]?c.push(s.types[p]):c.push(e.Engine.TEXTURETYPE_FLOAT),s.samplingModes&&s.samplingModes[p]?f.push(s.samplingModes[p]):f.push(e.Texture.BILINEAR_SAMPLINGMODE);var d=void 0===s.generateDepthBuffer||s.generateDepthBuffer,m=void 0!==s.generateStencilBuffer&&s.generateStencilBuffer;return a._count=n,a._size=r,a._multiRenderTargetOptions={samplingModes:f,generateMipMaps:l,generateDepthBuffer:d,generateStencilBuffer:m,generateDepthTexture:h,types:c,textureCount:n},a._createInternalTextures(),a._createTextures(),a}a.dispose()}return n(i,t),Object.defineProperty(i.prototype,"isSupported",{get:function(){return this._engine.webGLVersion>1||this._engine.getCaps().drawBuffersExtension},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"textures",{get:function(){return this._textures},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"depthTexture",{get:function(){return this._textures[this._textures.length-1]},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"wrapU",{set:function(e){if(this._textures)for(var t=0;t<this._textures.length;t++)this._textures[t].wrapU=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"wrapV",{set:function(e){if(this._textures)for(var t=0;t<this._textures.length;t++)this._textures[t].wrapV=e},enumerable:!0,configurable:!0}),i.prototype._rebuild=function(){this.releaseInternalTextures(),this._createInternalTextures();for(var e=0;e<this._internalTextures.length;e++)this._textures[e]._texture=this._internalTextures[e];this._texture=this._internalTextures[0]},i.prototype._createInternalTextures=function(){this._internalTextures=this._engine.createMultipleRenderTarget(this._size,this._multiRenderTargetOptions)},i.prototype._createTextures=function(){this._textures=[];for(var t=0;t<this._internalTextures.length;t++){var i=new e.Texture(null,this.getScene());i._texture=this._internalTextures[t],this._textures.push(i)}this._texture=this._internalTextures[0]},Object.defineProperty(i.prototype,"samples",{get:function(){return this._samples},set:function(e){if(this._samples!==e)for(var t=0;t<this._internalTextures.length;t++)this._samples=this._engine.updateRenderTargetTextureSampleCount(this._internalTextures[t],e)},enumerable:!0,configurable:!0}),i.prototype.resize=function(e){this.releaseInternalTextures(),this._internalTextures=this._engine.createMultipleRenderTarget(e,this._multiRenderTargetOptions),this._createInternalTextures()},i.prototype.dispose=function(){this.releaseInternalTextures(),t.prototype.dispose.call(this)},i.prototype.releaseInternalTextures=function(){if(this._internalTextures)for(var e=this._internalTextures.length-1;e>=0;e--)void 0!==this._internalTextures[e]&&(this._internalTextures[e].dispose(),this._internalTextures.splice(e,1))},i}(e.RenderTargetTexture);e.MultiRenderTarget=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l){void 0===s&&(s=e.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE),void 0===l&&(l=!0);var h=t.call(this,i,r,n,o,!0,s,!1,a,l)||this;return h.mirrorPlane=new e.Plane(0,1,0,1),h._transformMatrix=e.Matrix.Zero(),h._mirrorMatrix=e.Matrix.Zero(),h._adaptiveBlurKernel=0,h._blurKernelX=0,h._blurKernelY=0,h._blurRatio=1,h.ignoreCameraViewport=!0,h.onBeforeRenderObservable.add(function(){e.Matrix.ReflectionToRef(h.mirrorPlane,h._mirrorMatrix),h._savedViewMatrix=n.getViewMatrix(),h._mirrorMatrix.multiplyToRef(h._savedViewMatrix,h._transformMatrix),n.setTransformMatrix(h._transformMatrix,n.getProjectionMatrix()),n.clipPlane=h.mirrorPlane,n.getEngine().cullBackFaces=!1,n._mirroredCameraPosition=e.Vector3.TransformCoordinates(n.activeCamera.globalPosition,h._mirrorMatrix)}),h.onAfterRenderObservable.add(function(){n.setTransformMatrix(h._savedViewMatrix,n.getProjectionMatrix()),n.getEngine().cullBackFaces=!0,n._mirroredCameraPosition=null,delete n.clipPlane}),h}return n(i,t),Object.defineProperty(i.prototype,"blurRatio",{get:function(){return this._blurRatio},set:function(e){this._blurRatio!==e&&(this._blurRatio=e,this._preparePostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"adaptiveBlurKernel",{set:function(e){this._adaptiveBlurKernel=e,this._autoComputeBlurKernel()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"blurKernel",{set:function(e){this.blurKernelX=e,this.blurKernelY=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"blurKernelX",{get:function(){return this._blurKernelX},set:function(e){this._blurKernelX!==e&&(this._blurKernelX=e,this._preparePostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"blurKernelY",{get:function(){return this._blurKernelY},set:function(e){this._blurKernelY!==e&&(this._blurKernelY=e,this._preparePostProcesses())},enumerable:!0,configurable:!0}),i.prototype._autoComputeBlurKernel=function(){var e=this.getScene().getEngine(),t=this.getRenderWidth()/e.getRenderWidth(),i=this.getRenderHeight()/e.getRenderHeight();this.blurKernelX=this._adaptiveBlurKernel*t,this.blurKernelY=this._adaptiveBlurKernel*i},i.prototype._onRatioRescale=function(){this._sizeRatio&&(this.resize(this._initialSizeParameter),this._adaptiveBlurKernel||this._preparePostProcesses()),this._adaptiveBlurKernel&&this._autoComputeBlurKernel()},i.prototype._preparePostProcesses=function(){if(this.clearPostProcesses(!0),this._blurKernelX&&this._blurKernelY){var t=this.getScene().getEngine(),i=t.getCaps().textureFloatRender?e.Engine.TEXTURETYPE_FLOAT:e.Engine.TEXTURETYPE_HALF_FLOAT;this._blurX=new e.BlurPostProcess("horizontal blur",new e.Vector2(1,0),this._blurKernelX,this._blurRatio,null,e.Texture.BILINEAR_SAMPLINGMODE,t,!1,i),this._blurX.autoClear=!1,1===this._blurRatio&&this.samples<2&&this._texture?this._blurX.outputTexture=this._texture:this._blurX.alwaysForcePOT=!0,this._blurY=new e.BlurPostProcess("vertical blur",new e.Vector2(0,1),this._blurKernelY,this._blurRatio,null,e.Texture.BILINEAR_SAMPLINGMODE,t,!1,i),this._blurY.autoClear=!1,this._blurY.alwaysForcePOT=1!==this._blurRatio,this.addPostProcess(this._blurX),this.addPostProcess(this._blurY)}else this._blurY&&(this.removePostProcess(this._blurY),this._blurY.dispose(),this._blurY=null),this._blurX&&(this.removePostProcess(this._blurX),this._blurX.dispose(),this._blurX=null)},i.prototype.clone=function(){var e=this.getScene();if(!e)return this;var t=this.getSize(),r=new i(this.name,t.width,e,this._renderTargetOptions.generateMipMaps,this._renderTargetOptions.type,this._renderTargetOptions.samplingMode,this._renderTargetOptions.generateDepthBuffer);return r.hasAlpha=this.hasAlpha,r.level=this.level,r.mirrorPlane=this.mirrorPlane.clone(),this.renderList&&(r.renderList=this.renderList.slice(0)),r},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}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o){var s=t.call(this,i,r,n,o,!0)||this;return s.refractionPlane=new e.Plane(0,1,0,1),s.depth=2,s.onBeforeRenderObservable.add(function(){n.clipPlane=s.refractionPlane}),s.onAfterRenderObservable.add(function(){delete n.clipPlane}),s}return n(i,t),i.prototype.clone=function(){var e=this.getScene();if(!e)return this;var t=this.getSize(),r=new i(this.name,t.width,e,this._generateMipMaps);return r.hasAlpha=this.hasAlpha,r.level=this.level,r.refractionPlane=this.refractionPlane.clone(),this.renderList&&(r.renderList=this.renderList.slice(0)),r.depth=this.depth,r},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}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a){void 0===n&&(n=null),void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=e.Engine.TEXTUREFORMAT_RGBA);var l=t.call(this,null,n,!o,void 0,s,void 0,void 0,void 0,void 0,a)||this;l.name=i,l._engine=l.getScene().getEngine(),l.wrapU=e.Texture.CLAMP_ADDRESSMODE,l.wrapV=e.Texture.CLAMP_ADDRESSMODE,l._generateMipMaps=o,r.getContext?(l._canvas=r,l._texture=l._engine.createDynamicTexture(r.width,r.height,o,s)):(l._canvas=document.createElement("canvas"),r.width?l._texture=l._engine.createDynamicTexture(r.width,r.height,o,s):l._texture=l._engine.createDynamicTexture(r,r,o,s));var h=l.getSize();return l._canvas.width=h.width,l._canvas.height=h.height,l._context=l._canvas.getContext("2d"),l}return n(i,t),Object.defineProperty(i.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),i.prototype._recreate=function(e){this._canvas.width=e.width,this._canvas.height=e.height,this.releaseInternalTexture(),this._texture=this._engine.createDynamicTexture(e.width,e.height,this._generateMipMaps,this._samplingMode)},i.prototype.scale=function(e){var t=this.getSize();t.width*=e,t.height*=e,this._recreate(t)},i.prototype.scaleTo=function(e,t){var i=this.getSize();i.width=e,i.height=t,this._recreate(i)},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._engine.updateDynamicTexture(this._texture,this._canvas,void 0===e||e,void 0,this._format||void 0)},i.prototype.drawText=function(e,t,i,r,n,o,s,a){void 0===a&&(a=!0);var l=this.getSize();if(o&&(this._context.fillStyle=o,this._context.fillRect(0,0,l.width,l.height)),this._context.font=r,null===t||void 0===t){var h=this._context.measureText(e);t=(l.width-h.width)/2}if(null===i||void 0===i){var u=parseInt(r.replace(/\D/g,""));i=l.height/2+u/3.65}this._context.fillStyle=n,this._context.fillText(e,t,i),a&&this.update(s)},i.prototype.clone=function(){var e=this.getScene();if(!e)return this;var t=this.getSize(),r=new i(this.name,t,e,this._generateMipMaps);return r.hasAlpha=this.hasAlpha,r.level=this.level,r.wrapU=this.wrapU,r.wrapV=this.wrapV,r},i.prototype._rebuild=function(){this.update()},i}(e.Texture);e.DynamicTexture=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a){void 0===o&&(o=!1),void 0===s&&(s=!1),void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE);var l=t.call(this,null,n,!o,s)||this;l._autoLaunch=!0;var h=null;return l.name=i,r instanceof HTMLVideoElement?l.video=r:(h=r,l.video=document.createElement("video"),l.video.autoplay=!1,l.video.loop=!0),l._engine=l.getScene().getEngine(),l._generateMipMaps=o,l._samplingMode=a,!l._engine.needPOTTextures||e.Tools.IsExponentOfTwo(l.video.videoWidth)&&e.Tools.IsExponentOfTwo(l.video.videoHeight)?(l.wrapU=e.Texture.WRAP_ADDRESSMODE,l.wrapV=e.Texture.WRAP_ADDRESSMODE):(l.wrapU=e.Texture.CLAMP_ADDRESSMODE,l.wrapV=e.Texture.CLAMP_ADDRESSMODE,l._generateMipMaps=!1),h?(l.video.addEventListener("canplay",function(){l._createTexture()}),h.forEach(function(e){var t=document.createElement("source");t.src=e,l.video.appendChild(t)})):l._createTexture(),l._lastUpdate=e.Tools.Now,l}return n(i,t),i.prototype.__setTextureReady=function(){this._texture&&(this._texture.isReady=!0)},i.prototype._createTexture=function(){this._texture=this._engine.createDynamicTexture(this.video.videoWidth,this.video.videoHeight,this._generateMipMaps,this._samplingMode),this._autoLaunch&&(this._autoLaunch=!1,this.video.play()),this._setTextureReady=this.__setTextureReady.bind(this),this.video.addEventListener("playing",this._setTextureReady)},i.prototype._rebuild=function(){this.update()},i.prototype.update=function(){var t=e.Tools.Now;return!(t-this._lastUpdate<15||this.video.readyState!==this.video.HAVE_ENOUGH_DATA)&&(this._lastUpdate=t,this._engine.updateVideoTexture(this._texture,this.video,this._invertY),!0)},i.prototype.dispose=function(){t.prototype.dispose.call(this),this.video.removeEventListener("playing",this._setTextureReady)},i.CreateFromWebCam=function(t,i,r){var n,o=document.createElement("video");r&&r.deviceId&&(n={exact:r.deviceId}),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,window.URL=window.URL||window.webkitURL||window.mozURL||window.msURL,navigator.getUserMedia&&navigator.getUserMedia({video:{deviceId:n,width:{min:r&&r.minWidth||256,max:r&&r.maxWidth||640},height:{min:r&&r.minHeight||256,max:r&&r.maxHeight||480}}},function(r){void 0!==o.mozSrcObject?o.mozSrcObject=r:o.src=window.URL&&window.URL.createObjectURL(r)||r,o.play(),i&&i(new e.VideoTexture("video",o,t,!0,!0))},function(t){e.Tools.Error(t.name)})},i}(e.Texture);e.VideoTexture=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l,h){void 0===a&&(a=!0),void 0===l&&(l=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE);var u=t.call(this,null,s,!a,l)||this;return u.format=o,u._engine=s.getEngine(),u._texture=s.getEngine().createRawTexture(i,r,n,o,a,l,h),u.wrapU=e.Texture.CLAMP_ADDRESSMODE,u.wrapV=e.Texture.CLAMP_ADDRESSMODE,u}return n(i,t),i.prototype.update=function(e){this._engine.updateRawTexture(this._texture,e,this.format,this._invertY)},i.CreateLuminanceTexture=function(t,r,n,o,s,a,l){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_LUMINANCE,o,s,a,l)},i.CreateLuminanceAlphaTexture=function(t,r,n,o,s,a,l){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA,o,s,a,l)},i.CreateAlphaTexture=function(t,r,n,o,s,a,l){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_ALPHA,o,s,a,l)},i.CreateRGBTexture=function(t,r,n,o,s,a,l){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_RGB,o,s,a,l)},i.CreateRGBATexture=function(t,r,n,o,s,a,l){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_RGBA,o,s,a,l)},i}(e.Texture);e.RawTexture=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n,o,s,a,l,h,u,c,f,p,d){void 0===a&&(a=e.Texture.NEAREST_SAMPLINGMODE),void 0===u&&(u=null),void 0===c&&(c=e.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===f&&(f="postprocess"),void 0===d&&(d=!1),this.name=t,this.width=-1,this.height=-1,this.autoClear=!0,this.alphaMode=e.Engine.ALPHA_DISABLE,this.enablePixelPerfectMode=!1,this.scaleMode=e.Engine.SCALEMODE_FLOOR,this.alwaysForcePOT=!1,this.samples=1,this.adaptScaleToCurrentViewport=!1,this._reusable=!1,this._textures=new e.SmartArray(2),this._currentRenderTextureInd=0,this._scaleRatio=new e.Vector2(1,1),this._texelSize=e.Vector2.Zero(),this.onActivateObservable=new e.Observable,this.onSizeChangedObservable=new e.Observable,this.onApplyObservable=new e.Observable,this.onBeforeRenderObservable=new e.Observable,this.onAfterRenderObservable=new e.Observable,null!=s?(this._camera=s,this._scene=s.getScene(),s.attachPostProcess(this),this._engine=this._scene.getEngine(),this._scene.postProcesses.push(this)):l&&(this._engine=l,this._engine.postProcesses.push(this)),this._options=o,this.renderTargetSamplingMode=a||e.Texture.NEAREST_SAMPLINGMODE,this._reusable=h||!1,this._textureType=c,this._samplers=n||[],this._samplers.push("textureSampler"),this._fragmentUrl=i,this._vertexUrl=f,this._parameters=r||[],this._parameters.push("scale"),this._indexParameters=p,d||this.updateEffect(u)}return Object.defineProperty(t.prototype,"onActivate",{set:function(e){this._onActivateObserver&&this.onActivateObservable.remove(this._onActivateObserver),e&&(this._onActivateObserver=this.onActivateObservable.add(e))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onSizeChanged",{set:function(e){this._onSizeChangedObserver&&this.onSizeChangedObservable.remove(this._onSizeChangedObserver),this._onSizeChangedObserver=this.onSizeChangedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onApply",{set:function(e){this._onApplyObserver&&this.onApplyObservable.remove(this._onApplyObserver),this._onApplyObserver=this.onApplyObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onBeforeRender",{set:function(e){this._onBeforeRenderObserver&&this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver),this._onBeforeRenderObserver=this.onBeforeRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onAfterRender",{set:function(e){this._onAfterRenderObserver&&this.onAfterRenderObservable.remove(this._onAfterRenderObserver),this._onAfterRenderObserver=this.onAfterRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"outputTexture",{get:function(){return this._textures.data[this._currentRenderTextureInd]},set:function(e){this._forcedOutputTexture=e},enumerable:!0,configurable:!0}),t.prototype.getCamera=function(){return this._camera},Object.defineProperty(t.prototype,"texelSize",{get:function(){return this._shareOutputWithPostProcess?this._shareOutputWithPostProcess.texelSize:(this._forcedOutputTexture&&this._texelSize.copyFromFloats(1/this._forcedOutputTexture.width,1/this._forcedOutputTexture.height),this._texelSize)},enumerable:!0,configurable:!0}),t.prototype.getEngine=function(){return this._engine},t.prototype.getEffect=function(){return this._effect},t.prototype.shareOutputWith=function(e){return this._disposeTextures(),this._shareOutputWithPostProcess=e,this},t.prototype.updateEffect=function(e,t,i,r,n,o){void 0===e&&(e=null),void 0===t&&(t=null),void 0===i&&(i=null),this._effect=this._engine.createEffect({vertex:this._vertexUrl,fragment:this._fragmentUrl},["position"],t||this._parameters,i||this._samplers,null!==e?e:"",void 0,n,o,r||this._indexParameters)},t.prototype.isReusable=function(){return this._reusable},t.prototype.markTextureDirty=function(){this.width=-1},t.prototype.activate=function(t,i,r){var n=this;void 0===i&&(i=null);var o=(t=t||this._camera).getScene(),s=o.getEngine(),a=s.getCaps().maxTextureSize,l=(i?i.width:this._engine.getRenderWidth(!0))*this._options|0,h=(i?i.height:this._engine.getRenderHeight(!0))*this._options|0,u=this._options.width||l,c=this._options.height||h;if(!this._shareOutputWithPostProcess&&!this._forcedOutputTexture){if(this.adaptScaleToCurrentViewport){var f=s.currentViewport;f&&(u*=f.width,c*=f.height)}if((this.renderTargetSamplingMode===e.Texture.TRILINEAR_SAMPLINGMODE||this.alwaysForcePOT)&&(this._options.width||(u=s.needPOTTextures?e.Tools.GetExponentOfTwo(u,a,this.scaleMode):u),this._options.height||(c=s.needPOTTextures?e.Tools.GetExponentOfTwo(c,a,this.scaleMode):c)),this.width!==u||this.height!==c){if(this._textures.length>0){for(var p=0;p<this._textures.length;p++)this._engine._releaseTexture(this._textures.data[p]);this._textures.reset()}this.width=u,this.height=c;var d={width:this.width,height:this.height},m={generateMipMaps:!1,generateDepthBuffer:r||0===t._postProcesses.indexOf(this),generateStencilBuffer:(r||0===t._postProcesses.indexOf(this))&&this._engine.isStencilEnable,samplingMode:this.renderTargetSamplingMode,type:this._textureType};this._textures.push(this._engine.createRenderTargetTexture(d,m)),this._reusable&&this._textures.push(this._engine.createRenderTargetTexture(d,m)),this._texelSize.copyFromFloats(1/this.width,1/this.height),this.onSizeChangedObservable.notifyObservers(this)}this._textures.forEach(function(e){e.samples!==n.samples&&n._engine.updateRenderTargetTextureSampleCount(e,n.samples)})}var g;this._shareOutputWithPostProcess?g=this._shareOutputWithPostProcess.outputTexture:this._forcedOutputTexture?(g=this._forcedOutputTexture,this.width=this._forcedOutputTexture.width,this.height=this._forcedOutputTexture.height):g=this.outputTexture,this.enablePixelPerfectMode?(this._scaleRatio.copyFromFloats(l/u,h/c),this._engine.bindFramebuffer(g,0,l,h,!0)):(this._scaleRatio.copyFromFloats(1,1),this._engine.bindFramebuffer(g,0,void 0,void 0,!0)),this.onActivateObservable.notifyObservers(t),this.autoClear&&this.alphaMode===e.Engine.ALPHA_DISABLE&&this._engine.clear(this.clearColor?this.clearColor:o.clearColor,!0,!0,!0),this._reusable&&(this._currentRenderTextureInd=(this._currentRenderTextureInd+1)%2)},Object.defineProperty(t.prototype,"isSupported",{get:function(){return this._effect.isSupported},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return this._shareOutputWithPostProcess?this._shareOutputWithPostProcess.aspectRatio:this._forcedOutputTexture?this._forcedOutputTexture.width/this._forcedOutputTexture.height:this.width/this.height},enumerable:!0,configurable:!0}),t.prototype.apply=function(){if(!this._effect||!this._effect.isReady())return null;this._engine.enableEffect(this._effect),this._engine.setState(!1),this._engine.setDepthBuffer(!1),this._engine.setDepthWrite(!1),this._engine.setAlphaMode(this.alphaMode),this.alphaConstants&&this.getEngine().setAlphaConstants(this.alphaConstants.r,this.alphaConstants.g,this.alphaConstants.b,this.alphaConstants.a);var e;return e=this._shareOutputWithPostProcess?this._shareOutputWithPostProcess.outputTexture:this._forcedOutputTexture?this._forcedOutputTexture:this.outputTexture,this._effect._bindTexture("textureSampler",e),this._effect.setVector2("scale",this._scaleRatio),this.onApplyObservable.notifyObservers(this._effect),this._effect},t.prototype._disposeTextures=function(){if(!this._shareOutputWithPostProcess&&!this._forcedOutputTexture){if(this._textures.length>0)for(var e=0;e<this._textures.length;e++)this._engine._releaseTexture(this._textures.data[e]);this._textures.dispose()}},t.prototype.dispose=function(e){if(e=e||this._camera,this._disposeTextures(),this._scene){var t=this._scene.postProcesses.indexOf(this);-1!==t&&this._scene.postProcesses.splice(t,1)}else{var i=this._engine.postProcesses.indexOf(this);-1!==i&&this._engine.postProcesses.splice(i,1)}e&&(e.detachPostProcess(this),0===e._postProcesses.indexOf(this)&&e._postProcesses.length>0&&this._camera._postProcesses[0].markTextureDirty(),this.onActivateObservable.clear(),this.onAfterRenderObservable.clear(),this.onApplyObservable.clear(),this.onBeforeRenderObservable.clear(),this.onSizeChangedObservable.clear())},t}();e.PostProcess=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l){return void 0===l&&(l=e.Engine.TEXTURETYPE_UNSIGNED_INT),t.call(this,i,"pass",null,null,r,n,o,s,a,void 0,l)||this}return n(i,t),i}(e.PostProcess);e.PassPostProcess=t}(s||(s={}));!function(e){var t=function(){function t(i,r,n){this._bias=5e-5,this._blurBoxOffset=1,this._blurScale=2,this._blurKernel=1,this._useKernelBlur=!1,this._filter=t.FILTER_NONE,this._darkness=0,this._transparencyShadow=!1,this.frustumEdgeFalloff=0,this.forceBackFacesOnly=!1,this._lightDirection=e.Vector3.Zero(),this._viewMatrix=e.Matrix.Zero(),this._projectionMatrix=e.Matrix.Zero(),this._transformMatrix=e.Matrix.Zero(),this._currentFaceIndex=0,this._currentFaceIndexCache=0,this._defaultTextureMatrix=e.Matrix.Identity(),this._mapSize=i,this._light=r,this._scene=r.getScene(),r._shadowGenerator=this;var o=this._scene.getEngine().getCaps();n?o.textureFloatRender&&o.textureFloatLinearFiltering?this._textureType=e.Engine.TEXTURETYPE_FLOAT:o.textureHalfFloatRender&&o.textureHalfFloatLinearFiltering?this._textureType=e.Engine.TEXTURETYPE_HALF_FLOAT:this._textureType=e.Engine.TEXTURETYPE_UNSIGNED_INT:o.textureHalfFloatRender&&o.textureHalfFloatLinearFiltering?this._textureType=e.Engine.TEXTURETYPE_HALF_FLOAT:o.textureFloatRender&&o.textureFloatLinearFiltering?this._textureType=e.Engine.TEXTURETYPE_FLOAT:this._textureType=e.Engine.TEXTURETYPE_UNSIGNED_INT,this._initializeGenerator()}return Object.defineProperty(t,"FILTER_NONE",{get:function(){return t._FILTER_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FILTER_POISSONSAMPLING",{get:function(){return t._FILTER_POISSONSAMPLING},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FILTER_EXPONENTIALSHADOWMAP",{get:function(){return t._FILTER_EXPONENTIALSHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FILTER_BLUREXPONENTIALSHADOWMAP",{get:function(){return t._FILTER_BLUREXPONENTIALSHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FILTER_CLOSEEXPONENTIALSHADOWMAP",{get:function(){return t._FILTER_CLOSEEXPONENTIALSHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FILTER_BLURCLOSEEXPONENTIALSHADOWMAP",{get:function(){return t._FILTER_BLURCLOSEEXPONENTIALSHADOWMAP},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(e){this._blurBoxOffset!==e&&(this._blurBoxOffset=e,this._disposeBlurPostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"blurScale",{get:function(){return this._blurScale},set:function(e){this._blurScale!==e&&(this._blurScale=e,this._disposeBlurPostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"blurKernel",{get:function(){return this._blurKernel},set:function(e){this._blurKernel!==e&&(this._blurKernel=e,this._disposeBlurPostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useKernelBlur",{get:function(){return this._useKernelBlur},set:function(e){this._useKernelBlur!==e&&(this._useKernelBlur=e,this._disposeBlurPostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"depthScale",{get:function(){return void 0!==this._depthScale?this._depthScale:this._light.getDepthScale()},set:function(e){this._depthScale=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"filter",{get:function(){return this._filter},set:function(e){if(this._light.needCube()){if(e===t.FILTER_BLUREXPONENTIALSHADOWMAP)return void(this.useExponentialShadowMap=!0);if(e===t.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP)return void(this.useCloseExponentialShadowMap=!0)}this._filter!==e&&(this._filter=e,this._disposeBlurPostProcesses(),this._applyFilterValues(),this._light._markMeshesAsLightDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"usePoissonSampling",{get:function(){return this.filter===t.FILTER_POISSONSAMPLING},set:function(e){(e||this.filter===t.FILTER_POISSONSAMPLING)&&(this.filter=e?t.FILTER_POISSONSAMPLING:t.FILTER_NONE)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useVarianceShadowMap",{get:function(){return e.Tools.Warn("VSM are now replaced by ESM. Please use useExponentialShadowMap instead."),this.useExponentialShadowMap},set:function(t){e.Tools.Warn("VSM are now replaced by ESM. Please use useExponentialShadowMap instead."),this.useExponentialShadowMap=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useBlurVarianceShadowMap",{get:function(){return e.Tools.Warn("VSM are now replaced by ESM. Please use useBlurExponentialShadowMap instead."),this.useBlurExponentialShadowMap},set:function(t){e.Tools.Warn("VSM are now replaced by ESM. Please use useBlurExponentialShadowMap instead."),this.useBlurExponentialShadowMap=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useExponentialShadowMap",{get:function(){return this.filter===t.FILTER_EXPONENTIALSHADOWMAP},set:function(e){(e||this.filter===t.FILTER_EXPONENTIALSHADOWMAP)&&(this.filter=e?t.FILTER_EXPONENTIALSHADOWMAP:t.FILTER_NONE)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useBlurExponentialShadowMap",{get:function(){return this.filter===t.FILTER_BLUREXPONENTIALSHADOWMAP},set:function(e){(e||this.filter===t.FILTER_BLUREXPONENTIALSHADOWMAP)&&(this.filter=e?t.FILTER_BLUREXPONENTIALSHADOWMAP:t.FILTER_NONE)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useCloseExponentialShadowMap",{get:function(){return this.filter===t.FILTER_CLOSEEXPONENTIALSHADOWMAP},set:function(e){(e||this.filter===t.FILTER_CLOSEEXPONENTIALSHADOWMAP)&&(this.filter=e?t.FILTER_CLOSEEXPONENTIALSHADOWMAP:t.FILTER_NONE)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useBlurCloseExponentialShadowMap",{get:function(){return this.filter===t.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP},set:function(e){(e||this.filter===t.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP)&&(this.filter=e?t.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP:t.FILTER_NONE)},enumerable:!0,configurable:!0}),t.prototype.getDarkness=function(){return this._darkness},t.prototype.setDarkness=function(e){return this._darkness=e>=1?1:e<=0?0:e,this},t.prototype.setTransparencyShadow=function(e){return this._transparencyShadow=e,this},t.prototype.getShadowMap=function(){return this._shadowMap},t.prototype.getShadowMapForRendering=function(){return this._shadowMap2?this._shadowMap2:this._shadowMap},t.prototype.addShadowCaster=function(e,t){return void 0===t&&(t=!0),this._shadowMap?(this._shadowMap.renderList||(this._shadowMap.renderList=[]),this._shadowMap.renderList.push(e),t&&(i=this._shadowMap.renderList).push.apply(i,e.getChildMeshes()),this):this;var i},t.prototype.removeShadowCaster=function(e,t){if(void 0===t&&(t=!0),!this._shadowMap||!this._shadowMap.renderList)return this;var i=this._shadowMap.renderList.indexOf(e);if(-1!==i&&this._shadowMap.renderList.splice(i,1),t)for(var r=0,n=e.getChildren();r<n.length;r++){var o=n[r];this.removeShadowCaster(o)}return this},t.prototype.getLight=function(){return this._light},t.prototype._initializeGenerator=function(){this._light._markMeshesAsLightDirty(),this._initializeShadowMap()},t.prototype._initializeShadowMap=function(){var t=this;this._shadowMap=new e.RenderTargetTexture(this._light.name+"_shadowMap",this._mapSize,this._scene,!1,!0,this._textureType,this._light.needCube()),this._shadowMap.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(e.Texture.BILINEAR_SAMPLINGMODE),this._shadowMap.renderParticles=!1,this._shadowMap.ignoreCameraViewport=!0,this._shadowMap.onBeforeRenderObservable.add(function(e){t._currentFaceIndex=e}),this._shadowMap.customRenderFunction=this._renderForShadowMap.bind(this),this._shadowMap.onAfterUnbindObservable.add(function(){if(t.useBlurExponentialShadowMap||t.useBlurCloseExponentialShadowMap){t._blurPostProcesses&&t._blurPostProcesses.length||t._initializeBlurRTTAndPostProcesses();var e=t.getShadowMapForRendering();e&&t._scene.postProcessManager.directRender(t._blurPostProcesses,e.getInternalTexture(),!0)}}),this._shadowMap.onClearObservable.add(function(i){t.useExponentialShadowMap||t.useBlurExponentialShadowMap?i.clear(new e.Color4(0,0,0,0),!0,!0,!0):i.clear(new e.Color4(1,1,1,1),!0,!0,!0)})},t.prototype._initializeBlurRTTAndPostProcesses=function(){var t=this,i=this._scene.getEngine(),r=this._mapSize/this.blurScale;this.useKernelBlur&&1===this.blurScale||(this._shadowMap2=new e.RenderTargetTexture(this._light.name+"_shadowMap2",r,this._scene,!1,!0,this._textureType),this._shadowMap2.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap2.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap2.updateSamplingMode(e.Texture.BILINEAR_SAMPLINGMODE)),this.useKernelBlur?(this._kernelBlurXPostprocess=new e.BlurPostProcess(this._light.name+"KernelBlurX",new e.Vector2(1,0),this.blurKernel,1,null,e.Texture.BILINEAR_SAMPLINGMODE,i,!1,this._textureType),this._kernelBlurXPostprocess.width=r,this._kernelBlurXPostprocess.height=r,this._kernelBlurXPostprocess.onApplyObservable.add(function(e){e.setTexture("textureSampler",t._shadowMap)}),this._kernelBlurYPostprocess=new e.BlurPostProcess(this._light.name+"KernelBlurY",new e.Vector2(0,1),this.blurKernel,1,null,e.Texture.BILINEAR_SAMPLINGMODE,i,!1,this._textureType),this._kernelBlurXPostprocess.autoClear=!1,this._kernelBlurYPostprocess.autoClear=!1,this._textureType===e.Engine.TEXTURETYPE_UNSIGNED_INT&&(this._kernelBlurXPostprocess.packedFloat=!0,this._kernelBlurYPostprocess.packedFloat=!0),this._blurPostProcesses=[this._kernelBlurXPostprocess,this._kernelBlurYPostprocess]):(this._boxBlurPostprocess=new e.PostProcess(this._light.name+"DepthBoxBlur","depthBoxBlur",["screenSize","boxOffset"],[],1,null,e.Texture.BILINEAR_SAMPLINGMODE,i,!1,"#define OFFSET "+this._blurBoxOffset,this._textureType),this._boxBlurPostprocess.onApplyObservable.add(function(e){e.setFloat2("screenSize",r,r),e.setTexture("textureSampler",t._shadowMap)}),this._boxBlurPostprocess.autoClear=!1,this._blurPostProcesses=[this._boxBlurPostprocess])},t.prototype._renderForShadowMap=function(e,t,i,r){var n,o=this._scene.getEngine();if(r.length){for(o.setColorWrite(!1),n=0;n<r.length;n++)this._renderSubMeshForShadowMap(r.data[n]);o.setColorWrite(!0)}for(n=0;n<e.length;n++)this._renderSubMeshForShadowMap(e.data[n]);for(n=0;n<t.length;n++)this._renderSubMeshForShadowMap(t.data[n]);if(this._transparencyShadow)for(n=0;n<i.length;n++)this._renderSubMeshForShadowMap(i.data[n])},t.prototype._renderSubMeshForShadowMap=function(t){var i=this,r=t.getRenderingMesh(),n=this._scene,o=n.getEngine(),s=t.getMaterial();if(s){o.setState(s.backFaceCulling);var a=r._getInstancesRenderList(t._id);if(!a.mustReturn){var l=o.getCaps().instancedArrays&&null!==a.visibleInstances[t._id]&&void 0!==a.visibleInstances[t._id];if(this.isReady(t,l)){if(o.enableEffect(this._effect),r._bind(t,this._effect,e.Material.TriangleFillMode),this._effect.setFloat2("biasAndScale",this.bias,this.depthScale),this._effect.setMatrix("viewProjection",this.getTransformMatrix()),this._effect.setVector3("lightPosition",this.getLight().position),n.activeCamera&&this._effect.setFloat2("depthValues",this.getLight().getDepthMinZ(n.activeCamera),this.getLight().getDepthMinZ(n.activeCamera)+this.getLight().getDepthMaxZ(n.activeCamera)),s&&s.needAlphaTesting()){var h=s.getAlphaTestTexture();h&&(this._effect.setTexture("diffuseSampler",h),this._effect.setMatrix("diffuseMatrix",h.getTextureMatrix()||this._defaultTextureMatrix))}r.useBones&&r.computeBonesUsingShaders&&this._effect.setMatrices("mBones",r.skeleton.getTransformMatrices(r)),this.forceBackFacesOnly&&o.setState(!0,0,!1,!0),r._processRendering(t,this._effect,e.Material.TriangleFillMode,a,l,function(e,t){return i._effect.setMatrix("world",t)}),this.forceBackFacesOnly&&o.setState(!0,0,!1,!1)}else this._shadowMap&&this._shadowMap.resetRefreshCounter()}}},t.prototype._applyFilterValues=function(){this._shadowMap&&(this.filter===t.FILTER_NONE?this._shadowMap.updateSamplingMode(e.Texture.NEAREST_SAMPLINGMODE):this._shadowMap.updateSamplingMode(e.Texture.BILINEAR_SAMPLINGMODE))},t.prototype.forceCompilation=function(e,t){var i=this,r=this.getShadowMap();if(r){var n=new Array,o=0,s=r.renderList;if(s){for(var a=0,l=s;a<l.length;a++){var h=l[a];n.push.apply(n,h.subMeshes)}var u=function(){if(i._scene&&i._scene.getEngine()){for(;i.isReady(n[o],!!t&&t.useInstances);)if(++o>=n.length)return void(e&&e(i));setTimeout(u,16)}};n.length>0&&u()}}},t.prototype.isReady=function(t,i){var r=[];this._textureType!==e.Engine.TEXTURETYPE_UNSIGNED_INT&&r.push("#define FLOAT"),(this.useExponentialShadowMap||this.useBlurExponentialShadowMap)&&r.push("#define ESM");var n=[e.VertexBuffer.PositionKind],o=t.getMesh(),s=t.getMaterial();if(s&&s.needAlphaTesting()){var a=s.getAlphaTestTexture();a&&(r.push("#define ALPHATEST"),o.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(n.push(e.VertexBuffer.UVKind),r.push("#define UV1")),o.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&1===a.coordinatesIndex&&(n.push(e.VertexBuffer.UV2Kind),r.push("#define UV2")))}o.useBones&&o.computeBonesUsingShaders?(n.push(e.VertexBuffer.MatricesIndicesKind),n.push(e.VertexBuffer.MatricesWeightsKind),o.numBoneInfluencers>4&&(n.push(e.VertexBuffer.MatricesIndicesExtraKind),n.push(e.VertexBuffer.MatricesWeightsExtraKind)),r.push("#define NUM_BONE_INFLUENCERS "+o.numBoneInfluencers),r.push("#define BonesPerMesh "+(o.skeleton.bones.length+1))):r.push("#define NUM_BONE_INFLUENCERS 0"),i&&(r.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var l=r.join("\n");return this._cachedDefines!==l&&(this._cachedDefines=l,this._effect=this._scene.getEngine().createEffect("shadowMap",n,["world","mBones","viewProjection","diffuseMatrix","lightPosition","depthValues","biasAndScale"],["diffuseSampler"],l)),this._effect.isReady()},t.prototype.prepareDefines=function(e,t){var i=this._scene,r=this._light;i.shadowsEnabled&&r.shadowEnabled&&(e["SHADOW"+t]=!0,this.usePoissonSampling?e["SHADOWPCF"+t]=!0:this.useExponentialShadowMap||this.useBlurExponentialShadowMap?e["SHADOWESM"+t]=!0:(this.useCloseExponentialShadowMap||this.useBlurCloseExponentialShadowMap)&&(e["SHADOWCLOSEESM"+t]=!0),r.needCube()&&(e["SHADOWCUBE"+t]=!0))},t.prototype.bindShadowLight=function(e,t){var i=this._light,r=this._scene;if(r.shadowsEnabled&&i.shadowEnabled){var n=r.activeCamera;if(n){var o=this.getShadowMap();o&&(i.needCube()||t.setMatrix("lightMatrix"+e,this.getTransformMatrix()),t.setTexture("shadowSampler"+e,this.getShadowMapForRendering()),i._uniformBuffer.updateFloat4("shadowsInfo",this.getDarkness(),this.blurScale/o.getSize().width,this.depthScale,this.frustumEdgeFalloff,e),i._uniformBuffer.updateFloat2("depthValues",this.getLight().getDepthMinZ(n),this.getLight().getDepthMinZ(n)+this.getLight().getDepthMaxZ(n),e))}}},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;if(this._light.computeTransformedInformation()&&(i=this._light.transformedPosition),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.needProjectionMatrixCompute()||!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);var r=this.getShadowMap();if(r){var n=r.renderList;n&&this._light.setShadowProjectionMatrix(this._projectionMatrix,this._viewMatrix,n)}this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)}return this._transformMatrix},t.prototype.recreateShadowMap=function(){var e=this._shadowMap;if(e){var t=e.renderList;this._disposeRTTandPostProcesses(),this._initializeGenerator(),this.filter=this.filter,this._applyFilterValues(),this._shadowMap.renderList=t}},t.prototype._disposeBlurPostProcesses=function(){this._shadowMap2&&(this._shadowMap2.dispose(),this._shadowMap2=null),this._downSamplePostprocess&&(this._downSamplePostprocess.dispose(),this._downSamplePostprocess=null),this._boxBlurPostprocess&&(this._boxBlurPostprocess.dispose(),this._boxBlurPostprocess=null),this._kernelBlurXPostprocess&&(this._kernelBlurXPostprocess.dispose(),this._kernelBlurXPostprocess=null),this._kernelBlurYPostprocess&&(this._kernelBlurYPostprocess.dispose(),this._kernelBlurYPostprocess=null),this._blurPostProcesses=[]},t.prototype._disposeRTTandPostProcesses=function(){this._shadowMap&&(this._shadowMap.dispose(),this._shadowMap=null),this._disposeBlurPostProcesses()},t.prototype.dispose=function(){this._disposeRTTandPostProcesses(),this._light&&(this._light._shadowGenerator=null,this._light._markMeshesAsLightDirty())},t.prototype.serialize=function(){var e={},t=this.getShadowMap();if(!t)return e;if(e.lightId=this._light.id,e.mapSize=t.getRenderSize(),e.useExponentialShadowMap=this.useExponentialShadowMap,e.useBlurExponentialShadowMap=this.useBlurExponentialShadowMap,e.useCloseExponentialShadowMap=this.useBlurExponentialShadowMap,e.useBlurCloseExponentialShadowMap=this.useBlurExponentialShadowMap,e.usePoissonSampling=this.usePoissonSampling,e.forceBackFacesOnly=this.forceBackFacesOnly,e.depthScale=this.depthScale,e.darkness=this.getDarkness(),e.blurBoxOffset=this.blurBoxOffset,e.blurKernel=this.blurKernel,e.blurScale=this.blurScale,e.useKernelBlur=this.useKernelBlur,e.transparencyShadow=this._transparencyShadow,e.renderList=[],t.renderList)for(var i=0;i<t.renderList.length;i++){var r=t.renderList[i];e.renderList.push(r.id)}return e},t.Parse=function(e,i){for(var r=i.getLightByID(e.lightId),n=new t(e.mapSize,r),o=n.getShadowMap(),s=0;s<e.renderList.length;s++)i.getMeshesByID(e.renderList[s]).forEach(function(e){o&&(o.renderList||(o.renderList=[]),o.renderList.push(e))});return e.usePoissonSampling?n.usePoissonSampling=!0:e.useExponentialShadowMap?n.useExponentialShadowMap=!0:e.useBlurExponentialShadowMap?n.useBlurExponentialShadowMap=!0:e.useCloseExponentialShadowMap?n.useCloseExponentialShadowMap=!0:e.useBlurCloseExponentialShadowMap?n.useBlurCloseExponentialShadowMap=!0:e.useVarianceShadowMap?n.useExponentialShadowMap=!0:e.useBlurVarianceShadowMap&&(n.useBlurExponentialShadowMap=!0),e.depthScale&&(n.depthScale=e.depthScale),e.blurScale&&(n.blurScale=e.blurScale),e.blurBoxOffset&&(n.blurBoxOffset=e.blurBoxOffset),e.useKernelBlur&&(n.useKernelBlur=e.useKernelBlur),e.blurKernel&&(n.blurKernel=e.blurKernel),void 0!==e.bias&&(n.bias=e.bias),e.darkness&&n.setDarkness(e.darkness),e.transparencyShadow&&n.setTransparencyShadow(!0),n.forceBackFacesOnly=e.forceBackFacesOnly,n},t._FILTER_NONE=0,t._FILTER_EXPONENTIALSHADOWMAP=1,t._FILTER_POISSONSAMPLING=2,t._FILTER_BLUREXPONENTIALSHADOWMAP=3,t._FILTER_CLOSEEXPONENTIALSHADOWMAP=4,t._FILTER_BLURCLOSEEXPONENTIALSHADOWMAP=5,t}();e.ShadowGenerator=t}(s||(s={}));!function(e){var t=function(){function e(e,t,i){void 0===t&&(t=""),void 0===i&&(i="black");var r=this;this._renderingCanvas=e,this._loadingText=t,this._loadingDivBackgroundColor=i,this._resizeLoadingUI=function(){var e=r._renderingCanvas.getBoundingClientRect(),t=window.getComputedStyle(r._renderingCanvas).position;r._loadingDiv&&(r._loadingDiv.style.position="fixed"===t?"fixed":"absolute",r._loadingDiv.style.left=e.left+"px",r._loadingDiv.style.top=e.top+"px",r._loadingDiv.style.width=e.width+"px",r._loadingDiv.style.height=e.height+"px")}}return e.prototype.displayLoadingUI=function(){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._loadingDiv.style.pointerEvents="none",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 e=document.createElement("style");e.type="text/css";e.innerHTML="@-webkit-keyframes spin1 { 0% { -webkit-transform: rotate(0deg);}\n 100% { -webkit-transform: rotate(360deg);}\n } @keyframes spin1 { 0% { transform: rotate(0deg);}\n 100% { transform: rotate(360deg);}\n }",document.getElementsByTagName("head")[0].appendChild(e);var t=new Image;t.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTZEaa/1AAAYq0lEQVR4Xu2dCZRcVZnHScAJUZSwjSOIbAJmEAZwQCCMoAInYRGIg8AwegQx7AFzUBBmzAFlE4EAwxz2GRk2w7AnAURZBiEOZgyEQDAQAjmEJqTpNd3V1V3Vmd+/6utKV7/1vnpVXd2p/zn3vOV+27vfu/fd/W3QQAPrBZqbm7fJZrN79vf3T+/r67uf4wO9vb37WXQDIwWtra0Tenp6voQTv5XP56/BkfcR3iLk1g6B7hEeI+zP5V+ZiAbqBZ2dnZ8lV+6Gg87CobfhpOc4byf0FjwYE9DneBkWcXrM2tmzNzTxDdQKJPyETCazI46YgiMuI9zJuXJltuChFIHsP/PSfIfTjU19A2mira1tcxy3ey6XO5vEnkV4kes11XBmENDVj97XOT2O03FmWgMuoNLzGRJva8IUnPkzjjcT/kLoKCZzfQB7XiX8M2G8md7AUJgzJ+Z6e88gZ1xGuj3HsY17PcVkrG9gp7CUF/F8PUvxqdZDrFq1ahNVfKjwTCYxZuDE2wjKlc2WViMePM+HPNsFPOdf22OPblD5OZQHvphnV65cjTMzxaQY3eA5V9OO/hmnm1lSjE7woFsQbiXki4++foHnXkW4mLC1JUl947333tsMY3emqfB9jtPJlXN5U0+bOXPmWCPxgOccSy4+AfqPio+9/oFnbyatbqVE28GSZfjQ1NT0KQzaHMcdyPfyaNoE12HcvdxT29K3Fkv8A2vWrPmcifAFZNtD91yRY+SBZ+9UsMtEgD+jTpeenp6JXI6xpKkuUDqRcA6Kr0Wpens+InQTnIpV6Fdi+BQT64ulS5eOIzefD62na7CeoGcnLCM8ykt5OWlzcPv772/BS/w3nP+K+xU11+DvQe5dcrQlTfWAwbNMb8XA8AyGX80xtLlA6TAJuteMbVhhia1v5VMcr+LWMeoZ4xiYw7q6urbhHbgG+paCkIRQehHu4pO3O5fVydEomF5Ulx548JfVD2wqfKE2I3R3ob/f2GoC1DWhdz7HG3i5j2pvb9+Z24m6HvVZQtYsZFWcowlzePEP4jJdR/OQhxTVpAs9NMXxmZxuZKo8IG4s+v8R2tUFphSBTBWzH+OAFwn/gS3TuN55xYoVqfc6dXd3fwHZ1xFaTX0iyGbwjJqXXAammxP00EXx6UMGEx7ram7+vKnzBZ/87Xiwp40tEdDTgYwlHG/CmadSjO7L+XiialOZAej7POFG2VK0Khngl6Pn8/LL0YEtlFh4n8oDAqvaAYH8tzH2iNDm1IIFn8Ax50G7xtgCAU07CfAG4RHOz+vLZL7e0dGxlYlKHaj8BHo25xgrsfV5wrYH4KmouxV+ZZDnCUdwmXxMGgFvFUVWD+jQuOot6rI0tb4gcfaG9v+MrcAn+wj38gL8C7cObmlp2ZRjOkWYD6ypuAf6zjFHLSJ0c/6YQ813DM/yZXgehreiVgP8cvSfsOeExYsXuzs6n8v9j8mqBRZQmdjXVPuira1NHSpn8UDf4Xu0vd2uCtDzacJOlDDf5ng94X8JTWarB8R1EK7ju7udiYgEz/v3pLFKm4oHUHhh3iZdfshpaEYpA4pvKLLXBujLYKRq71XLhUHg27z12rW9B6L/QhLrWWxRH7nzeDK8awi/5HRTEx0K6MZQ694LHk0DqrgfADkreIYz1q5c+UlTEQzesIuMryrggYQWjNL3RGO7p2tuFMeqjaOidgzyCz1yJMTJ6L6d66WEVCcHIO/dQkI75Chs2g97Hoc3jRz9Lge1ED5l4r0gckqRPB0gTw34t1B+h3IqxZkmrn2SULUa7ezZszdE5xfR9130Xsm5ilrnHrmkQOcKvrkncxqrIiY6wlewbw7BOUfDo/b84zzvj9C7J7eCS0NrUiRKCPjUE7ScMBdlF/B2HqBi0ERXBcuXL99YnQz9fX2ah3Up4UnsWGEmDRuUhoTn+Z5PfvbZZ2N/fuCZRJgnfhNVBu73EZoIKt7l0L2UBsYeDZg016nb5EUCWuXQewinUtTuyq2aTStF14a8SD+VDQVj6hDYxjuXf4Hjl83sSMCmTp8j4FtoMuRQ5dAZcii3kk/0s2bBhxIcBxjxUlib1hWInEDO/6qKV+y4geO5HAMntEE/pq+nZyo0ywsG1SmwL4Orf+0yqGCfmvR73LAn9lAeBjQTEhkA+1h49a08iRflcq4H5iuXFU9cz4lqihC/LXS/NZa6Bc+pz5gql5ub6VXD2tZWTSPeyS7XgeLhXrMnEhj6MSHSwaIhFGZH8oA/JzzFeexvJbRN2HW03moT6cEChx6w4QY2rurn85JWrxsiCy0FwjcIqos8w7GZNPulkawDEbFHlaBtjzODEDrVztuKXMmADPWA3RaljyJeNdKq98ilAez8iJdyGqfO31V4NoV/EvyaCqR54V2EshE5Lqcb+TrkstkTLD4WKB4PNNZQ8P05HAelMXNSPWChC8JsYvwthJo0jSoF6fIqjjqe08Aat+LIkd+AVjn09zxbZFqK3tjXAUbXUaWDjTUSyN4J45YZX2Igo4cEOVfFson2ALIxSjR0jog5YNgpfNHM90BxIjDyWIB8Z2NfB01HISJ20wPaw4w1FlavXq1v8aPGXhFw9JNRFTDItifU/RwwpfmKxYsDK180kU4x0lhAXvOSJUs+bezlIDL2N4xi4GpjK4MGCuzUA+SPxzn3m4iKgKyV2DCV08DeMWg0B+zHHOt2DpjS3Mz1BfFOM25C5ZH4LxldJBB0g7GVARkaXgv8VsKqZtIMPpN9RUnJgRzU5Wfp22vifcG3+2vQvmdsdQXsX2pm+oKX+GYjjQXkPWqsXshpRhcJ0RpbGShSHiSuheP37ZYHsGusVHOrU1lMxkO9od4eE+8LlSzQqfetpnPAooBN/2Um+gISp89MkF8K4G3RrMJYoOhbYGxlQEGhSOGogfoLwipExGtUZVVBYIVAluaAaUpuWA+YujlPF22Ra/iBLYEOsV6tV4w0FiitfmLsXiBMU0NiAVrfsp77Zd8MHPgbDoHtva6uLs1jiv1piAKy5tCG+4KJ9wVO/p6RDzvy+b5rzSwP9Okh/WKPERiCWzfk4K8bUSTiOljAyCdx5DZG4gE8W5Dov+NYUfsV/j50fUC4dmXIQDh0qQ6PVgJsOcLM8oA410Ggvo6Ojr81di+g2TKuQOiyJOKWxlpCJpM5zUjKAL3awTsamQfEbYhjtDGKa5tPsyn/wAuiURftlBO56h6aunEwCMxxvV1d+2Fr7Jce2vAu5LUtLeoGi/19gtbToCaR97BoD6BvUs+WkXqgbw6OuhC6wH5l4rRGaCFOvYnjYbyxnpcsCvDVhYOxo6+zszNwSNHVTtJEmSiwzlMAQmNPwIPW42Dds2hfEK/5WJo0Fth+5VNxFHSlkoTzFRh/N3wnq0OGWxXtdoO8enFwaI4jsyidYgNZTxhrMEjEJ4w+En65ESWRXZ7Q4K/COqDAPlhka87WedB8KawmngTIHREOJs5pMiRp+p/GGgxL1FiA9hxjK6G1tVVdhJGAV15+cPXq1f7dahVC20Wg4miCp0uTe3Xh4Hwu93rY1B7SR/t7xQbP5R1FGgpy8IlKe+MJhZ9Aa7u5jPm+pGLX2BMDOZ+hDXgQiXIJ5xoXHZg96anEEFcvOTi0SMUXS4w0FijSTzTWYEA3hkTSEtDI2qw6RoytDLA6jctCvzKqJ8oPFOO7kAhnYe9cZGiWiZ/N9ezguWaSL4h3TUfvKJIfoN0I4sjigYSdZyxlcDVMgEczEY41ER6oZFBOh2Yqegf2zYoziFC3DuZZrjSTPLDtMlxaNPmPP/54W2OPxksrVozP5fLPGr8vEOpbxJCr3jQSJyDvGRNRhv7iHh8vE5LMpKznHBz4zSTOaXwe+mXGGh9tbWvVQf+iyfCAON/ZlTj4v43ECfB94Le4CuMrWVpTtw7O9fZOM5M8oD7xVSOLBdLuNWN1g7bgJUF8+4qpBjf7Te9M6hD4tBDc0289Wh2MHbuaSR7gsHOMLBaQ9W/G6o5MJrNDPu9dcYdQ33Yc95I6OFV5hnp2cGCliDingX5KU+9MShd0dmqta/k8J4zwnV2JsuuNxAnI83VwNpO52kiSoC4djA255cuXBzYPycGzjTQWkPdNY00OfRcQVLafRnd39ySLLsG1i20AyPZ3cDb7AyNJgnp1cOhUHUhcFiL045v9jTUa8Gjlm29fsQQhb3DzJLUEhC+oiK7EISPOwapoEh+7JQJti5YfGXs0YNC62ouC1h9lsrlToClsjc/RM7uSe0kd3EmlzTO/Kqk8Q106mM/Yw2aOB9jnOg6sWTHxJ9FraSJMy6nGz7RbZUDYmN7e3BnQ5Gisez7u3J9c0JwA6Pb0aCFvNObgwKk6NoU59uJwaJ8y1viAT4vCtEFXYO8SFQGtCZpllyXQtNqL+4lmZ/BN/5qJKQFZozEHe9JtAGSaw4wsFnie4JmUQcjleh8yZq0Fnmq3y0D02IzPMgnonYqYIfA4pC+TcXrgIahLB+PEb5s5HrjaR0b7kbHGB0pK7TDO1/T39x1lUZGAPlUH0xTbz+KSoC4dDDx2DQCHzTCaWOB5zjbW+KCSpW0IS0BIJmy6zWCk7WDuxZ4r5oO6dHB7e/sBZo4H2OfUsYOv9jHW+ECJdkAtA/c6MpmMd+XaEKj7km9M4F5TEfBzSKovDLKG1cHobw+b6EDa3WOksYBPAhevBUJMxl8GJTRhFyMLBKSJFn5ls9nvmogS0DfaHOzb3h8AcUuNNBLQNiWa0gRv4MwMMyBwCqxAfCIH82JdYSJKQN+ocjA5NHD2I/e1aj/23iPyhbG6A+bAgXsZoUEII/UAkkQORu71JqIE7o22HBw4VaelpWU74mPPDc/39d1trO5Qb4vJ8QXxbwat06WofcTInMCzeToAtN4VXUn/l1AXDkan9tDSfmL6C81BZooHxDkN9CMveLFZFFAWWZtDwVta3G0sJcAbe3bmYEiniShBXabcL+wflQDD5mD0yKlvk0b/Tk33AG5F7idG+/ibRe54oEl1nLG6A+ZYe1jyAIuG/u2LB3MazxwAfL5vJFGJinxQUwcju6c/n3+FNPm5JhJyy2k/sQTp5nm+2HBJCGi1X1WpwzuBoQXAN+IcjDz8mdePKi/WhH1uxd7GcCjIVBcWpUYDfZ0VbclEJSr2akMBhVrdX6j+Jx3DpSh7vKB8CIiqKwcrcXGqdr05k3RKbU9ryTQVkUB3aHMrEshw7kGCXiv8xxG0h6Uzent6Fpn6MhA17A6GT/3yTxNO1coJbgWur3JFf1fXNuTes5AZe18xXobFHJKv04JZc3O7CtIcgGL9KW03u3QCfL4D4b292dhrpoYgsYOhEz4kaOuHqXKqiagYiN9QnUlyKgX84JUYsQFP9GKzMFRSe8XJb9upE9Dn62CK/KQT75wdTLz+NXgPNdrDuYzeUd0ByN4Wp07n+EdCRZuTY1/ymZQDwIjQye9pA32xdw6IiUgHc639mN8kzCLRjkxzQRzitUpkZ8LZBP1CILUd55EVvdgsCrzJl5i8mgCja+Zgjst4Pq3DUnMmtSWqyNIuQruRU3+CbO08n+pvBAZAjf1IU5kcGJc0YRMBfVV3MPd2RN4+YbvYukI/3sSpe+LUmbw0ryG/6ts1oSLeYrMw6C0xeaFAGc+Wq3hbfeRk582b55lrzf3UHJwWkD0Wp+6BQ3+BfXEXw6UCdHX4TVB0BoJi9Y1Cp59XbUWN8HW7lRjLli3zbINE+1hNiCRI1cGakIhT99ani/A6z1z1nDoUqNQfbO40kyqDfrCBwMg3E5rsCy+8sFlHR8dEnFzRTq/I8hQ9NFFOtGhXVOxgFeUqfknUK7Ctpjl1ANKJ/vmUkvrdwRZmWjpA4J9MTyja2toKY8TQa/ufxP/Whdd5c5cQJHIwfBsTvkKiaqd6/fRyOHKqavdL0H+V2sxmWvrQCAeKItfmQlNyDG/8SVwnetMHyxmA7lm0K2I7GFrlVBW/V6FPP9GqeU4V0Kt2+O2yhctUN6AJBEWD9ngMnessJxh5AfCoQe+8q+xQOYLuWbQrQh2MXP1XYh8S9DKC2sI1z6kCatW3/RCZ6Vj9fNPMqx2wQVNJQlcNEl/mGG5pv48bi7HxMVSOoHsW7QqPg5GlvnJtk6/B9+HMqYUfaXE6rampqWy4dVhgi8FfLprnBXEex+i/wCSkNiSNDSpUxxt7Ccj2nQQYAwUHc9yE3HEotuifDklnfFYMdGNC/lWCxotDf4PvB/jHZTs71c+f2n+ryqCPPcb5/pKdGrTvbH2MUjH4ByOLBDpON9YSFi5cuI1FOwFbbyTox5T6y+iwFL8CqvWvwVtolWgSv/N4sXbl5ZP3r8hRLT50d56KgYJDCYXVhYOhtqqReKDdZuGJtSQSOk8f67x581SspvH3lpoBe9Vefbg/lzveaXmnAf6tEDMNGRp3LnV3ch29o10lQIf+bOKZc+XnmMGARF2EK4vUwQiSw33n7ZlqDWwcaK9Ob29vd26vwj+OT8m3kKFxdd9tlILSJ1Wo8Y8RZT/YiKOY4le5P3SGZJAc7telg7FroL16Jc/n/a1cBBCxsSblwT8LOfofcCh4AQ4x1uoCXZtgVKnYDXLMUECnPSQD29VBcrhfVw7GHrVXb6WylGg0SvUZcrr+YPYuwWVfaE9ltmpA2Q6EQq2UY+yigzf2oqCH4v4MIysD94fdwdig9uqDnB4T5/d+gwHPGNVFcOopyJiPLOfmGTwa0Ek8qS8RKDKORLFWH95utwbDd94SRqqN/Cv4PDXbTFfXfUZWBvRUPJCRBJiIqfnnccy0Dz74wHkWoypY2D4ZGU8gK+kKjQKQ8RcTW1uQI2fmc7nH7LIMFEW+sw6xdyN4CgvNByNIDjp+ZyRVhzlV7dVLaZc7t1cRoW0w9of/No6ptbuRdZupqC3QPZY33HchMkbJiRPssgyaHkN82XaJXPtOJuN+JRuixQI6Cu1VXiZtJehcFGpeNPyXI6cqPWTIvsxU1R7o912akevre4OHfTHot3fEfRbD3y8+Qu0djO5Ce5UXNGl7dTt4z0RGqnOuhgLZgmcPk2FHrrd3jgwkAVQ58e1ioxjcHeMLPWQcq+5gZKm9+hJHjXo5z4xQBQsxxyDjEfir+nNq5GfQo/nYh6f9e4NUgGEFx3DEzvw1nPrOhSJ+kh6GUBUHw6//Kmls96dJ2qv6FxNF9z8g405kVLVXDfkaiFAd4JIkttYUGFpyDOf91Ch/YVEe8DA/gORpuywDfLNMjBOQt4qEupbTPTX4YeJig+/qrnoxkfMeIdH2UHGBfP0H6kFepElc1rY5lBQYXZbzuO7BWYH7b3V3d/+TX1FEG/JSExEJdOi7qsnrx3DuNM8Zdg2NqnN/BjK0EXlVhxORr56wP6Lv/DT+X1FzYLynaOWe2s1TjCQW4An9t6Jk4hBVdH6YpB9YNXoS+SRk/JaQZHd5J2CnesLuyGaze3KZ2hTemoNcpO+uB3pAQuzvC7SeJSfc0258Wo97aX9PT+TmMEMB73jsO0wJzXnVx4llL7pe5kWaFtSqGHHgu6rpPr5jsdx+hyI59G+hA4C25GDO1V69mbf/77h0+lZpzZX44B+Ye1X1cWKz92pKrYlcjtzc6gfN+ufhApd/ErcwTvuTRNI0m4c4Tg77u6gfbCHdTuQcrRFaRKiFU7Xl1O/RqX9RObevRxR43gmEBYUn9wEJIMeF/jk0yVKTta2tE0jg43kx1OatWifEYKDrHYKGDnfkMrU1xHUPaoh7k8i+030EvoV3c6i4aTCoc/9+9NVkFgh6BmZFaig08he3oxYkwBEkQGCzg7gfG6kzaDvuSyLfgIyqt1cF6SAspoS4iJf3c9xaf3JrGEgUzZcOGgvO4agzjTQUkI9V5z4851MuLhBvUUp1gR7tjXEHL+shXFZnduNIBomi6T73FVLLByQePu4N3CxMbVxyzfeQUTYZrdpA3yvoPVf/1jdTGggC6aXx0ieLSecFcWoj72vkhU4IcswU7gVORksb6FHnufbouJ4Xbv+gf1g0EADav9uSeO9YenpA3IfURFVZ0gqEms1rRg0qCzM4TuYy1T061jt0dXXpX0xJ96FMDXIqQXtJ3tSfze6OaY0KU1ogfTUgUJMK0lBIL06dS/F/LJeRe0k2kAAk7BgSWN2GVW/aCOjRuPCbBHVGBG6J3ECKIN3VlfjroguqA+RrMsFvCNqisf5mRox2qPlB4s8vuiMdIE/fVjVvLlRnhKlqYLig7QIpOiva40PAqR2E22neJFrN10AVgWMOIDgPuMOjmRFa+HVaR0fHliaugXoEOe80nBWrZg2dZkZoYffuaW5u1kCVkadmbT70AGdqJodWOhxHqP2eFg1UDvsLatnSFq41M+KKnp6eXbhsdB2OdGiCeX8+/2ecqgnmk/VXNYtqYLSAnNposzpjgw3+H/belpVa8J7TAAAAAElFTkSuQmCC",t.style.position="absolute",t.style.left="50%",t.style.top="50%",t.style.marginLeft="-60px",t.style.marginTop="-60px",t.style.animation="spin1 2s infinite ease-in-out",t.style.webkitAnimation="spin1 2s infinite ease-in-out",t.style.transformOrigin="50% 50%",t.style.webkitTransformOrigin="50% 50%",this._loadingDiv.appendChild(t),this._resizeLoadingUI(),window.addEventListener("resize",this._resizeLoadingUI),this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor,document.body.appendChild(this._loadingDiv),this._loadingDiv.style.opacity="1"}},e.prototype.hideLoadingUI=function(){var e=this;if(this._loadingDiv){this._loadingDiv.style.opacity="0",this._loadingDiv.addEventListener("transitionend",function(){e._loadingDiv&&(document.body.removeChild(e._loadingDiv),window.removeEventListener("resize",e._resizeLoadingUI),e._loadingDiv=null)})}},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}(s||(s={}));!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}),Object.defineProperty(t,"CleanBoneMatrixWeights",{get:function(){return t._CleanBoneMatrixWeights},set:function(e){t._CleanBoneMatrixWeights=e},enumerable:!0,configurable:!0}),t._getDefaultPlugin=function(){return t._registeredPlugins[".babylon"]},t._getPluginForExtension=function(e){var i=t._registeredPlugins[e];return i||t._getDefaultPlugin()},t._getPluginForDirectLoad=function(e){for(var i in t._registeredPlugins){var r=t._registeredPlugins[i].plugin;if(r.canDirectLoad&&r.canDirectLoad(e))return t._registeredPlugins[i]}return t._getDefaultPlugin()},t._getPluginForFilename=function(e){e.name&&(e=e.name);var i=e.lastIndexOf("."),r=e.indexOf("?");-1===r&&(r=e.length);var n=e.substring(i,r).toLowerCase();return t._getPluginForExtension(n)},t._getDirectLoad=function(e){return e.substr&&"data:"===e.substr(0,5)?e.substr(5):null},t._loadData=function(i,r,n,o,s,a,l){var h,u=t._getDirectLoad(r),c=l?t._getPluginForExtension(l):u?t._getPluginForDirectLoad(r):t._getPluginForFilename(r);h=c.plugin.createPlugin?c.plugin.createPlugin():c.plugin;var f,p=c.isBinary;t.OnPluginActivatedObservable.notifyObservers(h);var d=function(e,t){if(n.isDisposed)a("Scene has been disposed");else{n.database=f;try{o(h,e,t)}catch(e){a(null,e)}}},m=function(t){e.Tools.LoadFile(i+r,d,s,f,p,function(e){e&&a(e.status+" "+e.statusText)})};if(u)return d(u),h;if(-1===i.indexOf("file:"))n.getEngine().enableOfflineSupport?f=new e.Database(i+r,m):m();else{var g=r;g.name?e.Tools.ReadFile(g,d,s,p):e.FilesInput.FilesToLoad[r]?e.Tools.ReadFile(e.FilesInput.FilesToLoad[r],d,s,p):a("Unable to find file named "+r)}return h},t.GetPluginForExtension=function(e){return t._getPluginForExtension(e).plugin},t.RegisterPlugin=function(e){if("string"==typeof e.extensions){var i=e.extensions;t._registeredPlugins[i.toLowerCase()]={plugin:e,isBinary:!1}}else{var r=e.extensions;Object.keys(r).forEach(function(i){t._registeredPlugins[i.toLowerCase()]={plugin:e,isBinary:r[i].isBinary}})}},t.ImportMesh=function(i,r,n,o,s,a,l,h){if(void 0===s&&(s=null),void 0===a&&(a=null),void 0===l&&(l=null),n.substr&&"/"===n.substr(0,1))return e.Tools.Error("Wrong sceneFilename parameter"),null;var u={};o._addPendingData(u);var c=function(t,i){var s="Unable to import meshes from "+r+n+(t?": "+t:"");l?l(o,s,i):e.Tools.Error(s),o._removePendingData(u)},f=function(e){a&&a(e)};return t._loadData(r,n,o,function(e,t,a){if(e.rewriteRootURL&&(r=e.rewriteRootURL(r,a)),e.importMesh){var l=e,h=new Array,p=new Array,d=new Array;if(!l.importMesh(i,o,t,r,h,p,d,c))return;if(s)try{o.importedMeshesFiles.push(r+n),s(h,p,d),o._removePendingData(u)}catch(e){c("Error in onSuccess callback.",e)}}else e.importMeshAsync(i,o,t,r,function(e,t,i){if(s)try{o.importedMeshesFiles.push(r+n),s(e,t,i),o._removePendingData(u)}catch(e){c("Error in onSuccess callback.",e)}},f,c)},f,c,h)},t.Load=function(i,r,n,o,s,a,l){return t.Append(i,r,new e.Scene(n),o,s,a,l)},t.Append=function(i,r,n,o,s,a,l){if(r.substr&&"/"===r.substr(0,1))return e.Tools.Error("Wrong sceneFilename parameter"),null;t.ShowLoadingScreen&&n.getEngine().displayLoadingUI();var h={};n._addPendingData(h);var u=function(t,o){var s="Unable to load from "+i+r+(t?": "+t:"");a?a(n,s,o):e.Tools.Error(s),n._removePendingData(h),n.getEngine().hideLoadingUI()},c=function(e){s&&s(e)};return t._loadData(i,r,n,function(e,r,s){if(e.load){if(!e.load(n,r,i,u))return;if(o)try{o(n)}catch(e){u("Error in onSuccess callback",e)}n.loadingPluginName=e.name,n._removePendingData(h)}else e.loadAsync(n,r,i,function(){o&&o(n),n.loadingPluginName=e.name,n._removePendingData(h)},c,u);t.ShowLoadingScreen&&n.executeWhenReady(function(){n.getEngine().hideLoadingUI()})},c,u,l)},t._ForceFullSceneLoadingForIncremental=!1,t._ShowLoadingScreen=!0,t._CleanBoneMatrixWeights=!1,t._loggingLevel=t.NO_LOGGING,t.OnPluginActivatedObservable=new e.Observable,t._registeredPlugins={},t}();e.SceneLoader=t}(s||(s={}));!function(e){!function(t){var i=function(t,i,r,n){for(var o=0,s=i.materials.length;o<s;o++){var a=i.materials[o];if(a.id===t)return e.Material.Parse(a,r,n)}return null},r=function(e,t,i){for(var r in t)if(e.name===t[r])return i.push(e.id),!0;return!(!e.parentId||-1===i.indexOf(e.parentId))&&(i.push(e.id),!0)},n=function(e,t){return e+" of "+(t?t.file+" from "+t.name+" version: "+t.version+", exporter version: "+t.exporter_version:"unknown")};e.SceneLoader.RegisterPlugin({name:"babylon.js",extensions:".babylon",canDirectLoad:function(e){return-1!==e.indexOf("babylon")},importMesh:function(t,o,s,a,l,h,u,c){var f="importMesh has failed JSON parse";try{var p=JSON.parse(s);f="";var d=e.SceneLoader.loggingLevel===e.SceneLoader.DETAILED_LOGGING;t?Array.isArray(t)||(t=[t]):t=null;var m=new Array;if(void 0!==p.meshes&&null!==p.meshes){var g,v,_=[],y=[];for(g=0,v=p.meshes.length;g<v;g++){var x=p.meshes[g];if(null===t||r(x,t,m)){if(null!==t&&delete t[t.indexOf(x.name)],void 0!==x.geometryId&&null!==x.geometryId&&void 0!==p.geometries&&null!==p.geometries){var b=!1;["boxes","spheres","cylinders","toruses","grounds","planes","torusKnots","vertexData"].forEach(function(t){!0!==b&&p.geometries[t]&&Array.isArray(p.geometries[t])&&p.geometries[t].forEach(function(i){if(i.id===x.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)}b=!0}})}),!1===b&&e.Tools.Warn("Geometry not found for mesh "+x.id)}if(x.materialId){var T=-1!==y.indexOf(x.materialId);if(!1===T&&void 0!==p.multiMaterials&&null!==p.multiMaterials)for(var E=0,A=p.multiMaterials.length;E<A;E++){var P=p.multiMaterials[E];if(P.id===x.materialId){for(var S=0,M=P.materials.length;S<M;S++){var C=P.materials[S];y.push(C),f+="\n\tMaterial "+(R=i(C,p,o,a)).toString(d)}y.push(P.id),T=!0,f+="\n\tMulti-Material "+e.Material.ParseMultiMaterial(P,o).toString(d);break}}if(!1===T){y.push(x.materialId);var R=i(x.materialId,p,o,a);R?f+="\n\tMaterial "+R.toString(d):e.Tools.Warn("Material not found for mesh "+x.id)}}if(x.skeletonId>-1&&void 0!==p.skeletons&&null!==p.skeletons&&!1===_.indexOf(x.skeletonId)>-1)for(var I=0,O=p.skeletons.length;I<O;I++){var D=p.skeletons[I];if(D.id===x.skeletonId){var w=e.Skeleton.Parse(D,o);u.push(w),_.push(D.id),f+="\n\tSkeleton "+w.toString(d)}}var L=e.Mesh.Parse(x,o,a);l.push(L),f+="\n\tMesh "+L.toString(d)}}var F;for(g=0,v=o.meshes.length;g<v;g++)(F=o.meshes[g])._waitingParentId&&(F.parent=o.getLastEntryByID(F._waitingParentId),F._waitingParentId=null);for(g=0,v=o.meshes.length;g<v;g++)(F=o.meshes[g])._waitingFreezeWorldMatrix?(F.freezeWorldMatrix(),F._waitingFreezeWorldMatrix=null):F.computeWorldMatrix(!0)}if(void 0!==p.particleSystems&&null!==p.particleSystems)for(g=0,v=p.particleSystems.length;g<v;g++){var N=p.particleSystems[g];-1!==m.indexOf(N.emitterId)&&h.push(e.ParticleSystem.Parse(N,o,a))}return!0}catch(t){var B=n("importMesh",p?p.producer:"Unknown")+f;if(!c)throw e.Tools.Log(B),t;c(B,t)}finally{null!==f&&e.SceneLoader.loggingLevel!==e.SceneLoader.NO_LOGGING&&e.Tools.Log(n("importMesh",p?p.producer:"Unknown")+(e.SceneLoader.loggingLevel!==e.SceneLoader.MINIMAL_LOGGING?f:""))}return!1},load:function(t,i,r,o){var s="importScene has failed JSON parse";try{var a=JSON.parse(i);s="";var l=e.SceneLoader.loggingLevel===e.SceneLoader.DETAILED_LOGGING;if(void 0!==a.useDelayedTextureLoading&&null!==a.useDelayedTextureLoading&&(t.useDelayedTextureLoading=a.useDelayedTextureLoading&&!e.SceneLoader.ForceFullSceneLoadingForIncremental),void 0!==a.autoClear&&null!==a.autoClear&&(t.autoClear=a.autoClear),void 0!==a.clearColor&&null!==a.clearColor&&(t.clearColor=e.Color4.FromArray(a.clearColor)),void 0!==a.ambientColor&&null!==a.ambientColor&&(t.ambientColor=e.Color3.FromArray(a.ambientColor)),void 0!==a.gravity&&null!==a.gravity&&(t.gravity=e.Vector3.FromArray(a.gravity)),a.fogMode&&0!==a.fogMode)switch(t.fogMode=a.fogMode,t.fogColor=e.Color3.FromArray(a.fogColor),t.fogStart=a.fogStart,t.fogEnd=a.fogEnd,t.fogDensity=a.fogDensity,s+="\tFog mode for scene: ",t.fogMode){case 1:s+="exp\n";break;case 2:s+="exp2\n";break;case 3:s+="linear\n"}if(a.physicsEnabled){var h;"cannon"===a.physicsEngine?h=new e.CannonJSPlugin:"oimo"===a.physicsEngine&&(h=new e.OimoJSPlugin),s="\tPhysics engine "+(a.physicsEngine?a.physicsEngine:"oimo")+" enabled\n";var u=a.physicsGravity?e.Vector3.FromArray(a.physicsGravity):null;t.enablePhysics(u,h)}void 0!==a.metadata&&null!==a.metadata&&(t.metadata=a.metadata),void 0!==a.collisionsEnabled&&null!==a.collisionsEnabled&&(t.collisionsEnabled=a.collisionsEnabled),t.workerCollisions=!!a.workerCollisions;var c,f;if(void 0!==a.lights&&null!==a.lights)for(c=0,f=a.lights.length;c<f;c++){var p=a.lights[c],d=e.Light.Parse(p,t);d&&(s+=0===c?"\n\tLights:":"",s+="\n\t\t"+d.toString(l))}if(void 0!==a.animations&&null!==a.animations)for(c=0,f=a.animations.length;c<f;c++){var m=a.animations[c],g=e.Animation.Parse(m);t.animations.push(g),s+=0===c?"\n\tAnimations:":"",s+="\n\t\t"+g.toString(l)}if(a.autoAnimate&&t.beginAnimation(t,a.autoAnimateFrom,a.autoAnimateTo,a.autoAnimateLoop,a.autoAnimateSpeed||1),void 0!==a.materials&&null!==a.materials)for(c=0,f=a.materials.length;c<f;c++){var v=a.materials[c],_=e.Material.Parse(v,t,r);s+=0===c?"\n\tMaterials:":"",s+="\n\t\t"+_.toString(l)}if(void 0!==a.multiMaterials&&null!==a.multiMaterials)for(c=0,f=a.multiMaterials.length;c<f;c++){var y=a.multiMaterials[c],x=e.Material.ParseMultiMaterial(y,t);s+=0===c?"\n\tMultiMaterials:":"",s+="\n\t\t"+x.toString(l)}if(void 0!==a.morphTargetManagers&&null!==a.morphTargetManagers)for(var b=0,T=a.morphTargetManagers;b<T.length;b++){var E=T[b];e.MorphTargetManager.Parse(E,t)}if(void 0!==a.skeletons&&null!==a.skeletons)for(c=0,f=a.skeletons.length;c<f;c++){var A=a.skeletons[c],P=e.Skeleton.Parse(A,t);s+=0===c?"\n\tSkeletons:":"",s+="\n\t\t"+P.toString(l)}var S=a.geometries;if(void 0!==S&&null!==S){var M=S.boxes;if(void 0!==M&&null!==M)for(c=0,f=M.length;c<f;c++){var C=M[c];e.Geometry.Primitives.Box.Parse(C,t)}var R=S.spheres;if(void 0!==R&&null!==R)for(c=0,f=R.length;c<f;c++){var I=R[c];e.Geometry.Primitives.Sphere.Parse(I,t)}var O=S.cylinders;if(void 0!==O&&null!==O)for(c=0,f=O.length;c<f;c++){var D=O[c];e.Geometry.Primitives.Cylinder.Parse(D,t)}var w=S.toruses;if(void 0!==w&&null!==w)for(c=0,f=w.length;c<f;c++){var L=w[c];e.Geometry.Primitives.Torus.Parse(L,t)}var F=S.grounds;if(void 0!==F&&null!==F)for(c=0,f=F.length;c<f;c++){var N=F[c];e.Geometry.Primitives.Ground.Parse(N,t)}var B=S.planes;if(void 0!==B&&null!==B)for(c=0,f=B.length;c<f;c++){var V=B[c];e.Geometry.Primitives.Plane.Parse(V,t)}var U=S.torusKnots;if(void 0!==U&&null!==U)for(c=0,f=U.length;c<f;c++){var z=U[c];e.Geometry.Primitives.TorusKnot.Parse(z,t)}var k=S.vertexData;if(void 0!==k&&null!==k)for(c=0,f=k.length;c<f;c++){var G=k[c];e.Geometry.Parse(G,t,r)}}if(void 0!==a.transformNodes&&null!==a.transformNodes)for(c=0,f=a.transformNodes.length;c<f;c++){var H=a.transformNodes[c];e.TransformNode.Parse(H,t,r)}if(void 0!==a.meshes&&null!==a.meshes)for(c=0,f=a.meshes.length;c<f;c++){var W=a.meshes[c],j=e.Mesh.Parse(W,t,r);s+=0===c?"\n\tMeshes:":"",s+="\n\t\t"+j.toString(l)}if(void 0!==a.cameras&&null!==a.cameras)for(c=0,f=a.cameras.length;c<f;c++){var X=a.cameras[c],Y=e.Camera.Parse(X,t);s+=0===c?"\n\tCameras:":"",s+="\n\t\t"+Y.toString(l)}for(void 0!==a.activeCameraID&&null!==a.activeCameraID&&t.setActiveCameraByID(a.activeCameraID),c=0,f=t.cameras.length;c<f;c++)(Y=t.cameras[c])._waitingParentId&&(Y.parent=t.getLastEntryByID(Y._waitingParentId),Y._waitingParentId=null);for(c=0,f=t.lights.length;c<f;c++){var K=t.lights[c];K&&K._waitingParentId&&(K.parent=t.getLastEntryByID(K._waitingParentId),K._waitingParentId=null)}var Q,Z=[];if(e.AudioEngine&&void 0!==a.sounds&&null!==a.sounds)for(c=0,f=a.sounds.length;c<f;c++){var q=a.sounds[c];e.Engine.audioEngine.canUseWebAudio?(q.url||(q.url=q.name),Z[q.url]?e.Sound.Parse(q,t,r,Z[q.url]):(Q=e.Sound.Parse(q,t,r),Z[q.url]=Q)):new e.Sound(q.name,null,t)}for(Z=[],c=0,f=t.transformNodes.length;c<f;c++){var J=t.transformNodes[c];J._waitingParentId&&(J.parent=t.getLastEntryByID(J._waitingParentId),J._waitingParentId=null)}for(c=0,f=t.meshes.length;c<f;c++)(j=t.meshes[c])._waitingParentId&&(j.parent=t.getLastEntryByID(j._waitingParentId),j._waitingParentId=null),j._waitingActions&&(e.ActionManager.Parse(j._waitingActions,j,t),j._waitingActions=null);for(c=0,f=t.meshes.length;c<f;c++){var $=t.meshes[c];$._waitingFreezeWorldMatrix?($.freezeWorldMatrix(),$._waitingFreezeWorldMatrix=null):$.computeWorldMatrix(!0)}if(void 0!==a.particleSystems&&null!==a.particleSystems)for(c=0,f=a.particleSystems.length;c<f;c++){var ee=a.particleSystems[c];e.ParticleSystem.Parse(ee,t,r)}if(void 0!==a.environmentTexture&&null!==a.environmentTexture&&(t.environmentTexture=e.CubeTexture.CreateFromPrefilteredData(r+a.environmentTexture,t),!0===a.createDefaultSkybox)){var te=void 0!==t.activeCamera&&null!==t.activeCamera?(t.activeCamera.maxZ-t.activeCamera.minZ)/2:1e3,ie=a.skyboxBlurLevel||0;t.createDefaultSkybox(void 0,!0,te,ie)}if(void 0!==a.lensFlareSystems&&null!==a.lensFlareSystems)for(c=0,f=a.lensFlareSystems.length;c<f;c++){var re=a.lensFlareSystems[c];e.LensFlareSystem.Parse(re,t,r)}if(void 0!==a.shadowGenerators&&null!==a.shadowGenerators)for(c=0,f=a.shadowGenerators.length;c<f;c++){var ne=a.shadowGenerators[c];e.ShadowGenerator.Parse(ne,t)}for(c=0,f=t.lights.length;c<f;c++){var oe=t.lights[c];if(oe._excludedMeshesIds.length>0){for(var se=0;se<oe._excludedMeshesIds.length;se++){var ae=t.getMeshByID(oe._excludedMeshesIds[se]);ae&&oe.excludedMeshes.push(ae)}oe._excludedMeshesIds=[]}if(oe._includedOnlyMeshesIds.length>0){for(var le=0;le<oe._includedOnlyMeshesIds.length;le++){var he=t.getMeshByID(oe._includedOnlyMeshesIds[le]);he&&oe.includedOnlyMeshes.push(he)}oe._includedOnlyMeshesIds=[]}}return void 0!==a.actions&&null!==a.actions&&e.ActionManager.Parse(a.actions,null,t),!0}catch(t){var ue=n("importScene",a?a.producer:"Unknown")+s;if(!o)throw e.Tools.Log(ue),t;o(ue,t)}finally{null!==s&&e.SceneLoader.loggingLevel!==e.SceneLoader.NO_LOGGING&&e.Tools.Log(n("importScene",a?a.producer:"Unknown")+(e.SceneLoader.loggingLevel!==e.SceneLoader.MINIMAL_LOGGING?s:""))}return!1}})}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){var t=function(){function t(e,t,i,r,n,o,s,a,l){this.onProcessFileCallback=function(){return!0},this._engine=e,this._currentScene=t,this._sceneLoadedCallback=i,this._progressCallback=r,this._additionalRenderLoopLogicCallback=n,this._textureLoadingCallback=o,this._startingProcessingFilesCallback=s,this._onReloadCallback=a,this._errorCallback=l}return t.prototype.monitorElementForDragNDrop=function(e){var t=this;e&&(this._elementToMonitor=e,this._dragEnterHandler=function(e){t.drag(e)},this._dragOverHandler=function(e){t.drag(e)},this._dropHandler=function(e){t.drop(e)},this._elementToMonitor.addEventListener("dragenter",this._dragEnterHandler,!1),this._elementToMonitor.addEventListener("dragover",this._dragOverHandler,!1),this._elementToMonitor.addEventListener("drop",this._dropHandler,!1))},t.prototype.dispose=function(){this._elementToMonitor&&(this._elementToMonitor.removeEventListener("dragenter",this._dragEnterHandler),this._elementToMonitor.removeEventListener("dragover",this._dragOverHandler),this._elementToMonitor.removeEventListener("drop",this._dropHandler))},t.prototype.renderFunction=function(){if(this._additionalRenderLoopLogicCallback&&this._additionalRenderLoopLogicCallback(),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._traverseFolder=function(e,t,i,r){var n=this,o=e.createReader(),s=e.fullPath.replace(/^\//,"").replace(/(.+?)\/?$/,"$1/");o.readEntries(function(e){i.count+=e.length;for(var o=0,a=e;o<a.length;o++){var l=a[o];l.isFile?l.file(function(e){e.correctName=s+e.name,t.push(e),0==--i.count&&r()}):l.isDirectory&&n._traverseFolder(l,t,i,r)}--i.count&&r()})},t.prototype._processFiles=function(e){for(var i=0,r=0;r<e.length;r++){var n=e[r].correctName.toLowerCase(),o=n.split(".").pop();this.onProcessFileCallback(e[r],n,o)?"babylon"!==o&&"stl"!==o&&"obj"!==o&&"gltf"!==o&&"glb"!==o||-1!==n.indexOf(".binary.babylon")||-1!==n.indexOf(".incremental.babylon")?t.FilesToLoad[n]=e[r]:this._sceneFileToLoad=e[r]:i++}this._onReloadCallback?this._onReloadCallback(this._sceneFileToLoad):i<e.length&&this.reload()},t.prototype.loadFiles=function(e){var t=this;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=new Array,r=[],n=e.dataTransfer?e.dataTransfer.items:null,o=0;o<this._filesToLoad.length;o++){var s=this._filesToLoad[o],a=s.name.toLowerCase(),l=void 0;if(s.correctName=a,n){var h=n[o];h.getAsEntry?l=h.getAsEntry():h.webkitGetAsEntry&&(l=h.webkitGetAsEntry())}l&&l.isDirectory?r.push(l):i.push(s)}if(0===r.length)this._processFiles(i);else for(var u={count:r.length},c=0,f=r;c<f.length;c++){var p=f[c];this._traverseFolder(p,i,u,function(){t._processFiles(i)})}}},t.prototype.reload=function(){var t=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){t._currentScene=e,t._sceneLoadedCallback&&t._sceneLoadedCallback(t._sceneFileToLoad,t._currentScene),t._currentScene.executeWhenReady(function(){t._engine.runRenderLoop(function(){t.renderFunction()})})},function(e){t._progressCallback&&t._progressCallback(e)},function(e,i){t._currentScene=e,t._errorCallback&&t._errorCallback(t._sceneFileToLoad,t._currentScene,i)})):e.Tools.Error("Please provide a valid .babylon file.")},t.FilesToLoad={},t}();e.FilesInput=t}(s||(s={}));!function(e){var t=function(){function e(){this._count=0,this._data={}}return e.prototype.copyFrom=function(e){var t=this;this.clear(),e.forEach(function(e,i){return t.add(e,i)})},e.prototype.get=function(e){var t=this._data[e];if(void 0!==t)return t},e.prototype.getOrAddWithFactory=function(e,t){var i=this.get(e);return void 0!==i?i:((i=t(e))&&this.add(e,i),i)},e.prototype.getOrAdd=function(e,t){var i=this.get(e);return void 0!==i?i:(this.add(e,t),t)},e.prototype.contains=function(e){return void 0!==this._data[e]},e.prototype.add=function(e,t){return void 0===this._data[e]&&(this._data[e]=t,++this._count,!0)},e.prototype.set=function(e,t){return void 0!==this._data[e]&&(this._data[e]=t,!0)},e.prototype.getAndRemove=function(e){var t=this.get(e);return void 0!==t?(delete this._data[e],--this._count,t):null},e.prototype.remove=function(e){return!!this.contains(e)&&(delete this._data[e],--this._count,!0)},e.prototype.clear=function(){this._data={},this._count=0},Object.defineProperty(e.prototype,"count",{get:function(){return this._count},enumerable:!0,configurable:!0}),e.prototype.forEach=function(e){for(var t in this._data)e(t,this._data[t])},e.prototype.first=function(e){for(var t in this._data){var i=e(t,this._data[t]);if(i)return i}return null},e}();e.StringDictionary=t}(s||(s={}));!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)},t.GetTags=function(e,t){if(void 0===t&&(t=!0),!e._tags)return null;if(t){var i=[];for(var r in e._tags)e._tags.hasOwnProperty(r)&&!0===e._tags[r]&&i.push(r);return i.join(" ")}return e._tags},t.AddTagsTo=function(e,i){i&&"string"==typeof i&&i.split(" ").forEach(function(i,r,n){t._AddTagTo(e,i)})},t._AddTagTo=function(e,i){""!==(i=i.trim())&&"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 r=i.split(" ");for(var n in r)t._RemoveTagFrom(e,r[n])}},t._RemoveTagFrom=function(e,t){delete e._tags[t]},t.MatchesQuery=function(i,r){return void 0===r||(""===r?t.HasTags(i):e.Internals.AndOrNotEvaluator.Eval(r,function(e){return t.HasTags(i)&&i._tags[e]}))},t}();e.Tags=t}(s||(s={}));!function(e){!function(e){var t=function(){function e(){}return e.Eval=function(t,i){return"true"===(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))||"false"!==t&&e.Eval(t,i)},e._HandleParenthesisContent=function(t,i){i=i||function(e){return"true"===e};var r,n=t.split("||");for(var o in n)if(n.hasOwnProperty(o)){var s=e._SimplifyNegation(n[o].trim()),a=s.split("&&");if(a.length>1)for(var l=0;l<a.length;++l){var h=e._SimplifyNegation(a[l].trim());if(!(r="true"!==h&&"false"!==h?"!"===h[0]?!i(h.substring(1)):i(h):"true"===h)){s="false";break}}if(r||"true"===s){r=!0;break}r="true"!==s&&"false"!==s?"!"===s[0]?!i(s.substring(1)):i(s):"true"===s}return r?"true":"false"},e._SimplifyNegation=function(e){return e=e.replace(/^[\s!]+/,function(e){return(e=e.replace(/[\s]/g,function(){return""})).length%2?"!":""}),"!true"===(e=e.trim())?e="false":"!false"===e&&(e="true"),e},e}();e.AndOrNotEvaluator=t}(e.Internals||(e.Internals={}))}(s||(s={}));!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 Object.defineProperty(t.prototype,"enableSceneOffline",{get:function(){return this._enableSceneOffline},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enableTexturesOffline",{get:function(){return this._enableTexturesOffline},enumerable:!0,configurable:!0}),t.prototype.checkManifestFile=function(){var t=this,i=function(){t._enableSceneOffline=!1,t._enableTexturesOffline=!1,t.callbackManifestChecked(!1)},r=!1,n=this.currentSceneUrl+".manifest",o=new XMLHttpRequest;navigator.onLine&&(r=!0,n=n+(null==n.match(/\?/)?"?":"&")+(new Date).getTime()),o.open("GET",n,!0),o.addEventListener("load",function(){if(200===o.status||e.Tools.ValidateXHRData(o,1))try{var r=JSON.parse(o.response);t._enableSceneOffline=r.enableSceneOffline,t._enableTexturesOffline=r.enableTexturesOffline,r.version&&!isNaN(parseInt(r.version))&&(t.manifestVersionFound=r.version),t.callbackManifestChecked&&t.callbackManifestChecked(!0)}catch(e){i()}else i()},!1),o.addEventListener("error",function(e){if(r){r=!1;var n=t.currentSceneUrl+".manifest";o.open("GET",n,!0),o.send()}else i()},!1);try{o.send()}catch(t){e.Tools.Error("Error on XHR send request."),this.callbackManifestChecked(!1)}},t.prototype.openAsync=function(t,i){var r=this,n=function(){r.isSupported=!1,i&&i()};if(this.idbFactory&&(this._enableSceneOffline||this._enableTexturesOffline))if(this.db)t&&t();else{this.hasReachedQuota=!1,this.isSupported=!0;var o=this.idbFactory.open("babylonjs",1);o.onerror=function(e){n()},o.onblocked=function(t){e.Tools.Error("IDB request blocked. Please reload the page."),n()},o.onsuccess=function(e){r.db=o.result,t()},o.onupgradeneeded=function(t){if(r.db=t.target.result,r.db)try{r.db.createObjectStore("scenes",{keyPath:"sceneUrl"}),r.db.createObjectStore("versions",{keyPath:"sceneUrl"}),r.db.createObjectStore("textures",{keyPath:"textureUrl"})}catch(t){e.Tools.Error("Error while creating object stores. Exception: "+t.message),n()}}}else this.isSupported=!1,i&&i()},t.prototype.loadImageFromDB=function(e,i){var r=this,n=t.ReturnFullUrlLocation(e),o=function(){r.hasReachedQuota||null===r.db?i.src=e:r._saveImageIntoDBAsync(n,i)};this.mustUpdateRessources?o():this._loadImageFromDBAsync(n,i,o)},t.prototype._loadImageFromDBAsync=function(t,i,r){if(this.isSupported&&null!==this.db){var n,o=this.db.transaction(["textures"]);o.onabort=function(e){i.src=t},o.oncomplete=function(o){var s;if(n){var a=window.URL||window.webkitURL;s=a.createObjectURL(n.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 r()};var s=o.objectStore("textures").get(t);s.onsuccess=function(e){n=e.target.result},s.onerror=function(r){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,r){var n=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)}}e&&(r.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&&n.db){s=a.response;var e=n.db.transaction(["textures"],"readwrite");e.onabort=function(e){try{var t=(e.srcElement||e.target).error;t&&"QuotaExceededError"===t.name&&(n.hasReachedQuota=!0)}catch(e){}o()},e.oncomplete=function(e){o()};var l={textureUrl:i,data:s};try{var h=e.objectStore("textures").put(l);h.onsuccess=function(e){},h.onerror=function(e){o()}}catch(e){25===e.code&&(t.IsUASupportingBlobStorage=!1),r.src=i}}else r.src=i},!1),a.addEventListener("error",function(t){e.Tools.Error("Error in XHR request in BABYLON.Database."),r.src=i},!1),a.send()}else r.src=i}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),r.src=i},t.prototype._checkVersionFromDB=function(e,t){var i=this;this._loadVersionFromDBAsync(e,t,function(){i._saveVersionIntoDBAsync(e,t)})},t.prototype._loadVersionFromDBAsync=function(t,i,r){var n=this;if(this.isSupported&&this.db){var o;try{var s=this.db.transaction(["versions"]);s.oncomplete=function(e){o?n.manifestVersionFound>o.data?(n.mustUpdateRessources=!0,r()):i(o.data):(n.mustUpdateRessources=!0,r())},s.onabort=function(e){i(-1)};var a=s.objectStore("versions").get(t);a.onsuccess=function(e){o=e.target.result},a.onerror=function(r){e.Tools.Error("Error loading version for scene "+t+" from DB."),i(-1)}}catch(t){e.Tools.Error("Error while accessing 'versions' object store (READ OP). Exception: "+t.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 r=this;if(this.isSupported&&!this.hasReachedQuota&&this.db)try{var n=this.db.transaction(["versions"],"readwrite");n.onabort=function(e){try{var t=e.srcElement.error;t&&"QuotaExceededError"===t.name&&(r.hasReachedQuota=!0)}catch(e){}i(-1)},n.oncomplete=function(e){i(r.manifestVersionFound)};var o={sceneUrl:t,data:this.manifestVersionFound},s=n.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(t){e.Tools.Error("Error while accessing 'versions' object store (WRITE OP). Exception: "+t.message),i(-1)}else i(-1)},t.prototype.loadFileFromDB=function(e,i,r,n,o){var s=this,a=t.ReturnFullUrlLocation(e),l=function(){s._saveFileIntoDBAsync(a,i,r)};this._checkVersionFromDB(a,function(e){-1!==e?s.mustUpdateRessources?s._saveFileIntoDBAsync(a,i,r,o):s._loadFileFromDBAsync(a,i,l,o):n&&n()})},t.prototype._loadFileFromDBAsync=function(t,i,r,n){if(this.isSupported&&this.db){var o;o=-1!==t.indexOf(".babylon")?"scenes":"textures";var s,a=this.db.transaction([o]);a.oncomplete=function(e){s?i(s.data):r()},a.onabort=function(e){r()};var l=a.objectStore(o).get(t);l.onsuccess=function(e){s=e.target.result},l.onerror=function(i){e.Tools.Error("Error loading file "+t+" from DB."),r()}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},t.prototype._saveFileIntoDBAsync=function(t,i,r,n){var o=this;if(this.isSupported){var s;s=-1!==t.indexOf(".babylon")?"scenes":"textures";var a,l=new XMLHttpRequest;l.open("GET",t,!0),n&&(l.responseType="arraybuffer"),r&&(l.onprogress=r),l.addEventListener("load",function(){if(200===l.status||e.Tools.ValidateXHRData(l,n?6:1))if(a=n?l.response:l.responseText,!o.hasReachedQuota&&o.db){var r=o.db.transaction([s],"readwrite");r.onabort=function(e){try{var t=e.srcElement.error;t&&"QuotaExceededError"===t.name&&(o.hasReachedQuota=!0)}catch(e){}i(a)},r.oncomplete=function(e){i(a)};var h;h="scenes"===s?{sceneUrl:t,data:a,version:o.manifestVersionFound}:{textureUrl:t,data:a};try{var u=r.objectStore(s).put(h);u.onsuccess=function(e){},u.onerror=function(t){e.Tools.Error("Error in DB add file request in BABYLON.Database.")}}catch(e){i(a)}}else i(a);else i()},!1),l.addEventListener("error",function(t){e.Tools.Error("error on XHR request."),i()},!1),l.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){document.createElement("a").href=e;var t=e.substring(0,e.lastIndexOf("#")),i=e.substring(t.lastIndexOf("/")+1,e.length);return e.substring(0,e.indexOf(i,0))},t.ReturnFullUrlLocation=function(e){return-1===e.indexOf("http:/")&&-1===e.indexOf("https:/")?t.parseURL(window.location.href)+e:e},t}();e.Database=t}(s||(s={}));!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 Object.defineProperty(t.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(t){this._isEnabled!==t&&(this._isEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.FresnelDirtyFlag))},enumerable:!0,configurable:!0}),t.prototype.clone=function(){var i=new t;return e.Tools.DeepCopy(this,i),i},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 r=new t;return r.isEnabled=i.isEnabled,r.leftColor=e.Color3.FromArray(i.leftColor),r.rightColor=e.Color3.FromArray(i.rightColor),r.bias=i.bias,r.power=i.power||1,r},t}();e.FresnelParameters=t}(s||(s={}));!function(e){var t=function(t){function i(e,i){var r=t.call(this,e,i,!0)||this;return i.multiMaterials.push(r),r.subMaterials=new Array,r.storeEffectOnSubMeshes=!0,r}return n(i,t),Object.defineProperty(i.prototype,"subMaterials",{get:function(){return this._subMaterials},set:function(e){this._subMaterials=e,this._hookArray(e)},enumerable:!0,configurable:!0}),i.prototype._hookArray=function(e){var t=this,i=e.push;e.push=function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];var o=i.apply(e,r);return t._markAllSubMeshesAsTexturesDirty(),o};var r=e.splice;e.splice=function(i,n){var o=r.apply(e,[i,n]);return t._markAllSubMeshesAsTexturesDirty(),o}},i.prototype.getSubMaterial=function(e){return e<0||e>=this.subMaterials.length?this.getScene().defaultMaterial:this.subMaterials[e]},i.prototype.getActiveTextures=function(){return(e=t.prototype.getActiveTextures.call(this)).concat.apply(e,this.subMaterials.map(function(e){return e?e.getActiveTextures():[]}));var e},i.prototype.getClassName=function(){return"MultiMaterial"},i.prototype.isReadyForSubMesh=function(e,t,i){for(var r=0;r<this.subMaterials.length;r++){var n=this.subMaterials[r];if(n){if(n.storeEffectOnSubMeshes){if(!n.isReadyForSubMesh(e,t,i))return!1;continue}if(!n.isReady(e))return!1}}return!0},i.prototype.clone=function(e,t){for(var r=new i(e,this.getScene()),n=0;n<this.subMaterials.length;n++){var o=null,s=this.subMaterials[n];o=t&&s?s.clone(e+"-"+s.name):this.subMaterials[n],r.subMaterials.push(o)}return r},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 r=this.subMaterials[i];r?t.materials.push(r.id):t.materials.push(null)}return t},i.prototype.dispose=function(e,i){var r=this.getScene();if(r){var n=r.multiMaterials.indexOf(this);n>=0&&r.multiMaterials.splice(n,1),t.prototype.dispose.call(this,e,i)}},i}(e.Material);e.MultiMaterial=t}(s||(s={}));!function(e){var t=function(){function t(){this._offsetX=null,this._offsetY=null,this._pointerCount=0,this._pointerPressed=new Array,this.touchAngularSensibility=2e5,this.touchMoveSensibility=250}return t.prototype.attachControl=function(t,i){var r=this,n=null;void 0===this._pointerInput&&(this._onLostFocus=function(e){r._offsetX=null,r._offsetY=null},this._pointerInput=function(t,o){var s=t.event;if("mouse"!==s.pointerType)if(t.type===e.PointerEventTypes.POINTERDOWN){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(i||s.preventDefault(),-1===(a=r._pointerPressed.indexOf(s.pointerId)))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(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),this._onLostFocus&&t.addEventListener("blur",this._onLostFocus)},t.prototype.detachControl=function(e){this._pointerInput&&e&&(this._observer&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._observer=null),this._onLostFocus&&(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&&this._offsetY){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(),r=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(r,t._cameraRotationMatrix))}}},t.prototype.getClassName=function(){return"FreeCameraTouchInput"},t.prototype.getSimpleName=function(){return"touch"},r([e.serialize()],t.prototype,"touchAngularSensibility",void 0),r([e.serialize()],t.prototype,"touchMoveSensibility",void 0),t}();e.FreeCameraTouchInput=t,e.CameraInputTypes.FreeCameraTouchInput=t}(s||(s={}));!function(e){var t=function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n.inputs.addTouch(),n._setupInputs(),n}return n(t,e),Object.defineProperty(t.prototype,"touchAngularSensibility",{get:function(){var e=this.inputs.attached.touch;return e?e.touchAngularSensibility: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:0},set:function(e){var t=this.inputs.attached.touch;t&&(t.touchMoveSensibility=e)},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"TouchCamera"},t.prototype._setupInputs=function(){var e=this.inputs.attached.mouse;e&&(e.touchEnabled=!1)},t}(e.FreeCamera);e.TouchCamera=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l){void 0===s&&(s=null),void 0===a&&(a=!0),void 0===l&&(l=!1);var h=t.call(this,null,o,!a)||this;h.isCube=l,h.isEnabled=!0,h._currentRefreshId=-1,h._refreshRate=1,h._vertexBuffers={},h._uniforms=new Array,h._samplers=new Array,h._textures={},h._floats={},h._floatsArrays={},h._colors3={},h._colors4={},h._vectors2={},h._vectors3={},h._matrices={},h._fallbackTextureUsed=!1,o._proceduralTextures.push(h),h._engine=o.getEngine(),h.name=i,h.isRenderTarget=!0,h._size=r,h._generateMipMaps=a,h.setFragment(n),h._fallbackTexture=s,l?(h._texture=h._engine.createRenderTargetCubeTexture(r,{generateMipMaps:a}),h.setFloat("face",0)):h._texture=h._engine.createRenderTargetTexture(r,a);var u=[];return u.push(1,1),u.push(-1,1),u.push(-1,-1),u.push(1,-1),h._vertexBuffers[e.VertexBuffer.PositionKind]=new e.VertexBuffer(h._engine,u,e.VertexBuffer.PositionKind,!1,!1,2),h._createIndexBuffer(),h}return n(i,t),i.prototype._createIndexBuffer=function(){var e=this._engine,t=[];t.push(0),t.push(1),t.push(2),t.push(0),t.push(2),t.push(3),this._indexBuffer=e.createIndexBuffer(t)},i.prototype._rebuild=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&t._rebuild(),this._createIndexBuffer(),this.refreshRate===e.RenderTargetTexture.REFRESHRATE_RENDER_ONCE&&(this.refreshRate=e.RenderTargetTexture.REFRESHRATE_RENDER_ONCE)},i.prototype.reset=function(){void 0!==this._effect&&this._engine._releaseEffect(this._effect)},i.prototype.isReady=function(){var t,i=this,r=this._engine;return!!this._fragment&&(!!this._fallbackTextureUsed||(t=void 0!==this._fragment.fragmentElement?{vertex:"procedural",fragmentElement:this._fragment.fragmentElement}:{vertex:"procedural",fragment:this._fragment},this._effect=r.createEffect(t,[e.VertexBuffer.PositionKind],this._uniforms,this._samplers,"",void 0,void 0,function(){i.releaseInternalTexture(),i._fallbackTexture&&(i._texture=i._fallbackTexture._texture,i._texture&&i._texture.incrementReferences()),i._fallbackTextureUsed=!0}),this._effect.isReady()))},i.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},i.prototype.setFragment=function(e){this._fragment=e},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!!(this.isEnabled&&this.isReady()&&this._texture)&&(!this._fallbackTextureUsed&&(-1===this._currentRefreshId?(this._currentRefreshId=1,!0):this.refreshRate===this._currentRefreshId?(this._currentRefreshId=1,!0):(this._currentRefreshId++,!1)))},i.prototype.getRenderSize=function(){return this._size},i.prototype.resize=function(e,t){this._fallbackTextureUsed||(this.releaseInternalTexture(),this._texture=this._engine.createRenderTargetTexture(e,t))},i.prototype._checkUniform=function(e){-1===this._uniforms.indexOf(e)&&this._uniforms.push(e)},i.prototype.setTexture=function(e,t){return-1===this._samplers.indexOf(e)&&this._samplers.push(e),this._textures[e]=t,this},i.prototype.setFloat=function(e,t){return this._checkUniform(e),this._floats[e]=t,this},i.prototype.setFloats=function(e,t){return this._checkUniform(e),this._floatsArrays[e]=t,this},i.prototype.setColor3=function(e,t){return this._checkUniform(e),this._colors3[e]=t,this},i.prototype.setColor4=function(e,t){return this._checkUniform(e),this._colors4[e]=t,this},i.prototype.setVector2=function(e,t){return this._checkUniform(e),this._vectors2[e]=t,this},i.prototype.setVector3=function(e,t){return this._checkUniform(e),this._vectors3[e]=t,this},i.prototype.setMatrix=function(e,t){return this._checkUniform(e),this._matrices[e]=t,this},i.prototype.render=function(e){var t=this.getScene();if(t){var i=this._engine;i.enableEffect(this._effect),i.setState(!1);for(var r in this._textures)this._effect.setTexture(r,this._textures[r]);for(r in this._floats)this._effect.setFloat(r,this._floats[r]);for(r in this._floatsArrays)this._effect.setArray(r,this._floatsArrays[r]);for(r in this._colors3)this._effect.setColor3(r,this._colors3[r]);for(r in this._colors4){var n=this._colors4[r];this._effect.setFloat4(r,n.r,n.g,n.b,n.a)}for(r in this._vectors2)this._effect.setVector2(r,this._vectors2[r]);for(r in this._vectors3)this._effect.setVector3(r,this._vectors3[r]);for(r in this._matrices)this._effect.setMatrix(r,this._matrices[r]);if(this._texture){if(this.isCube)for(var o=0;o<6;o++)i.bindFramebuffer(this._texture,o,void 0,void 0,!0),i.bindBuffers(this._vertexBuffers,this._indexBuffer,this._effect),this._effect.setFloat("face",o),i.clear(t.clearColor,!0,!0,!0),i.draw(!0,0,6),5===o&&i.generateMipMapsForCubemap(this._texture);else i.bindFramebuffer(this._texture,0,void 0,void 0,!0),i.bindBuffers(this._vertexBuffers,this._indexBuffer,this._effect),i.clear(t.clearColor,!0,!0,!0),i.draw(!0,0,6);i.unBindFramebuffer(this._texture,this.isCube),this.onGenerated&&this.onGenerated()}}},i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this._fragment,this.getScene(),this._fallbackTexture,this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.coordinatesMode=this.coordinatesMode,t},i.prototype.dispose=function(){var i=this.getScene();if(i){var r=i._proceduralTextures.indexOf(this);r>=0&&i._proceduralTextures.splice(r,1);var n=this._vertexBuffers[e.VertexBuffer.PositionKind];n&&(n.dispose(),this._vertexBuffers[e.VertexBuffer.PositionKind]=null),this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer)&&(this._indexBuffer=null),t.prototype.dispose.call(this)}},i}(e.Texture);e.ProceduralTexture=t}(s||(s={}));!function(e){var t=function(t){function i(e,i,r,n,o,s){var a=t.call(this,e,r,null,n,o,s)||this;return a._animate=!0,a._time=0,a._texturePath=i,a.loadJson(i),a.refreshRate=1,a}return n(i,t),i.prototype.loadJson=function(t){var i=this,r=function(){e.Tools.Log("No config file found in "+t+" trying to use ShadersStore or DOM element");try{i.setFragment(i._texturePath)}catch(t){e.Tools.Error("No json or ShaderStore or DOM element found for CustomProceduralTexture")}},n=t+"/config.json",o=new XMLHttpRequest;o.open("GET",n,!0),o.addEventListener("load",function(){if(200===o.status||e.Tools.ValidateXHRData(o,1))try{i._config=JSON.parse(o.response),i.updateShaderUniforms(),i.updateTextures(),i.setFragment(i._texturePath+"/custom"),i._animate=i._config.animate,i.refreshRate=i._config.refreshrate}catch(e){r()}else r()},!1),o.addEventListener("error",function(){r()},!1);try{o.send()}catch(t){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)if(!this._textures[e].isReady())return!1;return!0},i.prototype.render=function(e){var i=this.getScene();this._animate&&i&&(this._time+=.03*i.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}(s||(s={}));!function(e){var t=function(){function t(){this.gamepadAngularSensibility=200,this.gamepadMoveSensibility=40,this._cameraTransform=e.Matrix.Identity(),this._deltaTransform=e.Vector3.Zero(),this._vector3=e.Vector3.Zero(),this._vector2=e.Vector2.Zero()}return t.prototype.attachControl=function(t,i){var r=this,n=this.camera.getScene().gamepadManager;this._onGamepadConnectedObserver=n.onGamepadConnectedObservable.add(function(t){t.type!==e.Gamepad.POSE_ENABLED&&(r.gamepad&&t.type!==e.Gamepad.XBOX||(r.gamepad=t))}),this._onGamepadDisconnectedObserver=n.onGamepadDisconnectedObservable.add(function(e){r.gamepad===e&&(r.gamepad=null)}),this.gamepad=n.getGamepadByType(e.Gamepad.XBOX)},t.prototype.detachControl=function(e){this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver),this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver),this.gamepad=null},t.prototype.checkInputs=function(){if(this.gamepad&&this.gamepad.leftStick){var t=this.camera,i=this.gamepad.leftStick,r=i.x/this.gamepadMoveSensibility,n=i.y/this.gamepadMoveSensibility;i.x=Math.abs(r)>.005?0+r:0,i.y=Math.abs(n)>.005?0+n:0;var o=this.gamepad.rightStick;if(o){var 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}else o={x:0,y:0};t.rotationQuaternion?t.rotationQuaternion.toRotationMatrix(this._cameraTransform):e.Matrix.RotationYawPitchRollToRef(t.rotation.y,t.rotation.x,0,this._cameraTransform);var l=50*t._computeLocalCameraSpeed();this._vector3.copyFromFloats(i.x*l,0,-i.y*l),e.Vector3.TransformCoordinatesToRef(this._vector3,this._cameraTransform,this._deltaTransform),t.cameraDirection.addInPlace(this._deltaTransform),this._vector2.copyFromFloats(o.y,o.x),t.cameraRotation.addInPlace(this._vector2)}},t.prototype.getClassName=function(){return"FreeCameraGamepadInput"},t.prototype.getSimpleName=function(){return"gamepad"},r([e.serialize()],t.prototype,"gamepadAngularSensibility",void 0),r([e.serialize()],t.prototype,"gamepadMoveSensibility",void 0),t}();e.FreeCameraGamepadInput=t,e.CameraInputTypes.FreeCameraGamepadInput=t}(s||(s={}));!function(e){var t=function(){function t(){this.gamepadRotationSensibility=80,this.gamepadMoveSensibility=40}return t.prototype.attachControl=function(t,i){var r=this,n=this.camera.getScene().gamepadManager;this._onGamepadConnectedObserver=n.onGamepadConnectedObservable.add(function(t){t.type!==e.Gamepad.POSE_ENABLED&&(r.gamepad&&t.type!==e.Gamepad.XBOX||(r.gamepad=t))}),this._onGamepadDisconnectedObserver=n.onGamepadDisconnectedObservable.add(function(e){r.gamepad===e&&(r.gamepad=null)}),this.gamepad=n.getGamepadByType(e.Gamepad.XBOX)},t.prototype.detachControl=function(e){this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver),this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver),this.gamepad=null},t.prototype.checkInputs=function(){if(this.gamepad){var e=this.camera,t=this.gamepad.rightStick;if(t){if(0!=t.x){var i=t.x/this.gamepadRotationSensibility;0!=i&&Math.abs(i)>.005&&(e.inertialAlphaOffset+=i)}if(0!=t.y){var r=t.y/this.gamepadRotationSensibility;0!=r&&Math.abs(r)>.005&&(e.inertialBetaOffset+=r)}}var n=this.gamepad.leftStick;if(n&&0!=n.y){var o=n.y/this.gamepadMoveSensibility;0!=o&&Math.abs(o)>.005&&(this.camera.inertialRadiusOffset-=o)}}},t.prototype.getClassName=function(){return"ArcRotateCameraGamepadInput"},t.prototype.getSimpleName=function(){return"gamepad"},r([e.serialize()],t.prototype,"gamepadRotationSensibility",void 0),r([e.serialize()],t.prototype,"gamepadMoveSensibility",void 0),t}();e.ArcRotateCameraGamepadInput=t,e.CameraInputTypes.ArcRotateCameraGamepadInput=t}(s||(s={}));!function(e){var t=function(){function t(){var t=this;this._babylonGamepads=[],this._oneGamepadConnected=!1,this._isMonitoring=!1,this.onGamepadDisconnectedObservable=new e.Observable,e.Tools.IsWindowObjectExist()?(this._gamepadEventSupported="GamepadEvent"in window,this._gamepadSupport=navigator.getGamepads||navigator.webkitGetGamepads||navigator.msGetGamepads||navigator.webkitGamepads):this._gamepadEventSupported=!1,this.onGamepadConnectedObservable=new e.Observable(function(e){for(var i in t._babylonGamepads){var r=t._babylonGamepads[i];r&&r._isConnected&&t.onGamepadConnectedObservable.notifyObserver(e,r)}}),this._onGamepadConnectedEvent=function(e){var i=e.gamepad;if(!(i.index in t._babylonGamepads&&t._babylonGamepads[i.index].isConnected)){var r;t._babylonGamepads[i.index]?((r=t._babylonGamepads[i.index]).browserGamepad=i,r._isConnected=!0):r=t._addNewGamepad(i),t.onGamepadConnectedObservable.notifyObservers(r),t._startMonitoringGamepads()}},this._onGamepadDisconnectedEvent=function(e){var i=e.gamepad;for(var r in t._babylonGamepads)if(t._babylonGamepads[r].index===i.index){var n=t._babylonGamepads[r];n._isConnected=!1,t.onGamepadDisconnectedObservable.notifyObservers(n);break}},this._gamepadSupport&&(this._updateGamepadObjects(),this._babylonGamepads.length&&this._startMonitoringGamepads(),this._gamepadEventSupported?(window.addEventListener("gamepadconnected",this._onGamepadConnectedEvent,!1),window.addEventListener("gamepaddisconnected",this._onGamepadDisconnectedEvent,!1)):this._startMonitoringGamepads())}return Object.defineProperty(t.prototype,"gamepads",{get:function(){return this._babylonGamepads},enumerable:!0,configurable:!0}),t.prototype.getGamepadByType=function(t){void 0===t&&(t=e.Gamepad.XBOX);for(var i=0,r=this._babylonGamepads;i<r.length;i++){var n=r[i];if(n&&n.type===t)return n}return null},t.prototype.dispose=function(){this._gamepadEventSupported&&(this._onGamepadConnectedEvent&&window.removeEventListener("gamepadconnected",this._onGamepadConnectedEvent),this._onGamepadDisconnectedEvent&&window.removeEventListener("gamepaddisconnected",this._onGamepadDisconnectedEvent),this._onGamepadConnectedEvent=null,this._onGamepadDisconnectedEvent=null),this._babylonGamepads.forEach(function(e){e.dispose()}),this.onGamepadConnectedObservable.clear(),this.onGamepadDisconnectedObservable.clear(),this._oneGamepadConnected=!1,this._stopMonitoringGamepads(),this._babylonGamepads=[]},t.prototype._addNewGamepad=function(t){this._oneGamepadConnected||(this._oneGamepadConnected=!0);var i,r=-1!==t.id.search("Xbox One");return i=r||-1!==t.id.search("Xbox 360")||-1!==t.id.search("xinput")?new e.Xbox360Pad(t.id,t.index,t,r):t.pose?e.PoseEnabledControllerHelper.InitiateController(t):new e.GenericPad(t.id,t.index,t),this._babylonGamepads[i.index]=i,i},t.prototype._startMonitoringGamepads=function(){this._isMonitoring||(this._isMonitoring=!0,this._checkGamepadsStatus())},t.prototype._stopMonitoringGamepads=function(){this._isMonitoring=!1},t.prototype._checkGamepadsStatus=function(){var t=this;this._updateGamepadObjects();for(var i in this._babylonGamepads){var r=this._babylonGamepads[i];r&&r.isConnected&&r.update()}this._isMonitoring&&e.Tools.QueueNewFrame(function(){t._checkGamepadsStatus()})},t.prototype._updateGamepadObjects=function(){for(var e=navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads():[],t=0;t<e.length;t++)if(e[t])if(this._babylonGamepads[e[t].index])this._babylonGamepads[t].browserGamepad=e[t],this._babylonGamepads[t].isConnected||(this._babylonGamepads[t]._isConnected=!0,this.onGamepadConnectedObservable.notifyObservers(this._babylonGamepads[t]));else{var i=this._addNewGamepad(e[t]);this.onGamepadConnectedObservable.notifyObservers(i)}},t}();e.GamepadManager=t}(s||(s={}));!function(e){var t=function(){return function(e,t){this.x=e,this.y=t}}();e.StickValues=t;var i=function(){function e(t,i,r,n,o,s,a){void 0===n&&(n=0),void 0===o&&(o=1),void 0===s&&(s=2),void 0===a&&(a=3),this.id=t,this.index=i,this.browserGamepad=r,this._isConnected=!0,this.type=e.GAMEPAD,this._leftStickAxisX=n,this._leftStickAxisY=o,this._rightStickAxisX=s,this._rightStickAxisY=a,this.browserGamepad.axes.length>=2&&(this._leftStick={x:this.browserGamepad.axes[this._leftStickAxisX],y:this.browserGamepad.axes[this._leftStickAxisY]}),this.browserGamepad.axes.length>=4&&(this._rightStick={x:this.browserGamepad.axes[this._rightStickAxisX],y:this.browserGamepad.axes[this._rightStickAxisY]})}return Object.defineProperty(e.prototype,"isConnected",{get:function(){return this._isConnected},enumerable:!0,configurable:!0}),e.prototype.onleftstickchanged=function(e){this._onleftstickchanged=e},e.prototype.onrightstickchanged=function(e){this._onrightstickchanged=e},Object.defineProperty(e.prototype,"leftStick",{get:function(){return this._leftStick},set:function(e){!this._onleftstickchanged||this._leftStick.x===e.x&&this._leftStick.y===e.y||this._onleftstickchanged(e),this._leftStick=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rightStick",{get:function(){return this._rightStick},set:function(e){!this._onrightstickchanged||this._rightStick.x===e.x&&this._rightStick.y===e.y||this._onrightstickchanged(e),this._rightStick=e},enumerable:!0,configurable:!0}),e.prototype.update=function(){this._leftStick&&(this.leftStick={x:this.browserGamepad.axes[this._leftStickAxisX],y:this.browserGamepad.axes[this._leftStickAxisY]}),this._rightStick&&(this.rightStick={x:this.browserGamepad.axes[this._rightStickAxisX],y:this.browserGamepad.axes[this._rightStickAxisY]})},e.prototype.dispose=function(){},e.GAMEPAD=0,e.GENERIC=1,e.XBOX=2,e.POSE_ENABLED=3,e}();e.Gamepad=i;var r=function(t){function r(r,n,o){var s=t.call(this,r,n,o)||this;return s.onButtonDownObservable=new e.Observable,s.onButtonUpObservable=new e.Observable,s.type=i.GENERIC,s._buttons=new Array(o.buttons.length),s}return n(r,t),r.prototype.onbuttondown=function(e){this._onbuttondown=e},r.prototype.onbuttonup=function(e){this._onbuttonup=e},r.prototype._setButtonValue=function(e,t,i){return e!==t&&(1===e&&(this._onbuttondown&&this._onbuttondown(i),this.onButtonDownObservable.notifyObservers(i)),0===e&&(this._onbuttonup&&this._onbuttonup(i),this.onButtonUpObservable.notifyObservers(i))),e},r.prototype.update=function(){t.prototype.update.call(this);for(var e=0;e<this._buttons.length;e++)this._buttons[e]=this._setButtonValue(this.browserGamepad.buttons[e].value,this._buttons[e],e)},r}(i);e.GenericPad=r}(s||(s={}));!function(e){var t;!function(e){e[e.A=0]="A",e[e.B=1]="B",e[e.X=2]="X",e[e.Y=3]="Y",e[e.Start=4]="Start",e[e.Back=5]="Back",e[e.LB=6]="LB",e[e.RB=7]="RB",e[e.LeftStick=8]="LeftStick",e[e.RightStick=9]="RightStick"}(t=e.Xbox360Button||(e.Xbox360Button={}));var i;!function(e){e[e.Up=0]="Up",e[e.Down=1]="Down",e[e.Left=2]="Left",e[e.Right=3]="Right"}(i=e.Xbox360Dpad||(e.Xbox360Dpad={}));var r=function(r){function o(t,i,n,o){void 0===o&&(o=!1);var s=r.call(this,t,i,n,0,1,2,3)||this;return s._leftTrigger=0,s._rightTrigger=0,s.onButtonDownObservable=new e.Observable,s.onButtonUpObservable=new e.Observable,s.onPadDownObservable=new e.Observable,s.onPadUpObservable=new e.Observable,s._buttonA=0,s._buttonB=0,s._buttonX=0,s._buttonY=0,s._buttonBack=0,s._buttonStart=0,s._buttonLB=0,s._buttonRB=0,s._buttonLeftStick=0,s._buttonRightStick=0,s._dPadUp=0,s._dPadDown=0,s._dPadLeft=0,s._dPadRight=0,s._isXboxOnePad=!1,s.type=e.Gamepad.XBOX,s._isXboxOnePad=o,s}return n(o,r),o.prototype.onlefttriggerchanged=function(e){this._onlefttriggerchanged=e},o.prototype.onrighttriggerchanged=function(e){this._onrighttriggerchanged=e},Object.defineProperty(o.prototype,"leftTrigger",{get:function(){return this._leftTrigger},set:function(e){this._onlefttriggerchanged&&this._leftTrigger!==e&&this._onlefttriggerchanged(e),this._leftTrigger=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"rightTrigger",{get:function(){return this._rightTrigger},set:function(e){this._onrighttriggerchanged&&this._rightTrigger!==e&&this._onrighttriggerchanged(e),this._rightTrigger=e},enumerable:!0,configurable:!0}),o.prototype.onbuttondown=function(e){this._onbuttondown=e},o.prototype.onbuttonup=function(e){this._onbuttonup=e},o.prototype.ondpaddown=function(e){this._ondpaddown=e},o.prototype.ondpadup=function(e){this._ondpadup=e},o.prototype._setButtonValue=function(e,t,i){return e!==t&&(1===e&&(this._onbuttondown&&this._onbuttondown(i),this.onButtonDownObservable.notifyObservers(i)),0===e&&(this._onbuttonup&&this._onbuttonup(i),this.onButtonUpObservable.notifyObservers(i))),e},o.prototype._setDPadValue=function(e,t,i){return e!==t&&(1===e&&(this._ondpaddown&&this._ondpaddown(i),this.onPadDownObservable.notifyObservers(i)),0===e&&(this._ondpadup&&this._ondpadup(i),this.onPadUpObservable.notifyObservers(i))),e},Object.defineProperty(o.prototype,"buttonA",{get:function(){return this._buttonA},set:function(e){this._buttonA=this._setButtonValue(e,this._buttonA,t.A)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"buttonB",{get:function(){return this._buttonB},set:function(e){this._buttonB=this._setButtonValue(e,this._buttonB,t.B)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"buttonX",{get:function(){return this._buttonX},set:function(e){this._buttonX=this._setButtonValue(e,this._buttonX,t.X)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"buttonY",{get:function(){return this._buttonY},set:function(e){this._buttonY=this._setButtonValue(e,this._buttonY,t.Y)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"buttonStart",{get:function(){return this._buttonStart},set:function(e){this._buttonStart=this._setButtonValue(e,this._buttonStart,t.Start)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"buttonBack",{get:function(){return this._buttonBack},set:function(e){this._buttonBack=this._setButtonValue(e,this._buttonBack,t.Back)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"buttonLB",{get:function(){return this._buttonLB},set:function(e){this._buttonLB=this._setButtonValue(e,this._buttonLB,t.LB)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"buttonRB",{get:function(){return this._buttonRB},set:function(e){this._buttonRB=this._setButtonValue(e,this._buttonRB,t.RB)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"buttonLeftStick",{get:function(){return this._buttonLeftStick},set:function(e){this._buttonLeftStick=this._setButtonValue(e,this._buttonLeftStick,t.LeftStick)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"buttonRightStick",{get:function(){return this._buttonRightStick},set:function(e){this._buttonRightStick=this._setButtonValue(e,this._buttonRightStick,t.RightStick)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"dPadUp",{get:function(){return this._dPadUp},set:function(e){this._dPadUp=this._setDPadValue(e,this._dPadUp,i.Up)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"dPadDown",{get:function(){return this._dPadDown},set:function(e){this._dPadDown=this._setDPadValue(e,this._dPadDown,i.Down)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"dPadLeft",{get:function(){return this._dPadLeft},set:function(e){this._dPadLeft=this._setDPadValue(e,this._dPadLeft,i.Left)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"dPadRight",{get:function(){return this._dPadRight},set:function(e){this._dPadRight=this._setDPadValue(e,this._dPadRight,i.Right)},enumerable:!0,configurable:!0}),o.prototype.update=function(){r.prototype.update.call(this),this._isXboxOnePad?(this.buttonA=this.browserGamepad.buttons[0].value,this.buttonB=this.browserGamepad.buttons[1].value,this.buttonX=this.browserGamepad.buttons[2].value,this.buttonY=this.browserGamepad.buttons[3].value,this.buttonLB=this.browserGamepad.buttons[4].value,this.buttonRB=this.browserGamepad.buttons[5].value,this.leftTrigger=this.browserGamepad.axes[2],this.rightTrigger=this.browserGamepad.axes[5],this.buttonBack=this.browserGamepad.buttons[9].value,this.buttonStart=this.browserGamepad.buttons[8].value,this.buttonLeftStick=this.browserGamepad.buttons[6].value,this.buttonRightStick=this.browserGamepad.buttons[7].value,this.dPadUp=this.browserGamepad.buttons[11].value,this.dPadDown=this.browserGamepad.buttons[12].value,this.dPadLeft=this.browserGamepad.buttons[13].value,this.dPadRight=this.browserGamepad.buttons[14].value):(this.buttonA=this.browserGamepad.buttons[0].value,this.buttonB=this.browserGamepad.buttons[1].value,this.buttonX=this.browserGamepad.buttons[2].value,this.buttonY=this.browserGamepad.buttons[3].value,this.buttonLB=this.browserGamepad.buttons[4].value,this.buttonRB=this.browserGamepad.buttons[5].value,this.leftTrigger=this.browserGamepad.buttons[6].value,this.rightTrigger=this.browserGamepad.buttons[7].value,this.buttonBack=this.browserGamepad.buttons[8].value,this.buttonStart=this.browserGamepad.buttons[9].value,this.buttonLeftStick=this.browserGamepad.buttons[10].value,this.buttonRightStick=this.browserGamepad.buttons[11].value,this.dPadUp=this.browserGamepad.buttons[12].value,this.dPadDown=this.browserGamepad.buttons[13].value,this.dPadLeft=this.browserGamepad.buttons[14].value,this.dPadRight=this.browserGamepad.buttons[15].value)},o}(e.Gamepad);e.Xbox360Pad=r}(s||(s={}));!function(e){var t;!function(e){e[e.VIVE=0]="VIVE",e[e.OCULUS=1]="OCULUS",e[e.WINDOWS=2]="WINDOWS",e[e.GENERIC=3]="GENERIC"}(t=e.PoseEnabledControllerType||(e.PoseEnabledControllerType={}));var i=function(){function t(){}return t.InitiateController=function(t){return-1!==t.id.indexOf("Oculus Touch")?new e.OculusTouchController(t):0===t.id.indexOf(e.WindowsMotionController.GAMEPAD_ID_PREFIX)?new e.WindowsMotionController(t):-1!==t.id.toLowerCase().indexOf("openvr")?new e.ViveController(t):new e.GenericController(t)},t}();e.PoseEnabledControllerHelper=i;var r=function(i){function r(r){var n=i.call(this,r.id,r.index,r)||this;return n.deviceScaleFactor=1,n._leftHandSystemQuaternion=new e.Quaternion,n.type=e.Gamepad.POSE_ENABLED,n.controllerType=t.GENERIC,n.position=e.Vector3.Zero(),n.rotationQuaternion=new e.Quaternion,n.devicePosition=e.Vector3.Zero(),n.deviceRotationQuaternion=new e.Quaternion,n._calculatedPosition=e.Vector3.Zero(),n._calculatedRotation=new e.Quaternion,e.Quaternion.RotationYawPitchRollToRef(Math.PI,0,0,n._leftHandSystemQuaternion),n}return n(r,i),r.prototype.update=function(){i.prototype.update.call(this);var e=this.browserGamepad.pose;this.updateFromDevice(e),this._mesh&&(this._mesh.position.copyFrom(this._calculatedPosition),this._mesh.rotationQuaternion&&this._mesh.rotationQuaternion.copyFrom(this._calculatedRotation))},r.prototype.updateFromDevice=function(e){if(e){this.rawPose=e,e.position&&(this.devicePosition.copyFromFloats(e.position[0],e.position[1],-e.position[2]),this._mesh&&this._mesh.getScene().useRightHandedSystem&&(this.devicePosition.z*=-1),this.devicePosition.scaleToRef(this.deviceScaleFactor,this._calculatedPosition),this._calculatedPosition.addInPlace(this.position));var t=this.rawPose;e.orientation&&t.orientation&&(this.deviceRotationQuaternion.copyFromFloats(t.orientation[0],t.orientation[1],-t.orientation[2],-t.orientation[3]),this._mesh&&(this._mesh.getScene().useRightHandedSystem?(this.deviceRotationQuaternion.z*=-1,this.deviceRotationQuaternion.w*=-1):this.deviceRotationQuaternion.multiplyToRef(this._leftHandSystemQuaternion,this.deviceRotationQuaternion)),this.deviceRotationQuaternion.multiplyToRef(this.rotationQuaternion,this._calculatedRotation))}},r.prototype.attachToMesh=function(t){this._mesh&&(this._mesh.parent=null),this._mesh=t,this._poseControlledCamera&&(this._mesh.parent=this._poseControlledCamera),this._mesh.rotationQuaternion||(this._mesh.rotationQuaternion=new e.Quaternion)},r.prototype.attachToPoseControlledCamera=function(e){this._poseControlledCamera=e,this._mesh&&(this._mesh.parent=this._poseControlledCamera)},r.prototype.dispose=function(){this._mesh&&this._mesh.dispose(),this._mesh=null,i.prototype.dispose.call(this)},Object.defineProperty(r.prototype,"mesh",{get:function(){return this._mesh},enumerable:!0,configurable:!0}),r.prototype.getForwardRay=function(t){if(void 0===t&&(t=100),!this.mesh)return new e.Ray(e.Vector3.Zero(),new e.Vector3(0,0,1),t);var i=this.mesh.getWorldMatrix(),r=i.getTranslation(),n=new e.Vector3(0,0,-1),o=e.Vector3.TransformNormal(n,i),s=e.Vector3.Normalize(o);return new e.Ray(r,s,t)},r}(e.Gamepad);e.PoseEnabledController=r}(s||(s={}));!function(e){var t=function(t){function i(i){var r=t.call(this,i)||this;return r.onTriggerStateChangedObservable=new e.Observable,r.onMainButtonStateChangedObservable=new e.Observable,r.onSecondaryButtonStateChangedObservable=new e.Observable,r.onPadStateChangedObservable=new e.Observable,r.onPadValuesChangedObservable=new e.Observable,r.pad={x:0,y:0},r._changes={pressChanged:!1,touchChanged:!1,valueChanged:!1,changed:!1},r._buttons=new Array(i.buttons.length),r.hand=i.hand,r}return n(i,t),i.prototype.onButtonStateChange=function(e){this._onButtonStateChange=e},Object.defineProperty(i.prototype,"defaultModel",{get:function(){return this._defaultModel},enumerable:!0,configurable:!0}),i.prototype.update=function(){t.prototype.update.call(this);for(var e=0;e<this._buttons.length;e++)this._setButtonValue(this.browserGamepad.buttons[e],this._buttons[e],e);this.leftStick.x===this.pad.x&&this.leftStick.y===this.pad.y||(this.pad.x=this.leftStick.x,this.pad.y=this.leftStick.y,this.onPadValuesChangedObservable.notifyObservers(this.pad))},i.prototype._setButtonValue=function(e,t,i){e||(e={pressed:!1,touched:!1,value:0}),t?(this._checkChanges(e,t),this._changes.changed&&(this._onButtonStateChange&&this._onButtonStateChange(this.index,i,e),this.handleButtonChange(i,e,this._changes)),this._buttons[i].pressed=e.pressed,this._buttons[i].touched=e.touched,this._buttons[i].value=e.value<1e-8?0:e.value):this._buttons[i]={pressed:e.pressed,touched:e.touched,value:e.value}},i.prototype._checkChanges=function(e,t){return this._changes.pressChanged=e.pressed!==t.pressed,this._changes.touchChanged=e.touched!==t.touched,this._changes.valueChanged=e.value!==t.value,this._changes.changed=this._changes.pressChanged||this._changes.touchChanged||this._changes.valueChanged,this._changes},i.prototype.dispose=function(){t.prototype.dispose.call(this),this.onTriggerStateChangedObservable.clear(),this.onMainButtonStateChangedObservable.clear(),this.onSecondaryButtonStateChangedObservable.clear(),this.onPadStateChangedObservable.clear(),this.onPadValuesChangedObservable.clear()},i}(e.PoseEnabledController);e.WebVRController=t}(s||(s={}));!function(e){var t=function(t){function i(i){var r=t.call(this,i)||this;return r.onSecondaryTriggerStateChangedObservable=new e.Observable,r.onThumbRestChangedObservable=new e.Observable,r.controllerType=e.PoseEnabledControllerType.OCULUS,r}return n(i,t),i.prototype.initControllerMesh=function(t,r){var n,o=this;n="left"===this.hand?i.MODEL_LEFT_FILENAME:i.MODEL_RIGHT_FILENAME,e.SceneLoader.ImportMesh("",i.MODEL_BASE_URL,n,t,function(e){o._defaultModel=e[1],o.attachToMesh(o._defaultModel),r&&r(o._defaultModel)})},Object.defineProperty(i.prototype,"onAButtonStateChangedObservable",{get:function(){if("right"===this.hand)return this.onMainButtonStateChangedObservable;throw new Error("No A button on left hand")},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onBButtonStateChangedObservable",{get:function(){if("right"===this.hand)return this.onSecondaryButtonStateChangedObservable;throw new Error("No B button on left hand")},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onXButtonStateChangedObservable",{get:function(){if("left"===this.hand)return this.onMainButtonStateChangedObservable;throw new Error("No X button on right hand")},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onYButtonStateChangedObservable",{get:function(){if("left"===this.hand)return this.onSecondaryButtonStateChangedObservable;throw new Error("No Y button on right hand")},enumerable:!0,configurable:!0}),i.prototype.handleButtonChange=function(e,t,i){var r=t,n="right"===this.hand?-1:1;switch(e){case 0:return void this.onPadStateChangedObservable.notifyObservers(r);case 1:return this._defaultModel&&(this._defaultModel.getChildren()[3].rotation.x=.2*-r.value,this._defaultModel.getChildren()[3].position.y=.005*-r.value,this._defaultModel.getChildren()[3].position.z=.005*-r.value),void this.onTriggerStateChangedObservable.notifyObservers(r);case 2:return this._defaultModel&&(this._defaultModel.getChildren()[4].position.x=n*r.value*.0035),void this.onSecondaryTriggerStateChangedObservable.notifyObservers(r);case 3:return this._defaultModel&&(r.pressed?this._defaultModel.getChildren()[1].position.y=-.001:this._defaultModel.getChildren()[1].position.y=0),void this.onMainButtonStateChangedObservable.notifyObservers(r);case 4:return this._defaultModel&&(r.pressed?this._defaultModel.getChildren()[2].position.y=-.001:this._defaultModel.getChildren()[2].position.y=0),void this.onSecondaryButtonStateChangedObservable.notifyObservers(r);case 5:return void this.onThumbRestChangedObservable.notifyObservers(r)}},i.MODEL_BASE_URL="https://controllers.babylonjs.com/oculus/",i.MODEL_LEFT_FILENAME="left.babylon",i.MODEL_RIGHT_FILENAME="right.babylon",i}(e.WebVRController);e.OculusTouchController=t}(s||(s={}));!function(e){var t=function(t){function i(i){var r=t.call(this,i)||this;return r.controllerType=e.PoseEnabledControllerType.VIVE,r}return n(i,t),i.prototype.initControllerMesh=function(t,r){var n=this;e.SceneLoader.ImportMesh("",i.MODEL_BASE_URL,i.MODEL_FILENAME,t,function(e){n._defaultModel=e[1],n.attachToMesh(n._defaultModel),r&&r(n._defaultModel)})},Object.defineProperty(i.prototype,"onLeftButtonStateChangedObservable",{get:function(){return this.onMainButtonStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onRightButtonStateChangedObservable",{get:function(){return this.onMainButtonStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onMenuButtonStateChangedObservable",{get:function(){return this.onSecondaryButtonStateChangedObservable},enumerable:!0,configurable:!0}),i.prototype.handleButtonChange=function(e,t,i){var r=t;switch(e){case 0:return void this.onPadStateChangedObservable.notifyObservers(r);case 1:return this._defaultModel&&(this._defaultModel.getChildren()[6].rotation.x=.15*-r.value),void this.onTriggerStateChangedObservable.notifyObservers(r);case 2:return void this.onMainButtonStateChangedObservable.notifyObservers(r);case 3:return this._defaultModel&&(r.pressed?this._defaultModel.getChildren()[2].position.y=-.001:this._defaultModel.getChildren()[2].position.y=0),void this.onSecondaryButtonStateChangedObservable.notifyObservers(r)}},i.MODEL_BASE_URL="https://controllers.babylonjs.com/vive/",i.MODEL_FILENAME="wand.babylon",i}(e.WebVRController);e.ViveController=t}(s||(s={}));!function(e){var t=function(t){function i(e){return t.call(this,e)||this}return n(i,t),i.prototype.initControllerMesh=function(t,r){var n=this;e.SceneLoader.ImportMesh("",i.MODEL_BASE_URL,i.MODEL_FILENAME,t,function(e){n._defaultModel=e[1],n.attachToMesh(n._defaultModel),r&&r(n._defaultModel)})},i.prototype.handleButtonChange=function(e,t,i){console.log("Button id: "+e+"state: "),console.dir(t)},i.MODEL_BASE_URL="https://controllers.babylonjs.com/generic/",i.MODEL_FILENAME="generic.babylon",i}(e.WebVRController);e.GenericController=t}(s||(s={}));!function(e){var t=function(){return function(){this.buttonMeshes={},this.axisMeshes={}}}(),i=function(i){function r(t){var r=i.call(this,t)||this;return r._mapping={buttons:["thumbstick","trigger","grip","menu","trackpad"],buttonMeshNames:{trigger:"SELECT",menu:"MENU",grip:"GRASP",thumbstick:"THUMBSTICK_PRESS",trackpad:"TOUCHPAD_PRESS"},buttonObservableNames:{trigger:"onTriggerStateChangedObservable",menu:"onSecondaryButtonStateChangedObservable",grip:"onMainButtonStateChangedObservable",thumbstick:"onPadStateChangedObservable",trackpad:"onTrackpadChangedObservable"},axisMeshNames:["THUMBSTICK_X","THUMBSTICK_Y","TOUCHPAD_TOUCH_X","TOUCHPAD_TOUCH_Y"],pointingPoseMeshName:"POINTING_POSE"},r.onTrackpadChangedObservable=new e.Observable,r.controllerType=e.PoseEnabledControllerType.WINDOWS,r._loadedMeshInfo=null,r}return n(r,i),Object.defineProperty(r.prototype,"onTriggerButtonStateChangedObservable",{get:function(){return this.onTriggerStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onMenuButtonStateChangedObservable",{get:function(){return this.onSecondaryButtonStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onGripButtonStateChangedObservable",{get:function(){return this.onMainButtonStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onThumbstickButtonStateChangedObservable",{get:function(){return this.onPadStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onTouchpadButtonStateChangedObservable",{get:function(){return this.onTrackpadChangedObservable},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(i.prototype.update.call(this),this._loadedMeshInfo&&this.browserGamepad.axes)for(var e=0;e<this._mapping.axisMeshNames.length;e++)this.lerpAxisTransform(e,this.browserGamepad.axes[e])},r.prototype.handleButtonChange=function(e,t,i){var r=this._mapping.buttons[e];if(r){var n=this[this._mapping.buttonObservableNames[r]];n&&n.notifyObservers(t),this.lerpButtonTransform(r,t.value)}},r.prototype.lerpButtonTransform=function(t,i){if(this._loadedMeshInfo){var r=this._loadedMeshInfo.buttonMeshes[t];r.unpressed.rotationQuaternion&&r.pressed.rotationQuaternion&&r.value.rotationQuaternion&&(e.Quaternion.SlerpToRef(r.unpressed.rotationQuaternion,r.pressed.rotationQuaternion,i,r.value.rotationQuaternion),e.Vector3.LerpToRef(r.unpressed.position,r.pressed.position,i,r.value.position))}},r.prototype.lerpAxisTransform=function(t,i){if(this._loadedMeshInfo){var r=this._loadedMeshInfo.axisMeshes[t];if(r&&r.min.rotationQuaternion&&r.max.rotationQuaternion&&r.value.rotationQuaternion){var n=.5*i+.5;e.Quaternion.SlerpToRef(r.min.rotationQuaternion,r.max.rotationQuaternion,n,r.value.rotationQuaternion),e.Vector3.LerpToRef(r.min.position,r.max.position,n,r.value.position)}}},r.prototype.initControllerMesh=function(t,i,n){var o=this;void 0===n&&(n=!1);var s,a;if(e.SceneLoader.GetPluginForExtension("glb")){var l="default";if(this.id&&!n){var h=this.id.match(r.GAMEPAD_ID_PATTERN);l=h&&h[0]||l}a="left"===this.hand?r.MODEL_LEFT_FILENAME:r.MODEL_RIGHT_FILENAME,s=r.MODEL_BASE_URL+l+"/"}else e.Tools.Warn("You need to reference GLTF loader to load Windows Motion Controllers model. Falling back to generic models"),s=e.GenericController.MODEL_BASE_URL,a=e.GenericController.MODEL_FILENAME;e.SceneLoader.ImportMesh("",s,a,t,function(e){o._loadedMeshInfo=o.processModel(t,e),o._loadedMeshInfo&&(o._defaultModel=o._loadedMeshInfo.rootNode,o.attachToMesh(o._defaultModel),i&&i(o._defaultModel))},null,function(t,r){e.Tools.Log(r),e.Tools.Warn("Failed to retrieve controller model from the remote server: "+s+a),n||o.initControllerMesh(t,i,!0)})},r.prototype.processModel=function(t,i){for(var r=null,n=new e.Mesh(this.id+" "+this.hand,t),o=null,s=0;s<i.length;s++){var a=i[s];if(!a.parent){a.isPickable=!1,o=a;break}}return o?(o.setParent(n),r=this.createMeshInfo(n)):e.Tools.Warn("Could not find root node in model file."),r},r.prototype.createMeshInfo=function(i){function r(e,t){return e.getChildMeshes(!1,function(e){return e.name===t})[0]}function n(e,t){return e.getChildMeshes(!0,function(e){return e.name==t})[0]}var o,s=new t;for(s.rootNode=i,s.buttonMeshes={},s.axisMeshes={},o=0;o<this._mapping.buttons.length;o++){var a=this._mapping.buttonMeshNames[this._mapping.buttons[o]];if(a){var l=r(i,a);if(l){var h={index:o,value:n(l,"VALUE"),pressed:n(l,"PRESSED"),unpressed:n(l,"UNPRESSED")};h.value&&h.pressed&&h.unpressed?s.buttonMeshes[this._mapping.buttons[o]]=h:e.Tools.Warn("Missing button submesh under mesh with name: "+a+"(VALUE: "+!!h.value+", PRESSED: "+!!h.pressed+", UNPRESSED:"+!!h.unpressed+")")}else e.Tools.Warn("Missing button mesh with name: "+a)}else e.Tools.Log("Skipping unknown button at index: "+o+" with mapped name: "+this._mapping.buttons[o])}for(o=0;o<this._mapping.axisMeshNames.length;o++){var u=this._mapping.axisMeshNames[o];if(u){var c=r(i,u);if(c){var f={index:o,value:n(c,"VALUE"),min:n(c,"MIN"),max:n(c,"MAX")};f.value&&f.min&&f.max?s.axisMeshes[o]=f:e.Tools.Warn("Missing axis submesh under mesh with name: "+u+"(VALUE: "+!!f.value+", MIN: "+!!f.min+", MAX:"+!!f.max+")")}else e.Tools.Warn("Missing axis mesh with name: "+u)}else e.Tools.Log("Skipping unknown axis at index: "+o)}return s.pointingPoseNode=r(i,this._mapping.pointingPoseMeshName),s.pointingPoseNode||e.Tools.Warn("Missing pointing pose mesh with name: "+this._mapping.pointingPoseMeshName),s},r.prototype.getForwardRay=function(t){if(void 0===t&&(t=100),!this._loadedMeshInfo||!this._loadedMeshInfo.pointingPoseNode)return i.prototype.getForwardRay.call(this,t);var r=this._loadedMeshInfo.pointingPoseNode.getWorldMatrix(),n=r.getTranslation(),o=new e.Vector3(0,0,-1),s=e.Vector3.TransformNormal(o,r),a=e.Vector3.Normalize(s);return new e.Ray(n,a,t)},r.prototype.dispose=function(){i.prototype.dispose.call(this),this.onTrackpadChangedObservable.clear()},r.MODEL_BASE_URL="https://controllers.babylonjs.com/microsoft/",r.MODEL_LEFT_FILENAME="left.glb",r.MODEL_RIGHT_FILENAME="right.glb",r.GAMEPAD_ID_PREFIX="Spatial Controller (Spatial Interaction Source) ",r.GAMEPAD_ID_PATTERN=/([0-9a-zA-Z]+-[0-9a-zA-Z]+)$/,r}(e.WebVRController);e.WindowsMotionController=i}(s||(s={}));!function(e){var t=function(t){function i(e,i,r,n){void 0===n&&(n=null);var o=t.call(this,e,i,r)||this;return o.radius=12,o.rotationOffset=0,o.heightOffset=4,o.cameraAcceleration=.05,o.maxCameraSpeed=20,o.lockedTarget=n,o}return n(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 r=new e.Matrix;t.rotationQuaternion.toRotationMatrix(r),i=Math.atan2(r.m[8],r.m[10])}else i=t.rotation.y;var n=this.getRadians(this.rotationOffset)+i,o=t.getAbsolutePosition(),s=o.x+Math.sin(n)*this.radius,a=o.z+Math.cos(n)*this.radius,l=s-this.position.x,h=o.y+this.heightOffset-this.position.y,u=a-this.position.z,c=l*this.cameraAcceleration*2,f=h*this.cameraAcceleration,p=u*this.cameraAcceleration*2;(c>this.maxCameraSpeed||c<-this.maxCameraSpeed)&&(c=c<1?-this.maxCameraSpeed:this.maxCameraSpeed),(f>this.maxCameraSpeed||f<-this.maxCameraSpeed)&&(f=f<1?-this.maxCameraSpeed:this.maxCameraSpeed),(p>this.maxCameraSpeed||p<-this.maxCameraSpeed)&&(p=p<1?-this.maxCameraSpeed:this.maxCameraSpeed),this.position=new e.Vector3(this.position.x+c,this.position.y+f,this.position.z+p),this.setTarget(o)}},i.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.lockedTarget&&this.follow(this.lockedTarget)},i.prototype.getClassName=function(){return"FollowCamera"},r([e.serialize()],i.prototype,"radius",void 0),r([e.serialize()],i.prototype,"rotationOffset",void 0),r([e.serialize()],i.prototype,"heightOffset",void 0),r([e.serialize()],i.prototype,"cameraAcceleration",void 0),r([e.serialize()],i.prototype,"maxCameraSpeed",void 0),r([e.serializeAsMeshReference("lockedTargetId")],i.prototype,"lockedTarget",void 0),i}(e.TargetCamera);e.FollowCamera=t;var i=function(t){function i(i,r,n,o,s,a){var l=t.call(this,i,e.Vector3.Zero(),a)||this;return l.alpha=r,l.beta=n,l.radius=o,l.target=s,l._cartesianCoordinates=e.Vector3.Zero(),l.follow(),l}return n(i,t),i.prototype.follow=function(){if(this.target){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);var e=this.target.getAbsolutePosition();this.position=e.add(this._cartesianCoordinates),this.setTarget(e)}},i.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.follow()},i.prototype.getClassName=function(){return"ArcFollowCamera"},i}(e.TargetCamera);e.ArcFollowCamera=i}(s||(s={}));!function(e){var t=function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n.inputs.addGamepad(),n}return n(t,e),Object.defineProperty(t.prototype,"gamepadAngularSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadAngularSensibility:0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadAngularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"gamepadMoveSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadMoveSensibility:0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadMoveSensibility=e)},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"UniversalCamera"},t}(e.TouchCamera);e.UniversalCamera=t}(s||(s={}));!function(e){var t=function(e){function t(t,i,r){return e.call(this,t,i,r)||this}return n(t,e),Object.defineProperty(t.prototype,"gamepadAngularSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadAngularSensibility:0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadAngularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"gamepadMoveSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadMoveSensibility:0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadMoveSensibility=e)},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"GamepadCamera"},t}(e.UniversalCamera);e.GamepadCamera=t}(s||(s={}));!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){void 0===i&&(i=!1);var r=this._renderPipelines[e];r&&r._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 r=this._renderPipelines[e];r&&r._enableEffect(t,i)},e.prototype.disableEffectInPipeline=function(e,t,i){var r=this._renderPipelines[e];r&&r._disableEffect(t,i)},e.prototype.enableDisplayOnlyPassInPipeline=function(e,t,i){var r=this._renderPipelines[e];r&&r._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)if(this._renderPipelines.hasOwnProperty(e)){var t=this._renderPipelines[e];t.isSupported?t._update():(t.dispose(),delete this._renderPipelines[e])}},e.prototype._rebuild=function(){for(var e in this._renderPipelines)this._renderPipelines.hasOwnProperty(e)&&this._renderPipelines[e]._rebuild()},e.prototype.dispose=function(){for(var e in this._renderPipelines)this._renderPipelines.hasOwnProperty(e)&&this._renderPipelines[e].dispose()},e}();e.PostProcessRenderPipelineManager=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n,o,s){this._refCount=0,this._name=i,this._renderTexture=new e.RenderTargetTexture(i,r,t),this.setRenderList(n),this._renderTexture.onBeforeRenderObservable.add(o),this._renderTexture.onAfterRenderObservable.add(s),this._scene=t,this._renderList=n}return t.prototype._incRefCount=function(){return 0===this._refCount&&this._scene.customRenderTargets.push(this._renderTexture),++this._refCount},t.prototype._decRefCount=function(){return this._refCount--,this._refCount<=0&&this._scene.customRenderTargets.splice(this._scene.customRenderTargets.indexOf(this._renderTexture),1),this._refCount},t.prototype._update=function(){this.setRenderList(this._renderList)},t.prototype.setRenderList=function(e){this._renderTexture.renderList=e},t.prototype.getRenderTexture=function(){return this._renderTexture},t}();e.PostProcessRenderPass=t}(s||(s={}));!function(e){var t=function(){function t(e,t,i,r){this._engine=e,this._name=t,this._singleInstance=r||!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];return null},t.prototype.emptyPasses=function(){this._renderPasses={},this._linkParameters()},t.prototype._attachCameras=function(t){var i,r=e.Tools.MakeArray(t||this._cameras);if(r){for(var n=0;n<r.length;n++){var o=r[n],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),this._cameras[s]||(this._cameras[s]=o);for(var l in this._renderPasses)this._renderPasses[l]._incRefCount()}this._linkParameters()}},t.prototype._detachCameras=function(t){var i=e.Tools.MakeArray(t||this._cameras);if(i)for(var r=0;r<i.length;r++){var n=i[r],o=n.name;n.detachPostProcess(this._postProcesses[this._singleInstance?0:o]),this._cameras[o]&&(this._cameras[o]=null);for(var s in this._renderPasses)this._renderPasses[s]._decRefCount()}},t.prototype._enable=function(t){var i=e.Tools.MakeArray(t||this._cameras);if(i)for(var r=0;r<i.length;r++){for(var n=i[r],o=n.name,s=0;s<this._indicesForCamera[o].length;s++)void 0===n._postProcesses[this._indicesForCamera[o][s]]&&t[r].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){var i=e.Tools.MakeArray(t||this._cameras);if(i)for(var r=0;r<i.length;r++){var n=i[r],o=n.Name;n.detachPostProcess(this._postProcesses[this._singleInstance?0:o]);for(var s in this._renderPasses)this._renderPasses[s]._decRefCount()}},t.prototype.getPostProcess=function(e){return this._singleInstance?this._postProcesses[0]:e?this._postProcesses[e.name]:null},t.prototype._linkParameters=function(){var e=this;for(var t in this._postProcesses)this.applyParameters&&this.applyParameters(this._postProcesses[t]),this._postProcesses[t].onBeforeRenderObservable.add(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}(s||(s={}));!function(e){var t=function(){function t(e,t){this._engine=e,this._name=t,this._renderEffects={},this._renderEffectsForIsolatedPass=new Array,this._cameras=[]}return t.prototype.getClassName=function(){return"PostProcessRenderPipeline"},Object.defineProperty(t.prototype,"isSupported",{get:function(){for(var e in this._renderEffects)if(this._renderEffects.hasOwnProperty(e)&&!this._renderEffects[e].isSupported)return!1;return!0},enumerable:!0,configurable:!0}),t.prototype.addEffect=function(e){this._renderEffects[e._name]=e},t.prototype._rebuild=function(){},t.prototype._enableEffect=function(t,i){var r=this._renderEffects[t];r&&r._enable(e.Tools.MakeArray(i||this._cameras))},t.prototype._disableEffect=function(t,i){var r=this._renderEffects[t];r&&r._disable(e.Tools.MakeArray(i||this._cameras))},t.prototype._attachCameras=function(t,i){var r=e.Tools.MakeArray(t||this._cameras);if(r){var n,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 l in this._renderEffects)this._renderEffects.hasOwnProperty(l)&&this._renderEffects[l]._attachCameras(r)}},t.prototype._detachCameras=function(t){var i=e.Tools.MakeArray(t||this._cameras);if(i){for(var r in this._renderEffects)this._renderEffects.hasOwnProperty(r)&&this._renderEffects[r]._detachCameras(i);for(var n=0;n<i.length;n++)this._cameras.splice(this._cameras.indexOf(i[n]),1)}},t.prototype._enableDisplayOnlyPass=function(i,r){var n=this,o=e.Tools.MakeArray(r||this._cameras);if(o){var s,a=null;for(s in this._renderEffects)if(this._renderEffects.hasOwnProperty(s)&&null!=(a=this._renderEffects[s].getPass(i)))break;if(null!==a){for(s in this._renderEffects)this._renderEffects.hasOwnProperty(s)&&this._renderEffects[s]._disable(o);a._name=t.PASS_SAMPLER_NAME;for(var l=0;l<o.length;l++){var h=o[l],u=h.name;this._renderEffectsForIsolatedPass[u]=this._renderEffectsForIsolatedPass[u]||new e.PostProcessRenderEffect(this._engine,t.PASS_EFFECT_NAME,function(){return new e.DisplayPassPostProcess(t.PASS_EFFECT_NAME,1,null,void 0,n._engine,!0)}),this._renderEffectsForIsolatedPass[u].emptyPasses(),this._renderEffectsForIsolatedPass[u].addPass(a),this._renderEffectsForIsolatedPass[u]._attachCameras(h)}}}},t.prototype._disableDisplayOnlyPass=function(i){var r=this,n=e.Tools.MakeArray(i||this._cameras);if(n){for(var o=0;o<n.length;o++){var s=n[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,void 0,r._engine,!0)}),this._renderEffectsForIsolatedPass[a]._disable(s)}for(var l in this._renderEffects)this._renderEffects.hasOwnProperty(l)&&this._renderEffects[l]._enable(n)}},t.prototype._update=function(){for(var e in this._renderEffects)this._renderEffects.hasOwnProperty(e)&&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._reset=function(){this._renderEffects={},this._renderEffectsForIsolatedPass=new Array},t.prototype.dispose=function(){},t.PASS_EFFECT_NAME="passEffect",t.PASS_SAMPLER_NAME="passSampler",r([e.serialize()],t.prototype,"_name",void 0),t}();e.PostProcessRenderPipeline=t}(s||(s={}));!function(e){var t=function(){function t(t,i){void 0===i&&(i=e.Engine.TEXTURETYPE_FLOAT);var r=this;this._scene=t;var n=t.getEngine();this._depthMap=new e.RenderTargetTexture("depthMap",{width:n.getRenderWidth(),height:n.getRenderHeight()},this._scene,!1,!0,i),this._depthMap.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._depthMap.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._depthMap.refreshRate=1,this._depthMap.renderParticles=!1,this._depthMap.renderList=null,this._depthMap.onClearObservable.add(function(t){t.clear(new e.Color4(1,1,1,1),!0,!0,!0)});var o=function(t){var i=t.getRenderingMesh(),n=r._scene,o=n.getEngine(),s=t.getMaterial();if(s){o.setState(s.backFaceCulling);var a=i._getInstancesRenderList(t._id);if(!a.mustReturn){var l=o.getCaps().instancedArrays&&null!==a.visibleInstances[t._id];if(r.isReady(t,l)&&n.activeCamera){if(o.enableEffect(r._effect),i._bind(t,r._effect,e.Material.TriangleFillMode),r._effect.setMatrix("viewProjection",n.getTransformMatrix()),r._effect.setFloat2("depthValues",n.activeCamera.minZ,n.activeCamera.minZ+n.activeCamera.maxZ),s&&s.needAlphaTesting()){var h=s.getAlphaTestTexture();h&&(r._effect.setTexture("diffuseSampler",h),r._effect.setMatrix("diffuseMatrix",h.getTextureMatrix()))}i.useBones&&i.computeBonesUsingShaders&&i.skeleton&&r._effect.setMatrices("mBones",i.skeleton.getTransformMatrices(i)),i._processRendering(t,r._effect,e.Material.TriangleFillMode,a,l,function(e,t){return r._effect.setMatrix("world",t)})}}}};this._depthMap.customRenderFunction=function(e,t,i,r){var s;if(r.length){for(n.setColorWrite(!1),s=0;s<r.length;s++)o(r.data[s]);n.setColorWrite(!0)}for(s=0;s<e.length;s++)o(e.data[s]);for(s=0;s<t.length;s++)o(t.data[s])}}return t.prototype.isReady=function(t,i){var r=t.getMaterial();if(r.disableDepthWrite)return!1;var n=[],o=[e.VertexBuffer.PositionKind],s=t.getMesh();r&&r.needAlphaTesting()&&(n.push("#define ALPHATEST"),s.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(o.push(e.VertexBuffer.UVKind),n.push("#define UV1")),s.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(o.push(e.VertexBuffer.UV2Kind),n.push("#define UV2"))),s.useBones&&s.computeBonesUsingShaders?(o.push(e.VertexBuffer.MatricesIndicesKind),o.push(e.VertexBuffer.MatricesWeightsKind),s.numBoneInfluencers>4&&(o.push(e.VertexBuffer.MatricesIndicesExtraKind),o.push(e.VertexBuffer.MatricesWeightsExtraKind)),n.push("#define NUM_BONE_INFLUENCERS "+s.numBoneInfluencers),n.push("#define BonesPerMesh "+(s.skeleton?s.skeleton.bones.length+1:0))):n.push("#define NUM_BONE_INFLUENCERS 0"),i&&(n.push("#define INSTANCES"),o.push("world0"),o.push("world1"),o.push("world2"),o.push("world3"));var a=n.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("depth",o,["world","mBones","viewProjection","diffuseMatrix","depthValues"],["diffuseSampler"],a)),this._effect.isReady()},t.prototype.getDepthMap=function(){return this._depthMap},t.prototype.dispose=function(){this._depthMap.dispose()},t}();e.DepthRenderer=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o){var s=t.call(this,r.getEngine(),i)||this;s.SSAOOriginalSceneColorEffect="SSAOOriginalSceneColorEffect",s.SSAORenderEffect="SSAORenderEffect",s.SSAOBlurHRenderEffect="SSAOBlurHRenderEffect",s.SSAOBlurVRenderEffect="SSAOBlurVRenderEffect",s.SSAOCombineRenderEffect="SSAOCombineRenderEffect",s.totalStrength=1,s.radius=1e-4,s.area=.0075,s.fallOff=1e-6,s.base=.5,s._firstUpdate=!0,s._scene=r,s._createRandomTexture(),s._depthTexture=r.enableDepthRenderer().getDepthMap();var a=n.ssaoRatio||n,l=n.combineRatio||n;return s._ratio={ssaoRatio:a,combineRatio:l},s._originalColorPostProcess=new e.PassPostProcess("SSAOOriginalSceneColor",l,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1),s._createSSAOPostProcess(a),s._createBlurPostProcess(a),s._createSSAOCombinePostProcess(l),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOOriginalSceneColorEffect,function(){return s._originalColorPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAORenderEffect,function(){return s._ssaoPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOBlurHRenderEffect,function(){return s._blurHPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOBlurVRenderEffect,function(){return s._blurVPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOCombineRenderEffect,function(){return s._ssaoCombinePostProcess},!0)),r.postProcessRenderPipelineManager.addPipeline(s),o&&r.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(i,o),s}return n(i,t),i.prototype.dispose=function(e){void 0===e&&(e=!1);for(var i=0;i<this._scene.cameras.length;i++){var r=this._scene.cameras[i];this._originalColorPostProcess.dispose(r),this._ssaoPostProcess.dispose(r),this._blurHPostProcess.dispose(r),this._blurVPostProcess.dispose(r),this._ssaoCombinePostProcess.dispose(r)}this._randomTexture.dispose(),e&&this._scene.disableDepthRenderer(),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras),t.prototype.dispose.call(this)},i.prototype._createBlurPostProcess=function(t){var i=this;this._blurHPostProcess=new e.BlurPostProcess("BlurH",new e.Vector2(1,0),16,t,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,e.Engine.TEXTURETYPE_UNSIGNED_INT),this._blurVPostProcess=new e.BlurPostProcess("BlurV",new e.Vector2(0,1),16,t,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,e.Engine.TEXTURETYPE_UNSIGNED_INT),this._blurHPostProcess.onActivateObservable.add(function(){var e=i._blurHPostProcess.width/i._scene.getEngine().getRenderWidth();i._blurHPostProcess.kernel=16*e}),this._blurVPostProcess.onActivateObservable.add(function(){var e=i._blurVPostProcess.height/i._scene.getEngine().getRenderHeight();i._blurVPostProcess.kernel=16*e})},i.prototype._rebuild=function(){this._firstUpdate=!0,t.prototype._rebuild.call(this)},i.prototype._createSSAOPostProcess=function(t){var i=this,r=[.5381,.1856,-.4319,.1379,.2486,.443,.3371,.5679,-.0057,-.6999,-.0451,-.0019,.0689,-.1598,-.8547,.056,.0069,-.1843,-.0146,.1402,.0762,.01,-.1924,-.0344,-.3577,-.5301,-.4358,-.3169,.1063,.0158,.0103,-.5869,.0046,-.0897,-.494,.3287,.7119,-.0154,-.0918,-.0533,.0596,-.5411,.0352,-.0631,.546,-.4776,.2847,-.0271];this._ssaoPostProcess=new e.PostProcess("ssao","ssao",["sampleSphere","samplesFactor","randTextureTiles","totalStrength","radius","area","fallOff","base","range","viewport"],["randomSampler"],t,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define SAMPLES 16\n#define SSAO"),this._ssaoPostProcess.onApply=function(e){i._firstUpdate&&(e.setArray3("sampleSphere",r),e.setFloat("samplesFactor",1/16),e.setFloat("randTextureTiles",4)),e.setFloat("totalStrength",i.totalStrength),e.setFloat("radius",i.radius),e.setFloat("area",i.area),e.setFloat("fallOff",i.fallOff),e.setFloat("base",i.base),e.setTexture("textureSampler",i._depthTexture),e.setTexture("randomSampler",i._randomTexture)}},i.prototype._createSSAOCombinePostProcess=function(t){var i=this;this._ssaoCombinePostProcess=new e.PostProcess("ssaoCombine","ssaoCombine",[],["originalColor"],t,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._ssaoCombinePostProcess.onApply=function(e){e.setTextureFromPostProcess("originalColor",i._originalColorPostProcess)}},i.prototype._createRandomTexture=function(){this._randomTexture=new e.DynamicTexture("SSAORandomTexture",512,this._scene,!1,e.Texture.TRILINEAR_SAMPLINGMODE),this._randomTexture.wrapU=e.Texture.WRAP_ADDRESSMODE,this._randomTexture.wrapV=e.Texture.WRAP_ADDRESSMODE;for(var t=this._randomTexture.getContext(),i=function(e,t){return Math.random()*(t-e)+e},r=e.Vector3.Zero(),n=0;n<512;n++)for(var o=0;o<512;o++)r.x=Math.floor(255*i(-1,1)),r.y=Math.floor(255*i(-1,1)),r.z=Math.floor(255*i(-1,1)),t.fillStyle="rgb("+r.x+", "+r.y+", "+r.z+")",t.fillRect(n,o,1,1);this._randomTexture.update(!1)},r([e.serialize()],i.prototype,"totalStrength",void 0),r([e.serialize()],i.prototype,"radius",void 0),r([e.serialize()],i.prototype,"area",void 0),r([e.serialize()],i.prototype,"fallOff",void 0),r([e.serialize()],i.prototype,"base",void 0),r([e.serialize()],i.prototype,"_ratio",void 0),i}(e.PostProcessRenderPipeline);e.SSAORenderingPipeline=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o){var s=t.call(this,r.getEngine(),i)||this;if(s.SSAOOriginalSceneColorEffect="SSAOOriginalSceneColorEffect",s.SSAORenderEffect="SSAORenderEffect",s.SSAOBlurHRenderEffect="SSAOBlurHRenderEffect",s.SSAOBlurVRenderEffect="SSAOBlurVRenderEffect",s.SSAOCombineRenderEffect="SSAOCombineRenderEffect",s.totalStrength=1,s.maxZ=100,s.minZAspect=.2,s._samples=8,s._expensiveBlur=!0,s.radius=2,s.base=.1,s._firstUpdate=!0,s._scene=r,!s.isSupported)return e.Tools.Error("SSAO 2 needs WebGL 2 support."),s;var a=n.ssaoRatio||n,l=n.blurRatio||n;s._ratio={ssaoRatio:a,blurRatio:l};var h=r.enableGeometryBufferRenderer();return s._createRandomTexture(),s._depthTexture=h.getGBuffer().textures[0],s._normalTexture=h.getGBuffer().textures[1],s._originalColorPostProcess=new e.PassPostProcess("SSAOOriginalSceneColor",1,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1),s._createSSAOPostProcess(1),s._createBlurPostProcess(a,l),s._createSSAOCombinePostProcess(l),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOOriginalSceneColorEffect,function(){return s._originalColorPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAORenderEffect,function(){return s._ssaoPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOBlurHRenderEffect,function(){return s._blurHPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOBlurVRenderEffect,function(){return s._blurVPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOCombineRenderEffect,function(){return s._ssaoCombinePostProcess},!0)),r.postProcessRenderPipelineManager.addPipeline(s),o&&r.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(i,o),s}return n(i,t),Object.defineProperty(i.prototype,"samples",{get:function(){return this._samples},set:function(e){this._ssaoPostProcess.updateEffect("#define SAMPLES "+e+"\n#define SSAO"),this._samples=e,this._sampleSphere=this._generateHemisphere(),this._firstUpdate=!0},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"expensiveBlur",{get:function(){return this._expensiveBlur},set:function(e){this._blurHPostProcess.updateEffect("#define BILATERAL_BLUR\n#define BILATERAL_BLUR_H\n#define SAMPLES 16\n#define EXPENSIVE "+(e?"1":"0")+"\n",null,["textureSampler","depthSampler"]),this._blurVPostProcess.updateEffect("#define BILATERAL_BLUR\n#define SAMPLES 16\n#define EXPENSIVE "+(e?"1":"0")+"\n",null,["textureSampler","depthSampler"]),this._expensiveBlur=e,this._firstUpdate=!0},enumerable:!0,configurable:!0}),Object.defineProperty(i,"IsSupported",{get:function(){var t=e.Engine.LastCreatedEngine;return!!t&&t.getCaps().drawBuffersExtension},enumerable:!0,configurable:!0}),i.prototype.dispose=function(e){void 0===e&&(e=!1);for(var i=0;i<this._scene.cameras.length;i++){var r=this._scene.cameras[i];this._originalColorPostProcess.dispose(r),this._ssaoPostProcess.dispose(r),this._blurHPostProcess.dispose(r),this._blurVPostProcess.dispose(r),this._ssaoCombinePostProcess.dispose(r)}this._randomTexture.dispose(),e&&this._scene.disableGeometryBufferRenderer(),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras),t.prototype.dispose.call(this)},i.prototype._createBlurPostProcess=function(t,i){var r=this;this._samplerOffsets=[];for(var n=this.expensiveBlur,o=-8;o<8;o++)this._samplerOffsets.push(2*o+.5);this._blurHPostProcess=new e.PostProcess("BlurH","ssao2",["outSize","samplerOffsets","near","far","radius"],["depthSampler"],t,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define BILATERAL_BLUR\n#define BILATERAL_BLUR_H\n#define SAMPLES 16\n#define EXPENSIVE "+(n?"1":"0")+"\n"),this._blurHPostProcess.onApply=function(e){r._scene.activeCamera&&(e.setFloat("outSize",r._ssaoCombinePostProcess.width>0?r._ssaoCombinePostProcess.width:r._originalColorPostProcess.width),e.setFloat("near",r._scene.activeCamera.minZ),e.setFloat("far",r._scene.activeCamera.maxZ),e.setFloat("radius",r.radius),e.setTexture("depthSampler",r._depthTexture),r._firstUpdate&&e.setArray("samplerOffsets",r._samplerOffsets))},this._blurVPostProcess=new e.PostProcess("BlurV","ssao2",["outSize","samplerOffsets","near","far","radius"],["depthSampler"],i,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define BILATERAL_BLUR\n#define BILATERAL_BLUR_V\n#define SAMPLES 16\n#define EXPENSIVE "+(n?"1":"0")+"\n"),this._blurVPostProcess.onApply=function(e){r._scene.activeCamera&&(e.setFloat("outSize",r._ssaoCombinePostProcess.height>0?r._ssaoCombinePostProcess.height:r._originalColorPostProcess.height),e.setFloat("near",r._scene.activeCamera.minZ),e.setFloat("far",r._scene.activeCamera.maxZ),e.setFloat("radius",r.radius),e.setTexture("depthSampler",r._depthTexture),r._firstUpdate&&(e.setArray("samplerOffsets",r._samplerOffsets),r._firstUpdate=!1))}},i.prototype._rebuild=function(){this._firstUpdate=!0,t.prototype._rebuild.call(this)},i.prototype._generateHemisphere=function(){for(var t,i,r=this.samples,n=[],o=function(e,t){return Math.random()*(t-e)+e},s=0;s<r;)(t=new e.Vector3(o(-1,1),o(-1,1),o(.3,1))).normalize(),i=s/r,i=e.Scalar.Lerp(.1,1,i*i),t.scaleInPlace(i),n.push(t.x,t.y,t.z),s++;return n},i.prototype._createSSAOPostProcess=function(t){var i=this,r=this.samples;this._sampleSphere=this._generateHemisphere(),this._ssaoPostProcess=new e.PostProcess("ssao2","ssao2",["sampleSphere","samplesFactor","randTextureTiles","totalStrength","radius","base","range","projection","near","far","texelSize","xViewport","yViewport","maxZ","minZAspect"],["randomSampler","normalSampler"],t,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define SAMPLES "+r+"\n#define SSAO"),this._ssaoPostProcess.onApply=function(e){i._firstUpdate&&(e.setArray3("sampleSphere",i._sampleSphere),e.setFloat("randTextureTiles",4)),i._scene.activeCamera&&(e.setFloat("samplesFactor",1/i.samples),e.setFloat("totalStrength",i.totalStrength),e.setFloat2("texelSize",1/i._ssaoPostProcess.width,1/i._ssaoPostProcess.height),e.setFloat("radius",i.radius),e.setFloat("maxZ",i.maxZ),e.setFloat("minZAspect",i.minZAspect),e.setFloat("base",i.base),e.setFloat("near",i._scene.activeCamera.minZ),e.setFloat("far",i._scene.activeCamera.maxZ),e.setFloat("xViewport",Math.tan(i._scene.activeCamera.fov/2)*i._scene.getEngine().getAspectRatio(i._scene.activeCamera,!0)),e.setFloat("yViewport",Math.tan(i._scene.activeCamera.fov/2)),e.setMatrix("projection",i._scene.getProjectionMatrix()),e.setTexture("textureSampler",i._depthTexture),e.setTexture("normalSampler",i._normalTexture),e.setTexture("randomSampler",i._randomTexture))}},i.prototype._createSSAOCombinePostProcess=function(t){var i=this;this._ssaoCombinePostProcess=new e.PostProcess("ssaoCombine","ssaoCombine",[],["originalColor"],t,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._ssaoCombinePostProcess.onApply=function(e){e.setTextureFromPostProcess("originalColor",i._originalColorPostProcess)}},i.prototype._createRandomTexture=function(){this._randomTexture=new e.DynamicTexture("SSAORandomTexture",512,this._scene,!1,e.Texture.TRILINEAR_SAMPLINGMODE),this._randomTexture.wrapU=e.Texture.WRAP_ADDRESSMODE,this._randomTexture.wrapV=e.Texture.WRAP_ADDRESSMODE;for(var t=this._randomTexture.getContext(),i=function(e,t){return Math.random()*(t-e)+e},r=e.Vector3.Zero(),n=0;n<512;n++)for(var o=0;o<512;o++)r.x=i(0,1),r.y=i(0,1),r.z=0,r.normalize(),r.scaleInPlace(255),r.x=Math.floor(r.x),r.y=Math.floor(r.y),t.fillStyle="rgb("+r.x+", "+r.y+", "+r.z+")",t.fillRect(n,o,1,1);this._randomTexture.update(!1)},r([e.serialize()],i.prototype,"totalStrength",void 0),r([e.serialize()],i.prototype,"maxZ",void 0),r([e.serialize()],i.prototype,"minZAspect",void 0),r([e.serialize("samples")],i.prototype,"_samples",void 0),r([e.serialize("expensiveBlur")],i.prototype,"_expensiveBlur",void 0),r([e.serialize()],i.prototype,"radius",void 0),r([e.serialize()],i.prototype,"base",void 0),r([e.serialize()],i.prototype,"_ratio",void 0),i}(e.PostProcessRenderPipeline);e.SSAO2RenderingPipeline=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s){void 0===o&&(o=1);var a=t.call(this,n.getEngine(),i)||this;return a.LensChromaticAberrationEffect="LensChromaticAberrationEffect",a.HighlightsEnhancingEffect="HighlightsEnhancingEffect",a.LensDepthOfFieldEffect="LensDepthOfFieldEffect",a._scene=n,a._depthTexture=n.enableDepthRenderer().getDepthMap(),r.grain_texture?a._grainTexture=r.grain_texture:a._createGrainTexture(),a._edgeBlur=r.edge_blur?r.edge_blur:0,a._grainAmount=r.grain_amount?r.grain_amount:0,a._chromaticAberration=r.chromatic_aberration?r.chromatic_aberration:0,a._distortion=r.distortion?r.distortion:0,a._highlightsGain=void 0!==r.dof_gain?r.dof_gain:-1,a._highlightsThreshold=r.dof_threshold?r.dof_threshold:1,a._dofDistance=void 0!==r.dof_focus_distance?r.dof_focus_distance:-1,a._dofAperture=r.dof_aperture?r.dof_aperture:1,a._dofDarken=r.dof_darken?r.dof_darken:0,a._dofPentagon=void 0===r.dof_pentagon||r.dof_pentagon,a._blurNoise=void 0===r.blur_noise||r.blur_noise,a._createChromaticAberrationPostProcess(o),a._createHighlightsPostProcess(o),a._createDepthOfFieldPostProcess(o/4),a.addEffect(new e.PostProcessRenderEffect(n.getEngine(),a.LensChromaticAberrationEffect,function(){return a._chromaticAberrationPostProcess},!0)),a.addEffect(new e.PostProcessRenderEffect(n.getEngine(),a.HighlightsEnhancingEffect,function(){return a._highlightsPostProcess},!0)),a.addEffect(new e.PostProcessRenderEffect(n.getEngine(),a.LensDepthOfFieldEffect,function(){return a._depthOfFieldPostProcess},!0)),-1===a._highlightsGain&&a._disableEffect(a.HighlightsEnhancingEffect,null),n.postProcessRenderPipelineManager.addPipeline(a),s&&n.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(i,s),a}return n(i,t),i.prototype.setEdgeBlur=function(e){this._edgeBlur=e},i.prototype.disableEdgeBlur=function(){this._edgeBlur=0},i.prototype.setGrainAmount=function(e){this._grainAmount=e},i.prototype.disableGrain=function(){this._grainAmount=0},i.prototype.setChromaticAberration=function(e){this._chromaticAberration=e},i.prototype.disableChromaticAberration=function(){this._chromaticAberration=0},i.prototype.setEdgeDistortion=function(e){this._distortion=e},i.prototype.disableEdgeDistortion=function(){this._distortion=0},i.prototype.setFocusDistance=function(e){this._dofDistance=e},i.prototype.disableDepthOfField=function(){this._dofDistance=-1},i.prototype.setAperture=function(e){this._dofAperture=e},i.prototype.setDarkenOutOfFocus=function(e){this._dofDarken=e},i.prototype.enablePentagonBokeh=function(){this._highlightsPostProcess.updateEffect("#define PENTAGON\n")},i.prototype.disablePentagonBokeh=function(){this._highlightsPostProcess.updateEffect()},i.prototype.enableNoiseBlur=function(){this._blurNoise=!0},i.prototype.disableNoiseBlur=function(){this._blurNoise=!1},i.prototype.setHighlightsGain=function(e){this._highlightsGain=e},i.prototype.setHighlightsThreshold=function(e){-1===this._highlightsGain&&(this._highlightsGain=1),this._highlightsThreshold=e},i.prototype.disableHighlights=function(){this._highlightsGain=-1},i.prototype.dispose=function(e){void 0===e&&(e=!1),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras),this._chromaticAberrationPostProcess=null,this._highlightsPostProcess=null,this._depthOfFieldPostProcess=null,this._grainTexture.dispose(),e&&this._scene.disableDepthRenderer()},i.prototype._createChromaticAberrationPostProcess=function(t){var i=this;this._chromaticAberrationPostProcess=new e.PostProcess("LensChromaticAberration","chromaticAberration",["chromatic_aberration","screen_width","screen_height"],[],t,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._chromaticAberrationPostProcess.onApply=function(e){e.setFloat("chromatic_aberration",i._chromaticAberration),e.setFloat("screen_width",i._scene.getEngine().getRenderWidth()),e.setFloat("screen_height",i._scene.getEngine().getRenderHeight())}},i.prototype._createHighlightsPostProcess=function(t){var i=this;this._highlightsPostProcess=new e.PostProcess("LensHighlights","lensHighlights",["gain","threshold","screen_width","screen_height"],[],t,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,this._dofPentagon?"#define PENTAGON\n":""),this._highlightsPostProcess.onApply=function(e){e.setFloat("gain",i._highlightsGain),e.setFloat("threshold",i._highlightsThreshold),e.setTextureFromPostProcess("textureSampler",i._chromaticAberrationPostProcess),e.setFloat("screen_width",i._scene.getEngine().getRenderWidth()),e.setFloat("screen_height",i._scene.getEngine().getRenderHeight())}},i.prototype._createDepthOfFieldPostProcess=function(t){var i=this;this._depthOfFieldPostProcess=new e.PostProcess("LensDepthOfField","depthOfField",["grain_amount","blur_noise","screen_width","screen_height","distortion","dof_enabled","screen_distance","aperture","darken","edge_blur","highlights","near","far"],["depthSampler","grainSampler","highlightsSampler"],t,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._depthOfFieldPostProcess.onApply=function(e){e.setTexture("depthSampler",i._depthTexture),e.setTexture("grainSampler",i._grainTexture),e.setTextureFromPostProcess("textureSampler",i._highlightsPostProcess),e.setTextureFromPostProcess("highlightsSampler",i._depthOfFieldPostProcess),e.setFloat("grain_amount",i._grainAmount),e.setBool("blur_noise",i._blurNoise),e.setFloat("screen_width",i._scene.getEngine().getRenderWidth()),e.setFloat("screen_height",i._scene.getEngine().getRenderHeight()),e.setFloat("distortion",i._distortion),e.setBool("dof_enabled",-1!==i._dofDistance),e.setFloat("screen_distance",1/(.1-1/i._dofDistance)),e.setFloat("aperture",i._dofAperture),e.setFloat("darken",i._dofDarken),e.setFloat("edge_blur",i._edgeBlur),e.setBool("highlights",-1!==i._highlightsGain),i._scene.activeCamera&&(e.setFloat("near",i._scene.activeCamera.minZ),e.setFloat("far",i._scene.activeCamera.maxZ))}},i.prototype._createGrainTexture=function(){this._grainTexture=new e.DynamicTexture("LensNoiseTexture",512,this._scene,!1,e.Texture.BILINEAR_SAMPLINGMODE),this._grainTexture.wrapU=e.Texture.WRAP_ADDRESSMODE,this._grainTexture.wrapV=e.Texture.WRAP_ADDRESSMODE;for(var t,i=this._grainTexture.getContext(),r=0;r<512;r++)for(var n=0;n<512;n++)t=Math.floor(255*function(e,t){return Math.random()*(t-e)+e}(.42,.58)),i.fillStyle="rgb("+t+", "+t+", "+t+")",i.fillRect(r,n,1,1);this._grainTexture.update(!1)},i}(e.PostProcessRenderPipeline);e.LensRenderingPipeline=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s){void 0===o&&(o=null);var a=t.call(this,r.getEngine(),i)||this;return a.downSampleX4PostProcess=null,a.brightPassPostProcess=null,a.blurHPostProcesses=[],a.blurVPostProcesses=[],a.textureAdderPostProcess=null,a.volumetricLightPostProcess=null,a.volumetricLightSmoothXPostProcess=null,a.volumetricLightSmoothYPostProcess=null,a.volumetricLightMergePostProces=null,a.volumetricLightFinalPostProcess=null,a.luminancePostProcess=null,a.luminanceDownSamplePostProcesses=[],a.hdrPostProcess=null,a.textureAdderFinalPostProcess=null,a.lensFlareFinalPostProcess=null,a.hdrFinalPostProcess=null,a.lensFlarePostProcess=null,a.lensFlareComposePostProcess=null,a.motionBlurPostProcess=null,a.depthOfFieldPostProcess=null,a.brightThreshold=1,a.blurWidth=512,a.horizontalBlur=!1,a.exposure=1,a.lensTexture=null,a.volumetricLightCoefficient=.2,a.volumetricLightPower=4,a.volumetricLightBlurScale=64,a.sourceLight=null,a.hdrMinimumLuminance=1,a.hdrDecreaseRate=.5,a.hdrIncreaseRate=.5,a.lensColorTexture=null,a.lensFlareStrength=20,a.lensFlareGhostDispersal=1.4,a.lensFlareHaloWidth=.7,a.lensFlareDistortionStrength=16,a.lensStarTexture=null,a.lensFlareDirtTexture=null,a.depthOfFieldDistance=10,a.depthOfFieldBlurWidth=64,a.motionStrength=1,a.animations=[],a._currentDepthOfFieldSource=null,a._hdrCurrentLuminance=1,a._bloomEnabled=!0,a._depthOfFieldEnabled=!1,a._vlsEnabled=!1,a._lensFlareEnabled=!1,a._hdrEnabled=!1,a._motionBlurEnabled=!1,a._motionBlurSamples=64,a._volumetricLightStepsCount=50,a._cameras=s||[],a._scene=r,a._basePostProcess=o,a._ratio=n,a._floatTextureType=r.getEngine().getCaps().textureFloatRender?e.Engine.TEXTURETYPE_FLOAT:e.Engine.TEXTURETYPE_HALF_FLOAT,r.postProcessRenderPipelineManager.addPipeline(a),a._buildPipeline(),a}return n(i,t),Object.defineProperty(i.prototype,"BloomEnabled",{get:function(){return this._bloomEnabled},set:function(e){this._bloomEnabled!==e&&(this._bloomEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"DepthOfFieldEnabled",{get:function(){return this._depthOfFieldEnabled},set:function(e){this._depthOfFieldEnabled!==e&&(this._depthOfFieldEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"LensFlareEnabled",{get:function(){return this._lensFlareEnabled},set:function(e){this._lensFlareEnabled!==e&&(this._lensFlareEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"HDREnabled",{get:function(){return this._hdrEnabled},set:function(e){this._hdrEnabled!==e&&(this._hdrEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"VLSEnabled",{get:function(){return this._vlsEnabled},set:function(t){this._vlsEnabled!==t&&(!t||this._scene.enableGeometryBufferRenderer()?(this._vlsEnabled=t,this._buildPipeline()):e.Tools.Warn("Geometry renderer is not supported, cannot create volumetric lights in Standard Rendering Pipeline"))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"MotionBlurEnabled",{get:function(){return this._motionBlurEnabled},set:function(e){this._motionBlurEnabled!==e&&(this._motionBlurEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"volumetricLightStepsCount",{get:function(){return this._volumetricLightStepsCount},set:function(e){this.volumetricLightPostProcess&&this.volumetricLightPostProcess.updateEffect("#define VLS\n#define NB_STEPS "+e.toFixed(1)),this._volumetricLightStepsCount=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"motionBlurSamples",{get:function(){return this._motionBlurSamples},set:function(e){this.motionBlurPostProcess&&this.motionBlurPostProcess.updateEffect("#define MOTION_BLUR\n#define MAX_MOTION_SAMPLES "+e.toFixed(1)),this._motionBlurSamples=e},enumerable:!0,configurable:!0}),i.prototype._buildPipeline=function(){var t=this,i=this._ratio,r=this._scene;this._disposePostProcesses(),this._reset(),this._basePostProcess?this.originalPostProcess=this._basePostProcess:(this.originalPostProcess=new e.PostProcess("HDRPass","standard",[],[],i,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1,"#define PASS_POST_PROCESS",this._floatTextureType),this.originalPostProcess.onApply=function(e){t._currentDepthOfFieldSource=t.originalPostProcess}),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRPassPostProcess",function(){return t.originalPostProcess},!0)),this._currentDepthOfFieldSource=this.originalPostProcess,this._vlsEnabled&&(this._createVolumetricLightPostProcess(r,i),this.volumetricLightFinalPostProcess=new e.PostProcess("HDRVLSFinal","standard",[],[],i,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1,"#define PASS_POST_PROCESS",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRVLSFinal",function(){return t.volumetricLightFinalPostProcess},!0))),this._bloomEnabled&&(this._createDownSampleX4PostProcess(r,i/2),this._createBrightPassPostProcess(r,i/2),this._createBlurPostProcesses(r,i/4,1),this._createTextureAdderPostProcess(r,i),this.textureAdderFinalPostProcess=new e.PostProcess("HDRDepthOfFieldSource","standard",[],[],i,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1,"#define PASS_POST_PROCESS",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRBaseDepthOfFieldSource",function(){return t.textureAdderFinalPostProcess},!0))),this._lensFlareEnabled&&(this._createLensFlarePostProcess(r,i),this.lensFlareFinalPostProcess=new e.PostProcess("HDRPostLensFlareDepthOfFieldSource","standard",[],[],i,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1,"#define PASS_POST_PROCESS",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRPostLensFlareDepthOfFieldSource",function(){return t.lensFlareFinalPostProcess},!0))),this._hdrEnabled&&(this._createLuminancePostProcesses(r,this._floatTextureType),this._createHdrPostProcess(r,i),this.hdrFinalPostProcess=new e.PostProcess("HDRPostHDReDepthOfFieldSource","standard",[],[],i,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1,"#define PASS_POST_PROCESS",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),"HDRPostHDReDepthOfFieldSource",function(){return t.hdrFinalPostProcess},!0))),this._depthOfFieldEnabled&&(this._createBlurPostProcesses(r,i/2,3,"depthOfFieldBlurWidth"),this._createDepthOfFieldPostProcess(r,i)),this._motionBlurEnabled&&this._createMotionBlurPostProcess(r,i),null!==this._cameras&&this._scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this._name,this._cameras)},i.prototype._createDownSampleX4PostProcess=function(t,i){var r=this,n=new Array(32);this.downSampleX4PostProcess=new e.PostProcess("HDRDownSampleX4","standard",["dsOffsets"],[],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define DOWN_SAMPLE_X4",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.downSampleX4PostProcess.onApply=function(e){for(var t=0,i=r.downSampleX4PostProcess.width,o=r.downSampleX4PostProcess.height,s=-2;s<2;s++)for(var a=-2;a<2;a++)n[t]=(s+.5)*(1/i),n[t+1]=(a+.5)*(1/o),t+=2;e.setArray2("dsOffsets",n)},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRDownSampleX4",function(){return r.downSampleX4PostProcess},!0))},i.prototype._createBrightPassPostProcess=function(t,i){var r=this,n=new Array(8);this.brightPassPostProcess=new e.PostProcess("HDRBrightPass","standard",["dsOffsets","brightThreshold"],[],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define BRIGHT_PASS",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.brightPassPostProcess.onApply=function(e){var t=1/r.brightPassPostProcess.width,i=1/r.brightPassPostProcess.height;n[0]=-.5*t,n[1]=.5*i,n[2]=.5*t,n[3]=.5*i,n[4]=-.5*t,n[5]=-.5*i,n[6]=.5*t,n[7]=-.5*i,e.setArray2("dsOffsets",n),e.setFloat("brightThreshold",r.brightThreshold)},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRBrightPass",function(){return r.brightPassPostProcess},!0))},i.prototype._createBlurPostProcesses=function(t,i,r,n){var o=this;void 0===n&&(n="blurWidth");var s=t.getEngine(),a=new e.BlurPostProcess("HDRBlurH_"+r,new e.Vector2(1,0),this[n],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,e.Engine.TEXTURETYPE_UNSIGNED_INT),l=new e.BlurPostProcess("HDRBlurV_"+r,new e.Vector2(0,1),this[n],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,e.Engine.TEXTURETYPE_UNSIGNED_INT);a.onActivateObservable.add(function(){var e=a.width/s.getRenderWidth();a.kernel=o[n]*e}),l.onActivateObservable.add(function(){var e=l.height/s.getRenderHeight();l.kernel=o.horizontalBlur?64*e:o[n]*e}),this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRBlurH"+r,function(){return a},!0)),this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRBlurV"+r,function(){return l},!0)),this.blurHPostProcesses.push(a),this.blurVPostProcesses.push(l)},i.prototype._createTextureAdderPostProcess=function(t,i){var r=this;this.textureAdderPostProcess=new e.PostProcess("HDRTextureAdder","standard",["exposure"],["otherSampler","lensSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define TEXTURE_ADDER",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.textureAdderPostProcess.onApply=function(e){e.setTextureFromPostProcess("otherSampler",r._vlsEnabled?r._currentDepthOfFieldSource:r.originalPostProcess),e.setTexture("lensSampler",r.lensTexture),e.setFloat("exposure",r.exposure),r._currentDepthOfFieldSource=r.textureAdderFinalPostProcess},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRTextureAdder",function(){return r.textureAdderPostProcess},!0))},i.prototype._createVolumetricLightPostProcess=function(t,i){var r=this,n=t.enableGeometryBufferRenderer();n.enablePosition=!0;var o=n.getGBuffer();this.volumetricLightPostProcess=new e.PostProcess("HDRVLS","standard",["shadowViewProjection","cameraPosition","sunDirection","sunColor","scatteringCoefficient","scatteringPower","depthValues"],["shadowMapSampler","positionSampler"],i/8,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define VLS\n#define NB_STEPS "+this._volumetricLightStepsCount.toFixed(1));var s=e.Vector2.Zero();this.volumetricLightPostProcess.onApply=function(e){if(r.sourceLight&&r.sourceLight.getShadowGenerator()&&r._scene.activeCamera){var t=r.sourceLight.getShadowGenerator();e.setTexture("shadowMapSampler",t.getShadowMap()),e.setTexture("positionSampler",o.textures[2]),e.setColor3("sunColor",r.sourceLight.diffuse),e.setVector3("sunDirection",r.sourceLight.getShadowDirection()),e.setVector3("cameraPosition",r._scene.activeCamera.globalPosition),e.setMatrix("shadowViewProjection",t.getTransformMatrix()),e.setFloat("scatteringCoefficient",r.volumetricLightCoefficient),e.setFloat("scatteringPower",r.volumetricLightPower),s.x=t.getLight().getDepthMinZ(r._scene.activeCamera),s.y=t.getLight().getDepthMaxZ(r._scene.activeCamera),e.setVector2("depthValues",s)}},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRVLS",function(){return r.volumetricLightPostProcess},!0)),this._createBlurPostProcesses(t,i/4,0,"volumetricLightBlurScale"),this.volumetricLightMergePostProces=new e.PostProcess("HDRVLSMerge","standard",[],["originalSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define VLSMERGE"),this.volumetricLightMergePostProces.onApply=function(e){e.setTextureFromPostProcess("originalSampler",r.originalPostProcess),r._currentDepthOfFieldSource=r.volumetricLightFinalPostProcess},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRVLSMerge",function(){return r.volumetricLightMergePostProces},!0))},i.prototype._createLuminancePostProcesses=function(t,r){var n=this,o=Math.pow(3,i.LuminanceSteps);this.luminancePostProcess=new e.PostProcess("HDRLuminance","standard",["lumOffsets"],[],{width:o,height:o},null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define LUMINANCE",r);var s=[];this.luminancePostProcess.onApply=function(e){var t=1/n.luminancePostProcess.width,i=1/n.luminancePostProcess.height;s[0]=-.5*t,s[1]=.5*i,s[2]=.5*t,s[3]=.5*i,s[4]=-.5*t,s[5]=-.5*i,s[6]=.5*t,s[7]=-.5*i,e.setArray2("lumOffsets",s)},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRLuminance",function(){return n.luminancePostProcess},!0));for(var a=i.LuminanceSteps-1;a>=0;a--){var o=Math.pow(3,a),l="#define LUMINANCE_DOWN_SAMPLE\n";0===a&&(l+="#define FINAL_DOWN_SAMPLER");var h=new e.PostProcess("HDRLuminanceDownSample"+a,"standard",["dsOffsets","halfDestPixelSize"],[],{width:o,height:o},null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,l,r);this.luminanceDownSamplePostProcesses.push(h)}var u=this.luminancePostProcess;this.luminanceDownSamplePostProcesses.forEach(function(i,r){var o=new Array(18);i.onApply=function(e){if(u){for(var t=0,s=-1;s<2;s++)for(var a=-1;a<2;a++)o[t]=s/u.width,o[t+1]=a/u.height,t+=2;e.setArray2("dsOffsets",o),e.setFloat("halfDestPixelSize",.5/u.width),u=r===n.luminanceDownSamplePostProcesses.length-1?n.luminancePostProcess:i}},r===n.luminanceDownSamplePostProcesses.length-1&&(i.onAfterRender=function(i){var r=t.getEngine().readPixels(0,0,1,1),o=new e.Vector4(1/16581375,1/65025,1/255,1);n._hdrCurrentLuminance=(r[0]*o.x+r[1]*o.y+r[2]*o.z+r[3]*o.w)/100}),n.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRLuminanceDownSample"+r,function(){return i},!0))})},i.prototype._createHdrPostProcess=function(t,i){var r=this;this.hdrPostProcess=new e.PostProcess("HDR","standard",["averageLuminance"],["textureAdderSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define HDR",e.Engine.TEXTURETYPE_UNSIGNED_INT);var n=1,o=0,s=0;this.hdrPostProcess.onApply=function(i){if(i.setTextureFromPostProcess("textureAdderSampler",r._currentDepthOfFieldSource),o+=t.getEngine().getDeltaTime(),n<0)n=r._hdrCurrentLuminance;else{var a=(s-o)/1e3;r._hdrCurrentLuminance<n+r.hdrDecreaseRate*a?n+=r.hdrDecreaseRate*a:r._hdrCurrentLuminance>n-r.hdrIncreaseRate*a?n-=r.hdrIncreaseRate*a:n=r._hdrCurrentLuminance}n=e.Scalar.Clamp(n,r.hdrMinimumLuminance,1e20),i.setFloat("averageLuminance",n),s=o,r._currentDepthOfFieldSource=r.hdrFinalPostProcess},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDR",function(){return r.hdrPostProcess},!0))},i.prototype._createLensFlarePostProcess=function(t,i){var r=this;this.lensFlarePostProcess=new e.PostProcess("HDRLensFlare","standard",["strength","ghostDispersal","haloWidth","resolution","distortionStrength"],["lensColorSampler"],i/2,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define LENS_FLARE",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRLensFlare",function(){return r.lensFlarePostProcess},!0)),this._createBlurPostProcesses(t,i/4,2),this.lensFlareComposePostProcess=new e.PostProcess("HDRLensFlareCompose","standard",["lensStarMatrix"],["otherSampler","lensDirtSampler","lensStarSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define LENS_FLARE_COMPOSE",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRLensFlareCompose",function(){return r.lensFlareComposePostProcess},!0));var n=new e.Vector2(0,0);this.lensFlarePostProcess.onApply=function(e){e.setTextureFromPostProcess("textureSampler",r._bloomEnabled?r.blurHPostProcesses[0]:r.originalPostProcess),e.setTexture("lensColorSampler",r.lensColorTexture),e.setFloat("strength",r.lensFlareStrength),e.setFloat("ghostDispersal",r.lensFlareGhostDispersal),e.setFloat("haloWidth",r.lensFlareHaloWidth),n.x=r.lensFlarePostProcess.width,n.y=r.lensFlarePostProcess.height,e.setVector2("resolution",n),e.setFloat("distortionStrength",r.lensFlareDistortionStrength)};var o=e.Matrix.FromValues(2,0,-1,0,0,2,-1,0,0,0,1,0,0,0,0,1),s=e.Matrix.FromValues(.5,0,.5,0,0,.5,.5,0,0,0,1,0,0,0,0,1);this.lensFlareComposePostProcess.onApply=function(t){if(r._scene.activeCamera){t.setTextureFromPostProcess("otherSampler",r._currentDepthOfFieldSource),t.setTexture("lensDirtSampler",r.lensFlareDirtTexture),t.setTexture("lensStarSampler",r.lensStarTexture);var i=r._scene.activeCamera.getViewMatrix().getRow(0),n=r._scene.activeCamera.getViewMatrix().getRow(2),a=e.Vector3.Dot(i.toVector3(),new e.Vector3(1,0,0))+e.Vector3.Dot(n.toVector3(),new e.Vector3(0,0,1));a*=4;var l=e.Matrix.FromValues(.5*Math.cos(a),-Math.sin(a),0,0,Math.sin(a),.5*Math.cos(a),0,0,0,0,1,0,0,0,0,1),h=s.multiply(l).multiply(o);t.setMatrix("lensStarMatrix",h),r._currentDepthOfFieldSource=r.lensFlareFinalPostProcess}}},i.prototype._createDepthOfFieldPostProcess=function(t,i){var r=this;this.depthOfFieldPostProcess=new e.PostProcess("HDRDepthOfField","standard",["distance"],["otherSampler","depthSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define DEPTH_OF_FIELD",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.depthOfFieldPostProcess.onApply=function(e){e.setTextureFromPostProcess("otherSampler",r._currentDepthOfFieldSource),e.setTexture("depthSampler",r._getDepthTexture()),e.setFloat("distance",r.depthOfFieldDistance)},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRDepthOfField",function(){return r.depthOfFieldPostProcess},!0))},i.prototype._createMotionBlurPostProcess=function(t,i){var r=this;this.motionBlurPostProcess=new e.PostProcess("HDRMotionBlur","standard",["inverseViewProjection","prevViewProjection","screenSize","motionScale","motionStrength"],["depthSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define MOTION_BLUR\n#define MAX_MOTION_SAMPLES "+this.motionBlurSamples.toFixed(1),e.Engine.TEXTURETYPE_UNSIGNED_INT);var n=0,o=e.Matrix.Identity(),s=e.Matrix.Identity(),a=e.Matrix.Identity(),l=e.Vector2.Zero();this.motionBlurPostProcess.onApply=function(e){(a=t.getProjectionMatrix().multiply(t.getViewMatrix())).invertToRef(s),e.setMatrix("inverseViewProjection",s),e.setMatrix("prevViewProjection",o),o=a,l.x=r.motionBlurPostProcess.width,l.y=r.motionBlurPostProcess.height,e.setVector2("screenSize",l),n=t.getEngine().getFps()/60,e.setFloat("motionScale",n),e.setFloat("motionStrength",r.motionStrength),e.setTexture("depthSampler",r._getDepthTexture())},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRMotionBlur",function(){return r.motionBlurPostProcess},!0))},i.prototype._getDepthTexture=function(){return this._scene.getEngine().getCaps().drawBuffersExtension?this._scene.enableGeometryBufferRenderer().getGBuffer().textures[0]:this._scene.enableDepthRenderer().getDepthMap()},i.prototype._disposePostProcesses=function(){for(var e=0;e<this._cameras.length;e++){var t=this._cameras[e];this.originalPostProcess&&this.originalPostProcess.dispose(t),this.downSampleX4PostProcess&&this.downSampleX4PostProcess.dispose(t),this.brightPassPostProcess&&this.brightPassPostProcess.dispose(t),this.textureAdderPostProcess&&this.textureAdderPostProcess.dispose(t),this.textureAdderFinalPostProcess&&this.textureAdderFinalPostProcess.dispose(t),this.volumetricLightPostProcess&&this.volumetricLightPostProcess.dispose(t),this.volumetricLightSmoothXPostProcess&&this.volumetricLightSmoothXPostProcess.dispose(t),this.volumetricLightSmoothYPostProcess&&this.volumetricLightSmoothYPostProcess.dispose(t),this.volumetricLightMergePostProces&&this.volumetricLightMergePostProces.dispose(t),this.volumetricLightFinalPostProcess&&this.volumetricLightFinalPostProcess.dispose(t),this.lensFlarePostProcess&&this.lensFlarePostProcess.dispose(t),this.lensFlareComposePostProcess&&this.lensFlareComposePostProcess.dispose(t);for(i=0;i<this.luminanceDownSamplePostProcesses.length;i++)this.luminanceDownSamplePostProcesses[i].dispose(t);this.luminancePostProcess&&this.luminancePostProcess.dispose(t),this.hdrPostProcess&&this.hdrPostProcess.dispose(t),this.hdrFinalPostProcess&&this.hdrFinalPostProcess.dispose(t),this.depthOfFieldPostProcess&&this.depthOfFieldPostProcess.dispose(t),this.motionBlurPostProcess&&this.motionBlurPostProcess.dispose(t);for(i=0;i<this.blurHPostProcesses.length;i++)this.blurHPostProcesses[i].dispose(t);for(var i=0;i<this.blurVPostProcesses.length;i++)this.blurVPostProcesses[i].dispose(t)}this.originalPostProcess=null,this.downSampleX4PostProcess=null,this.brightPassPostProcess=null,this.textureAdderPostProcess=null,this.textureAdderFinalPostProcess=null,this.volumetricLightPostProcess=null,this.volumetricLightSmoothXPostProcess=null,this.volumetricLightSmoothYPostProcess=null,this.volumetricLightMergePostProces=null,this.volumetricLightFinalPostProcess=null,this.lensFlarePostProcess=null,this.lensFlareComposePostProcess=null,this.luminancePostProcess=null,this.hdrPostProcess=null,this.hdrFinalPostProcess=null,this.depthOfFieldPostProcess=null,this.motionBlurPostProcess=null,this.luminanceDownSamplePostProcesses=[],this.blurHPostProcesses=[],this.blurVPostProcesses=[]},i.prototype.dispose=function(){this._disposePostProcesses(),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._cameras),t.prototype.dispose.call(this)},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="StandardRenderingPipeline",t},i.Parse=function(t,r,n){return e.SerializationHelper.Parse(function(){return new i(t._name,r,t._ratio)},t,r,n)},i.LuminanceSteps=6,r([e.serialize()],i.prototype,"brightThreshold",void 0),r([e.serialize()],i.prototype,"blurWidth",void 0),r([e.serialize()],i.prototype,"horizontalBlur",void 0),r([e.serialize()],i.prototype,"exposure",void 0),r([e.serializeAsTexture("lensTexture")],i.prototype,"lensTexture",void 0),r([e.serialize()],i.prototype,"volumetricLightCoefficient",void 0),r([e.serialize()],i.prototype,"volumetricLightPower",void 0),r([e.serialize()],i.prototype,"volumetricLightBlurScale",void 0),r([e.serialize()],i.prototype,"hdrMinimumLuminance",void 0),r([e.serialize()],i.prototype,"hdrDecreaseRate",void 0),r([e.serialize()],i.prototype,"hdrIncreaseRate",void 0),r([e.serializeAsTexture("lensColorTexture")],i.prototype,"lensColorTexture",void 0),r([e.serialize()],i.prototype,"lensFlareStrength",void 0),r([e.serialize()],i.prototype,"lensFlareGhostDispersal",void 0),r([e.serialize()],i.prototype,"lensFlareHaloWidth",void 0),r([e.serialize()],i.prototype,"lensFlareDistortionStrength",void 0),r([e.serializeAsTexture("lensStarTexture")],i.prototype,"lensStarTexture",void 0),r([e.serializeAsTexture("lensFlareDirtTexture")],i.prototype,"lensFlareDirtTexture",void 0),r([e.serialize()],i.prototype,"depthOfFieldDistance",void 0),r([e.serialize()],i.prototype,"depthOfFieldBlurWidth",void 0),r([e.serialize()],i.prototype,"motionStrength",void 0),r([e.serialize()],i.prototype,"BloomEnabled",null),r([e.serialize()],i.prototype,"DepthOfFieldEnabled",null),r([e.serialize()],i.prototype,"LensFlareEnabled",null),r([e.serialize()],i.prototype,"HDREnabled",null),r([e.serialize()],i.prototype,"VLSEnabled",null),r([e.serialize()],i.prototype,"MotionBlurEnabled",null),r([e.serialize()],i.prototype,"volumetricLightStepsCount",null),r([e.serialize()],i.prototype,"motionBlurSamples",null),i}(e.PostProcessRenderPipeline);e.StandardRenderingPipeline=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l){void 0===n&&(n=null),void 0===l&&(l=e.Engine.TEXTURETYPE_UNSIGNED_INT);var h=t.call(this,i,"fxaa",["texelSize"],null,r,n,o||e.Texture.BILINEAR_SAMPLINGMODE,s,a,null,l,"fxaa")||this;return h.onApplyObservable.add(function(e){var t=h.texelSize;e.setFloat2("texelSize",t.x,t.y)}),h}return n(i,t),i}(e.PostProcess);e.FxaaPostProcess=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s){void 0===s&&(s=!0);var a=t.call(this,n.getEngine(),i)||this;a.PassPostProcessId="PassPostProcessEffect",a.HighLightsPostProcessId="HighLightsPostProcessEffect",a.BlurXPostProcessId="BlurXPostProcessEffect",a.BlurYPostProcessId="BlurYPostProcessEffect",a.CopyBackPostProcessId="CopyBackPostProcessEffect",a.ImageProcessingPostProcessId="ImageProcessingPostProcessEffect",a.FxaaPostProcessId="FxaaPostProcessEffect",a.FinalMergePostProcessId="FinalMergePostProcessEffect",a.animations=[],a._bloomEnabled=!1,a._fxaaEnabled=!1,a._imageProcessingEnabled=!0,a._bloomScale=.6,a._buildAllowed=!0,a.bloomKernel=64,a._bloomWeight=.15,a._cameras=o||[],a._buildAllowed=s,a._scene=n;var l=a._scene.getEngine().getCaps();return a._hdr=r&&(l.textureHalfFloatRender||l.textureFloatRender),a._hdr?l.textureHalfFloatRender?a._defaultPipelineTextureType=e.Engine.TEXTURETYPE_HALF_FLOAT:l.textureFloatRender&&(a._defaultPipelineTextureType=e.Engine.TEXTURETYPE_FLOAT):a._defaultPipelineTextureType=e.Engine.TEXTURETYPE_UNSIGNED_INT,n.postProcessRenderPipelineManager.addPipeline(a),a._buildPipeline(),a}return n(i,t),Object.defineProperty(i.prototype,"bloomWeight",{get:function(){return this._bloomWeight},set:function(t){this._bloomWeight!==t&&(this._bloomWeight=t,this._hdr&&this.copyBack&&(this.copyBack.alphaConstants=new e.Color4(t,t,t,t)))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"bloomScale",{get:function(){return this._bloomScale},set:function(e){this._bloomScale!==e&&(this._bloomScale=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"bloomEnabled",{get:function(){return this._bloomEnabled},set:function(e){this._bloomEnabled!==e&&(this._bloomEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"fxaaEnabled",{get:function(){return this._fxaaEnabled},set:function(e){this._fxaaEnabled!==e&&(this._fxaaEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"imageProcessingEnabled",{get:function(){return this._imageProcessingEnabled},set:function(e){this._imageProcessingEnabled!==e&&(this._imageProcessingEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),i.prototype.prepare=function(){var e=this._buildAllowed;this._buildAllowed=!0,this._buildPipeline(),this._buildAllowed=e},i.prototype._buildPipeline=function(){var t=this;if(this._buildAllowed){var i=this._scene.getEngine();if(this._disposePostProcesses(),this._reset(),this.bloomEnabled){if(this.pass=new e.PassPostProcess("sceneRenderTarget",1,null,e.Texture.BILINEAR_SAMPLINGMODE,i,!1,this._defaultPipelineTextureType),this.addEffect(new e.PostProcessRenderEffect(i,this.PassPostProcessId,function(){return t.pass},!0)),this._hdr||(this.highlights=new e.HighlightsPostProcess("highlights",this.bloomScale,null,e.Texture.BILINEAR_SAMPLINGMODE,i,!1,this._defaultPipelineTextureType),this.addEffect(new e.PostProcessRenderEffect(i,this.HighLightsPostProcessId,function(){return t.highlights},!0)),this.highlights.autoClear=!1,this.highlights.alwaysForcePOT=!0),this.blurX=new e.BlurPostProcess("horizontal blur",new e.Vector2(1,0),10,this.bloomScale,null,e.Texture.BILINEAR_SAMPLINGMODE,i,!1,this._defaultPipelineTextureType),this.addEffect(new e.PostProcessRenderEffect(i,this.BlurXPostProcessId,function(){return t.blurX},!0)),this.blurX.alwaysForcePOT=!0,this.blurX.autoClear=!1,this.blurX.onActivateObservable.add(function(){var e=t.blurX.width/i.getRenderWidth(!0);t.blurX.kernel=t.bloomKernel*e}),this.blurY=new e.BlurPostProcess("vertical blur",new e.Vector2(0,1),10,this.bloomScale,null,e.Texture.BILINEAR_SAMPLINGMODE,i,!1,this._defaultPipelineTextureType),this.addEffect(new e.PostProcessRenderEffect(i,this.BlurYPostProcessId,function(){return t.blurY},!0)),this.blurY.alwaysForcePOT=!0,this.blurY.autoClear=!1,this.blurY.onActivateObservable.add(function(){var e=t.blurY.height/i.getRenderHeight(!0);t.blurY.kernel=t.bloomKernel*e}),this.copyBack=new e.PassPostProcess("bloomBlendBlit",this.bloomScale,null,e.Texture.BILINEAR_SAMPLINGMODE,i,!1,this._defaultPipelineTextureType),this.addEffect(new e.PostProcessRenderEffect(i,this.CopyBackPostProcessId,function(){return t.copyBack},!0)),this.copyBack.alwaysForcePOT=!0,this._hdr){this.copyBack.alphaMode=e.Engine.ALPHA_INTERPOLATE;var r=this.bloomWeight;this.copyBack.alphaConstants=new e.Color4(r,r,r,r)}else this.copyBack.alphaMode=e.Engine.ALPHA_SCREENMODE;this.copyBack.autoClear=!1}this._imageProcessingEnabled&&(this.imageProcessing=new e.ImageProcessingPostProcess("imageProcessing",1,null,e.Texture.BILINEAR_SAMPLINGMODE,i,!1,this._defaultPipelineTextureType),this._hdr?this.addEffect(new e.PostProcessRenderEffect(i,this.ImageProcessingPostProcessId,function(){return t.imageProcessing},!0)):this._scene.imageProcessingConfiguration.applyByPostProcess=!1),this.fxaaEnabled?(this.fxaa=new e.FxaaPostProcess("fxaa",1,null,e.Texture.BILINEAR_SAMPLINGMODE,i,!1,this._defaultPipelineTextureType),this.addEffect(new e.PostProcessRenderEffect(i,this.FxaaPostProcessId,function(){return t.fxaa},!0)),this.fxaa.autoClear=!(this.bloomEnabled||this._hdr&&this.imageProcessing)):(this.finalMerge=new e.PassPostProcess("finalMerge",1,null,e.Texture.BILINEAR_SAMPLINGMODE,i,!1,this._defaultPipelineTextureType),this.addEffect(new e.PostProcessRenderEffect(i,this.FinalMergePostProcessId,function(){return t.finalMerge},!0)),this.finalMerge.autoClear=!(this.bloomEnabled||this._hdr&&this.imageProcessing)),this.bloomEnabled&&(this._hdr?(this.copyBack.shareOutputWith(this.blurX),this.imageProcessing?(this.imageProcessing.shareOutputWith(this.pass),this.imageProcessing.autoClear=!1):this.fxaa?this.fxaa.shareOutputWith(this.pass):this.finalMerge.shareOutputWith(this.pass)):this.fxaa?this.fxaa.shareOutputWith(this.pass):this.finalMerge.shareOutputWith(this.pass)),null!==this._cameras&&this._scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this._name,this._cameras)}},i.prototype._disposePostProcesses=function(){for(var e=0;e<this._cameras.length;e++){var t=this._cameras[e];this.pass&&this.pass.dispose(t),this.highlights&&this.highlights.dispose(t),this.blurX&&this.blurX.dispose(t),this.blurY&&this.blurY.dispose(t),this.copyBack&&this.copyBack.dispose(t),this.imageProcessing&&this.imageProcessing.dispose(t),this.fxaa&&this.fxaa.dispose(t),this.finalMerge&&this.finalMerge.dispose(t)}this.pass=null,this.highlights=null,this.blurX=null,this.blurY=null,this.copyBack=null,this.imageProcessing=null,this.fxaa=null,this.finalMerge=null},i.prototype.dispose=function(){this._disposePostProcesses(),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._cameras),t.prototype.dispose.call(this)},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="DefaultRenderingPipeline",t},i.Parse=function(t,r,n){return e.SerializationHelper.Parse(function(){return new i(t._name,t._name._hdr,r)},t,r,n)},r([e.serialize()],i.prototype,"bloomKernel",void 0),r([e.serialize()],i.prototype,"_bloomWeight",void 0),r([e.serialize()],i.prototype,"_hdr",void 0),r([e.serialize()],i.prototype,"bloomWeight",null),r([e.serialize()],i.prototype,"bloomScale",null),r([e.serialize()],i.prototype,"bloomEnabled",null),r([e.serialize()],i.prototype,"fxaaEnabled",null),r([e.serialize()],i.prototype,"imageProcessingEnabled",null),i}(e.PostProcessRenderPipeline);e.DefaultRenderingPipeline=t}(s||(s={}));!function(e){var t=function(){function t(e,t){void 0===t&&(t=1),this._enablePosition=!1,this._scene=e,this._ratio=t,this._createRenderTargets()}return Object.defineProperty(t.prototype,"renderList",{set:function(e){this._multiRenderTarget.renderList=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isSupported",{get:function(){return this._multiRenderTarget.isSupported},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enablePosition",{get:function(){return this._enablePosition},set:function(e){this._enablePosition=e,this.dispose(),this._createRenderTargets()},enumerable:!0,configurable:!0}),t.prototype.isReady=function(t,i){var r=t.getMaterial();if(r&&r.disableDepthWrite)return!1;var n=[],o=[e.VertexBuffer.PositionKind,e.VertexBuffer.NormalKind],s=t.getMesh();r&&r.needAlphaTesting()&&(n.push("#define ALPHATEST"),s.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(o.push(e.VertexBuffer.UVKind),n.push("#define UV1")),s.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(o.push(e.VertexBuffer.UV2Kind),n.push("#define UV2"))),this._enablePosition&&n.push("#define POSITION"),s.useBones&&s.computeBonesUsingShaders?(o.push(e.VertexBuffer.MatricesIndicesKind),o.push(e.VertexBuffer.MatricesWeightsKind),s.numBoneInfluencers>4&&(o.push(e.VertexBuffer.MatricesIndicesExtraKind),o.push(e.VertexBuffer.MatricesWeightsExtraKind)),n.push("#define NUM_BONE_INFLUENCERS "+s.numBoneInfluencers),n.push("#define BonesPerMesh "+(s.skeleton?s.skeleton.bones.length+1:0))):n.push("#define NUM_BONE_INFLUENCERS 0"),i&&(n.push("#define INSTANCES"),o.push("world0"),o.push("world1"),o.push("world2"),o.push("world3"));var a=n.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("geometry",o,["world","mBones","viewProjection","diffuseMatrix","view"],["diffuseSampler"],a,void 0,void 0,void 0,{buffersCount:this._enablePosition?3:2})),this._effect.isReady()},t.prototype.getGBuffer=function(){return this._multiRenderTarget},t.prototype.dispose=function(){this.getGBuffer().dispose()},t.prototype._createRenderTargets=function(){var t=this,i=this._scene.getEngine(),r=this._enablePosition?3:2;if(this._multiRenderTarget=new e.MultiRenderTarget("gBuffer",{width:i.getRenderWidth()*this._ratio,height:i.getRenderHeight()*this._ratio},r,this._scene,{generateMipMaps:!1,generateDepthTexture:!0}),this.isSupported){this._multiRenderTarget.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._multiRenderTarget.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._multiRenderTarget.refreshRate=1,this._multiRenderTarget.renderParticles=!1,this._multiRenderTarget.renderList=null,this._multiRenderTarget.onClearObservable.add(function(t){t.clear(new e.Color4(0,0,0,1),!0,!0,!0)});var n=function(i){var r=i.getRenderingMesh(),n=t._scene,o=n.getEngine(),s=i.getMaterial();if(s){o.setState(s.backFaceCulling);var a=r._getInstancesRenderList(i._id);if(!a.mustReturn){var l=o.getCaps().instancedArrays&&null!==a.visibleInstances[i._id];if(t.isReady(i,l)){if(o.enableEffect(t._effect),r._bind(i,t._effect,e.Material.TriangleFillMode),t._effect.setMatrix("viewProjection",n.getTransformMatrix()),t._effect.setMatrix("view",n.getViewMatrix()),s&&s.needAlphaTesting()){var h=s.getAlphaTestTexture();h&&(t._effect.setTexture("diffuseSampler",h),t._effect.setMatrix("diffuseMatrix",h.getTextureMatrix()))}r.useBones&&r.computeBonesUsingShaders&&r.skeleton&&t._effect.setMatrices("mBones",r.skeleton.getTransformMatrices(r)),r._processRendering(i,t._effect,e.Material.TriangleFillMode,a,l,function(e,i){return t._effect.setMatrix("world",i)})}}}};this._multiRenderTarget.customRenderFunction=function(e,t,r,o){var s;if(o.length){for(i.setColorWrite(!1),s=0;s<o.length;s++)n(o.data[s]);i.setColorWrite(!0)}for(s=0;s<e.length;s++)n(e.data[s]);for(s=0;s<t.length;s++)n(t.data[s])}}},t}();e.GeometryBufferRenderer=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l,h,u,c){var f=t.call(this,i,"refraction",["baseColor","depth","colorLevel"],["refractionSampler"],a,l,h,u,c)||this;return f.color=n,f.depth=o,f.colorLevel=s,f.onActivateObservable.add(function(t){f._refRexture=f._refRexture||new e.Texture(r,t.getScene())}),f.onApplyObservable.add(function(e){e.setColor3("baseColor",f.color),e.setFloat("depth",f.depth),e.setFloat("colorLevel",f.colorLevel),e.setTexture("refractionSampler",f._refRexture)}),f}return n(i,t),i.prototype.dispose=function(e){this._refRexture&&this._refRexture.dispose(),t.prototype.dispose.call(this,e)},i}(e.PostProcess);e.RefractionPostProcess=t}(s||(s={}));!function(e){var t=function(e){function t(t,i,r,n,o,s){var a=e.call(this,t,"blackAndWhite",["degree"],null,i,r,n,o,s)||this;return a.degree=1,a.onApplyObservable.add(function(e){e.setFloat("degree",a.degree)}),a}return n(t,e),t}(e.PostProcess);e.BlackAndWhitePostProcess=t}(s||(s={}));!function(e){var t=function(e){function t(t,i,r,n,o,s,a){var l=e.call(this,t,"convolution",["kernel","screenSize"],null,r,n,o,s,a)||this;return l.kernel=i,l.onApply=function(e){e.setFloat2("screenSize",l.width,l.height),e.setArray("kernel",l.kernel)},l}return n(t,e),t.EdgeDetect0Kernel=[1,0,-1,0,0,0,-1,0,1],t.EdgeDetect1Kernel=[0,1,0,1,-4,1,0,1,0],t.EdgeDetect2Kernel=[-1,-1,-1,-1,8,-1,-1,-1,-1],t.SharpenKernel=[0,-1,0,-1,5,-1,0,-1,0],t.EmbossKernel=[-2,-1,0,-1,1,1,0,1,2],t.GaussianKernel=[0,1,0,1,1,1,0,1,0],t}(e.PostProcess);e.ConvolutionPostProcess=t}(s||(s={}));!function(e){var t=function(e){function t(t,i,r,n,o,s,a){var l=e.call(this,t,"filter",["kernelMatrix"],null,r,n,o,s,a)||this;return l.kernelMatrix=i,l.onApply=function(e){e.setMatrix("kernelMatrix",l.kernelMatrix)},l}return n(t,e),t}(e.PostProcess);e.FilterPostProcess=t}(s||(s={}));!function(e){var t=function(t){function i(r,n,o,s,a,l,h,u,c){void 0===a&&(a=100),void 0===l&&(l=e.Texture.BILINEAR_SAMPLINGMODE);var f=t.call(this,r,"volumetricLightScattering",["decay","exposure","weight","meshPositionOnScreen","density"],["lightScatteringSampler"],n.postProcessRatio||n,o,l,h,u,"#define NUM_SAMPLES "+a)||this;return f._screenCoordinates=e.Vector2.Zero(),f.customMeshPosition=e.Vector3.Zero(),f.useCustomMeshPosition=!1,f.invert=!0,f.excludedMeshes=new Array,f.exposure=.3,f.decay=.96815,f.weight=.58767,f.density=.926,c=null===o?c:o.getScene(),h=c.getEngine(),f._viewPort=new e.Viewport(0,0,1,1).toGlobal(h.getRenderWidth(),h.getRenderHeight()),f.mesh=null!==s?s:i.CreateDefaultMesh("VolumetricLightScatteringMesh",c),f._createPass(c,n.passRatio||n),f.onActivate=function(e){f.isSupported||f.dispose(e),f.onActivate=null},f.onApplyObservable.add(function(e){f._updateMeshScreenCoordinates(c),e.setTexture("lightScatteringSampler",f._volumetricLightScatteringRTT),e.setFloat("exposure",f.exposure),e.setFloat("decay",f.decay),e.setFloat("weight",f.weight),e.setFloat("density",f.density),e.setVector2("meshPositionOnScreen",f._screenCoordinates)}),f}return n(i,t),Object.defineProperty(i.prototype,"useDiffuseColor",{get:function(){return e.Tools.Warn("VolumetricLightScatteringPostProcess.useDiffuseColor is no longer used, use the mesh material directly instead"),!1},set:function(t){e.Tools.Warn("VolumetricLightScatteringPostProcess.useDiffuseColor is no longer used, use the mesh material directly instead")},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"VolumetricLightScatteringPostProcess"},i.prototype.isReady=function(t,i){var r=t.getMesh();if(r===this.mesh&&r.material)return r.material.isReady(r);var n=[],o=[e.VertexBuffer.PositionKind],s=t.getMaterial();s&&(s.needAlphaTesting()&&n.push("#define ALPHATEST"),r.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(o.push(e.VertexBuffer.UVKind),n.push("#define UV1")),r.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(o.push(e.VertexBuffer.UV2Kind),n.push("#define UV2"))),r.useBones&&r.computeBonesUsingShaders?(o.push(e.VertexBuffer.MatricesIndicesKind),o.push(e.VertexBuffer.MatricesWeightsKind),n.push("#define NUM_BONE_INFLUENCERS "+r.numBoneInfluencers),n.push("#define BonesPerMesh "+(r.skeleton?r.skeleton.bones.length+1:0))):n.push("#define NUM_BONE_INFLUENCERS 0"),i&&(n.push("#define INSTANCES"),o.push("world0"),o.push("world1"),o.push("world2"),o.push("world3"));var a=n.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._volumetricLightScatteringPass=r.getScene().getEngine().createEffect({vertexElement:"depth",fragmentElement:"volumetricLightScatteringPass"},o,["world","mBones","viewProjection","diffuseMatrix"],["diffuseSampler"],a)),this._volumetricLightScatteringPass.isReady()},i.prototype.setCustomMeshPosition=function(e){this.customMeshPosition=e},i.prototype.getCustomMeshPosition=function(){return this.customMeshPosition},i.prototype.dispose=function(e){var i=e.getScene().customRenderTargets.indexOf(this._volumetricLightScatteringRTT);-1!==i&&e.getScene().customRenderTargets.splice(i,1),this._volumetricLightScatteringRTT.dispose(),t.prototype.dispose.call(this,e)},i.prototype.getPass=function(){return this._volumetricLightScatteringRTT},i.prototype._meshExcluded=function(e){return this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e)},i.prototype._createPass=function(t,i){var r=this,n=t.getEngine();this._volumetricLightScatteringRTT=new e.RenderTargetTexture("volumetricLightScatteringMap",{width:n.getRenderWidth()*i,height:n.getRenderHeight()*i},t,!1,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT),this._volumetricLightScatteringRTT.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.renderList=null,this._volumetricLightScatteringRTT.renderParticles=!1;var o=this.getCamera();o?o.customRenderTargets.push(this._volumetricLightScatteringRTT):t.customRenderTargets.push(this._volumetricLightScatteringRTT);var s,a=function(t){var i=t.getRenderingMesh();if(!r._meshExcluded(i)){var n=t.getMaterial();if(n){var o=i.getScene(),s=o.getEngine();s.setState(n.backFaceCulling);var a=i._getInstancesRenderList(t._id);if(!a.mustReturn){var l=s.getCaps().instancedArrays&&null!==a.visibleInstances[t._id];if(r.isReady(t,l)){var h=r._volumetricLightScatteringPass;if(i===r.mesh&&(h=t.effect?t.effect:n.getEffect()),s.enableEffect(h),i._bind(t,h,e.Material.TriangleFillMode),i===r.mesh)n.bind(i.getWorldMatrix(),i);else{if(r._volumetricLightScatteringPass.setMatrix("viewProjection",o.getTransformMatrix()),n&&n.needAlphaTesting()){var u=n.getAlphaTestTexture();r._volumetricLightScatteringPass.setTexture("diffuseSampler",u),u&&r._volumetricLightScatteringPass.setMatrix("diffuseMatrix",u.getTextureMatrix())}i.useBones&&i.computeBonesUsingShaders&&i.skeleton&&r._volumetricLightScatteringPass.setMatrices("mBones",i.skeleton.getTransformMatrices(i))}i._processRendering(t,r._volumetricLightScatteringPass,e.Material.TriangleFillMode,a,l,function(e,t){return h.setMatrix("world",t)})}}}}},l=new e.Color4(0,0,0,1);this._volumetricLightScatteringRTT.onBeforeRenderObservable.add(function(){s=t.clearColor,t.clearColor=l}),this._volumetricLightScatteringRTT.onAfterRenderObservable.add(function(){t.clearColor=s}),this._volumetricLightScatteringRTT.customRenderFunction=function(i,r,n,o){var s,l=t.getEngine();if(o.length){for(l.setColorWrite(!1),s=0;s<o.length;s++)a(o.data[s]);l.setColorWrite(!0)}for(s=0;s<i.length;s++)a(i.data[s]);for(l.setAlphaTesting(!0),s=0;s<r.length;s++)a(r.data[s]);if(l.setAlphaTesting(!1),n.length){for(s=0;s<n.length;s++){var h=n.data[s],u=h.getBoundingInfo();u&&t.activeCamera&&(h._alphaIndex=h.getMesh().alphaIndex,h._distanceToCamera=u.boundingSphere.centerWorld.subtract(t.activeCamera.position).length())}var c=n.data.slice(0,n.length);for(c.sort(function(e,t){return e._alphaIndex>t._alphaIndex?1:e._alphaIndex<t._alphaIndex?-1:e._distanceToCamera<t._distanceToCamera?1:e._distanceToCamera>t._distanceToCamera?-1:0}),l.setAlphaMode(e.Engine.ALPHA_COMBINE),s=0;s<c.length;s++)a(c[s]);l.setAlphaMode(e.Engine.ALPHA_DISABLE)}}},i.prototype._updateMeshScreenCoordinates=function(t){var i,r=t.getTransformMatrix();i=this.useCustomMeshPosition?this.customMeshPosition:this.attachedNode?this.attachedNode.position:this.mesh.parent?this.mesh.getAbsolutePosition():this.mesh.position;var n=e.Vector3.Project(i,e.Matrix.Identity(),r,this._viewPort);this._screenCoordinates.x=n.x/this._viewPort.width,this._screenCoordinates.y=n.y/this._viewPort.height,this.invert&&(this._screenCoordinates.y=1-this._screenCoordinates.y)},i.CreateDefaultMesh=function(t,i){var r=e.Mesh.CreatePlane(t,1,i);r.billboardMode=e.AbstractMesh.BILLBOARDMODE_ALL;var n=new e.StandardMaterial(t+"Material",i);return n.emissiveColor=new e.Color3(1,1,1),r.material=n,r},r([e.serializeAsVector3()],i.prototype,"customMeshPosition",void 0),r([e.serialize()],i.prototype,"useCustomMeshPosition",void 0),r([e.serialize()],i.prototype,"invert",void 0),r([e.serializeAsMeshReference()],i.prototype,"mesh",void 0),r([e.serialize()],i.prototype,"excludedMeshes",void 0),r([e.serialize()],i.prototype,"exposure",void 0),r([e.serialize()],i.prototype,"decay",void 0),r([e.serialize()],i.prototype,"weight",void 0),r([e.serialize()],i.prototype,"density",void 0),i}(e.PostProcess);e.VolumetricLightScatteringPostProcess=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l){var h=t.call(this,i,"colorCorrection",null,["colorTable"],n,o,s,a,l)||this;return h._colorTableTexture=new e.Texture(r,o.getScene(),!0,!1,e.Texture.TRILINEAR_SAMPLINGMODE),h._colorTableTexture.anisotropicFilteringLevel=1,h._colorTableTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,h._colorTableTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,h.onApply=function(e){e.setTexture("colorTable",h._colorTableTexture)},h}return n(i,t),i}(e.PostProcess);e.ColorCorrectionPostProcess=t}(s||(s={}));!function(e){var t;!function(e){e[e.Hable=0]="Hable",e[e.Reinhard=1]="Reinhard",e[e.HejiDawson=2]="HejiDawson",e[e.Photographic=3]="Photographic"}(t=e.TonemappingOperator||(e.TonemappingOperator={}));var i=function(i){function r(r,n,o,s,a,l,h){void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE),void 0===h&&(h=e.Engine.TEXTURETYPE_UNSIGNED_INT);var u=i.call(this,r,"tonemap",["_ExposureAdjustment"],null,1,s,a,l,!0,null,h)||this;u._operator=n,u.exposureAdjustment=o;var c="#define ";return u._operator===t.Hable?c+="HABLE_TONEMAPPING":u._operator===t.Reinhard?c+="REINHARD_TONEMAPPING":u._operator===t.HejiDawson?c+="OPTIMIZED_HEJIDAWSON_TONEMAPPING":u._operator===t.Photographic&&(c+="PHOTOGRAPHIC_TONEMAPPING"),u.updateEffect(c),u.onApply=function(e){e.setFloat("_ExposureAdjustment",u.exposureAdjustment)},u}return n(r,i),r}(e.PostProcess);e.TonemapPostProcess=i}(s||(s={}));!function(e){var t=function(e){function t(t,i,r,n,o,s){return e.call(this,t,"displayPass",["passSampler"],["passSampler"],i,r,n,o,s)||this}return n(t,e),t}(e.PostProcess);e.DisplayPassPostProcess=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l){return void 0===l&&(l=e.Engine.TEXTURETYPE_UNSIGNED_INT),t.call(this,i,"highlights",null,null,r,n,o,s,a,null,l)||this}return n(i,t),i}(e.PostProcess);e.HighlightsPostProcess=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l){void 0===n&&(n=null),void 0===l&&(l=e.Engine.TEXTURETYPE_UNSIGNED_INT);var h=t.call(this,i,"imageProcessing",[],[],r,n,o,s,a,null,l,"postprocess",null,!0)||this;return h._fromLinearSpace=!0,h._defines={IMAGEPROCESSING:!1,VIGNETTE:!1,VIGNETTEBLENDMODEMULTIPLY:!1,VIGNETTEBLENDMODEOPAQUE:!1,TONEMAPPING:!1,CONTRAST:!1,COLORCURVES:!1,COLORGRADING:!1,COLORGRADING3D:!1,FROMLINEARSPACE:!1,SAMPLER3DGREENDEPTH:!1,SAMPLER3DBGRMAP:!1,IMAGEPROCESSINGPOSTPROCESS:!1,EXPOSURE:!1},h._attachImageProcessingConfiguration(null,!0),h.imageProcessingConfiguration.applyByPostProcess=!0,h.onApply=function(e){h.imageProcessingConfiguration.bind(e,h.aspectRatio)},h}return n(i,t),Object.defineProperty(i.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},set:function(e){this._attachImageProcessingConfiguration(e)},enumerable:!0,configurable:!0}),i.prototype._attachImageProcessingConfiguration=function(t,i){var r=this;if(void 0===i&&(i=!1),t!==this._imageProcessingConfiguration){if(this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),t)this._imageProcessingConfiguration=t;else{var n=null,o=this.getEngine(),s=this.getCamera();if(s)n=s.getScene();else if(o&&o.scenes){var a=o.scenes;n=a[a.length-1]}else n=e.Engine.LastCreatedScene;this._imageProcessingConfiguration=n.imageProcessingConfiguration}this._imageProcessingObserver=this._imageProcessingConfiguration.onUpdateParameters.add(function(e){r._updateParameters()}),i||this._updateParameters()}},Object.defineProperty(i.prototype,"colorCurves",{get:function(){return this.imageProcessingConfiguration.colorCurves},set:function(e){this.imageProcessingConfiguration.colorCurves=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"colorCurvesEnabled",{get:function(){return this.imageProcessingConfiguration.colorCurvesEnabled},set:function(e){this.imageProcessingConfiguration.colorCurvesEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"colorGradingTexture",{get:function(){return this.imageProcessingConfiguration.colorGradingTexture},set:function(e){this.imageProcessingConfiguration.colorGradingTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"colorGradingEnabled",{get:function(){return this.imageProcessingConfiguration.colorGradingEnabled},set:function(e){this.imageProcessingConfiguration.colorGradingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"exposure",{get:function(){return this.imageProcessingConfiguration.exposure},set:function(e){this.imageProcessingConfiguration.exposure=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"toneMappingEnabled",{get:function(){return this._imageProcessingConfiguration.toneMappingEnabled},set:function(e){this._imageProcessingConfiguration.toneMappingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"contrast",{get:function(){return this.imageProcessingConfiguration.contrast},set:function(e){this.imageProcessingConfiguration.contrast=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"vignetteStretch",{get:function(){return this.imageProcessingConfiguration.vignetteStretch},set:function(e){this.imageProcessingConfiguration.vignetteStretch=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"vignetteCentreX",{get:function(){return this.imageProcessingConfiguration.vignetteCentreX},set:function(e){this.imageProcessingConfiguration.vignetteCentreX=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"vignetteCentreY",{get:function(){return this.imageProcessingConfiguration.vignetteCentreY},set:function(e){this.imageProcessingConfiguration.vignetteCentreY=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"vignetteWeight",{get:function(){return this.imageProcessingConfiguration.vignetteWeight},set:function(e){this.imageProcessingConfiguration.vignetteWeight=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"vignetteColor",{get:function(){return this.imageProcessingConfiguration.vignetteColor},set:function(e){this.imageProcessingConfiguration.vignetteColor=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"vignetteCameraFov",{get:function(){return this.imageProcessingConfiguration.vignetteCameraFov},set:function(e){this.imageProcessingConfiguration.vignetteCameraFov=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"vignetteBlendMode",{get:function(){return this.imageProcessingConfiguration.vignetteBlendMode},set:function(e){this.imageProcessingConfiguration.vignetteBlendMode=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"vignetteEnabled",{get:function(){return this.imageProcessingConfiguration.vignetteEnabled},set:function(e){this.imageProcessingConfiguration.vignetteEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"fromLinearSpace",{get:function(){return this._fromLinearSpace},set:function(e){this._fromLinearSpace!==e&&(this._fromLinearSpace=e,this._updateParameters())},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"ImageProcessingPostProcess"},i.prototype._updateParameters=function(){this._defines.FROMLINEARSPACE=this._fromLinearSpace,this.imageProcessingConfiguration.prepareDefines(this._defines,!0);var t="";for(var i in this._defines)this._defines[i]&&(t+="#define "+i+";\r\n");var r=["textureSampler"];e.ImageProcessingConfiguration.PrepareSamplers(r,this._defines);var n=["scale"];e.ImageProcessingConfiguration.PrepareUniforms(n,this._defines),this.updateEffect(t,n,r)},i.prototype.dispose=function(e){t.prototype.dispose.call(this,e),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),this.imageProcessingConfiguration.applyByPostProcess=!1},r([e.serialize()],i.prototype,"_fromLinearSpace",void 0),i}(e.PostProcess);e.ImageProcessingPostProcess=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l,h,u){void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE),void 0===u&&(u=e.Engine.TEXTURETYPE_UNSIGNED_INT);var c=t.call(this,i,"kernelBlur",["delta","direction"],null,o,s,a,l,h,null,u,"kernelBlur",{varyingCount:0,depCount:0},!0)||this;return c.direction=r,c._packedFloat=!1,c.onApplyObservable.add(function(e){e.setFloat2("delta",1/c.width*c.direction.x,1/c.height*c.direction.y)}),c.kernel=n,c}return n(i,t),Object.defineProperty(i.prototype,"kernel",{get:function(){return this._idealKernel},set:function(e){this._idealKernel!==e&&(e=Math.max(e,1),this._idealKernel=e,this._kernel=this._nearestBestKernel(e),this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"packedFloat",{get:function(){return this._packedFloat},set:function(e){this._packedFloat!==e&&(this._packedFloat=e,this._updateParameters())},enumerable:!0,configurable:!0}),i.prototype._updateParameters=function(){for(var e=this._kernel,t=(e-1)/2,i=[],r=[],n=0,o=0;o<e;o++){var s=o/(e-1),a=this._gaussianWeight(2*s-1);i[o]=o-t,r[o]=a,n+=a}for(o=0;o<r.length;o++)r[o]/=n;for(var l=[],h=[],u=[],o=0;o<=t;o+=2){var c=Math.min(o+1,Math.floor(t));if(o===c)u.push({o:i[o],w:r[o]});else{var f=c===t,p=r[o]+r[c]*(f?.5:1),d=i[o]+1/(1+r[o]/r[c]);0===d?(u.push({o:i[o],w:r[o]}),u.push({o:i[o+1],w:r[o+1]})):(u.push({o:d,w:p}),u.push({o:-d,w:p}))}}for(o=0;o<u.length;o++)h[o]=u[o].o,l[o]=u[o].w;i=h,r=l;for(var m=this.getEngine().getCaps().maxVaryingVectors,g=Math.max(m,0)-1,v=Math.min(i.length,g),_="",o=0;o<v;o++)_+="#define KERNEL_OFFSET"+o+" "+this._glslFloat(i[o])+"\r\n",_+="#define KERNEL_WEIGHT"+o+" "+this._glslFloat(r[o])+"\r\n";for(var y=0,o=g;o<i.length;o++)_+="#define KERNEL_DEP_OFFSET"+y+" "+this._glslFloat(i[o])+"\r\n",_+="#define KERNEL_DEP_WEIGHT"+y+" "+this._glslFloat(r[o])+"\r\n",y++;this.packedFloat&&(_+="#define PACKEDFLOAT 1"),this.updateEffect(_,null,null,{varyingCount:v,depCount:y})},i.prototype._nearestBestKernel=function(e){for(var t=Math.round(e),i=0,r=[t,t-1,t+1,t-2,t+2];i<r.length;i++){var n=r[i];if(n%2!=0&&Math.floor(n/2)%2==0&&n>0)return Math.max(n,3)}return Math.max(t,3)},i.prototype._gaussianWeight=function(e){var t=-e*e/(1/3*2*(1/3));return 1/(Math.sqrt(2*Math.PI)*(1/3))*Math.exp(t)},i.prototype._glslFloat=function(e,t){return void 0===t&&(t=8),e.toFixed(t).replace(/0+$/,"")},i}(e.PostProcess);e.BlurPostProcess=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l){void 0===n&&(n=null),void 0===o&&(o=null),void 0===s&&(s=null),void 0===a&&(a=null),void 0===l&&(l=null);var h=t.call(this,i,r.getScene())||this;return h.name=i,h.children=new Array,h.animations=new Array,h._index=null,h._worldTransform=new e.Matrix,h._absoluteTransform=new e.Matrix,h._invertedAbsoluteTransform=new e.Matrix,h._scaleMatrix=e.Matrix.Identity(),h._scaleVector=e.Vector3.One(),h._negateScaleChildren=e.Vector3.One(),h._scalingDeterminant=1,h._skeleton=r,h._localMatrix=o||e.Matrix.Identity(),h._restPose=s||h._localMatrix.clone(),h._baseMatrix=a||h._localMatrix.clone(),h._index=l,r.bones.push(h),h.setParent(n,!1),h._updateDifferenceMatrix(),h}return n(i,t),Object.defineProperty(i.prototype,"_matrix",{get:function(){return this._localMatrix},set:function(e){this._localMatrix?this._localMatrix.copyFrom(e):this._localMatrix=e},enumerable:!0,configurable:!0}),i.prototype.getSkeleton=function(){return this._skeleton},i.prototype.getParent=function(){return this._parent},i.prototype.setParent=function(e,t){if(void 0===t&&(t=!0),this._parent!==e){if(this._parent){var i=this._parent.children.indexOf(this);-1!==i&&this._parent.children.splice(i,1)}this._parent=e,this._parent&&this._parent.children.push(this),t&&this._updateDifferenceMatrix()}},i.prototype.getLocalMatrix=function(){return this._localMatrix},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},Object.defineProperty(i.prototype,"position",{get:function(){return this.getPosition()},set:function(e){this.setPosition(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"rotation",{get:function(){return this.getRotation()},set:function(e){this.setRotation(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"rotationQuaternion",{get:function(){return this.getRotationQuaternion()},set:function(e){this.setRotationQuaternion(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"scaling",{get:function(){return this.getScale()},set:function(e){this.setScale(e.x,e.y,e.z)},enumerable:!0,configurable:!0}),i.prototype.updateMatrix=function(e,t){void 0===t&&(t=!0),this._baseMatrix=e.clone(),this._localMatrix=e.clone(),this._skeleton._markAsDirty(),t&&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();this._scalingDeterminant=this._absoluteTransform.determinant()<0?-1:1},i.prototype.markAsDirty=function(){this._currentRenderId++,this._skeleton._markAsDirty()},i.prototype.copyAnimationRange=function(t,i,r,n,o){void 0===n&&(n=!1),void 0===o&&(o=null),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 s=t.animations[0].getRange(i);if(!s)return!1;for(var a,l,h,u=s.from,c=s.to,f=t.animations[0].getKeys(),p=t.length,d=t.getParent(),m=this.getParent(),g=n&&d&&p&&this.length&&p!==this.length,v=g&&m&&d?m.length/d.length:1,_=n&&!m&&o&&(1!==o.x||1!==o.y||1!==o.z),y=this.animations[0].getKeys(),x=0,b=f.length;x<b;x++)(a=f[x]).frame>=u&&a.frame<=c&&(n?(h=a.value.clone(),g?(l=h.getTranslation(),h.setTranslation(l.scaleInPlace(v))):_&&o?(l=h.getTranslation(),h.setTranslation(l.multiplyInPlace(o))):h=a.value):h=a.value,y.push({frame:a.frame+r,value:h}));return this.animations[0].createRange(i,u+r,c+r),!0},i.prototype.translate=function(t,r,n){void 0===r&&(r=e.Space.LOCAL);var o=this.getLocalMatrix();if(r==e.Space.LOCAL)o.m[12]+=t.x,o.m[13]+=t.y,o.m[14]+=t.z;else{var s=null;n&&(s=n.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var a=i._tmpMats[0],l=i._tmpVecs[0];this._parent&&(n&&s?(a.copyFrom(this._parent.getAbsoluteTransform()),a.multiplyToRef(s,a)):a.copyFrom(this._parent.getAbsoluteTransform())),a.m[12]=0,a.m[13]=0,a.m[14]=0,a.invert(),e.Vector3.TransformCoordinatesToRef(t,a,l),o.m[12]+=l.x,o.m[13]+=l.y,o.m[14]+=l.z}this.markAsDirty()},i.prototype.setPosition=function(t,r,n){void 0===r&&(r=e.Space.LOCAL);var o=this.getLocalMatrix();if(r==e.Space.LOCAL)o.m[12]=t.x,o.m[13]=t.y,o.m[14]=t.z;else{var s=null;n&&(s=n.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var a=i._tmpMats[0],l=i._tmpVecs[0];this._parent&&(n&&s?(a.copyFrom(this._parent.getAbsoluteTransform()),a.multiplyToRef(s,a)):a.copyFrom(this._parent.getAbsoluteTransform())),a.invert(),e.Vector3.TransformCoordinatesToRef(t,a,l),o.m[12]=l.x,o.m[13]=l.y,o.m[14]=l.z}this.markAsDirty()},i.prototype.setAbsolutePosition=function(t,i){this.setPosition(t,e.Space.WORLD,i)},i.prototype.setScale=function(e,t,i,r){void 0===r&&(r=!1),this.animations[0]&&!this.animations[0].hasRunningRuntimeAnimations&&(r||(this._negateScaleChildren.x=1/e,this._negateScaleChildren.y=1/t,this._negateScaleChildren.z=1/i),this._syncScaleVector()),this.scale(e/this._scaleVector.x,t/this._scaleVector.y,i/this._scaleVector.z,r)},i.prototype.scale=function(t,r,n,o){void 0===o&&(o=!1);var s=this.getLocalMatrix(),a=i._tmpMats[0];a.copyFrom(s);var l=i._tmpMats[1];l.copyFrom(a),l.invert();var h=i._tmpMats[2];e.Matrix.FromValuesToRef(t,0,0,0,0,r,0,0,0,0,n,0,0,0,0,1,h),this._scaleMatrix.multiplyToRef(h,this._scaleMatrix),this._scaleVector.x*=t,this._scaleVector.y*=r,this._scaleVector.z*=n,s.multiplyToRef(l,s),s.multiplyToRef(h,s),s.multiplyToRef(a,s);var u=this.getParent();u?s.multiplyToRef(u.getAbsoluteTransform(),this.getAbsoluteTransform()):this.getAbsoluteTransform().copyFrom(s);var c=this.children.length;h.invert();for(m=0;m<c;m++){var f=this.children[m],p=f.getLocalMatrix();p.multiplyToRef(h,p);var d=f.getLocalMatrix();d.m[12]*=t,d.m[13]*=r,d.m[14]*=n}if(this.computeAbsoluteTransforms(),o)for(var m=0;m<c;m++)this.children[m].scale(t,r,n,o);this.markAsDirty()},i.prototype.setYawPitchRoll=function(t,r,n,o,s){void 0===o&&(o=e.Space.LOCAL);var a=i._tmpMats[0];e.Matrix.RotationYawPitchRollToRef(t,r,n,a);var l=i._tmpMats[1];this._getNegativeRotationToRef(l,o,s),l.multiplyToRef(a,a),this._rotateWithMatrix(a,o,s)},i.prototype.rotate=function(t,r,n,o){void 0===n&&(n=e.Space.LOCAL);var s=i._tmpMats[0];s.m[12]=0,s.m[13]=0,s.m[14]=0,e.Matrix.RotationAxisToRef(t,r,s),this._rotateWithMatrix(s,n,o)},i.prototype.setAxisAngle=function(t,r,n,o){void 0===n&&(n=e.Space.LOCAL);var s=i._tmpMats[0];e.Matrix.RotationAxisToRef(t,r,s);var a=i._tmpMats[1];this._getNegativeRotationToRef(a,n,o),a.multiplyToRef(s,s),this._rotateWithMatrix(s,n,o)},i.prototype.setRotation=function(t,i,r){void 0===i&&(i=e.Space.LOCAL),this.setYawPitchRoll(t.y,t.x,t.z,i,r)},i.prototype.setRotationQuaternion=function(t,r,n){void 0===r&&(r=e.Space.LOCAL);var o=i._tmpMats[0];this._getNegativeRotationToRef(o,r,n);var s=i._tmpMats[1];e.Matrix.FromQuaternionToRef(t,s),o.multiplyToRef(s,s),this._rotateWithMatrix(s,r,n)},i.prototype.setRotationMatrix=function(t,r,n){void 0===r&&(r=e.Space.LOCAL);var o=i._tmpMats[0];this._getNegativeRotationToRef(o,r,n);var s=i._tmpMats[1];s.copyFrom(t),o.multiplyToRef(t,s),this._rotateWithMatrix(s,r,n)},i.prototype._rotateWithMatrix=function(t,r,n){void 0===r&&(r=e.Space.LOCAL);var o=this.getLocalMatrix(),s=o.m[12],a=o.m[13],l=o.m[14],h=this.getParent(),u=i._tmpMats[3],c=i._tmpMats[4];h?(r==e.Space.WORLD?n?(u.copyFrom(n.getWorldMatrix()),h.getAbsoluteTransform().multiplyToRef(u,u)):u.copyFrom(h.getAbsoluteTransform()):u=h._scaleMatrix,c.copyFrom(u),c.invert(),o.multiplyToRef(u,o),o.multiplyToRef(t,o),o.multiplyToRef(c,o)):r==e.Space.WORLD&&n?(u.copyFrom(n.getWorldMatrix()),c.copyFrom(u),c.invert(),o.multiplyToRef(u,o),o.multiplyToRef(t,o),o.multiplyToRef(c,o)):o.multiplyToRef(t,o),o.m[12]=s,o.m[13]=a,o.m[14]=l,this.computeAbsoluteTransforms(),this.markAsDirty()},i.prototype._getNegativeRotationToRef=function(t,r,n){if(void 0===r&&(r=e.Space.LOCAL),r==e.Space.WORLD){if((s=i._tmpMats[2]).copyFrom(this._scaleMatrix),t.copyFrom(this.getAbsoluteTransform()),n){t.multiplyToRef(n.getWorldMatrix(),t);var o=i._tmpMats[3];e.Matrix.ScalingToRef(n.scaling.x,n.scaling.y,n.scaling.z,o),s.multiplyToRef(o,s)}t.invert(),s.m[0]*=this._scalingDeterminant,t.multiplyToRef(s,t)}else{t.copyFrom(this.getLocalMatrix()),t.invert();var s=i._tmpMats[2];if(s.copyFrom(this._scaleMatrix),this._parent){var a=i._tmpMats[3];a.copyFrom(this._parent._scaleMatrix),a.invert(),a.multiplyToRef(t,t)}else s.m[0]*=this._scalingDeterminant;t.multiplyToRef(s,t)}},i.prototype.getScale=function(){return this._scaleVector.clone()},i.prototype.getScaleToRef=function(e){e.copyFrom(this._scaleVector)},i.prototype.getPosition=function(t,i){void 0===t&&(t=e.Space.LOCAL),void 0===i&&(i=null);var r=e.Vector3.Zero();return this.getPositionToRef(t,i,r),r},i.prototype.getPositionToRef=function(t,r,n){if(void 0===t&&(t=e.Space.LOCAL),t==e.Space.LOCAL){var o=this.getLocalMatrix();n.x=o.m[12],n.y=o.m[13],n.z=o.m[14]}else{var s=null;r&&(s=r.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var a=i._tmpMats[0];r&&s?(a.copyFrom(this.getAbsoluteTransform()),a.multiplyToRef(s,a)):a=this.getAbsoluteTransform(),n.x=a.m[12],n.y=a.m[13],n.z=a.m[14]}},i.prototype.getAbsolutePosition=function(t){void 0===t&&(t=null);var i=e.Vector3.Zero();return this.getPositionToRef(e.Space.WORLD,t,i),i},i.prototype.getAbsolutePositionToRef=function(t,i){this.getPositionToRef(e.Space.WORLD,t,i)},i.prototype.computeAbsoluteTransforms=function(){if(this._parent)this._localMatrix.multiplyToRef(this._parent._absoluteTransform,this._absoluteTransform);else{this._absoluteTransform.copyFrom(this._localMatrix);var e=this._skeleton.getPoseMatrix();e&&this._absoluteTransform.multiplyToRef(e,this._absoluteTransform)}for(var t=this.children,i=t.length,r=0;r<i;r++)t[r].computeAbsoluteTransforms()},i.prototype._syncScaleVector=function(){var t=this.getLocalMatrix(),i=t.m[0]*t.m[0]+t.m[1]*t.m[1]+t.m[2]*t.m[2],r=t.m[4]*t.m[4]+t.m[5]*t.m[5]+t.m[6]*t.m[6],n=t.m[8]*t.m[8]+t.m[9]*t.m[9]+t.m[10]*t.m[10],o=t.m[0]*t.m[1]*t.m[2]*t.m[3]<0?-1:1,s=t.m[4]*t.m[5]*t.m[6]*t.m[7]<0?-1:1,a=t.m[8]*t.m[9]*t.m[10]*t.m[11]<0?-1:1;this._scaleVector.x=o*Math.sqrt(i),this._scaleVector.y=s*Math.sqrt(r),this._scaleVector.z=a*Math.sqrt(n),this._parent&&(this._scaleVector.x/=this._parent._negateScaleChildren.x,this._scaleVector.y/=this._parent._negateScaleChildren.y,this._scaleVector.z/=this._parent._negateScaleChildren.z),e.Matrix.FromValuesToRef(this._scaleVector.x,0,0,0,0,this._scaleVector.y,0,0,0,0,this._scaleVector.z,0,0,0,0,1,this._scaleMatrix)},i.prototype.getDirection=function(t,i){void 0===i&&(i=null);var r=e.Vector3.Zero();return this.getDirectionToRef(t,i,r),r},i.prototype.getDirectionToRef=function(t,r,n){void 0===r&&(r=null);var o=null;r&&(o=r.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var s=i._tmpMats[0];s.copyFrom(this.getAbsoluteTransform()),r&&o&&s.multiplyToRef(o,s),e.Vector3.TransformNormalToRef(t,s,n),n.normalize()},i.prototype.getRotation=function(t,i){void 0===t&&(t=e.Space.LOCAL),void 0===i&&(i=null);var r=e.Vector3.Zero();return this.getRotationToRef(t,i,r),r},i.prototype.getRotationToRef=function(t,r,n){void 0===t&&(t=e.Space.LOCAL),void 0===r&&(r=null);var o=i._tmpQuat;this.getRotationQuaternionToRef(t,r,o),o.toEulerAnglesToRef(n)},i.prototype.getRotationQuaternion=function(t,i){void 0===t&&(t=e.Space.LOCAL),void 0===i&&(i=null);var r=e.Quaternion.Identity();return this.getRotationQuaternionToRef(t,i,r),r},i.prototype.getRotationQuaternionToRef=function(t,r,n){if(void 0===t&&(t=e.Space.LOCAL),void 0===r&&(r=null),t==e.Space.LOCAL)this.getLocalMatrix().decompose(i._tmpVecs[0],n,i._tmpVecs[1]);else{var o=i._tmpMats[0],s=this.getAbsoluteTransform();r?s.multiplyToRef(r.getWorldMatrix(),o):o.copyFrom(s),o.m[0]*=this._scalingDeterminant,o.m[1]*=this._scalingDeterminant,o.m[2]*=this._scalingDeterminant,o.decompose(i._tmpVecs[0],n,i._tmpVecs[1])}},i.prototype.getRotationMatrix=function(t,i){void 0===t&&(t=e.Space.LOCAL);var r=e.Matrix.Identity();return this.getRotationMatrixToRef(t,i,r),r},i.prototype.getRotationMatrixToRef=function(t,r,n){if(void 0===t&&(t=e.Space.LOCAL),t==e.Space.LOCAL)this.getLocalMatrix().getRotationMatrixToRef(n);else{var o=i._tmpMats[0],s=this.getAbsoluteTransform();r?s.multiplyToRef(r.getWorldMatrix(),o):o.copyFrom(s),o.m[0]*=this._scalingDeterminant,o.m[1]*=this._scalingDeterminant,o.m[2]*=this._scalingDeterminant,o.getRotationMatrixToRef(n)}},i.prototype.getAbsolutePositionFromLocal=function(t,i){void 0===i&&(i=null);var r=e.Vector3.Zero();return this.getAbsolutePositionFromLocalToRef(t,i,r),r},i.prototype.getAbsolutePositionFromLocalToRef=function(t,r,n){void 0===r&&(r=null);var o=null;r&&(o=r.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var s=i._tmpMats[0];r&&o?(s.copyFrom(this.getAbsoluteTransform()),s.multiplyToRef(o,s)):s=this.getAbsoluteTransform(),e.Vector3.TransformCoordinatesToRef(t,s,n)},i.prototype.getLocalPositionFromAbsolute=function(t,i){void 0===i&&(i=null);var r=e.Vector3.Zero();return this.getLocalPositionFromAbsoluteToRef(t,i,r),r},i.prototype.getLocalPositionFromAbsoluteToRef=function(t,r,n){void 0===r&&(r=null);var o=null;r&&(o=r.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var s=i._tmpMats[0];s.copyFrom(this.getAbsoluteTransform()),r&&o&&s.multiplyToRef(o,s),s.invert(),e.Vector3.TransformCoordinatesToRef(t,s,n)},i._tmpVecs=[e.Vector3.Zero(),e.Vector3.Zero()],i._tmpQuat=e.Quaternion.Identity(),i._tmpMats=[e.Matrix.Identity(),e.Matrix.Identity(),e.Matrix.Identity(),e.Matrix.Identity(),e.Matrix.Identity()],i}(e.Node);e.Bone=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r){if(this.targetPosition=e.Vector3.Zero(),this.poleTargetPosition=e.Vector3.Zero(),this.poleTargetLocalOffset=e.Vector3.Zero(),this.poleAngle=0,this.slerpAmount=1,this._bone1Quat=e.Quaternion.Identity(),this._bone1Mat=e.Matrix.Identity(),this._bone2Ang=Math.PI,this._maxAngle=Math.PI,this._rightHandedSystem=!1,this._bendAxis=e.Vector3.Right(),this._slerping=!1,this._adjustRoll=0,this._bone2=i,this._bone1=i.getParent(),this._bone1){this.mesh=t;var n=i.getPosition();if(i.getAbsoluteTransform().determinant()>0&&(this._rightHandedSystem=!0,this._bendAxis.x=0,this._bendAxis.y=0,this._bendAxis.z=-1,n.x>n.y&&n.x>n.z&&(this._adjustRoll=.5*Math.PI,this._bendAxis.z=1)),this._bone1.length){var o=this._bone1.getScale(),s=this._bone2.getScale();this._bone1Length=this._bone1.length*o.y*this.mesh.scaling.y,this._bone2Length=this._bone2.length*s.y*this.mesh.scaling.y}else if(this._bone1.children[0]){t.computeWorldMatrix(!0);var a=this._bone2.children[0].getAbsolutePosition(t),l=this._bone2.getAbsolutePosition(t),h=this._bone1.getAbsolutePosition(t);this._bone1Length=e.Vector3.Distance(a,l),this._bone2Length=e.Vector3.Distance(l,h)}this._bone1.getRotationMatrixToRef(e.Space.WORLD,t,this._bone1Mat),this.maxAngle=Math.PI,r&&(r.targetMesh&&(this.targetMesh=r.targetMesh,this.targetMesh.computeWorldMatrix(!0)),r.poleTargetMesh?(this.poleTargetMesh=r.poleTargetMesh,this.poleTargetMesh.computeWorldMatrix(!0)):r.poleTargetBone?this.poleTargetBone=r.poleTargetBone:this._bone1.getParent()&&(this.poleTargetBone=this._bone1.getParent()),r.poleTargetLocalOffset&&this.poleTargetLocalOffset.copyFrom(r.poleTargetLocalOffset),r.poleAngle&&(this.poleAngle=r.poleAngle),r.bendAxis&&this._bendAxis.copyFrom(r.bendAxis),r.maxAngle&&(this.maxAngle=r.maxAngle),r.slerpAmount&&(this.slerpAmount=r.slerpAmount))}}return Object.defineProperty(t.prototype,"maxAngle",{get:function(){return this._maxAngle},set:function(e){this._setMaxAngle(e)},enumerable:!0,configurable:!0}),t.prototype._setMaxAngle=function(e){e<0&&(e=0),(e>Math.PI||void 0==e)&&(e=Math.PI),this._maxAngle=e;var t=this._bone1Length,i=this._bone2Length;this._maxReach=Math.sqrt(t*t+i*i-2*t*i*Math.cos(e))},t.prototype.update=function(){var i=this._bone1;if(i){var r=this.targetPosition,n=this.poleTargetPosition,o=t._tmpMats[0],s=t._tmpMats[1];this.targetMesh&&r.copyFrom(this.targetMesh.getAbsolutePosition()),this.poleTargetBone?this.poleTargetBone.getAbsolutePositionFromLocalToRef(this.poleTargetLocalOffset,this.mesh,n):this.poleTargetMesh&&e.Vector3.TransformCoordinatesToRef(this.poleTargetLocalOffset,this.poleTargetMesh.getWorldMatrix(),n);var a=t._tmpVecs[0],l=t._tmpVecs[1],h=t._tmpVecs[2],u=t._tmpVecs[3],c=t._tmpVecs[4],f=t._tmpQuat;i.getAbsolutePositionToRef(this.mesh,a),n.subtractToRef(a,c),0==c.x&&0==c.y&&0==c.z?c.y=1:c.normalize(),r.subtractToRef(a,u),u.normalize(),e.Vector3.CrossToRef(u,c,l),l.normalize(),e.Vector3.CrossToRef(u,l,h),h.normalize(),e.Matrix.FromXYZAxesToRef(h,u,l,o);var p=this._bone1Length,d=this._bone2Length,m=e.Vector3.Distance(a,r);this._maxReach>0&&(m=Math.min(this._maxReach,m));var g=(d*d+m*m-p*p)/(2*d*m),v=(m*m+p*p-d*d)/(2*m*p);g>1&&(g=1),v>1&&(v=1),g<-1&&(g=-1),v<-1&&(v=-1);var _=Math.acos(g),y=Math.acos(v),x=-_-y;if(this._rightHandedSystem)e.Matrix.RotationYawPitchRollToRef(0,0,this._adjustRoll,s),s.multiplyToRef(o,o),e.Matrix.RotationAxisToRef(this._bendAxis,y,s),s.multiplyToRef(o,o);else{var b=t._tmpVecs[5];b.copyFrom(this._bendAxis),b.x*=-1,e.Matrix.RotationAxisToRef(b,-y,s),s.multiplyToRef(o,o)}this.poleAngle&&(e.Matrix.RotationAxisToRef(u,this.poleAngle,s),o.multiplyToRef(s,o)),this._bone1&&(this.slerpAmount<1?(this._slerping||e.Quaternion.FromRotationMatrixToRef(this._bone1Mat,this._bone1Quat),e.Quaternion.FromRotationMatrixToRef(o,f),e.Quaternion.SlerpToRef(this._bone1Quat,f,this.slerpAmount,this._bone1Quat),x=this._bone2Ang*(1-this.slerpAmount)+x*this.slerpAmount,this._bone1.setRotationQuaternion(this._bone1Quat,e.Space.WORLD,this.mesh),this._slerping=!0):(this._bone1.setRotationMatrix(o,e.Space.WORLD,this.mesh),this._bone1Mat.copyFrom(o),this._slerping=!1)),this._bone2.setAxisAngle(this._bendAxis,x,e.Space.LOCAL),this._bone2Ang=x}},t._tmpVecs=[e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero()],t._tmpQuat=e.Quaternion.Identity(),t._tmpMats=[e.Matrix.Identity(),e.Matrix.Identity()],t}();e.BoneIKController=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n){if(this.upAxis=e.Vector3.Up(),this.upAxisSpace=e.Space.LOCAL,this.adjustYaw=0,this.adjustPitch=0,this.adjustRoll=0,this.slerpAmount=1,this._boneQuat=e.Quaternion.Identity(),this._slerping=!1,this._firstFrameSkipped=!1,this._fowardAxis=e.Vector3.Forward(),this.mesh=t,this.bone=i,this.target=r,n&&(n.adjustYaw&&(this.adjustYaw=n.adjustYaw),n.adjustPitch&&(this.adjustPitch=n.adjustPitch),n.adjustRoll&&(this.adjustRoll=n.adjustRoll),null!=n.maxYaw?this.maxYaw=n.maxYaw:this.maxYaw=Math.PI,null!=n.minYaw?this.minYaw=n.minYaw:this.minYaw=-Math.PI,null!=n.maxPitch?this.maxPitch=n.maxPitch:this.maxPitch=Math.PI,null!=n.minPitch?this.minPitch=n.minPitch:this.minPitch=-Math.PI,null!=n.slerpAmount&&(this.slerpAmount=n.slerpAmount),null!=n.upAxis&&(this.upAxis=n.upAxis),null!=n.upAxisSpace&&(this.upAxisSpace=n.upAxisSpace),null!=n.yawAxis||null!=n.pitchAxis)){var o=e.Axis.Y,s=e.Axis.X;null!=n.yawAxis&&(o=n.yawAxis.clone()).normalize(),null!=n.pitchAxis&&(s=n.pitchAxis.clone()).normalize();var a=e.Vector3.Cross(s,o);this._transformYawPitch=e.Matrix.Identity(),e.Matrix.FromXYZAxesToRef(s,o,a,this._transformYawPitch),this._transformYawPitchInv=this._transformYawPitch.clone(),this._transformYawPitch.invert()}i.getParent()||this.upAxisSpace!=e.Space.BONE||(this.upAxisSpace=e.Space.LOCAL)}return Object.defineProperty(t.prototype,"minYaw",{get:function(){return this._minYaw},set:function(e){this._minYaw=e,this._minYawSin=Math.sin(e),this._minYawCos=Math.cos(e),null!=this._maxYaw&&(this._midYawConstraint=.5*this._getAngleDiff(this._minYaw,this._maxYaw)+this._minYaw,this._yawRange=this._maxYaw-this._minYaw)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxYaw",{get:function(){return this._maxYaw},set:function(e){this._maxYaw=e,this._maxYawSin=Math.sin(e),this._maxYawCos=Math.cos(e),null!=this._minYaw&&(this._midYawConstraint=.5*this._getAngleDiff(this._minYaw,this._maxYaw)+this._minYaw,this._yawRange=this._maxYaw-this._minYaw)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"minPitch",{get:function(){return this._minPitch},set:function(e){this._minPitch=e,this._minPitchTan=Math.tan(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxPitch",{get:function(){return this._maxPitch},set:function(e){this._maxPitch=e,this._maxPitchTan=Math.tan(e)},enumerable:!0,configurable:!0}),t.prototype.update=function(){if(this.slerpAmount<1&&!this._firstFrameSkipped)this._firstFrameSkipped=!0;else{var i=this.bone,r=t._tmpVecs[0];i.getAbsolutePositionToRef(this.mesh,r);var n=this.target,o=t._tmpMats[0],s=t._tmpMats[1],a=this.mesh,l=i.getParent(),h=t._tmpVecs[1];h.copyFrom(this.upAxis),this.upAxisSpace==e.Space.BONE&&l?(this._transformYawPitch&&e.Vector3.TransformCoordinatesToRef(h,this._transformYawPitchInv,h),l.getDirectionToRef(h,this.mesh,h)):this.upAxisSpace==e.Space.LOCAL&&(a.getDirectionToRef(h,h),1==a.scaling.x&&1==a.scaling.y&&1==a.scaling.z||h.normalize());var u=!1,c=!1;if(this._maxYaw==Math.PI&&this._minYaw==-Math.PI||(u=!0),this._maxPitch==Math.PI&&this._minPitch==-Math.PI||(c=!0),u||c){var f=t._tmpMats[2],p=t._tmpMats[3];if(this.upAxisSpace==e.Space.BONE&&1==h.y&&l)l.getRotationMatrixToRef(e.Space.WORLD,this.mesh,f);else if(this.upAxisSpace!=e.Space.LOCAL||1!=h.y||l){(m=t._tmpVecs[2]).copyFrom(this._fowardAxis),this._transformYawPitch&&e.Vector3.TransformCoordinatesToRef(m,this._transformYawPitchInv,m),l?l.getDirectionToRef(m,this.mesh,m):a.getDirectionToRef(m,m);var d=e.Vector3.Cross(h,m);d.normalize();var m=e.Vector3.Cross(d,h);e.Matrix.FromXYZAxesToRef(d,h,m,f)}else f.copyFrom(a.getWorldMatrix());f.invertToRef(p);var g=null;if(c){y=t._tmpVecs[3];n.subtractToRef(r,y),e.Vector3.TransformCoordinatesToRef(y,p,y),g=Math.sqrt(y.x*y.x+y.z*y.z);var v=Math.atan2(y.y,g),_=v;v>this._maxPitch?(y.y=this._maxPitchTan*g,_=this._maxPitch):v<this._minPitch&&(y.y=this._minPitchTan*g,_=this._minPitch),v!=_&&(e.Vector3.TransformCoordinatesToRef(y,f,y),y.addInPlace(r),n=y)}if(u){var y=t._tmpVecs[4];n.subtractToRef(r,y),e.Vector3.TransformCoordinatesToRef(y,p,y);var x=Math.atan2(y.x,y.z),b=x;if((x>this._maxYaw||x<this._minYaw)&&(null==g&&(g=Math.sqrt(y.x*y.x+y.z*y.z)),this._yawRange>Math.PI?this._isAngleBetween(x,this._maxYaw,this._midYawConstraint)?(y.z=this._maxYawCos*g,y.x=this._maxYawSin*g,b=this._maxYaw):this._isAngleBetween(x,this._midYawConstraint,this._minYaw)&&(y.z=this._minYawCos*g,y.x=this._minYawSin*g,b=this._minYaw):x>this._maxYaw?(y.z=this._maxYawCos*g,y.x=this._maxYawSin*g,b=this._maxYaw):x<this._minYaw&&(y.z=this._minYawCos*g,y.x=this._minYawSin*g,b=this._minYaw)),this._slerping&&this._yawRange>Math.PI){var T=t._tmpVecs[8];T.copyFrom(e.Axis.Z),this._transformYawPitch&&e.Vector3.TransformCoordinatesToRef(T,this._transformYawPitchInv,T);var E=e.BoneLookController._tmpMats[4];this._boneQuat.toRotationMatrix(E),this.mesh.getWorldMatrix().multiplyToRef(E,E),e.Vector3.TransformCoordinatesToRef(T,E,T),e.Vector3.TransformCoordinatesToRef(T,p,T);var A=Math.atan2(T.x,T.z);if(this._getAngleBetween(A,x)>this._getAngleBetween(A,this._midYawConstraint)){null==g&&(g=Math.sqrt(y.x*y.x+y.z*y.z));var P=this._getAngleBetween(A,this._maxYaw);this._getAngleBetween(A,this._minYaw)<P?(b=A+.75*Math.PI,y.z=Math.cos(b)*g,y.x=Math.sin(b)*g):(b=A-.75*Math.PI,y.z=Math.cos(b)*g,y.x=Math.sin(b)*g)}}x!=b&&(e.Vector3.TransformCoordinatesToRef(y,f,y),y.addInPlace(r),n=y)}}var S=t._tmpVecs[5],M=t._tmpVecs[6],C=t._tmpVecs[7],R=t._tmpQuat;n.subtractToRef(r,S),S.normalize(),e.Vector3.CrossToRef(h,S,M),M.normalize(),e.Vector3.CrossToRef(S,M,C),C.normalize(),e.Matrix.FromXYZAxesToRef(M,C,S,o),0===M.x&&0===M.y&&0===M.z||0===C.x&&0===C.y&&0===C.z||0===S.x&&0===S.y&&0===S.z||((this.adjustYaw||this.adjustPitch||this.adjustRoll)&&(e.Matrix.RotationYawPitchRollToRef(this.adjustYaw,this.adjustPitch,this.adjustRoll,s),s.multiplyToRef(o,o)),this.slerpAmount<1?(this._slerping||this.bone.getRotationQuaternionToRef(e.Space.WORLD,this.mesh,this._boneQuat),this._transformYawPitch&&this._transformYawPitch.multiplyToRef(o,o),e.Quaternion.FromRotationMatrixToRef(o,R),e.Quaternion.SlerpToRef(this._boneQuat,R,this.slerpAmount,this._boneQuat),this.bone.setRotationQuaternion(this._boneQuat,e.Space.WORLD,this.mesh),this._slerping=!0):(this._transformYawPitch&&this._transformYawPitch.multiplyToRef(o,o),this.bone.setRotationMatrix(o,e.Space.WORLD,this.mesh),this._slerping=!1))}},t.prototype._getAngleDiff=function(e,t){var i=t-e;return(i%=2*Math.PI)>Math.PI?i-=2*Math.PI:i<-Math.PI&&(i+=2*Math.PI),i},t.prototype._getAngleBetween=function(e,t){var i=0;return(i=(e=(e%=2*Math.PI)<0?e+2*Math.PI:e)<(t=(t%=2*Math.PI)<0?t+2*Math.PI:t)?t-e:e-t)>Math.PI&&(i=2*Math.PI-i),i},t.prototype._isAngleBetween=function(e,t,i){if(e%=2*Math.PI,e=e<0?e+2*Math.PI:e,t%=2*Math.PI,t=t<0?t+2*Math.PI:t,i%=2*Math.PI,i=i<0?i+2*Math.PI:i,t<i){if(e>t&&e<i)return!0}else if(e>i&&e<t)return!0;return!1},t._tmpVecs=[e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero()],t._tmpQuat=e.Quaternion.Identity(),t._tmpMats=[e.Matrix.Identity(),e.Matrix.Identity(),e.Matrix.Identity(),e.Matrix.Identity(),e.Matrix.Identity()],t}();e.BoneLookController=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r){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._lastAbsoluteTransformsUpdateId=-1,this.onBeforeComputeObservable=new e.Observable,this.bones=[],this._scene=r||e.Engine.LastCreatedScene,r.skeletons.push(this),this._isDirty=!0}return t.prototype.getTransformMatrices=function(e){return this.needInitialSkinMatrix&&e._bonesTransformMatrices?e._bonesTransformMatrices:(this._transformMatrices||this.prepare(),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 r in this._ranges)i&&(t+=", ",i=!1),t+=r;t+="}"}return t},t.prototype.getBoneIndexByName=function(e){for(var t=0,i=this.bones.length;t<i;t++)if(this.bones[t].name===e)return t;return-1},t.prototype.createAnimationRange=function(t,i,r){if(!this._ranges[t]){this._ranges[t]=new e.AnimationRange(t,i,r);for(var n=0,o=this.bones.length;n<o;n++)this.bones[n].animations[0]&&this.bones[n].animations[0].createRange(t,i,r)}},t.prototype.deleteAnimationRange=function(e,t){void 0===t&&(t=!0);for(var i=0,r=this.bones.length;i<r;i++)this.bones[i].animations[0]&&this.bones[i].animations[0].deleteRange(e,t);this._ranges[e]=null},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,r){if(void 0===r&&(r=!1),this._ranges[i]||!t.getAnimationRange(i))return!1;var n,o,s=!0,a=this._getHighestAnimationFrame()+1,l={},h=t.bones;for(o=0,n=h.length;o<n;o++)l[h[o].name]=h[o];this.bones.length!==h.length&&(e.Tools.Warn("copyAnimationRange: this rig has "+this.bones.length+" bones, while source as "+h.length),s=!1);var u=r&&this.dimensionsAtRest&&t.dimensionsAtRest?this.dimensionsAtRest.divide(t.dimensionsAtRest):null;for(o=0,n=this.bones.length;o<n;o++){var c=this.bones[o].name,f=l[c];f?s=s&&this.bones[o].copyAnimationRange(f,i,a,r,u):(e.Tools.Warn("copyAnimationRange: not same rig, missing source bone "+c),s=!1)}var p=t.getAnimationRange(i);return p&&(this._ranges[i]=new e.AnimationRange(i,p.from+a,p.to+a)),s},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;t<i;t++)if(this.bones[t].animations[0]){var r=this.bones[t].animations[0].getHighestFrame();e<r&&(e=r)}return e},t.prototype.beginAnimation=function(e,t,i,r){var n=this.getAnimationRange(e);return n?this._scene.beginAnimation(this,n.from,n.to,t,i,r):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){this.onBeforeComputeObservable.notifyObservers(this);for(var i=0;i<this.bones.length;i++){var r=this.bones[i],n=r.getParent();if(n?r.getLocalMatrix().multiplyToRef(n.getWorldMatrix(),r.getWorldMatrix()):t?r.getLocalMatrix().multiplyToRef(t,r.getWorldMatrix()):r.getWorldMatrix().copyFrom(r.getLocalMatrix()),-1!==r._index){var o=null===r._index?i:r._index;r.getInvertedAbsoluteTransform().multiplyToArray(r.getWorldMatrix(),e,16*o)}}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],r=i.getPoseMatrix();if(i._bonesTransformMatrices&&i._bonesTransformMatrices.length===16*(this.bones.length+1)||(i._bonesTransformMatrices=new Float32Array(16*(this.bones.length+1))),this._synchronizedWithMesh!==i){this._synchronizedWithMesh=i;for(var n=0;n<this.bones.length;n++){var o=this.bones[n];o.getParent()||(o.getBaseMatrix().multiplyToRef(r,e.Tmp.Matrix[1]),o._updateDifferenceMatrix(e.Tmp.Matrix[1]))}}this._computeTransformMatrices(i._bonesTransformMatrices,r)}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.addCount(this.bones.length,!1)}},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,r){var n=new t(i,r||i,this._scene);n.needInitialSkinMatrix=this.needInitialSkinMatrix;for(var o=0;o<this.bones.length;o++){var s=this.bones[o],a=null,l=s.getParent();if(l){var h=this.bones.indexOf(l);a=n.bones[h]}var u=new e.Bone(s.name,n,a,s.getBaseMatrix().clone(),s.getRestPose().clone());e.Tools.DeepCopy(s.animations,u.animations)}if(this._ranges){n._ranges={};for(var c in this._ranges){var f=this._ranges[c];f&&(n._ranges[c]=f.clone())}}return this._isDirty=!0,n},t.prototype.enableBlending=function(e){void 0===e&&(e=.01),this.bones.forEach(function(t){t.animations.forEach(function(t){t.enableBlending=!0,t.blendingSpeed=e})})},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.dimensionsAtRest=this.dimensionsAtRest,e.bones=[],e.needInitialSkinMatrix=this.needInitialSkinMatrix;for(var t=0;t<this.bones.length;t++){var i=this.bones[t],r=i.getParent(),n={parentBoneIndex:r?this.bones.indexOf(r):-1,name:i.name,matrix:i.getBaseMatrix().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 o in this._ranges){var s=this._ranges[o];if(s){var a={};a.name=o,a.from=s.from,a.to=s.to,e.ranges.push(a)}}}return e},t.Parse=function(i,r){var n=new t(i.name,i.id,r);i.dimensionsAtRest&&(n.dimensionsAtRest=e.Vector3.FromArray(i.dimensionsAtRest)),n.needInitialSkinMatrix=i.needInitialSkinMatrix;var o;for(o=0;o<i.bones.length;o++){var s=i.bones[o],a=null;s.parentBoneIndex>-1&&(a=n.bones[s.parentBoneIndex]);var l=s.rest?e.Matrix.FromArray(s.rest):null,h=new e.Bone(s.name,n,a,e.Matrix.FromArray(s.matrix),l);s.length&&(h.length=s.length),s.animation&&h.animations.push(e.Animation.Parse(s.animation))}if(i.ranges)for(o=0;o<i.ranges.length;o++){var u=i.ranges[o];n.createAnimationRange(u.name,u.from,u.to)}return n},t.prototype.computeAbsoluteTransforms=function(e){void 0===e&&(e=!1);var t=this._scene.getRenderId();(this._lastAbsoluteTransformsUpdateId!=t||e)&&(this.bones[0].computeAbsoluteTransforms(),this._lastAbsoluteTransformsUpdateId=t)},t.prototype.getPoseMatrix=function(){var e=null;return this._meshesWithPoseMatrix.length>0&&(e=this._meshesWithPoseMatrix[0].getPoseMatrix()),e},t.prototype.sortBones=function(){for(var e=new Array,t=new Array(this.bones.length),i=0;i<this.bones.length;i++)this._sortBones(i,e,t);this.bones=e},t.prototype._sortBones=function(e,t,i){if(!i[e]){i[e]=!0;var r=this.bones[e];void 0===r._index&&(r._index=e);var n=r.getParent();n&&this._sortBones(this.bones.indexOf(n),t,i),t.push(r)}},t}();e.Skeleton=t}(s||(s={}));!function(e){var t=function(){function t(){this.x=e.Vector3.Zero(),this.y=e.Vector3.Zero(),this.z=e.Vector3.Zero(),this.xx=e.Vector3.Zero(),this.yy=e.Vector3.Zero(),this.zz=e.Vector3.Zero(),this.xy=e.Vector3.Zero(),this.yz=e.Vector3.Zero(),this.zx=e.Vector3.Zero()}return t.prototype.addAmbient=function(t){var i=new e.Vector3(t.r,t.g,t.b);this.xx=this.xx.add(i),this.yy=this.yy.add(i),this.zz=this.zz.add(i)},t.getSphericalPolynomialFromHarmonics=function(e){var i=new t;return i.x=e.L11.scale(1.02333),i.y=e.L1_1.scale(1.02333),i.z=e.L10.scale(1.02333),i.xx=e.L00.scale(.886277).subtract(e.L20.scale(.247708)).add(e.L22.scale(.429043)),i.yy=e.L00.scale(.886277).subtract(e.L20.scale(.247708)).subtract(e.L22.scale(.429043)),i.zz=e.L00.scale(.886277).add(e.L20.scale(.495417)),i.yz=e.L2_1.scale(.858086),i.zx=e.L21.scale(.858086),i.xy=e.L2_2.scale(.858086),i.scale(1/Math.PI),i},t.prototype.scale=function(e){this.x=this.x.scale(e),this.y=this.y.scale(e),this.z=this.z.scale(e),this.xx=this.xx.scale(e),this.yy=this.yy.scale(e),this.zz=this.zz.scale(e),this.yz=this.yz.scale(e),this.zx=this.zx.scale(e),this.xy=this.xy.scale(e)},t}();e.SphericalPolynomial=t;var i=function(){function t(){this.L00=e.Vector3.Zero(),this.L1_1=e.Vector3.Zero(),this.L10=e.Vector3.Zero(),this.L11=e.Vector3.Zero(),this.L2_2=e.Vector3.Zero(),this.L2_1=e.Vector3.Zero(),this.L20=e.Vector3.Zero(),this.L21=e.Vector3.Zero(),this.L22=e.Vector3.Zero()}return t.prototype.addLight=function(t,i,r){var n=new e.Vector3(i.r,i.g,i.b).scale(r);this.L00=this.L00.add(n.scale(.282095)),this.L1_1=this.L1_1.add(n.scale(.488603*t.y)),this.L10=this.L10.add(n.scale(.488603*t.z)),this.L11=this.L11.add(n.scale(.488603*t.x)),this.L2_2=this.L2_2.add(n.scale(1.092548*t.x*t.y)),this.L2_1=this.L2_1.add(n.scale(1.092548*t.y*t.z)),this.L21=this.L21.add(n.scale(1.092548*t.x*t.z)),this.L20=this.L20.add(n.scale(.315392*(3*t.z*t.z-1))),this.L22=this.L22.add(n.scale(.546274*(t.x*t.x-t.y*t.y)))},t.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)},t.prototype.convertIncidentRadianceToIrradiance=function(){this.L00=this.L00.scale(3.141593),this.L1_1=this.L1_1.scale(2.094395),this.L10=this.L10.scale(2.094395),this.L11=this.L11.scale(2.094395),this.L2_2=this.L2_2.scale(.785398),this.L2_1=this.L2_1.scale(.785398),this.L20=this.L20.scale(.785398),this.L21=this.L21.scale(.785398),this.L22=this.L22.scale(.785398)},t.prototype.convertIrradianceToLambertianRadiance=function(){this.scale(1/Math.PI)},t.getsphericalHarmonicsFromPolynomial=function(e){var i=new t;return i.L00=e.xx.scale(.376127).add(e.yy.scale(.376127)).add(e.zz.scale(.376126)),i.L1_1=e.y.scale(.977204),i.L10=e.z.scale(.977204),i.L11=e.x.scale(.977204),i.L2_2=e.xy.scale(1.16538),i.L2_1=e.yz.scale(1.16538),i.L20=e.zz.scale(1.34567).subtract(e.xx.scale(.672834)).subtract(e.yy.scale(.672834)),i.L21=e.zx.scale(1.16538),i.L22=e.xx.scale(1.16538).subtract(e.yy.scale(1.16538)),i.scale(Math.PI),i},t}();e.SphericalHarmonics=i}(s||(s={}));!function(e){!function(t){var i=function(){return function(e,t,i,r){this.name=e,this.worldAxisForNormal=t,this.worldAxisForFileX=i,this.worldAxisForFileY=r}}(),r=function(){function t(){}return t.ConvertCubeMapTextureToSphericalPolynomial=function(t){if(!t.isCube)return null;var i,r,n=t.getSize().width,o=t.readPixels(0),s=t.readPixels(1);t.isRenderTarget?(i=t.readPixels(3),r=t.readPixels(2)):(i=t.readPixels(2),r=t.readPixels(3));var a=t.readPixels(4),l=t.readPixels(5),h=t.gammaSpace,u=e.Engine.TEXTUREFORMAT_RGBA,c=e.Engine.TEXTURETYPE_UNSIGNED_INT;t.textureType&&t.textureType!==e.Engine.TEXTURETYPE_UNSIGNED_INT&&(c=e.Engine.TEXTURETYPE_FLOAT);var f={size:n,right:o,left:s,up:i,down:r,front:a,back:l,format:u,type:c,gammaSpace:h};return this.ConvertCubeMapToSphericalPolynomial(f)},t.ConvertCubeMapToSphericalPolynomial=function(t){for(var i=new e.SphericalHarmonics,r=0,n=2/t.size,o=n,s=.5*n-1,a=0;a<6;a++)for(var l=this.FileFaces[a],h=t[l.name],u=s,c=t.format===e.Engine.TEXTUREFORMAT_RGBA?4:3,f=0;f<t.size;f++){for(var p=s,d=0;d<t.size;d++){var m=l.worldAxisForFileX.scale(p).add(l.worldAxisForFileY.scale(u)).add(l.worldAxisForNormal);m.normalize();var g=Math.pow(1+p*p+u*u,-1.5),v=h[f*t.size*c+d*c+0],_=h[f*t.size*c+d*c+1],y=h[f*t.size*c+d*c+2];t.type===e.Engine.TEXTURETYPE_UNSIGNED_INT&&(v/=255,_/=255,y/=255),t.gammaSpace&&(v=Math.pow(e.Scalar.Clamp(v),e.ToLinearSpace),_=Math.pow(e.Scalar.Clamp(_),e.ToLinearSpace),y=Math.pow(e.Scalar.Clamp(y),e.ToLinearSpace));var x=new e.Color3(v,_,y);i.addLight(m,x,g),r+=g,p+=n}u+=o}var b=6*(4*Math.PI)/6/r;return i.scale(b),i.convertIncidentRadianceToIrradiance(),i.convertIrradianceToLambertianRadiance(),e.SphericalPolynomial.getSphericalPolynomialFromHarmonics(i)},t.FileFaces=[new i("right",new e.Vector3(1,0,0),new e.Vector3(0,0,-1),new e.Vector3(0,-1,0)),new i("left",new e.Vector3(-1,0,0),new e.Vector3(0,0,1),new e.Vector3(0,-1,0)),new i("up",new e.Vector3(0,1,0),new e.Vector3(1,0,0),new e.Vector3(0,0,1)),new i("down",new e.Vector3(0,-1,0),new e.Vector3(1,0,0),new e.Vector3(0,0,-1)),new i("front",new e.Vector3(0,0,1),new e.Vector3(1,0,0),new e.Vector3(0,-1,0)),new i("back",new e.Vector3(0,0,-1),new e.Vector3(-1,0,0),new e.Vector3(0,-1,0))],t}();t.CubeMapToSphericalPolynomialTools=r}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){!function(t){var i=function(){function t(){}return t.ConvertPanoramaToCubemap=function(t,i,r,n){if(!t)throw"ConvertPanoramaToCubemap: input cannot be null";if(t.length!=i*r*3)throw"ConvertPanoramaToCubemap: input size is wrong";return{front:this.CreateCubemapTexture(n,this.FACE_FRONT,t,i,r),back:this.CreateCubemapTexture(n,this.FACE_BACK,t,i,r),left:this.CreateCubemapTexture(n,this.FACE_LEFT,t,i,r),right:this.CreateCubemapTexture(n,this.FACE_RIGHT,t,i,r),up:this.CreateCubemapTexture(n,this.FACE_UP,t,i,r),down:this.CreateCubemapTexture(n,this.FACE_DOWN,t,i,r),size:n,type:e.Engine.TEXTURETYPE_FLOAT,format:e.Engine.TEXTUREFORMAT_RGB,gammaSpace:!1}},t.CreateCubemapTexture=function(e,t,i,r,n){for(var o=new ArrayBuffer(e*e*4*3),s=new Float32Array(o),a=t[1].subtract(t[0]).scale(1/e),l=t[3].subtract(t[2]).scale(1/e),h=1/e,u=0,c=0;c<e;c++){for(var f=t[0],p=t[2],d=0;d<e;d++){var m=p.subtract(f).scale(u).add(f);m.normalize();var g=this.CalcProjectionSpherical(m,i,r,n);s[c*e*3+3*d+0]=g.r,s[c*e*3+3*d+1]=g.g,s[c*e*3+3*d+2]=g.b,f=f.add(a),p=p.add(l)}u+=h}return s},t.CalcProjectionSpherical=function(e,t,i,r){for(var n=Math.atan2(e.z,e.x),o=Math.acos(e.y);n<-Math.PI;)n+=2*Math.PI;for(;n>Math.PI;)n-=2*Math.PI;var s=n/Math.PI,a=o/Math.PI;s=.5*s+.5;var l=Math.round(s*i);l<0?l=0:l>=i&&(l=i-1);var h=Math.round(a*r);h<0?h=0:h>=r&&(h=r-1);var u=r-h-1;return{r:t[u*i*3+3*l+0],g:t[u*i*3+3*l+1],b:t[u*i*3+3*l+2]}},t.FACE_FRONT=[new e.Vector3(-1,-1,-1),new e.Vector3(1,-1,-1),new e.Vector3(-1,1,-1),new e.Vector3(1,1,-1)],t.FACE_BACK=[new e.Vector3(1,-1,1),new e.Vector3(-1,-1,1),new e.Vector3(1,1,1),new e.Vector3(-1,1,1)],t.FACE_RIGHT=[new e.Vector3(1,-1,-1),new e.Vector3(1,-1,1),new e.Vector3(1,1,-1),new e.Vector3(1,1,1)],t.FACE_LEFT=[new e.Vector3(-1,-1,1),new e.Vector3(-1,-1,-1),new e.Vector3(-1,1,1),new e.Vector3(-1,1,-1)],t.FACE_DOWN=[new e.Vector3(-1,1,-1),new e.Vector3(1,1,-1),new e.Vector3(-1,1,1),new e.Vector3(1,1,1)],t.FACE_UP=[new e.Vector3(-1,-1,1),new e.Vector3(1,-1,1),new e.Vector3(-1,-1,-1),new e.Vector3(1,-1,-1)],t}();t.PanoramaToCubeMapTools=i}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){!function(e){var t=function(){function t(){}return t.Ldexp=function(e,t){return t>1023?e*Math.pow(2,1023)*Math.pow(2,t-1023):t<-1074?e*Math.pow(2,-1074)*Math.pow(2,t+1074):e*Math.pow(2,t)},t.Rgbe2float=function(e,t,i,r,n,o){n>0?(n=this.Ldexp(1,n-136),e[o+0]=t*n,e[o+1]=i*n,e[o+2]=r*n):(e[o+0]=0,e[o+1]=0,e[o+2]=0)},t.readStringLine=function(e,t){for(var i="",r="",n=t;n<e.length-t&&"\n"!=(r=String.fromCharCode(e[n]));n++)i+=r;return i},t.RGBE_ReadHeader=function(e){var t=0,i=0,r=this.readStringLine(e,0);if("#"!=r[0]||"?"!=r[1])throw"Bad HDR Format.";var n=!1,o=!1,s=0;do{s+=r.length+1,"FORMAT=32-bit_rle_rgbe"==(r=this.readStringLine(e,s))?o=!0:0==r.length&&(n=!0)}while(!n);if(!o)throw"HDR Bad header format, unsupported FORMAT";s+=r.length+1,r=this.readStringLine(e,s);var a=/^\-Y (.*) \+X (.*)$/g.exec(r);if(!a||a.length<3)throw"HDR Bad header format, no size";if(i=parseInt(a[2]),t=parseInt(a[1]),i<8||i>32767)throw"HDR Bad header format, unsupported size";return s+=r.length+1,{height:t,width:i,dataPosition:s}},t.GetCubeMapTextureData=function(t,i){var r=new Uint8Array(t),n=this.RGBE_ReadHeader(r),o=this.RGBE_ReadPixels_RLE(r,n);return e.PanoramaToCubeMapTools.ConvertPanoramaToCubemap(o,n.width,n.height,i)},t.RGBE_ReadPixels=function(e,t){return this.RGBE_ReadPixels_RLE(e,t)},t.RGBE_ReadPixels_RLE=function(e,t){for(var i,r,n,o,s,a=t.height,l=t.width,h=t.dataPosition,u=0,c=0,f=0,p=new ArrayBuffer(4*l),d=new Uint8Array(p),m=new ArrayBuffer(t.width*t.height*4*3),g=new Float32Array(m);a>0;){if(i=e[h++],r=e[h++],n=e[h++],o=e[h++],2!=i||2!=r||128&n)throw"HDR Bad header format, not RLE";if((n<<8|o)!=l)throw"HDR Bad header format, wrong scan line width";for(u=0,f=0;f<4;f++)for(c=(f+1)*l;u<c;)if(i=e[h++],r=e[h++],i>128){if(0==(s=i-128)||s>c-u)throw"HDR Bad Format, bad scanline data (run)";for(;s-- >0;)d[u++]=r}else{if(0==(s=i)||s>c-u)throw"HDR Bad Format, bad scanline data (non-run)";if(d[u++]=r,--s>0)for(var v=0;v<s;v++)d[u++]=e[h++]}for(f=0;f<l;f++)i=d[f],r=d[f+l],n=d[f+2*l],o=d[f+3*l],this.Rgbe2float(g,i,r,n,o,(t.height-a)*l*3+3*f);a--}return g},t}();e.HDRTools=t}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l,h,u){void 0===o&&(o=!1),void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=!1),void 0===h&&(h=null),void 0===u&&(u=null);var c=t.call(this,r)||this;if(c._useInGammaSpace=!1,c._generateHarmonics=!0,c._isBABYLONPreprocessed=!1,c._onLoad=null,c._onError=null,c.coordinatesMode=e.Texture.CUBIC_MODE,c.isPMREM=!1,c._isBlocking=!0,!i)return c;c.name=i,c.url=i,c.hasAlpha=!1,c.isCube=!0,c._textureMatrix=e.Matrix.Identity(),c._onLoad=h,c._onError=u,c.gammaSpace=!1;var f=r.getEngine().getCaps();return n?(c._isBABYLONPreprocessed=!1,c._noMipmap=o,c._size=n,c._useInGammaSpace=a,c._usePMREMGenerator=l&&f.textureLOD&&f.textureFloat&&!c._useInGammaSpace):(c._isBABYLONPreprocessed=!0,c._noMipmap=!1,c._useInGammaSpace=!1,c._usePMREMGenerator=f.textureLOD&&f.textureFloat&&!c._useInGammaSpace),c.isPMREM=c._usePMREMGenerator,c._texture=c._getFromCache(i,c._noMipmap),c._texture||(r.useDelayedTextureLoading?c.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:c.loadTexture()),c}return n(i,t),Object.defineProperty(i.prototype,"isBlocking",{get:function(){return this._isBlocking},set:function(e){this._isBlocking=e},enumerable:!0,configurable:!0}),i.prototype.loadBabylonTexture=function(){var t=this,i=0,r=null,n=this.getScene(),o=!this._useInGammaSpace&&n&&n.getEngine().getCaps().textureFloat?function(e){var n=new Array;if(!r)return n;for(var o=30,s=0;s<i;s++){n.push([]);for(var a=3*Math.pow(t._size>>s,2),l=0;l<6;l++){var h=r.subarray(o,o+a);n[s].push(h),o+=a}}return n}:null;n&&(this._texture=n.getEngine().createRawCubeTextureFromUrl(this.url,n,this._size,e.Engine.TEXTUREFORMAT_RGB,n.getEngine().getCaps().textureFloat?e.Engine.TEXTURETYPE_FLOAT:e.Engine.TEXTURETYPE_UNSIGNED_INT,this._noMipmap,function(n){var s=t.getScene();if(!s)return null;var a=new Int32Array(n);r=new Float32Array(n);var l=a[0];if(t._size=a[1],!t._texture)return null;t._texture.updateSize(t._size,t._size);var h=new e.SphericalPolynomial;h.x.copyFromFloats(r[2],r[3],r[4]),h.y.copyFromFloats(r[5],r[6],r[7]),h.z.copyFromFloats(r[8],r[9],r[10]),h.xx.copyFromFloats(r[11],r[12],r[13]),h.yy.copyFromFloats(r[14],r[15],r[16]),h.zz.copyFromFloats(r[17],r[18],r[19]),h.xy.copyFromFloats(r[20],r[21],r[22]),h.yz.copyFromFloats(r[23],r[24],r[25]),h.zx.copyFromFloats(r[26],r[27],r[28]),t.sphericalPolynomial=h,i=a[29];for(var u=30,c=[],f=3*Math.pow(t._size,2),p=0;p<6;p++)c.push(r.subarray(u,u+f)),u+=f;for(var d=[],m=null,g=0;g<6;g++){var v=null;if(1===l&&(v=c[[0,2,4,1,3,5][g]]),!o&&v){if(!s.getEngine().getCaps().textureFloat){var _=new ArrayBuffer(f);m=new Uint8Array(_)}for(var y=0;y<t._size*t._size;y++)if(t._useInGammaSpace&&(v[3*y+0]=Math.pow(v[3*y+0],e.ToGammaSpace),v[3*y+1]=Math.pow(v[3*y+1],e.ToGammaSpace),v[3*y+2]=Math.pow(v[3*y+2],e.ToGammaSpace)),m){var x=Math.max(255*v[3*y+0],0),b=Math.max(255*v[3*y+1],0),T=Math.max(255*v[3*y+2],0),E=Math.max(Math.max(x,b),T);if(E>255){var A=255/E;x*=A,b*=A,T*=A}m[3*y+0]=x,m[3*y+1]=b,m[3*y+2]=T}}m?d.push(m):d.push(v)}return d},o,this._onLoad,this._onError))},i.prototype.loadHDRTexture=function(){var t=this,r=this.getScene();r&&(this._texture=r.getEngine().createRawCubeTextureFromUrl(this.url,r,this._size,e.Engine.TEXTUREFORMAT_RGB,r.getEngine().getCaps().textureFloat?e.Engine.TEXTURETYPE_FLOAT:e.Engine.TEXTURETYPE_UNSIGNED_INT,this._noMipmap,function(r){var n=t.getScene();if(!n)return null;var o=e.Internals.HDRTools.GetCubeMapTextureData(r,t._size);if(t._generateHarmonics){var s=e.Internals.CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(o);t.sphericalPolynomial=s}for(var a=[],l=null,h=0;h<6;h++){if(!n.getEngine().getCaps().textureFloat){var u=new ArrayBuffer(t._size*t._size*3);l=new Uint8Array(u)}var c=o[i._facesMapping[h]];if(t._useInGammaSpace||l)for(var f=0;f<t._size*t._size;f++)if(t._useInGammaSpace&&(c[3*f+0]=Math.pow(c[3*f+0],e.ToGammaSpace),c[3*f+1]=Math.pow(c[3*f+1],e.ToGammaSpace),c[3*f+2]=Math.pow(c[3*f+2],e.ToGammaSpace)),l){var p=Math.max(255*c[3*f+0],0),d=Math.max(255*c[3*f+1],0),m=Math.max(255*c[3*f+2],0),g=Math.max(Math.max(p,d),m);if(g>255){var v=255/g;p*=v,d*=v,m*=v}l[3*f+0]=p,l[3*f+1]=d,l[3*f+2]=m}l?a.push(l):a.push(c)}return a},null,this._onLoad,this._onError))},i.prototype.loadTexture=function(){this._isBABYLONPreprocessed?this.loadBabylonTexture():this.loadHDRTexture()},i.prototype.clone=function(){var e=this.getScene();if(!e)return this;var t=this._isBABYLONPreprocessed?null:this._size,r=new i(this.url,e,t,this._noMipmap,this._generateHarmonics,this._useInGammaSpace,this._usePMREMGenerator);return r.level=this.level,r.wrapU=this.wrapU,r.wrapV=this.wrapV,r.coordinatesIndex=this.coordinatesIndex,r.coordinatesMode=this.coordinatesMode,r},i.prototype.delayLoad=function(){this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap),this._texture||this.loadTexture())},i.prototype.getReflectionTextureMatrix=function(){return this._textureMatrix},i.prototype.setReflectionTextureMatrix=function(e){this._textureMatrix=e},i.Parse=function(t,i,r){var n=null;if(t.name&&!t.isRenderTarget){var o=t.isBABYLONPreprocessed?null:t.size;(n=new e.HDRCubeTexture(r+t.name,i,o,t.noMipmap,t.generateHarmonics,t.useInGammaSpace,t.usePMREMGenerator)).name=t.name,n.hasAlpha=t.hasAlpha,n.level=t.level,n.coordinatesMode=t.coordinatesMode,n.isBlocking=t.isBlocking}return n},i.prototype.serialize=function(){if(!this.name)return null;var e={};return e.name=this.name,e.hasAlpha=this.hasAlpha,e.isCube=!0,e.level=this.level,e.size=this._size,e.coordinatesMode=this.coordinatesMode,e.useInGammaSpace=this._useInGammaSpace,e.generateHarmonics=this._generateHarmonics,e.usePMREMGenerator=this._usePMREMGenerator,e.isBABYLONPreprocessed=this._isBABYLONPreprocessed,e.customType="BABYLON.HDRCubeTexture",e.noMipmap=this._noMipmap,e.isBlocking=this._isBlocking,e},i.generateBabylonHDROnDisk=function(e,t,r){void 0===r&&(r=null);i.generateBabylonHDR(e,t,function(e){var t=new Blob([e],{type:"application/octet-stream"}),i=window.URL.createObjectURL(t),r=document.createElement("a");document.body.appendChild(r),r.style.display="none",r.href=i,r.download="envmap.babylon.hdr",r.click()},r)},i.generateBabylonHDR=function(t,i,r,n){void 0===n&&(n=null),t&&e.Tools.IsExponentOfTwo(i)&&e.Tools.Error("Generation of Babylon HDR is coming back in 3.1.")},i._facesMapping=["right","left","up","down","front","back"],i}(e.BaseTexture);e.HDRCubeTexture=t}(s||(s={}));var o;!function(e){function t(e,t,i,r,n){var o,s=null;if(n===M(e,t,i,r)>0)for(o=t;o<i;o+=r)s=P(o,e[o],e[o+1],s);else for(o=i-r;o>=t;o-=r)s=P(o,e[o],e[o+1],s);return s&&y(s,s.next)&&(S(s),s=s.next),s}function i(e,t){if(!e)return e;t||(t=e);var i,r=e;do{if(i=!1,r.steiner||!y(r,r.next)&&0!==_(r.prev,r,r.next))r=r.next;else{if(S(r),(r=t=r.prev)===r.next)return;i=!0}}while(i||r!==t);return t}function r(e,t,l,h,u,c,p){if(e){!p&&c&&f(e,h,u,c);for(var d,m,g=e;e.prev!==e.next;)if(d=e.prev,m=e.next,c?o(e,h,u,c):n(e))t.push(d.i/l),t.push(e.i/l),t.push(m.i/l),S(e),e=m.next,g=m.next;else if((e=m)===g){p?1===p?r(e=s(e,t,l),t,l,h,u,c,2):2===p&&a(e,t,l,h,u,c):r(i(e,void 0),t,l,h,u,c,1);break}}}function n(e){var t=e.prev,i=e,r=e.next;if(_(t,i,r)>=0)return!1;for(var n=e.next.next;n!==e.prev;){if(g(t.x,t.y,i.x,i.y,r.x,r.y,n.x,n.y)&&_(n.prev,n,n.next)>=0)return!1;n=n.next}return!0}function o(e,t,i,r){var n=e.prev,o=e,s=e.next;if(_(n,o,s)>=0)return!1;for(var a=n.x<o.x?n.x<s.x?n.x:s.x:o.x<s.x?o.x:s.x,l=n.y<o.y?n.y<s.y?n.y:s.y:o.y<s.y?o.y:s.y,h=n.x>o.x?n.x>s.x?n.x:s.x:o.x>s.x?o.x:s.x,u=n.y>o.y?n.y>s.y?n.y:s.y:o.y>s.y?o.y:s.y,c=d(a,l,t,i,r),f=d(h,u,t,i,r),p=e.nextZ;p&&p.z<=f;){if(p!==e.prev&&p!==e.next&&g(n.x,n.y,o.x,o.y,s.x,s.y,p.x,p.y)&&_(p.prev,p,p.next)>=0)return!1;p=p.nextZ}for(p=e.prevZ;p&&p.z>=c;){if(p!==e.prev&&p!==e.next&&g(n.x,n.y,o.x,o.y,s.x,s.y,p.x,p.y)&&_(p.prev,p,p.next)>=0)return!1;p=p.prevZ}return!0}function s(e,t,i){var r=e;do{var n=r.prev,o=r.next.next;!y(n,o)&&x(n,r,r.next,o)&&T(n,o)&&T(o,n)&&(t.push(n.i/i),t.push(r.i/i),t.push(o.i/i),S(r),S(r.next),r=e=o),r=r.next}while(r!==e);return r}function a(e,t,n,o,s,a){var l=e;do{for(var h=l.next.next;h!==l.prev;){if(l.i!==h.i&&v(l,h)){var u=A(l,h);return l=i(l,l.next),u=i(u,u.next),r(l,t,n,o,s,a,void 0),void r(u,t,n,o,s,a,void 0)}h=h.next}l=l.next}while(l!==e)}function l(e,r,n,o){var s,a,l,c=[];for(s=0,a=r.length;s<a;s++)(l=t(e,r[s]*o,s<a-1?r[s+1]*o:e.length,o,!1))===l.next&&(l.steiner=!0),c.push(m(l));for(c.sort(h),s=0;s<c.length;s++)u(c[s],n),n=i(n,n.next);return n}function h(e,t){return e.x-t.x}function u(e,t){if(t=c(e,t)){var r=A(t,e);i(r,r.next)}}function c(e,t){var i,r=t,n=e.x,o=e.y,s=-1/0;do{if(o<=r.y&&o>=r.next.y){var a=r.x+(o-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(a<=n&&a>s){if(s=a,a===n){if(o===r.y)return r;if(o===r.next.y)return r.next}i=r.x<r.next.x?r:r.next}}r=r.next}while(r!==t);if(!i)return null;if(n===s)return i.prev;var l,h=i,u=i.x,c=i.y,f=1/0;for(r=i.next;r!==h;)n>=r.x&&r.x>=u&&g(o<c?n:s,o,u,c,o<c?s:n,o,r.x,r.y)&&((l=Math.abs(o-r.y)/(n-r.x))<f||l===f&&r.x>i.x)&&T(r,e)&&(i=r,f=l),r=r.next;return i}function f(e,t,i,r){var n=e;do{null===n.z&&(n.z=d(n.x,n.y,t,i,r)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next}while(n!==e);n.prevZ.nextZ=null,n.prevZ=null,p(n)}function p(e){var t,i,r,n,o,s,a,l,h=1;do{for(i=e,e=null,o=null,s=0;i;){for(s++,r=i,a=0,t=0;t<h&&(a++,r=r.nextZ);t++);for(l=h;a>0||l>0&&r;)0===a?(n=r,r=r.nextZ,l--):0!==l&&r?i.z<=r.z?(n=i,i=i.nextZ,a--):(n=r,r=r.nextZ,l--):(n=i,i=i.nextZ,a--),o?o.nextZ=n:e=n,n.prevZ=o,o=n;i=r}o.nextZ=null,h*=2}while(s>1);return e}function d(e,t,i,r,n){return e=32767*(e-i)/n,t=32767*(t-r)/n,e=16711935&(e|e<<8),e=252645135&(e|e<<4),e=858993459&(e|e<<2),e=1431655765&(e|e<<1),t=16711935&(t|t<<8),t=252645135&(t|t<<4),t=858993459&(t|t<<2),t=1431655765&(t|t<<1),e|t<<1}function m(e){var t=e,i=e;do{t.x<i.x&&(i=t),t=t.next}while(t!==e);return i}function g(e,t,i,r,n,o,s,a){return(n-s)*(t-a)-(e-s)*(o-a)>=0&&(e-s)*(r-a)-(i-s)*(t-a)>=0&&(i-s)*(o-a)-(n-s)*(r-a)>=0}function v(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!b(e,t)&&T(e,t)&&T(t,e)&&E(e,t)}function _(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function y(e,t){return e.x===t.x&&e.y===t.y}function x(e,t,i,r){return!!(y(e,t)&&y(i,r)||y(e,r)&&y(i,t))||_(e,t,i)>0!=_(e,t,r)>0&&_(i,r,e)>0!=_(i,r,t)>0}function b(e,t){var i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&x(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}function T(e,t){return _(e.prev,e,e.next)<0?_(e,t,e.next)>=0&&_(e,e.prev,t)>=0:_(e,t,e.prev)<0||_(e,e.next,t)<0}function E(e,t){var i=e,r=!1,n=(e.x+t.x)/2,o=(e.y+t.y)/2;do{i.y>o!=i.next.y>o&&n<(i.next.x-i.x)*(o-i.y)/(i.next.y-i.y)+i.x&&(r=!r),i=i.next}while(i!==e);return r}function A(e,t){var i=new C(e.i,e.x,e.y),r=new C(t.i,t.x,t.y),n=e.next,o=t.prev;return e.next=t,t.prev=e,i.next=n,n.prev=i,r.next=i,i.prev=r,o.next=r,r.prev=o,r}function P(e,t,i,r){var n=new C(e,t,i);return r?(n.next=r.next,n.prev=r,r.next.prev=n,r.next=n):(n.prev=n,n.next=n),n}function S(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function M(e,t,i,r){for(var n=0,o=t,s=i-r;o<i;o+=r)n+=(e[s]-e[o])*(e[o+1]+e[s+1]),s=o;return n}e.earcut=function(e,i,n){n=n||2;var o=i&&i.length,s=o?i[0]*n:e.length,a=t(e,0,s,n,!0),h=new Array;if(!a)return h;var u,c,f,p,d=0,m=0,g=0;if(o&&(a=l(e,i,a,n)),e.length>80*n){d=u=e[0],m=c=e[1];for(var v=n;v<s;v+=n)f=e[v],p=e[v+1],f<d&&(d=f),p<m&&(m=p),f>u&&(u=f),p>c&&(c=p);g=Math.max(u-d,c-m)}return r(a,h,n,d,m,g,0),h};var C=function(){return function(e,t,i){this.i=e,this.x=t,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}}();e.deviation=function(e,t,i,r){var n=t&&t.length,o=n?t[0]*i:e.length,s=Math.abs(M(e,0,o,i));if(n)for(var a=0,l=t.length;a<l;a++){var h=t[a]*i,u=a<l-1?t[a+1]*i:e.length;s-=Math.abs(M(e,h,u,i))}var c=0;for(a=0;a<r.length;a+=3){var f=r[a]*i,p=r[a+1]*i,d=r[a+2]*i;c+=Math.abs((e[f]-e[d])*(e[p+1]-e[f+1])-(e[f]-e[p])*(e[d+1]-e[f+1]))}return 0===s&&0===c?0:Math.abs((c-s)/s)},e.flatten=function(e){for(var t=e[0][0].length,i={vertices:new Array,holes:new Array,dimensions:t},r=0,n=0;n<e.length;n++){for(var o=0;o<e[n].length;o++)for(var s=0;s<t;s++)i.vertices.push(e[n][o][s]);n>0&&(r+=e[n-1].length,i.holes.push(r))}return i}}(o||(o={}));!function(e){var t=function(e){function t(t,i){var r=e.call(this,t.x,t.y)||this;return r.index=i,r}return n(t,e),t}(e.Vector2),i=function(){function i(){this.elements=new Array}return i.prototype.add=function(e){var i=this,r=new Array;return e.forEach(function(e){if(0===r.length||!e.equalsWithEpsilon(r[0])){var n=new t(e,i.elements.length);r.push(n),i.elements.push(n)}}),r},i.prototype.computeBounds=function(){var t=new e.Vector2(this.elements[0].x,this.elements[0].y),i=new e.Vector2(this.elements[0].x,this.elements[0].y);return this.elements.forEach(function(e){e.x<t.x?t.x=e.x:e.x>i.x&&(i.x=e.x),e.y<t.y?t.y=e.y:e.y>i.y&&(i.y=e.y)}),{min:t,max:i,width:i.x-t.x,height:i.y-t.y}},i}(),r=function(){function t(){}return t.Rectangle=function(t,i,r,n){return[new e.Vector2(t,i),new e.Vector2(r,i),new e.Vector2(r,n),new e.Vector2(t,n)]},t.Circle=function(t,i,r,n){void 0===i&&(i=0),void 0===r&&(r=0),void 0===n&&(n=32);for(var o=new Array,s=0,a=2*Math.PI/n,l=0;l<n;l++)o.push(new e.Vector2(i+Math.cos(s)*t,r+Math.sin(s)*t)),s-=a;return o},t.Parse=function(t){var i,r=t.split(/[^-+eE\.\d]+/).map(parseFloat).filter(function(e){return!isNaN(e)}),n=[];for(i=0;i<(2147483646&r.length);i+=2)n.push(new e.Vector2(r[i],r[i+1]));return n},t.StartingAt=function(t,i){return e.Path2.StartingAt(t,i)},t}();e.Polygon=r;var s=function(){function t(t,r,n){this._points=new i,this._outlinepoints=new i,this._holes=new Array,this._epoints=new Array,this._eholes=new Array,this._name=t,this._scene=n;var o;o=r instanceof e.Path2?r.getPoints():r,this._addToepoint(o),this._points.add(o),this._outlinepoints.add(o)}return t.prototype._addToepoint=function(e){for(var t=0,i=e;t<i.length;t++){var r=i[t];this._epoints.push(r.x,r.y)}},t.prototype.addHole=function(e){this._points.add(e);var t=new i;return t.add(e),this._holes.push(t),this._eholes.push(this._epoints.length/2),this._addToepoint(e),this},t.prototype.build=function(t,i){var r=this;void 0===t&&(t=!1),void 0===i&&(i=0);var n=new e.Mesh(this._name,this._scene),s=new Array,a=new Array,l=new Array,h=this._points.computeBounds();this._points.elements.forEach(function(e){s.push(0,1,0),a.push(e.x,0,e.y),l.push((e.x-h.min.x)/h.width,(e.y-h.min.y)/h.height)});for(var u=new Array,c=o.earcut(this._epoints,this._eholes,2),f=0;f<c.length;f++)u.push(c[f]);if(i>0){var p=a.length/3;this._points.elements.forEach(function(e){s.push(0,-1,0),a.push(e.x,-i,e.y),l.push(1-(e.x-h.min.x)/h.width,1-(e.y-h.min.y)/h.height)});for(var d=u.length,f=0;f<d;f+=3){var m=u[f+0],g=u[f+1],v=u[f+2];u.push(v+p),u.push(g+p),u.push(m+p)}this.addSide(a,s,l,u,h,this._outlinepoints,i,!1),this._holes.forEach(function(e){r.addSide(a,s,l,u,h,e,i,!0)})}return n.setVerticesData(e.VertexBuffer.PositionKind,a,t),n.setVerticesData(e.VertexBuffer.NormalKind,s,t),n.setVerticesData(e.VertexBuffer.UVKind,l,t),n.setIndices(u),n},t.prototype.addSide=function(t,i,r,n,o,s,a,l){for(var h=t.length/3,u=0,c=0;c<s.elements.length;c++){var f,p=s.elements[c];f=c+1>s.elements.length-1?s.elements[0]:s.elements[c+1],t.push(p.x,0,p.y),t.push(p.x,-a,p.y),t.push(f.x,0,f.y),t.push(f.x,-a,f.y);var d=new e.Vector3(p.x,0,p.y),m=new e.Vector3(f.x,0,f.y).subtract(d),g=new e.Vector3(0,1,0),v=e.Vector3.Cross(m,g);v=v.normalize(),r.push(u/o.width,0),r.push(u/o.width,1),u+=m.length(),r.push(u/o.width,0),r.push(u/o.width,1),l?(i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),n.push(h),n.push(h+2),n.push(h+1),n.push(h+1),n.push(h+2),n.push(h+3)):(i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),n.push(h),n.push(h+1),n.push(h+2),n.push(h+1),n.push(h+3),n.push(h+2)),h+=4}},t}();e.PolygonMeshBuilder=s}(s||(s={}));!function(e){var t=0,i=function(){function t(e,t,i){this.pos=e,this.normal=t,this.uv=i}return t.prototype.clone=function(){return new t(this.pos.clone(),this.normal.clone(),this.uv.clone())},t.prototype.flip=function(){this.normal=this.normal.scale(-1)},t.prototype.interpolate=function(i,r){return new t(e.Vector3.Lerp(this.pos,i.pos,r),e.Vector3.Lerp(this.normal,i.normal,r),e.Vector2.Lerp(this.uv,i.uv,r))},t}(),r=function(){function t(e,t){this.normal=e,this.w=t}return t.FromPoints=function(i,r,n){var o=n.subtract(i),s=r.subtract(i);if(0===o.lengthSquared()||0===s.lengthSquared())return null;var a=e.Vector3.Normalize(e.Vector3.Cross(o,s));return new t(a,e.Vector3.Dot(a,i))},t.prototype.clone=function(){return new t(this.normal.clone(),this.w)},t.prototype.flip=function(){this.normal.scaleInPlace(-1),this.w=-this.w},t.prototype.splitPolygon=function(i,r,o,s,a){var l,h,u=0,c=[];for(l=0;l<i.vertices.length;l++){var f=(h=e.Vector3.Dot(this.normal,i.vertices[l].pos)-this.w)<-t.EPSILON?2:h>t.EPSILON?1:0;u|=f,c.push(f)}switch(u){case 0:(e.Vector3.Dot(this.normal,i.plane.normal)>0?r:o).push(i);break;case 1:s.push(i);break;case 2:a.push(i);break;case 3:var p=[],d=[];for(l=0;l<i.vertices.length;l++){var m=(l+1)%i.vertices.length,g=c[l],v=c[m],_=i.vertices[l],y=i.vertices[m];if(2!==g&&p.push(_),1!==g&&d.push(2!==g?_.clone():_),3==(g|v)){h=(this.w-e.Vector3.Dot(this.normal,_.pos))/e.Vector3.Dot(this.normal,y.pos.subtract(_.pos));var x=_.interpolate(y,h);p.push(x),d.push(x.clone())}}var b;p.length>=3&&(b=new n(p,i.shared)).plane&&s.push(b),d.length>=3&&(b=new n(d,i.shared)).plane&&a.push(b)}},t.EPSILON=1e-5,t}(),n=function(){function e(e,t){this.vertices=e,this.shared=t,this.plane=r.FromPoints(e[0].pos,e[1].pos,e[2].pos)}return e.prototype.clone=function(){return new e(this.vertices.map(function(e){return e.clone()}),this.shared)},e.prototype.flip=function(){this.vertices.reverse().map(function(e){e.flip()}),this.plane.flip()},e}(),o=function(){function e(e){this.plane=null,this.front=null,this.back=null,this.polygons=new Array,e&&this.build(e)}return e.prototype.clone=function(){var t=new e;return t.plane=this.plane&&this.plane.clone(),t.front=this.front&&this.front.clone(),t.back=this.back&&this.back.clone(),t.polygons=this.polygons.map(function(e){return e.clone()}),t},e.prototype.invert=function(){for(var e=0;e<this.polygons.length;e++)this.polygons[e].flip();this.plane&&this.plane.flip(),this.front&&this.front.invert(),this.back&&this.back.invert();var t=this.front;this.front=this.back,this.back=t},e.prototype.clipPolygons=function(e){if(!this.plane)return e.slice();for(var t=new Array,i=new Array,r=0;r<e.length;r++)this.plane.splitPolygon(e[r],t,i,t,i);return this.front&&(t=this.front.clipPolygons(t)),i=this.back?this.back.clipPolygons(i):[],t.concat(i)},e.prototype.clipTo=function(e){this.polygons=e.clipPolygons(this.polygons),this.front&&this.front.clipTo(e),this.back&&this.back.clipTo(e)},e.prototype.allPolygons=function(){var e=this.polygons.slice();return this.front&&(e=e.concat(this.front.allPolygons())),this.back&&(e=e.concat(this.back.allPolygons())),e},e.prototype.build=function(t){if(t.length){this.plane||(this.plane=t[0].plane.clone());for(var i=new Array,r=new Array,n=0;n<t.length;n++)this.plane.splitPolygon(t[n],this.polygons,this.polygons,i,r);i.length&&(this.front||(this.front=new e),this.front.build(i)),r.length&&(this.back||(this.back=new e),this.back.build(r))}},e}(),s=function(){function r(){this.polygons=new Array}return r.FromMesh=function(o){var s,a,l,h,u,c,f,p,d,m,g=new Array,v=null;if(!(o instanceof e.Mesh))throw"BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh";o.computeWorldMatrix(!0),f=o.getWorldMatrix(),p=o.position.clone(),d=o.rotation.clone(),o.rotationQuaternion&&(v=o.rotationQuaternion.clone()),m=o.scaling.clone();for(var _=o.getIndices(),y=o.getVerticesData(e.VertexBuffer.PositionKind),x=o.getVerticesData(e.VertexBuffer.NormalKind),b=o.getVerticesData(e.VertexBuffer.UVKind),T=o.subMeshes,E=0,A=T.length;E<A;E++)for(var P=T[E].indexStart,S=T[E].indexCount+T[E].indexStart;P<S;P+=3){c=[];for(var M=0;M<3;M++){var C=new e.Vector3(x[3*_[P+M]],x[3*_[P+M]+1],x[3*_[P+M]+2]);l=new e.Vector2(b[2*_[P+M]],b[2*_[P+M]+1]);var R=new e.Vector3(y[3*_[P+M]],y[3*_[P+M]+1],y[3*_[P+M]+2]);h=e.Vector3.TransformCoordinates(R,f),a=e.Vector3.TransformNormal(C,f),s=new i(h,a,l),c.push(s)}(u=new n(c,{subMeshId:E,meshId:t,materialIndex:T[E].materialIndex})).plane&&g.push(u)}var I=r.FromPolygons(g);return I.matrix=f,I.position=p,I.rotation=d,I.scaling=m,I.rotationQuaternion=v,t++,I},r.FromPolygons=function(e){var t=new r;return t.polygons=e,t},r.prototype.clone=function(){var e=new r;return e.polygons=this.polygons.map(function(e){return e.clone()}),e.copyTransformAttributes(this),e},r.prototype.union=function(e){var t=new o(this.clone().polygons),i=new o(e.clone().polygons);return t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),r.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},r.prototype.unionInPlace=function(e){var t=new o(this.polygons),i=new o(e.polygons);t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),this.polygons=t.allPolygons()},r.prototype.subtract=function(e){var t=new o(this.clone().polygons),i=new o(e.clone().polygons);return t.invert(),t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),t.invert(),r.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},r.prototype.subtractInPlace=function(e){var t=new o(this.polygons),i=new o(e.polygons);t.invert(),t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),t.invert(),this.polygons=t.allPolygons()},r.prototype.intersect=function(e){var t=new o(this.clone().polygons),i=new o(e.clone().polygons);return t.invert(),i.clipTo(t),i.invert(),t.clipTo(i),i.clipTo(t),t.build(i.allPolygons()),t.invert(),r.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},r.prototype.intersectInPlace=function(e){var t=new o(this.polygons),i=new o(e.polygons);t.invert(),i.clipTo(t),i.invert(),t.clipTo(i),i.clipTo(t),t.build(i.allPolygons()),t.invert(),this.polygons=t.allPolygons()},r.prototype.inverse=function(){var e=this.clone();return e.inverseInPlace(),e},r.prototype.inverseInPlace=function(){this.polygons.map(function(e){e.flip()})},r.prototype.copyTransformAttributes=function(e){return this.matrix=e.matrix,this.position=e.position,this.rotation=e.rotation,this.scaling=e.scaling,this.rotationQuaternion=e.rotationQuaternion,this},r.prototype.buildMeshGeometry=function(t,i,r){var n=this.matrix.clone();n.invert();var o,s,a,l=new e.Mesh(t,i),h=[],u=[],c=[],f=[],p=e.Vector3.Zero(),d=e.Vector3.Zero(),m=e.Vector2.Zero(),g=this.polygons,v=[0,0,0],_={},y=0,x={};r&&g.sort(function(e,t){return e.shared.meshId===t.shared.meshId?e.shared.subMeshId-t.shared.subMeshId:e.shared.meshId-t.shared.meshId});for(var b=0,T=g.length;b<T;b++){x[(o=g[b]).shared.meshId]||(x[o.shared.meshId]={}),x[o.shared.meshId][o.shared.subMeshId]||(x[o.shared.meshId][o.shared.subMeshId]={indexStart:1/0,indexEnd:-1/0,materialIndex:o.shared.materialIndex}),a=x[o.shared.meshId][o.shared.subMeshId];for(var E=2,A=o.vertices.length;E<A;E++){v[0]=0,v[1]=E-1,v[2]=E;for(var P=0;P<3;P++){p.copyFrom(o.vertices[v[P]].pos),d.copyFrom(o.vertices[v[P]].normal),m.copyFrom(o.vertices[v[P]].uv);var S=e.Vector3.TransformCoordinates(p,n),M=e.Vector3.TransformNormal(d,n);void 0!==(s=_[S.x+","+S.y+","+S.z])&&c[3*s]===M.x&&c[3*s+1]===M.y&&c[3*s+2]===M.z&&f[2*s]===m.x&&f[2*s+1]===m.y||(h.push(S.x,S.y,S.z),f.push(m.x,m.y),c.push(d.x,d.y,d.z),s=_[S.x+","+S.y+","+S.z]=h.length/3-1),u.push(s),a.indexStart=Math.min(y,a.indexStart),a.indexEnd=Math.max(y,a.indexEnd),y++}}}if(l.setVerticesData(e.VertexBuffer.PositionKind,h),l.setVerticesData(e.VertexBuffer.NormalKind,c),l.setVerticesData(e.VertexBuffer.UVKind,f),l.setIndices(u,null),r){var C,R=0;l.subMeshes=new Array;for(var I in x){C=-1;for(var O in x[I])a=x[I][O],e.SubMesh.CreateFromIndices(a.materialIndex+R,a.indexStart,a.indexEnd-a.indexStart+1,l),C=Math.max(a.materialIndex,C);R+=++C}}return l},r.prototype.toMesh=function(e,t,i,r){var n=this.buildMeshGeometry(e,i,r);return n.material=t,n.position.copyFrom(this.position),n.rotation.copyFrom(this.rotation),this.rotationQuaternion&&(n.rotationQuaternion=this.rotationQuaternion.clone()),n.scaling.copyFrom(this.scaling),n.computeWorldMatrix(!0),n},r}();e.CSG=s}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n,o){this.size=t,this.position=i,this.alphaMode=e.Engine.ALPHA_ONEONE,this.color=r||new e.Color3(1,1,1),this.texture=n?new e.Texture(n,o.getScene(),!0):null,this._system=o,o.lensFlares.push(this)}return t.AddFlare=function(e,i,r,n,o){return new t(e,i,r,n,o)},t.prototype.dispose=function(){this.texture&&this.texture.dispose();var e=this._system.lensFlares.indexOf(this);this._system.lensFlares.splice(e,1)},t}();e.LensFlare=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r){this.name=t,this.lensFlares=new Array,this.borderLimit=300,this.viewportBorder=0,this.layerMask=268435455,this._vertexBuffers={},this._isEnabled=!0,this._scene=r||e.Engine.LastCreatedScene,this._emitter=i,this.id=t,r.lensFlareSystems.push(this),this.meshesSelectionPredicate=function(e){return r.activeCamera&&e.material&&e.isVisible&&e.isEnabled()&&e.isBlocker&&0!=(e.layerMask&r.activeCamera.layerMask)};var n=r.getEngine(),o=[];o.push(1,1),o.push(-1,1),o.push(-1,-1),o.push(1,-1),this._vertexBuffers[e.VertexBuffer.PositionKind]=new e.VertexBuffer(n,o,e.VertexBuffer.PositionKind,!1,!1,2);var s=[];s.push(0),s.push(1),s.push(2),s.push(0),s.push(2),s.push(3),this._indexBuffer=n.createIndexBuffer(s),this._effect=n.createEffect("lensFlare",[e.VertexBuffer.PositionKind],["color","viewportMatrix"],["textureSampler"],"")}return Object.defineProperty(t.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(e){this._isEnabled=e},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},t.prototype.getEmitter=function(){return this._emitter},t.prototype.setEmitter=function(e){this._emitter=e},t.prototype.getEmitterPosition=function(){return this._emitter.getAbsolutePosition?this._emitter.getAbsolutePosition():this._emitter.position},t.prototype.computeEffectivePosition=function(t){var i=this.getEmitterPosition();return i=e.Vector3.Project(i,e.Matrix.Identity(),this._scene.getTransformMatrix(),t),this._positionX=i.x,this._positionY=i.y,i=e.Vector3.TransformCoordinates(this.getEmitterPosition(),this._scene.getViewMatrix()),this.viewportBorder>0&&(t.x-=this.viewportBorder,t.y-=this.viewportBorder,t.width+=2*this.viewportBorder,t.height+=2*this.viewportBorder,i.x+=this.viewportBorder,i.y+=this.viewportBorder,this._positionX+=this.viewportBorder,this._positionY+=this.viewportBorder),i.z>0&&(this._positionX>t.x&&this._positionX<t.x+t.width&&this._positionY>t.y&&(this._positionY,t.y,t.height),!0)},t.prototype._isVisible=function(){if(!this._isEnabled||!this._scene.activeCamera)return!1;var t=this.getEmitterPosition().subtract(this._scene.activeCamera.globalPosition),i=t.length();t.normalize();var r=new e.Ray(this._scene.activeCamera.globalPosition,t),n=this._scene.pickWithRay(r,this.meshesSelectionPredicate,!0);return!n||!n.hit||n.distance>i},t.prototype.render=function(){if(!this._effect.isReady()||!this._scene.activeCamera)return!1;var t=this._scene.getEngine(),i=this._scene.activeCamera.viewport.toGlobal(t.getRenderWidth(!0),t.getRenderHeight(!0));if(!this.computeEffectivePosition(i))return!1;if(!this._isVisible())return!1;var r,n,o=(r=this._positionX<this.borderLimit+i.x?this.borderLimit+i.x-this._positionX:this._positionX>i.x+i.width-this.borderLimit?this._positionX-i.x-i.width+this.borderLimit:0)>(n=this._positionY<this.borderLimit+i.y?this.borderLimit+i.y-this._positionY:this._positionY>i.y+i.height-this.borderLimit?this._positionY-i.y-i.height+this.borderLimit:0)?r:n;(o-=this.viewportBorder)>this.borderLimit&&(o=this.borderLimit);var s=1-o/this.borderLimit;if(s<0)return!1;s>1&&(s=1),this.viewportBorder>0&&(i.x+=this.viewportBorder,i.y+=this.viewportBorder,i.width-=2*this.viewportBorder,i.height-=2*this.viewportBorder,this._positionX-=this.viewportBorder,this._positionY-=this.viewportBorder);var a=i.x+i.width/2,l=i.y+i.height/2,h=a-this._positionX,u=l-this._positionY;t.enableEffect(this._effect),t.setState(!1),t.setDepthBuffer(!1),t.bindBuffers(this._vertexBuffers,this._indexBuffer,this._effect);for(var c=0;c<this.lensFlares.length;c++){var f=this.lensFlares[c];t.setAlphaMode(f.alphaMode);var p=a-h*f.position,d=l-u*f.position,m=f.size,g=f.size*t.getAspectRatio(this._scene.activeCamera,!0),v=p/(i.width+2*i.x)*2-1,_=1-d/(i.height+2*i.y)*2,y=e.Matrix.FromValues(m/2,0,0,0,0,g/2,0,0,0,0,1,0,v,_,0,1);this._effect.setMatrix("viewportMatrix",y),this._effect.setTexture("textureSampler",f.texture),this._effect.setFloat4("color",f.color.r*s,f.color.g*s,f.color.b*s,1),t.draw(!0,0,6)}return t.setDepthBuffer(!0),t.setAlphaMode(e.Engine.ALPHA_DISABLE),!0},t.prototype.dispose=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];for(t&&(t.dispose(),this._vertexBuffers[e.VertexBuffer.PositionKind]=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null);this.lensFlares.length;)this.lensFlares[0].dispose();var i=this._scene.lensFlareSystems.indexOf(this);this._scene.lensFlareSystems.splice(i,1)},t.Parse=function(i,r,n){var o=r.getLastEntryByID(i.emitterId),s=i.name||"lensFlareSystem#"+i.emitterId,a=new t(s,o,r);a.id=i.id||s,a.borderLimit=i.borderLimit;for(var l=0;l<i.flares.length;l++){var h=i.flares[l];e.LensFlare.AddFlare(h.size,h.position,e.Color3.FromArray(h.color),h.textureName?n+h.textureName:"",a)}return a},t.prototype.serialize=function(){var t={};t.id=this.id,t.name=this.name,t.emitterId=this.getEmitter().id,t.borderLimit=this.borderLimit,t.flares=[];for(var i=0;i<this.lensFlares.length;i++){var r=this.lensFlares[i];t.flares.push({size:r.size,position:r.position,color:r.color.asArray(),textureName:e.Tools.GetFilename(r.texture?r.texture.name:"")})}return t},t}();e.LensFlareSystem=t}(s||(s={}));!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.LockJoint=10,e}();e.PhysicsJoint=t;var i=function(e){function i(i){return e.call(this,t.DistanceJoint,i)||this}return n(i,e),i.prototype.updateDistance=function(e,t){this._physicsPlugin.updateDistanceJoint(this,e,t)},i}(t);e.DistanceJoint=i;var r=function(e){function t(t,i){return e.call(this,t,i)||this}return n(t,e),t.prototype.setMotor=function(e,t){this._physicsPlugin.setMotor(this,e||0,t)},t.prototype.setLimit=function(e,t){this._physicsPlugin.setLimit(this,e,t)},t}(t);e.MotorEnabledJoint=r;var o=function(e){function i(i){return e.call(this,t.HingeJoint,i)||this}return n(i,e),i.prototype.setMotor=function(e,t){this._physicsPlugin.setMotor(this,e||0,t)},i.prototype.setLimit=function(e,t){this._physicsPlugin.setLimit(this,e,t)},i}(r);e.HingeJoint=o;var s=function(e){function i(i){return e.call(this,t.Hinge2Joint,i)||this}return n(i,e),i.prototype.setMotor=function(e,t,i){void 0===i&&(i=0),this._physicsPlugin.setMotor(this,e||0,t,i)},i.prototype.setLimit=function(e,t,i){void 0===i&&(i=0),this._physicsPlugin.setLimit(this,e,t,i)},i}(r);e.Hinge2Joint=s}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n){void 0===r&&(r={mass:0});var o=this;this.object=t,this.type=i,this._options=r,this._scene=n,this._bodyUpdateRequired=!1,this._onBeforePhysicsStepCallbacks=new Array,this._onAfterPhysicsStepCallbacks=new Array,this._onPhysicsCollideCallbacks=[],this._deltaPosition=e.Vector3.Zero(),this._isDisposed=!1,this._tmpQuat=new e.Quaternion,this._tmpQuat2=new e.Quaternion,this.beforeStep=function(){o._physicsEngine&&(o.object.translate(o._deltaPosition,-1),o._deltaRotationConjugated&&o.object.rotationQuaternion&&o.object.rotationQuaternion.multiplyToRef(o._deltaRotationConjugated,o.object.rotationQuaternion),o.object.computeWorldMatrix(!1),o.object.parent&&o.object.rotationQuaternion?(o.getParentsRotation(),o._tmpQuat.multiplyToRef(o.object.rotationQuaternion,o._tmpQuat)):o._tmpQuat.copyFrom(o.object.rotationQuaternion||new e.Quaternion),o._options.disableBidirectionalTransformation||o.object.rotationQuaternion&&o._physicsEngine.getPhysicsPlugin().setPhysicsBodyTransformation(o,o.object.getAbsolutePivotPoint(),o._tmpQuat),o._onBeforePhysicsStepCallbacks.forEach(function(e){e(o)}))},this.afterStep=function(){o._physicsEngine&&(o._onAfterPhysicsStepCallbacks.forEach(function(e){e(o)}),o._physicsEngine.getPhysicsPlugin().setTransformationFromPhysicsBody(o),o.object.parent&&o.object.rotationQuaternion&&(o.getParentsRotation(),o._tmpQuat.conjugateInPlace(),o._tmpQuat.multiplyToRef(o.object.rotationQuaternion,o.object.rotationQuaternion)),o.object.setAbsolutePosition(o.object.position),o._deltaRotation&&o.object.rotationQuaternion&&o.object.rotationQuaternion.multiplyToRef(o._deltaRotation,o.object.rotationQuaternion),o.object.translate(o._deltaPosition,1))},this.onCollideEvent=null,this.onCollide=function(e){if((o._onPhysicsCollideCallbacks.length||o.onCollideEvent)&&o._physicsEngine){var t=o._physicsEngine.getImpostorWithPhysicsBody(e.body);t&&(o.onCollideEvent&&o.onCollideEvent(o,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._scene&&(this._physicsEngine=this._scene.getPhysicsEngine(),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===r.mass?0:r.mass,this._options.friction=void 0===r.friction?.2:r.friction,this._options.restitution=void 0===r.restitution?.2:r.restitution,this._joints=[],!this.object.parent||this._options.ignoreParent?this._init():this.object.parent.physicsImpostor&&e.Tools.Warn("You must affect impostors to children before affecting impostor to parent.")):e.Tools.Error("Physics not enabled. Please use scene.enablePhysics(...) before creating impostors."))):e.Tools.Error("No object was provided. A physics object is obligatory")}return Object.defineProperty(t.prototype,"isDisposed",{get:function(){return this._isDisposed},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"mass",{get:function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getBodyMass(this):0},set:function(e){this.setMass(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"friction",{get:function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getBodyFriction(this):0},set:function(e){this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().setBodyFriction(this,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"restitution",{get:function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getBodyRestitution(this):0},set:function(e){this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().setBodyRestitution(this,e)},enumerable:!0,configurable:!0}),t.prototype._init=function(){this._physicsEngine&&(this._physicsEngine.removeImpostor(this),this.physicsBody=null,this._parent=this._parent||this._getPhysicsParent(),this.parent&&!this._options.ignoreParent||this._physicsEngine.addImpostor(this))},t.prototype._getPhysicsParent=function(){return this.object.parent instanceof e.AbstractMesh?this.object.parent.physicsImpostor:null},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._options.ignoreParent&&this.parent.forceUpdate()},Object.defineProperty(t.prototype,"physicsBody",{get:function(){return this._parent&&!this._options.ignoreParent?this._parent.physicsBody:this._physicsBody},set:function(e){this._physicsBody&&this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().removePhysicsBody(this),this._physicsBody=e,this.resetUpdateFlags()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return!this._options.ignoreParent&&this._parent?this._parent:null},set:function(e){this._parent=e},enumerable:!0,configurable:!0}),t.prototype.resetUpdateFlags=function(){this._bodyUpdateRequired=!1},t.prototype.getObjectExtendSize=function(){if(this.object.getBoundingInfo){var i=this.object.rotationQuaternion;this.object.rotationQuaternion=t.IDENTITY_QUATERNION,this.object.computeWorldMatrix&&this.object.computeWorldMatrix(!0);var r=this.object.getBoundingInfo(),n=void 0;return n=r?r.boundingBox.extendSizeWorld.scale(2):e.Vector3.Zero(),this.object.rotationQuaternion=i,this.object.computeWorldMatrix&&this.object.computeWorldMatrix(!0),n}return t.DEFAULT_OBJECT_SIZE},t.prototype.getObjectCenter=function(){if(this.object.getBoundingInfo){var e=this.object.getBoundingInfo();return e?e.boundingBox.centerWorld:this.object.position}return 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&&this._physicsEngine.getPhysicsPlugin().setBodyMass(this,e)},t.prototype.getLinearVelocity=function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getLinearVelocity(this):e.Vector3.Zero()},t.prototype.setLinearVelocity=function(e){this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().setLinearVelocity(this,e)},t.prototype.getAngularVelocity=function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getAngularVelocity(this):e.Vector3.Zero()},t.prototype.setAngularVelocity=function(e){this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().setAngularVelocity(this,e)},t.prototype.executeNativeFunction=function(e){this._physicsEngine&&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 r=t instanceof Array?t:[t],n=this._onPhysicsCollideCallbacks.indexOf({callback:i,otherImpostors:r});n>-1?this._onPhysicsCollideCallbacks.splice(n,1):e.Tools.Warn("Function to remove was not found")},t.prototype.getParentsRotation=function(){var t=this.object.parent;for(this._tmpQuat.copyFromFloats(0,0,0,1);t;)t.rotationQuaternion?this._tmpQuat2.copyFrom(t.rotationQuaternion):e.Quaternion.RotationYawPitchRollToRef(t.rotation.y,t.rotation.x,t.rotation.z,this._tmpQuat2),this._tmpQuat.multiplyToRef(this._tmpQuat2,this._tmpQuat),t=t.parent;return this._tmpQuat},t.prototype.applyForce=function(e,t){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().applyForce(this,e,t),this},t.prototype.applyImpulse=function(e,t){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().applyImpulse(this,e,t),this},t.prototype.createJoint=function(t,i,r){var n=new e.PhysicsJoint(i,r);return this.addJoint(t,n),this},t.prototype.addJoint=function(e,t){return this._joints.push({otherImpostor:e,joint:t}),this._physicsEngine&&this._physicsEngine.addJoint(this,e,t),this},t.prototype.sleep=function(){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().sleepBody(this),this},t.prototype.wakeUp=function(){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().wakeUpBody(this),this},t.prototype.clone=function(e){return e?new t(e,this.type,this._options,this._scene):null},t.prototype.dispose=function(){var e=this;this._physicsEngine&&(this._joints.forEach(function(t){e._physicsEngine&&e._physicsEngine.removeJoint(e,t.otherImpostor,t.joint)}),this._physicsEngine.removeImpostor(this),this.parent&&this.parent.forceUpdate(),this._isDisposed=!0)},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.prototype.getBoxSizeToRef=function(e){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().getBoxSizeToRef(this,e),this},t.prototype.getRadius=function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getRadius(this):0},t.prototype.syncBoneWithImpostor=function(i,r,n,o,s){var a=t._tmpVecs[0],l=this.object;if(l.rotationQuaternion)if(s){var h=t._tmpQuat;l.rotationQuaternion.multiplyToRef(s,h),i.setRotationQuaternion(h,e.Space.WORLD,r)}else i.setRotationQuaternion(l.rotationQuaternion,e.Space.WORLD,r);a.x=0,a.y=0,a.z=0,n&&(a.x=n.x,a.y=n.y,a.z=n.z,i.getDirectionToRef(a,r,a),void 0!==o&&null!==o||(o=n.length()),a.x*=o,a.y*=o,a.z*=o),i.getParent()?(a.addInPlace(l.getAbsolutePosition()),i.setAbsolutePosition(a,r)):(r.setAbsolutePosition(l.getAbsolutePosition()),r.position.x-=a.x,r.position.y-=a.y,r.position.z-=a.z)},t.prototype.syncImpostorWithBone=function(i,r,n,o,s,a){var l=this.object;if(l.rotationQuaternion)if(s){var h=t._tmpQuat;i.getRotationQuaternionToRef(e.Space.WORLD,r,h),h.multiplyToRef(s,l.rotationQuaternion)}else i.getRotationQuaternionToRef(e.Space.WORLD,r,l.rotationQuaternion);var u=t._tmpVecs[0],c=t._tmpVecs[1];a||((a=t._tmpVecs[2]).x=0,a.y=1,a.z=0),i.getDirectionToRef(a,r,c),i.getAbsolutePositionToRef(r,u),void 0!==o&&null!==o||!n||(o=n.length()),void 0!==o&&null!==o&&(u.x+=c.x*o,u.y+=c.y*o,u.z+=c.z*o),l.setAbsolutePosition(u)},t.DEFAULT_OBJECT_SIZE=new e.Vector3(1,1,1),t.IDENTITY_QUATERNION=e.Quaternion.Identity(),t._tmpVecs=[e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero()],t._tmpQuat=e.Quaternion.Identity(),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}(s||(s={}));!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.getTimeStep=function(){return this._physicsPlugin.getTimeStep()},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 r={mainImpostor:e,connectedImpostor:t,joint:i};i.physicsPlugin=this._physicsPlugin,this._joints.push(r),this._physicsPlugin.generateJoint(r)},t.prototype.removeJoint=function(e,t,i){var r=this._joints.filter(function(r){return r.connectedImpostor===t&&r.joint===i&&r.mainImpostor===e});r.length&&this._physicsPlugin.removeJoint(r[0])},t.prototype._step=function(e){var t=this;this._impostors.forEach(function(e){e.isBodyInitRequired()&&t._physicsPlugin.generatePhysicsBody(e)}),e>.1?e=.1:e<=0&&(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];return null},t.prototype.getImpostorWithPhysicsBody=function(e){for(var t=0;t<this._impostors.length;++t)if(this._impostors[t].physicsBody===e)return this._impostors[t];return null},t.Epsilon=.001,t}();e.PhysicsEngine=t}(s||(s={}));!function(e){var t=function(){function t(t,r){void 0===t&&(t=!0),void 0===r&&(r=10),this._useDeltaForWorldStep=t,this.name="CannonJSPlugin",this._physicsMaterials=new Array,this._fixedTimeStep=1/60,this.BJSCANNON="undefined"!=typeof CANNON?CANNON:i(15),this._minus90X=new e.Quaternion(-.7071067811865475,0,0,.7071067811865475),this._plus90X=new e.Quaternion(.7071067811865475,0,0,.7071067811865475),this._tmpPosition=e.Vector3.Zero(),this._tmpDeltaPosition=e.Vector3.Zero(),this._tmpUnityRotation=new e.Quaternion,this.isSupported()?(this.world=new this.BJSCANNON.World,this.world.broadphase=new this.BJSCANNON.NaiveBroadphase,this.world.solver.iterations=r):e.Tools.Error("CannonJS is not available. Please make sure you included the js file.")}return t.prototype.setGravity=function(e){this.world.gravity.copy(e)},t.prototype.setTimeStep=function(e){this._fixedTimeStep=e},t.prototype.getTimeStep=function(){return this._fixedTimeStep},t.prototype.executeStep=function(e,t){this.world.step(this._fixedTimeStep,this._useDeltaForWorldStep?e:0,3)},t.prototype.applyImpulse=function(e,t,i){var r=new this.BJSCANNON.Vec3(i.x,i.y,i.z),n=new this.BJSCANNON.Vec3(t.x,t.y,t.z);e.physicsBody.applyImpulse(n,r)},t.prototype.applyForce=function(e,t,i){var r=new this.BJSCANNON.Vec3(i.x,i.y,i.z),n=new this.BJSCANNON.Vec3(t.x,t.y,t.z);e.physicsBody.applyForce(n,r)},t.prototype.generatePhysicsBody=function(e){if(e.parent)e.physicsBody&&(this.removePhysicsBody(e),e.forceUpdate());else{if(e.isBodyInitRequired()){var t=this._createShape(e),i=e.physicsBody;i&&this.removePhysicsBody(e);var r=this._addMaterial("mat-"+e.uniqueId,e.getParam("friction"),e.getParam("restitution")),n={mass:e.getParam("mass"),material:r},o=e.getParam("nativeOptions");for(var s in o)o.hasOwnProperty(s)&&(n[s]=o[s]);e.physicsBody=new this.BJSCANNON.Body(n),e.physicsBody.addEventListener("collide",e.onCollide),this.world.addEventListener("preStep",e.beforeStep),this.world.addEventListener("postStep",e.afterStep),e.physicsBody.addShape(t),this.world.add(e.physicsBody),i&&["force","torque","velocity","angularVelocity"].forEach(function(t){e.physicsBody[t].copy(i[t])}),this._processChildMeshes(e)}this._updatePhysicsBodyTransformation(e)}},t.prototype._processChildMeshes=function(t){var i=this,r=t.object.getChildMeshes?t.object.getChildMeshes(!0):[],n=t.object.rotationQuaternion;if(r.length){var o=function(r,s){if(n&&s.rotationQuaternion){var a=s.getPhysicsImpostor();if(a&&a.parent!==t){var l=s.getAbsolutePosition().subtract(t.object.getAbsolutePosition()),h=s.rotationQuaternion.multiply(e.Quaternion.Inverse(n));a.physicsBody&&(i.removePhysicsBody(a),a.physicsBody=null),a.parent=t,a.resetUpdateFlags(),t.physicsBody.addShape(i._createShape(a),new i.BJSCANNON.Vec3(l.x,l.y,l.z),new i.BJSCANNON.Quaternion(h.x,h.y,h.z,h.w)),t.physicsBody.mass+=a.getParam("mass")}n.multiplyInPlace(s.rotationQuaternion),s.getChildMeshes(!0).filter(function(e){return!!e.physicsImpostor}).forEach(o.bind(i,s.getAbsolutePosition()))}};r.filter(function(e){return!!e.physicsImpostor}).forEach(o.bind(this,t.object.getAbsolutePosition()))}},t.prototype.removePhysicsBody=function(e){e.physicsBody.removeEventListener("collide",e.onCollide),this.world.removeEventListener("preStep",e.beforeStep),this.world.removeEventListener("postStep",e.afterStep),this.world.remove(e.physicsBody)},t.prototype.generateJoint=function(t){var i=t.mainImpostor.physicsBody,r=t.connectedImpostor.physicsBody;if(i&&r){var n,o=t.joint.jointData,s={pivotA:o.mainPivot?(new this.BJSCANNON.Vec3).copy(o.mainPivot):null,pivotB:o.connectedPivot?(new this.BJSCANNON.Vec3).copy(o.connectedPivot):null,axisA:o.mainAxis?(new this.BJSCANNON.Vec3).copy(o.mainAxis):null,axisB:o.connectedAxis?(new this.BJSCANNON.Vec3).copy(o.connectedAxis):null,maxForce:o.nativeParams.maxForce,collideConnected:!!o.collision};switch(t.joint.type){case e.PhysicsJoint.HingeJoint:case e.PhysicsJoint.Hinge2Joint:n=new this.BJSCANNON.HingeConstraint(i,r,s);break;case e.PhysicsJoint.DistanceJoint:n=new this.BJSCANNON.DistanceConstraint(i,r,o.maxDistance||2);break;case e.PhysicsJoint.SpringJoint:var a=o;n=new this.BJSCANNON.Spring(i,r,{restLength:a.length,stiffness:a.stiffness,damping:a.damping,localAnchorA:s.pivotA,localAnchorB:s.pivotB});break;case e.PhysicsJoint.LockJoint:n=new this.BJSCANNON.LockConstraint(i,r,s);break;case e.PhysicsJoint.PointToPointJoint:case e.PhysicsJoint.BallAndSocketJoint:default:n=new this.BJSCANNON.PointToPointConstraint(i,s.pivotA,r,s.pivotA,s.maxForce)}n.collideConnected=!!o.collision,t.joint.physicsJoint=n,t.joint.type!==e.PhysicsJoint.SpringJoint?this.world.addConstraint(n):t.mainImpostor.registerAfterPhysicsStep(function(){n.applyForce()})}},t.prototype.removeJoint=function(e){this.world.removeConstraint(e.joint.physicsJoint)},t.prototype._addMaterial=function(e,t,i){var r,n;for(r=0;r<this._physicsMaterials.length;r++)if((n=this._physicsMaterials[r]).friction===t&&n.restitution===i)return n;var o=new this.BJSCANNON.Material(e);return o.friction=t,o.restitution=i,this._physicsMaterials.push(o),o},t.prototype._checkWithEpsilon=function(t){return t<e.PhysicsEngine.Epsilon?e.PhysicsEngine.Epsilon:t},t.prototype._createShape=function(t){var i,r=t.object,n=t.getObjectExtendSize();switch(t.type){case e.PhysicsImpostor.SphereImpostor:var o=n.x,s=n.y,a=n.z;i=new this.BJSCANNON.Sphere(Math.max(this._checkWithEpsilon(o),this._checkWithEpsilon(s),this._checkWithEpsilon(a))/2);break;case e.PhysicsImpostor.CylinderImpostor:i=new this.BJSCANNON.Cylinder(this._checkWithEpsilon(n.x)/2,this._checkWithEpsilon(n.x)/2,this._checkWithEpsilon(n.y),16);break;case e.PhysicsImpostor.BoxImpostor:var l=n.scale(.5);i=new this.BJSCANNON.Box(new this.BJSCANNON.Vec3(this._checkWithEpsilon(l.x),this._checkWithEpsilon(l.y),this._checkWithEpsilon(l.z)));break;case e.PhysicsImpostor.PlaneImpostor:e.Tools.Warn("Attention, PlaneImposter might not behave as you expect. Consider using BoxImposter instead"),i=new this.BJSCANNON.Plane;break;case e.PhysicsImpostor.MeshImpostor:var h=r.getVerticesData?r.getVerticesData(e.VertexBuffer.PositionKind):[],u=r.getIndices?r.getIndices():[];if(!h)return;var c=r.position.clone(),f=r.rotation&&r.rotation.clone(),p=r.rotationQuaternion&&r.rotationQuaternion.clone();r.position.copyFromFloats(0,0,0),r.rotation&&r.rotation.copyFromFloats(0,0,0),r.rotationQuaternion&&r.rotationQuaternion.copyFrom(t.getParentsRotation()),r.rotationQuaternion&&r.parent&&r.rotationQuaternion.conjugateInPlace();var d,m=r.computeWorldMatrix(!0),g=new Array;for(d=0;d<h.length;d+=3)e.Vector3.TransformCoordinates(e.Vector3.FromArray(h,d),m).toArray(g,d);e.Tools.Warn("MeshImpostor only collides against spheres."),i=new this.BJSCANNON.Trimesh(g,u),r.position.copyFrom(c),f&&r.rotation&&r.rotation.copyFrom(f),p&&r.rotationQuaternion&&r.rotationQuaternion.copyFrom(p);break;case e.PhysicsImpostor.HeightmapImpostor:var v=r.position.clone(),_=r.rotation&&r.rotation.clone(),y=r.rotationQuaternion&&r.rotationQuaternion.clone();r.position.copyFromFloats(0,0,0),r.rotation&&r.rotation.copyFromFloats(0,0,0),r.rotationQuaternion&&r.rotationQuaternion.copyFrom(t.getParentsRotation()),r.rotationQuaternion&&r.parent&&r.rotationQuaternion.conjugateInPlace(),r.rotationQuaternion&&r.rotationQuaternion.multiplyInPlace(this._minus90X),i=this._createHeightmap(r),r.position.copyFrom(v),_&&r.rotation&&r.rotation.copyFrom(_),y&&r.rotationQuaternion&&r.rotationQuaternion.copyFrom(y),r.computeWorldMatrix(!0);break;case e.PhysicsImpostor.ParticleImpostor:i=new this.BJSCANNON.Particle}return i},t.prototype._createHeightmap=function(t,i){var r,n=t.getVerticesData(e.VertexBuffer.PositionKind),o=t.computeWorldMatrix(!0),s=new Array;for(r=0;r<n.length;r+=3)e.Vector3.TransformCoordinates(e.Vector3.FromArray(n,r),o).toArray(s,r);n=s;for(var a=new Array,l=i||~~(Math.sqrt(n.length/3)-1),h=t.getBoundingInfo(),u=Math.min(h.boundingBox.extendSizeWorld.x,h.boundingBox.extendSizeWorld.y),c=h.boundingBox.extendSizeWorld.z,f=2*u/l,p=0;p<n.length;p+=3){var d=Math.round(n[p+0]/f+l/2),m=Math.round(-1*(n[p+1]/f-l/2)),g=-n[p+2]+c;a[d]||(a[d]=[]),a[d][m]||(a[d][m]=g),a[d][m]=Math.max(g,a[d][m])}for(d=0;d<=l;++d){if(!a[d]){for(_=1;!a[(d+_)%l];)_++;a[d]=a[(d+_)%l].slice()}for(m=0;m<=l;++m)if(!a[d][m]){for(var v,_=1;void 0===v;)v=a[d][(m+_++)%l];a[d][m]=v}}var y=new this.BJSCANNON.Heightfield(a,{elementSize:f});return y.minY=c,y},t.prototype._updatePhysicsBodyTransformation=function(t){var i=t.object;if(i.computeWorldMatrix&&i.computeWorldMatrix(!0),i.getBoundingInfo()){var r=t.getObjectCenter();this._tmpDeltaPosition.copyFrom(i.getAbsolutePivotPoint().subtract(r)),this._tmpPosition.copyFrom(r);var n=i.rotationQuaternion;if(n){if(t.type!==e.PhysicsImpostor.PlaneImpostor&&t.type!==e.PhysicsImpostor.HeightmapImpostor&&t.type!==e.PhysicsImpostor.CylinderImpostor||(n=n.multiply(this._minus90X),t.setDeltaRotation(this._plus90X)),t.type===e.PhysicsImpostor.HeightmapImpostor){var o=i,s=o.getBoundingInfo(),a=o.rotationQuaternion;o.rotationQuaternion=this._tmpUnityRotation,o.computeWorldMatrix(!0);var l=r.clone(),h=o.getPivotMatrix()||e.Matrix.Translation(0,0,0),u=e.Matrix.Translation(s.boundingBox.extendSizeWorld.x,0,-s.boundingBox.extendSizeWorld.z);o.setPivotMatrix(u),o.computeWorldMatrix(!0);var c=s.boundingBox.centerWorld.subtract(r).subtract(o.position).negate();this._tmpPosition.copyFromFloats(c.x,c.y-s.boundingBox.extendSizeWorld.y,c.z),this._tmpDeltaPosition.copyFrom(s.boundingBox.centerWorld.subtract(l)),this._tmpDeltaPosition.y+=s.boundingBox.extendSizeWorld.y,o.rotationQuaternion=a,o.setPivotMatrix(h),o.computeWorldMatrix(!0)}else t.type===e.PhysicsImpostor.MeshImpostor&&this._tmpDeltaPosition.copyFromFloats(0,0,0);t.setDeltaPosition(this._tmpDeltaPosition),t.physicsBody.position.copy(this._tmpPosition),t.physicsBody.quaternion.copy(n)}}},t.prototype.setTransformationFromPhysicsBody=function(e){e.object.position.copyFrom(e.physicsBody.position),e.object.rotationQuaternion&&e.object.rotationQuaternion.copyFrom(e.physicsBody.quaternion)},t.prototype.setPhysicsBodyTransformation=function(e,t,i){e.physicsBody.position.copy(t),e.physicsBody.quaternion.copy(i)},t.prototype.isSupported=function(){return void 0!==this.BJSCANNON},t.prototype.setLinearVelocity=function(e,t){e.physicsBody.velocity.copy(t)},t.prototype.setAngularVelocity=function(e,t){e.physicsBody.angularVelocity.copy(t)},t.prototype.getLinearVelocity=function(t){var i=t.physicsBody.velocity;return i?new e.Vector3(i.x,i.y,i.z):null},t.prototype.getAngularVelocity=function(t){var i=t.physicsBody.angularVelocity;return i?new e.Vector3(i.x,i.y,i.z):null},t.prototype.setBodyMass=function(e,t){e.physicsBody.mass=t,e.physicsBody.updateMassProperties()},t.prototype.getBodyMass=function(e){return e.physicsBody.mass},t.prototype.getBodyFriction=function(e){return e.physicsBody.material.friction},t.prototype.setBodyFriction=function(e,t){e.physicsBody.material.friction=t},t.prototype.getBodyRestitution=function(e){return e.physicsBody.material.restitution},t.prototype.setBodyRestitution=function(e,t){e.physicsBody.material.restitution=t},t.prototype.sleepBody=function(e){e.physicsBody.sleep()},t.prototype.wakeUpBody=function(e){e.physicsBody.wakeUp()},t.prototype.updateDistanceJoint=function(e,t,i){e.physicsJoint.distance=t},t.prototype.setMotor=function(e,t,i,r){r||(e.physicsJoint.enableMotor(),e.physicsJoint.setMotorSpeed(t),i&&this.setLimit(e,i))},t.prototype.setLimit=function(e,t,i){e.physicsJoint.motorEquation.maxForce=t,e.physicsJoint.motorEquation.minForce=void 0===i?-t:i},t.prototype.syncMeshWithImpostor=function(e,t){var i=t.physicsBody;e.position.x=i.position.x,e.position.y=i.position.y,e.position.z=i.position.z,e.rotationQuaternion&&(e.rotationQuaternion.x=i.quaternion.x,e.rotationQuaternion.y=i.quaternion.y,e.rotationQuaternion.z=i.quaternion.z,e.rotationQuaternion.w=i.quaternion.w)},t.prototype.getRadius=function(e){return e.physicsBody.shapes[0].boundingSphereRadius},t.prototype.getBoxSizeToRef=function(e,t){var i=e.physicsBody.shapes[0];t.x=2*i.halfExtents.x,t.y=2*i.halfExtents.y,t.z=2*i.halfExtents.z},t.prototype.dispose=function(){},t}();e.CannonJSPlugin=t}(s||(s={}));!function(e){var t=function(){function t(t){this.name="OimoJSPlugin",this._tmpImpostorsArray=[],this._tmpPositionVector=e.Vector3.Zero(),this.BJSOIMO="undefined"!=typeof OIMO?OIMO:i(16),this.world=new this.BJSOIMO.World(1/60,2,t,!0),this.world.worldscale(1),this.world.clear(),this.world.isNoStat=!0}return t.prototype.setGravity=function(e){this.world.gravity.copy(e)},t.prototype.setTimeStep=function(e){this.world.timeStep=e},t.prototype.getTimeStep=function(){return this.world.timeStep},t.prototype.executeStep=function(e,t){var i=this;t.forEach(function(e){e.beforeStep()}),this.world.step(),t.forEach(function(e){e.afterStep(),i._tmpImpostorsArray[e.uniqueId]=e});for(var r=this.world.contacts;null!==r;)if(!r.touching||r.body1.sleeping||r.body2.sleeping){var n=this._tmpImpostorsArray[+r.body1.name],o=this._tmpImpostorsArray[+r.body2.name];n&&o?(n.onCollide({body:o.physicsBody}),o.onCollide({body:n.physicsBody}),r=r.next):r=r.next}else r=r.next},t.prototype.applyImpulse=function(e,t,i){var r=e.physicsBody.massInfo.mass;e.physicsBody.applyImpulse(i.scale(this.BJSOIMO.INV_SCALE),t.scale(this.BJSOIMO.INV_SCALE*r))},t.prototype.applyForce=function(t,i,r){e.Tools.Warn("Oimo doesn't support applying force. Using impule instead."),this.applyImpulse(t,i,r)},t.prototype.generatePhysicsBody=function(t){var i=this;if(t.parent)t.physicsBody&&(this.removePhysicsBody(t),t.forceUpdate());else{if(t.isBodyInitRequired()){var r={name:t.uniqueId,config:[t.getParam("mass")||1,t.getParam("friction"),t.getParam("restitution")],size:[],type:[],pos:[],rot:[],move:0!==t.getParam("mass"),world:this.world},n=[t];(function(e){e.getChildMeshes&&e.getChildMeshes().forEach(function(e){e.physicsImpostor&&n.push(e.physicsImpostor)})})(t.object);var o=function(t){return Math.max(t,e.PhysicsEngine.Epsilon)};n.forEach(function(n){if(t.object.rotationQuaternion){var s=n.object.rotationQuaternion,a=(new i.BJSOIMO.Euler).setFromQuaternion({x:t.object.rotationQuaternion.x,y:t.object.rotationQuaternion.y,z:t.object.rotationQuaternion.z,s:t.object.rotationQuaternion.w}),l=n.getObjectExtendSize();if(n===t){var h=t.getObjectCenter();t.object.position.subtractToRef(h,i._tmpPositionVector),r.pos.push(h.x),r.pos.push(h.y),r.pos.push(h.z),r.rot.push(a.x/(i.BJSOIMO.degtorad||i.BJSOIMO.TO_RAD)),r.rot.push(a.y/(i.BJSOIMO.degtorad||i.BJSOIMO.TO_RAD)),r.rot.push(a.z/(i.BJSOIMO.degtorad||i.BJSOIMO.TO_RAD))}else{var u=n.object.getAbsolutePosition().subtract(t.object.getAbsolutePosition());r.pos.push(u.x),r.pos.push(u.y),r.pos.push(u.z),r.rot.push(0),r.rot.push(0),r.rot.push(0)}switch(n.type){case e.PhysicsImpostor.ParticleImpostor:e.Tools.Warn("No Particle support in this.BJSOIMO.js. using SphereImpostor instead");case e.PhysicsImpostor.SphereImpostor:var c=l.x,f=l.y,p=l.z,d=Math.max(o(c),o(f),o(p))/2;r.type.push("sphere"),r.size.push(d),r.size.push(d),r.size.push(d);break;case e.PhysicsImpostor.CylinderImpostor:var m=o(l.x)/2,g=o(l.y);r.type.push("cylinder"),r.size.push(m),r.size.push(g),r.size.push(g);break;case e.PhysicsImpostor.PlaneImpostor:case e.PhysicsImpostor.BoxImpostor:default:var m=o(l.x),g=o(l.y),v=o(l.z);r.type.push("box"),r.size.push(m),r.size.push(g),r.size.push(v)}n.object.rotationQuaternion=s}}),t.physicsBody=new this.BJSOIMO.Body(r).body}else this._tmpPositionVector.copyFromFloats(0,0,0);t.setDeltaPosition(this._tmpPositionVector)}},t.prototype.removePhysicsBody=function(e){this.world.removeRigidBody(e.physicsBody)},t.prototype.generateJoint=function(t){var i=t.mainImpostor.physicsBody,r=t.connectedImpostor.physicsBody;if(i&&r){var n,o=t.joint.jointData,s=o.nativeParams||{},a={body1:i,body2:r,axe1:s.axe1||(o.mainAxis?o.mainAxis.asArray():null),axe2:s.axe2||(o.connectedAxis?o.connectedAxis.asArray():null),pos1:s.pos1||(o.mainPivot?o.mainPivot.asArray():null),pos2:s.pos2||(o.connectedPivot?o.connectedPivot.asArray():null),min:s.min,max:s.max,collision:s.collision||o.collision,spring:s.spring,world:this.world};switch(t.joint.type){case e.PhysicsJoint.BallAndSocketJoint:n="jointBall";break;case e.PhysicsJoint.SpringJoint:e.Tools.Warn("this.BJSOIMO.js doesn't support Spring Constraint. Simulating using DistanceJoint instead");var l=o;a.min=l.length||a.min,a.max=Math.max(a.min,a.max);case e.PhysicsJoint.DistanceJoint:n="jointDistance",a.max=o.maxDistance;break;case e.PhysicsJoint.PrismaticJoint:n="jointPrisme";break;case e.PhysicsJoint.SliderJoint:n="jointSlide";break;case e.PhysicsJoint.WheelJoint:n="jointWheel";break;case e.PhysicsJoint.HingeJoint:default:n="jointHinge"}a.type=n,t.joint.physicsJoint=new this.BJSOIMO.Link(a).joint}},t.prototype.removeJoint=function(t){try{this.world.removeJoint(t.joint.physicsJoint)}catch(t){e.Tools.Warn(t)}},t.prototype.isSupported=function(){return void 0!==this.BJSOIMO},t.prototype.setTransformationFromPhysicsBody=function(e){if(!e.physicsBody.sleeping){if(e.physicsBody.shapes.next){var t=this._getLastShape(e.physicsBody);e.object.position.x=t.position.x*this.BJSOIMO.WORLD_SCALE,e.object.position.y=t.position.y*this.BJSOIMO.WORLD_SCALE,e.object.position.z=t.position.z*this.BJSOIMO.WORLD_SCALE}else e.object.position.copyFrom(e.physicsBody.getPosition());e.object.rotationQuaternion&&(e.object.rotationQuaternion.copyFrom(e.physicsBody.getQuaternion()),e.object.rotationQuaternion.normalize())}},t.prototype.setPhysicsBodyTransformation=function(e,t,i){var r=e.physicsBody;r.position.init(t.x*this.BJSOIMO.INV_SCALE,t.y*this.BJSOIMO.INV_SCALE,t.z*this.BJSOIMO.INV_SCALE),r.orientation.init(i.w,i.x,i.y,i.z),r.syncShapes(),r.awake()},t.prototype._getLastShape=function(e){for(var t=e.shapes;t.next;)t=t.next;return t},t.prototype.setLinearVelocity=function(e,t){e.physicsBody.linearVelocity.init(t.x,t.y,t.z)},t.prototype.setAngularVelocity=function(e,t){e.physicsBody.angularVelocity.init(t.x,t.y,t.z)},t.prototype.getLinearVelocity=function(t){var i=t.physicsBody.linearVelocity;return i?new e.Vector3(i.x,i.y,i.z):null},t.prototype.getAngularVelocity=function(t){var i=t.physicsBody.angularVelocity;return i?new e.Vector3(i.x,i.y,i.z):null},t.prototype.setBodyMass=function(e,t){var i=0===t;e.physicsBody.shapes.density=i?1:t,e.physicsBody.setupMass(i?2:1)},t.prototype.getBodyMass=function(e){return e.physicsBody.shapes.density},t.prototype.getBodyFriction=function(e){return e.physicsBody.shapes.friction},t.prototype.setBodyFriction=function(e,t){e.physicsBody.shapes.friction=t},t.prototype.getBodyRestitution=function(e){return e.physicsBody.shapes.restitution},t.prototype.setBodyRestitution=function(e,t){e.physicsBody.shapes.restitution=t},t.prototype.sleepBody=function(e){e.physicsBody.sleep()},t.prototype.wakeUpBody=function(e){e.physicsBody.awake()},t.prototype.updateDistanceJoint=function(e,t,i){e.physicsJoint.limitMotor.upperLimit=t,void 0!==i&&(e.physicsJoint.limitMotor.lowerLimit=i)},t.prototype.setMotor=function(e,t,i,r){var n=r?e.physicsJoint.rotationalLimitMotor2:e.physicsJoint.rotationalLimitMotor1||e.physicsJoint.rotationalLimitMotor||e.physicsJoint.limitMotor;n&&n.setMotor(t,i)},t.prototype.setLimit=function(e,t,i,r){var n=r?e.physicsJoint.rotationalLimitMotor2:e.physicsJoint.rotationalLimitMotor1||e.physicsJoint.rotationalLimitMotor||e.physicsJoint.limitMotor;n&&n.setLimit(t,void 0===i?-t:i)},t.prototype.syncMeshWithImpostor=function(e,t){var i=t.physicsBody;e.position.x=i.position.x,e.position.y=i.position.y,e.position.z=i.position.z,e.rotationQuaternion&&(e.rotationQuaternion.x=i.orientation.x,e.rotationQuaternion.y=i.orientation.y,e.rotationQuaternion.z=i.orientation.z,e.rotationQuaternion.w=i.orientation.s)},t.prototype.getRadius=function(e){return e.physicsBody.shapes.radius},t.prototype.getBoxSizeToRef=function(e,t){var i=e.physicsBody.shapes;t.x=2*i.halfWidth,t.y=2*i.halfHeight,t.z=2*i.halfDepth},t.prototype.dispose=function(){this.world.clear()},t}();e.OimoJSPlugin=t}(s||(s={}));!function(e){!function(t){var i=function(){function t(){}return t.GetTGAHeader=function(e){var t=0;return{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++]}},t.UploadContent=function(i,r){if(r.length<19)e.Tools.Error("Unable to load TGA file - Not enough data to contain header");else{var n=18,o=t.GetTGAHeader(r);if(o.id_length+n>r.length)e.Tools.Error("Unable to load TGA file - Not enough data");else{n+=o.id_length;var s=!1,a=!1,l=!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:!0;break;case t._TYPE_RLE_GREY:s=!0;case t._TYPE_GREY:l=!0}var h,u,c=o.pixel_size>>3,f=o.width*o.height*c;if(a&&(u=r.subarray(n,n+=o.colormap_length*(o.colormap_size>>3))),s){h=new Uint8Array(f);for(var p,d,m,g=0,v=new Uint8Array(c);n<f&&g<f;)if(p=r[n++],d=1+(127&p),128&p){for(m=0;m<c;++m)v[m]=r[n++];for(m=0;m<d;++m)h.set(v,g+m*c);g+=c*d}else{for(d*=c,m=0;m<d;++m)h[g+m]=r[n++];g+=d}}else h=r.subarray(n,n+=a?o.width*o.height:f);var _,y,x,b,T,E;switch((o.flags&t._ORIGIN_MASK)>>t._ORIGIN_SHIFT){default:case t._ORIGIN_UL:_=0,x=1,E=o.width,y=0,b=1,T=o.height;break;case t._ORIGIN_BL:_=0,x=1,E=o.width,y=o.height-1,b=-1,T=-1;break;case t._ORIGIN_UR:_=o.width-1,x=-1,E=-1,y=0,b=1,T=o.height;break;case t._ORIGIN_BR:_=o.width-1,x=-1,E=-1,y=o.height-1,b=-1,T=-1}var A=t["_getImageData"+(l?"Grey":"")+o.pixel_size+"bits"](o,u,h,y,b,T,_,x,E);i.texImage2D(i.TEXTURE_2D,0,i.RGBA,o.width,o.height,0,i.RGBA,i.UNSIGNED_BYTE,A)}}},t._getImageData8bits=function(e,t,i,r,n,o,s,a,l){var h,u,c,f=i,p=t,d=e.width,m=e.height,g=0,v=new Uint8Array(d*m*4);for(c=r;c!==o;c+=n)for(u=s;u!==l;u+=a,g++)h=f[g],v[4*(u+d*c)+3]=255,v[4*(u+d*c)+2]=p[3*h+0],v[4*(u+d*c)+1]=p[3*h+1],v[4*(u+d*c)+0]=p[3*h+2];return v},t._getImageData16bits=function(e,t,i,r,n,o,s,a,l){var h,u,c,f=i,p=e.width,d=e.height,m=0,g=new Uint8Array(p*d*4);for(c=r;c!==o;c+=n)for(u=s;u!==l;u+=a,m+=2)h=f[m+0]+(f[m+1]<<8),g[4*(u+p*c)+0]=(31744&h)>>7,g[4*(u+p*c)+1]=(992&h)>>2,g[4*(u+p*c)+2]=(31&h)>>3,g[4*(u+p*c)+3]=32768&h?0:255;return g},t._getImageData24bits=function(e,t,i,r,n,o,s,a,l){var h,u,c=i,f=e.width,p=e.height,d=0,m=new Uint8Array(f*p*4);for(u=r;u!==o;u+=n)for(h=s;h!==l;h+=a,d+=3)m[4*(h+f*u)+3]=255,m[4*(h+f*u)+2]=c[d+0],m[4*(h+f*u)+1]=c[d+1],m[4*(h+f*u)+0]=c[d+2];return m},t._getImageData32bits=function(e,t,i,r,n,o,s,a,l){var h,u,c=i,f=e.width,p=e.height,d=0,m=new Uint8Array(f*p*4);for(u=r;u!==o;u+=n)for(h=s;h!==l;h+=a,d+=4)m[4*(h+f*u)+2]=c[d+0],m[4*(h+f*u)+1]=c[d+1],m[4*(h+f*u)+0]=c[d+2],m[4*(h+f*u)+3]=c[d+3];return m},t._getImageDataGrey8bits=function(e,t,i,r,n,o,s,a,l){var h,u,c,f=i,p=e.width,d=e.height,m=0,g=new Uint8Array(p*d*4);for(c=r;c!==o;c+=n)for(u=s;u!==l;u+=a,m++)h=f[m],g[4*(u+p*c)+0]=h,g[4*(u+p*c)+1]=h,g[4*(u+p*c)+2]=h,g[4*(u+p*c)+3]=255;return g},t._getImageDataGrey16bits=function(e,t,i,r,n,o,s,a,l){var h,u,c=i,f=e.width,p=e.height,d=0,m=new Uint8Array(f*p*4);for(u=r;u!==o;u+=n)for(h=s;h!==l;h+=a,d+=2)m[4*(h+f*u)+0]=c[d+0],m[4*(h+f*u)+1]=c[d+0],m[4*(h+f*u)+2]=c[d+0],m[4*(h+f*u)+3]=c[d+1];return m},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}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){!function(t){function i(e){return e.charCodeAt(0)+(e.charCodeAt(1)<<8)+(e.charCodeAt(2)<<16)+(e.charCodeAt(3)<<24)}function r(e){return String.fromCharCode(255&e,e>>8&255,e>>16&255,e>>24&255)}var n=i("DXT1"),o=i("DXT3"),s=i("DXT5"),a=i("DX10"),l=function(){function t(){}return t.GetDDSInfo=function(t){var i=new Int32Array(t,0,31),r=new Int32Array(t,0,35),l=1;131072&i[2]&&(l=Math.max(1,i[7]));var h=i[21],u=h===a?r[32]:0,c=e.Engine.TEXTURETYPE_UNSIGNED_INT;switch(h){case 113:c=e.Engine.TEXTURETYPE_HALF_FLOAT;break;case 116:c=e.Engine.TEXTURETYPE_FLOAT;break;case a:if(10===u){c=e.Engine.TEXTURETYPE_HALF_FLOAT;break}}return{width:i[4],height:i[3],mipmapCount:l,isFourCC:4==(4&i[20]),isRGB:64==(64&i[20]),isLuminance:131072==(131072&i[20]),isCube:512==(512&i[28]),isCompressed:h===n||h===o||h===s,dxgiFormat:u,textureType:c}},t._ToHalfFloat=function(e){t._FloatView||(t._FloatView=new Float32Array(1),t._Int32View=new Int32Array(t._FloatView.buffer)),t._FloatView[0]=e;var i=t._Int32View[0],r=i>>16&32768,n=i>>12&2047,o=i>>23&255;return o<103?r:o>142?(r|=31744,r|=(255==o?0:1)&&8388607&i):o<113?(n|=2048,r|=(n>>114-o)+(n>>113-o&1)):(r|=o-112<<10|n>>1,r+=1&n)},t._FromHalfFloat=function(e){var t=(32768&e)>>15,i=(31744&e)>>10,r=1023&e;return 0===i?(t?-1:1)*Math.pow(2,-14)*(r/Math.pow(2,10)):31==i?r?NaN:1/0*(t?-1:1):(t?-1:1)*Math.pow(2,i-15)*(1+r/Math.pow(2,10))},t._GetHalfFloatAsFloatRGBAArrayBuffer=function(e,i,r,n,o,s){for(var a=new Float32Array(n),l=new Uint16Array(o,r),h=0,u=0;u<i;u++)for(var c=0;c<e;c++){var f=4*(c+u*e);a[h]=t._FromHalfFloat(l[f]),a[h+1]=t._FromHalfFloat(l[f+1]),a[h+2]=t._FromHalfFloat(l[f+2]),a[h+3]=t.StoreLODInAlphaChannel?s:t._FromHalfFloat(l[f+3]),h+=4}return a},t._GetHalfFloatRGBAArrayBuffer=function(e,i,r,n,o,s){if(t.StoreLODInAlphaChannel){for(var a=new Uint16Array(n),l=new Uint16Array(o,r),h=0,u=0;u<i;u++)for(var c=0;c<e;c++){var f=4*(c+u*e);a[h]=l[f],a[h+1]=l[f+1],a[h+2]=l[f+2],a[h+3]=t._ToHalfFloat(s),h+=4}return a}return new Uint16Array(o,r,n)},t._GetFloatRGBAArrayBuffer=function(e,i,r,n,o,s){if(t.StoreLODInAlphaChannel){for(var a=new Float32Array(n),l=new Float32Array(o,r),h=0,u=0;u<i;u++)for(var c=0;c<e;c++){var f=4*(c+u*e);a[h]=l[f],a[h+1]=l[f+1],a[h+2]=l[f+2],a[h+3]=s,h+=4}return a}return new Float32Array(o,r,n)},t._GetFloatAsUIntRGBAArrayBuffer=function(i,r,n,o,s,a){for(var l=new Uint8Array(o),h=new Float32Array(s,n),u=0,c=0;c<r;c++)for(var f=0;f<i;f++){var p=4*(f+c*i);l[u]=255*e.Scalar.Clamp(h[p]),l[u+1]=255*e.Scalar.Clamp(h[p+1]),l[u+2]=255*e.Scalar.Clamp(h[p+2]),l[u+3]=t.StoreLODInAlphaChannel?a:255*e.Scalar.Clamp(h[p+3]),u+=4}return l},t._GetHalfFloatAsUIntRGBAArrayBuffer=function(i,r,n,o,s,a){for(var l=new Uint8Array(o),h=new Uint16Array(s,n),u=0,c=0;c<r;c++)for(var f=0;f<i;f++){var p=4*(f+c*i);l[u]=255*e.Scalar.Clamp(t._FromHalfFloat(h[p])),l[u+1]=255*e.Scalar.Clamp(t._FromHalfFloat(h[p+1])),l[u+2]=255*e.Scalar.Clamp(t._FromHalfFloat(h[p+2])),l[u+3]=t.StoreLODInAlphaChannel?a:255*e.Scalar.Clamp(t._FromHalfFloat(h[p+3])),u+=4}return l},t._GetRGBAArrayBuffer=function(e,t,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n,i),a=0,l=0;l<t;l++)for(var h=0;h<e;h++){var u=4*(h+l*e);o[a]=s[u+2],o[a+1]=s[u+1],o[a+2]=s[u],o[a+3]=s[u+3],a+=4}return o},t._GetRGBArrayBuffer=function(e,t,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n,i),a=0,l=0;l<t;l++)for(var h=0;h<e;h++){var u=3*(h+l*e);o[a]=s[u+2],o[a+1]=s[u+1],o[a+2]=s[u],a+=3}return o},t._GetLuminanceArrayBuffer=function(e,t,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n,i),a=0,l=0;l<t;l++)for(var h=0;h<e;h++){var u=h+l*e;o[a]=s[u],a++}return o},t.UploadDDSLevels=function(i,l,h,u,c,f,p){void 0===p&&(p=-1);var d,m,g,v,_,y,x,b,T=i.getCaps().s3tc,E=new Int32Array(h,0,31),A=0,P=0,S=1;if(542327876==E[0])if(u.isFourCC||u.isRGB||u.isLuminance)if(!u.isCompressed||T){var M=E[22];_=E[1]+4;var C=!1;if(u.isFourCC)switch(d=E[21]){case n:S=8,A=T.COMPRESSED_RGBA_S3TC_DXT1_EXT;break;case o:S=16,A=T.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case s:S=16,A=T.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;case 113:case 116:C=!0;break;case a:_+=20;var R=!1;switch(u.dxgiFormat){case 10:C=!0,R=!0;break;case 88:u.isRGB=!0,u.isFourCC=!1,M=32,R=!0}if(R)break;default:return void console.error("Unsupported FourCC code:",r(d))}C&&(P=i._getWebGLTextureType(u.textureType),A=i._getRGBABufferInternalSizedFormat(u.textureType)),x=1,131072&E[2]&&!1!==c&&(x=Math.max(1,E[7]));for(var I=0;I<f;I++){var O=1===f?l.TEXTURE_2D:l.TEXTURE_CUBE_MAP_POSITIVE_X+I;for(m=E[4],g=E[3],b=0;b<x;++b){if(-1===p||p===b){var D=-1===p?b:0;if(!u.isCompressed&&u.isFourCC){v=m*g*4;var w=null;i.badOS||i.badDesktopOS||!i.getCaps().textureHalfFloat&&!i.getCaps().textureFloat?(128===M?w=t._GetFloatAsUIntRGBAArrayBuffer(m,g,_,v,h,D):64===M&&(w=t._GetHalfFloatAsUIntRGBAArrayBuffer(m,g,_,v,h,D)),u.textureType=e.Engine.TEXTURETYPE_UNSIGNED_INT,P=i._getWebGLTextureType(u.textureType),A=i._getRGBABufferInternalSizedFormat(u.textureType)):128===M?w=t._GetFloatRGBAArrayBuffer(m,g,_,v,h,D):64!==M||i.getCaps().textureHalfFloat?w=t._GetHalfFloatRGBAArrayBuffer(m,g,_,v,h,D):(w=t._GetHalfFloatAsFloatRGBAArrayBuffer(m,g,_,v,h,D),u.textureType=e.Engine.TEXTURETYPE_FLOAT,P=i._getWebGLTextureType(u.textureType),A=i._getRGBABufferInternalSizedFormat(u.textureType)),w&&i._uploadDataToTexture(O,D,A,m,g,l.RGBA,P,w)}else if(u.isRGB)24===M?(y=t._GetRGBArrayBuffer(m,g,_,v=m*g*3,h),i._uploadDataToTexture(O,D,l.RGB,m,g,l.RGB,l.UNSIGNED_BYTE,y)):(y=t._GetRGBAArrayBuffer(m,g,_,v=m*g*4,h),i._uploadDataToTexture(O,D,l.RGBA,m,g,l.RGBA,l.UNSIGNED_BYTE,y));else if(u.isLuminance){var L=l.getParameter(l.UNPACK_ALIGNMENT),F=m,N=Math.floor((m+L-1)/L)*L;y=t._GetLuminanceArrayBuffer(m,g,_,v=N*(g-1)+F,h),i._uploadDataToTexture(O,D,l.LUMINANCE,m,g,l.LUMINANCE,l.UNSIGNED_BYTE,y)}else v=Math.max(4,m)/4*Math.max(4,g)/4*S,y=new Uint8Array(h,_,v),i._uploadCompressedDataToTexture(O,D,A,m,g,y)}_+=m*g*(M/8),m*=.5,g*=.5,m=Math.max(1,m),g=Math.max(1,g)}}}else e.Tools.Error("Compressed textures are not supported on this platform.");else e.Tools.Error("Unsupported format, must contain a FourCC, RGB or LUMINANCE code");else e.Tools.Error("Invalid magic number in DDS header")},t.StoreLODInAlphaChannel=!1,t}();t.DDSTools=l}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){!function(t){var i=function(){function t(i,r,n,o){this.arrayBuffer=i;var s=new Uint8Array(this.arrayBuffer,0,12);if(171===s[0]&&75===s[1]&&84===s[2]&&88===s[3]&&32===s[4]&&49===s[5]&&49===s[6]&&187===s[7]&&13===s[8]&&10===s[9]&&26===s[10]&&10===s[11]){var a=new Int32Array(this.arrayBuffer,12,13),l=16909060===a[0];this.glType=l?this.switchEndainness(a[1]):a[1],this.glTypeSize=l?this.switchEndainness(a[2]):a[2],this.glFormat=l?this.switchEndainness(a[3]):a[3],this.glInternalFormat=l?this.switchEndainness(a[4]):a[4],this.glBaseInternalFormat=l?this.switchEndainness(a[5]):a[5],this.pixelWidth=l?this.switchEndainness(a[6]):a[6],this.pixelHeight=l?this.switchEndainness(a[7]):a[7],this.pixelDepth=l?this.switchEndainness(a[8]):a[8],this.numberOfArrayElements=l?this.switchEndainness(a[9]):a[9],this.numberOfFaces=l?this.switchEndainness(a[10]):a[10],this.numberOfMipmapLevels=l?this.switchEndainness(a[11]):a[11],this.bytesOfKeyValueData=l?this.switchEndainness(a[12]):a[12],0===this.glType?(this.numberOfMipmapLevels=Math.max(1,this.numberOfMipmapLevels),0!==this.pixelHeight&&0===this.pixelDepth?0===this.numberOfArrayElements?this.numberOfFaces===r?this.loadType=t.COMPRESSED_2D:e.Tools.Error("number of faces expected"+r+", but found "+this.numberOfFaces):e.Tools.Error("texture arrays not currently supported"):e.Tools.Error("only 2D textures currently supported")):e.Tools.Error("only compressed formats currently supported")}else e.Tools.Error("texture missing KTX identifier")}return t.prototype.switchEndainness=function(e){return(255&e)<<24|(65280&e)<<8|e>>8&65280|e>>24&255},t.prototype.uploadLevels=function(e,i){switch(this.loadType){case t.COMPRESSED_2D:this._upload2DCompressedLevels(e,i);break;case t.TEX_2D:case t.COMPRESSED_3D:case t.TEX_3D:}},t.prototype._upload2DCompressedLevels=function(e,i){for(var r=t.HEADER_LEN+this.bytesOfKeyValueData,n=this.pixelWidth,o=this.pixelHeight,s=i?this.numberOfMipmapLevels:1,a=0;a<s;a++){for(var l=new Int32Array(this.arrayBuffer,r,1)[0],h=0;h<this.numberOfFaces;h++){var u=1===this.numberOfFaces?e.TEXTURE_2D:e.TEXTURE_CUBE_MAP_POSITIVE_X+h,c=new Uint8Array(this.arrayBuffer,r+4,l);e.compressedTexImage2D(u,a,this.glInternalFormat,n,o,0,c),r+=l+4,r+=3-(l+3)%4}n=Math.max(1,.5*n),o=Math.max(1,.5*o)}},t.HEADER_LEN=64,t.COMPRESSED_2D=0,t.COMPRESSED_3D=1,t.TEX_2D=2,t.TEX_3D=3,t}();t.KhronosTextureContainer=i}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){!function(t){var i=function(){function t(t,i,r,n,o){void 0===n&&(n=!0),void 0===o&&(o=1),this.skeleton=t,this.mesh=i,this.autoUpdateBonesMatrices=n,this.renderingGroupId=o,this.color=e.Color3.White(),this._debugLines=new Array,this._isEnabled=!1,this._scene=r,this.update(),this._renderFunction=this.update.bind(this)}return Object.defineProperty(t.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(e){this._isEnabled!==e&&(this._isEnabled=e,e?this._scene.registerBeforeRender(this._renderFunction):this._scene.unregisterBeforeRender(this._renderFunction))},enumerable:!0,configurable:!0}),t.prototype._getBonePosition=function(t,i,r,n,o,s){void 0===n&&(n=0),void 0===o&&(o=0),void 0===s&&(s=0);var a=e.Tmp.Matrix[0],l=i.getParent();if(a.copyFrom(i.getLocalMatrix()),0!==n||0!==o||0!==s){var h=e.Tmp.Matrix[1];e.Matrix.IdentityToRef(h),h.m[12]=n,h.m[13]=o,h.m[14]=s,h.multiplyToRef(a,a)}l&&a.multiplyToRef(l.getAbsoluteTransform(),a),a.multiplyToRef(r,a),t.x=a.m[12],t.y=a.m[13],t.z=a.m[14]},t.prototype._getLinesForBonesWithLength=function(t,i){for(var r=t.length,n=this.mesh.position,o=0;o<r;o++){var s=t[o],a=this._debugLines[o];a||(a=[e.Vector3.Zero(),e.Vector3.Zero()],this._debugLines[o]=a),this._getBonePosition(a[0],s,i),this._getBonePosition(a[1],s,i,0,s.length,0),a[0].subtractInPlace(n),a[1].subtractInPlace(n)}},t.prototype._getLinesForBonesNoLength=function(t,i){for(var r=t.length,n=0,o=this.mesh.position,s=r-1;s>=0;s--){var a=t[s],l=a.getParent();if(l){var h=this._debugLines[n];h||(h=[e.Vector3.Zero(),e.Vector3.Zero()],this._debugLines[n]=h),a.getAbsolutePositionToRef(this.mesh,h[0]),l.getAbsolutePositionToRef(this.mesh,h[1]),h[0].subtractInPlace(o),h[1].subtractInPlace(o),n++}}},t.prototype.update=function(){this.autoUpdateBonesMatrices&&this.skeleton.computeAbsoluteTransforms(),void 0===this.skeleton.bones[0].length?this._getLinesForBonesNoLength(this.skeleton.bones,this.mesh.getWorldMatrix()):this._getLinesForBonesWithLength(this.skeleton.bones,this.mesh.getWorldMatrix()),this._debugMesh?e.MeshBuilder.CreateLineSystem("",{lines:this._debugLines,updatable:!0,instance:this._debugMesh},this._scene):(this._debugMesh=e.MeshBuilder.CreateLineSystem("",{lines:this._debugLines,updatable:!0,instance:null},this._scene),this._debugMesh.renderingGroupId=this.renderingGroupId),this._debugMesh.position.copyFrom(this.mesh.position),this._debugMesh.color=this.color},t.prototype.dispose=function(){this._debugMesh&&(this.isEnabled=!1,this._debugMesh.dispose(),this._debugMesh=null)},t}();t.SkeletonViewer=i}(e.Debug||(e.Debug={}))}(s||(s={}));!function(e){!function(t){var i=function(){function t(t,i){void 0===i&&(i=1),this._xline=[e.Vector3.Zero(),e.Vector3.Zero()],this._yline=[e.Vector3.Zero(),e.Vector3.Zero()],this._zline=[e.Vector3.Zero(),e.Vector3.Zero()],this.scaleLines=1,this.scaleLines=i,this._xmesh=e.Mesh.CreateLines("xline",this._xline,t,!0),this._ymesh=e.Mesh.CreateLines("yline",this._yline,t,!0),this._zmesh=e.Mesh.CreateLines("zline",this._zline,t,!0),this._xmesh.renderingGroupId=2,this._ymesh.renderingGroupId=2,this._zmesh.renderingGroupId=2,this._xmesh.material.checkReadyOnlyOnce=!0,this._xmesh.color=new e.Color3(1,0,0),this._ymesh.material.checkReadyOnlyOnce=!0,this._ymesh.color=new e.Color3(0,1,0),this._zmesh.material.checkReadyOnlyOnce=!0,this._zmesh.color=new e.Color3(0,0,1),this.scene=t}return t.prototype.update=function(t,i,r,n){var o=this.scaleLines;this._xmesh&&this._xmesh.position.copyFrom(t),this._ymesh&&this._ymesh.position.copyFrom(t),this._zmesh&&this._zmesh.position.copyFrom(t);var s=this._xline[1];s.x=i.x*o,s.y=i.y*o,s.z=i.z*o,e.Mesh.CreateLines("",this._xline,null,!1,this._xmesh),(s=this._yline[1]).x=r.x*o,s.y=r.y*o,s.z=r.z*o,e.Mesh.CreateLines("",this._yline,null,!1,this._ymesh),(s=this._zline[1]).x=n.x*o,s.y=n.y*o,s.z=n.z*o,e.Mesh.CreateLines("",this._zline,null,!1,this._zmesh)},t.prototype.dispose=function(){this._xmesh&&this._xmesh.dispose(),this._ymesh&&this._ymesh.dispose(),this._zmesh&&this._zmesh.dispose(),this._xmesh=null,this._ymesh=null,this._zmesh=null,this.scene=null},t}();t.AxesViewer=i}(e.Debug||(e.Debug={}))}(s||(s={}));!function(e){!function(t){var i=function(t){function i(i,r,n,o){void 0===o&&(o=1);var s=t.call(this,i,o)||this;return s.pos=e.Vector3.Zero(),s.xaxis=e.Vector3.Zero(),s.yaxis=e.Vector3.Zero(),s.zaxis=e.Vector3.Zero(),s.mesh=n,s.bone=r,s}return n(i,t),i.prototype.update=function(){if(this.mesh&&this.bone){var i=this.bone;i.getAbsolutePositionToRef(this.mesh,this.pos),i.getDirectionToRef(e.Axis.X,this.mesh,this.xaxis),i.getDirectionToRef(e.Axis.Y,this.mesh,this.yaxis),i.getDirectionToRef(e.Axis.Z,this.mesh,this.zaxis),t.prototype.update.call(this,this.pos,this.xaxis,this.yaxis,this.zaxis)}},i.prototype.dispose=function(){this.mesh&&(this.mesh=null,this.bone=null,t.prototype.dispose.call(this))},i}(t.AxesViewer);t.BoneAxesViewer=i}(e.Debug||(e.Debug={}))}(s||(s={}));!function(e){var t=function(){function t(e){this.ray=e}return t.CreateAndShow=function(e,i,r){var n=new t(e);return n.show(i,r),n},t.prototype.show=function(t,i){if(!this._renderFunction&&this.ray){var r=this.ray;this._renderFunction=this._render.bind(this),this._scene=t,this._renderPoints=[r.origin,r.origin.add(r.direction.scale(r.length))],this._renderLine=e.Mesh.CreateLines("ray",this._renderPoints,t,!0),this._renderFunction&&this._scene.registerBeforeRender(this._renderFunction)}i&&this._renderLine&&this._renderLine.color.copyFrom(i)},t.prototype.hide=function(){this._renderFunction&&this._scene&&(this._scene.unregisterBeforeRender(this._renderFunction),this._scene=null,this._renderFunction=null,this._renderLine&&(this._renderLine.dispose(),this._renderLine=null),this._renderPoints=[])},t.prototype._render=function(){var t=this.ray;if(t){var i=this._renderPoints[1],r=Math.min(t.length,1e6);i.copyFrom(t.direction),i.scaleInPlace(r),i.addInPlace(t.origin),e.Mesh.CreateLines("ray",this._renderPoints,this._scene,!0,this._renderLine)}},t.prototype.attachToMesh=function(t,i,r,n){this._attachedToMesh=t;var o=this.ray;o&&(o.direction||(o.direction=e.Vector3.Zero()),o.origin||(o.origin=e.Vector3.Zero()),n&&(o.length=n),r||(r=e.Vector3.Zero()),i||(i=new e.Vector3(0,0,-1)),this._meshSpaceDirection?(this._meshSpaceDirection.copyFrom(i),this._meshSpaceOrigin.copyFrom(r)):(this._meshSpaceDirection=i.clone(),this._meshSpaceOrigin=r.clone()),this._updateToMeshFunction||(this._updateToMeshFunction=this._updateToMesh.bind(this),this._attachedToMesh.getScene().registerBeforeRender(this._updateToMeshFunction)),this._updateToMesh())},t.prototype.detachFromMesh=function(){this._attachedToMesh&&(this._updateToMeshFunction&&this._attachedToMesh.getScene().unregisterBeforeRender(this._updateToMeshFunction),this._attachedToMesh=null,this._updateToMeshFunction=null)},t.prototype._updateToMesh=function(){var t=this.ray;this._attachedToMesh&&t&&(this._attachedToMesh._isDisposed?this.detachFromMesh():(this._attachedToMesh.getDirectionToRef(this._meshSpaceDirection,t.direction),e.Vector3.TransformCoordinatesToRef(this._meshSpaceOrigin,this._attachedToMesh.getWorldMatrix(),t.origin)))},t.prototype.dispose=function(){this.hide(),this.detachFromMesh(),this.ray=null},t}();e.RayHelper=t}(s||(s={}));!function(e){var t=function(){function t(e){this.BJSINSPECTOR="undefined"!=typeof INSPECTOR?INSPECTOR:void 0,this._scene=e}return t.prototype._createInspector=function(e){void 0===e&&(e={});var t=e.popup||!1,i=e.initialTab||0,r=e.parentElement||null;this._inspector||(this.BJSINSPECTOR=this.BJSINSPECTOR||"undefined"!=typeof INSPECTOR?INSPECTOR:void 0,this._inspector=new this.BJSINSPECTOR.Inspector(this._scene,t,i,r,e.newColors))},t.prototype.isVisible=function(){return!!this._inspector},t.prototype.hide=function(){if(this._inspector){try{this._inspector.dispose()}catch(e){}this._inspector=null}},t.prototype.show=function(i){void 0===i&&(i={}),void 0===this.BJSINSPECTOR?e.Tools.LoadScript(t.InspectorURL,this._createInspector.bind(this,i)):this._createInspector(i)},t.InspectorURL="https://preview.babylonjs.com/inspector/babylon.inspector.bundle.js",t}();e.DebugLayer=t}(s||(s={}));!function(e){!function(t){var i=function(){function t(t){this._impostors=[],this._meshes=[],this._numMeshes=0,this._scene=t||e.Engine.LastCreatedScene;var i=this._scene.getPhysicsEngine();i&&(this._physicsEnginePlugin=i.getPhysicsPlugin())}return t.prototype._updateDebugMeshes=function(){for(var e=this._physicsEnginePlugin,t=0;t<this._numMeshes;t++){var i=this._impostors[t];if(i)if(i.isDisposed)this.hideImpostor(this._impostors[t--]);else{var r=this._meshes[t];r&&e&&e.syncMeshWithImpostor(r,i)}}},t.prototype.showImpostor=function(e){if(this._scene){for(var t=0;t<this._numMeshes;t++)if(this._impostors[t]==e)return;var i=this._getDebugMesh(e,this._scene);i&&(this._impostors[this._numMeshes]=e,this._meshes[this._numMeshes]=i,0===this._numMeshes&&(this._renderFunction=this._updateDebugMeshes.bind(this),this._scene.registerBeforeRender(this._renderFunction)),this._numMeshes++)}},t.prototype.hideImpostor=function(e){if(e&&this._scene){for(var t=!1,i=0;i<this._numMeshes;i++)if(this._impostors[i]==e){var r=this._meshes[i];if(!r)continue;this._scene.removeMesh(r),r.dispose(),this._numMeshes--,this._numMeshes>0?(this._meshes[i]=this._meshes[this._numMeshes],this._impostors[i]=this._impostors[this._numMeshes],this._meshes[this._numMeshes]=null,this._impostors[this._numMeshes]=null):(this._meshes[0]=null,this._impostors[0]=null),t=!0;break}t&&0===this._numMeshes&&this._scene.unregisterBeforeRender(this._renderFunction)}},t.prototype._getDebugMaterial=function(t){return this._debugMaterial||(this._debugMaterial=new e.StandardMaterial("",t),this._debugMaterial.wireframe=!0),this._debugMaterial},t.prototype._getDebugBoxMesh=function(t){return this._debugBoxMesh||(this._debugBoxMesh=e.MeshBuilder.CreateBox("physicsBodyBoxViewMesh",{size:1},t),this._debugBoxMesh.renderingGroupId=1,this._debugBoxMesh.rotationQuaternion=e.Quaternion.Identity(),this._debugBoxMesh.material=this._getDebugMaterial(t),t.removeMesh(this._debugBoxMesh)),this._debugBoxMesh.createInstance("physicsBodyBoxViewInstance")},t.prototype._getDebugSphereMesh=function(t){return this._debugSphereMesh||(this._debugSphereMesh=e.MeshBuilder.CreateSphere("physicsBodySphereViewMesh",{diameter:1},t),this._debugSphereMesh.renderingGroupId=1,this._debugSphereMesh.rotationQuaternion=e.Quaternion.Identity(),this._debugSphereMesh.material=this._getDebugMaterial(t),t.removeMesh(this._debugSphereMesh)),this._debugSphereMesh.createInstance("physicsBodyBoxViewInstance")},t.prototype._getDebugMesh=function(t,i){var r=null;if(t.type==e.PhysicsImpostor.BoxImpostor)r=this._getDebugBoxMesh(i),t.getBoxSizeToRef(r.scaling);else if(t.type==e.PhysicsImpostor.SphereImpostor){r=this._getDebugSphereMesh(i);var n=t.getRadius();r.scaling.x=2*n,r.scaling.y=2*n,r.scaling.z=2*n}return r},t.prototype.dispose=function(){for(var e=0;e<this._numMeshes;e++)this.hideImpostor(this._impostors[e]);this._debugBoxMesh&&this._debugBoxMesh.dispose(),this._debugSphereMesh&&this._debugSphereMesh.dispose(),this._debugMaterial&&this._debugMaterial.dispose(),this._impostors.length=0,this._scene=null,this._physicsEnginePlugin=null},t}();t.PhysicsViewer=i}(e.Debug||(e.Debug={}))}(s||(s={}));!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._vertexBuffers={},this._scene=t}return t.prototype._prepareRessources=function(){if(!this._colorShader){this._colorShader=new e.ShaderMaterial("colorShader",this._scene,"color",{attributes:[e.VertexBuffer.PositionKind],uniforms:["world","viewProjection","color"]});var t=this._scene.getEngine(),i=e.VertexData.CreateBox({size:1});this._vertexBuffers[e.VertexBuffer.PositionKind]=new e.VertexBuffer(t,i.positions,e.VertexBuffer.PositionKind,!1),this._createIndexBuffer()}},t.prototype._createIndexBuffer=function(){var e=this._scene.getEngine();this._indexBuffer=e.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._rebuild=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&t._rebuild(),this._createIndexBuffer()},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 r=this.renderList.data[i],n=r.minimum,o=r.maximum.subtract(n),s=n.add(o.scale(.5)),a=e.Matrix.Scaling(o.x,o.y,o.z).multiply(e.Matrix.Translation(s.x,s.y,s.z)).multiply(r.getWorldMatrix());t.bindBuffers(this._vertexBuffers,this._indexBuffer,this._colorShader.getEffect()),this.showBackLines&&(t.setDepthFunctionToGreaterOrEqual(),this._scene.resetCachedMaterial(),this._colorShader.setColor4("color",this.backColor.toColor4()),this._colorShader.bind(a),t.draw(!1,0,24)),t.setDepthFunctionToLess(),this._scene.resetCachedMaterial(),this._colorShader.setColor4("color",this.frontColor.toColor4()),this._colorShader.bind(a),t.draw(!1,0,24)}this._colorShader.unbind(),t.setDepthFunctionToLessOrEqual(),t.setDepthWrite(!0)}},t.prototype.renderOcclusionBoundingBox=function(t){if(this._prepareRessources(),this._colorShader.isReady()&&t._boundingInfo){var i=this._scene.getEngine();i.setDepthWrite(!1),i.setColorWrite(!1),this._colorShader._preBind();var r=t._boundingInfo.boundingBox,n=r.minimum,o=r.maximum.subtract(n),s=n.add(o.scale(.5)),a=e.Matrix.Scaling(o.x,o.y,o.z).multiply(e.Matrix.Translation(s.x,s.y,s.z)).multiply(r.getWorldMatrix());i.bindBuffers(this._vertexBuffers,this._indexBuffer,this._colorShader.getEffect()),i.setDepthFunctionToLess(),this._scene.resetCachedMaterial(),this._colorShader.bind(a),i.draw(!1,0,24),this._colorShader.unbind(),i.setDepthFunctionToLessOrEqual(),i.setDepthWrite(!0),i.setColorWrite(!0)}},t.prototype.dispose=function(){if(this._colorShader){this.renderList.dispose(),this._colorShader.dispose();var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&(t.dispose(),this._vertexBuffers[e.VertexBuffer.PositionKind]=null),this._scene.getEngine()._releaseBuffer(this._indexBuffer)}},t}();e.BoundingBoxRenderer=t}(s||(s={}));!function(e){var t=function(){function t(t,i){void 0===i&&(i=0),this.name=t,this.animations=new Array,this._positions=null,this._normals=null,this._tangents=null,this.onInfluenceChanged=new e.Observable,this.influence=i}return Object.defineProperty(t.prototype,"influence",{get:function(){return this._influence},set:function(e){if(this._influence!==e){var t=this._influence;this._influence=e,this.onInfluenceChanged.hasObservers&&this.onInfluenceChanged.notifyObservers(0===t||0===e)}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasPositions",{get:function(){return!!this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasNormals",{get:function(){return!!this._normals},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasTangents",{get:function(){return!!this._tangents},enumerable:!0,configurable:!0}),t.prototype.setPositions=function(e){this._positions=e},t.prototype.getPositions=function(){return this._positions},t.prototype.setNormals=function(e){this._normals=e},t.prototype.getNormals=function(){return this._normals},t.prototype.setTangents=function(e){this._tangents=e},t.prototype.getTangents=function(){return this._tangents},t.prototype.serialize=function(){var t={};return t.name=this.name,t.influence=this.influence,t.positions=Array.prototype.slice.call(this.getPositions()),this.hasNormals&&(t.normals=Array.prototype.slice.call(this.getNormals())),this.hasTangents&&(t.tangents=Array.prototype.slice.call(this.getTangents())),e.Animation.AppendSerializedAnimations(this,t),t},t.Parse=function(i){var r=new t(i.name,i.influence);if(r.setPositions(i.positions),i.normals&&r.setNormals(i.normals),i.tangents&&r.setTangents(i.tangents),i.animations)for(var n=0;n<i.animations.length;n++){var o=i.animations[n];r.animations.push(e.Animation.Parse(o))}return r},t.FromMesh=function(i,r,n){r||(r=i.name);var o=new t(r,n);return o.setPositions(i.getVerticesData(e.VertexBuffer.PositionKind)),i.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&o.setNormals(i.getVerticesData(e.VertexBuffer.NormalKind)),i.isVerticesDataPresent(e.VertexBuffer.TangentKind)&&o.setTangents(i.getVerticesData(e.VertexBuffer.TangentKind)),o},t}();e.MorphTarget=t}(s||(s={}));!function(e){var t=function(){function t(t){void 0===t&&(t=null),this._targets=new Array,this._targetObservable=new Array,this._activeTargets=new e.SmartArray(16),this._supportsNormals=!1,this._supportsTangents=!1,this._vertexCount=0,this._uniqueId=0,this._tempInfluences=new Array,t||(t=e.Engine.LastCreatedScene),this._scene=t,this._scene&&(this._scene.morphTargetManagers.push(this),this._uniqueId=this._scene.getUniqueId())}return Object.defineProperty(t.prototype,"uniqueId",{get:function(){return this._uniqueId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vertexCount",{get:function(){return this._vertexCount},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"supportsNormals",{get:function(){return this._supportsNormals},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"supportsTangents",{get:function(){return this._supportsTangents},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"numTargets",{get:function(){return this._targets.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"numInfluencers",{get:function(){return this._activeTargets.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"influences",{get:function(){return this._influences},enumerable:!0,configurable:!0}),t.prototype.getActiveTarget=function(e){return this._activeTargets.data[e]},t.prototype.getTarget=function(e){return this._targets[e]},t.prototype.addTarget=function(e){var t=this;this._targets.push(e),this._targetObservable.push(e.onInfluenceChanged.add(function(e){t._syncActiveTargets(e)})),this._syncActiveTargets(!0)},t.prototype.removeTarget=function(e){var t=this._targets.indexOf(e);t>=0&&(this._targets.splice(t,1),e.onInfluenceChanged.remove(this._targetObservable.splice(t,1)[0]),this._syncActiveTargets(!0))},t.prototype.serialize=function(){var e={};e.id=this.uniqueId,e.targets=[];for(var t=0,i=this._targets;t<i.length;t++){var r=i[t];e.targets.push(r.serialize())}return e},t.prototype._syncActiveTargets=function(t){var i=0;this._activeTargets.reset(),this._supportsNormals=!0,this._supportsTangents=!0,this._vertexCount=0;for(var r=0,n=this._targets;r<n.length;r++){var o=n[r];if(o.influence>0){this._activeTargets.push(o),this._tempInfluences[i++]=o.influence,this._supportsNormals=this._supportsNormals&&o.hasNormals,this._supportsTangents=this._supportsTangents&&o.hasTangents;var s=o.getPositions();if(!s)return void e.Tools.Error("Invalid target. Target must positions.");var a=s.length/3;if(0===this._vertexCount)this._vertexCount=a;else if(this._vertexCount!==a)return void e.Tools.Error("Incompatible target. Targets must all have the same vertices count.")}}this._influences&&this._influences.length===i||(this._influences=new Float32Array(i));for(var l=0;l<i;l++)this._influences[l]=this._tempInfluences[l];if(t&&this._scene)for(var h=0,u=this._scene.meshes;h<u.length;h++){var c=u[h];c.morphTargetManager===this&&c._syncGeometryWithMorphTargetManager()}},t.Parse=function(i,r){var n=new t(r);n._uniqueId=i.id;for(var o=0,s=i.targets;o<s.length;o++){var a=s[o];n.addTarget(e.MorphTarget.Parse(a))}return n},t}();e.MorphTargetManager=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r){void 0===r&&(r=2),this.maxDepth=r,this.dynamicContent=new Array,this._maxBlockCapacity=i||64,this._selectionContent=new e.SmartArrayNoDuplicate(1024),this._creationFunc=t}return t.prototype.update=function(e,i,r){t._CreateBlocks(e,i,r,this._maxBlockCapacity,0,this.maxDepth,this,this._creationFunc)},t.prototype.addMesh=function(e){for(var t=0;t<this.blocks.length;t++)this.blocks[t].addEntry(e)},t.prototype.select=function(e,t){this._selectionContent.reset();for(var i=0;i<this.blocks.length;i++)this.blocks[i].select(e,this._selectionContent,t);return t?this._selectionContent.concat(this.dynamicContent):this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},t.prototype.intersects=function(e,t,i){this._selectionContent.reset();for(var r=0;r<this.blocks.length;r++)this.blocks[r].intersects(e,t,this._selectionContent,i);return i?this._selectionContent.concat(this.dynamicContent):this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},t.prototype.intersectsRay=function(e){this._selectionContent.reset();for(var t=0;t<this.blocks.length;t++)this.blocks[t].intersectsRay(e,this._selectionContent);return this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},t._CreateBlocks=function(t,i,r,n,o,s,a,l){a.blocks=new Array;for(var h=new e.Vector3((i.x-t.x)/2,(i.y-t.y)/2,(i.z-t.z)/2),u=0;u<2;u++)for(var c=0;c<2;c++)for(var f=0;f<2;f++){var p=t.add(h.multiplyByFloats(u,c,f)),d=t.add(h.multiplyByFloats(u+1,c+1,f+1)),m=new e.OctreeBlock(p,d,n,o+1,s,l);m.addEntries(r),a.blocks.push(m)}},t.CreationFuncForMeshes=function(e,t){var i=e.getBoundingInfo();!e.isBlocked&&i&&i.boundingBox.intersectsMinMax(t.minPoint,t.maxPoint)&&t.entries.push(e)},t.CreationFuncForSubMeshes=function(e,t){var i=e.getBoundingInfo();i&&i.boundingBox.intersectsMinMax(t.minPoint,t.maxPoint)&&t.entries.push(e)},t}();e.Octree=t}(s||(s={}));!function(e){var t=function(){function t(e,t,i,r,n,o){this.entries=new Array,this._boundingVectors=new Array,this._capacity=i,this._depth=r,this._maxDepth=n,this._creationFunc=o,this._minPoint=e,this._maxPoint=t,this._boundingVectors.push(e.clone()),this._boundingVectors.push(t.clone()),this._boundingVectors.push(e.clone()),this._boundingVectors[2].x=t.x,this._boundingVectors.push(e.clone()),this._boundingVectors[3].y=t.y,this._boundingVectors.push(e.clone()),this._boundingVectors[4].z=t.z,this._boundingVectors.push(t.clone()),this._boundingVectors[5].z=e.z,this._boundingVectors.push(t.clone()),this._boundingVectors[6].x=e.x,this._boundingVectors.push(t.clone()),this._boundingVectors[7].y=e.y}return Object.defineProperty(t.prototype,"capacity",{get:function(){return this._capacity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"minPoint",{get:function(){return this._minPoint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxPoint",{get:function(){return this._maxPoint},enumerable:!0,configurable:!0}),t.prototype.addEntry=function(e){if(this.blocks)for(var t=0;t<this.blocks.length;t++)this.blocks[t].addEntry(e);else this._creationFunc(e,this),this.entries.length>this.capacity&&this._depth<this._maxDepth&&this.createInnerBlocks()},t.prototype.addEntries=function(e){for(var t=0;t<e.length;t++){var i=e[t];this.addEntry(i)}},t.prototype.select=function(t,i,r){if(e.BoundingBox.IsInFrustum(this._boundingVectors,t)){if(this.blocks){for(var n=0;n<this.blocks.length;n++)this.blocks[n].select(t,i,r);return}r?i.concat(this.entries):i.concatWithNoDuplicate(this.entries)}},t.prototype.intersects=function(t,i,r,n){if(e.BoundingBox.IntersectsSphere(this._minPoint,this._maxPoint,t,i)){if(this.blocks){for(var o=0;o<this.blocks.length;o++)this.blocks[o].intersects(t,i,r,n);return}n?r.concat(this.entries):r.concatWithNoDuplicate(this.entries)}},t.prototype.intersectsRay=function(e,t){if(e.intersectsBoxMinMax(this._minPoint,this._maxPoint)){if(this.blocks){for(var i=0;i<this.blocks.length;i++)this.blocks[i].intersectsRay(e,t);return}t.concatWithNoDuplicate(this.entries)}},t.prototype.createInnerBlocks=function(){e.Octree._CreateBlocks(this._minPoint,this._maxPoint,this.entries,this._capacity,this._depth,this._maxDepth,this,this._creationFunc)},t}();e.OctreeBlock=t}(s||(s={}));!function(e){var t=function(){function e(){}return e.TransformCoordinatesToRefSIMD=function(t,i,r){e.TransformCoordinatesFromFloatsToRefSIMD(t.x,t.y,t.z,i,r)},e.TransformCoordinatesFromFloatsToRefSIMD=function(e,t,i,r,n){var o=r.m,s=SIMD.Float32x4.load(o,0),a=SIMD.Float32x4.load(o,4),l=SIMD.Float32x4.load(o,8),h=SIMD.Float32x4.load(o,12),u=SIMD.Float32x4.add(SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.splat(e),s),SIMD.Float32x4.mul(SIMD.Float32x4.splat(t),a)),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.splat(i),l),h));u=SIMD.Float32x4.div(u,SIMD.Float32x4.swizzle(u,3,3,3,3)),n.x=SIMD.Float32x4.extractLane(u,0),n.y=SIMD.Float32x4.extractLane(u,1),n.z=SIMD.Float32x4.extractLane(u,2)},e}(),i=function(){function e(){}return e.prototype.multiplyToArraySIMD=function(e,t,i){for(var r=this.m,n=e.m,o=SIMD.Float32x4.load(n,0),s=SIMD.Float32x4.load(n,4),a=SIMD.Float32x4.load(n,8),l=SIMD.Float32x4.load(n,12),h=0;h<16;h+=4)SIMD.Float32x4.store(t,h+i,SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.splat(r[h]),o),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.splat(r[h+1]),s),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.splat(r[h+2]),a),SIMD.Float32x4.mul(SIMD.Float32x4.splat(r[h+3]),l)))));return this},e.prototype.invertToRefSIMD=function(e){var t=this.m,i=e.m,r=SIMD.Float32x4.load(t,0),n=SIMD.Float32x4.load(t,4),o=SIMD.Float32x4.load(t,8),s=SIMD.Float32x4.load(t,12),a=SIMD.Float32x4.shuffle(r,n,0,1,4,5),l=SIMD.Float32x4.shuffle(o,s,0,1,4,5),h=SIMD.Float32x4.shuffle(a,l,0,2,4,6);l=SIMD.Float32x4.shuffle(l,a,1,3,5,7),a=SIMD.Float32x4.shuffle(r,n,2,3,6,7);var u=SIMD.Float32x4.shuffle(o,s,2,3,6,7),c=SIMD.Float32x4.shuffle(a,u,0,2,4,6);u=SIMD.Float32x4.shuffle(u,a,1,3,5,7),a=SIMD.Float32x4.mul(c,u),a=SIMD.Float32x4.swizzle(a,1,0,3,2);var f=SIMD.Float32x4.mul(l,a),p=SIMD.Float32x4.mul(h,a);a=SIMD.Float32x4.swizzle(a,2,3,0,1),f=SIMD.Float32x4.sub(SIMD.Float32x4.mul(l,a),f),p=SIMD.Float32x4.sub(SIMD.Float32x4.mul(h,a),p),p=SIMD.Float32x4.swizzle(p,2,3,0,1),a=SIMD.Float32x4.mul(l,c),a=SIMD.Float32x4.swizzle(a,1,0,3,2),f=SIMD.Float32x4.add(SIMD.Float32x4.mul(u,a),f);var d=SIMD.Float32x4.mul(h,a);a=SIMD.Float32x4.swizzle(a,2,3,0,1),f=SIMD.Float32x4.sub(f,SIMD.Float32x4.mul(u,a)),d=SIMD.Float32x4.sub(SIMD.Float32x4.mul(h,a),d),d=SIMD.Float32x4.swizzle(d,2,3,0,1),a=SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(l,2,3,0,1),u),a=SIMD.Float32x4.swizzle(a,1,0,3,2),c=SIMD.Float32x4.swizzle(c,2,3,0,1),f=SIMD.Float32x4.add(SIMD.Float32x4.mul(c,a),f);var m=SIMD.Float32x4.mul(h,a);a=SIMD.Float32x4.swizzle(a,2,3,0,1),f=SIMD.Float32x4.sub(f,SIMD.Float32x4.mul(c,a)),m=SIMD.Float32x4.sub(SIMD.Float32x4.mul(h,a),m),m=SIMD.Float32x4.swizzle(m,2,3,0,1),a=SIMD.Float32x4.mul(h,l),a=SIMD.Float32x4.swizzle(a,1,0,3,2),m=SIMD.Float32x4.add(SIMD.Float32x4.mul(u,a),m),d=SIMD.Float32x4.sub(SIMD.Float32x4.mul(c,a),d),a=SIMD.Float32x4.swizzle(a,2,3,0,1),m=SIMD.Float32x4.sub(SIMD.Float32x4.mul(u,a),m),d=SIMD.Float32x4.sub(d,SIMD.Float32x4.mul(c,a)),a=SIMD.Float32x4.mul(h,u),a=SIMD.Float32x4.swizzle(a,1,0,3,2),p=SIMD.Float32x4.sub(p,SIMD.Float32x4.mul(c,a)),m=SIMD.Float32x4.add(SIMD.Float32x4.mul(l,a),m),a=SIMD.Float32x4.swizzle(a,2,3,0,1),p=SIMD.Float32x4.add(SIMD.Float32x4.mul(c,a),p),m=SIMD.Float32x4.sub(m,SIMD.Float32x4.mul(l,a)),a=SIMD.Float32x4.mul(h,c),a=SIMD.Float32x4.swizzle(a,1,0,3,2),p=SIMD.Float32x4.add(SIMD.Float32x4.mul(u,a),p),d=SIMD.Float32x4.sub(d,SIMD.Float32x4.mul(l,a)),a=SIMD.Float32x4.swizzle(a,2,3,0,1),p=SIMD.Float32x4.sub(p,SIMD.Float32x4.mul(u,a)),d=SIMD.Float32x4.add(SIMD.Float32x4.mul(l,a),d);var g=SIMD.Float32x4.mul(h,f);return g=SIMD.Float32x4.add(SIMD.Float32x4.swizzle(g,2,3,0,1),g),g=SIMD.Float32x4.add(SIMD.Float32x4.swizzle(g,1,0,3,2),g),a=SIMD.Float32x4.reciprocalApproximation(g),g=SIMD.Float32x4.sub(SIMD.Float32x4.add(a,a),SIMD.Float32x4.mul(g,SIMD.Float32x4.mul(a,a))),g=SIMD.Float32x4.swizzle(g,0,0,0,0),SIMD.Float32x4.store(i,0,SIMD.Float32x4.mul(g,f)),SIMD.Float32x4.store(i,4,SIMD.Float32x4.mul(g,p)),SIMD.Float32x4.store(i,8,m=SIMD.Float32x4.mul(g,m)),SIMD.Float32x4.store(i,12,SIMD.Float32x4.mul(g,d)),this},e.LookAtLHToRefSIMD=function(e,t,i,r){var n=r.m,o=SIMD.Float32x4(t.x,t.y,t.z,0),s=SIMD.Float32x4(e.x,e.y,e.z,0),a=SIMD.Float32x4(i.x,i.y,i.z,0),l=SIMD.Float32x4.sub(o,s),h=SIMD.Float32x4.mul(l,l);h=SIMD.Float32x4.add(h,SIMD.Float32x4.add(SIMD.Float32x4.swizzle(h,1,2,0,3),SIMD.Float32x4.swizzle(h,2,0,1,3))),l=SIMD.Float32x4.mul(l,SIMD.Float32x4.reciprocalSqrtApproximation(h)),h=SIMD.Float32x4.mul(a,a),h=SIMD.Float32x4.add(h,SIMD.Float32x4.add(SIMD.Float32x4.swizzle(h,1,2,0,3),SIMD.Float32x4.swizzle(h,2,0,1,3))),a=SIMD.Float32x4.mul(a,SIMD.Float32x4.reciprocalSqrtApproximation(h));var u=SIMD.Float32x4.sub(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(l,1,2,0,3),SIMD.Float32x4.swizzle(a,2,0,1,3)),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(l,2,0,1,3),SIMD.Float32x4.swizzle(a,1,2,0,3)));h=SIMD.Float32x4.mul(u,u),h=SIMD.Float32x4.add(h,SIMD.Float32x4.add(SIMD.Float32x4.swizzle(h,1,2,0,3),SIMD.Float32x4.swizzle(h,2,0,1,3))),u=SIMD.Float32x4.mul(u,SIMD.Float32x4.reciprocalSqrtApproximation(h));var c=SIMD.Float32x4.sub(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(u,1,2,0,3),SIMD.Float32x4.swizzle(l,2,0,1,3)),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(u,2,0,1,3),SIMD.Float32x4.swizzle(l,1,2,0,3)));h=SIMD.Float32x4.mul(u,u),h=SIMD.Float32x4.add(h,SIMD.Float32x4.add(SIMD.Float32x4.swizzle(h,1,2,0,3),SIMD.Float32x4.swizzle(h,2,0,1,3))),u=SIMD.Float32x4.mul(u,SIMD.Float32x4.reciprocalSqrtApproximation(h));var f=SIMD.Float32x4.splat(0);u=SIMD.Float32x4.neg(u);var p=SIMD.Float32x4.shuffle(u,c,0,1,4,5),d=SIMD.Float32x4.shuffle(l,f,0,1,4,5),m=SIMD.Float32x4.shuffle(p,d,0,2,4,6),g=SIMD.Float32x4.shuffle(p,d,1,3,5,7),v=SIMD.Float32x4.shuffle(SIMD.Float32x4.shuffle(u,c,2,3,6,7),SIMD.Float32x4.shuffle(l,f,2,3,6,7),0,2,4,6),_=SIMD.Float32x4(0,0,0,1),y=SIMD.Float32x4(1,0,0,0);SIMD.Float32x4.store(n,0,SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,0,0,0,0),m),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,1,1,1,1),g),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,2,2,2,2),v),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,3,3,3,3),_))))),y=SIMD.Float32x4(0,1,0,0),SIMD.Float32x4.store(n,4,SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,0,0,0,0),m),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,1,1,1,1),g),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,2,2,2,2),v),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,3,3,3,3),_))))),y=SIMD.Float32x4(0,0,1,0),SIMD.Float32x4.store(n,8,SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,0,0,0,0),m),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,1,1,1,1),g),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,2,2,2,2),v),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,3,3,3,3),_))))),y=SIMD.Float32x4.replaceLane(SIMD.Float32x4.neg(s),3,1),SIMD.Float32x4.store(n,12,SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,0,0,0,0),m),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,1,1,1,1),g),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,2,2,2,2),v),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(y,3,3,3,3),_)))))},e}(),r=e.Matrix.prototype.multiplyToArray,n=e.Matrix.prototype.invertToRef,o=e.Matrix.LookAtLHToRef,s=e.Vector3.TransformCoordinatesToRef,a=e.Vector3.TransformCoordinatesFromFloatsToRef,l=function(){function l(){}return Object.defineProperty(l,"IsEnabled",{get:function(){return l._isEnabled},enumerable:!0,configurable:!0}),l.DisableSIMD=function(){e.Matrix.prototype.multiplyToArray=r,e.Matrix.prototype.invertToRef=n,e.Matrix.LookAtLHToRef=o,e.Vector3.TransformCoordinatesToRef=s,e.Vector3.TransformCoordinatesFromFloatsToRef=a,l._isEnabled=!1},l.EnableSIMD=function(){void 0!==self.SIMD&&(self.Math.fround||(self.Math.fround=function(e){return function(t){return e[0]=t,e[0]}}(new Float32Array(1))),self.Math.imul||(self.Math.imul=function(e,t){var i=65535&e,r=65535&t;return i*r+((e>>>16&65535)*r+i*(t>>>16&65535)<<16>>>0)|0}),e.Matrix.prototype.multiplyToArray=i.prototype.multiplyToArraySIMD,e.Matrix.prototype.invertToRef=i.prototype.invertToRefSIMD,e.Matrix.LookAtLHToRef=i.LookAtLHToRefSIMD,e.Vector3.TransformCoordinatesToRef=t.TransformCoordinatesToRefSIMD,e.Vector3.TransformCoordinatesFromFloatsToRef=t.TransformCoordinatesFromFloatsToRefSIMD,l._isEnabled=!0)},l._isEnabled=!1,l}();e.SIMDHelper=l}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o){var s=t.call(this,i,"vrDistortionCorrection",["LensCenter","Scale","ScaleIn","HmdWarpParam"],null,o.postProcessScaleFactor,r,e.Texture.BILINEAR_SAMPLINGMODE)||this;return s._isRightEye=n,s._distortionFactors=o.distortionK,s._postProcessScaleFactor=o.postProcessScaleFactor,s._lensCenterOffset=o.lensCenterOffset,s.adaptScaleToCurrentViewport=!0,s.onSizeChangedObservable.add(function(){s.aspectRatio=.5*s.width/s.height,s._scaleIn=new e.Vector2(2,2/s.aspectRatio),s._scaleFactor=new e.Vector2(1/s._postProcessScaleFactor*.5,1/s._postProcessScaleFactor*.5*s.aspectRatio),s._lensCenter=new e.Vector2(s._isRightEye?.5-.5*s._lensCenterOffset:.5+.5*s._lensCenterOffset,.5)}),s.onApplyObservable.add(function(e){e.setFloat2("LensCenter",s._lensCenter.x,s._lensCenter.y),e.setFloat2("Scale",s._scaleFactor.x,s._scaleFactor.y),e.setFloat2("ScaleIn",s._scaleIn.x,s._scaleIn.y),e.setFloat4("HmdWarpParam",s._distortionFactors[0],s._distortionFactors[1],s._distortionFactors[2],s._distortionFactors[3])}),s}return n(i,t),i}(e.PostProcess);e.VRDistortionCorrectionPostProcess=t}(s||(s={}));!function(e){var t=function(e){function t(t,i,r,n,o,s){var a=e.call(this,t,"anaglyph",null,["leftSampler"],i,r[1],n,o,s)||this;return a._passedProcess=r[0]._rigPostProcess,a.onApplyObservable.add(function(e){e.setTextureFromPostProcess("leftSampler",a._passedProcess)}),a}return n(t,e),t}(e.PostProcess);e.AnaglyphPostProcess=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a){var l=t.call(this,i,"stereoscopicInterlace",["stepSize"],["camASampler"],1,r[1],o,s,a,n?"#define IS_STEREOSCOPIC_HORIZ 1":void 0)||this;return l._passedProcess=r[0]._rigPostProcess,l._stepSize=new e.Vector2(1/l.width,1/l.height),l.onSizeChangedObservable.add(function(){l._stepSize=new e.Vector2(1/l.width,1/l.height)}),l.onApplyObservable.add(function(e){e.setTextureFromPostProcess("camASampler",l._passedProcess),e.setFloat2("stepSize",l._stepSize.x,l._stepSize.y)}),l}return n(i,t),i}(e.PostProcess);e.StereoscopicInterlacePostProcess=t}(s||(s={}));!function(e){var t=function(){function t(){var t=this;this._screenOrientationAngle=0,this._screenQuaternion=new e.Quaternion,this._alpha=0,this._beta=0,this._gamma=0,this._orientationChanged=function(){t._screenOrientationAngle=void 0!==window.orientation?+window.orientation:window.screen.orientation&&window.screen.orientation.angle?window.screen.orientation.angle:0,t._screenOrientationAngle=-e.Tools.ToRadians(t._screenOrientationAngle/2),t._screenQuaternion.copyFromFloats(0,Math.sin(t._screenOrientationAngle),0,Math.cos(t._screenOrientationAngle))},this._deviceOrientation=function(e){t._alpha=null!==e.alpha?e.alpha:0,t._beta=null!==e.beta?e.beta:0,t._gamma=null!==e.gamma?e.gamma:0},this._constantTranform=new e.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),this._orientationChanged()}return Object.defineProperty(t.prototype,"camera",{get:function(){return this._camera},set:function(t){this._camera=t,null==this._camera||this._camera.rotationQuaternion||(this._camera.rotationQuaternion=new e.Quaternion)},enumerable:!0,configurable:!0}),t.prototype.attachControl=function(e,t){window.addEventListener("orientationchange",this._orientationChanged),window.addEventListener("deviceorientation",this._deviceOrientation),this._orientationChanged()},t.prototype.detachControl=function(e){window.removeEventListener("orientationchange",this._orientationChanged),window.removeEventListener("deviceorientation",this._deviceOrientation)},t.prototype.checkInputs=function(){this._alpha&&(e.Quaternion.RotationYawPitchRollToRef(e.Tools.ToRadians(this._alpha),e.Tools.ToRadians(this._beta),-e.Tools.ToRadians(this._gamma),this.camera.rotationQuaternion),this._camera.rotationQuaternion.multiplyInPlace(this._screenQuaternion),this._camera.rotationQuaternion.multiplyInPlace(this._constantTranform),this._camera.rotationQuaternion.z*=-1,this._camera.rotationQuaternion.w*=-1)},t.prototype.getClassName=function(){return"FreeCameraDeviceOrientationInput"},t.prototype.getSimpleName=function(){return"deviceOrientation"},t}();e.FreeCameraDeviceOrientationInput=t,e.CameraInputTypes.FreeCameraDeviceOrientationInput=t}(s||(s={}));!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){null!==e.alpha&&(this._alpha=0|+e.alpha),null!==e.beta&&(this._beta=0|+e.beta),null!==e.gamma&&(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.getClassName=function(){return"ArcRotateCameraVRDeviceOrientationInput"},e.prototype.getSimpleName=function(){return"VRDeviceOrientation"},e}();e.ArcRotateCameraVRDeviceOrientationInput=t,e.CameraInputTypes.ArcRotateCameraVRDeviceOrientationInput=t}(s||(s={}));!function(e){var t=function(){function t(){this.compensateDistortion=!0}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return this.hResolution/(2*this.vResolution)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"aspectRatioFov",{get:function(){return 2*Math.atan(this.postProcessScaleFactor*this.vScreenSize/(2*this.eyeToScreenDistance))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"leftHMatrix",{get:function(){var t=4*(this.hScreenSize/4-this.lensSeparationDistance/2)/this.hScreenSize;return e.Matrix.Translation(t,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightHMatrix",{get:function(){var t=4*(this.hScreenSize/4-this.lensSeparationDistance/2)/this.hScreenSize;return e.Matrix.Translation(-t,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"leftPreViewMatrix",{get:function(){return e.Matrix.Translation(.5*this.interpupillaryDistance,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightPreViewMatrix",{get:function(){return e.Matrix.Translation(-.5*this.interpupillaryDistance,0,0)},enumerable:!0,configurable:!0}),t.GetDefault=function(){var e=new t;return e.hResolution=1280,e.vResolution=800,e.hScreenSize=.149759993,e.vScreenSize=.0935999975,e.vScreenCenter=.0467999987,e.eyeToScreenDistance=.0410000011,e.lensSeparationDistance=.063500002,e.interpupillaryDistance=.064000003,e.distortionK=[1,.219999999,.239999995,0],e.chromaAbCorrection=[.995999992,-.00400000019,1.01400006,0],e.postProcessScaleFactor=1.714605507808412,e.lensCenterOffset=.151976421,e},t}();e.VRCameraMetrics=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o){void 0===o&&(o={});var s=t.call(this,i,r,n)||this;s.webVROptions=o,s._vrDevice=null,s.rawPose=null,s._specsVersion="1.1",s._attached=!1,s._descendants=[],s.devicePosition=e.Vector3.Zero(),s.deviceScaleFactor=1,s.controllers=[],s.onControllersAttachedObservable=new e.Observable,s.onControllerMeshLoadedObservable=new e.Observable,s.rigParenting=!0,s.minZ=.1,5===arguments.length&&(s.webVROptions=arguments[4]),void 0==s.webVROptions.trackPosition&&(s.webVROptions.trackPosition=!0),void 0==s.webVROptions.controllerMeshes&&(s.webVROptions.controllerMeshes=!0),void 0==s.webVROptions.defaultLightingOnControllers&&(s.webVROptions.defaultLightingOnControllers=!0),s.rotationQuaternion=new e.Quaternion,s.deviceRotationQuaternion=new e.Quaternion,s.webVROptions&&s.webVROptions.positionScale&&(s.deviceScaleFactor=s.webVROptions.positionScale);var a=s.getEngine();return s._onVREnabled=function(e){e&&s.initControllers()},a.onVRRequestPresentComplete.add(s._onVREnabled),a.initWebVR().add(function(t){t.vrDisplay&&s._vrDevice!==t.vrDisplay&&(s._vrDevice=t.vrDisplay,s.setCameraRigMode(e.Camera.RIG_MODE_WEBVR,{parentCamera:s,vrDisplay:s._vrDevice,frameData:s._frameData,specs:s._specsVersion}),s._attached&&s.getEngine().enableVR())}),"undefined"!=typeof VRFrameData&&(s._frameData=new VRFrameData),n.onBeforeCameraRenderObservable.add(function(e){e.parent===s&&s.rigParenting&&(s._descendants=s.getDescendants(!0,function(e){var t=s.controllers.some(function(t){return t._mesh===e}),i=-1!==s._rigCameras.indexOf(e);return!t&&!i}),s._descendants.forEach(function(t){t.parent=e}))}),n.onAfterCameraRenderObservable.add(function(e){e.parent===s&&s.rigParenting&&s._descendants.forEach(function(e){e.parent=s})}),s}return n(i,t),i.prototype.dispose=function(){this.getEngine().onVRRequestPresentComplete.removeCallback(this._onVREnabled),t.prototype.dispose.call(this)},i.prototype.getControllerByName=function(e){for(var t=0,i=this.controllers;t<i.length;t++){var r=i[t];if(r.hand===e)return r}return null},Object.defineProperty(i.prototype,"leftController",{get:function(){return this._leftController||(this._leftController=this.getControllerByName("left")),this._leftController},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"rightController",{get:function(){return this._rightController||(this._rightController=this.getControllerByName("right")),this._rightController},enumerable:!0,configurable:!0}),i.prototype.getForwardRay=function(e){return void 0===e&&(e=100),this.leftCamera?t.prototype.getForwardRay.call(this,e,this.leftCamera.getWorldMatrix(),this.position.add(this.devicePosition)):t.prototype.getForwardRay.call(this,e)},i.prototype._checkInputs=function(){this._vrDevice&&this._vrDevice.isPresenting&&(this._vrDevice.getFrameData(this._frameData),this.updateFromDevice(this._frameData.pose)),t.prototype._checkInputs.call(this)},i.prototype.updateFromDevice=function(e){e&&e.orientation&&(this.rawPose=e,this.deviceRotationQuaternion.copyFromFloats(e.orientation[0],e.orientation[1],-e.orientation[2],-e.orientation[3]),this.getScene().useRightHandedSystem&&(this.deviceRotationQuaternion.z*=-1,this.deviceRotationQuaternion.w*=-1),this.webVROptions.trackPosition&&this.rawPose.position&&(this.devicePosition.copyFromFloats(this.rawPose.position[0],this.rawPose.position[1],-this.rawPose.position[2]),this.getScene().useRightHandedSystem&&(this.devicePosition.z*=-1)))},i.prototype.attachControl=function(i,r){t.prototype.attachControl.call(this,i,r),this._attached=!0,r=!e.Camera.ForceAttachControlToAlwaysPreventDefault&&r,this._vrDevice&&this.getEngine().enableVR()},i.prototype.detachControl=function(e){this.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver),this.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver),t.prototype.detachControl.call(this,e),this._attached=!1,this.getEngine().disableVR()},i.prototype.getClassName=function(){return"WebVRFreeCamera"},i.prototype.resetToCurrentRotation=function(){this._vrDevice.resetPose()},i.prototype._updateRigCameras=function(){var e=this._rigCameras[0],t=this._rigCameras[1];e.rotationQuaternion.copyFrom(this.deviceRotationQuaternion),t.rotationQuaternion.copyFrom(this.deviceRotationQuaternion),e.position.copyFrom(this.devicePosition),t.position.copyFrom(this.devicePosition)},i.prototype._getWebVRViewMatrix=function(){var t=this,i=this._cameraRigParams.left?this._cameraRigParams.frameData.leftViewMatrix:this._cameraRigParams.frameData.rightViewMatrix;e.Matrix.FromArrayToRef(i,0,this._webvrViewMatrix),this.getScene().useRightHandedSystem||[2,6,8,9,14].forEach(function(e){t._webvrViewMatrix.m[e]*=-1}),this._webvrViewMatrix.getRotationMatrixToRef(this._cameraRotationMatrix),e.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),this.position.addToRef(this._transformedReferencePoint,this._currentTarget);var r=this._cameraRigParams.parentCamera;return 1!==r.deviceScaleFactor&&(this._webvrViewMatrix.invert(),r.deviceScaleFactor&&(this._webvrViewMatrix.m[12]*=r.deviceScaleFactor,this._webvrViewMatrix.m[13]*=r.deviceScaleFactor,this._webvrViewMatrix.m[14]*=r.deviceScaleFactor),this._webvrViewMatrix.invert()),this._webvrViewMatrix},i.prototype._getWebVRProjectionMatrix=function(){var t=this,i=this.parent;i._vrDevice.depthNear=i.minZ,i._vrDevice.depthFar=i.maxZ;var r=this._cameraRigParams.left?this._cameraRigParams.frameData.leftProjectionMatrix:this._cameraRigParams.frameData.rightProjectionMatrix;return e.Matrix.FromArrayToRef(r,0,this._projectionMatrix),this.getScene().useRightHandedSystem||[8,9,10,11].forEach(function(e){t._projectionMatrix.m[e]*=-1}),this._projectionMatrix},i.prototype.initControllers=function(){var t=this;this.controllers=[];var i=this.getScene().gamepadManager;this._onGamepadDisconnectedObserver=i.onGamepadDisconnectedObservable.add(function(t){if(t.type===e.Gamepad.POSE_ENABLED){var i=t;i.defaultModel&&i.defaultModel.setEnabled(!1)}}),this._onGamepadConnectedObserver=i.onGamepadConnectedObservable.add(function(i){if(i.type===e.Gamepad.POSE_ENABLED){var r=i;if(t.webVROptions.controllerMeshes&&(r.defaultModel?r.defaultModel.setEnabled(!0):r.initControllerMesh(t.getScene(),function(i){if(t.onControllerMeshLoadedObservable.notifyObservers(r),t.webVROptions.defaultLightingOnControllers){t._lightOnControllers||(t._lightOnControllers=new e.HemisphericLight("vrControllersLight",new e.Vector3(0,1,0),t.getScene()));var n=function(e,t){var i=e.getChildren();0!==i.length&&i.forEach(function(e){t.includedOnlyMeshes.push(e),n(e,t)})};t._lightOnControllers.includedOnlyMeshes.push(i),n(i,t._lightOnControllers)}})),r.attachToPoseControlledCamera(t),-1===t.controllers.indexOf(r)&&(t.controllers.push(r),t.controllers.length>=2)){for(var n=!1,o=0;o<t.controllers.length;o++)t.controllers[o].controllerType===e.PoseEnabledControllerType.VIVE&&(n?t.controllers[o].hand="right":(n=!0,t.controllers[o].hand="left"));t.onControllersAttachedObservable.notifyObservers(t.controllers)}}})},i}(e.FreeCamera);e.WebVRFreeCamera=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n){var o=t.call(this,i,r,n)||this;return o._quaternionCache=new e.Quaternion,o.inputs.addDeviceOrientation(),o}return n(i,t),i.prototype.getClassName=function(){return"DeviceOrientationCamera"},i.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this._quaternionCache.copyFrom(this.rotationQuaternion),this._initialQuaternion&&this._initialQuaternion.multiplyToRef(this.rotationQuaternion,this.rotationQuaternion)},i.prototype.resetToCurrentRotation=function(t){var i=this;void 0===t&&(t=e.Axis.Y),this.rotationQuaternion&&(this._initialQuaternion||(this._initialQuaternion=new e.Quaternion),this._initialQuaternion.copyFrom(this._quaternionCache||this.rotationQuaternion),["x","y","z"].forEach(function(e){t[e]?i._initialQuaternion[e]*=-1:i._initialQuaternion[e]=0}),this._initialQuaternion.normalize(),this._initialQuaternion.multiplyToRef(this.rotationQuaternion,this.rotationQuaternion))},i}(e.FreeCamera);e.DeviceOrientationCamera=t}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s){void 0===o&&(o=!0),void 0===s&&(s=e.VRCameraMetrics.GetDefault());var a=t.call(this,i,r,n)||this;return s.compensateDistortion=o,a.setCameraRigMode(e.Camera.RIG_MODE_VR,{vrCameraMetrics:s}),a}return n(i,t),i.prototype.getClassName=function(){return"VRDeviceOrientationFreeCamera"},i}(e.DeviceOrientationCamera);e.VRDeviceOrientationFreeCamera=t;var i=function(t){function i(i,r,n,o,s){void 0===o&&(o=!0),void 0===s&&(s=e.VRCameraMetrics.GetDefault());var a=t.call(this,i,r,n,o,s)||this;return a.inputs.addGamepad(),a}return n(i,t),i.prototype.getClassName=function(){return"VRDeviceOrientationGamepadCamera"},i}(t);e.VRDeviceOrientationGamepadCamera=i;var r=function(t){function i(i,r,n,o,s,a,l,h){void 0===l&&(l=!0),void 0===h&&(h=e.VRCameraMetrics.GetDefault());var u=t.call(this,i,r,n,o,s,a)||this;return h.compensateDistortion=l,u.setCameraRigMode(e.Camera.RIG_MODE_VR,{vrCameraMetrics:h}),u.inputs.addVRDeviceOrientation(),u}return n(i,t),i.prototype.getClassName=function(){return"VRDeviceOrientationArcRotateCamera"},i}(e.ArcRotateCamera);e.VRDeviceOrientationArcRotateCamera=r}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o){var s=t.call(this,i,r,o)||this;return s.interaxialDistance=n,s.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:n}),s}return n(i,t),i.prototype.getClassName=function(){return"AnaglyphFreeCamera"},i}(e.FreeCamera);e.AnaglyphFreeCamera=t;var i=function(t){function i(i,r,n,o,s,a,l){var h=t.call(this,i,r,n,o,s,l)||this;return h.interaxialDistance=a,h.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:a}),h}return n(i,t),i.prototype.getClassName=function(){return"AnaglyphArcRotateCamera"},i}(e.ArcRotateCamera);e.AnaglyphArcRotateCamera=i;var r=function(t){function i(i,r,n,o){var s=t.call(this,i,r,o)||this;return s.interaxialDistance=n,s.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:n}),s}return n(i,t),i.prototype.getClassName=function(){return"AnaglyphGamepadCamera"},i}(e.GamepadCamera);e.AnaglyphGamepadCamera=r;var o=function(t){function i(i,r,n,o){var s=t.call(this,i,r,o)||this;return s.interaxialDistance=n,s.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:n}),s}return n(i,t),i.prototype.getClassName=function(){return"AnaglyphUniversalCamera"},i}(e.UniversalCamera);e.AnaglyphUniversalCamera=o;var s=function(t){function i(i,r,n,o,s){var a=t.call(this,i,r,s)||this;return a.interaxialDistance=n,a.isStereoscopicSideBySide=o,a.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:n}),a}return n(i,t),i.prototype.getClassName=function(){return"StereoscopicFreeCamera"},i}(e.FreeCamera);e.StereoscopicFreeCamera=s;var a=function(t){function i(i,r,n,o,s,a,l,h){var u=t.call(this,i,r,n,o,s,h)||this;return u.interaxialDistance=a,u.isStereoscopicSideBySide=l,u.setCameraRigMode(l?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:a}),u}return n(i,t),i.prototype.getClassName=function(){return"StereoscopicArcRotateCamera"},i}(e.ArcRotateCamera);e.StereoscopicArcRotateCamera=a;var l=function(t){function i(i,r,n,o,s){var a=t.call(this,i,r,s)||this;return a.interaxialDistance=n,a.isStereoscopicSideBySide=o,a.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:n}),a}return n(i,t),i.prototype.getClassName=function(){return"StereoscopicGamepadCamera"},i}(e.GamepadCamera);e.StereoscopicGamepadCamera=l;var h=function(t){function i(i,r,n,o,s){var a=t.call(this,i,r,s)||this;return a.interaxialDistance=n,a.isStereoscopicSideBySide=o,a.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:n}),a}return n(i,t),i.prototype.getClassName=function(){return"StereoscopicUniversalCamera"},i}(e.UniversalCamera);e.StereoscopicUniversalCamera=h}(s||(s={}));!function(e){var t=function(){function t(t,i){void 0===i&&(i={});var r=this;this.webVROptions=i,this._webVRsupported=!1,this._webVRready=!1,this._webVRrequesting=!1,this._webVRpresenting=!1,this._fullscreenVRpresenting=!1,this._scene=t,!this._scene.activeCamera||isNaN(this._scene.activeCamera.position.x)?(this._position=new e.Vector3(0,2,0),this._deviceOrientationCamera=new e.DeviceOrientationCamera("deviceOrientationVRHelper",new e.Vector3(0,2,0),t)):(this._position=this._scene.activeCamera.position.clone(),this._deviceOrientationCamera=new e.DeviceOrientationCamera("deviceOrientationVRHelper",this._position,t),this._deviceOrientationCamera.minZ=this._scene.activeCamera.minZ,this._deviceOrientationCamera.maxZ=this._scene.activeCamera.maxZ),this._scene.activeCamera=this._deviceOrientationCamera,this._canvas=t.getEngine().getRenderingCanvas(),this._canvas&&this._scene.activeCamera.attachControl(this._canvas),this._btnVR=document.createElement("BUTTON"),this._btnVR.className="babylonVRicon",this._btnVR.id="babylonVRiconbtn",this._btnVR.title="Click to switch to VR";var n=".babylonVRicon { position: absolute; right: 20px; height: 50px; width: 80px; background-color: rgba(51,51,51,0.7); background-image: url(data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%222048%22%20height%3D%221152%22%20viewBox%3D%220%200%202048%201152%22%20version%3D%221.1%22%3E%3Cpath%20transform%3D%22rotate%28180%201024%2C576.0000000000001%29%22%20d%3D%22m1109%2C896q17%2C0%2030%2C-12t13%2C-30t-12.5%2C-30.5t-30.5%2C-12.5l-170%2C0q-18%2C0%20-30.5%2C12.5t-12.5%2C30.5t13%2C30t30%2C12l170%2C0zm-85%2C256q59%2C0%20132.5%2C-1.5t154.5%2C-5.5t164.5%2C-11.5t163%2C-20t150%2C-30t124.5%2C-41.5q23%2C-11%2042%2C-24t38%2C-30q27%2C-25%2041%2C-61.5t14%2C-72.5l0%2C-257q0%2C-123%20-47%2C-232t-128%2C-190t-190%2C-128t-232%2C-47l-81%2C0q-37%2C0%20-68.5%2C14t-60.5%2C34.5t-55.5%2C45t-53%2C45t-53%2C34.5t-55.5%2C14t-55.5%2C-14t-53%2C-34.5t-53%2C-45t-55.5%2C-45t-60.5%2C-34.5t-68.5%2C-14l-81%2C0q-123%2C0%20-232%2C47t-190%2C128t-128%2C190t-47%2C232l0%2C257q0%2C68%2038%2C115t97%2C73q54%2C24%20124.5%2C41.5t150%2C30t163%2C20t164.5%2C11.5t154.5%2C5.5t132.5%2C1.5zm939%2C-298q0%2C39%20-24.5%2C67t-58.5%2C42q-54%2C23%20-122%2C39.5t-143.5%2C28t-155.5%2C19t-157%2C11t-148.5%2C5t-129.5%2C1.5q-59%2C0%20-130%2C-1.5t-148%2C-5t-157%2C-11t-155.5%2C-19t-143.5%2C-28t-122%2C-39.5q-34%2C-14%20-58.5%2C-42t-24.5%2C-67l0%2C-257q0%2C-106%2040.5%2C-199t110%2C-162.5t162.5%2C-109.5t199%2C-40l81%2C0q27%2C0%2052%2C14t50%2C34.5t51%2C44.5t55.5%2C44.5t63.5%2C34.5t74%2C14t74%2C-14t63.5%2C-34.5t55.5%2C-44.5t51%2C-44.5t50%2C-34.5t52%2C-14l14%2C0q37%2C0%2070%2C0.5t64.5%2C4.5t63.5%2C12t68%2C23q71%2C30%20128.5%2C78.5t98.5%2C110t63.5%2C133.5t22.5%2C149l0%2C257z%22%20fill%3D%22white%22%20/%3E%3C/svg%3E%0A); background-size: 80%; background-repeat:no-repeat; background-position: center; border: none; outline: none; transition: transform 0.125s ease-out } .babylonVRicon:hover { transform: scale(1.05) } .babylonVRicon:active {background-color: rgba(51,51,51,1) } .babylonVRicon:focus {background-color: rgba(51,51,51,1) }";n+=".babylonVRicon.vrdisplaypresenting { display: none; }";var o=document.createElement("style");o.appendChild(document.createTextNode(n)),document.getElementsByTagName("head")[0].appendChild(o),this._canvas&&(this._btnVR.style.top=this._canvas.offsetTop+this._canvas.offsetHeight-70+"px",this._btnVR.style.left=this._canvas.offsetLeft+this._canvas.offsetWidth-100+"px",this._btnVR.addEventListener("click",function(){r.enterVR()}),window.addEventListener("resize",function(){r._canvas&&(r._btnVR.style.top=r._canvas.offsetTop+r._canvas.offsetHeight-70+"px",r._btnVR.style.left=r._canvas.offsetLeft+r._canvas.offsetWidth-100+"px"),r._fullscreenVRpresenting&&r._webVRready&&r.exitVR()})),document.addEventListener("fullscreenchange",function(){r._onFullscreenChange()},!1),document.addEventListener("mozfullscreenchange",function(){r._onFullscreenChange()},!1),document.addEventListener("webkitfullscreenchange",function(){r._onFullscreenChange()},!1),document.addEventListener("msfullscreenchange",function(){r._onFullscreenChange()},!1),document.body.appendChild(this._btnVR),this._onKeyDown=function(e){27===e.keyCode&&r.isInVRMode()&&r.exitVR()},document.addEventListener("keydown",this._onKeyDown),this._scene.onPrePointerObservable.add(function(e,t){r.isInVRMode()&&(r.exitVR(),r._fullscreenVRpresenting&&r._scene.getEngine().switchFullscreen(!0))},e.PointerEventTypes.POINTERDOUBLETAP,!1),this._onVRDisplayChanged=function(e){return r.onVRDisplayChanged(e)},this._onVrDisplayPresentChange=function(){return r.onVrDisplayPresentChange()},this._onVRRequestPresentStart=function(){r._webVRrequesting=!0,r.updateButtonVisibility()},this._onVRRequestPresentComplete=function(e){r._webVRrequesting=!1,r.updateButtonVisibility()},t.getEngine().onVRDisplayChangedObservable.add(this._onVRDisplayChanged),t.getEngine().onVRRequestPresentStart.add(this._onVRRequestPresentStart),t.getEngine().onVRRequestPresentComplete.add(this._onVRRequestPresentComplete),window.addEventListener("vrdisplaypresentchange",this._onVrDisplayPresentChange),this._vrDeviceOrientationCamera=new e.VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper",this._position,this._scene),this._webVRCamera=new e.WebVRFreeCamera("WebVRHelper",this._position,this._scene,i),this._webVRCamera.onControllerMeshLoadedObservable.add(function(e){return r._onDefaultMeshLoaded(e)}),this.updateButtonVisibility()}return Object.defineProperty(t.prototype,"deviceOrientationCamera",{get:function(){return this._deviceOrientationCamera},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"currentVRCamera",{get:function(){return this._webVRready?this._webVRCamera:this._vrDeviceOrientationCamera},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"webVRCamera",{get:function(){return this._webVRCamera},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vrDeviceOrientationCamera",{get:function(){return this._vrDeviceOrientationCamera},enumerable:!0,configurable:!0}),t.prototype._onDefaultMeshLoaded=function(e){this.onControllerMeshLoaded&&this.onControllerMeshLoaded(e)},t.prototype._onFullscreenChange=function(){void 0!==document.fullscreen?this._fullscreenVRpresenting=document.fullscreen:void 0!==document.mozFullScreen?this._fullscreenVRpresenting=document.mozFullScreen:void 0!==document.webkitIsFullScreen?this._fullscreenVRpresenting=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(this._fullscreenVRpresenting=document.msIsFullScreen),!this._fullscreenVRpresenting&&this._canvas&&(this.exitVR(),this._btnVR.style.top=this._canvas.offsetTop+this._canvas.offsetHeight-70+"px",this._btnVR.style.left=this._canvas.offsetLeft+this._canvas.offsetWidth-100+"px")},t.prototype.isInVRMode=function(){return this._webVRpresenting||this._fullscreenVRpresenting},t.prototype.onVrDisplayPresentChange=function(){var t=this._scene.getEngine().getVRDevice();if(t){var i=this._webVRpresenting;this._webVRpresenting=t.isPresenting,i&&!this._webVRpresenting&&this.exitVR()}else e.Tools.Warn("Detected VRDisplayPresentChange on an unknown VRDisplay. Did you can enterVR on the vrExperienceHelper?");this.updateButtonVisibility()},t.prototype.onVRDisplayChanged=function(e){this._webVRsupported=e.vrSupported,this._webVRready=!!e.vrDisplay,this._webVRpresenting=e.vrDisplay&&e.vrDisplay.isPresenting,this.updateButtonVisibility()},t.prototype.updateButtonVisibility=function(){this._btnVR&&(this._btnVR.className="babylonVRicon",this.isInVRMode()?this._btnVR.className+=" vrdisplaypresenting":(this._webVRready&&(this._btnVR.className+=" vrdisplayready"),this._webVRsupported&&(this._btnVR.className+=" vrdisplaysupported"),this._webVRrequesting&&(this._btnVR.className+=" vrdisplayrequesting")))},t.prototype.enterVR=function(){this._scene.activeCamera&&(this._position=this._scene.activeCamera.position.clone()),this.onEnteringVR&&this.onEnteringVR(),this._webVRrequesting||(this._webVRready?this._webVRpresenting||(this._webVRCamera.position=this._position,this._scene.activeCamera=this._webVRCamera):(this._vrDeviceOrientationCamera.position=this._position,this._scene.activeCamera=this._vrDeviceOrientationCamera,this._scene.getEngine().switchFullscreen(!0),this.updateButtonVisibility()),this._scene.activeCamera&&this._canvas&&this._scene.activeCamera.attachControl(this._canvas))},t.prototype.exitVR=function(){this.onExitingVR&&this.onExitingVR(),this._webVRpresenting&&this._scene.getEngine().disableVR(),this._scene.activeCamera&&(this._position=this._scene.activeCamera.position.clone()),this._deviceOrientationCamera.position=this._position,this._scene.activeCamera=this._deviceOrientationCamera,this._canvas&&this._scene.activeCamera.attachControl(this._canvas),this.updateButtonVisibility()},Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(e){this._position=e,this._scene.activeCamera&&(this._scene.activeCamera.position=e)},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){this.isInVRMode()&&this.exitVR(),this._deviceOrientationCamera.dispose(),this._webVRCamera&&this._webVRCamera.dispose(),this._vrDeviceOrientationCamera&&this._vrDeviceOrientationCamera.dispose(),document.body.removeChild(this._btnVR),document.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("vrdisplaypresentchange",this._onVrDisplayPresentChange)},t.prototype.getClassName=function(){return"VRExperienceHelper"},t}();e.VRExperienceHelper=t}(s||(s={}));!function(e){var t;!function(e){e[e.X=0]="X",e[e.Y=1]="Y",e[e.Z=2]="Z"}(t=e.JoystickAxis||(e.JoystickAxis={}));var i=function(){function i(r){var n=this;if(this._leftJoystick=!!r,this._joystickIndex=i._globalJoystickIndex,i._globalJoystickIndex++,this._axisTargetedByLeftAndRight=t.X,this._axisTargetedByUpAndDown=t.Y,this.reverseLeftRight=!1,this.reverseUpDown=!1,this._touches=new e.StringDictionary,this.deltaPosition=e.Vector3.Zero(),this._joystickSensibility=25,this._inversedSensibility=1/(this._joystickSensibility/1e3),this._rotationSpeed=25,this._inverseRotationSpeed=1/(this._rotationSpeed/1e3),this._rotateOnAxisRelativeToMesh=!1,this._onResize=function(e){i.vjCanvasWidth=window.innerWidth,i.vjCanvasHeight=window.innerHeight,i.vjCanvas&&(i.vjCanvas.width=i.vjCanvasWidth,i.vjCanvas.height=i.vjCanvasHeight),i.halfWidth=i.vjCanvasWidth/2,i.halfHeight=i.vjCanvasHeight/2},!i.vjCanvas){window.addEventListener("resize",this._onResize,!1),i.vjCanvas=document.createElement("canvas"),i.vjCanvasWidth=window.innerWidth,i.vjCanvasHeight=window.innerHeight,i.vjCanvas.width=window.innerWidth,i.vjCanvas.height=window.innerHeight,i.vjCanvas.style.width="100%",i.vjCanvas.style.height="100%",i.vjCanvas.style.position="absolute",i.vjCanvas.style.backgroundColor="transparent",i.vjCanvas.style.top="0px",i.vjCanvas.style.left="0px",i.vjCanvas.style.zIndex="5",i.vjCanvas.style.msTouchAction="none",i.vjCanvas.setAttribute("touch-action","none");var o=i.vjCanvas.getContext("2d");if(!o)throw new Error("Unable to create canvas for virtual joystick");i.vjCanvasContext=o,i.vjCanvasContext.strokeStyle="#ffffff",i.vjCanvasContext.lineWidth=2,document.body.appendChild(i.vjCanvas)}i.halfWidth=i.vjCanvas.width/2,i.halfHeight=i.vjCanvas.height/2,this.pressed=!1,this._joystickColor="cyan",this._joystickPointerID=-1,this._joystickPointerPos=new e.Vector2(0,0),this._joystickPreviousPointerPos=new e.Vector2(0,0),this._joystickPointerStartPos=new e.Vector2(0,0),this._deltaJoystickVector=new e.Vector2(0,0),this._onPointerDownHandlerRef=function(e){n._onPointerDown(e)},this._onPointerMoveHandlerRef=function(e){n._onPointerMove(e)},this._onPointerOutHandlerRef=function(e){n._onPointerUp(e)},this._onPointerUpHandlerRef=function(e){n._onPointerUp(e)},i.vjCanvas.addEventListener("pointerdown",this._onPointerDownHandlerRef,!1),i.vjCanvas.addEventListener("pointermove",this._onPointerMoveHandlerRef,!1),i.vjCanvas.addEventListener("pointerup",this._onPointerUpHandlerRef,!1),i.vjCanvas.addEventListener("pointerout",this._onPointerUpHandlerRef,!1),i.vjCanvas.addEventListener("contextmenu",function(e){e.preventDefault()},!1),requestAnimationFrame(function(){n._drawVirtualJoystick()})}return i.prototype.setJoystickSensibility=function(e){this._joystickSensibility=e,this._inversedSensibility=1/(this._joystickSensibility/1e3)},i.prototype._onPointerDown=function(e){e.preventDefault(),(!0===this._leftJoystick?e.clientX<i.halfWidth:e.clientX>i.halfWidth)&&this._joystickPointerID<0?(this._joystickPointerID=e.pointerId,this._joystickPointerStartPos.x=e.clientX,this._joystickPointerStartPos.y=e.clientY,this._joystickPointerPos=this._joystickPointerStartPos.clone(),this._joystickPreviousPointerPos=this._joystickPointerStartPos.clone(),this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this.pressed=!0,this._touches.add(e.pointerId.toString(),e)):i._globalJoystickIndex<2&&this._action&&(this._action(),this._touches.add(e.pointerId.toString(),{x:e.clientX,y:e.clientY,prevX:e.clientX,prevY:e.clientY}))},i.prototype._onPointerMove=function(e){if(this._joystickPointerID==e.pointerId){this._joystickPointerPos.x=e.clientX,this._joystickPointerPos.y=e.clientY,this._deltaJoystickVector=this._joystickPointerPos.clone(),this._deltaJoystickVector=this._deltaJoystickVector.subtract(this._joystickPointerStartPos);var i=(this.reverseLeftRight?-1:1)*this._deltaJoystickVector.x/this._inversedSensibility;switch(this._axisTargetedByLeftAndRight){case t.X:this.deltaPosition.x=Math.min(1,Math.max(-1,i));break;case t.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,i));break;case t.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,i))}var r=(this.reverseUpDown?1:-1)*this._deltaJoystickVector.y/this._inversedSensibility;switch(this._axisTargetedByUpAndDown){case t.X:this.deltaPosition.x=Math.min(1,Math.max(-1,r));break;case t.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,r));break;case t.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,r))}}else{var n=this._touches.get(e.pointerId.toString());n&&(n.x=e.clientX,n.y=e.clientY)}},i.prototype._onPointerUp=function(e){if(this._joystickPointerID==e.pointerId)i.vjCanvasContext.clearRect(this._joystickPointerStartPos.x-64,this._joystickPointerStartPos.y-64,128,128),i.vjCanvasContext.clearRect(this._joystickPreviousPointerPos.x-42,this._joystickPreviousPointerPos.y-42,84,84),this._joystickPointerID=-1,this.pressed=!1;else{var t=this._touches.get(e.pointerId.toString());t&&i.vjCanvasContext.clearRect(t.prevX-44,t.prevY-44,88,88)}this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this._touches.remove(e.pointerId.toString())},i.prototype.setJoystickColor=function(e){this._joystickColor=e},i.prototype.setActionOnTouch=function(e){this._action=e},i.prototype.setAxisForLeftRight=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByLeftAndRight=e;break;default:this._axisTargetedByLeftAndRight=t.X}},i.prototype.setAxisForUpDown=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByUpAndDown=e;break;default:this._axisTargetedByUpAndDown=t.Y}},i.prototype._drawVirtualJoystick=function(){var e=this;this.pressed&&this._touches.forEach(function(t,r){r.pointerId===e._joystickPointerID?(i.vjCanvasContext.clearRect(e._joystickPointerStartPos.x-64,e._joystickPointerStartPos.y-64,128,128),i.vjCanvasContext.clearRect(e._joystickPreviousPointerPos.x-42,e._joystickPreviousPointerPos.y-42,84,84),i.vjCanvasContext.beginPath(),i.vjCanvasContext.lineWidth=6,i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.lineWidth=2,i.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,60,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.arc(e._joystickPointerPos.x,e._joystickPointerPos.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),e._joystickPreviousPointerPos=e._joystickPointerPos.clone()):(i.vjCanvasContext.clearRect(r.prevX-44,r.prevY-44,88,88),i.vjCanvasContext.beginPath(),i.vjCanvasContext.fillStyle="white",i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle="red",i.vjCanvasContext.lineWidth=6,i.vjCanvasContext.arc(r.x,r.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),r.prevX=r.x,r.prevY=r.y)}),requestAnimationFrame(function(){e._drawVirtualJoystick()})},i.prototype.releaseCanvas=function(){i.vjCanvas&&(i.vjCanvas.removeEventListener("pointerdown",this._onPointerDownHandlerRef),i.vjCanvas.removeEventListener("pointermove",this._onPointerMoveHandlerRef),i.vjCanvas.removeEventListener("pointerup",this._onPointerUpHandlerRef),i.vjCanvas.removeEventListener("pointerout",this._onPointerUpHandlerRef),window.removeEventListener("resize",this._onResize),document.body.removeChild(i.vjCanvas),i.vjCanvas=null)},i._globalJoystickIndex=0,i}();e.VirtualJoystick=i}(s||(s={}));!function(e){var t=function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n.inputs.addVirtualJoystick(),n}return n(t,e),t.prototype.getClassName=function(){return"VirtualJoysticksCamera"},t}(e.FreeCamera);e.VirtualJoysticksCamera=t}(s||(s={}));!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(),r=e.Matrix.RotationYawPitchRoll(t.rotation.y,t.rotation.x,0),n=e.Vector3.TransformCoordinates(new e.Vector3(this._leftjoystick.deltaPosition.x*i,this._leftjoystick.deltaPosition.y*i,this._leftjoystick.deltaPosition.z*i),r);t.cameraDirection=t.cameraDirection.add(n),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.getClassName=function(){return"FreeCameraVirtualJoystickInput"},t.prototype.getSimpleName=function(){return"virtualJoystick"},t}();e.FreeCameraVirtualJoystickInput=t,e.CameraInputTypes.FreeCameraVirtualJoystickInput=t}(s||(s={}));!function(e){var t=function(){return function(e,t,i){this.quality=e,this.distance=t,this.optimizeMesh=i}}();e.SimplificationSettings=t;var i=function(){function t(){this.running=!1,this._simplificationArray=[]}return t.prototype.addTask=function(e){this._simplificationArray.push(e)},t.prototype.executeNext=function(){var e=this._simplificationArray.pop();e?(this.running=!0,this.runSimplification(e)):this.running=!1},t.prototype.runSimplification=function(t){var i=this;if(t.parallelProcessing)t.settings.forEach(function(e){i.getSimplifier(t).simplify(e,function(r){t.mesh.addLODLevel(e.distance,r),r.isVisible=!0,e.quality===t.settings[t.settings.length-1].quality&&t.successCallback&&t.successCallback(),i.executeNext()})});else{var r=this.getSimplifier(t),n=function(e,i){r.simplify(e,function(r){t.mesh.addLODLevel(e.distance,r),r.isVisible=!0,i()})};e.AsyncLoop.Run(t.settings.length,function(e){n(t.settings[e.index],function(){e.executeNext()})},function(){t.successCallback&&t.successCallback(),i.executeNext()})}},t.prototype.getSimplifier=function(e){switch(e.simplificationType){case r.QUADRATIC:default:return new l(e.mesh)}},t}();e.SimplificationQueue=i;var r;!function(e){e[e.QUADRATIC=0]="QUADRATIC"}(r=e.SimplificationType||(e.SimplificationType={}));var n=function(){return function(e){this.vertices=e,this.error=new Array(4),this.deleted=!1,this.isDirty=!1,this.deletePending=!1,this.borderFactor=0}}();e.DecimationTriangle=n;var o=function(){function e(e,t){this.position=e,this.id=t,this.isBorder=!0,this.q=new s,this.triangleCount=0,this.triangleStart=0,this.originalOffsets=[]}return e.prototype.updatePosition=function(e){this.position.copyFrom(e)},e}();e.DecimationVertex=o;var s=function(){function e(e){this.data=new Array(10);for(var t=0;t<10;++t)e&&e[t]?this.data[t]=e[t]:this.data[t]=0}return e.prototype.det=function(e,t,i,r,n,o,s,a,l){return this.data[e]*this.data[n]*this.data[l]+this.data[i]*this.data[r]*this.data[a]+this.data[t]*this.data[o]*this.data[s]-this.data[i]*this.data[n]*this.data[s]-this.data[e]*this.data[o]*this.data[a]-this.data[t]*this.data[r]*this.data[l]},e.prototype.addInPlace=function(e){for(var t=0;t<10;++t)this.data[t]+=e.data[t]},e.prototype.addArrayInPlace=function(e){for(var t=0;t<10;++t)this.data[t]+=e[t]},e.prototype.add=function(t){for(var i=new e,r=0;r<10;++r)i.data[r]=this.data[r]+t.data[r];return i},e.FromData=function(t,i,r,n){return new e(e.DataFromNumbers(t,i,r,n))},e.DataFromNumbers=function(e,t,i,r){return[e*e,e*t,e*i,e*r,t*t,t*i,t*r,i*i,i*r,r*r]},e}();e.QuadraticMatrix=s;var a=function(){return function(e,t){this.vertexId=e,this.triangleId=t}}();e.Reference=a;var l=function(){function t(t){this._mesh=t,this.initialized=!1,this.syncIterations=5e3,this.aggressiveness=7,this.decimationIterations=100,this.boundingBoxEpsilon=e.Epsilon}return t.prototype.simplify=function(t,i){var r=this;this.initDecimatedMesh(),e.AsyncLoop.Run(this._mesh.subMeshes.length,function(e){r.initWithMesh(e.index,function(){r.runDecimation(t,e.index,function(){e.executeNext()})},t.optimizeMesh)},function(){setTimeout(function(){i(r._reconstructedMesh)},0)})},t.prototype.runDecimation=function(t,i,r){var n=this,o=~~(this.triangles.length*t.quality),s=0,a=this.triangles.length,l=function(t,i){setTimeout(function(){t%5==0&&n.updateMesh(0===t);for(var r=0;r<n.triangles.length;++r)n.triangles[r].isDirty=!1;var l=1e-9*Math.pow(t+3,n.aggressiveness);e.AsyncLoop.SyncAsyncForLoop(n.triangles.length,n.syncIterations,function(t){var i=~~((n.triangles.length/2+t)%n.triangles.length),r=n.triangles[i];if(r&&!(r.error[3]>l||r.deleted||r.isDirty))for(var o=0;o<3;++o)if(r.error[o]<l){var a=[],h=[],u=r.vertices[o],c=r.vertices[(o+1)%3];if(u.isBorder||c.isBorder)continue;var f=e.Vector3.Zero(),p=e.Vector3.Zero(),d=e.Vector2.Zero(),m=new e.Color4(0,0,0,1);n.calculateError(u,c,f,p,d,m);var g=new Array;if(n.isFlipped(u,c,f,a,r.borderFactor,g))continue;if(n.isFlipped(c,u,f,h,r.borderFactor,g))continue;if(a.indexOf(!0)<0||h.indexOf(!0)<0)continue;var v=new Array;if(g.forEach(function(e){-1===v.indexOf(e)&&(e.deletePending=!0,v.push(e))}),v.length%2!=0)continue;u.q=c.q.add(u.q),u.updatePosition(f);var _=n.references.length;s=n.updateTriangles(u,u,a,s),s=n.updateTriangles(u,c,h,s);var y=n.references.length-_;if(y<=u.triangleCount){if(y)for(var x=0;x<y;x++)n.references[u.triangleStart+x]=n.references[_+x]}else u.triangleStart=_;u.triangleCount=y;break}},i,function(){return a-s<=o})},0)};e.AsyncLoop.Run(this.decimationIterations,function(e){a-s<=o?e.breakLoop():l(e.index,function(){e.executeNext()})},function(){setTimeout(function(){n.reconstructMesh(i),r()},0)})},t.prototype.initWithMesh=function(t,i,r){var s=this;this.vertices=[],this.triangles=[];var a=this._mesh.getVerticesData(e.VertexBuffer.PositionKind),l=this._mesh.getIndices(),h=this._mesh.subMeshes[t],u=function(e){if(r)for(var t=0;t<s.vertices.length;++t)if(s.vertices[t].position.equals(e))return s.vertices[t];return null},c=[],f=h.verticesCount;e.AsyncLoop.SyncAsyncForLoop(f,this.syncIterations/4>>0,function(t){if(a){var i=t+h.verticesStart,r=e.Vector3.FromArray(a,3*i),n=u(r)||new o(r,s.vertices.length);n.originalOffsets.push(i),n.id===s.vertices.length&&s.vertices.push(n),c.push(n.id)}},function(){e.AsyncLoop.SyncAsyncForLoop(h.indexCount/3,s.syncIterations,function(e){if(l){var t=3*(h.indexStart/3+e),i=l[t+0],r=l[t+1],o=l[t+2],a=s.vertices[c[i-h.verticesStart]],u=s.vertices[c[r-h.verticesStart]],f=s.vertices[c[o-h.verticesStart]],p=new n([a,u,f]);p.originalOffset=t,s.triangles.push(p)}},function(){s.init(i)})})},t.prototype.init=function(t){var i=this;e.AsyncLoop.SyncAsyncForLoop(this.triangles.length,this.syncIterations,function(t){var r=i.triangles[t];r.normal=e.Vector3.Cross(r.vertices[1].position.subtract(r.vertices[0].position),r.vertices[2].position.subtract(r.vertices[0].position)).normalize();for(var n=0;n<3;n++)r.vertices[n].q.addArrayInPlace(s.DataFromNumbers(r.normal.x,r.normal.y,r.normal.z,-e.Vector3.Dot(r.normal,r.vertices[0].position)))},function(){e.AsyncLoop.SyncAsyncForLoop(i.triangles.length,i.syncIterations,function(e){for(var t=i.triangles[e],r=0;r<3;++r)t.error[r]=i.calculateError(t.vertices[r],t.vertices[(r+1)%3]);t.error[3]=Math.min(t.error[0],t.error[1],t.error[2])},function(){i.initialized=!0,t()})})},t.prototype.reconstructMesh=function(t){var i,r=[];for(i=0;i<this.vertices.length;++i)this.vertices[i].triangleCount=0;var n,o;for(i=0;i<this.triangles.length;++i)if(!this.triangles[i].deleted){for(n=this.triangles[i],o=0;o<3;++o)n.vertices[o].triangleCount=1;r.push(n)}var s=this._reconstructedMesh.getVerticesData(e.VertexBuffer.PositionKind)||[],a=this._reconstructedMesh.getVerticesData(e.VertexBuffer.NormalKind)||[],l=this._reconstructedMesh.getVerticesData(e.VertexBuffer.UVKind)||[],h=this._reconstructedMesh.getVerticesData(e.VertexBuffer.ColorKind)||[],u=this._mesh.getVerticesData(e.VertexBuffer.NormalKind),c=this._mesh.getVerticesData(e.VertexBuffer.UVKind),f=this._mesh.getVerticesData(e.VertexBuffer.ColorKind),p=0;for(i=0;i<this.vertices.length;++i){var d=this.vertices[i];d.id=p,d.triangleCount&&d.originalOffsets.forEach(function(e){u&&(s.push(d.position.x),s.push(d.position.y),s.push(d.position.z),a.push(u[3*e]),a.push(u[3*e+1]),a.push(u[3*e+2]),c&&c.length?(l.push(c[2*e]),l.push(c[2*e+1])):f&&f.length&&(h.push(f[4*e]),h.push(f[4*e+1]),h.push(f[4*e+2]),h.push(f[4*e+3])),++p)})}var m=this._reconstructedMesh.getTotalIndices(),g=this._reconstructedMesh.getTotalVertices(),v=this._reconstructedMesh.subMeshes;this._reconstructedMesh.subMeshes=[];var _=this._reconstructedMesh.getIndices(),y=this._mesh.getIndices();for(i=0;i<r.length;++i)n=r[i],[0,1,2].forEach(function(e){var t=y[n.originalOffset+e],i=n.vertices[e].originalOffsets.indexOf(t);i<0&&(i=0),_.push(n.vertices[e].id+i+g)});this._reconstructedMesh.setIndices(_),this._reconstructedMesh.setVerticesData(e.VertexBuffer.PositionKind,s),this._reconstructedMesh.setVerticesData(e.VertexBuffer.NormalKind,a),l.length>0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.UVKind,l),h.length>0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.ColorKind,h);var x=this._mesh.subMeshes[t];t>0&&(this._reconstructedMesh.subMeshes=[],v.forEach(function(t){e.SubMesh.AddToMesh(t.materialIndex,t.verticesStart,t.verticesCount,t.indexStart,t.indexCount,t.getMesh())}),e.SubMesh.AddToMesh(x.materialIndex,g,p,m,3*r.length,this._reconstructedMesh))},t.prototype.initDecimatedMesh=function(){this._reconstructedMesh=new e.Mesh(this._mesh.name+"Decimated",this._mesh.getScene()),this._reconstructedMesh.material=this._mesh.material,this._reconstructedMesh.parent=this._mesh.parent,this._reconstructedMesh.isVisible=!1,this._reconstructedMesh.renderingGroupId=this._mesh.renderingGroupId},t.prototype.isFlipped=function(t,i,r,n,o,s){for(var a=0;a<t.triangleCount;++a){var l=this.triangles[this.references[t.triangleStart+a].triangleId];if(!l.deleted){var h=this.references[t.triangleStart+a].vertexId,u=l.vertices[(h+1)%3],c=l.vertices[(h+2)%3];if(u!==i&&c!==i){var f=u.position.subtract(r);f=f.normalize();var p=c.position.subtract(r);if(p=p.normalize(),Math.abs(e.Vector3.Dot(f,p))>.999)return!0;var d=e.Vector3.Cross(f,p).normalize();if(n[a]=!1,e.Vector3.Dot(d,l.normal)<.2)return!0}else n[a]=!0,s.push(l)}}return!1},t.prototype.updateTriangles=function(e,t,i,r){for(var n=r,o=0;o<t.triangleCount;++o){var s=this.references[t.triangleStart+o],a=this.triangles[s.triangleId];a.deleted||(i[o]&&a.deletePending?(a.deleted=!0,n++):(a.vertices[s.vertexId]=e,a.isDirty=!0,a.error[0]=this.calculateError(a.vertices[0],a.vertices[1])+a.borderFactor/2,a.error[1]=this.calculateError(a.vertices[1],a.vertices[2])+a.borderFactor/2,a.error[2]=this.calculateError(a.vertices[2],a.vertices[0])+a.borderFactor/2,a.error[3]=Math.min(a.error[0],a.error[1],a.error[2]),this.references.push(s)))}return n},t.prototype.identifyBorder=function(){for(var e=0;e<this.vertices.length;++e){var t,i=[],r=[],n=this.vertices[e];for(t=0;t<n.triangleCount;++t)for(var o=this.triangles[this.references[n.triangleStart+t].triangleId],s=0;s<3;s++){for(var a=0,l=o.vertices[s];a<i.length&&r[a]!==l.id;)++a;a===i.length?(i.push(1),r.push(l.id)):i[a]++}for(t=0;t<i.length;++t)1===i[t]?this.vertices[r[t]].isBorder=!0:this.vertices[r[t]].isBorder=!1}},t.prototype.updateMesh=function(e){void 0===e&&(e=!1);var t;if(!e){var i=[];for(t=0;t<this.triangles.length;++t)this.triangles[t].deleted||i.push(this.triangles[t]);this.triangles=i}for(t=0;t<this.vertices.length;++t)this.vertices[t].triangleCount=0,this.vertices[t].triangleStart=0;var r,n,o;for(t=0;t<this.triangles.length;++t)for(r=this.triangles[t],n=0;n<3;++n)(o=r.vertices[n]).triangleCount++;var s=0;for(t=0;t<this.vertices.length;++t)this.vertices[t].triangleStart=s,s+=this.vertices[t].triangleCount,this.vertices[t].triangleCount=0;var l=new Array(3*this.triangles.length);for(t=0;t<this.triangles.length;++t)for(r=this.triangles[t],n=0;n<3;++n)l[(o=r.vertices[n]).triangleStart+o.triangleCount]=new a(n,t),o.triangleCount++;this.references=l,e&&this.identifyBorder()},t.prototype.vertexError=function(e,t){var i=t.x,r=t.y,n=t.z;return e.data[0]*i*i+2*e.data[1]*i*r+2*e.data[2]*i*n+2*e.data[3]*i+e.data[4]*r*r+2*e.data[5]*r*n+2*e.data[6]*r+e.data[7]*n*n+2*e.data[8]*n+e.data[9]},t.prototype.calculateError=function(t,i,r,n,o,s){var a=t.q.add(i.q),l=t.isBorder&&i.isBorder,h=0,u=a.det(0,1,2,1,4,5,2,5,7);if(0===u||l){var c=t.position.add(i.position).divide(new e.Vector3(2,2,2)),f=this.vertexError(a,t.position),p=this.vertexError(a,i.position),d=this.vertexError(a,c);(h=Math.min(f,p,d))===f?r&&r.copyFrom(t.position):h===p?r&&r.copyFrom(i.position):r&&r.copyFrom(c)}else r||(r=e.Vector3.Zero()),r.x=-1/u*a.det(1,2,3,4,5,6,5,7,8),r.y=1/u*a.det(0,2,3,1,5,6,2,7,8),r.z=-1/u*a.det(0,1,3,1,4,6,2,5,8),h=this.vertexError(a,r);return h},t}();e.QuadraticErrorSimplification=l}(s||(s={}));!function(e){!function(e){var t=function(){return function(e,t){this.distance=e,this.mesh=t}}();e.MeshLODLevel=t}(e.Internals||(e.Internals={}))}(s||(s={}));!function(e){var t=function(){return function(e){void 0===e&&(e=0),this.priority=e,this.apply=function(e){return!0}}}();e.SceneOptimization=t;var i=function(e){function t(t,i){void 0===t&&(t=0),void 0===i&&(i=1024);var r=e.call(this,t)||this;return r.priority=t,r.maximumSize=i,r.apply=function(e){for(var t=!0,i=0;i<e.textures.length;i++){var n=e.textures[i];if(n.canRescale&&!n.getContext){var o=n.getSize();Math.max(o.width,o.height)>r.maximumSize&&(n.scale(.5),t=!1)}}return t},r}return n(t,e),t}(t);e.TextureOptimization=i;var r=function(e){function t(t,i){void 0===t&&(t=0),void 0===i&&(i=2);var r=e.call(this,t)||this;return r.priority=t,r.maximumScale=i,r._currentScale=1,r.apply=function(e){return r._currentScale++,e.getEngine().setHardwareScalingLevel(r._currentScale),r._currentScale>=r.maximumScale},r}return n(t,e),t}(t);e.HardwareScalingOptimization=r;var o=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.apply=function(e){return e.shadowsEnabled=!1,!0},t}return n(t,e),t}(t);e.ShadowsOptimization=o;var s=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.apply=function(e){return e.postProcessesEnabled=!1,!0},t}return n(t,e),t}(t);e.PostProcessesOptimization=s;var a=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.apply=function(e){return e.lensFlaresEnabled=!1,!0},t}return n(t,e),t}(t);e.LensFlaresOptimization=a;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.apply=function(e){return e.particlesEnabled=!1,!0},t}return n(t,e),t}(t);e.ParticlesOptimization=l;var h=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.apply=function(e){return e.renderTargetsEnabled=!1,!0},t}return n(t,e),t}(t);e.RenderTargetsOptimization=h;var u=function(t){function i(){var r=null!==t&&t.apply(this,arguments)||this;return r._canBeMerged=function(t){if(!(t instanceof e.Mesh))return!1;var i=t;return!(!i.isVisible||!i.isEnabled())&&(!(i.instances.length>0)&&(!i.skeleton&&!i.hasLODLevels&&!i.parent))},r.apply=function(t,n){for(var o=t.meshes.slice(0),s=o.length,a=0;a<s;a++){var l=new Array,h=o[a];if(r._canBeMerged(h)){l.push(h);for(var u=a+1;u<s;u++){var c=o[u];r._canBeMerged(c)&&(c.material===h.material&&c.checkCollisions===h.checkCollisions&&(l.push(c),s--,o.splice(u,1),u--))}l.length<2||e.Mesh.MergeMeshes(l)}}return void 0!=n?n&&t.createOrUpdateSelectionOctree():i.UpdateSelectionTree&&t.createOrUpdateSelectionOctree(),!0},r}return n(i,t),Object.defineProperty(i,"UpdateSelectionTree",{get:function(){return i._UpdateSelectionTree},set:function(e){i._UpdateSelectionTree=e},enumerable:!0,configurable:!0}),i._UpdateSelectionTree=!1,i}(t);e.MergeMeshesOptimization=u;var c=function(){function e(e,t){void 0===e&&(e=60),void 0===t&&(t=2e3),this.targetFrameRate=e,this.trackerDuration=t,this.optimizations=new Array}return e.LowDegradationAllowed=function(t){var r=new e(t),n=0;return r.optimizations.push(new u(n)),r.optimizations.push(new o(n)),r.optimizations.push(new a(n)),n++,r.optimizations.push(new s(n)),r.optimizations.push(new l(n)),n++,r.optimizations.push(new i(n,1024)),r},e.ModerateDegradationAllowed=function(t){var n=new e(t),c=0;return n.optimizations.push(new u(c)),n.optimizations.push(new o(c)),n.optimizations.push(new a(c)),c++,n.optimizations.push(new s(c)),n.optimizations.push(new l(c)),c++,n.optimizations.push(new i(c,512)),c++,n.optimizations.push(new h(c)),c++,n.optimizations.push(new r(c,2)),n},e.HighDegradationAllowed=function(t){var n=new e(t),c=0;return n.optimizations.push(new u(c)),n.optimizations.push(new o(c)),n.optimizations.push(new a(c)),c++,n.optimizations.push(new s(c)),n.optimizations.push(new l(c)),c++,n.optimizations.push(new i(c,256)),c++,n.optimizations.push(new h(c)),c++,n.optimizations.push(new r(c,4)),n},e}();e.SceneOptimizerOptions=c;var f=function(){function e(){}return e._CheckCurrentState=function(t,i,r,n,o){if(t.getEngine().getFps()>=i.targetFrameRate)n&&n();else{for(var s=!0,a=!0,l=0;l<i.optimizations.length;l++){var h=i.optimizations[l];h.priority===r&&(a=!1,s=s&&h.apply(t))}a?o&&o():(s&&r++,t.executeWhenReady(function(){setTimeout(function(){e._CheckCurrentState(t,i,r,n,o)},i.trackerDuration)}))}},e.OptimizeAsync=function(t,i,r,n){i||(i=c.ModerateDegradationAllowed()),t.executeWhenReady(function(){setTimeout(function(){e._CheckCurrentState(t,i,0,r,n)},i.trackerDuration)})},e}();e.SceneOptimizer=f}(s||(s={}));!function(e){var t=function(){function t(e){this.zOffset=1,this._scene=e}return t.prototype.render=function(t,i,r){var n=this;void 0===r&&(r=!1);var o=this._scene,s=this._scene.getEngine(),a=s.getCaps().instancedArrays&&null!==i.visibleInstances[t._id]&&void 0!==i.visibleInstances[t._id];if(this.isReady(t,a)){var l=t.getRenderingMesh(),h=t.getMaterial();if(h&&o.activeCamera){if(s.enableEffect(this._effect),h.useLogarithmicDepth&&this._effect.setFloat("logarithmicDepthConstant",2/(Math.log(o.activeCamera.maxZ+1)/Math.LN2)),this._effect.setFloat("offset",r?0:l.outlineWidth),this._effect.setColor4("color",r?l.overlayColor:l.outlineColor,r?l.overlayAlpha:h.alpha),this._effect.setMatrix("viewProjection",o.getTransformMatrix()),l.useBones&&l.computeBonesUsingShaders&&l.skeleton&&this._effect.setMatrices("mBones",l.skeleton.getTransformMatrices(l)),l._bind(t,this._effect,e.Material.TriangleFillMode),h&&h.needAlphaTesting()){var u=h.getAlphaTestTexture();u&&(this._effect.setTexture("diffuseSampler",u),this._effect.setMatrix("diffuseMatrix",u.getTextureMatrix()))}s.setZOffset(-this.zOffset),l._processRendering(t,this._effect,e.Material.TriangleFillMode,i,a,function(e,t){n._effect.setMatrix("world",t)}),s.setZOffset(0)}}},t.prototype.isReady=function(t,i){var r=[],n=[e.VertexBuffer.PositionKind,e.VertexBuffer.NormalKind],o=t.getMesh(),s=t.getMaterial();s&&(s.needAlphaTesting()&&(r.push("#define ALPHATEST"),o.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(n.push(e.VertexBuffer.UVKind),r.push("#define UV1")),o.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(n.push(e.VertexBuffer.UV2Kind),r.push("#define UV2"))),s.useLogarithmicDepth&&r.push("#define LOGARITHMICDEPTH")),o.useBones&&o.computeBonesUsingShaders?(n.push(e.VertexBuffer.MatricesIndicesKind),n.push(e.VertexBuffer.MatricesWeightsKind),o.numBoneInfluencers>4&&(n.push(e.VertexBuffer.MatricesIndicesExtraKind),n.push(e.VertexBuffer.MatricesWeightsExtraKind)),r.push("#define NUM_BONE_INFLUENCERS "+o.numBoneInfluencers),r.push("#define BonesPerMesh "+(o.skeleton?o.skeleton.bones.length+1:0))):r.push("#define NUM_BONE_INFLUENCERS 0"),i&&(r.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var a=r.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("outline",n,["world","mBones","viewProjection","diffuseMatrix","offset","color","logarithmicDepthConstant"],["diffuseSampler"],a)),this._effect.isReady()},t}();e.OutlineRenderer=t}(s||(s={}));!function(e){var t=function(){return function(){this.edges=new Array,this.edgesConnectedCount=0}}(),i=function(){function i(e,t,i){void 0===t&&(t=.95),void 0===i&&(i=!1),this.edgesWidthScalerForOrthographic=1e3,this.edgesWidthScalerForPerspective=50,this._linesPositions=new Array,this._linesNormals=new Array,this._linesIndices=new Array,this._buffers={},this._checkVerticesInsteadOfIndices=!1,this._source=e,this._checkVerticesInsteadOfIndices=i,this._epsilon=t,this._prepareRessources(),this._generateEdgesLines()}return i.prototype._prepareRessources=function(){this._lineShader||(this._lineShader=new e.ShaderMaterial("lineShader",this._source.getScene(),"line",{attributes:["position","normal"],uniforms:["worldViewProjection","color","width","aspectRatio"]}),this._lineShader.disableDepthWrite=!0,this._lineShader.backFaceCulling=!1)},i.prototype._rebuild=function(){var t=this._buffers[e.VertexBuffer.PositionKind];t&&t._rebuild(),(t=this._buffers[e.VertexBuffer.NormalKind])&&t._rebuild();var i=this._source.getScene().getEngine();this._ib=i.createIndexBuffer(this._linesIndices)},i.prototype.dispose=function(){var t=this._buffers[e.VertexBuffer.PositionKind];t&&(t.dispose(),this._buffers[e.VertexBuffer.PositionKind]=null),(t=this._buffers[e.VertexBuffer.NormalKind])&&(t.dispose(),this._buffers[e.VertexBuffer.NormalKind]=null),this._source.getScene().getEngine()._releaseBuffer(this._ib),this._lineShader.dispose()},i.prototype._processEdgeForAdjacencies=function(e,t,i,r,n){return e===i&&t===r||e===r&&t===i?0:e===r&&t===n||e===n&&t===r?1:e===n&&t===i||e===i&&t===n?2:-1},i.prototype._processEdgeForAdjacenciesWithVertices=function(e,t,i,r,n){return e.equalsWithEpsilon(i)&&t.equalsWithEpsilon(r)||e.equalsWithEpsilon(r)&&t.equalsWithEpsilon(i)?0:e.equalsWithEpsilon(r)&&t.equalsWithEpsilon(n)||e.equalsWithEpsilon(n)&&t.equalsWithEpsilon(r)?1:e.equalsWithEpsilon(n)&&t.equalsWithEpsilon(i)||e.equalsWithEpsilon(i)&&t.equalsWithEpsilon(n)?2:-1},i.prototype._checkEdge=function(t,i,r,n,o){if(void 0===i||e.Vector3.Dot(r[t],r[i])<this._epsilon){var s=this._linesPositions.length/3;n.subtract(o).normalize(),this._linesPositions.push(n.x),this._linesPositions.push(n.y),this._linesPositions.push(n.z),this._linesPositions.push(n.x),this._linesPositions.push(n.y),this._linesPositions.push(n.z),this._linesPositions.push(o.x),this._linesPositions.push(o.y),this._linesPositions.push(o.z),this._linesPositions.push(o.x),this._linesPositions.push(o.y),this._linesPositions.push(o.z),this._linesNormals.push(o.x),this._linesNormals.push(o.y),this._linesNormals.push(o.z),this._linesNormals.push(-1),this._linesNormals.push(o.x),this._linesNormals.push(o.y),this._linesNormals.push(o.z),this._linesNormals.push(1),this._linesNormals.push(n.x),this._linesNormals.push(n.y),this._linesNormals.push(n.z),this._linesNormals.push(-1),this._linesNormals.push(n.x),this._linesNormals.push(n.y),this._linesNormals.push(n.z),this._linesNormals.push(1),this._linesIndices.push(s),this._linesIndices.push(s+1),this._linesIndices.push(s+2),this._linesIndices.push(s),this._linesIndices.push(s+2),this._linesIndices.push(s+3)}},i.prototype._generateEdgesLines=function(){var i=this._source.getVerticesData(e.VertexBuffer.PositionKind),r=this._source.getIndices();if(r&&i){var n,o,s=new Array,a=new Array;for(n=0;n<r.length;n+=3){o=new t;var l=r[n],h=r[n+1],u=r[n+2];o.p0=new e.Vector3(i[3*l],i[3*l+1],i[3*l+2]),o.p1=new e.Vector3(i[3*h],i[3*h+1],i[3*h+2]),o.p2=new e.Vector3(i[3*u],i[3*u+1],i[3*u+2]);var c=e.Vector3.Cross(o.p1.subtract(o.p0),o.p2.subtract(o.p1));c.normalize(),a.push(c),s.push(o)}for(n=0;n<s.length;n++){o=s[n];for(var f=n+1;f<s.length;f++){var p=s[f];if(3===o.edgesConnectedCount)break;if(3!==p.edgesConnectedCount)for(var d=r[3*f],m=r[3*f+1],g=r[3*f+2],v=0;v<3;v++){var _=0;if(void 0===o.edges[v]){switch(v){case 0:_=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(o.p0,o.p1,p.p0,p.p1,p.p2):this._processEdgeForAdjacencies(r[3*n],r[3*n+1],d,m,g);break;case 1:_=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(o.p1,o.p2,p.p0,p.p1,p.p2):this._processEdgeForAdjacencies(r[3*n+1],r[3*n+2],d,m,g);break;case 2:_=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(o.p2,o.p0,p.p0,p.p1,p.p2):this._processEdgeForAdjacencies(r[3*n+2],r[3*n],d,m,g)}if(-1!==_&&(o.edges[v]=f,p.edges[_]=n,o.edgesConnectedCount++,p.edgesConnectedCount++,3===o.edgesConnectedCount))break}}}}for(n=0;n<s.length;n++){var y=s[n];this._checkEdge(n,y.edges[0],a,y.p0,y.p1),this._checkEdge(n,y.edges[1],a,y.p1,y.p2),this._checkEdge(n,y.edges[2],a,y.p2,y.p0)}var x=this._source.getScene().getEngine();this._buffers[e.VertexBuffer.PositionKind]=new e.VertexBuffer(x,this._linesPositions,e.VertexBuffer.PositionKind,!1),this._buffers[e.VertexBuffer.NormalKind]=new e.VertexBuffer(x,this._linesNormals,e.VertexBuffer.NormalKind,!1,!1,4),this._ib=x.createIndexBuffer(this._linesIndices),this._indicesCount=this._linesIndices.length}},i.prototype.render=function(){var t=this._source.getScene();if(this._lineShader.isReady()&&t.activeCamera){var i=t.getEngine();this._lineShader._preBind(),i.bindBuffers(this._buffers,this._ib,this._lineShader.getEffect()),t.resetCachedMaterial(),this._lineShader.setColor4("color",this._source.edgesColor),t.activeCamera.mode===e.Camera.ORTHOGRAPHIC_CAMERA?this._lineShader.setFloat("width",this._source.edgesWidth/this.edgesWidthScalerForOrthographic):this._lineShader.setFloat("width",this._source.edgesWidth/this.edgesWidthScalerForPerspective),this._lineShader.setFloat("aspectRatio",i.getAspectRatio(t.activeCamera)),this._lineShader.bind(this._source.getWorldMatrix()),i.draw(!0,0,this._indicesCount),this._lineShader.unbind(),i.setDepthWrite(!0)}},i}();e.EdgesRenderer=i}(s||(s={}));!function(e){var t=function(t){function i(i,r,n,o,s,a,l,h){void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE);var u=t.call(this,i,"glowBlurPostProcess",["screenSize","direction","blurWidth"],null,o,s,a,l,h)||this;return u.direction=r,u.kernel=n,u.onApplyObservable.add(function(e){e.setFloat2("screenSize",u.width,u.height),e.setVector2("direction",u.direction),e.setFloat("blurWidth",u.kernel)}),u}return n(i,t),i}(e.PostProcess),i=function(){function i(t,r,n){this.name=t,this._vertexBuffers={},this._mainTextureDesiredSize={width:0,height:0},this._meshes={},this._maxSize=0,this._shouldRender=!1,this._instanceGlowingMeshStencilReference=i.glowingMeshStencilReference++,this._excludedMeshes={},this.innerGlow=!0,this.outerGlow=!0,this.isEnabled=!0,this.onDisposeObservable=new e.Observable,this.onBeforeRenderMainTextureObservable=new e.Observable,this.onBeforeBlurObservable=new e.Observable,this.onAfterBlurObservable=new e.Observable,this.onBeforeComposeObservable=new e.Observable,this.onAfterComposeObservable=new e.Observable,this.onSizeChangedObservable=new e.Observable,this._scene=r||e.Engine.LastCreatedScene;var o=r.getEngine();this._engine=o,this._maxSize=this._engine.getCaps().maxTextureSize,this._scene.highlightLayers.push(this),this._engine.isStencilEnable||e.Tools.Warn("Rendering the Highlight Layer requires the stencil to be active on the canvas. var engine = new BABYLON.Engine(canvas, antialias, { stencil: true }"),this._options=n||{mainTextureRatio:.5,blurTextureSizeRatio:.5,blurHorizontalSize:1,blurVerticalSize:1,alphaBlendingMode:e.Engine.ALPHA_COMBINE,camera:null},this._options.mainTextureRatio=this._options.mainTextureRatio||.5,this._options.blurTextureSizeRatio=this._options.blurTextureSizeRatio||1,this._options.blurHorizontalSize=this._options.blurHorizontalSize||1,this._options.blurVerticalSize=this._options.blurVerticalSize||1,this._options.alphaBlendingMode=this._options.alphaBlendingMode||e.Engine.ALPHA_COMBINE;var s=[];s.push(1,1),s.push(-1,1),s.push(-1,-1),s.push(1,-1);var a=new e.VertexBuffer(o,s,e.VertexBuffer.PositionKind,!1,!1,2);this._vertexBuffers[e.VertexBuffer.PositionKind]=a,this._createIndexBuffer(),this._glowMapMergeEffect=o.createEffect("glowMapMerge",[e.VertexBuffer.PositionKind],["offset"],["textureSampler"],""),this.setMainTextureSize(),this.createTextureAndPostProcesses()}return Object.defineProperty(i.prototype,"blurHorizontalSize",{get:function(){return this._horizontalBlurPostprocess.kernel},set:function(e){this._horizontalBlurPostprocess.kernel=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"blurVerticalSize",{get:function(){return this._verticalBlurPostprocess.kernel},set:function(e){this._verticalBlurPostprocess.kernel=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"camera",{get:function(){return this._options.camera},enumerable:!0,configurable:!0}),i.prototype._createIndexBuffer=function(){var e=this._scene.getEngine(),t=[];t.push(0),t.push(1),t.push(2),t.push(0),t.push(2),t.push(3),this._indexBuffer=e.createIndexBuffer(t)},i.prototype._rebuild=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&t._rebuild(),this._createIndexBuffer()},i.prototype.createTextureAndPostProcesses=function(){var r=this,n=this._mainTextureDesiredSize.width*this._options.blurTextureSizeRatio,o=this._mainTextureDesiredSize.height*this._options.blurTextureSizeRatio;n=this._engine.needPOTTextures?e.Tools.GetExponentOfTwo(n,this._maxSize):n,o=this._engine.needPOTTextures?e.Tools.GetExponentOfTwo(o,this._maxSize):o,this._mainTexture=new e.RenderTargetTexture("HighlightLayerMainRTT",{width:this._mainTextureDesiredSize.width,height:this._mainTextureDesiredSize.height},this._scene,!1,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT),this._mainTexture.activeCamera=this._options.camera,this._mainTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._mainTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._mainTexture.anisotropicFilteringLevel=1,this._mainTexture.updateSamplingMode(e.Texture.BILINEAR_SAMPLINGMODE),this._mainTexture.renderParticles=!1,this._mainTexture.renderList=null,this._mainTexture.ignoreCameraViewport=!0,this._blurTexture=new e.RenderTargetTexture("HighlightLayerBlurRTT",{width:n,height:o},this._scene,!1,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT),this._blurTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._blurTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._blurTexture.anisotropicFilteringLevel=16,this._blurTexture.updateSamplingMode(e.Texture.TRILINEAR_SAMPLINGMODE),this._blurTexture.renderParticles=!1,this._blurTexture.ignoreCameraViewport=!0,this._downSamplePostprocess=new e.PassPostProcess("HighlightLayerPPP",this._options.blurTextureSizeRatio,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._downSamplePostprocess.onApplyObservable.add(function(e){e.setTexture("textureSampler",r._mainTexture)}),this._options.alphaBlendingMode===e.Engine.ALPHA_COMBINE?(this._horizontalBlurPostprocess=new t("HighlightLayerHBP",new e.Vector2(1,0),this._options.blurHorizontalSize,1,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._horizontalBlurPostprocess.onApplyObservable.add(function(e){e.setFloat2("screenSize",n,o)}),this._verticalBlurPostprocess=new t("HighlightLayerVBP",new e.Vector2(0,1),this._options.blurVerticalSize,1,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._verticalBlurPostprocess.onApplyObservable.add(function(e){e.setFloat2("screenSize",n,o)})):(this._horizontalBlurPostprocess=new e.BlurPostProcess("HighlightLayerHBP",new e.Vector2(1,0),this._options.blurHorizontalSize,1,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._horizontalBlurPostprocess.onApplyObservable.add(function(e){e.setFloat2("screenSize",n,o)}),this._verticalBlurPostprocess=new e.BlurPostProcess("HighlightLayerVBP",new e.Vector2(0,1),this._options.blurVerticalSize,1,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._verticalBlurPostprocess.onApplyObservable.add(function(e){e.setFloat2("screenSize",n,o)})),this._mainTexture.onAfterUnbindObservable.add(function(){r.onBeforeBlurObservable.notifyObservers(r);var e=r._blurTexture.getInternalTexture();e&&r._scene.postProcessManager.directRender([r._downSamplePostprocess,r._horizontalBlurPostprocess,r._verticalBlurPostprocess],e,!0),r.onAfterBlurObservable.notifyObservers(r)});var s=function(t){if(r._meshes){var n=t.getMaterial(),o=t.getRenderingMesh(),s=r._scene,a=s.getEngine();if(n){a.setState(n.backFaceCulling);var l=o._getInstancesRenderList(t._id);if(!(l.mustReturn||r._excludedMeshes&&r._excludedMeshes[o.uniqueId])){var h=a.getCaps().instancedArrays&&null!==l.visibleInstances[t._id]&&void 0!==l.visibleInstances[t._id],u=r._meshes[o.uniqueId],c=null;if(u&&u.glowEmissiveOnly&&n&&(c=n.emissiveTexture),r.isReady(t,h,c)){if(a.enableEffect(r._glowMapGenerationEffect),o._bind(t,r._glowMapGenerationEffect,e.Material.TriangleFillMode),r._glowMapGenerationEffect.setMatrix("viewProjection",s.getTransformMatrix()),u?r._glowMapGenerationEffect.setFloat4("color",u.color.r,u.color.g,u.color.b,1):r._glowMapGenerationEffect.setFloat4("color",i.neutralColor.r,i.neutralColor.g,i.neutralColor.b,i.neutralColor.a),n&&n.needAlphaTesting()){var f=n.getAlphaTestTexture();if(f){r._glowMapGenerationEffect.setTexture("diffuseSampler",f);var p=f.getTextureMatrix();p&&r._glowMapGenerationEffect.setMatrix("diffuseMatrix",p)}}c&&(r._glowMapGenerationEffect.setTexture("emissiveSampler",c),r._glowMapGenerationEffect.setMatrix("emissiveMatrix",c.getTextureMatrix())),o.useBones&&o.computeBonesUsingShaders&&o.skeleton&&r._glowMapGenerationEffect.setMatrices("mBones",o.skeleton.getTransformMatrices(o)),o._processRendering(t,r._glowMapGenerationEffect,e.Material.TriangleFillMode,l,h,function(e,t){return r._glowMapGenerationEffect.setMatrix("world",t)})}else r._mainTexture.resetRefreshCounter()}}}};this._mainTexture.customRenderFunction=function(e,t,i,n){r.onBeforeRenderMainTextureObservable.notifyObservers(r);var o,a=r._scene.getEngine();if(n.length){for(a.setColorWrite(!1),o=0;o<n.length;o++)s(n.data[o]);a.setColorWrite(!0)}for(o=0;o<e.length;o++)s(e.data[o]);for(o=0;o<t.length;o++)s(t.data[o]);for(o=0;o<i.length;o++)s(i.data[o])},this._mainTexture.onClearObservable.add(function(e){e.clear(i.neutralColor,!0,!0,!0)})},i.prototype.isReady=function(t,i,r){var n=t.getMaterial();if(!n)return!1;if(!n.isReady(t.getMesh(),i))return!1;var o=[],s=[e.VertexBuffer.PositionKind],a=t.getMesh(),l=!1,h=!1;if(n&&n.needAlphaTesting()){var u=n.getAlphaTestTexture();u&&(o.push("#define ALPHATEST"),a.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&1===u.coordinatesIndex?(o.push("#define DIFFUSEUV2"),h=!0):a.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(o.push("#define DIFFUSEUV1"),l=!0))}r&&(o.push("#define EMISSIVE"),a.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&1===r.coordinatesIndex?(o.push("#define EMISSIVEUV2"),h=!0):a.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(o.push("#define EMISSIVEUV1"),l=!0)),l&&(s.push(e.VertexBuffer.UVKind),o.push("#define UV1")),h&&(s.push(e.VertexBuffer.UV2Kind),o.push("#define UV2")),a.useBones&&a.computeBonesUsingShaders?(s.push(e.VertexBuffer.MatricesIndicesKind),s.push(e.VertexBuffer.MatricesWeightsKind),a.numBoneInfluencers>4&&(s.push(e.VertexBuffer.MatricesIndicesExtraKind),s.push(e.VertexBuffer.MatricesWeightsExtraKind)),o.push("#define NUM_BONE_INFLUENCERS "+a.numBoneInfluencers),o.push("#define BonesPerMesh "+(a.skeleton?a.skeleton.bones.length+1:0))):o.push("#define NUM_BONE_INFLUENCERS 0"),i&&(o.push("#define INSTANCES"),s.push("world0"),s.push("world1"),s.push("world2"),s.push("world3"));var c=o.join("\n");return this._cachedDefines!==c&&(this._cachedDefines=c,this._glowMapGenerationEffect=this._scene.getEngine().createEffect("glowMapGeneration",s,["world","mBones","viewProjection","diffuseMatrix","color","emissiveMatrix"],["diffuseSampler","emissiveSampler"],c)),this._glowMapGenerationEffect.isReady()},i.prototype.render=function(){var t=this._glowMapMergeEffect;if(t.isReady()&&this._blurTexture.isReady()){var i=this._scene.getEngine();this.onBeforeComposeObservable.notifyObservers(this),i.enableEffect(t),i.setState(!1);var r=i.getStencilBuffer(),n=i.getStencilFunction(),o=i.getStencilMask(),s=i.getStencilOperationPass(),a=i.getStencilOperationFail(),l=i.getStencilOperationDepthFail(),h=i.getAlphaMode();t.setTexture("textureSampler",this._blurTexture),i.bindBuffers(this._vertexBuffers,this._indexBuffer,t),i.setStencilOperationPass(e.Engine.REPLACE),i.setStencilOperationFail(e.Engine.KEEP),i.setStencilOperationDepthFail(e.Engine.KEEP),i.setAlphaMode(this._options.alphaBlendingMode),i.setStencilMask(0),i.setStencilBuffer(!0),i.setStencilFunctionReference(this._instanceGlowingMeshStencilReference),this.outerGlow&&(t.setFloat("offset",0),i.setStencilFunction(e.Engine.NOTEQUAL),i.draw(!0,0,6)),this.innerGlow&&(t.setFloat("offset",1),i.setStencilFunction(e.Engine.EQUAL),i.draw(!0,0,6)),i.setStencilFunction(n),i.setStencilMask(o),i.setAlphaMode(h),i.setStencilBuffer(r),i.setStencilOperationPass(s),i.setStencilOperationFail(a),i.setStencilOperationDepthFail(l),i._stencilState.reset(),this.onAfterComposeObservable.notifyObservers(this);var u=this._mainTexture.getSize();this.setMainTextureSize(),u.width===this._mainTextureDesiredSize.width&&u.height===this._mainTextureDesiredSize.height||(this.onSizeChangedObservable.notifyObservers(this),this.disposeTextureAndPostProcesses(),this.createTextureAndPostProcesses())}},i.prototype.addExcludedMesh=function(e){this._excludedMeshes&&(this._excludedMeshes[e.uniqueId]||(this._excludedMeshes[e.uniqueId]={mesh:e,beforeRender:e.onBeforeRenderObservable.add(function(e){e.getEngine().setStencilBuffer(!1)}),afterRender:e.onAfterRenderObservable.add(function(e){e.getEngine().setStencilBuffer(!0)})}))},i.prototype.removeExcludedMesh=function(e){if(this._excludedMeshes){var t=this._excludedMeshes[e.uniqueId];t&&(t.beforeRender&&e.onBeforeRenderObservable.remove(t.beforeRender),t.afterRender&&e.onAfterRenderObservable.remove(t.afterRender)),this._excludedMeshes[e.uniqueId]=null}},i.prototype.addMesh=function(e,t,i){var r=this;if(void 0===i&&(i=!1),this._meshes){var n=this._meshes[e.uniqueId];n?n.color=t:this._meshes[e.uniqueId]={mesh:e,color:t,observerHighlight:e.onBeforeRenderObservable.add(function(e){r._excludedMeshes&&r._excludedMeshes[e.uniqueId]?r.defaultStencilReference(e):e.getScene().getEngine().setStencilFunctionReference(r._instanceGlowingMeshStencilReference)}),observerDefault:e.onAfterRenderObservable.add(this.defaultStencilReference),glowEmissiveOnly:i},this._shouldRender=!0}},i.prototype.removeMesh=function(e){if(this._meshes){var t=this._meshes[e.uniqueId];t&&(t.observerHighlight&&e.onBeforeRenderObservable.remove(t.observerHighlight),t.observerDefault&&e.onAfterRenderObservable.remove(t.observerDefault)),this._meshes[e.uniqueId]=null,this._shouldRender=!1;for(var i in this._meshes)if(i){this._shouldRender=!0;break}}},i.prototype.shouldRender=function(){return this.isEnabled&&this._shouldRender},i.prototype.setMainTextureSize=function(){this._options.mainTextureFixedSize?(this._mainTextureDesiredSize.width=this._options.mainTextureFixedSize,this._mainTextureDesiredSize.height=this._options.mainTextureFixedSize):(this._mainTextureDesiredSize.width=this._engine.getRenderWidth()*this._options.mainTextureRatio,this._mainTextureDesiredSize.height=this._engine.getRenderHeight()*this._options.mainTextureRatio,this._mainTextureDesiredSize.width=this._engine.needPOTTextures?e.Tools.GetExponentOfTwo(this._mainTextureDesiredSize.width,this._maxSize):this._mainTextureDesiredSize.width,this._mainTextureDesiredSize.height=this._engine.needPOTTextures?e.Tools.GetExponentOfTwo(this._mainTextureDesiredSize.height,this._maxSize):this._mainTextureDesiredSize.height)},i.prototype.defaultStencilReference=function(e){e.getScene().getEngine().setStencilFunctionReference(i.normalMeshStencilReference)},i.prototype.disposeTextureAndPostProcesses=function(){this._blurTexture.dispose(),this._mainTexture.dispose(),this._downSamplePostprocess.dispose(),this._horizontalBlurPostprocess.dispose(),this._verticalBlurPostprocess.dispose()},i.prototype.dispose=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];if(t&&(t.dispose(),this._vertexBuffers[e.VertexBuffer.PositionKind]=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this.disposeTextureAndPostProcesses(),this._meshes){for(var i in this._meshes)(r=this._meshes[i])&&r.mesh&&(r.observerHighlight&&r.mesh.onBeforeRenderObservable.remove(r.observerHighlight),r.observerDefault&&r.mesh.onAfterRenderObservable.remove(r.observerDefault));this._meshes=null}if(this._excludedMeshes){for(var i in this._excludedMeshes){var r=this._excludedMeshes[i];r&&(r.beforeRender&&r.mesh.onBeforeRenderObservable.remove(r.beforeRender),r.afterRender&&r.mesh.onAfterRenderObservable.remove(r.afterRender))}this._excludedMeshes=null}var n=this._scene.highlightLayers.indexOf(this,0);n>-1&&this._scene.highlightLayers.splice(n,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this.onBeforeRenderMainTextureObservable.clear(),this.onBeforeBlurObservable.clear(),this.onBeforeComposeObservable.clear(),this.onAfterComposeObservable.clear(),this.onSizeChangedObservable.clear()},i.neutralColor=new e.Color4(0,0,0,0),i.glowingMeshStencilReference=2,i.normalMeshStencilReference=1,i}();e.HighlightLayer=i}(s||(s={}));!function(e){var t;!function(e){e[e.INIT=0]="INIT",e[e.RUNNING=1]="RUNNING",e[e.DONE=2]="DONE",e[e.ERROR=3]="ERROR"}(t=e.AssetTaskState||(e.AssetTaskState={}));var i=function(){function e(e){this.name=e,this.isCompleted=!1,this.taskState=t.INIT}return e.prototype.run=function(e,i,r){var n=this;this.taskState=t.RUNNING,this.runTask(e,function(){n.onDoneCallback(i,r)},function(e,t){n.onErrorCallback(r,e,t)})},e.prototype.runTask=function(e,t,i){throw new Error("runTask is not implemented")},e.prototype.onErrorCallback=function(e,i,r){this.taskState=t.ERROR,this.errorObject={message:i,exception:r},this.onError&&this.onError(this,i,r),e()},e.prototype.onDoneCallback=function(e,i){try{this.taskState=t.DONE,this.isCompleted=!0,this.onSuccess&&this.onSuccess(this),e()}catch(e){this.onErrorCallback(i,"Task is done, error executing success callback(s)",e)}},e}();e.AbstractAssetTask=i;var r=function(){return function(e,t,i){this.remainingCount=e,this.totalCount=t,this.task=i}}();e.AssetsProgressEvent=r;var o=function(t){function i(e,i,r,n){var o=t.call(this,e)||this;return o.name=e,o.meshesNames=i,o.rootUrl=r,o.sceneFilename=n,o}return n(i,t),i.prototype.runTask=function(t,i,r){var n=this;e.SceneLoader.ImportMesh(this.meshesNames,this.rootUrl,this.sceneFilename,t,function(e,t,r){n.loadedMeshes=e,n.loadedParticleSystems=t,n.loadedSkeletons=r,i()},null,function(e,t,i){r(t,i)})},i}(i);e.MeshAssetTask=o;var s=function(t){function i(e,i){var r=t.call(this,e)||this;return r.name=e,r.url=i,r}return n(i,t),i.prototype.runTask=function(t,i,r){var n=this;e.Tools.LoadFile(this.url,function(e){n.text=e,i()},void 0,t.database,!1,function(e,t){e&&r(e.status+" "+e.statusText,t)})},i}(i);e.TextFileAssetTask=s;var a=function(t){function i(e,i){var r=t.call(this,e)||this;return r.name=e,r.url=i,r}return n(i,t),i.prototype.runTask=function(t,i,r){var n=this;e.Tools.LoadFile(this.url,function(e){n.data=e,i()},void 0,t.database,!0,function(e,t){e&&r(e.status+" "+e.statusText,t)})},i}(i);e.BinaryFileAssetTask=a;var l=function(t){function i(e,i){var r=t.call(this,e)||this;return r.name=e,r.url=i,r}return n(i,t),i.prototype.runTask=function(t,i,r){var n=this,o=new Image;e.Tools.SetCorsBehavior(this.url,o),o.onload=function(){n.image=o,i()},o.onerror=function(e){r("Error loading image",e)},o.src=this.url},i}(i);e.ImageAssetTask=l;var h=function(t){function i(i,r,n,o,s){void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE);var a=t.call(this,i)||this;return a.name=i,a.url=r,a.noMipmap=n,a.invertY=o,a.samplingMode=s,a}return n(i,t),i.prototype.runTask=function(t,i,r){this.texture=new e.Texture(this.url,t,this.noMipmap,this.invertY,this.samplingMode,function(){i()},function(e,t){r(e,t)})},i}(i);e.TextureAssetTask=h;var u=function(t){function i(e,i,r,n,o){var s=t.call(this,e)||this;return s.name=e,s.url=i,s.extensions=r,s.noMipmap=n,s.files=o,s}return n(i,t),i.prototype.runTask=function(t,i,r){this.texture=new e.CubeTexture(this.url,t,this.extensions,this.noMipmap,this.files,function(){i()},function(e,t){r(e,t)})},i}(i);e.CubeTextureAssetTask=u;var c=function(t){function i(e,i,r,n,o,s,a){void 0===n&&(n=!1),void 0===o&&(o=!0),void 0===s&&(s=!1),void 0===a&&(a=!1);var l=t.call(this,e)||this;return l.name=e,l.url=i,l.size=r,l.noMipmap=n,l.generateHarmonics=o,l.useInGammaSpace=s,l.usePMREMGenerator=a,l}return n(i,t),i.prototype.run=function(t,i,r){this.texture=new e.HDRCubeTexture(this.url,t,this.size,this.noMipmap,this.generateHarmonics,this.useInGammaSpace,this.usePMREMGenerator,function(){i()},function(e,t){r(e,t)})},i}(i);e.HDRCubeTextureAssetTask=c;var f=function(){function t(t){this.tasks=new Array,this.waitingTasksCount=0,this.onTaskSuccessObservable=new e.Observable,this.onTaskErrorObservable=new e.Observable,this.onTasksDoneObservable=new e.Observable,this.onProgressObservable=new e.Observable,this.useDefaultLoadingScreen=!0,this._scene=t}return t.prototype.addMeshTask=function(e,t,i,r){var n=new o(e,t,i,r);return this.tasks.push(n),n},t.prototype.addTextFileTask=function(e,t){var i=new s(e,t);return this.tasks.push(i),i},t.prototype.addBinaryFileTask=function(e,t){var i=new a(e,t);return this.tasks.push(i),i},t.prototype.addImageTask=function(e,t){var i=new l(e,t);return this.tasks.push(i),i},t.prototype.addTextureTask=function(t,i,r,n,o){void 0===o&&(o=e.Texture.TRILINEAR_SAMPLINGMODE);var s=new h(t,i,r,n,o);return this.tasks.push(s),s},t.prototype.addCubeTextureTask=function(e,t,i,r,n){var o=new u(e,t,i,r,n);return this.tasks.push(o),o},t.prototype.addHDRCubeTextureTask=function(e,t,i,r,n,o,s){void 0===r&&(r=!1),void 0===n&&(n=!0),void 0===o&&(o=!1),void 0===s&&(s=!1);var a=new c(e,t,i,r,n,o,s);return this.tasks.push(a),a},t.prototype._decreaseWaitingTasksCount=function(t){this.waitingTasksCount--;try{this.onProgress&&this.onProgress(this.waitingTasksCount,this.tasks.length,t),this.onProgressObservable.notifyObservers(new r(this.waitingTasksCount,this.tasks.length,t))}catch(t){e.Tools.Error("Error running progress callbacks."),console.log(t)}if(0===this.waitingTasksCount){try{this.onFinish&&this.onFinish(this.tasks),this.onTasksDoneObservable.notifyObservers(this.tasks)}catch(t){e.Tools.Error("Error running tasks-done callbacks."),console.log(t)}this._scene.getEngine().hideLoadingUI()}},t.prototype._runTask=function(e){var t=this,i=function(i,r){e.errorObject=e.errorObject||{message:i,exception:r},t.onTaskError&&t.onTaskError(e),t.onTaskErrorObservable.notifyObservers(e),t._decreaseWaitingTasksCount(e)};e.run(this._scene,function(){try{t.onTaskSuccess&&t.onTaskSuccess(e),t.onTaskSuccessObservable.notifyObservers(e),t._decreaseWaitingTasksCount(e)}catch(e){i("Error executing task success callbacks",e)}},i)},t.prototype.reset=function(){return this.tasks=new Array,this},t.prototype.load=function(){if(this.waitingTasksCount=this.tasks.length,0===this.waitingTasksCount)return this.onFinish&&this.onFinish(this.tasks),this.onTasksDoneObservable.notifyObservers(this.tasks),this;this.useDefaultLoadingScreen&&this._scene.getEngine().displayLoadingUI();for(var e=0;e<this.tasks.length;e++){var t=this.tasks[e];this._runTask(t)}return this},t}();e.AssetsManager=f}(s||(s={}));!function(e){var t=[],i=function(i,r){if(!t[i.id]&&!i.doNotSerialize){if(i instanceof e.Geometry.Primitives.Box)r.boxes.push(i.serialize());else if(i instanceof e.Geometry.Primitives.Sphere)r.spheres.push(i.serialize());else if(i instanceof e.Geometry.Primitives.Cylinder)r.cylinders.push(i.serialize());else if(i instanceof e.Geometry.Primitives.Torus)r.toruses.push(i.serialize());else if(i instanceof e.Geometry.Primitives.Ground)r.grounds.push(i.serialize());else if(i instanceof e.Geometry.Primitives.Plane)r.planes.push(i.serialize());else if(i instanceof e.Geometry.Primitives.TorusKnot)r.torusKnots.push(i.serialize());else{if(i instanceof e.Geometry.Primitives._Primitive)throw new Error("Unknown primitive type");r.vertexData.push(i.serializeVerticeData())}t[i.id]=!0}},r=function(e,t){var r={},n=e._geometry;return n&&(e.getScene().getGeometryByID(n.id)||i(n,t.geometries)),e.serialize&&e.serialize(r),r},n=function(t,n){if(t.delayLoadState===e.Engine.DELAYLOADSTATE_LOADED||t.delayLoadState===e.Engine.DELAYLOADSTATE_NONE){t.material&&(t.material instanceof e.StandardMaterial?(n.materials=n.materials||[],n.materials.some(function(e){return e.id===t.material.id})||n.materials.push(t.material.serialize())):t.material instanceof e.MultiMaterial&&(n.multiMaterials=n.multiMaterials||[],n.multiMaterials.some(function(e){return e.id===t.material.id})||n.multiMaterials.push(t.material.serialize())));var o=t._geometry;o&&(n.geometries||(n.geometries={},n.geometries.boxes=[],n.geometries.spheres=[],n.geometries.cylinders=[],n.geometries.toruses=[],n.geometries.grounds=[],n.geometries.planes=[],n.geometries.torusKnots=[],n.geometries.vertexData=[]),i(o,n.geometries)),t.skeleton&&(n.skeletons=n.skeletons||[],n.skeletons.push(t.skeleton.serialize())),n.meshes=n.meshes||[],n.meshes.push(r(t,n))}},o=function(){function o(){}return o.ClearCache=function(){t=[]},o.Serialize=function(n){var s={};if(o.ClearCache(),s.useDelayedTextureLoading=n.useDelayedTextureLoading,s.autoClear=n.autoClear,s.clearColor=n.clearColor.asArray(),s.ambientColor=n.ambientColor.asArray(),s.gravity=n.gravity.asArray(),s.collisionsEnabled=n.collisionsEnabled,s.workerCollisions=n.workerCollisions,n.fogMode&&0!==n.fogMode&&(s.fogMode=n.fogMode,s.fogColor=n.fogColor.asArray(),s.fogStart=n.fogStart,s.fogEnd=n.fogEnd,s.fogDensity=n.fogDensity),n.isPhysicsEnabled()){var a=n.getPhysicsEngine();a&&(s.physicsEnabled=!0,s.physicsGravity=a.gravity.asArray(),s.physicsEngine=a.getPhysicsPluginName())}n.metadata&&(s.metadata=n.metadata),s.morphTargetManagers=[];for(var l=0,h=n.meshes;l<h.length;l++){var u=(_=h[l]).morphTargetManager;u&&s.morphTargetManagers.push(u.serialize())}s.lights=[];var c,f;for(c=0;c<n.lights.length;c++)(f=n.lights[c]).doNotSerialize||s.lights.push(f.serialize());for(s.cameras=[],c=0;c<n.cameras.length;c++){var p=n.cameras[c];p.doNotSerialize||s.cameras.push(p.serialize())}n.activeCamera&&(s.activeCameraID=n.activeCamera.id),e.Animation.AppendSerializedAnimations(n,s),s.materials=[],s.multiMaterials=[];var d;for(c=0;c<n.materials.length;c++)(d=n.materials[c]).doNotSerialize||s.materials.push(d.serialize());for(s.multiMaterials=[],c=0;c<n.multiMaterials.length;c++){var m=n.multiMaterials[c];s.multiMaterials.push(m.serialize())}for(s.skeletons=[],c=0;c<n.skeletons.length;c++)s.skeletons.push(n.skeletons[c].serialize());for(s.transformNodes=[],c=0;c<n.transformNodes.length;c++)s.transformNodes.push(n.transformNodes[c].serialize());s.geometries={},s.geometries.boxes=[],s.geometries.spheres=[],s.geometries.cylinders=[],s.geometries.toruses=[],s.geometries.grounds=[],s.geometries.planes=[],s.geometries.torusKnots=[],s.geometries.vertexData=[],t=[];var g=n.getGeometries();for(c=0;c<g.length;c++){var v=g[c];v.isReady()&&i(v,s.geometries)}for(s.meshes=[],c=0;c<n.meshes.length;c++){var _=n.meshes[c];if(_ instanceof e.Mesh){var y=_;y.doNotSerialize||y.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADED&&y.delayLoadState!==e.Engine.DELAYLOADSTATE_NONE||s.meshes.push(r(y,s))}}for(s.particleSystems=[],c=0;c<n.particleSystems.length;c++)s.particleSystems.push(n.particleSystems[c].serialize());for(s.lensFlareSystems=[],c=0;c<n.lensFlareSystems.length;c++)s.lensFlareSystems.push(n.lensFlareSystems[c].serialize());for(s.shadowGenerators=[],c=0;c<n.lights.length;c++){var x=(f=n.lights[c]).getShadowGenerator();x&&s.shadowGenerators.push(x.serialize())}for(n.actionManager&&(s.actions=n.actionManager.serialize("scene")),s.sounds=[],c=0;c<n.soundTracks.length;c++)for(var b=n.soundTracks[c],T=0;T<b.soundCollection.length;T++)s.sounds.push(b.soundCollection[T].serialize());return s},o.SerializeMesh=function(t,i,r){void 0===i&&(i=!1),void 0===r&&(r=!1);var s={};if(o.ClearCache(),t=t instanceof Array?t:[t],i||r)for(var a=0;a<t.length;++a)r&&t[a].getDescendants().forEach(function(i){i instanceof e.Mesh&&t.indexOf(i)<0&&t.push(i)}),i&&t[a].parent&&t.indexOf(t[a].parent)<0&&t.push(t[a].parent);return t.forEach(function(e){n(e,s)}),s},o}();e.SceneSerializer=o}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n){void 0===n&&(n=!0);var o=this;this.name=t,this._viewMatrix=e.Matrix.Identity(),this._target=e.Vector3.Zero(),this._add=e.Vector3.Zero(),this.invertYAxis=!1,this.position=e.Vector3.Zero(),this._scene=r,this._scene.reflectionProbes.push(this),this._renderTargetTexture=new e.RenderTargetTexture(t,i,r,n,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT,!0),this._renderTargetTexture.onBeforeRenderObservable.add(function(t){switch(t){case 0:o._add.copyFromFloats(1,0,0);break;case 1:o._add.copyFromFloats(-1,0,0);break;case 2:o._add.copyFromFloats(0,o.invertYAxis?1:-1,0);break;case 3:o._add.copyFromFloats(0,o.invertYAxis?-1:1,0);break;case 4:o._add.copyFromFloats(0,0,1);break;case 5:o._add.copyFromFloats(0,0,-1)}o._attachedMesh&&o.position.copyFrom(o._attachedMesh.getAbsolutePosition()),o.position.addToRef(o._add,o._target),e.Matrix.LookAtLHToRef(o.position,o._target,e.Vector3.Up(),o._viewMatrix),r.setTransformMatrix(o._viewMatrix,o._projectionMatrix),r._forcedViewPosition=o.position}),this._renderTargetTexture.onAfterUnbindObservable.add(function(){r._forcedViewPosition=null,r.updateTransformMatrix(!0)}),r.activeCamera&&(this._projectionMatrix=e.Matrix.PerspectiveFovLH(Math.PI/2,1,r.activeCamera.minZ,r.activeCamera.maxZ))}return Object.defineProperty(t.prototype,"samples",{get:function(){return this._renderTargetTexture.samples},set:function(e){this._renderTargetTexture.samples=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"refreshRate",{get:function(){return this._renderTargetTexture.refreshRate},set:function(e){this._renderTargetTexture.refreshRate=e},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},Object.defineProperty(t.prototype,"cubeTexture",{get:function(){return this._renderTargetTexture},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"renderList",{get:function(){return this._renderTargetTexture.renderList},enumerable:!0,configurable:!0}),t.prototype.attachToMesh=function(e){this._attachedMesh=e},t.prototype.setRenderingAutoClearDepthStencil=function(e,t){this._renderTargetTexture.setRenderingAutoClearDepthStencil(e,t)},t.prototype.dispose=function(){var e=this._scene.reflectionProbes.indexOf(this);-1!==e&&this._scene.reflectionProbes.splice(e,1),this._renderTargetTexture&&(this._renderTargetTexture.dispose(),this._renderTargetTexture=null)},t}();e.ReflectionProbe=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n,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.layerMask=268435455,this._vertexBuffers={},this.onDisposeObservable=new e.Observable,this.onBeforeRenderObservable=new e.Observable,this.onAfterRenderObservable=new e.Observable,this.texture=i?new e.Texture(i,r,!0):null,this.isBackground=void 0===n||n,this.color=void 0===o?new e.Color4(1,1,1,1):o,this._scene=r||e.Engine.LastCreatedScene,this._scene.layers.push(this);var s=this._scene.getEngine(),a=[];a.push(1,1),a.push(-1,1),a.push(-1,-1),a.push(1,-1);var l=new e.VertexBuffer(s,a,e.VertexBuffer.PositionKind,!1,!1,2);this._vertexBuffers[e.VertexBuffer.PositionKind]=l,this._createIndexBuffer(),this._effect=s.createEffect("layer",[e.VertexBuffer.PositionKind],["textureMatrix","color","scale","offset"],["textureSampler"],""),this._alphaTestEffect=s.createEffect("layer",[e.VertexBuffer.PositionKind],["textureMatrix","color","scale","offset"],["textureSampler"],"#define ALPHATEST")}return Object.defineProperty(t.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onBeforeRender",{set:function(e){this._onBeforeRenderObserver&&this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver),this._onBeforeRenderObserver=this.onBeforeRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onAfterRender",{set:function(e){this._onAfterRenderObserver&&this.onAfterRenderObservable.remove(this._onAfterRenderObserver),this._onAfterRenderObserver=this.onAfterRenderObservable.add(e)},enumerable:!0,configurable:!0}),t.prototype._createIndexBuffer=function(){var e=this._scene.getEngine(),t=[];t.push(0),t.push(1),t.push(2),t.push(0),t.push(2),t.push(3),this._indexBuffer=e.createIndexBuffer(t)},t.prototype._rebuild=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&t._rebuild(),this._createIndexBuffer()},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.onBeforeRenderObservable.notifyObservers(this),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._vertexBuffers,this._indexBuffer,t),this.alphaTest?i.draw(!0,0,6):(i.setAlphaMode(this.alphaBlendingMode),i.draw(!0,0,6),i.setAlphaMode(e.Engine.ALPHA_DISABLE)),this.onAfterRenderObservable.notifyObservers(this)}},t.prototype.dispose=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&(t.dispose(),this._vertexBuffers[e.VertexBuffer.PositionKind]=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this.texture&&(this.texture.dispose(),this.texture=null);var i=this._scene.layers.indexOf(this);this._scene.layers.splice(i,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this.onAfterRenderObservable.clear(),this.onBeforeRenderObservable.clear()},t}();e.Layer=t}(s||(s={}));!function(e){var t=function(){function t(){}return t.CreateResizedCopy=function(t,i,r,n){void 0===n&&(n=!0);var o=t.getScene(),s=o.getEngine(),a=new e.RenderTargetTexture("resized"+t.name,{width:i,height:r},o,!t.noMipmap,!0,t._texture.type,!1,t._samplingMode,!1);a.wrapU=t.wrapU,a.wrapV=t.wrapV,a.uOffset=t.uOffset,a.vOffset=t.vOffset,a.uScale=t.uScale,a.vScale=t.vScale,a.uAng=t.uAng,a.vAng=t.vAng,a.wAng=t.wAng,a.coordinatesIndex=t.coordinatesIndex,a.level=t.level,a.anisotropicFilteringLevel=t.anisotropicFilteringLevel,a._texture.isReady=!1,t.wrapU=e.Texture.CLAMP_ADDRESSMODE,t.wrapV=e.Texture.CLAMP_ADDRESSMODE;var l=new e.PassPostProcess("pass",1,null,n?e.Texture.BILINEAR_SAMPLINGMODE:e.Texture.NEAREST_SAMPLINGMODE,s,!1,e.Engine.TEXTURETYPE_UNSIGNED_INT);return l.getEffect().executeWhenCompiled(function(){l.onApply=function(e){e.setTexture("textureSampler",t)};var e=a.getInternalTexture();e&&(o.postProcessManager.directRender([l],e),s.unBindFramebuffer(e),a.disposeFramebufferObjects(),l.dispose(),e.isReady=!0)}),a},t.GetEnvironmentBRDFTexture=function(t){if(!t._environmentBRDFTexture){var i=e.Texture.CreateFromBase64String(this._environmentBRDFBase64Texture,"EnvironmentBRDFTexture",t,!0,!1,e.Texture.BILINEAR_SAMPLINGMODE);i.wrapU=e.Texture.CLAMP_ADDRESSMODE,i.wrapV=e.Texture.CLAMP_ADDRESSMODE,t._environmentBRDFTexture=i}return t._environmentBRDFTexture},t._environmentBRDFBase64Texture="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAgAElEQVR4Xu19Z7PtTHbW1g3jMMbGmGDAZAMm5xxMLDAU0WSKWOQcCoqccw6eGdtgk4yNbZxnvvAL+Af8Af6AsQl+06ako9X36dXPSi3pnPu+cz/cOntL3S1pq5+w1mrpLs/eud9fvn27rf9evPPwFz+v22S7fGZ/n7/70G79J5/Xv/qzbLP+Pnvvoc/6Tz7jX/15/c62LfeH7fofbpfP3l/ct36Wf+u4+D37+XYb++G26LPsr/zFttnPuh37bm1bt0f7MvtlnOx4uv0H4fty8UUsz77rfn/57u32cgXvDv72eQf0tl0+G38b0Nf9K4Dl704MEfA16KsE8Gw9JgD+DQE8EA0DT2b7GwK4GHnF4a8iguXZt9/vL5/dbisJbEq/uwD5vIK/fbbAv4N9U/8nJIDNCazKvBLBGwdwu62OhajxmQSAx6gqNp5HCg9wPan2nwSNjhLD8ux/3u8vP3y7vbwDAYjtR8AzFyDqLu1Q+YEINnew23rPCYiKb+q/K7o4AVT4tg0t/h4ydJZfkQASQ/d5b9fZ/Z1ENmuPn/cwYCYEELBguKC3nRkCnE0AFOwOKCOAR/sH/L4hgFMpbSWP5dn/uN9ffs7t9mJ5cAHoBLTyszBAFJ/F/xIKdASw5wgaEWDMLySxAk4svf6L+4QAGPiJCziNAPb4f3UZ2dh/m+z7BK4SAPYrxf5FB6ABPgCUAfANAZwKyscc7IEA/vv9/uLzbreXzx9cQCMACAl00m8jAlF7ov6SCMQ8gJsMFFBnCECSg5H6TxJAU3vPAbwhgFfz9AABeOEDBcIbB3AqPzwQwH+731/8sNvt5Ydut5e3B2C/fG9P+jESgGz/RgxG9r9VAwTUUh0goQDafUz+DYnAnSha5l99Z1l/yQVswAZSGIAugNd/9xBgCw9E8aECkHUB22QPHIAVDlQdQAMWAibhBgZAasAVHUAI8Cqg96Tm0bj3VBS9jwd7IIBvuN9ffMHt9vLTbreXy+32QlwAhgMIeuNzKwOqCoB2Aa00KHE+EsIeDuj4H2N+Hf/TfAC6A4nhgQCQDDwiaKDXiq9KgBEJNPArAtCk0AEd2mpAizW3/lYIoANpBPg3BPA+hjs/9eXZV+0E8Bm32wsJA9aEoBCAuAABPiEAC/yDC4gSgRgKRHkAlgsI6v7iEFqJEMgBwb4BGkEfEEDnDlReoAP/SQRgOYIB+IYDMEE/SQBbXoLNr0jhq4qOZc0PHBSf5oKW519xvz//kbfby8+83V68ABfwniIBgwgQ/HoRUMv8w5qAoQqgk4DWQiCw+63eD8k/XAPQgK5s/5a5xzAAqgR6wY9k+ZEMtCOoJABb230hEHMFWQdgAl0Ap/+uc6tKBrrP/n0AuwfiNwTwNKguHHV5/qX3+/M1B/Ddb7cXax7g2e324vaQB3hhkMAW92tHoFb96cVAbimwkgQ0Vv7R+D8iACfuxzKfLvnNlAAjAsBwwP2MwLQAD9sbYJME0AFcg5uBPSAA0x0AobhtcDKDA0j3KYDhk7Hp8uKj9/vzH3C7vfget9uLT9nDgDUZuOYCLBJA8MNKPyGGIftPrL+4gy3eh5p/lwRUYYAs9Fn7tM/E9lvJwCH2DxJ/mPTr4nyyLiDtBgTAGCrgNuPzNuETgN+suEEAFhng9lkCoICMLH7V0isCeEMCxylrefkl9/uzz90J4NNUGLDmAnYXINUBrf5dCCAuQCcCvYVAYPk3G++VAveVfkIAFRLolgbr2F9ifP33pAqAV/fHRF4HcAS7AKlAAEIYFNwITOszs/wMsB6II4BXFZ0QwBsSOEYCDwTw2TsBfPrt9uLlqzCgcwFABI0EVCiANl8Uvq0JWNsi2JPZ/0YKsOiHxftsW4v51ZqAaBWgZf91PsBL/jFHwEqBR1cCiuJ3gAfCmCEA3cf8rmz8AMZHIoA3JDBPAsuHVgL4jNvt+UoCH34ggK0asIYBGArsAB7AD+reQgCl+GwZ8LaNlP3MEEDaSg4ACMGr/+ulwV4JsAEfLH42/vdKgWElAJ4QpBl+LAlKErHwt+oGMgTA2ngE4IUIOH3dGr/hAKT/m/UBdSJYPuVL7vflU26352sScCWAD+0EsCcDVxewKjfmAzAsENVn4EfgdySgnYB81yEAgL4RA8T8mTUASAAYBgylQAkL8K/+zL6rsl8qF6ArAeS7WRGoAB8Sf7isN/VZqTs6jQ5wXlweWfyqpQ8I4I0TmCCAT/3I/b48u92ef9bt9nwNAdZE4FoOFALYXcAGegkDMByAzzQEgJh+cAIs/legH0IA5QTCPADE+7ISkD0TgA/8sBIgLQfOgF/F9kPcr+J8fIYguyCILQRKgV4DNviOzoKqeJS0u4AA3pBAjQSWT//I/b5OmC0MWB3ASgBrGLA+IryvDNxCgRXo+wKhjgwk8bcTwUACsJ09ANRVAALwCxmEoFcrAUsuAJ4M1E8BDuHABAHomJ8RgACrZfQLyT9dBWi2OOEG9NJd/TDQ8HAQuBE97ZhjGKy6o+imnU+4gDckkCeB5cMfud/v6zr9Dz84gOdCAM/3JwQhF9CAD25gBWWz/8wNgMpj3K9Lfy0foMMBVffXyT4r+cceC9bvCcDFP0311QrATPkvWgosYQFLAuoqQEcQuw3v2si25F+M1RkZXLUU+CgBmCBOEsCbvECOBJbP+Oj9fv+u2+3Zp91uz9cy4Kfebs/3ROD6iPD2b10YJCXB+0PyrgsHdtBuRACfBeTN+uM+suJPSEDbfh3/oxPoHgwiC3/06j8Eutj69sAQqj++I0CUfvIpwCEvYCT90O4Pn1XsT5Ve1/+dcp9FBh3woqXBSEJkvjHHEOUPqJPAjUUCeOMGfCJYPvOj9/t7//d2e7YmAlcS2B3A8xcPYcBm/7ULEDIQew+5gS0EIEA31R8Uf6gAoBsgKwBd9ddvBBJAs6XARgLQXQ2o7T8+IETe+9eRACg7rhCMVgCiE8D4O9wOCb2ubOht1/vYd2ubzLlgKbBHEDSnAMfL6durVm8qBPwXWz7rY/f7/X/fbsvL2+3Zqv4QAjzfw4COAMAJbEC3wC8koBJ9lAhgxZ+4hi3Oh/f8dU8EqtV/JhHgWn9cC4CJQZXZp6GAk/1nawMkrrcqAiwPIIA2FwOB2oaAF5UkcX+GADBs0I5gsNbBQqCorJcFJjqWKvhNMjky0Aek7/LZH7vf3/vO2215vruAD91uz/dSYCOAPQzYkoD7vw34sFIQw4LNymNSUKk8Wv0hCYhkoJ74Q6BboO9eDKoWAHXvBiCvAdPZf4nt3QqA924AbfXV8t8uN4Bt2We029WkoErWpSoCSm11TM8AOYA5uRS4RAITIQDDavaYHxCcm5exfM7H7vd3v2N9McDt9uxDD//WKsAG/ue32/M1DEACuO3g1jkBsf57fqCL/7UbIISAio85AAG0VQEYiIC9DJTYfy/+Dx8HlpeDRK8G90IBHQbgWgD2WT8LoOJ7NyeA5JEkAwwxmuqzur5X6y+sBEwDMggrqoBNH7c68Puk/fI9Vwfwvx4e6H724oEA1iSg5AAaAewlweeyLmAnAHQCTfU1CTAH4GyTMt+QDMRFQFEYQB71lXUAOjHYlvTqh4N2xe5yASoh2PpaJUGDBDrLr9cGIDlY1l+vDlQOAQHckYMiA68KMFsGtOy65RCGsMIDT+QqJoD3yUwCy/f+6P3+7koAt50AXrwigM0FrIuEoBrwHMMAUhmQUKAlAwHo7VmAPURo9h/r//ozLv1V7/5v6wGMV4B3rwYPXEBqIZAQwp4TYDE+LQlqtQfw6my/LgsyZaeLg7wVgmDnWQ5AA5ZWCDRx7ECzyn3udgFptFCIgTlyFRMEUCKgA+O/jl2Xz/3o/f7Otz88QvpszQOsLmAPARoBSDVgud02AthdwPZ5BSxUBVr8L3kAVHrvs076KSLQi3/M9QCJ7H/G/rf4n8X41XIgcwHecuBMDgAe+BHA6uQgqnvbF5DB5hwUQM3vQgIWkKOVftH+gAC6cz0RXZ9MjmD5fh/ZCWCd1CsB7CSwhgArAUgIIC5AQoDOCewJwab+CH79WR4C0mQAZT4hEQS9DgfEztNkoEECDfi6FAhZflb6Q1XXqwHDEECpvZX4a0qP1l7bfAS98cQfzQUo9a4mASMC0CsIm6JGK/2i/QkCuFK9PxmIYPm8nQDu795uy3K7LTvwVyJAB7ARwJoAVLkA7QIkJ9A5AQS95Ad2YmgvAJWwQFcBpB38pUuB9wVKbAWgCXwV86Mz2ICKTwUWFgOxMEBicr0eoBwCGBUADfxsDsAiA+zflNay31ZcfnAdAAXgDGkcdAcfZCJYfuCX3O9vf/vtthHAmgcQF7ATwOoAtn9IACsRSDkQ/wqIIUGoXYEQQ/sL5IDJP539776DwodVAGlr5QBgP8sDdApP3gSUXQa8/rZsRaBeHmy+HwDyCI1MUNlZzX9iJSBO9igJGJYCo4RdIqMfJQ4Ztq8C7FXjHuSnQ92XH/yvdwJ4Z68ErOXAlQRW0O9/JRG42v9GBHsuAImAqv+uzDo30C3yAfVHoHeg9xyAp/7wlp+WFCSWv1sOTBb+0EoAZP5DImBrApAUMFHolQG19c+EAkbpjyUEdQ6gm/QEsCzZFxKDlWNwprJVWfBm/1WAvWrcQ0ie7Lz80H91v7/9v263+9sPI2zrAZAEdvXvXMBKBJIIFDcgyUAEvHICg/o7wA/Bvyt35wCc2F9Cg03RvRyAA34N8hD0xsIfXP7bQgDMFSgyYO8GsF4N/hQ5ALak1yUGRQDZZJ5VWXgKEsie8yQuH63b8vn/8oEA3lsJYJ2EQgD73xX4z9bs/74gaHMBQgA7+DsXAJWBBniHCLTtNx2AUnkG/LYNiUCpvX7wp6sIOHF/lwgkNf8UGagwYMgLMBdgLQCyVgOyciCGCs5nz/Jr8EXOQOcQZEbrfjjTU8qaCBseMyx4vxPB8iP+RU8A24Kg9R8Qgaj/av8lDBgcwApQ+QdVgW0bKr3+jsk//AztzBKgtv4K+Kj08rl7JFgt9BnCAIsQcD2AsQAolQj0CAGAqhOFCK5u3cA+84dyIJLCPm6buAgoBa5qDoDF6wzUkZ13iSDKKwTamSKZSf29cuzJUwq7LV/wz18RwH2Nl9dKABLArv6bC5B/+9OBGxmsIIR1AQ3w2gk4RECTfwBulgC0rP96/FYJUOv9SzkAB/xuKTBY/qsTgZ0LILF/s/RW9v81ywEwhbeAwUIH6hRwGp+wEOhqoF49fojqQoPlR/+z+/3t77jd3n3rdru999CzEYAQAYJfXACEAqL8W5lQgA5uoJUK9zxBB3ii9ALiYT2AjvuN72wFILP+XdlP8gLKFeg6f5QM3AC+VlMMZ9ABGuN+VePHWL6tHVD23or3tQPo2iWfBRgShDp0ELcBjmIAbwTWqEzIJvLM6kEDEFcD9erxCzg3my4/9p/e7299x+323lu32+oAtjwAhgE7Cazqv7mAvRLQcgG7A9B5AAwHus87CWBYsIKFfe+eCSBgt2J+7QBQ+VsogOU/9fIPBvLhASEF8AHwlhPQ2wVYFhmo/Wby74QyYLcmQAEbbbue2FcnAb28QTmHQKBwNVCvHv8IESw//h/f7299pyIA7QIE/LsTeIbqL59hPUADvHIBG8jBIWgn0L4rsKMj2Noomz8QgZELsCoAAnh0Caj8lup7ib9tX+ZBoKgUmFkWTGJ8S/UHZa/kAHT+QGaeoeQmMUC/CoAzVYAjYDvSNwPCq8fPnINus/zEfwQE8O7tdt8dwGZjIQQQ9Y9cwAB+RQIC4I4MdvvdLL+O//E7LgLykn6q3Efjf6X8bOUfkoNYcQZ8z/KzBUBYCqT/YQgjBuOBHxPs7JHh7JoAy/IzWz+xEtBKBEYg8fIGw+SeQQQ+CzHZP+oWXWPU/8z9y0/+h/f729/5kAN4791X/6/cpl4SCsDfLRQwHEBLCmJFYH92vssNgBPo7D8qv4CekIHpAjKgx1iffGbKb5UAQwdguIAtz2KsEWj7vIQggNON91lYoIFN2mznYKj9UBmwQgXLLcDstRTdBchEFWAWcLP9MgC9cuzM8aXN8lP//v3+9v/uCUDyAM0FIBFADqAjAsgFiAvYwK3/MfAL8InSd/Yfy37Qpyv3OSTgxf8C5vZXPfF3aB2AA3hJGg5LghMOgCUBo8SgEAyC3Irvh5xAwhW0cT1iQBKYWds/QQLdeVUQcrEjeGoiWH7633sggHfWJOAaAkglYL/wLQyQf3tYsCp9CwmgFIgOgIJ/JwMdBuB3cQTDX4z9wR2whN+WE9idh67761p/F/8bpb8O/OotQCsJDhZfji0qT9p0LsCI83X9H8E9KH8iCSiTrQO29bwAAbvlCipPAw4T/oRKQAVElbaMJ472t7jnqnEjrlt+1t+539/6P4oAxLquawIkF7Bb/40M9hAAHcD2GVzABmBYKSgxfyMGAbROCipl1w6gs/8ZF0Cy/UIOOr7vHAIu9iHP/2v77yX9ROUt29+AHVUCnDJgtvSn8wXsnQGzIUAW3F27qFS4z2CrD07wCogqbR8LtGecUwR4vX/5OX/7FQFsOYC9FCiToBGAEAH83ZwA5AM06BspiPKrNQIt/kcg69iffBegNqVXb/wdQgIMC0DltUuQ+L+Bmz0OrNTdK/91+4JVf15SEPMCYRkwEfc3stBxurMS0AoTMKRocaV8cKw6jpcFsdUn2/8qRT8buGeP55HC8vP+5v3+1v99cADvvfNQBZB4dO24Kv5GAntSUOz/+n1wAis4wAnoMAC/N9svSUKsBABgmwPAbQTwWzsW/2vAI6j14h+1CEjnBYZFQWSxj+sEVFyPjgBBrhf+aOtPY39vRaBVJlQ2vyOGIATQsb6etBguDMSQyAF4IMhUAmZANNNnUNSqBDvtzzif6HSWL/wbuwN4eycA4gDEBQgRYPzfSGC3/BYBdOCHxKBHBAJoAbdWfIz1I9XXsf5g9y0yAJB7iUDPCaC6e2EA2ngMGyIHwAgBldncf4ID0EDXVp1NYmbnrclOtyfDhiPOoCO4CEXB/rOBfOZ4yy/8a7sDAALY1gKAfWMEgOovoNdk0IArKr+7gwH02gWQ2L4t/sEEoLL2IQnoFX96HYC4CIz/jcSgAJSVAtu2RPZ/SPRBHkC7AkYEqceC2fqBfdKaCcHAAeAkpKVBCANcElBVgBQRTC4HngHOTJ+rQo2jhEbP6xf/VU4AmBza7L+EAZgLgGSgxP8dGQDwmQOQbS2xp6oEWAnQn1seIEMCJO4fsv8Q2w/JQU0IJMvPiCCT/NPuQP/noJ0rAFBa23VSr1N/vQhIgxzzB9odMMIAkGvFZPF6JkyIlJeFFl6IcRYYX0ciOOOcll/6l+/3t/7fngPYy4BSCmyT0SGAlgvY4/+BAET10fZjUhAWCg2AV8nBEPQ6D6DJgSUAoQ/G+Dr+T9l/pfg0HxAs/e3WBUhbsihIgHKkHGiGCQHYO/UHomDgdd0BcRkZlYtyAFlgZNtlzqkSJcwc1xr/6FjLL/tLPQG8t+YA3tuXBKPiqISgAB//bjZdkoNE/Rs5EAIYXIAKCwYHYJADlvhalp8RgS4PogNwFN8jgo1A2LoALxRw1gA09TbCAjckQHBZlQEFwEoS0Iv1S3mAYFGPlwOIJn+0v+ocPohEsHzRX9gJYM0BvPvwTyoB2gGsP6iEAowANsBJWAAVgRYeAPCb/WdkAKEAttNJwRbzM+UPQI8K36k9Kf3RagBTe2vhj3o8uAFXLxUGxTdXBrK1AIltTZ2JzUe7Lp/Ralvxvrb5kcWP9nv2fwBzIRF4FRFkx/XcwRljHCGm5Vf++fv9re+63d4xCABVRhOAJoOtRCguQKoCmghwv7L/mBPQwB/KfMQhCEF0ym8RAUkIToUAxrP/gxOwSoDGmn9WCjTzASw3kHQA5poA7Q4g3n+MEMAChiadiopXwHZV26usvB43e/7Lr/pznADakmBdDcB8AFj+5ggcF4AhgAlwwyUM6m+pPgF8U3BS6jOdAAkJ3HUAO5C7ZKBT99/IVDsGhwyY3e8qNfhCERXDa5BrlW/ftaoqe265Ar0U+PIQQCUzqwqYBYfnSK4AcuW8sjmHaMzl1/zZnQDeud3eXRcCrfH/ngNYbyxzAKL8nQNAMiC5gI0gBNz42XIBAnAkBACwqDyWByPlp2BPWP7WD0Crs/5ewq+1JaBnWX8rEajbDiVAlbNpwHRyAJ4D6EqECQcQWfxo/0wI4E3wcPJnUbSLXqH5A26qHaD9kb7ssKaj+nV/ZiSALRG4rwhsJLBfUKt/k3yAJMGwEtCFBGD/PTIY4n6d8ANyaEk/Q/nPUv8h+WeRgXYCVgIwSwbK3osKi4PonEGUC2C2Pngc2LL73Xanlj9bBTg7BIgAFe2vuoxZS14B7wy/DCT8xX/qfn/rrYccwLtrElA7AJkgkrDSJUHJfO/Z/wZ4Kx8g4IXyYKfm0i9QfkoSJK5HghALr51Ce2Jwv0ad9BvAj1WCidKfZf1x3UDnvPQ90HYf7o1WfSQMGbOpU1D3H6oCynpjPE7VfSccpoalMEHNdAxFKkDLgDzTRo5ZaXukz1E34f1Gy2/8kzEB6MUlsjCoCwWMEAAdgOcGTECrnECn+JYTgPyABn0U82vwt7hfJft0rK9DAlHooTSolH94GxBUAnTSL/reAbz6UBADt344SDkIJBIT5E62HgnEAwgFmjq3ChFkAJUFd7Zd9fwsdZ89nnX85Tf/8Z0A1hwAOgDJAxBbuU1usboYCoiCKvWX+L/lAUDlNUG0bD8Bt7dviP9Vf0v9LbV3XQCz/3qbZf2d0h8D+JAPYDb/RAfArL1l92W7Z/OjEICpOZvkw7bES0EisET7M0RxRNkzx78qJGj37rf+MUUA+zoAnQjs1gTAhJNyFy4X7kBtkYHKB0ifDMgrLiADfJMESGa/Cwe0/a+CHsmA5QQ8N6ByAzJZh1IhEobOAegsvwaVDhEKDkCre0cielYbau4SQfIZggyIM0DMtMkc6ywnMHMsduzlt/+R+/2tt2+3d8QBiAtQSUBaEVDxPyYB22cEuiYDQgJtLUFk7539ke1vgAeAR05gC3ekbAclwuaEjEVA3XoAAnLpT6sBCuStrUrIpqsBHhkwcBOVTecFJAteCAFSyk/GzapwBOJofwV0mbEQkNX2p/X9HX9IEcB7eyLw3q8IlPgSbV/LBThEIMreQJkhAeYOIsDrsELV8VmIgHX9ITGo1L+BnxGB5wQY6IvKLzZZCKD7nsj8m+sADjoAVHk9ga19tF1CzSk5GO8T9MCUAdpZbSqEUW17lpNYfucfvN/fBgfwLlQBcEnwdkA9cdGiCjCgGrCpZhACDMSA6wL28dewgKl6GzuI963EXwtf1Nr/wQ0YMb+bCJwAPgKc5gPIPeiImeUC4B5J2zbZnGXBQjI4Mdk2HFNPYqv9MNlJCJByAzPPEezIiUAe7a8ANjPWGYpePc52Db/799/vb7/zKgQQAnhvDwH0cwFWLqBluwkRYJ7AqgoMTiHjApTqR9ZfbLxbCbCUX1wOKQGiO8ASn7XdKgMimL2SoG4nkxGVnqk+OoeBDHR4AN87EmCWnlULBGiBuiNJMFC5RJB8HsACRgYwZ7WpEEY2pNEuYOoYv/f37Q7g3dvtnT3+39YC6BBAv3IK1wVA9p8SAYC5gRDBqz53QDasvag/dQboGMCy0zBA7e/CgoTyszX/VeA35QeH1YGc2Hwr2YchGn5mJNGVd8FdoEOIHEBo9VkeQc3cqFJgEkPhxSBHwoIMCVTAlx1vlggq4y+/7/fe72+tDuDdV2XARgD7isDtd95BpZWjKRUov4Acwa6BT5OEsEjICg1aBUAl8DpwA2kgQeCYbHsjL0zygfKbll9XC5xk3zYGgM1yA0IKERGgI2PJQJ20M13CAQfgWv1kEjBj+Yc2zlqAGdWPgBPtrwI2O16FXMrn8Ad+z04AaxVgTwDiasAtBNgnrK4E6HBgSApichCBBHkBCnQNbmb1iTPoSEXlDXCfTv6x0EAA2OUDtCPA70bMT6sAXjVAlf4sIhieC8BYXy0CYk5gIPKCA8CJGzoAI5QYJqoRzx8NAZ6KCLLgzra7igSWP/i79hzA6gCAAMQFrBMNSUCrFypUm+x78k/cQRffY45AqatOGDJy0CDHkh5dDERielFhWvrTIYHO+icy/jK+qe6sCkCAH70erLsXylXMWv5GFowQrLyACISU6HZ0W+RALX0Qz2ug4NgYUWScRNQ+q6IZ8GbaVMCdHS99jX/4dwIBCAmsoNd5AHAB1sRDArByAV1YgLkBnfRDF6AtPbP4LNY32lkOgMX/tPynSKFzC466Y2JP+mT+mk8BOiVAVP2MA9COgH4nQGcgHxyCAe5uMicqARTcJ+QBIlB5+6O+V4E7c9wMCSx/9HfkCEDyAMPDJiQZ2AABqtZUVwG7s+ZWMlCDO/F9iPFZso9l/IkDaMRgxPqe4g8JQa30yg14pdaM7TddgWHxXcUPVgLqvnqyWw6AqrlT0jPV33AekYJb4IlAdfX+6LwR0BVi8Yhg+WO//X5/e68AyLMAawlwCAEwF2BkpTfgqwlu5QU6G45KrdYNsNi9qwAQMgjBnyEDI77XYGcxfjXut1wAhlfSptsGoNHJPab6XkLwTAeAk1MIidp+mJlRJYCqPxCABwizr0aUDl3I/ogEMsDMjJEZp0oYjECWP/HbSA4ACEDWAbA8gJ6MjADWbYP6i5LqvyRROBBABHgjXEAV14k963s7d0koOkm/s+J+FiaERADqbjkAHKNNrsRCoE7lmYsQ0HjlPm+dgMzKRLmQkkgyBJhR/SPWPwPyTJuriWD5U78FHMB7eyJQ5QDaYiBhXL0mgGWumRNQAO/KbieTASMOL8bvVgUSq2/lAvAaOvDiwiEjs6/BThdZ6bUBJNvfuQN0Z+pzVzI09nXqrT3UMRMAACAASURBVJcKg+J6xKAnLao7Tvruc6ZcyBS6EDpUXUIEvgyAz2oTnQuqe+aYzT386d98v69rALZ1AEIAazVgz/4zBzC8aorlAdS2rkIgC4e8v2TxkOsGMLeA45I6vgZ7ygFg4g8JQhOdl+FPZv+ZnRey0CQhE4PtH1TfCBmkXQd+S+1ZXkCTiQZq0gG4sb6qMHSAKFYQHpsIMoDMtKla/syYy5/9Tb0DWGP/7R8QgOUA2NtnzEw3LhRS6hjlA9CK6/gfS4XU5rOk427p9bg02cfATtS9CwGcSsB6/taTf9Zvx0ItvQ2JgH7WgEYyMMA+5AwmHMBMDsAjAhrPTz5M9H4mggy4M65g+XO/YSeAXf1lLYAsBca/24D7MwKdakBIYOUBxKYyJ0BDAeIOTOW2QI75AgVkXNVH7b+VBFTgDisAQda/gd5LrCrlZpa/WXJrEVBk+cGxNWAkqwDMQWiFNq2/zNKgDOi6A2NFICULRAV8rrSN7HgEzmh/NH4G2MZlDi8qXf78Fz8QgNj/thjIcADtvw9HNcgQwGxIwPIGLHTQVj8BfszWmzkAlZsQwFrlPbcCYOUCjBwKKwl6pUBRWyFhukxY7LmO7414X8f61BVY4YLY9iDBhy6BTX6LPJCoPHtcAXelbQRUD+gZEojGZyCvjrv8hV/fOwArBGBLgnFpcGdJYUJ0gNknxLDNCwm8xKEV6xtqPwt4DWpm92kIQICN7bSNF2Xv/pLfUgNd5wxoCEAA34GbqL0VAmhSuMIBuIqv8wGJRUQWmCzAfNIQwV/8tff7O+9BEhBKgEMiUIUAXjLQinMbAAAcCIruFWMVgBPFX28iLhW2Yvzu+JCo06A21wAQm69XRVJwk+RpaiEQCxeQKEDlaWhgtEWQWEqvt7vhwoQDKAFfjR+5hytdgjf20X1HLH/kIpa//GtUCLATgE4CogOQz628IwzslKx0gosuG1bWnuUGotJhyzUYYUIjBSsnoJKVXZnPCAeYo3EBH1UDDIA38CniiBR/CA1I1r5VEQBUg/1XVt8jjG7iWZUD5WEz5UIK8sRagIhYquQQgfqI/a/aeBYKZMOD5a/86r0MCGsApAqQcQDbgTQBMNuqJ70GE/nuOgMSGjDFj7ZZhNABnxBTIxon459Vfa9yYpUEEfRU5RXounEUkJEgGJlEYNb9O2IQ16hsO07y9nk2ETjzJKG4JIKUSlgQKqyDzgzQM22ic/AcxPLXflXSAew30no8eDsJvBGWyhmJsKojQOAOi3R0yRFtPcvuqxo/tf7qeryYv2T/mZqT0IARgfzmG9Eg6erP8Jvr+4Tk4Sk6IwnWfgA/IxsCPhmfKWuk3ugcqENIgLwC+hl1j4Ac7c+CPDNOd4/++q/ccwCRA1iFHkqAtBrA3ICh/J46Yp7AjM+DHIK27t1aA0YIbKGPIisrw59NAOqSH/0NEKyMCBS4qwnAtNpnk4JGnN8pfKYKoIgiA2R2DEYglW1XE8FZQI6AHu1vv8nf+BUPBNDKgFYOgDkAsHdmQhAnkhP74kNDg72OwgMP0CRuN90GW+CTdCwWoVluQKv3EAYQ1cZjuOpv9JXJNyT49KIgliMwlByVu7kJUFwvPBjcQuaxYSuUOBAGZMjGIxEP1BEQn3z/3/oi4gA0CQD4uxAACMBLCKLNjFSPJd3Q7rtJOWu1oZNcHMgmE+8H5T3P3Xj7OlCzCgEeN+sEVDs8Rpu4Ol9ggd1ScuYWkAQIsDv1lrYqB+BZ/2FfsBqQAe3sbZG6Xwn2aGzr3Ja//cuJA8CnAXfr314SajgBkwBwAs6EAwmwWWFChThY0s8iI297B3DDPYRtCLi3Psb2AdRAHrKvqb9BCEyNtaKXS4OkoqAnomXjKUEo9e/GSjqAs0HvAS8C5WzfaNwKES1/95cZDmAlAbIacPudIRcgi4H0oqBuUirgU6WDSVtJsHnJw8gtZNyGWeJLEJNn61vZzYjzo/3dQ0Ea1DgmUXMWAqTAbil9UOaLynttQj+iAzibCCLQRfstUM+ShJiqqP/y937p7gDuex5gBz5bByD23woDMA9ACeCAG8jkCLTis+8ZUhjCAisZOKvwySw/OoWONFWMrmv4ZsWAqX+wrXMGbLkwnMvgIowEIWuHTsV1CTKz978WeViA88IKDzRnA/Ts8TyCcUng7/+SngC2twFZJLBPljIB4IQ1wgA9waPM+rCfJApN9Tae1beOGZ1LO06CEKj7UbF9A7CVB7AShIa9R3Uf1gOwhF9V6S1iEEQFDqFN3my14IJEYNYRTANNERd+PZMMIsXXp7H8g198v68VgHf2uP9dBX5xAtvbgaUUqEqCg/1HKweAlx9vsLeGIlqxchWojCyqY1RCgXK5jxGHofIsD9B+V92nSAgIxCEkgLEGBU8mAaO4PgoVmEJbOQQG1CzIs+08Msg6kAwRzJBOlgiWf/SLRgewksCq8l0YAKBveQAgBGb/t4vDhJQmAwf4a9dQeZPWnJbiHMfgOYeNlAKlx3BFOxs3L6B+LySS8EUg6rzwuEgQ3luBGugDqx/lCzyCGPbtCBBi05M9Io2OFB4hEXgmGLMgzZDEjIvYruUf/0I7BGgkAJWAbY46SUArGThMyAIZVADH2ppEkiCBir2n5xmpu5ME1I5pUH+LYEnFICKEDpiFEADPSSu0JhQX/MphTBFBIYnI3MRjgLviLs48H9OR/JNf4IcAK9bxPwoV9TerAXgj4T0BOJk9MhAQDZOfACUCNgIy0zbTJpPZpyGAQwTiKug7AYkr0L+N991Vf00gpGyHINbK3yZVMQQwVT2xEMh1BEZ/Nvk1EKsKmgXyGeOeTQQdEf/TL3wggNX2b/H//jqwLRGo1gC0HMCeD9AlQPw+WDqZJEZIoCdaNY6OgOmFAVq5u7ae3Y9AHam7sd8kApUsZHaekclAvrv86eoBcwkZkFvrA1hf1wU4Cu4Btu1T/c8G/hWgrxDEmSFDc0D//OdDCEAqADoPIMnA7a8wrv6LpSEFfJlkoQtAdfKShEmAWlUDN7xgOYYE6DPuBY+Lv0W0HRXdK/cN2X6l0jqcsICubbx2AVeFAK7Sy+zV1YDiasAjgH6MvqZth+vXH6sksfyLn/eKAFaw6yoA5gEE9FYScDsZZfsR8CwhSJNb2Tq5UVLsQO0lE5Pk4bqRiBDU/oEcHFVn9X1T4dFZ6TKhYfWZcltqbm6HsZm6D07QKuGRcqQGgEUKSF5N2QySYPutbZkw4SmJwCIIJIXIYSz/8uf2BEDXAWAosN/w7gUhAHwhge7GY2wGBKFtf5oMGKgcl1Cx/wKwKKQY2hWB3oHbqver7ab6J8t/2L9VbaR6sM8auk4gArlRNbBchQnSaBw5RyV7lRCAgSYCerS/otRZwqiMmSECc7x/9XNUDkCvAyB5AAwDtrlBQgG8KegCOsvolQgrgPKcQKTQSReBhOCquBP3a8LTToXF/vpY8ls2J6AdBFH/rNJfov4YDoL6UzVP5gDc8MBJBFbBnwHrWW08EEcqrvhw+5oNBZZ//bMLBCDqb7kAcAJtUQeyOuQDcGIPnzFeJQClSbJqngBULW3xIzKpkBYe3wGxkISn/u5zASwccLbh5NHhht43ELsFcGeFXwfmA1UAdBsZ9YxU/ej+zDkwJ+RtO5Mkmhh9yc+637cKwJ79lxyAlP/kKcC1IqBzAJgL0K4AQwC0m7hgyAsBrAVEaL0HJU6SQKeiyT6dWictOwsTsqW+9ttosAax/pA3AKJBEqEhQLX+T+J2PG9GEIxEPPC6ag/SNzhOtm/fZo3JABYpfLT/KBFU+leUvxHNR37mSAAC/lYBUDkA76EgIYWOAHASKnXHm4/hwaB8pIxIV8oFFpxlziNws/0diSgF91bwuQQmE7QQ+2fUvwO+pf7KkXRA9db6W6QB1+KCHu1qMgTQE70DoTOG24/Y5qMuIEMOFYBXQ4FM++WjP2MnAFUClGTg5gCEAMhy4M4F7JNou/eZ0qBWELD7qO6D0uNkZXmEwKqb4HXI4wzAa8ejLTYSjb5mfXz8jgCvlP86YrhC/ZH4lfpSFU4SgAfMo88TZFxAlRgyY1aI4Iy2zQF87KfbBLCVAAP199YCaBJAV9AlnAxX0NqwnIBSrHSSziAPa/VeJt/ACMp0AY6l1+CNvofqb6h6NikoJMMUHN2apayZNt3YxRwAPa6Tb2iTXj4cVP2MwkdkUQFz5njsGt1tX/rTHghArwHY7P++DBhdwDanYCWgzgPIfh2TtfUB+6QcJhcBedfGUXoGwAaOyXhdKy4rC1rxPAtlymqfjP0x5h6ArVSdARJdiQa6BWC8t3h8RhQ616AnY+cEigRQdREWUZ1NDBnFz4I5Y+OroMf2y5f9VE4ACH50AS4B7OD28gDtxyEVgW6yOIQwWGlg/Uz8bQLXcBoa/AM56Dq8FcMbCTyx/o3ISF3fsvaMWPRv7JLEPht08nC4TyTDb5UNI1VnwO3coaHQFPBKxa0QwAO/G1LAucwA+2oHkDkny2Vs27/8pygCANUXF9D+h2CdC1CA334rcQf7Z7yxsp8qiFpBOKhPQAiW6jIlN9UdzllAKQBjdtxT9eF8HJLQ5xNae6Lska1nSu+pfyMjb3GOlxwEYrHANwA6sO/abdBxyRiPAf4ZoGf6WOA9y0Es/+YnAwHs4JfsP4v/JSEoTgD/is1veYFZEsB+xAp7gDEX0yRU2asQaHX2wD8QjEEsCDKt0pZqM2LpSqaiiNpteCW7mQSgukc4UTWxsH0Z8EaKT/erRGIW/E/pAo6AOdt35+Pxvwf/t0gA8BKQFfzZMiDmAYakoJ4oUB2gE4UtHDLiYQSa9bnsDEhJj4HfdBYHF/V4Vn8gvh3sh9Rfk60ot7c9Uf+Xc80AkDnCNGng+RrnzCa/RS6Z8zXBJDv0ORnf9bHY96Pbov7LV/ykMQfQrQMgVQABvP67//60BKgXA7UTU9Z/mDgk+TeAndjrBtpCBcEF9Wz23on7j1p9TW74mzaH4jgC/Vtri20uDdakzvIDbTL0y1I9Gx+V8CJHgNeTBfIMEXhjz5LDU5HB8pU/ccwByBOAXQ6AxP9sQVBL5EJGF8uByPYDCehJE1UGAuB7JKD3MadA22iFx9DCiPPpeZAFOZWyH46Jk2cDPiZFRX1IvI7XrMdg2fsOvCRsYGMM25QadgC8KAeQIg5BblAajOL26v5Z4DPrb6m95wKWf/cTxhwAPgJskQAu/aUhAIB5+22J9aelQa0uOuFFQoRBCY2Soc4PNBDBMQVAGJ50amqVI8kYOH4F3FTZsyU9EvuLMs4q/NBP3SNT1Y2FPQyQcs0RYYT7JxYTZQgiAmoE/Ki/8E80DgO+RQYe8Nvx/v2P3wng9updALgAyEoEYrY/ejS4katyBegG2OfOEqpSX7s4K0QohgVUpSft+5VgR7BFsb/nEkxScByD/s31pB2IIOMSIETRE9YLF0wiOGMtwcUu4EoyyIAe79uyEsDwIhAsBSrrT6sAuyJ0i4KU6p9CAkpl9boBNuHT7iCw9vThJBJfe8erKrt2IZZjoWSIcTkLCTwVt6oC6nojwLKYvuoWIsUf1DsZRljn7m3PAPcMBY/GqIK8YU/IHTYs/+HHKQLYAd+tBCQkMIQA7L0AQAxo8bbjI1MXPiOIqMJNOgIEly4HmvsUIaUA7oQ0tD/LuBsAzTqC7XosUnAy/MwBZADtKTl1fjhB2aT19j9RCHAGOWTGyII/Gyos//HHAgEo5c8kAbv4X6m+lRDEmy73EtViSEA5pcFOIVTSMHIEAgTLVuvVceXVeFWwO3F+ByIW5zuxv1ZRRqL6d2TK64E1Y/9dIiDWfVB3veqPEcEThAARcDNgPKtNdC6Dw/lPP+Z+fxcWAOHbgM2FQKDsQ/wP+7TSo+qzsiAqk1apLmGoVUor4kTpcCCDALzZen1EQpbNp+QEjgNdiZWxN8t4pCKQUXeLOChZOFacEoFxTmzsYRIjEZwQAnjjRwCL7Hu0PxofLnVc1IM7gzxGE96vWgkAHwUWF8AWAuGDQOyhIAQ/KwPu+9t5KmVvJwXtMHSgE9BQfU0g7oMy2g4byb9ZMFtkwUCMhNDtJ2VDDVoNLBoSEBLpQBYB18kPpElkv9HM1XRzwFB85gzw2BaArX4uoRRAFYG7up+RQYYgKm5i+aof/RACiPK39wAAEbB3ArSq3v4Bl//qpcAa8Nt3QhAM7N0FE7DTSWc4goEUAAwm8Ky1CNYCG69syWr/BJBWLkArvWflL1H/iDwE2I6dH0hKJkeyYtCRFYCThSdZYLuEwo6hCGwGlE9FBsNx//OP2gkAwwBJBBoVgK4SsE8KyQWwuJ8RAoIdCQJvpMXqVnlQA3z4TpRdjsHA1IEo6hss7JFzQQDQYwaE0AHAUmMrSWgAmJKomuRH7D8DmOVWGMAjgHb7T8oBeORR2XcFOcyMyfps2776C/ocwPr7df8rkEMC23xS/0uQLgVm3IBOAHYni1ldneHVcSMJKdbJEYYOQU7BDR+M8VMZeQZUY1tHVNYxlQJnQgJNKNbk9tzGAFovx0CWDXurDkPF1+MVcgBZhzDbbgaoVWdQsftNaIHcNwLQIYCQgCh9SwaC2jfgQ/lPg92qAnQnokIB6gCUcrlVAqNsZqqco+xMtTM2/FTwVxyBofAsvGGgNe25UxqskgxV+ETIkCaCAgFEzkLmqdXuqZ1ARBam6gMAl6/5kSoEUPYfwa/fBNSeBQBi2MZW7wRox8skBgnYTUfgKLeA11O4KDk3gJ0pWzI00BOYxuhOeU9fhwXWqdg/Io7MfuJKKNhBfRrAJisAFJgH1wF4oPYAF4HxyP6oLwN6xhls/f7Lj7jf5dHf9hdeBNoRgJH5L4UB+2TSpBDmBADsCG5U9izYq+Sg25uKqqsJhnJ64JdrcC13Mfan14tAdDL76MhM0qmOFdh2fRxGJBZQoycKI7BkQZ5tFx0v2h+BPw30BrhXH7bweCOA/eWf+kUgFvjxKcChGqAAbuYADCLQ4N5O14j9I/DjftcGe1UDpn7Ogh2LhCrHfyzw098Hwews/aVkkMzkD8qd7JciggNJQItUjoC0CuAjxMLOMzz3r/3h4ADgLcDM+ktOwKwC4HJg9ZmV/RoXWaGBUv1TiYABO8ofWLHwRDLPBd8JCn8quLMWPeMkiPozK5/dNpBCkAPIgnwWiLP9QqAqBc8of6rN1/3wh4VA8gRg9AxARwI7iFgJUCcAKwlBFg50lQIdDoCbMC1rpYKQrBygW+kUMcjkR+CsxvHus/sReCPQRvsR0A74rPCBnXtK6ZVTsdzgYwK+ovaVthE5zCi/8MnydZ+vQgC1AIiFARveINHnJQMbNlHlAbDbiTj7NBmUiYCoNqsiDBNUT+YjoHaSh3Lz3BDBcivedkaSjvqa8X2ypBe+QEQBVl9vBHrmCCi4H7EKcJban00GFcJYvv6H9UlA+i4AXAuAZT/1WWf/LdXv8G6VAQkxlMHPMsJFJ3CJylugstTaU2FPdT3wZpQ9UZ4LiYvU/TswJ1xDRsWZ88v0a0oIFjtDNt7YEQCPEEc0dnX/AwGQ2P9oDkDCAvld9XdP9dEV4I3tbpaenMZ3V2lIn0yCSlv0wyTh1Nkz9p6ppxVGoFU2VV/UOqn+6NKiMbtzdQgmcgRv1P/hJlXdw/C7/dcfajsAifeFDESU27MB+wa5jzoUaOB3LD4SA4v9NVF4LgAnd3ehgeozAHugHianEx6wCR+FG2YeA294whVQYtjvWQRUMw9BlDIkG7b6j4VmVrusOp9s/y0ncJX6R+POAD4kiI0A4L8BQ+Uf3gfg2H/2MBBTfdP+C7vAzdaPAFfIwLSERHVoIoqUBjNKm3EDGVIwx8kAOFLuaL86hkkkxcU/jDgrSh8CUhG9B6iMzc+0iUB7xO6H4EWszLqBb/ghJARgTwKytwI7OYAhBHBcQDYckOtlTmFYABIA3XILbCEJ3QaE1ampsRItHTbsF+mqqpUryCzZzYA/QzJJN+ICPLFqLwPCI/F/aXy5N4YjiRT6akB7BGmd2/INP/ghBGjJPwL+1QnIfGf2X8CuQ4GGEZXoO9UFEOdwhAxYDiCtXE79ngKh2t7LFWTAHwAbSTEKEby2kaqznEHUJ6XmCUJJjaPUdFbFK4CvtI2IprJ/+caVAHQSkD0ObL0MxCgJbnNNqb7+XlX+KATYLlwdky4NZVaRxY/ZcMGLZwNHkCaXCPwZ1bbOBZXNyS0wkJruSKmll1w9CsrHdACzZOBdYwWwYj7CcAhcijf+8o0/KHYAkgzs/u4Trqm+/g7gKYUDRNG7F4jKhTlAbz+SbgNjdz+g0S5yA0wFO5AQAnHVzwOoZ/vPAn8yMeclKSMlPwOspm1nhO2oeRZEM+0qgH8q9d/O8ZtWAig4AMGQuRDIWQ48JAUBkO3eRcDWuQSi+pETQOBSdpxQ/kjJI7IYljkrVXaBlajpZxbqeGrOQEDzGqA8OoywfvdqHP5+IICznEKFSDJOYhjvm35g0QEkFwIh2Bm4w3AgcAJ6MrV5R+y9BpcmCFQl+oOz8MByE0qNu/EK4UDkJBihWHF7Bvz4m5jAJct+I8Wn+6+I1a8YE0k4+OwBtaLwlbYZwIfjrQQwrP4jK/82+6+2y8q/IQmolR2SiNvvqFUc3x/A9jOwESfAgB6BnxGJFR6E9tWbhJ499ey9FUbIhDT6ejadAjwKMbSVtkgxY7kvAOuZjwFn1fvq0CACeAhucGPycejzzT9gdABYERheCLqDUQhh+0qeC2iYNcBvWf4wMWgQhE7+CdHoC04TAlFy0zkY6+41udAJkyANar8JKVIHEBFEspYfOZLIxofkmSEOr82B+H9WvWcIoALaStuILNj+bdtKAF4JUKu+uQpQx/5AFKj6NBwQeiLOYCCxKEegCELb++GHcCoCA2taYHXU0IrtXTJhjsd5kKcDpziDBEEgQZkkg+MBWVigiYjA/T3gZofjGI4kC+azwTszXgTaqwlgHX/5ls97tRRYVL2tADRCgUH1yYKgDofE4nc4VqDG/EGbE0ZiziMIF/yGYlCHYJEKKzviJLaOEWTbQ5CQpN9AAhcoP5JWGaBA8lmyKYHZI+FgldwMeLNhgncNlX0RWczufyAAWQqcjP2tCgACV+Z+t0RYAUmIpAOxEdtHTmDbTybBsHaAnIMmiuHmatcBk9m8iexcEgrqVgP2c6cxvFL+LMii2HkYJ5Er8H6TaeL4ANj/CKSPofiIowcH8P23COBGnwHQhOBVALxHg1l4kCED0mbIEVjqTIhk+4GT26dJIXAF0yGBQR4U6MR5ZNsNTkIRS0mVsa8ir+o4LnF4ZKvPYXKV3xWK/1o4gG/9/ioJKC8E9dyAAXaM75sDANDp+N8LA7p3CyjF1Y5B3xxKEsZ6AVo5SIDYZHMvGRUlqqLseLCSbzunpBVGMsy6hTA0icAWXf9sIjC45irZyPzKuJUjIH4KxR8cwLd+v50A1PMAmOzTnwXTYvkld7Bth5uM+9uBo3yAodKR8uP4HUEQ5dFtGYEM25QCDwQQqVAEzAgcQdx/JvipC4jICX50Cpxk/wzoorCkAsrM8WbHM0WCEGXU9qr9y0oAWwiglH8LCYz1/w3wqvznqr5BDhqsUwuEqg5BkUwHdgOI2yGsx02tHIHcaGd/pMQIbArMRF7hCGAwFMqAxWwTEdys+sO9zJzfjBuoKPVVba8lgGISsFsApElivyE45wdXADdNhwUdlkm8nnYCCeWXY+l439tecgvG5OxuZqSMjnPoJnwWYJETYUoenWOkaBP9M2C2yDML8my72fg/Am2FLKKxZvZvfb7t+77KAWxOwEj8NXUHp7DNb3QBCvwSAnSCq0MAQhiitugOcCzcbsX71qrAri9OXEY21nMGHUu9GnG4oQVncMg2Z8FPSDEFNMcVHemf6ssIidw3a6wsyM9oVwXhUQLwznkQMVIKbQRAV/45RKDJoAHcIQMhiwjUQwjQscer3hYh0BWBxhhCNCzej/ZZx9FuIsolHLbMFUWfAXIUviAY2ecKOUVjMTIoXH8EmAwhRSA/Cuoj/c255pHot33uQw6A5QFku5cLQGAjMSDmLCcw4BImixUaCDCZkntuwGtPCcABCx6nHBJkVDg7qSuvwEoAcQDIBPi9MTIAKyt59rcKyGWWHCr9IvJ4kv2NAII8gIC1Wwqs1wUAoi0yEABrx82UP+sGziCFDsgkHLDyBN1N80gjqCLg+CkQJOPqdn4BUOhEniENVJtE/2x8TduRa/IAmT1WBMSzxomO8yj7P/65r1YCotIPn0m8j28BFpVvwGdkoCRf2/gOd1k3MNgImIEEyBZZYEKJugVrHYEoi3EsTSzu5HEIZCCFyuQPnMIl4If7kgVMtt0hUkOCMj5XgVex7VM2XU3IlEAQxyPDdP0//n3GlYAh+FWs370OXBbbqWSfblNxAlbbsuUPyMLLBeA9YLafTZruB8+AO2vps+32650Flqem4b4T1d881oyreWICqJLL1e2XjQDkjUDkmX+d5WffEVeWE0CBNJU/qfq6f0eQBdVv/Qw1tdyCBWzGsDJGqBIZgiCAzjqK0kQ6A1hnjOGBNUEwIUmd5AAqxyndB0PFw7nkOAY9R5ePf+9XSUBGBAJudAVt234Ttn37xi4ESGyTE0rnAIBtBqwfAD/+Zl68r8nGdA3RykEsy2TtfJYkKsfWk+wM4GavJwnA2fj/CDCPgqzSPwoLov1HSOUVAeBKwGgtgJH80+AfbL8OC9A66Od0gFy0UiuCa+Sjt0cKboYQRGmHsR0w4vmGE0GRltk+AapuIlTbG9dcDh8mxpkCauL6wt/eUcojfY8AUiv0Wd+tc3ogAA/8xsKfDuykTVP2/YO1GlCLNnUCiii0Cpu7LUfgjUf2WTG/JgXLORwFtbkE2VLQRNKPTgiHjNKASBw7PZZ2J0Vnc+Q4ugsk6gAAG0BJREFUVVKKQH/muZxKCp/4Xv3DQGLn0fI3sEerAPVTghAaaFyllgcDi1Asq43t6yzwI2IIKgHiOFKWjZyjZ3XZBMuAOJqYbTJVwwuDfIb/l8FR2cy5VX6Ts0HmZdunz90i7eClJZnjZdoMv1EjAMcFbLiYAT+x8TpX0DCeAHPXxAA5XTug7YiW7on9NPYPwgLtEEKiSNjcTg2y4YSehCeBv+xUZid98ne5khCmwHaQDGeOGfVZVgKwqgAiiBH4U2XAfTCco1qxNcAZxiOAm+J/kSvwEoYU4Anl325ath0hr5BYNPDYq9Sr4LzY+reJfBZZVa/vhPYRGGf2Z/p4bZZPfM++CmCFAF4YIETR/upnApw3AqUJAQ4ShQPD/ovA3wjdANDwwxvKZbVjN45uSwI427eqnIywpsbIKOT7iAAy4Ix+p5kxMn2kzSsCCKoA+AiwJoOOAJTtF8vPSAK3NSFLhAJdPwLuTKiwHc8jhsx+1YaGBSRxJdeadQgWETBVTJNG0mVEE3TbXww9yg6lmPzL/gapawNSitpXgIdcF40783tlzmUd94EAEiVAuc8m+HWOoCH61fxAy19R/mplAElHicqrryeD3wM1fVkpm1gBkOgxHEV0gZA4VnpiFlQ5MzHNNoXjpM+9APBozKuI59BvpgAwJgE/B0KA6CWgrP7vZP4bWcBJZJYEI1FYQuzlAtw8gTFg2jXs12I+diz7gQA9tu/2GaRkOQvrfYapiZgNR6znyMn1zQCkpG7GOZfG0PenQAAZIM6cS2bcq9osnxAC0C6AgH14+Ie9EIQQwoY5FRo0HAbbKY5In3Yf2QtHEGVWiGEAVhHow1cHPHgeJnAZqAIll3GrSUdKBkdyBmQF41WTsxv3LMK6mAAe5bdwSKt6/AcCMEIAmevrbz88A7Dv1CofVQQ66w9ftAJrMdSuAHD46ucIiEGDeRDcKCwgB43KgZYa47l4biIav0QyybjfOufhWGcRiQHK7nivKQFUATcQ+Ylgnhl7+cT3sEOARgDO038dATjZ/w74AKTM9q05AScjBY8YEHRVy4/Kr4mEKZXbRnaSa/IAvR3HISk3CZkkr3AMOPeM3c2SiTtWAfyzgDyz3+xYZ/6e6XPoCMBZ9tuAboB8cALKIbT5x54H2CeVBrkGOHUFHjFQNlBJ6wnVZ+AWgogA3Fg6cVymuJ1zME/kYQdT0CwgXTUpEFdmUodtCgQQjrVf2NXtMuNn2lTu18x4rxyACgO8sp+n+ts+A+Rs+a+0Z1jFfXS/ASLLGQxjJEAYlgpn1FwdN0UazloDD6wR4aQVH4GTPP+ZCUkn/MmhxtWgsu7H7O9x5fkun/hsFQKw5B+AGsGfjfc9UrDIYjukmmjatlv4taoAFduvyccFWYJIvOSdFvIo7s8Avps0ScBaE606VoVUdFvL9byO4Inc2PvhnEcC2CfL+mf7p+P//ar1dgTsEA7AmJ1gFrZ36k36tXEjV8CshFwT3tEsqBPt2rDQNqX68GNl2kfEUQGmpcQR+VSOkQJIQf2vUMorxkxdd1R+hbl6aLzmAMhCnuEZAKPmrxW+EYAFcGtpsLM9dATgUrSiMvLQbSruYArQCaKIAJxyCjgxnGN6hGLuyy55npicFuEcJZSjAD7aPwvOK46TGfPBAej4nz3959T8B8VXYMR5aK4HIACOLD8DLZvzlp2nZiAB1G1+J9pVbD8jrdR6Awts5PymQL+Pf6j6EBCCNVHN/7iV/lgq6XkWCcn1k2NmwX2UxLLHyQBeLkPGXD7x3cccQGbdP1P9UPmt5CAAqiMLOVvD8re2XkjggHXASALUWfAzl4BzKLT0wblk+kdt0vuNc6lMbBPkhtU9tMpRgfUogGaApfmi8lsdPd9S/44ASLyPQEelZwlATQqIPU/56ctB1MtEGI61slP1NybvU4LfELBXmxMZfzZGxnGkQY8HgB9rxkVM9XkK0imqfYUYqgRYAnHBEelxXzkAJwcg4EOFz9p+5hSasBPlZuGCMgIPIkwmiN50RjWg+22zDsFxHRnwR21cEKtzjADvTUx0OzMgjsY2VbEI/iq4ps+L3JiKslfPszJ2pS2exwMBZHMA+8Re709HAGxxELTtnACgWZNIa5ew/APY9c0xngno+qlBXHxfDP7tBlaOwSZjsn+GFLZJciAMOUQYRQI4dKxHBvWVJDAz9vKJz4rXAYjidiHA/sPRtQDWE4LGOwIt1e+2KxvgEsD7DPyotNPqXwQNO84ApIkxI3IJwXryMcPjnUAAVeCd1f6MaxsJgNX9WXjgKbzlCIwyX7vn3jJhpZCUAGBjRBCKTzjukoraOlfbp04iooTk04mFic4I6QiwvQkvp+XlL44cewYkZwF0uDZ1D2Ztu76VR8ZZPv5ZDxpOwwDr+X9P4ZV9b66B2HodRmgXnHEGrc8Tgz98B4GF4wJp0Bud7B+BqDu9fcxMn6hNaT+5llL/IsnNkMNMn9eZUDYC0M/5I2jXzxqowzaw9l1bZzsCl1p9I1zQJCHkhffeVH+HJBgA9HwysZYE4TA/Z/sZziECi+clPAXOKg62y5xLFHJMjZFU2ciVnA30GRJ4jD7Lxz/zVQ5AwFVa/rt3osAv5gIQ3A+25OFuenbefV6AlBLZeBb4U/hMNSLQC8gonPyzx7Xq7gapyObwfKJx4SfIOJmzjveYQM78VlW7PktU2eseCSCI9wegW5Y/SQwakDpksPYLM1juofVTQHFxE71NKGkJQmyGDTyt9qsFGeCYo8N5ZcfJtnMnsvo9smNm2mWBUHU50bFnjvvYY67H6wiAvvLLyQPgk3xWqKCFRZSdAbdti5KBilws8YrcAd70cgxfJYtAYQPI97uPEog62DbxCmNGE7UKJjx2duwz2kVjXLl/hiAihzEz5isCCFYByhzRCj0A37H92xjE1neuwtmP/V1nQBYKWfMbQ40MCKvtD5EMO6ErgBqMGQGBnWa6z37sdPujoUYUipy4f9a+R0A/c9zl277bXgXYRQABjsDUIK0Anym7DiW0m2CCaS0ZHsggafuzYO6GSwCQNkn0CwnojDESYUwFjDjcTL9osVHZTTwigCMgvu77txCAEkCy7s9IAcHI3IIGNoJwIAV0ppmwYD+4xgn9HoCpAuIQl0aDsF9nH0J6KDWo2v5DKk86zxy/QjCZtq9Tm+hcrtq/EUCn9M4LQIYwYL+x5mpABUgK8H0jgmH47IC/U38Sl1fBnwV+GryzuYILwd+GTl5ENPmyzNONkzx2xg7PklP2ujLtHqtNdJxov3YljQBEibW1t7Y34CVW/Wngt3vv9MXxB4sPd5w5CBY+6PESTvihCUzU7JzF68uCwzrnSnKudCx1MZmJUxo/itWTP+bMeWX7PEW7s46ZGSdq00IA+uYfou4DkEG9vX2W7Weqz8gBccjcAQNPRfnNuUjcCQPB6a7BZIMqBI32SfBVjhZNtm6sxPFL48HglX5XtM2OeWa7zFhWm+VbP6NPAgrYXOX3VH8fwFT9qEqg+rvq76izRxQZfEVlQXcOJ4nDBdgZY6TZKoZ6ZpLFo4iq8JZHj1Htf1X7K8bNjDnTZiCAyPLPxvs4LnUEiaW/HaifCPyReEXEkSGfM22/nO82OaKTTyP4QMOLQo/M5NdnfXWf6viZ9pk263Vm2m0hwOoAUK3NxUCBsrvEkFH9YI1AN3+zFYHki0M6UBog8bCDYcth0SUHOgW3pwxyAPiJ9wvMjp6Z7Gzsx+pXPU62/RntGgFYyt/IQVnS9au3DwHL6vc6RIjWASDIBntvOMvsSkAPwBZuuu0HQBuNUwUFPd+LwZ+diFc4kPSxyQ/52H2rx6u0z7bV7ZZvkRyAEddr694BP3IFmXyAE/NHlt8iAv2fjXju1wJ/Cvhq4AzOzDZO58y4mXxClUxObX/4IvqzyU547xqOjnGkf7VvpX2p7bd8eCIJKIpLXAFTfq322jl0feCOee00qC2HYIHfUt408GFgb26n5v0JawVmiOVUgHuDpX6E+GwqEzseLRcnXz3OzDVV+3jtl5UAEKAIOhO40WO+mZifOA5KBEG7DuCJhUADIcDkZPPUJIQDil21/dP4KXYsNs9g46HNgYGrkz1/UucRwHrMo+c527/abwwBdgLoSIAou1bjSNU98jD/81Ct/t7/IyAuRPocAH9F9be2pEM0x+l+tTEag03u11H55Zy2yTZzURUUH2xbBVDmcEfGfOy+yzfrEMBaCrzfTAbsiBwyYcGg/oSEAOu9sKi2oe2fUP3WJQnacN4XbH84lp6VB9xJZoKn25RPPD3yaQ2PAC5zEkfHP9I/03cjAAbgAegHFv9YBMEsPyqsPgcNbNaWgb+bh4QsNLHgjWV9Q4IxZoZFIubxghmWcRWZSVrgj/xwb8Df/VYZMEY/7hVjPBAAgIIqvKHGkfJ3Y0UEsl99+L4AaQcoxLmm593Z4Gfz2pvrw76kg5giBXIiV+EwHDdsEE336/efAaiZszzzuEfHWr7508k7ARXIEMjMGZhKnnkpKGnDxhu2ESWfAX8K0Jn/ZwBmgjn3E7Y/i5uIWDITM3uszFgdYV01cPVEgvZHwXP0dK46fmXc5Zs+nZcBN8BFqn10v7H8V5NMZ7kTVYHBoicBTMkgqaqhC3AaRHiJ9m8TccJZeBM4dUw2wIHrjABVmdjkJ2nDV8eJzuus/VeelzX2RgCDwnuLghxV74CbedQ3Uy5MvBQkUn53P7odreIJUFnzvdueGKdq+b3xLwF2NqE/zRxnweiDNc6VpLD+Uo0AGnjBWg92f6dVur2yNFhA59h4nEfb5+T6fw2MCPxU9ZV8mG3UXKNzn1yjnqIRZtz9RXIpinaIplkiCgd+08D9Bc4ihuUbMQRQkzXrDBAv4UNBcllR+IDK/Ejgb5MZZnVEIJ7V9J4M9EAdEUI7ZqZhVrkzZJawFslTegPvR/gFMiSxEYBW2PX7oPIROWTe+JsIHzoygS/6fDTwjiq/Bv8s8BmJAOfR2x6BxnMW1dDBIyxrTkbnt/VzGqX6PwIgjhxCX0MGXEeO9xh912t4IIAo5nfAj2o0kAaqeDLb341hHNcDf/QEoAvsI8lCA4nW5D/iAE5558ABxR/O/SDCD3a/DCuZ83q/E8HyDZ/mVAF2pCEoKcizdj5DJEIaVfAnlgJXwT/lApxS3wzoM2DLTNSK8mfHE+UvtS/A9apxM6fwlMeW81vJ5WrnsREAA/W2LQHsVMyfGKez/gr8Q1ignEXm8V8PzFXXYIHJUmY2mWbIwPq/EvWEzkzeTJuQNMgg2XEzIJwJb6rjHgp7zjrYI43D3MryX8EBWHZ+VvUtEmGAbseAGUSPWwT/2apvglntOAv0bRwDWRnAXdYmM/BkEvKpgZm8tEeC7nWH6QhgRvVdkColt9rKcT1ioC4gsP0V8LttjUnMwFkBvjXJhu2EFGcBEk3saL8cN5uHmD3PaMpnzzMax9v/GMc4cn5n9N0IANXXBWnmPQCi0Enwb8AO2mbAXwFw1fJXiKQBxLg7FYJAR8aGiyboZfvVwNFxMhN1ZoyZPplzie5hZYzXve3y9RICEBAOZJAEdQnQxpiuG3DWBWA//RnJhu5TdyskFTIDKwBPtU2qfwQGb3/Ut/utEo0TTUxczPSd6ZMF5pVjZ88hanfkHDcCiAC7HSAqFQJthi4icAlU8YMyImPtAcAOmLBtCHzCHikwR6GEvtMnVxQY6ZFD2vMt8TDTjFN5yj5Xgisa29t/BNSV4y5f/6nj04ADABNZfI8kqJor5XcVPwF+D7RybimSgF/PHDNQ5YhAPCC2vkl3EYF6VvlpP7VxZpJW+lTasntbAYLVduYcKse9evzoXJav+9RX6wBkMnUKfgH4U+VFDcTkcmANCAR/SBIF8M+CPOUUCDnijZwB9UyfDlSJmZpo0s3HTPtMm7McRMkNRcgK9s9e18HDDt03AugArx7qMfftQ0XKP+MmvD4U4HguhDi8PpV9mfUGTJFToJdrMGaGNWHO2u46iYCQjgAwC4RsuyxRZoA0c8xo3CvGjI7p3dvla4kD2Dqom06JIOsOEs8A4A9jOZCzwV9yBKpxBtSZNt01JY5h3cwzicA7p84VZGZech1AFhjZdjPneYTIop+iet7ReGed60YAFuBc9T8R/IPiF2N+Rh6RWtM+xEmIw/EmlEckacA6KnsGuL0JaO5LJv2ykztqF+2fBXV23LNApcc5cnyPCM4Yd/kv6ACyoM62q7wSTD+BaDiQlAuYLBNSIBeAGRGBSQbkTlZAf0bb4dySbqQ62TOTNtPGDVkIarJjnkkCR45Z/V1nHMPa5xUBwEQ/TfnhF3DHJC8TYa7gKPhLqg8Hi4Bd3W9ZbDZhzgB3ZYx2bs7szUzsqM3R/Y/pBqJzPZM0HgP4eD0bAaTi/WxeoBDvD6SQIAzG/K1bslJgEUF3o48+XUhi32EiFev8WYKYAjzOPBCDSFkicHj7o75Zlc+MQy4vurS2vzp+9ryvtveZ81i+5lPGMiBT3zRJ7J3Tig9UHvVxHYC6SxmQm22csVwC2q8lcgTbGGRWHQF4tq83KbYxjNkegWAW6NG4mUk84wYyx50Zt3K+FgFUzu2o+9gIIALeVeBHuxmdQxb8VeAP48IAEZCn9zvHsCZQFuDZdvQ4CeWPJudTE0F0fjNOoDLmEQKoHmfmWjRhLF8dOQA1KVygFpKDrwP4B7IwgDkNdOYIDJBlgXt2O7wPenJEE3IG7DN9qhM9Ou8rx5slgMo5zzoT5hY2AjBBfTL48cfZhs6+OhzOvANtArBpR5AA5mEiIHc5GjPrCLLEcIXyW5O3uj07sTNgybTJgjU7Vna8KtEebe/1X/6z5QAmwT+AnL1g9CD4hTzcsMAiDba9mPCLQEv3G2RlTfoMoDNtvEnZ+quBZlR6Buwzx7lCvTMAz7SZIYDsuFlyZCrvnddGAIMDCMDfgbxCFIkKgUcg2q6m1X3/VWj7yTUD7Ec1iSHhLrJEcAT0dLIVKxHRRKwSQQSAq/dH15PdX2030z76LRj4oz7LV2kHQJRqIAgB1GOD31DRChF0bR3lM8GcKO91fYvuwmJr73y8yeQSRlL5zwL1rOJHk/jo/oxyR8e4GtDZ41fPoyeAQhKvVBk4Q/kD8FdIYLvhCTLxQozIAWzDBwCLQB3tj87BnQwTyl8hgkrbzKSNAHD1/gxJZNtkrhfVPLo2rfyV9hsBlMH8RMpfBjn8MpbyZ8asEEEbT/1GFZWOgB/tD13EBcpfBfwVbiCa+FfvrwA7OpfKWLNksZ7D8p8+lFwI9AS2H1U0A1Rp47YlwLTaTwF/7xSB9Oj+I+pfeX15SCYGyWYm5etGAhlQPmabqxwFjrsRgAaO+f0k5ccTcI+dBGuaHJLjReByCSNQ16PAj/qHgIUBKqrN2h7tH6ncFQQRgSoCeLQ/Gj+65gxxasufPSZrt/zHrAN4jcCfBjyG4RPPCZQdgAOuCLgeqUSEFIIeZt0VQD46pjeBryCBCMRX788CNjqPCplYx9wIIHQAB8GfVvwT3gNAgTQBflflme0l7qJCIDMgzwCvtQmcSZpECi82rTiECBTVsWbHi/pl9kdtzgT20bGW/xA5gNcc/K4bOAh8D8DdD3/kPygplhVLoL9Q+TPnESlUFdTV9rPOIgLw0f1HQRv9rjpE8I63EYDpAF5D8LuAP2j5o7GpSkMn/UNXvlfaZtxCa3Oh8lcAWWk7C9yzjpEFmAes2X3ZY2dIKNNm+feWA3hC8FeASNuS9QxZNbeOTfur38i6edkxI2BnVFc7kyPWPnO8yvhntI0m9WOSwBGQRy7g6P4skWwEMDiASfDjzTFdxX5m3f4CYCNyyCzwicZIkQUBv6fiFYWvtDVB9cjKnyWLqrqfBehZsM4CcbZfFrjR+BFRynGWf6cdwCT4GahSJBCAPwJrtx++6GOnQK3icVO5T3p+oAL0qG13fYScvImVAW/p+CoIzYxfPb8qkUSAuIIgZseMzjWzP9NmPb+NABpYXgPwlwAPE02vZjwT8BHJsMn7ZG6AzLoMAM9qU7H5Z6j7GWNkVLd6nCwAFVe2r5HCn7V/+crVAVSeAUALbyjhrPJ7LsIC9NaHKN4lDsBQVtMpOI7CIyg2ebxjzKr/DOgzfSok8NhtI2CeCfQjID3SN7pG3L985cvEOgAE/ZFXfSceCio7AMO1uIShriflFhySqQL2DMKgx0yofwbAnnupALYCpsx5PUaY8H4ILSoAjxzG8hUvi88C7Ee3VB5PjrZJuA02BgVp4EBSwM7E/cn1BBVV90A2tQ86RQCOCCuz/ygRZAF/lETOBLSnypXz9Igssy8igIp7WP7tTgAhcCfVuyOBE8DfLq4A/shVuERhAGsKpBeFBNH/gmRNqogoov2PRQJHj/MYJDBDDkeAPHs8fcxGAJaiVwHMwLZtS4Df7Kst+8HKgQX44fj7hizYz24XKbH8rmjzItAe3R+dU9WmZ53AB5UEZoE8228ggH+TdQAFADMgpQhGAZ0SAlHkSOGj/VZ4MRNCZPvMtuv6JQgqA9gqKWTBmAV3tl32uGcpvgWy6vZZpT8L5CgQlAA85a2qtwZ6RflDB5AEfwT4aL+21Fb7LIhn+kfAzfzHIhVgR22j8zmq/BVQZc61SgKV41fH9n6bWXI4q9/y5SoJiAMfBb9Xm7ccwXB8cQVE7QayIW8groI0s5KwOmYEHm9Cm/suUP+MEp/V5oiaV8B6VdsZEphR9Jk+FXLYCMAE0oTtb2OpCZoBq+kAjLFMsgDP4x33TOsfugohMnJuEUEM56lmRaSIV+/PnP8RwGfHrxzjyrZnksPlBPBlRhlwxrpnwW8CnWXJC0RymBCS5b4zwV5Wf+hwBNhH+lqW9rHdwVF1P9r/dQZ6ljiWlQC0SjIbPLRRilYFv0cC7Yc9WOrLAFWf94y9n+ljnZurdie8YnzquMS9PAUJHAVshqCs63oMsFeuzzvPaB8eZ/lS7QCU4jJVNckgUGurH1XuiVJfilSYFTdUtUIgR0nA67/tU7OjouBll2GEKVnQZ4EWXUPFps8es3KM15EEskoPt3T7KP02AojUO0UCk+CnoCWAzII7Au2w3yG8o6COzoUBioKCnKPrFBjJqRlQcQLVY2WJIjNuBaCvIwlUVX0G0NVjdATwMXEAAYBdEnhC8Ecgc/efGPNH5xFNdhOQRdt/ptpHCh3tj675CFE8JTFUjv2UriFz7GUlgOp/DNKRwUHwdxPfUeMjDoCCq5BfOOoEZvpr2x+BLavolXEyAM6obnTMzHEqoMuc09HxKv2rbTPAVYZO/ydUbXfkKP4/BnecprBuissAAAAASUVORK5CYII=",t}();e.TextureTools=t}(s||(s={}));!function(e){var t=function(){function t(){this._mode=t.FitFrustumSidesMode,this._radiusScale=1,this._positionScale=.5,this._defaultElevation=.3,this._elevationReturnTime=1500,this._elevationReturnWaitTime=1e3,this._zoomStopsAnimation=!1,this._framingTime=1500,this._isPointerDown=!1,this._lastInteractionTime=-1/0,this._animatables=new Array,this._betaIsAnimating=!1}return Object.defineProperty(t.prototype,"name",{get:function(){return"Framing"},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"mode",{get:function(){return this._mode},set:function(e){this._mode=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"radiusScale",{get:function(){return this._radiusScale},set:function(e){this._radiusScale=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"positionScale",{get:function(){return this._positionScale},set:function(e){this._positionScale=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"defaultElevation",{get:function(){return this._defaultElevation},set:function(e){this._defaultElevation=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"elevationReturnTime",{get:function(){return this._elevationReturnTime},set:function(e){this._elevationReturnTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"elevationReturnWaitTime",{get:function(){return this._elevationReturnWaitTime},set:function(e){this._elevationReturnWaitTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"zoomStopsAnimation",{get:function(){return this._zoomStopsAnimation},set:function(e){this._zoomStopsAnimation=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"framingTime",{get:function(){return this._framingTime},set:function(e){this._framingTime=e},enumerable:!0,configurable:!0}),t.prototype.init=function(){},t.prototype.attach=function(i){var r=this;this._attachedCamera=i;var n=this._attachedCamera.getScene();t.EasingFunction.setEasingMode(t.EasingMode),this._onPrePointerObservableObserver=n.onPrePointerObservable.add(function(t){t.type!==e.PointerEventTypes.POINTERDOWN?t.type===e.PointerEventTypes.POINTERUP&&(r._isPointerDown=!1):r._isPointerDown=!0}),this._onMeshTargetChangedObserver=i.onMeshTargetChangedObservable.add(function(e){e&&r.zoomOnMesh(e)}),this._onAfterCheckInputsObserver=i.onAfterCheckInputsObservable.add(function(){r._applyUserInteraction(),r._maintainCameraAboveGround()})},t.prototype.detach=function(){if(this._attachedCamera){var e=this._attachedCamera.getScene();this._onPrePointerObservableObserver&&e.onPrePointerObservable.remove(this._onPrePointerObservableObserver),this._onAfterCheckInputsObserver&&this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver),this._onMeshTargetChangedObserver&&this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver),this._attachedCamera=null}},t.prototype.zoomOnMesh=function(e,t,i){void 0===t&&(t=!1),void 0===i&&(i=null),e.computeWorldMatrix(!0);var r=e.getBoundingInfo().boundingBox;this.zoomOnBoundingInfo(r.minimumWorld,r.maximumWorld,t,i)},t.prototype.zoomOnBoundingInfo=function(i,r,n,o){var s=this;void 0===n&&(n=!1),void 0===o&&(o=null);var a;if(this._attachedCamera){var l=i.y,h=l+(r.y-l)*this._positionScale,u=r.subtract(i).scale(.5);if(n)a=new e.Vector3(0,h,0);else{var c=i.add(u);a=new e.Vector3(c.x,h,c.z)}this._vectorTransition||(this._vectorTransition=e.Animation.CreateAnimation("target",e.Animation.ANIMATIONTYPE_VECTOR3,60,t.EasingFunction)),this._betaIsAnimating=!0;var f=e.Animation.TransitionTo("target",a,this._attachedCamera,this._attachedCamera.getScene(),60,this._vectorTransition,this._framingTime);f&&this._animatables.push(f);var p=0;if(this._mode===t.FitFrustumSidesMode){var d=this._calculateLowerRadiusFromModelBoundingSphere(i,r);this._attachedCamera.lowerRadiusLimit=u.length()+this._attachedCamera.minZ,p=d}else this._mode===t.IgnoreBoundsSizeMode&&(p=this._calculateLowerRadiusFromModelBoundingSphere(i,r),null===this._attachedCamera.lowerRadiusLimit&&(this._attachedCamera.lowerRadiusLimit=this._attachedCamera.minZ));var m=r.subtract(i).length();this._attachedCamera.panningSensibility=5e3/m,this._attachedCamera.wheelPrecision=100/p,this._radiusTransition||(this._radiusTransition=e.Animation.CreateAnimation("radius",e.Animation.ANIMATIONTYPE_FLOAT,60,t.EasingFunction)),(f=e.Animation.TransitionTo("radius",p,this._attachedCamera,this._attachedCamera.getScene(),60,this._radiusTransition,this._framingTime,function(){o&&o(),s._attachedCamera&&s._attachedCamera.storeState()}))&&this._animatables.push(f)}},t.prototype._calculateLowerRadiusFromModelBoundingSphere=function(e,i){var r=i.subtract(e).length(),n=this._getFrustumSlope(),o=.5*r*this._radiusScale,s=o*Math.sqrt(1+1/(n.x*n.x)),a=o*Math.sqrt(1+1/(n.y*n.y)),l=Math.max(s,a),h=this._attachedCamera;return h?(h.lowerRadiusLimit&&this._mode===t.IgnoreBoundsSizeMode&&(l=l<h.lowerRadiusLimit?h.lowerRadiusLimit:l),h.upperRadiusLimit&&(l=l>h.upperRadiusLimit?h.upperRadiusLimit:l),l):0},t.prototype._maintainCameraAboveGround=function(){var i=this;if(!(this._elevationReturnTime<0)){var r=e.Tools.Now-this._lastInteractionTime,n=.5*Math.PI-this._defaultElevation,o=.5*Math.PI;if(this._attachedCamera&&!this._betaIsAnimating&&this._attachedCamera.beta>o&&r>=this._elevationReturnWaitTime){this._betaIsAnimating=!0,this.stopAllAnimations(),this._betaTransition||(this._betaTransition=e.Animation.CreateAnimation("beta",e.Animation.ANIMATIONTYPE_FLOAT,60,t.EasingFunction));var s=e.Animation.TransitionTo("beta",n,this._attachedCamera,this._attachedCamera.getScene(),60,this._betaTransition,this._elevationReturnTime,function(){i._clearAnimationLocks(),i.stopAllAnimations()});s&&this._animatables.push(s)}}},t.prototype._getFrustumSlope=function(){var t=this._attachedCamera;if(!t)return e.Vector2.Zero();var i=t.getScene().getEngine().getAspectRatio(t),r=Math.tan(t.fov/2),n=r*i;return new e.Vector2(n,r)},t.prototype._clearAnimationLocks=function(){this._betaIsAnimating=!1},t.prototype._applyUserInteraction=function(){this.isUserIsMoving&&(this._lastInteractionTime=e.Tools.Now,this.stopAllAnimations(),this._clearAnimationLocks())},t.prototype.stopAllAnimations=function(){for(this._attachedCamera&&(this._attachedCamera.animations=[]);this._animatables.length;)this._animatables[0]&&(this._animatables[0].onAnimationEnd=null,this._animatables[0].stop()),this._animatables.shift()},Object.defineProperty(t.prototype,"isUserIsMoving",{get:function(){return!!this._attachedCamera&&(0!==this._attachedCamera.inertialAlphaOffset||0!==this._attachedCamera.inertialBetaOffset||0!==this._attachedCamera.inertialRadiusOffset||0!==this._attachedCamera.inertialPanningX||0!==this._attachedCamera.inertialPanningY||this._isPointerDown)},enumerable:!0,configurable:!0}),t.EasingFunction=new e.ExponentialEase,t.EasingMode=e.EasingFunction.EASINGMODE_EASEINOUT,t.IgnoreBoundsSizeMode=0,t.FitFrustumSidesMode=1,t}();e.FramingBehavior=t}(s||(s={}));!function(e){var t=function(){function t(){this.transitionDuration=450,this.lowerRadiusTransitionRange=2,this.upperRadiusTransitionRange=-2,this._autoTransitionRange=!1,this._radiusIsAnimating=!1,this._radiusBounceTransition=null,this._animatables=new Array}return Object.defineProperty(t.prototype,"name",{get:function(){return"Bouncing"},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"autoTransitionRange",{get:function(){return this._autoTransitionRange},set:function(e){var t=this;if(this._autoTransitionRange!==e){this._autoTransitionRange=e;var i=this._attachedCamera;i&&(e?this._onMeshTargetChangedObserver=i.onMeshTargetChangedObservable.add(function(e){if(e){e.computeWorldMatrix(!0);var i=e.getBoundingInfo().diagonalLength;t.lowerRadiusTransitionRange=.05*i,t.upperRadiusTransitionRange=.05*i}}):this._onMeshTargetChangedObserver&&i.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver))}},enumerable:!0,configurable:!0}),t.prototype.init=function(){},t.prototype.attach=function(e){var t=this;this._attachedCamera=e,this._onAfterCheckInputsObserver=e.onAfterCheckInputsObservable.add(function(){t._attachedCamera&&(t._isRadiusAtLimit(t._attachedCamera.lowerRadiusLimit)&&t._applyBoundRadiusAnimation(t.lowerRadiusTransitionRange),t._isRadiusAtLimit(t._attachedCamera.upperRadiusLimit)&&t._applyBoundRadiusAnimation(t.upperRadiusTransitionRange))})},t.prototype.detach=function(){this._attachedCamera&&(this._onAfterCheckInputsObserver&&this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver),this._onMeshTargetChangedObserver&&this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver),this._attachedCamera=null)},t.prototype._isRadiusAtLimit=function(e){return!!this._attachedCamera&&(this._attachedCamera.radius===e&&!this._radiusIsAnimating)},t.prototype._applyBoundRadiusAnimation=function(i){var r=this;if(this._attachedCamera){this._radiusBounceTransition||(t.EasingFunction.setEasingMode(t.EasingMode),this._radiusBounceTransition=e.Animation.CreateAnimation("radius",e.Animation.ANIMATIONTYPE_FLOAT,60,t.EasingFunction)),this._cachedWheelPrecision=this._attachedCamera.wheelPrecision,this._attachedCamera.wheelPrecision=1/0,this._attachedCamera.inertialRadiusOffset=0,this.stopAllAnimations(),this._radiusIsAnimating=!0;var n=e.Animation.TransitionTo("radius",this._attachedCamera.radius+i,this._attachedCamera,this._attachedCamera.getScene(),60,this._radiusBounceTransition,this.transitionDuration,function(){return r._clearAnimationLocks()});n&&this._animatables.push(n)}},t.prototype._clearAnimationLocks=function(){this._radiusIsAnimating=!1,this._attachedCamera&&(this._attachedCamera.wheelPrecision=this._cachedWheelPrecision)},t.prototype.stopAllAnimations=function(){for(this._attachedCamera&&(this._attachedCamera.animations=[]);this._animatables.length;)this._animatables[0].onAnimationEnd=null,this._animatables[0].stop(),this._animatables.shift()},t.EasingFunction=new e.BackEase(.3),t.EasingMode=e.EasingFunction.EASINGMODE_EASEOUT,t}();e.BouncingBehavior=t}(s||(s={}));!function(e){var t=function(){function t(){this._zoomStopsAnimation=!1,this._idleRotationSpeed=.05,this._idleRotationWaitTime=2e3,this._idleRotationSpinupTime=2e3,this._isPointerDown=!1,this._lastFrameTime=null,this._lastInteractionTime=-1/0,this._cameraRotationSpeed=0,this._lastFrameRadius=0}return Object.defineProperty(t.prototype,"name",{get:function(){return"AutoRotation"},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"zoomStopsAnimation",{get:function(){return this._zoomStopsAnimation},set:function(e){this._zoomStopsAnimation=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"idleRotationSpeed",{get:function(){return this._idleRotationSpeed},set:function(e){this._idleRotationSpeed=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"idleRotationWaitTime",{get:function(){return this._idleRotationWaitTime},set:function(e){this._idleRotationWaitTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"idleRotationSpinupTime",{get:function(){return this._idleRotationSpinupTime},set:function(e){this._idleRotationSpinupTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationInProgress",{get:function(){return Math.abs(this._cameraRotationSpeed)>0},enumerable:!0,configurable:!0}),t.prototype.init=function(){},t.prototype.attach=function(t){var i=this;this._attachedCamera=t;var r=this._attachedCamera.getScene();this._onPrePointerObservableObserver=r.onPrePointerObservable.add(function(t){t.type!==e.PointerEventTypes.POINTERDOWN?t.type===e.PointerEventTypes.POINTERUP&&(i._isPointerDown=!1):i._isPointerDown=!0}),this._onAfterCheckInputsObserver=t.onAfterCheckInputsObservable.add(function(){var t=e.Tools.Now,r=0;null!=i._lastFrameTime&&(r=t-i._lastFrameTime),i._lastFrameTime=t,i._applyUserInteraction();var n=t-i._lastInteractionTime-i._idleRotationWaitTime,o=Math.max(Math.min(n/i._idleRotationSpinupTime,1),0);i._cameraRotationSpeed=i._idleRotationSpeed*o,i._attachedCamera&&(i._attachedCamera.alpha-=i._cameraRotationSpeed*(r/1e3))})},t.prototype.detach=function(){if(this._attachedCamera){var e=this._attachedCamera.getScene();this._onPrePointerObservableObserver&&e.onPrePointerObservable.remove(this._onPrePointerObservableObserver),this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver),this._attachedCamera=null}},t.prototype._userIsZooming=function(){return!!this._attachedCamera&&0!==this._attachedCamera.inertialRadiusOffset},t.prototype._shouldAnimationStopForInteraction=function(){if(!this._attachedCamera)return!1;var e=!1;return this._lastFrameRadius===this._attachedCamera.radius&&0!==this._attachedCamera.inertialRadiusOffset&&(e=!0),this._lastFrameRadius=this._attachedCamera.radius,this._zoomStopsAnimation?e:this._userIsZooming()},t.prototype._applyUserInteraction=function(){this._userIsMoving()&&!this._shouldAnimationStopForInteraction()&&(this._lastInteractionTime=e.Tools.Now)},t.prototype._userIsMoving=function(){return!!this._attachedCamera&&(0!==this._attachedCamera.inertialAlphaOffset||0!==this._attachedCamera.inertialBetaOffset||0!==this._attachedCamera.inertialRadiusOffset||0!==this._attachedCamera.inertialPanningX||0!==this._attachedCamera.inertialPanningY||this._isPointerDown)},t}();e.AutoRotationBehavior=t}(s||(s={}));!function(e){var t=function(){return function(){this.renderWidth=512,this.renderHeight=256,this.textureSize=512}}();e.NullEngineOptions=t;var i=function(i){function r(r){void 0===r&&(r=new t);var n=i.call(this,null)||this;return n._options=r,n._caps=new e.EngineCapabilities,n._caps.maxTexturesImageUnits=16,n._caps.maxVertexTextureImageUnits=16,n._caps.maxTextureSize=512,n._caps.maxCubemapTextureSize=512,n._caps.maxRenderTextureSize=512,n._caps.maxVertexAttribs=16,n._caps.maxVaryingVectors=16,n._caps.maxFragmentUniformVectors=16,n._caps.maxVertexUniformVectors=16,n._caps.standardDerivatives=!1,n._caps.astc=null,n._caps.s3tc=null,n._caps.pvrtc=null,n._caps.etc1=null,n._caps.etc2=null,n._caps.textureAnisotropicFilterExtension=null,n._caps.maxAnisotropy=0,n._caps.uintIndices=!1,n._caps.fragmentDepthSupported=!1,n._caps.highPrecisionShaderSupported=!0,n._caps.colorBufferFloat=!1,n._caps.textureFloat=!1,n._caps.textureFloatLinearFiltering=!1,n._caps.textureFloatRender=!1,n._caps.textureHalfFloat=!1,n._caps.textureHalfFloatLinearFiltering=!1,n._caps.textureHalfFloatRender=!1,n._caps.textureLOD=!1,n._caps.drawBuffersExtension=!1,n._caps.depthTextureExtension=!1,n._caps.vertexArrayObject=!1,n._caps.instancedArrays=!1,e.Tools.Log("Babylon.js null engine (v"+e.Engine.Version+") launched"),"undefined"==typeof URL&&(URL={createObjectURL:function(){},revokeObjectURL:function(){}}),"undefined"==typeof Blob&&(Blob=function(){}),n}return n(r,i),r.prototype.createVertexBuffer=function(e){return{capacity:0,references:1,is32Bits:!1}},r.prototype.createIndexBuffer=function(e){return{capacity:0,references:1,is32Bits:!1}},r.prototype.clear=function(e,t,i,r){void 0===r&&(r=!1)},r.prototype.getRenderWidth=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget.width:this._options.renderWidth},r.prototype.getRenderHeight=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget.height:this._options.renderHeight},r.prototype.setViewport=function(e,t,i){this._cachedViewport=e},r.prototype.createShaderProgram=function(e,t,i,r){return{transformFeedback:null,__SPECTOR_rebuildProgram:null}},r.prototype.getUniforms=function(e,t){return[]},r.prototype.getAttributes=function(e,t){return[]},r.prototype.bindSamplers=function(e){this._currentEffect=null},r.prototype.enableEffect=function(e){this._currentEffect=e,e.onBind&&e.onBind(e),e.onBindObservable.notifyObservers(e)},r.prototype.setState=function(e,t,i,r){void 0===t&&(t=0),void 0===r&&(r=!1)},r.prototype.setIntArray=function(e,t){},r.prototype.setIntArray2=function(e,t){},r.prototype.setIntArray3=function(e,t){},r.prototype.setIntArray4=function(e,t){},r.prototype.setFloatArray=function(e,t){},r.prototype.setFloatArray2=function(e,t){},r.prototype.setFloatArray3=function(e,t){},r.prototype.setFloatArray4=function(e,t){},r.prototype.setArray=function(e,t){},r.prototype.setArray2=function(e,t){},r.prototype.setArray3=function(e,t){},r.prototype.setArray4=function(e,t){},r.prototype.setMatrices=function(e,t){},r.prototype.setMatrix=function(e,t){},r.prototype.setMatrix3x3=function(e,t){},r.prototype.setMatrix2x2=function(e,t){},r.prototype.setFloat=function(e,t){},r.prototype.setFloat2=function(e,t,i){},r.prototype.setFloat3=function(e,t,i,r){},r.prototype.setBool=function(e,t){},r.prototype.setFloat4=function(e,t,i,r,n){},r.prototype.setColor3=function(e,t){},r.prototype.setColor4=function(e,t,i){},r.prototype.setAlphaMode=function(t,i){void 0===i&&(i=!1),this._alphaMode!==t&&(this._alphaState.alphaBlend=t!==e.Engine.ALPHA_DISABLE,i||this.setDepthWrite(t===e.Engine.ALPHA_DISABLE),this._alphaMode=t)},r.prototype.bindBuffers=function(e,t,i){},r.prototype.wipeCaches=function(e){this.preventCacheWipeBetweenFrames||(this.resetTextureCache(),this._currentEffect=null,e&&(this._currentProgram=null,this._stencilState.reset(),this._depthCullingState.reset(),this.setDepthFunctionToLessOrEqual(),this._alphaState.reset()),this._cachedVertexBuffers=null,this._cachedIndexBuffer=null,this._cachedEffectForVertexBuffers=null)},r.prototype.draw=function(e,t,i,r){},r.prototype._createTexture=function(){return{}},r.prototype.createTexture=function(t,i,r,n,o,s,a,l,h,u){void 0===o&&(o=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===s&&(s=null),void 0===a&&(a=null),void 0===l&&(l=null);var c=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_URL),f=String(t);return c.url=f,c.generateMipMaps=!i,c.samplingMode=o,c.invertY=r,c.baseWidth=this._options.textureSize,c.baseHeight=this._options.textureSize,c.width=this._options.textureSize,c.height=this._options.textureSize,u&&(c.format=u),c.isReady=!0,s&&s(),c},r.prototype.createRenderTargetTexture=function(t,i){var r=new e.RenderTargetCreationOptions;void 0!==i&&"object"==typeof i?(r.generateMipMaps=i.generateMipMaps,r.generateDepthBuffer=void 0===i.generateDepthBuffer||i.generateDepthBuffer,r.generateStencilBuffer=r.generateDepthBuffer&&i.generateStencilBuffer,r.type=void 0===i.type?e.Engine.TEXTURETYPE_UNSIGNED_INT:i.type,r.samplingMode=void 0===i.samplingMode?e.Texture.TRILINEAR_SAMPLINGMODE:i.samplingMode):(r.generateMipMaps=i,r.generateDepthBuffer=!0,r.generateStencilBuffer=!1,r.type=e.Engine.TEXTURETYPE_UNSIGNED_INT,r.samplingMode=e.Texture.TRILINEAR_SAMPLINGMODE);var n=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RENDERTARGET),o=t.width||t,s=t.height||t;return n._depthStencilBuffer={},n._framebuffer={},n.baseWidth=o,n.baseHeight=s,n.width=o,n.height=s,n.isReady=!0,n.samples=1,n.generateMipMaps=!!r.generateMipMaps,n.samplingMode=r.samplingMode,n.type=r.type,n._generateDepthBuffer=r.generateDepthBuffer,n._generateStencilBuffer=!!r.generateStencilBuffer,n},r.prototype.updateTextureSamplingMode=function(e,t){t.samplingMode=e},r.prototype.bindFramebuffer=function(e,t,i,r,n){this._currentRenderTarget&&this.unBindFramebuffer(this._currentRenderTarget),this._currentRenderTarget=e,this._currentFramebuffer=e._MSAAFramebuffer?e._MSAAFramebuffer:e._framebuffer,this._cachedViewport&&!n&&this.setViewport(this._cachedViewport,i,r)},r.prototype.unBindFramebuffer=function(e,t,i){void 0===t&&(t=!1),this._currentRenderTarget=null,i&&(e._MSAAFramebuffer&&(this._currentFramebuffer=e._framebuffer),i()),this._currentFramebuffer=null},r.prototype.createDynamicVertexBuffer=function(e){return{capacity:1,references:1,is32Bits:!1}},r.prototype.updateDynamicIndexBuffer=function(e,t,i){void 0===i&&(i=0)},r.prototype.updateDynamicVertexBuffer=function(e,t,i,r){},r.prototype._bindTextureDirectly=function(e,t){this._activeTexturesCache[this._activeTextureChannel]!==t&&(this._activeTexturesCache[this._activeTextureChannel]=t)},r.prototype._bindTexture=function(e,t){e<0||this._bindTextureDirectly(0,t)},r.prototype._releaseBuffer=function(e){return e.references--,0===e.references},r}(e.Engine);e.NullEngine=i}(s||(s={}));!function(e){var t=function(){function t(t){this.engine=t,this._captureGPUFrameTime=!1,this._gpuFrameTime=new e.PerfCounter,this._captureShaderCompilationTime=!1,this._shaderCompilationTime=new e.PerfCounter,this._onBeginFrameObserver=null,this._onEndFrameObserver=null,this._onBeforeShaderCompilationObserver=null,this._onAfterShaderCompilationObserver=null}return Object.defineProperty(t.prototype,"gpuFrameTimeCounter",{get:function(){return this._gpuFrameTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureGPUFrameTime",{get:function(){return this._captureGPUFrameTime},set:function(e){var t=this;e!==this._captureGPUFrameTime&&(this._captureGPUFrameTime=e,e?(this._onBeginFrameObserver=this.engine.onBeginFrameObservable.add(function(){t._gpuFrameTimeToken||(t._gpuFrameTimeToken=t.engine.startTimeQuery())}),this._onEndFrameObserver=this.engine.onEndFrameObservable.add(function(){if(t._gpuFrameTimeToken){var e=t.engine.endTimeQuery(t._gpuFrameTimeToken);e>-1&&(t._gpuFrameTimeToken=null,t._gpuFrameTime.fetchNewFrame(),t._gpuFrameTime.addCount(e,!0))}})):(this.engine.onBeginFrameObservable.remove(this._onBeginFrameObserver),this._onBeginFrameObserver=null,this.engine.onEndFrameObservable.remove(this._onEndFrameObserver),this._onEndFrameObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shaderCompilationTimeCounter",{get:function(){return this._shaderCompilationTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureShaderCompilationTime",{get:function(){return this._captureShaderCompilationTime},set:function(e){var t=this;e!==this._captureShaderCompilationTime&&(this._captureShaderCompilationTime=e,e?(this._onBeforeShaderCompilationObserver=this.engine.onBeforeShaderCompilationObservable.add(function(){t._shaderCompilationTime.fetchNewFrame(),t._shaderCompilationTime.beginMonitoring()}),this._onAfterShaderCompilationObserver=this.engine.onAfterShaderCompilationObservable.add(function(){t._shaderCompilationTime.endMonitoring()})):(this.engine.onBeforeShaderCompilationObservable.remove(this._onBeforeShaderCompilationObserver),this._onBeforeShaderCompilationObserver=null,this.engine.onAfterShaderCompilationObservable.remove(this._onAfterShaderCompilationObserver),this._onAfterShaderCompilationObserver=null))},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){this.engine.onBeginFrameObservable.remove(this._onBeginFrameObserver),this._onBeginFrameObserver=null,this.engine.onEndFrameObservable.remove(this._onEndFrameObserver),this._onEndFrameObserver=null,this.engine.onBeforeShaderCompilationObservable.remove(this._onBeforeShaderCompilationObserver),this._onBeforeShaderCompilationObserver=null,this.engine.onAfterShaderCompilationObservable.remove(this._onAfterShaderCompilationObserver),this._onAfterShaderCompilationObserver=null,this.engine=null},t}();e.EngineInstrumentation=t}(s||(s={}));!function(e){var t=function(){function t(t){var i=this;this.scene=t,this._captureActiveMeshesEvaluationTime=!1,this._activeMeshesEvaluationTime=new e.PerfCounter,this._captureRenderTargetsRenderTime=!1,this._renderTargetsRenderTime=new e.PerfCounter,this._captureFrameTime=!1,this._frameTime=new e.PerfCounter,this._captureRenderTime=!1,this._renderTime=new e.PerfCounter,this._captureInterFrameTime=!1,this._interFrameTime=new e.PerfCounter,this._captureParticlesRenderTime=!1,this._particlesRenderTime=new e.PerfCounter,this._captureSpritesRenderTime=!1,this._spritesRenderTime=new e.PerfCounter,this._capturePhysicsTime=!1,this._physicsTime=new e.PerfCounter,this._captureAnimationsTime=!1,this._animationsTime=new e.PerfCounter,this._onBeforeActiveMeshesEvaluationObserver=null,this._onAfterActiveMeshesEvaluationObserver=null,this._onBeforeRenderTargetsRenderObserver=null,this._onAfterRenderTargetsRenderObserver=null,this._onAfterRenderObserver=null,this._onBeforeDrawPhaseObserver=null,this._onAfterDrawPhaseObserver=null,this._onBeforeAnimationsObserver=null,this._onBeforeParticlesRenderingObserver=null,this._onAfterParticlesRenderingObserver=null,this._onBeforeSpritesRenderingObserver=null,this._onAfterSpritesRenderingObserver=null,this._onBeforePhysicsObserver=null,this._onAfterPhysicsObserver=null,this._onAfterAnimationsObserver=null,this._onBeforeAnimationsObserver=t.onBeforeAnimationsObservable.add(function(){i._captureActiveMeshesEvaluationTime&&i._activeMeshesEvaluationTime.fetchNewFrame(),i._captureRenderTargetsRenderTime&&i._renderTargetsRenderTime.fetchNewFrame(),i._captureFrameTime&&(e.Tools.StartPerformanceCounter("Scene rendering"),i._frameTime.beginMonitoring()),i._captureInterFrameTime&&i._interFrameTime.endMonitoring(),i._captureParticlesRenderTime&&i._particlesRenderTime.fetchNewFrame(),i._captureSpritesRenderTime&&i._spritesRenderTime.fetchNewFrame(),i._captureAnimationsTime&&i._animationsTime.beginMonitoring(),i.scene.getEngine()._drawCalls.fetchNewFrame()}),this._onAfterRenderObserver=t.onAfterRenderObservable.add(function(){i._captureFrameTime&&(e.Tools.EndPerformanceCounter("Scene rendering"),i._frameTime.endMonitoring()),i._captureRenderTime&&i._renderTime.endMonitoring(!1),i._captureInterFrameTime&&i._interFrameTime.beginMonitoring()})}return Object.defineProperty(t.prototype,"activeMeshesEvaluationTimeCounter",{get:function(){return this._activeMeshesEvaluationTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureActiveMeshesEvaluationTime",{get:function(){return this._captureActiveMeshesEvaluationTime},set:function(t){var i=this;t!==this._captureActiveMeshesEvaluationTime&&(this._captureActiveMeshesEvaluationTime=t,t?(this._onBeforeActiveMeshesEvaluationObserver=this.scene.onBeforeActiveMeshesEvaluationObservable.add(function(){e.Tools.StartPerformanceCounter("Active meshes evaluation"),i._activeMeshesEvaluationTime.beginMonitoring()}),this._onAfterActiveMeshesEvaluationObserver=this.scene.onAfterActiveMeshesEvaluationObservable.add(function(){e.Tools.EndPerformanceCounter("Active meshes evaluation"),i._activeMeshesEvaluationTime.endMonitoring()})):(this.scene.onBeforeActiveMeshesEvaluationObservable.remove(this._onBeforeActiveMeshesEvaluationObserver),this._onBeforeActiveMeshesEvaluationObserver=null,this.scene.onAfterActiveMeshesEvaluationObservable.remove(this._onAfterActiveMeshesEvaluationObserver),this._onAfterActiveMeshesEvaluationObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"renderTargetsRenderTimeCounter",{get:function(){return this._renderTargetsRenderTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureRenderTargetsRenderTime",{get:function(){return this._captureRenderTargetsRenderTime},set:function(t){var i=this;t!==this._captureRenderTargetsRenderTime&&(this._captureRenderTargetsRenderTime=t,t?(this._onBeforeRenderTargetsRenderObserver=this.scene.OnBeforeRenderTargetsRenderObservable.add(function(){e.Tools.StartPerformanceCounter("Render targets rendering"),i._renderTargetsRenderTime.beginMonitoring()}),this._onAfterRenderTargetsRenderObserver=this.scene.OnAfterRenderTargetsRenderObservable.add(function(){e.Tools.EndPerformanceCounter("Render targets rendering"),i._renderTargetsRenderTime.endMonitoring(!1)})):(this.scene.OnBeforeRenderTargetsRenderObservable.remove(this._onBeforeRenderTargetsRenderObserver),this._onBeforeRenderTargetsRenderObserver=null,this.scene.OnAfterRenderTargetsRenderObservable.remove(this._onAfterRenderTargetsRenderObserver),this._onAfterRenderTargetsRenderObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"particlesRenderTimeCounter",{get:function(){return this._particlesRenderTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureParticlesRenderTime",{get:function(){return this._captureParticlesRenderTime},set:function(t){var i=this;t!==this._captureParticlesRenderTime&&(this._captureParticlesRenderTime=t,t?(this._onBeforeParticlesRenderingObserver=this.scene.onBeforeParticlesRenderingObservable.add(function(){e.Tools.StartPerformanceCounter("Particles"),i._particlesRenderTime.beginMonitoring()}),this._onAfterParticlesRenderingObserver=this.scene.onAfterParticlesRenderingObservable.add(function(){e.Tools.EndPerformanceCounter("Particles"),i._particlesRenderTime.endMonitoring(!1)})):(this.scene.onBeforeParticlesRenderingObservable.remove(this._onBeforeParticlesRenderingObserver),this._onBeforeParticlesRenderingObserver=null,this.scene.onAfterParticlesRenderingObservable.remove(this._onAfterParticlesRenderingObserver),this._onAfterParticlesRenderingObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"spritesRenderTimeCounter",{get:function(){return this._spritesRenderTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureSpritesRenderTime",{get:function(){return this._captureSpritesRenderTime},set:function(t){var i=this;t!==this._captureSpritesRenderTime&&(this._captureSpritesRenderTime=t,t?(this._onBeforeSpritesRenderingObserver=this.scene.onBeforeSpritesRenderingObservable.add(function(){e.Tools.StartPerformanceCounter("Sprites"),i._spritesRenderTime.beginMonitoring()}),this._onAfterSpritesRenderingObserver=this.scene.onAfterSpritesRenderingObservable.add(function(){e.Tools.EndPerformanceCounter("Sprites"),i._spritesRenderTime.endMonitoring(!1)})):(this.scene.onBeforeSpritesRenderingObservable.remove(this._onBeforeSpritesRenderingObserver),this._onBeforeSpritesRenderingObserver=null,this.scene.onAfterSpritesRenderingObservable.remove(this._onAfterSpritesRenderingObserver),this._onAfterSpritesRenderingObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"physicsTimeCounter",{get:function(){return this._physicsTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"capturePhysicsTime",{get:function(){return this._capturePhysicsTime},set:function(t){var i=this;t!==this._capturePhysicsTime&&(this._capturePhysicsTime=t,t?(this._onBeforePhysicsObserver=this.scene.onBeforePhysicsObservable.add(function(){e.Tools.StartPerformanceCounter("Physics"),i._physicsTime.beginMonitoring()}),this._onAfterPhysicsObserver=this.scene.onAfterPhysicsObservable.add(function(){e.Tools.EndPerformanceCounter("Physics"),i._physicsTime.endMonitoring()})):(this.scene.onBeforePhysicsObservable.remove(this._onBeforePhysicsObserver),this._onBeforePhysicsObserver=null,this.scene.onAfterPhysicsObservable.remove(this._onAfterPhysicsObserver),this._onAfterPhysicsObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"animationsTimeCounter",{get:function(){return this._animationsTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureAnimationsTime",{get:function(){return this._captureAnimationsTime},set:function(e){var t=this;e!==this._captureAnimationsTime&&(this._captureAnimationsTime=e,e?this._onAfterAnimationsObserver=this.scene.onAfterAnimationsObservable.add(function(){t._animationsTime.endMonitoring()}):(this.scene.onAfterAnimationsObservable.remove(this._onAfterAnimationsObserver),this._onAfterAnimationsObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"frameTimeCounter",{get:function(){return this._frameTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureFrameTime",{get:function(){return this._captureFrameTime},set:function(e){this._captureFrameTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"interFrameTimeCounter",{get:function(){return this._interFrameTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureInterFrameTime",{get:function(){return this._captureInterFrameTime},set:function(e){this._captureInterFrameTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"renderTimeCounter",{get:function(){return this._renderTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureRenderTime",{get:function(){return this._captureRenderTime},set:function(t){var i=this;t!==this._captureRenderTime&&(this._captureRenderTime=t,t?(this._onBeforeDrawPhaseObserver=this.scene.onBeforeDrawPhaseObservable.add(function(){i._renderTime.beginMonitoring(),e.Tools.StartPerformanceCounter("Main render")}),this._onAfterDrawPhaseObserver=this.scene.onAfterDrawPhaseObservable.add(function(){i._renderTime.endMonitoring(!1),e.Tools.EndPerformanceCounter("Main render")})):(this.scene.onBeforeDrawPhaseObservable.remove(this._onBeforeDrawPhaseObserver),this._onBeforeDrawPhaseObserver=null,this.scene.onAfterDrawPhaseObservable.remove(this._onAfterDrawPhaseObserver),this._onAfterDrawPhaseObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"drawCallsCounter",{get:function(){return this.scene.getEngine()._drawCalls},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){this.scene.onAfterRenderObservable.remove(this._onAfterRenderObserver),this._onAfterRenderObserver=null,this.scene.onBeforeActiveMeshesEvaluationObservable.remove(this._onBeforeActiveMeshesEvaluationObserver),this._onBeforeActiveMeshesEvaluationObserver=null,this.scene.onAfterActiveMeshesEvaluationObservable.remove(this._onAfterActiveMeshesEvaluationObserver),this._onAfterActiveMeshesEvaluationObserver=null,this.scene.OnBeforeRenderTargetsRenderObservable.remove(this._onBeforeRenderTargetsRenderObserver),this._onBeforeRenderTargetsRenderObserver=null,this.scene.OnAfterRenderTargetsRenderObservable.remove(this._onAfterRenderTargetsRenderObserver),this._onAfterRenderTargetsRenderObserver=null,this.scene.onBeforeAnimationsObservable.remove(this._onBeforeAnimationsObserver),this._onBeforeAnimationsObserver=null,this.scene.onBeforeParticlesRenderingObservable.remove(this._onBeforeParticlesRenderingObserver),this._onBeforeParticlesRenderingObserver=null,this.scene.onAfterParticlesRenderingObservable.remove(this._onAfterParticlesRenderingObserver),this._onAfterParticlesRenderingObserver=null,this.scene.onBeforeSpritesRenderingObservable.remove(this._onBeforeSpritesRenderingObserver),this._onBeforeSpritesRenderingObserver=null,this.scene.onAfterSpritesRenderingObservable.remove(this._onAfterSpritesRenderingObserver),this._onAfterSpritesRenderingObserver=null,this.scene.onBeforeDrawPhaseObservable.remove(this._onBeforeDrawPhaseObserver),this._onBeforeDrawPhaseObserver=null,this.scene.onAfterDrawPhaseObservable.remove(this._onAfterDrawPhaseObserver),this._onAfterDrawPhaseObserver=null,this.scene.onBeforePhysicsObservable.remove(this._onBeforePhysicsObserver),this._onBeforePhysicsObserver=null,this.scene.onAfterPhysicsObservable.remove(this._onAfterPhysicsObserver),this._onAfterPhysicsObserver=null,this.scene.onAfterAnimationsObservable.remove(this._onAfterAnimationsObserver),this._onAfterAnimationsObserver=null,this.scene=null},t}();e.SceneInstrumentation=t}(s||(s={}));!function(e){var t=function(){return function(){this._timeElapsedQueryEnded=!1}}();e._TimeToken=t}(s||(s={}));!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.DIFFUSE=!1,t.DIFFUSEDIRECTUV=0,t.GAMMADIFFUSE=!1,t.DIFFUSEHASALPHA=!1,t.OPACITYFRESNEL=!1,t.REFLECTIONBLUR=!1,t.REFLECTIONFRESNEL=!1,t.REFLECTIONFALLOFF=!1,t.TEXTURELODSUPPORT=!1,t.PREMULTIPLYALPHA=!1,t.USERGBCOLOR=!1,t.NOISE=!1,t.IMAGEPROCESSING=!1,t.VIGNETTE=!1,t.VIGNETTEBLENDMODEMULTIPLY=!1,t.VIGNETTEBLENDMODEOPAQUE=!1,t.TONEMAPPING=!1,t.CONTRAST=!1,t.COLORCURVES=!1,t.COLORGRADING=!1,t.COLORGRADING3D=!1,t.SAMPLER3DGREENDEPTH=!1,t.SAMPLER3DBGRMAP=!1,t.IMAGEPROCESSINGPOSTPROCESS=!1,t.EXPOSURE=!1,t.REFLECTION=!1,t.REFLECTIONMAP_3D=!1,t.REFLECTIONMAP_SPHERICAL=!1,t.REFLECTIONMAP_PLANAR=!1,t.REFLECTIONMAP_CUBIC=!1,t.REFLECTIONMAP_PROJECTION=!1,t.REFLECTIONMAP_SKYBOX=!1,t.REFLECTIONMAP_EXPLICIT=!1,t.REFLECTIONMAP_EQUIRECTANGULAR=!1,t.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!1,t.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!1,t.INVERTCUBICMAP=!1,t.REFLECTIONMAP_OPPOSITEZ=!1,t.LODINREFLECTIONALPHA=!1,t.GAMMAREFLECTION=!1,t.MAINUV1=!1,t.MAINUV2=!1,t.UV1=!1,t.UV2=!1,t.CLIPPLANE=!1,t.POINTSIZE=!1,t.FOG=!1,t.NORMAL=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.SHADOWFLOAT=!1,t.rebuild(),t}return n(t,e),t}(e.MaterialDefines),i=function(i){function o(t,r){var n=i.call(this,t,r)||this;return n.primaryColor=e.Color3.White(),n.primaryLevel=1,n.secondaryColor=e.Color3.Gray(),n.secondaryLevel=1,n.tertiaryColor=e.Color3.Black(),n.tertiaryLevel=1,n.reflectionTexture=null,n.reflectionBlur=0,n.diffuseTexture=null,n._shadowLights=null,n.shadowLights=null,n.shadowBlurScale=1,n.shadowLevel=0,n.sceneCenter=e.Vector3.Zero(),n.opacityFresnel=!0,n.reflectionFresnel=!1,n.reflectionFalloffDistance=0,n.reflectionAmount=1,n.reflectionReflectance0=.05,n.reflectionReflectance90=.5,n.useRGBColor=!0,n.enableNoise=!1,n._maxSimultaneousLights=4,n.maxSimultaneousLights=4,n._imageProcessingObserver=null,n._renderTargets=new e.SmartArray(16),n._reflectionControls=e.Vector4.Zero(),n._attachImageProcessingConfiguration(null),n.getRenderTargetTextures=function(){return n._renderTargets.reset(),n._diffuseTexture&&n._diffuseTexture.isRenderTarget&&n._renderTargets.push(n._diffuseTexture),n._reflectionTexture&&n._reflectionTexture.isRenderTarget&&n._renderTargets.push(n._reflectionTexture),n._renderTargets},n}return n(o,i),Object.defineProperty(o.prototype,"reflectionStandardFresnelWeight",{set:function(e){var t=e;t<.5?(t*=2,this.reflectionReflectance0=o.standardReflectance0*t,this.reflectionReflectance90=o.standardReflectance90*t):(t=2*t-1,this.reflectionReflectance0=o.standardReflectance0+(1-o.standardReflectance0)*t,this.reflectionReflectance90=o.standardReflectance90+(1-o.standardReflectance90)*t)},enumerable:!0,configurable:!0}),o.prototype._attachImageProcessingConfiguration=function(e){var t=this;e!==this._imageProcessingConfiguration&&(this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),this._imageProcessingConfiguration=e||this.getScene().imageProcessingConfiguration,this._imageProcessingObserver=this._imageProcessingConfiguration.onUpdateParameters.add(function(e){t._markAllSubMeshesAsImageProcessingDirty()}))},Object.defineProperty(o.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},set:function(e){this._attachImageProcessingConfiguration(e),this._markAllSubMeshesAsTexturesDirty()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraColorCurvesEnabled",{get:function(){return this.imageProcessingConfiguration.colorCurvesEnabled},set:function(e){this.imageProcessingConfiguration.colorCurvesEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraColorGradingEnabled",{get:function(){return this.imageProcessingConfiguration.colorGradingEnabled},set:function(e){this.imageProcessingConfiguration.colorGradingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraToneMappingEnabled",{get:function(){return this._imageProcessingConfiguration.toneMappingEnabled},set:function(e){this._imageProcessingConfiguration.toneMappingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraExposure",{get:function(){return this._imageProcessingConfiguration.exposure},set:function(e){this._imageProcessingConfiguration.exposure=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraContrast",{get:function(){return this._imageProcessingConfiguration.contrast},set:function(e){this._imageProcessingConfiguration.contrast=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraColorGradingTexture",{get:function(){return this._imageProcessingConfiguration.colorGradingTexture},set:function(e){this.imageProcessingConfiguration.colorGradingTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"cameraColorCurves",{get:function(){return this.imageProcessingConfiguration.colorCurves},set:function(e){this.imageProcessingConfiguration.colorCurves=e},enumerable:!0,configurable:!0}),o.prototype.needAlphaTesting=function(){return!0},o.prototype.needAlphaBlending=function(){return this.alpha<0||null!=this._diffuseTexture&&this._diffuseTexture.hasAlpha},o.prototype.isReadyForSubMesh=function(i,r,n){var o=this;if(void 0===n&&(n=!1),r.effect&&this.isFrozen&&this._wasPreviouslyReady)return!0;r._materialDefines||(r._materialDefines=new t);var s=this.getScene(),a=r._materialDefines;if(!this.checkReadyOnEveryCall&&r.effect&&a._renderId===s.getRenderId())return!0;var l=s.getEngine();if(e.MaterialHelper.PrepareDefinesForLights(s,i,a,!1,this._maxSimultaneousLights),a._needNormals=!0,a._areTexturesDirty){if(a._needUVs=!1,s.texturesEnabled){if(s.getEngine().getCaps().textureLOD&&(a.TEXTURELODSUPPORT=!0),this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled){if(!this._diffuseTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._diffuseTexture,a,"DIFFUSE"),a.DIFFUSEHASALPHA=this._diffuseTexture.hasAlpha,a.GAMMADIFFUSE=this._diffuseTexture.gammaSpace,a.OPACITYFRESNEL=this._opacityFresnel}else a.DIFFUSE=!1,a.DIFFUSEHASALPHA=!1,a.GAMMADIFFUSE=!1,a.OPACITYFRESNEL=!1;var h=this._reflectionTexture;if(h&&e.StandardMaterial.ReflectionTextureEnabled){if(!h.isReadyOrNotBlocking())return!1;switch(a.REFLECTION=!0,a.GAMMAREFLECTION=h.gammaSpace,a.REFLECTIONBLUR=this._reflectionBlur>0,a.REFLECTIONMAP_OPPOSITEZ=this.getScene().useRightHandedSystem?!h.invertZ:h.invertZ,a.LODINREFLECTIONALPHA=h.lodLevelInAlpha,h.coordinatesMode===e.Texture.INVCUBIC_MODE&&(a.INVERTCUBICMAP=!0),a.REFLECTIONMAP_3D=h.isCube,h.coordinatesMode){case e.Texture.CUBIC_MODE:case e.Texture.INVCUBIC_MODE:a.REFLECTIONMAP_CUBIC=!0;break;case e.Texture.EXPLICIT_MODE:a.REFLECTIONMAP_EXPLICIT=!0;break;case e.Texture.PLANAR_MODE:a.REFLECTIONMAP_PLANAR=!0;break;case e.Texture.PROJECTION_MODE:a.REFLECTIONMAP_PROJECTION=!0;break;case e.Texture.SKYBOX_MODE:a.REFLECTIONMAP_SKYBOX=!0;break;case e.Texture.SPHERICAL_MODE:a.REFLECTIONMAP_SPHERICAL=!0;break;case e.Texture.EQUIRECTANGULAR_MODE:a.REFLECTIONMAP_EQUIRECTANGULAR=!0;break;case e.Texture.FIXED_EQUIRECTANGULAR_MODE:a.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!0;break;case e.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:a.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!0}this.reflectionFresnel?(a.REFLECTIONFRESNEL=!0,a.REFLECTIONFALLOFF=this.reflectionFalloffDistance>0,this._reflectionControls.x=this.reflectionAmount,this._reflectionControls.y=this.reflectionReflectance0,this._reflectionControls.z=this.reflectionReflectance90,this._reflectionControls.w=1/this.reflectionFalloffDistance):(a.REFLECTIONFRESNEL=!1,a.REFLECTIONFALLOFF=!1)}else a.REFLECTION=!1,a.REFLECTIONFALLOFF=!1,a.REFLECTIONBLUR=!1,a.REFLECTIONMAP_3D=!1,a.REFLECTIONMAP_SPHERICAL=!1,a.REFLECTIONMAP_PLANAR=!1,a.REFLECTIONMAP_CUBIC=!1,a.REFLECTIONMAP_PROJECTION=!1,a.REFLECTIONMAP_SKYBOX=!1,a.REFLECTIONMAP_EXPLICIT=!1,a.REFLECTIONMAP_EQUIRECTANGULAR=!1,a.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!1,a.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!1,a.INVERTCUBICMAP=!1,a.REFLECTIONMAP_OPPOSITEZ=!1,a.LODINREFLECTIONALPHA=!1,a.GAMMAREFLECTION=!1}a.PREMULTIPLYALPHA=this.alphaMode===e.Engine.ALPHA_PREMULTIPLIED||this.alphaMode===e.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF,a.USERGBCOLOR=this._useRGBColor,a.NOISE=this._enableNoise}if(a._areImageProcessingDirty){if(!this._imageProcessingConfiguration.isReady())return!1;this._imageProcessingConfiguration.prepareDefines(a)}if(e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,a),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,l,a,n,!1),e.MaterialHelper.PrepareDefinesForAttributes(i,a,!1,!0,!1)&&i&&(s.getEngine().getCaps().standardDerivatives||i.isVerticesDataPresent(e.VertexBuffer.NormalKind)||(i.createNormals(!0),e.Tools.Warn("BackgroundMaterial: Normals have been created for the mesh: "+i.name))),a.isDirty){a.markAsProcessed(),s.resetCachedMaterial();var u=new e.EffectFallbacks;a.FOG&&u.addFallback(0,"FOG"),a.POINTSIZE&&u.addFallback(1,"POINTSIZE"),e.MaterialHelper.HandleFallbacksForShadows(a,u,this._maxSimultaneousLights),a.NUM_BONE_INFLUENCERS>0&&u.addCPUSkinningFallback(0,i);var c=[e.VertexBuffer.PositionKind];a.NORMAL&&c.push(e.VertexBuffer.NormalKind),a.UV1&&c.push(e.VertexBuffer.UVKind),a.UV2&&c.push(e.VertexBuffer.UV2Kind),e.MaterialHelper.PrepareAttributesForBones(c,i,a,u),e.MaterialHelper.PrepareAttributesForInstances(c,a);var f=["world","view","viewProjection","vEyePosition","vLightsType","vFogInfos","vFogColor","pointSize","vClipPlane","mBones","vPrimaryColor","vSecondaryColor","vTertiaryColor","vReflectionInfos","reflectionMatrix","vReflectionMicrosurfaceInfos","shadowLevel","alpha","vBackgroundCenter","vReflectionControl","vDiffuseInfos","diffuseMatrix"],p=["diffuseSampler","reflectionSampler","reflectionSamplerLow","reflectionSamplerHigh"],d=["Material","Scene"];e.ImageProcessingConfiguration.PrepareUniforms(f,a),e.ImageProcessingConfiguration.PrepareSamplers(p,a),e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:f,uniformBuffersNames:d,samplers:p,defines:a,maxSimultaneousLights:this._maxSimultaneousLights});var m=function(e){o.onCompiled&&o.onCompiled(e),o.bindSceneUniformBuffer(e,s.getSceneUniformBuffer())},g=a.toString();r.setEffect(s.getEngine().createEffect("background",{attributes:c,uniformsNames:f,uniformBuffersNames:d,samplers:p,defines:g,fallbacks:u,onCompiled:m,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights}},l),a),this.buildUniformLayout()}return!(!r.effect||!r.effect.isReady())&&(a._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,!0)},o.prototype.buildUniformLayout=function(){this._uniformBuffer.addUniform("vPrimaryColor",4),this._uniformBuffer.addUniform("vSecondaryColor",4),this._uniformBuffer.addUniform("vTertiaryColor",4),this._uniformBuffer.addUniform("vDiffuseInfos",2),this._uniformBuffer.addUniform("vReflectionInfos",2),this._uniformBuffer.addUniform("diffuseMatrix",16),this._uniformBuffer.addUniform("reflectionMatrix",16),this._uniformBuffer.addUniform("vReflectionMicrosurfaceInfos",3),this._uniformBuffer.addUniform("pointSize",1),this._uniformBuffer.addUniform("shadowLevel",1),this._uniformBuffer.addUniform("alpha",1),this._uniformBuffer.addUniform("vBackgroundCenter",3),this._uniformBuffer.addUniform("vReflectionControl",4),this._uniformBuffer.create()},o.prototype.unbind=function(){this._diffuseTexture&&this._diffuseTexture.isRenderTarget&&this._uniformBuffer.setTexture("diffuseSampler",null),this._reflectionTexture&&this._reflectionTexture.isRenderTarget&&this._uniformBuffer.setTexture("reflectionSampler",null),i.prototype.unbind.call(this)},o.prototype.bindOnlyWorldMatrix=function(e){this._activeEffect.setMatrix("world",e)},o.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;if(s){this._activeEffect=s,this.bindOnlyWorldMatrix(t),e.MaterialHelper.BindBonesParameters(i,this._activeEffect);var a=this._mustRebind(n,s,i.visibility);if(a){this._uniformBuffer.bindToEffect(s,"Material"),this.bindViewProjection(s);var l=this._reflectionTexture;this._uniformBuffer.useUbo&&this.isFrozen&&this._uniformBuffer.isSync||(n.texturesEnabled&&(this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._uniformBuffer.updateFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),e.MaterialHelper.BindTextureMatrix(this._diffuseTexture,this._uniformBuffer,"diffuse")),l&&e.StandardMaterial.ReflectionTextureEnabled&&(this._uniformBuffer.updateMatrix("reflectionMatrix",l.getReflectionTextureMatrix()),this._uniformBuffer.updateFloat2("vReflectionInfos",l.level,this._reflectionBlur),this._uniformBuffer.updateFloat3("vReflectionMicrosurfaceInfos",l.getSize().width,l.lodGenerationScale,l.lodGenerationOffset))),this.shadowLevel>0&&this._uniformBuffer.updateFloat("shadowLevel",this.shadowLevel),this._uniformBuffer.updateFloat("alpha",this.alpha),this.pointsCloud&&this._uniformBuffer.updateFloat("pointSize",this.pointSize),this._uniformBuffer.updateColor4("vPrimaryColor",this._primaryColor,this._primaryLevel),this._uniformBuffer.updateColor4("vSecondaryColor",this._secondaryColor,this._secondaryLevel),this._uniformBuffer.updateColor4("vTertiaryColor",this._tertiaryColor,this._tertiaryLevel)),n.texturesEnabled&&(this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&this._uniformBuffer.setTexture("diffuseSampler",this._diffuseTexture),l&&e.StandardMaterial.ReflectionTextureEnabled&&(o.REFLECTIONBLUR&&o.TEXTURELODSUPPORT?this._uniformBuffer.setTexture("reflectionSampler",l):o.REFLECTIONBLUR?(this._uniformBuffer.setTexture("reflectionSampler",l._lodTextureMid||l),this._uniformBuffer.setTexture("reflectionSamplerLow",l._lodTextureLow||l),this._uniformBuffer.setTexture("reflectionSamplerHigh",l._lodTextureHigh||l)):this._uniformBuffer.setTexture("reflectionSampler",l),o.REFLECTIONFRESNEL&&(this._uniformBuffer.updateFloat3("vBackgroundCenter",this.sceneCenter.x,this.sceneCenter.y,this.sceneCenter.z),this._uniformBuffer.updateFloat4("vReflectionControl",this._reflectionControls.x,this._reflectionControls.y,this._reflectionControls.z,this._reflectionControls.w)))),e.MaterialHelper.BindClipPlane(this._activeEffect,n),e.MaterialHelper.BindEyePosition(s,n)}!a&&this.isFrozen||(n.lightsEnabled&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o,this._maxSimultaneousLights,!1),this.bindView(s),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._imageProcessingConfiguration.bind(this._activeEffect)),this._uniformBuffer.update(),this._afterBind(i)}}},o.prototype.dispose=function(e,t){void 0===e&&(e=!1),void 0===t&&(t=!1),t&&(this.diffuseTexture&&this.diffuseTexture.dispose(),this.reflectionTexture&&this.reflectionTexture.dispose()),this._renderTargets.dispose(),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),i.prototype.dispose.call(this,e)},o.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new o(t,i.getScene())},this)},o.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.BackgroundMaterial",t},o.prototype.getClassName=function(){return"BackgroundMaterial"},o.Parse=function(t,i,r){return e.SerializationHelper.Parse(function(){return new o(t.name,i)},t,i,r)},o.standardReflectance0=.05,o.standardReflectance90=.5,r([e.serializeAsColor3()],o.prototype,"_primaryColor",void 0),r([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],o.prototype,"primaryColor",void 0),r([e.serialize()],o.prototype,"_primaryLevel",void 0),r([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],o.prototype,"primaryLevel",void 0),r([e.serializeAsColor3()],o.prototype,"_secondaryColor",void 0),r([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],o.prototype,"secondaryColor",void 0),r([e.serialize()],o.prototype,"_secondaryLevel",void 0),r([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],o.prototype,"secondaryLevel",void 0),r([e.serializeAsColor3()],o.prototype,"_tertiaryColor",void 0),r([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],o.prototype,"tertiaryColor",void 0),r([e.serialize()],o.prototype,"_tertiaryLevel",void 0),r([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],o.prototype,"tertiaryLevel",void 0),r([e.serializeAsTexture()],o.prototype,"_reflectionTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"reflectionTexture",void 0),r([e.serialize()],o.prototype,"_reflectionBlur",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"reflectionBlur",void 0),r([e.serializeAsTexture()],o.prototype,"_diffuseTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"diffuseTexture",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"shadowLights",void 0),r([e.serialize()],o.prototype,"_shadowBlurScale",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"shadowBlurScale",void 0),r([e.serialize()],o.prototype,"_shadowLevel",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"shadowLevel",void 0),r([e.serializeAsVector3()],o.prototype,"_sceneCenter",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"sceneCenter",void 0),r([e.serialize()],o.prototype,"_opacityFresnel",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"opacityFresnel",void 0),r([e.serialize()],o.prototype,"_reflectionFresnel",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"reflectionFresnel",void 0),r([e.serialize()],o.prototype,"_reflectionFalloffDistance",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"reflectionFalloffDistance",void 0),r([e.serialize()],o.prototype,"_reflectionAmount",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"reflectionAmount",void 0),r([e.serialize()],o.prototype,"_reflectionReflectance0",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"reflectionReflectance0",void 0),r([e.serialize()],o.prototype,"_reflectionReflectance90",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"reflectionReflectance90",void 0),r([e.serialize()],o.prototype,"_useRGBColor",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"useRGBColor",void 0),r([e.serialize()],o.prototype,"_enableNoise",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"enableNoise",void 0),r([e.serialize()],o.prototype,"_maxSimultaneousLights",void 0),r([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],o.prototype,"maxSimultaneousLights",void 0),r([e.serializeAsImageProcessingConfiguration()],o.prototype,"_imageProcessingConfiguration",void 0),o}(e.PushMaterial);e.BackgroundMaterial=i}(s||(s={}));var s,a=this&&this.__assign||Object.assign||function(e){for(var t,i=1,r=arguments.length;i<r;i++){t=arguments[i];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e};!function(e){var t=function(){function t(e,i){this._options=a({},t._getDefaultOptions(),e),this._scene=i,this._setupBackground(),this._setupImageProcessing()}return t._getDefaultOptions=function(){return{createGround:!0,groundSize:15,groundTexture:this._groundTextureCDNUrl,groundColor:new e.Color3(.2,.2,.3).toLinearSpace().scale(3),groundOpacity:.9,enableGroundShadow:!0,groundShadowLevel:.5,enableGroundMirror:!1,groundMirrorSizeRatio:.3,groundMirrorBlurKernel:64,groundMirrorAmount:1,groundMirrorFresnelWeight:1,groundMirrorFallOffDistance:0,groundMirrorTextureType:e.Engine.TEXTURETYPE_UNSIGNED_INT,createSkybox:!0,skyboxSize:20,skyboxTexture:this._skyboxTextureCDNUrl,skyboxColor:new e.Color3(.2,.2,.3).toLinearSpace().scale(3),backgroundYRotation:0,sizeAuto:!0,rootPosition:e.Vector3.Zero(),setupImageProcessing:!0,environmentTexture:this._environmentTextureCDNUrl,cameraExposure:.8,cameraContrast:1.2,toneMappingEnabled:!0}},Object.defineProperty(t.prototype,"rootMesh",{get:function(){return this._rootMesh},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"skybox",{get:function(){return this._skybox},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"skyboxTexture",{get:function(){return this._skyboxTexture},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"skyboxMaterial",{get:function(){return this._skyboxMaterial},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"ground",{get:function(){return this._ground},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"groundTexture",{get:function(){return this._groundTexture},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"groundMirror",{get:function(){return this._groundMirror},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"groundMirrorRenderList",{get:function(){return this._groundMirror?this._groundMirror.renderList:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"groundMaterial",{get:function(){return this._groundMaterial},enumerable:!0,configurable:!0}),t.prototype.updateOptions=function(e){var t=a({},this._options,e);this._ground&&!t.createGround&&(this._ground.dispose(),this._ground=null),this._groundMaterial&&!t.createGround&&(this._groundMaterial.dispose(),this._groundMaterial=null),this._options.groundTexture&&!t.groundTexture&&this._groundTexture&&(this._groundTexture.dispose(),this._groundTexture=null),this._skybox&&!t.createSkybox&&(this._skybox.dispose(),this._skybox=null),this._skyboxMaterial&&!t.createSkybox&&(this._skyboxMaterial.dispose(),this._skyboxMaterial=null),this._options.skyboxTexture&&!t.skyboxTexture&&this._skyboxTexture&&(this._skyboxTexture.dispose(),this._skyboxTexture=null),this._groundMirror&&!t.enableGroundMirror&&(this._groundMirror.dispose(),this._groundMirror=null),this._setupBackground(),this._options.environmentTexture&&!t.environmentTexture&&this._scene.environmentTexture&&this._scene.environmentTexture.dispose(),this._setupImageProcessing()},t.prototype.setMainColor=function(t){this.groundMaterial&&(this.groundMaterial.primaryColor=t),this.skyboxMaterial&&(this.skyboxMaterial.primaryColor=t),this.groundMirror&&(this.groundMirror.clearColor=new e.Color4(t.r,t.g,t.b,1))},t.prototype._setupImageProcessing=function(){this._options.setupImageProcessing&&(this._scene.imageProcessingConfiguration.contrast=this._options.cameraContrast,this._scene.imageProcessingConfiguration.exposure=this._options.cameraExposure,this._scene.imageProcessingConfiguration.toneMappingEnabled=this._options.toneMappingEnabled,this._setupEnvironmentTexture())},t.prototype._setupEnvironmentTexture=function(){if(!this._scene.environmentTexture)if(this._options.environmentTexture instanceof e.BaseTexture)this._scene.environmentTexture=this._options.environmentTexture;else{var t=e.CubeTexture.CreateFromPrefilteredData(this._options.environmentTexture,this._scene);this._scene.environmentTexture=t}},t.prototype._setupBackground=function(){this._rootMesh||(this._rootMesh=new e.Mesh("BackgroundHelper",this._scene)),this._rootMesh.rotation.y=this._options.backgroundYRotation;var t=this._getSceneSize();this._options.createGround&&(this._setupGround(t),this._setupGroundMaterial(),this._setupGroundDiffuseTexture(),this._options.enableGroundMirror&&(this._setupGroundMirrorTexture(t),this._setupMirrorInGroundMaterial())),this._options.createSkybox&&(this._setupSkybox(t),this._setupSkyboxMaterial(),this._setupSkyboxReflectionTexture()),this._rootMesh.position.x=t.rootPosition.x,this._rootMesh.position.z=t.rootPosition.z,this._rootMesh.position.y=t.rootPosition.y},t.prototype._getSceneSize=function(){var t=this._options.groundSize,i=this._options.skyboxSize,r=this._options.rootPosition,n=this._scene.getWorldExtends(),o=n.max.subtract(n.min),s=1e-4;if(this._options.sizeAuto){this._scene.activeCamera instanceof e.ArcRotateCamera&&this._scene.activeCamera.upperRadiusLimit&&(t=2*this._scene.activeCamera.upperRadiusLimit),this._scene.activeCamera&&(s=(this._scene.activeCamera.maxZ-this._scene.activeCamera.minZ)/1e4);var a=o.length();a>t&&(t=2*a),t*=1.1,i*=1.5,(r=n.min.add(o.scale(.5))).y=n.min.y-s}return{groundSize:t,skyboxSize:i,rootPosition:r}},t.prototype._setupGround=function(t){this._ground||(this._ground=e.Mesh.CreatePlane("BackgroundPlane",t.groundSize,this._scene),this._ground.rotation.x=Math.PI/2,this._ground.parent=this._rootMesh),this._ground.receiveShadows=this._options.enableGroundShadow},t.prototype._setupGroundMaterial=function(){this._groundMaterial||(this._groundMaterial=new e.BackgroundMaterial("BackgroundPlaneMaterial",this._scene)),this._groundMaterial.alpha=this._options.groundOpacity,this._groundMaterial.alphaMode=e.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF,this._groundMaterial.shadowLevel=this._options.groundShadowLevel,this._groundMaterial.primaryLevel=1,this._groundMaterial.primaryColor=this._options.groundColor,this._groundMaterial.secondaryLevel=0,this._groundMaterial.tertiaryLevel=0,this._groundMaterial.useRGBColor=!1,this._groundMaterial.enableNoise=!0,this._ground&&(this._ground.material=this._groundMaterial)},t.prototype._setupGroundDiffuseTexture=function(){if(this._groundMaterial&&!this._groundTexture)if(this._options.groundTexture instanceof e.BaseTexture)this._groundMaterial.diffuseTexture=this._options.groundTexture;else{var t=new e.Texture(this._options.groundTexture,this._scene);t.gammaSpace=!1,t.hasAlpha=!0,this._groundMaterial.diffuseTexture=t}},t.prototype._setupGroundMirrorTexture=function(t){var i=e.Texture.CLAMP_ADDRESSMODE;if(!this._groundMirror&&(this._groundMirror=new e.MirrorTexture("BackgroundPlaneMirrorTexture",{ratio:this._options.groundMirrorSizeRatio},this._scene,!1,this._options.groundMirrorTextureType,e.Texture.BILINEAR_SAMPLINGMODE,!0),this._groundMirror.mirrorPlane=new e.Plane(0,-1,0,t.rootPosition.y),this._groundMirror.anisotropicFilteringLevel=1,this._groundMirror.wrapU=i,this._groundMirror.wrapV=i,this._groundMirror.gammaSpace=!1,this._groundMirror.renderList))for(var r=0;r<this._scene.meshes.length;r++){var n=this._scene.meshes[r];n!==this._ground&&n!==this._skybox&&n!==this._rootMesh&&this._groundMirror.renderList.push(n)}this._groundMirror.clearColor=new e.Color4(this._options.groundColor.r,this._options.groundColor.g,this._options.groundColor.b,1),this._groundMirror.adaptiveBlurKernel=this._options.groundMirrorBlurKernel},t.prototype._setupMirrorInGroundMaterial=function(){this._groundMaterial&&(this._groundMaterial.reflectionTexture=this._groundMirror,this._groundMaterial.reflectionFresnel=!0,this._groundMaterial.reflectionAmount=this._options.groundMirrorAmount,this._groundMaterial.reflectionStandardFresnelWeight=this._options.groundMirrorFresnelWeight,this._groundMaterial.reflectionFalloffDistance=this._options.groundMirrorFallOffDistance)},t.prototype._setupSkybox=function(t){this._skybox||(this._skybox=e.Mesh.CreateBox("BackgroundSkybox",t.skyboxSize,this._scene,void 0,e.Mesh.BACKSIDE)),this._skybox.parent=this._rootMesh},t.prototype._setupSkyboxMaterial=function(){this._skybox&&(this._skyboxMaterial||(this._skyboxMaterial=new e.BackgroundMaterial("BackgroundSkyboxMaterial",this._scene)),this._skyboxMaterial.useRGBColor=!1,this._skyboxMaterial.primaryLevel=1,this._skyboxMaterial.primaryColor=this._options.skyboxColor,this._skyboxMaterial.secondaryLevel=0,this._skyboxMaterial.tertiaryLevel=0,this._skyboxMaterial.enableNoise=!0,this._skybox.material=this._skyboxMaterial)},t.prototype._setupSkyboxReflectionTexture=function(){this._skyboxMaterial&&(this._skyboxTexture||(this._options.skyboxTexture instanceof e.BaseTexture?this._skyboxMaterial.reflectionTexture=this._skyboxTexture:(this._skyboxTexture=new e.CubeTexture(this._options.skyboxTexture,this._scene),this._skyboxTexture.coordinatesMode=e.Texture.SKYBOX_MODE,this._skyboxTexture.gammaSpace=!1,this._skyboxMaterial.reflectionTexture=this._skyboxTexture)))},t.prototype.dispose=function(){this._groundMaterial&&this._groundMaterial.dispose(!0,!0),this._skyboxMaterial&&this._skyboxMaterial.dispose(!0,!0),this._rootMesh.dispose(!0)},t._groundTextureCDNUrl="https://assets.babylonjs.com/environments/backgroundGround.png",t._skyboxTextureCDNUrl="https://assets.babylonjs.com/environments/backgroundSkybox.dds",t._environmentTextureCDNUrl="https://assets.babylonjs.com/environments/environmentSpecular.dds",t}();e.EnvironmentHelper=t}(s||(s={})),s.Effect.ShadersStore={defaultVertexShader:"#include<__decl__defaultVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\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<helperFunctions>\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nvarying vec2 vSpecularUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL \nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,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 MAINUV1\nvMainUV1=uv;\n#endif\n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\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#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\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#if defined(OPACITY) && OPACITYDIRECTUV == 0\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#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\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(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\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) && SPECULARDIRECTUV == 0\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#if defined(BUMP) && BUMPDIRECTUV == 0\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<bumpVertex>\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include<pointCloudVertex>\n#include<logDepthVertex>\n}",defaultPixelShader:"#include<__decl__defaultFragment>\n#if defined(BUMP) || !defined(NORMAL)\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;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY \n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\n#if SPECULARDIRECTUV == 1\n#define vSpecularUV vMainUV1\n#elif SPECULARDIRECTUV == 2\n#define vSpecularUV vMainUV2\n#else\nvarying vec2 vSpecularUV;\n#endif\nuniform sampler2D specularSampler;\n#endif\n\n#include<fresnelFunction>\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#include<imageProcessingDeclaration>\n#include<imageProcessingFunctions>\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=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include<bumpFragment>\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\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#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).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+uvOffset);\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#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\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+uvOffset);\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+uvOffset).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#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\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\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor;\n#else\ncolor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n#include<logDepthFragment>\n#include<fogFragment>\n\n\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);\ncolor=applyImageProcessing(color);\n#endif\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\ngl_FragColor=color;\n}",pbrVertexShader:"precision highp float;\n#include<__decl__pbrVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2; \n#endif \n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<helperFunctions>\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#if defined(ALBEDO) && ALBEDODIRECTUV == 0\nvarying vec2 vAlbedoUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(REFLECTIVITY) && REFLECTIVITYDIRECTUV == 0\nvarying vec2 vReflectivityUV;\n#endif\n#if defined(MICROSURFACEMAP) && MICROSURFACEMAPDIRECTUV == 0\nvarying vec2 vMicroSurfaceSamplerUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#include<harmonicsFunctions>\n#endif\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvec3 reflectionVector=vec3(reflectionMatrix*vec4(vNormalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\nvEnvironmentIrradiance=environmentIrradianceJones(reflectionVector);\n#endif\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,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 MAINUV1\nvMainUV1=uv;\n#endif \n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif \n#if defined(ALBEDO) && ALBEDODIRECTUV == 0 \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#if defined(AMBIENT) && AMBIENTDIRECTUV == 0 \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#if defined(OPACITY) && OPACITYDIRECTUV == 0 \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#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0 \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(LIGHTMAP) && LIGHTMAPDIRECTUV == 0 \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) && REFLECTIVITYDIRECTUV == 0 \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#if defined(MICROSURFACEMAP) && MICROSURFACEMAPDIRECTUV == 0 \nif (vMicroSurfaceSamplerInfos.x == 0.)\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0 \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<bumpVertex>\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n\n#include<logDepthVertex>\n}",pbrPixelShader:"#if defined(BUMP) || !defined(NORMAL) || defined(FORCENORMALFORWARD)\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;\n#include<__decl__pbrFragment>\nuniform vec4 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vCameraInfos;\n\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2;\n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#endif\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef ALBEDO\n#if ALBEDODIRECTUV == 1\n#define vAlbedoUV vMainUV1\n#elif ALBEDODIRECTUV == 2\n#define vAlbedoUV vMainUV2\n#else\nvarying vec2 vAlbedoUV;\n#endif\nuniform sampler2D albedoSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY\n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFLECTIVITY\n#if REFLECTIVITYDIRECTUV == 1\n#define vReflectivityUV vMainUV1\n#elif REFLECTIVITYDIRECTUV == 2\n#define vReflectivityUV vMainUV2\n#else\nvarying vec2 vReflectivityUV;\n#endif\nuniform sampler2D reflectivitySampler;\n#endif\n#ifdef MICROSURFACEMAP\n#if MICROSURFACEMAPDIRECTUV == 1\n#define vMicroSurfaceSamplerUV vMainUV1\n#elif MICROSURFACEMAPDIRECTUV == 2\n#define vMicroSurfaceSamplerUV vMainUV2\n#else\nvarying vec2 vMicroSurfaceSamplerUV;\n#endif\nuniform sampler2D microSurfaceSampler;\n#endif\n\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\n#define sampleRefraction(s,c) textureCube(s,c)\nuniform samplerCube refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube refractionSamplerLow;\nuniform samplerCube refractionSamplerHigh;\n#endif\n#else\n#define sampleRefraction(s,c) texture2D(s,c)\nuniform sampler2D refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube refractionSamplerLow;\nuniform samplerCube refractionSamplerHigh;\n#endif\n#endif\n#endif\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#ifdef ENVIRONMENTBRDF\nuniform sampler2D environmentBrdfSampler;\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n#include<imageProcessingDeclaration>\n#include<helperFunctions>\n#include<imageProcessingFunctions>\n\n#include<shadowsFragmentFunctions>\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>\n\n\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#endif\n#include<bumpFragment>\n#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nvec3 faceNormal=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#if defined(TWOSIDEDLIGHTING)\nfaceNormal=gl_FrontFacing ? faceNormal : -faceNormal;\n#endif\nnormalW*=sign(dot(normalW,faceNormal));\n#endif\n#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n\n\nvec3 surfaceAlbedo=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nvec4 albedoTexture=texture2D(albedoSampler,vAlbedoUV+uvOffset);\n#if defined(ALPHAFROMALBEDO) || defined(ALPHATEST)\nalpha*=albedoTexture.a;\n#endif\nsurfaceAlbedo*=toLinearSpace(albedoTexture.rgb);\nsurfaceAlbedo*=vAlbedoInfos.y;\n#endif\n\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nalpha=getLuminance(opacityMap.rgb);\n#else\nalpha*=opacityMap.a;\n#endif\nalpha*=vOpacityInfos.y;\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#if !defined(LINKREFRACTIONTOTRANSPARENCY) && !defined(ALPHAFRESNEL)\n#ifdef ALPHATEST\nif (alpha<=ALPHATESTVALUE)\ndiscard;\n#ifndef ALPHABLEND\n\nalpha=1.0;\n#endif\n#endif\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nsurfaceAlbedo*=vColor.rgb;\n#endif\n\nvec3 ambientOcclusionColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nvec3 ambientOcclusionColorMap=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#ifdef AMBIENTINGRAYSCALE\nambientOcclusionColorMap=vec3(ambientOcclusionColorMap.r,ambientOcclusionColorMap.r,ambientOcclusionColorMap.r);\n#endif\nambientOcclusionColor=mix(ambientOcclusionColor,ambientOcclusionColorMap,vAmbientInfos.z);\n#endif\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef METALLICWORKFLOW\nvec2 metallicRoughness=surfaceReflectivityColor.rg;\n#ifdef REFLECTIVITY\nvec4 surfaceMetallicColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\n#ifdef AOSTOREINMETALMAPRED\nvec3 aoStoreInMetalMap=vec3(surfaceMetallicColorMap.r,surfaceMetallicColorMap.r,surfaceMetallicColorMap.r);\nambientOcclusionColor=mix(ambientOcclusionColor,aoStoreInMetalMap,vReflectivityInfos.z);\n#endif\n#ifdef METALLNESSSTOREINMETALMAPBLUE\nmetallicRoughness.r*=surfaceMetallicColorMap.b;\n#else\nmetallicRoughness.r*=surfaceMetallicColorMap.r;\n#endif\n#ifdef ROUGHNESSSTOREINMETALMAPALPHA\nmetallicRoughness.g*=surfaceMetallicColorMap.a;\n#else\n#ifdef ROUGHNESSSTOREINMETALMAPGREEN\nmetallicRoughness.g*=surfaceMetallicColorMap.g;\n#endif\n#endif\n#endif\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmetallicRoughness.g*=microSurfaceTexel.r;\n#endif\n\nmicroSurface=1.0-metallicRoughness.g;\n\nvec3 baseColor=surfaceAlbedo;\n\n\nconst vec3 DefaultSpecularReflectanceDielectric=vec3(0.04,0.04,0.04);\n\nsurfaceAlbedo=mix(baseColor.rgb*(1.0-DefaultSpecularReflectanceDielectric.r),vec3(0.,0.,0.),metallicRoughness.r);\n\nsurfaceReflectivityColor=mix(DefaultSpecularReflectanceDielectric,baseColor,metallicRoughness.r);\n#else\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\nsurfaceReflectivityColor*=toLinearSpace(surfaceReflectivityColorMap.rgb);\nsurfaceReflectivityColor*=vReflectivityInfos.y;\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface*=surfaceReflectivityColorMap.a;\nmicroSurface*=vReflectivityInfos.z;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface*=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmicroSurface*=microSurfaceTexel.r;\n#endif\n#endif\n#endif\n#endif\n\nmicroSurface=clamp(microSurface,0.,1.);\n\nfloat roughness=1.-microSurface;\n\n#ifdef ALPHAFRESNEL\n#if defined(ALPHATEST) || defined(ALPHABLEND)\n\n\n\nfloat opacityPerceptual=alpha;\nfloat opacity0=opacityPerceptual*opacityPerceptual;\nfloat opacity90=fresnelGrazingReflectance(opacity0);\nvec3 normalForward=faceforward(normalW,-viewDirectionW,normalW);\n\nalpha=fresnelSchlickEnvironmentGGX(clamp(dot(viewDirectionW,normalForward),0.0,1.0),vec3(opacity0),vec3(opacity90),sqrt(microSurface)).x;\n#ifdef ALPHATEST\nif (alpha<=ALPHATESTVALUE)\ndiscard;\n#ifndef ALPHABLEND\n\nalpha=1.0;\n#endif\n#endif\n#endif\n#endif\n\n\nfloat NdotVUnclamped=dot(normalW,viewDirectionW);\nfloat NdotV=clamp(NdotVUnclamped,0.,1.)+0.00001;\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\n\n#ifdef REFRACTION\nvec3 environmentRefraction=vec3(0.,0.,0.);\nvec3 refractionVector=refract(-viewDirectionW,normalW,vRefractionInfos.y);\n#ifdef REFRACTIONMAP_OPPOSITEZ\nrefractionVector.z*=-1.0;\n#endif\n\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nvec3 refractionCoords=refractionVector;\nrefractionCoords=vec3(refractionMatrix*vec4(refractionCoords,0));\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#endif\n#ifdef LODINREFRACTIONALPHA\nfloat refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,alphaG,NdotVUnclamped);\n#else\nfloat refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,alphaG,1.0);\n#endif\n#ifdef LODBASEDMICROSFURACE\n\nrefractionLOD=refractionLOD*vRefractionMicrosurfaceInfos.y+vRefractionMicrosurfaceInfos.z;\n#ifdef LODINREFRACTIONALPHA\n\n\n\n\n\n\n\n\n\nfloat automaticRefractionLOD=UNPACK_LOD(sampleRefraction(refractionSampler,refractionCoords).a);\nfloat requestedRefractionLOD=max(automaticRefractionLOD,refractionLOD);\n#else\nfloat requestedRefractionLOD=refractionLOD;\n#endif\nenvironmentRefraction=sampleRefractionLod(refractionSampler,refractionCoords,requestedRefractionLOD).rgb;\n#else\nfloat lodRefractionNormalized=clamp(refractionLOD/log2(vRefractionMicrosurfaceInfos.x),0.,1.);\nfloat lodRefractionNormalizedDoubled=lodRefractionNormalized*2.0;\nvec3 environmentRefractionMid=sampleRefraction(refractionSampler,refractionCoords).rgb;\nif(lodRefractionNormalizedDoubled<1.0){\nenvironmentRefraction=mix(\nsampleRefraction(refractionSamplerHigh,refractionCoords).rgb,\nenvironmentRefractionMid,\nlodRefractionNormalizedDoubled\n);\n}else{\nenvironmentRefraction=mix(\nenvironmentRefractionMid,\nsampleRefraction(refractionSamplerLow,refractionCoords).rgb,\nlodRefractionNormalizedDoubled-1.0\n);\n}\n#endif\n#ifdef GAMMAREFRACTION\nenvironmentRefraction=toLinearSpace(environmentRefraction.rgb);\n#endif\n\nenvironmentRefraction*=vRefractionInfos.x;\n#endif\n\n#ifdef REFLECTION\nvec3 environmentRadiance=vec3(0.,0.,0.);\nvec3 environmentIrradiance=vec3(0.,0.,0.);\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\n\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords=reflectionVector;\n#else\nvec2 reflectionCoords=reflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nreflectionCoords/=reflectionVector.z;\n#endif\nreflectionCoords.y=1.0-reflectionCoords.y;\n#endif\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nfloat reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG,NdotVUnclamped);\n#else\nfloat reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG,1.);\n#endif\n#ifdef LODBASEDMICROSFURACE\n\nreflectionLOD=reflectionLOD*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;\n#ifdef LODINREFLECTIONALPHA\n\n\n\n\n\n\n\n\n\nfloat automaticReflectionLOD=UNPACK_LOD(sampleReflection(reflectionSampler,reflectionCoords).a);\nfloat requestedReflectionLOD=max(automaticReflectionLOD,reflectionLOD);\n#else\nfloat requestedReflectionLOD=reflectionLOD;\n#endif\nenvironmentRadiance=sampleReflectionLod(reflectionSampler,reflectionCoords,requestedReflectionLOD).rgb;\n#else\nfloat lodReflectionNormalized=clamp(reflectionLOD/log2(vReflectionMicrosurfaceInfos.x),0.,1.);\nfloat lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;\nvec3 environmentSpecularMid=sampleReflection(reflectionSampler,reflectionCoords).rgb;\nif(lodReflectionNormalizedDoubled<1.0){\nenvironmentRadiance=mix(\nsampleReflection(reflectionSamplerHigh,reflectionCoords).rgb,\nenvironmentSpecularMid,\nlodReflectionNormalizedDoubled\n);\n}else{\nenvironmentRadiance=mix(\nenvironmentSpecularMid,\nsampleReflection(reflectionSamplerLow,reflectionCoords).rgb,\nlodReflectionNormalizedDoubled-1.0\n);\n}\n#endif\n#ifdef GAMMAREFLECTION\nenvironmentRadiance=toLinearSpace(environmentRadiance.rgb);\n#endif\n\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX)\nenvironmentIrradiance=vEnvironmentIrradiance;\n#else\nvec3 irradianceVector=vec3(reflectionMatrix*vec4(normalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nirradianceVector.z*=-1.0;\n#endif\nenvironmentIrradiance=environmentIrradianceJones(irradianceVector);\n#endif\n#endif\n\nenvironmentRadiance*=vReflectionInfos.x;\nenvironmentRadiance*=vReflectionColor.rgb;\nenvironmentIrradiance*=vReflectionColor.rgb;\n#endif\n\n\n\nfloat reflectance=max(max(surfaceReflectivityColor.r,surfaceReflectivityColor.g),surfaceReflectivityColor.b);\nfloat reflectance90=fresnelGrazingReflectance(reflectance);\nvec3 specularEnvironmentR0=surfaceReflectivityColor.rgb;\nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0)*reflectance90;\n\nvec3 diffuseBase=vec3(0.,0.,0.);\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\nlightingInfo info;\nfloat shadow=1.; \nfloat NdotL=-1.;\n#include<lightFragment>[0..maxSimultaneousLights]\n\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\n\nvec2 brdfSamplerUV=vec2(NdotV,roughness);\n\nvec4 environmentBrdf=texture2D(environmentBrdfSampler,brdfSamplerUV);\nvec3 specularEnvironmentReflectance=specularEnvironmentR0*environmentBrdf.x+environmentBrdf.y;\n#ifdef AMBIENTINGRAYSCALE\nfloat ambientMonochrome=ambientOcclusionColor.r;\n#else\nfloat ambientMonochrome=getLuminance(ambientOcclusionColor);\n#endif\nfloat seo=environmentRadianceOcclusion(ambientMonochrome,NdotVUnclamped);\nspecularEnvironmentReflectance*=seo;\n#ifdef BUMP\n#ifdef REFLECTIONMAP_3D\nfloat eho=environmentHorizonOcclusion(reflectionCoords,normalW);\nspecularEnvironmentReflectance*=eho;\n#endif\n#endif\n#else\n\nvec3 specularEnvironmentReflectance=fresnelSchlickEnvironmentGGX(NdotV,specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n#endif\n\n#ifdef REFRACTION\nvec3 refractance=vec3(0.0,0.0,0.0);\nvec3 transmission=vec3(1.0,1.0,1.0);\n#ifdef LINKREFRACTIONTOTRANSPARENCY\n\ntransmission*=(1.0-alpha);\n\n\nvec3 mixedAlbedo=surfaceAlbedo;\nfloat maxChannel=max(max(mixedAlbedo.r,mixedAlbedo.g),mixedAlbedo.b);\nvec3 tint=clamp(maxChannel*mixedAlbedo,0.0,1.0);\n\nsurfaceAlbedo*=alpha;\n\nenvironmentIrradiance*=alpha;\n\nenvironmentRefraction*=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=transmission;\n#endif\n\n\n\n\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\n\nvec3 finalDiffuse=diffuseBase;\nfinalDiffuse.rgb+=vAmbientColor;\nfinalDiffuse*=surfaceAlbedo.rgb;\nfinalDiffuse=max(finalDiffuse,0.0);\n\n#ifdef REFLECTION\nvec3 finalIrradiance=environmentIrradiance;\nfinalIrradiance*=surfaceAlbedo.rgb;\n#endif\n\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase;\nfinalSpecular=max(finalSpecular,0.0);\n\nvec3 finalSpecularScaled=finalSpecular*vLightingIntensity.x*vLightingIntensity.w;\n#endif\n\n#ifdef REFLECTION\nvec3 finalRadiance=environmentRadiance;\nfinalRadiance*=specularEnvironmentReflectance;\n\nvec3 finalRadianceScaled=finalRadiance*vLightingIntensity.z;\n#endif\n\n#ifdef REFRACTION\nvec3 finalRefraction=environmentRefraction;\nfinalRefraction*=refractance;\n#endif\n\nvec3 finalEmissive=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb;\nfinalEmissive*=toLinearSpace(emissiveColorTex.rgb);\nfinalEmissive*=vEmissiveInfos.y;\n#endif\n\n#ifdef ALPHABLEND\nfloat luminanceOverAlpha=0.0;\n#if defined(REFLECTION) && defined(RADIANCEOVERALPHA)\nluminanceOverAlpha+=getLuminance(finalRadianceScaled);\n#endif\n#if defined(SPECULARTERM) && defined(SPECULAROVERALPHA)\nluminanceOverAlpha+=getLuminance(finalSpecularScaled);\n#endif\n#if defined(RADIANCEOVERALPHA) || defined(SPECULAROVERALPHA)\nalpha=clamp(alpha+luminanceOverAlpha*luminanceOverAlpha,0.,1.);\n#endif\n#endif\n\n\n\nvec4 finalColor=vec4(finalDiffuse*ambientOcclusionColor*vLightingIntensity.x +\n#ifdef REFLECTION\nfinalIrradiance*ambientOcclusionColor*vLightingIntensity.z +\n#endif\n#ifdef SPECULARTERM\n\n\nfinalSpecularScaled +\n#endif\n#ifdef REFLECTION\n\n\nfinalRadianceScaled +\n#endif\n#ifdef REFRACTION\nfinalRefraction*vLightingIntensity.z +\n#endif\nfinalEmissive*vLightingIntensity.y,\nalpha);\n\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\nfinalColor.rgb*=lightmapColor;\n#else\nfinalColor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n\nfinalColor=max(finalColor,0.0);\n#include<logDepthFragment>\n#include<fogFragment>(color,finalColor)\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n\n\nfinalColor.rgb=clamp(finalColor.rgb,0.,30.0);\n#else\n\nfinalColor=applyImageProcessing(finalColor);\n#endif\n#ifdef PREMULTIPLYALPHA\n\nfinalColor.rgb*=finalColor.a;\n#endif\ngl_FragColor=finalColor;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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\nvFogDistance=viewPos;\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}",particlesVertexShader:"\nattribute vec3 position;\nattribute vec4 color;\nattribute vec4 options;\nattribute float cellIndex;\n\nuniform mat4 view;\nuniform mat4 projection;\nuniform vec3 particlesInfos; \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;\n#ifdef ANIMATESHEET\nfloat rowOffset=floor(cellIndex/particlesInfos.z);\nfloat columnOffset=cellIndex-rowOffset*particlesInfos.z;\nvec2 uvScale=particlesInfos.xy;\nvec2 uvOffset=vec2(offset.x ,1.0-offset.y);\nvUV=(uvOffset+vec2(columnOffset,rowOffset))*uvScale;\n#else\nvUV=offset;\n#endif\n\n#ifdef CLIPPLANE\nvec4 worldPos=invView*vec4(viewPos,1.0);\nfClipDistance=dot(worldPos,vClipPlane);\n#endif\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}",gpuRenderParticlesVertexShader:"#version 300 es\n\nin vec3 position;\nin float age;\nin float life;\nin vec3 velocity;\nvoid main() {\ngl_PointSize=1.0;\ngl_Position=vec4(position,1.0);\n}",gpuRenderParticlesPixelShader:"void main() {\ngl_FragColor=vec4(1.0);\n}\n",gpuUpdateParticlesVertexShader:"#version 300 es\nuniform float timeDelta;\n\nin vec3 position;\nin float age;\nin float life;\nin vec3 velocity;\n\nout vec3 outPosition;\nout float outAge;\nout float outLife;\nout vec3 outVelocity;\nvoid main() {\nif (age>=life) {\n\noutPosition=vec3(0,0,0);\n\noutAge=0.0;\noutLife=life;\n\noutVelocity=vec3(0,1,0);\n} else {\noutPosition=position+velocity*timeDelta;\noutAge=age+timeDelta;\noutLife=life;\noutVelocity=velocity;\n}\n}",gpuUpdateParticlesPixelShader:"#version 300 es\nvoid main() {\ndiscard;\n}\n",colorVertexShader:"\nattribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\nuniform mat4 viewProjection;\nuniform mat4 world;\n\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\nvoid main(void) {\nmat4 finalWorld=world;\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n}",colorPixelShader:"#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#else\nuniform vec4 color;\n#endif\nvoid main(void) {\n#ifdef VERTEXCOLOR\ngl_FragColor=vColor;\n#else\ngl_FragColor=color;\n#endif\n}",postprocessVertexShader:"\nattribute vec2 position;\nuniform vec2 scale;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=(position*madd+madd)*scale;\ngl_Position=vec4(position,0.0,1.0);\n}",passPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nvoid main(void) \n{\ngl_FragColor=texture2D(textureSampler,vUV);\n}",shadowMapVertexShader:"\nattribute vec3 position;\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\nuniform vec2 biasAndScale;\nuniform vec2 depthValues;\nvarying float vDepthMetric;\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>\nvec4 worldPos=finalWorld*vec4(position,1.0);\ngl_Position=viewProjection*worldPos;\nvDepthMetric=((gl_Position.z+depthValues.x)/(depthValues.y))+biasAndScale.x;\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}",shadowMapPixelShader:"#ifndef FLOAT\nvec4 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#endif\nvarying float vDepthMetric;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\nuniform vec2 biasAndScale;\nuniform vec2 depthValues;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\nfloat depth=vDepthMetric;\n#ifdef ESM\ndepth=clamp(exp(-min(87.,biasAndScale.y*depth)),0.,1.);\n#endif\n#ifdef FLOAT\ngl_FragColor=vec4(depth,1.0,1.0,1.0);\n#else\ngl_FragColor=pack(depth);\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}",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}",depthVertexShader:"\nattribute vec3 position;\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\nuniform vec2 depthValues;\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\nvarying float vDepthMetric;\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvDepthMetric=((gl_Position.z+depthValues.x)/(depthValues.y));\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}",depthPixelShader:"#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\nvarying float vDepthMetric;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\ngl_FragColor=vec4(vDepthMetric,vDepthMetric*vDepthMetric,0.0,1.0);\n}",ssaoPixelShader:"\nuniform sampler2D textureSampler;\nvarying vec2 vUV;\n#ifdef SSAO\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;\nvec3 normalFromDepth(float depth,vec2 coords)\n{\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#endif\n",ssao2PixelShader:"\nprecision highp float;\nuniform sampler2D textureSampler;\nuniform float near;\nuniform float far;\nuniform float radius;\nvarying vec2 vUV;\nfloat perspectiveDepthToViewZ( const in float invClipZ,const in float near,const in float far ) {\nreturn ( near*far )/( ( far-near )*invClipZ-far );\n}\nfloat viewZToPerspectiveDepth( const in float viewZ,const in float near,const in float far ) {\nreturn ( near*far/viewZ+far)/( far-near );\n}\nfloat viewZToOrthographicDepth( const in float viewZ,const in float near,const in float far ) {\nreturn ( viewZ+near )/( near-far );\n}\n#ifdef SSAO\nuniform sampler2D randomSampler;\nuniform sampler2D normalSampler;\nuniform float randTextureTiles;\nuniform float samplesFactor;\nuniform vec3 sampleSphere[SAMPLES];\nuniform float totalStrength;\nuniform float base;\nuniform float xViewport;\nuniform float yViewport;\nuniform float maxZ;\nuniform float minZAspect;\nuniform vec2 texelSize;\nuniform mat4 projection;\nvoid main()\n{\nvec3 random=texture2D(randomSampler,vUV*randTextureTiles).rgb;\nfloat depth=abs(texture2D(textureSampler,vUV).r);\nvec3 normal=texture2D(normalSampler,vUV).rgb; \nfloat occlusion=0.0;\nfloat correctedRadius=min(radius,minZAspect*depth/near);\nvec3 vViewRay=vec3((vUV.x*2.0-1.0)*xViewport,(vUV.y*2.0-1.0)*yViewport,1.0);\nvec3 origin=vViewRay*depth;\nvec3 rvec=random*2.0-1.0;\nrvec.z=0.0;\nvec3 tangent=normalize(rvec-normal*dot(rvec,normal));\nvec3 bitangent=cross(normal,tangent);\nmat3 tbn=mat3(tangent,bitangent,normal);\nfloat difference;\nif (depth>maxZ) {\ngl_FragColor=vec4(1.0,1.0,1.0,1.0);\nreturn;\n}\nfor (int i=0; i<SAMPLES; ++i) {\n\nvec3 samplePosition=tbn*sampleSphere[i];\nsamplePosition=samplePosition*correctedRadius+origin;\n\nvec4 offset=vec4(samplePosition,1.0);\noffset=projection*offset;\noffset.xyz/=offset.w;\noffset.xy=offset.xy*0.5+0.5;\nif (offset.x<0.0 || offset.y<0.0 || offset.x>1.0 || offset.y>1.0) {\ncontinue;\n}\n\nfloat sampleDepth=abs(texture2D(textureSampler,offset.xy).r);\n\nfloat rangeCheck=abs(depth-sampleDepth)<correctedRadius ? 1.0 : 0.0;\ndifference=samplePosition.z-sampleDepth;\n\nocclusion+=(difference>=1e-5 ? 1.0 : 0.0)*rangeCheck;\n}\n\nfloat ao=1.0-totalStrength*occlusion*samplesFactor;\nfloat result=clamp(ao+base,0.0,1.0);\ngl_FragColor=vec4(vec3(result),1.0);\n}\n#endif\n#ifdef BILATERAL_BLUR\nuniform sampler2D depthSampler;\nuniform float outSize;\nuniform float samplerOffsets[SAMPLES];\nvec4 blur9(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.3846153846)*direction;\nvec2 off2=vec2(3.2307692308)*direction;\ncolor+=texture2D(image,uv)*0.2270270270;\ncolor+=texture2D(image,uv+(off1/resolution))*0.3162162162;\ncolor+=texture2D(image,uv-(off1/resolution))*0.3162162162;\ncolor+=texture2D(image,uv+(off2/resolution))*0.0702702703;\ncolor+=texture2D(image,uv-(off2/resolution))*0.0702702703;\nreturn color;\n}\nvec4 blur13(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.411764705882353)*direction;\nvec2 off2=vec2(3.2941176470588234)*direction;\nvec2 off3=vec2(5.176470588235294)*direction;\ncolor+=texture2D(image,uv)*0.1964825501511404;\ncolor+=texture2D(image,uv+(off1/resolution))*0.2969069646728344;\ncolor+=texture2D(image,uv-(off1/resolution))*0.2969069646728344;\ncolor+=texture2D(image,uv+(off2/resolution))*0.09447039785044732;\ncolor+=texture2D(image,uv-(off2/resolution))*0.09447039785044732;\ncolor+=texture2D(image,uv+(off3/resolution))*0.010381362401148057;\ncolor+=texture2D(image,uv-(off3/resolution))*0.010381362401148057;\nreturn color;\n}\nvec4 blur13Bilateral(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.411764705882353)*direction;\nvec2 off2=vec2(3.2941176470588234)*direction;\nvec2 off3=vec2(5.176470588235294)*direction;\nfloat compareDepth=abs(texture2D(depthSampler,uv).r);\nfloat sampleDepth;\nfloat weight;\nfloat weightSum=30.0;\ncolor+=texture2D(image,uv)*30.0;\nsampleDepth=abs(texture2D(depthSampler,uv+(off1/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off1/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off1/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off1/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv+(off2/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off2/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off2/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off2/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv+(off3/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off3/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off3/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off3/resolution))*weight;\nreturn color/weightSum;\n}\nvoid main()\n{\n#if EXPENSIVE\nfloat compareDepth=abs(texture2D(depthSampler,vUV).r);\nfloat texelsize=1.0/outSize;\nfloat result=0.0;\nfloat weightSum=0.0;\nfor (int i=0; i<SAMPLES; ++i)\n{\n#ifdef BILATERAL_BLUR_H\nvec2 direction=vec2(1.0,0.0);\nvec2 sampleOffset=vec2(texelsize*samplerOffsets[i],0.0);\n#else\nvec2 direction=vec2(0.0,1.0);\nvec2 sampleOffset=vec2(0.0,texelsize*samplerOffsets[i]);\n#endif\nvec2 samplePos=vUV+sampleOffset;\nfloat sampleDepth=abs(texture2D(depthSampler,samplePos).r);\nfloat weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30000.0);\nresult+=texture2D(textureSampler,samplePos).r*weight;\nweightSum+=weight;\n}\nresult/=weightSum;\ngl_FragColor.rgb=vec3(result);\ngl_FragColor.a=1.0;\n#else\nvec4 color;\n#ifdef BILATERAL_BLUR_H\nvec2 direction=vec2(1.0,0.0);\ncolor=blur13Bilateral(textureSampler,vUV,outSize,direction);\n#else\nvec2 direction=vec2(0.0,1.0);\ncolor=blur13Bilateral(textureSampler,vUV,outSize,direction);\n#endif\ngl_FragColor.rgb=vec3(color.r);\ngl_FragColor.a=1.0;\n#endif\n}\n#endif\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",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}",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}",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",standardPixelShader:"uniform sampler2D textureSampler;\nvarying vec2 vUV;\n#if defined(PASS_POST_PROCESS)\nvoid main(void)\n{\nvec4 color=texture2D(textureSampler,vUV);\ngl_FragColor=color;\n}\n#endif\n#if defined(DOWN_SAMPLE_X4)\nuniform vec2 dsOffsets[16];\nvoid main(void)\n{\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(BRIGHT_PASS)\nuniform vec2 dsOffsets[4];\nuniform float brightThreshold;\nvoid main(void)\n{\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(TEXTURE_ADDER)\nuniform sampler2D otherSampler;\nuniform sampler2D lensSampler;\nuniform float exposure;\nvoid main(void)\n{\nvec3 colour=texture2D(textureSampler,vUV).rgb;\ncolour*=exposure;\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;\ncolour+=colour*texture2D(lensSampler,vUV).rgb;\nvec4 finalColor=vec4(colour.rgb,1.0)+texture2D(otherSampler,vUV);\ngl_FragColor=finalColor;\n}\n#endif\n#if defined(VLS)\n#define PI 3.1415926535897932384626433832795\nuniform mat4 shadowViewProjection;\nuniform mat4 lightWorld;\nuniform vec3 cameraPosition;\nuniform vec3 sunDirection;\nuniform vec3 sunColor;\nuniform vec2 depthValues;\nuniform float scatteringCoefficient;\nuniform float scatteringPower;\nuniform sampler2D shadowMapSampler;\nuniform sampler2D positionSampler;\nfloat computeScattering(float lightDotView)\n{\nfloat result=1.0-scatteringCoefficient*scatteringCoefficient;\nresult/=(4.0*PI*pow(1.0+scatteringCoefficient*scatteringCoefficient-(2.0*scatteringCoefficient)*lightDotView,1.5));\nreturn result;\n}\nvoid main(void)\n{\n\nvec3 worldPos=texture2D(positionSampler,vUV).rgb;\nvec3 startPosition=cameraPosition;\nvec3 rayVector=worldPos-startPosition;\nfloat rayLength=length(rayVector);\nvec3 rayDirection=rayVector/rayLength;\nfloat stepLength=rayLength/NB_STEPS;\nvec3 stepL=rayDirection*stepLength;\nvec3 currentPosition=startPosition;\nvec3 accumFog=vec3(0.0);\nfor (int i=0; i<int(NB_STEPS); i++)\n{\nvec4 worldInShadowCameraSpace=shadowViewProjection*vec4(currentPosition,1.0);\nfloat depthMetric=(worldInShadowCameraSpace.z+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depthMetric,0.0,1.0);\nworldInShadowCameraSpace.xyz/=worldInShadowCameraSpace.w;\nworldInShadowCameraSpace.xyz=0.5*worldInShadowCameraSpace.xyz+vec3(0.5);\nfloat shadowMapValue=texture2D(shadowMapSampler,worldInShadowCameraSpace.xy).r;\nif (shadowMapValue>shadowPixelDepth)\naccumFog+=sunColor*computeScattering(dot(rayDirection,sunDirection));\ncurrentPosition+=stepL;\n}\naccumFog/=NB_STEPS;\nvec3 color=accumFog*scatteringPower;\ngl_FragColor=vec4(color*exp(color) ,1.0);\n}\n#endif\n#if defined(VLSMERGE)\nuniform sampler2D originalSampler;\nvoid main(void)\n{\ngl_FragColor=texture2D(originalSampler,vUV)+texture2D(textureSampler,vUV);\n}\n#endif\n#if defined(LUMINANCE)\nuniform vec2 lumOffsets[4];\nvoid main()\n{\nfloat average=0.0;\nvec4 color=vec4(0.0);\nfloat maximum=-1e20;\nvec3 weight=vec3(0.299,0.587,0.114);\nfor (int i=0; i<4; i++)\n{\ncolor=texture2D(textureSampler,vUV+ lumOffsets[i]);\n\nfloat GreyValue=dot(color.rgb,vec3(0.33,0.33,0.33));\n\n#ifdef WEIGHTED_AVERAGE\nfloat GreyValue=dot(color.rgb,weight);\n#endif\n#ifdef BRIGHTNESS\nfloat GreyValue=max(color.r,max(color.g,color.b));\n#endif\n#ifdef HSL_COMPONENT\nfloat GreyValue=0.5*(max(color.r,max(color.g,color.b))+min(color.r,min(color.g,color.b)));\n#endif\n#ifdef MAGNITUDE\nfloat GreyValue=length(color.rgb);\n#endif\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(LUMINANCE_DOWN_SAMPLE)\nuniform vec2 dsOffsets[9];\nuniform float halfDestPixelSize;\n#ifdef FINAL_DOWN_SAMPLER\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()\n{\nvec4 color=vec4(0.0);\nfloat average=0.0;\nfor (int i=0; i<9; i++)\n{\ncolor=texture2D(textureSampler,vUV+vec2(halfDestPixelSize,halfDestPixelSize)+dsOffsets[i]);\naverage+=color.r;\n}\naverage/=9.0;\n#ifdef FINAL_DOWN_SAMPLER\ngl_FragColor=pack(average);\n#else\ngl_FragColor=vec4(average,average,0.0,1.0);\n#endif\n}\n#endif\n#if defined(HDR)\nuniform sampler2D textureAdderSampler;\nuniform float averageLuminance;\nvoid main()\n{\nvec4 color=texture2D(textureAdderSampler,vUV);\nvec4 adjustedColor=color/averageLuminance;\ncolor=adjustedColor;\ncolor.a=1.0;\ngl_FragColor=color;\n}\n#endif\n#if defined(LENS_FLARE)\n#define GHOSTS 3\nuniform sampler2D lensColorSampler;\nuniform float strength;\nuniform float ghostDispersal;\nuniform float haloWidth;\nuniform vec2 resolution;\nuniform float distortionStrength;\nfloat hash(vec2 p)\n{\nfloat h=dot(p,vec2(127.1,311.7));\nreturn -1.0+2.0*fract(sin(h)*43758.5453123);\n}\nfloat noise(in vec2 p)\n{\nvec2 i=floor(p);\nvec2 f=fract(p);\nvec2 u=f*f*(3.0-2.0*f);\nreturn mix(mix(hash(i+vec2(0.0,0.0)),\nhash(i+vec2(1.0,0.0)),u.x),\nmix(hash(i+vec2(0.0,1.0)),\nhash(i+vec2(1.0,1.0)),u.x),u.y);\n}\nfloat fbm(vec2 p)\n{\nfloat f=0.0;\nf+=0.5000*noise(p); p*=2.02;\nf+=0.2500*noise(p); p*=2.03;\nf+=0.1250*noise(p); p*=2.01;\nf+=0.0625*noise(p); p*=2.04;\nf/=0.9375;\nreturn f;\n}\nvec3 pattern(vec2 uv)\n{\nvec2 p=-1.0+2.0*uv;\nfloat p2=dot(p,p);\nfloat f=fbm(vec2(15.0*p2))/2.0;\nfloat r=0.2+0.6*sin(12.5*length(uv-vec2(0.5)));\nfloat g=0.2+0.6*sin(20.5*length(uv-vec2(0.5)));\nfloat b=0.2+0.6*sin(17.2*length(uv-vec2(0.5)));\nreturn (1.0-f)*vec3(r,g,b);\n}\nfloat luminance(vec3 color)\n{\nreturn dot(color.rgb,vec3(0.2126,0.7152,0.0722));\n}\nvec4 textureDistorted(sampler2D tex,vec2 texcoord,vec2 direction,vec3 distortion)\n{\nreturn vec4(\ntexture2D(tex,texcoord+direction*distortion.r).r,\ntexture2D(tex,texcoord+direction*distortion.g).g,\ntexture2D(tex,texcoord+direction*distortion.b).b,\n1.0\n);\n}\nvoid main(void)\n{\nvec2 uv=-vUV+vec2(1.0);\nvec2 ghostDir=(vec2(0.5)-uv)*ghostDispersal;\nvec2 texelSize=1.0/resolution;\nvec3 distortion=vec3(-texelSize.x*distortionStrength,0.0,texelSize.x*distortionStrength);\nvec4 result=vec4(0.0);\nfloat ghostIndice=1.0;\nfor (int i=0; i<GHOSTS; ++i)\n{\nvec2 offset=fract(uv+ghostDir*ghostIndice);\nfloat weight=length(vec2(0.5)-offset)/length(vec2(0.5));\nweight=pow(1.0-weight,10.0);\nresult+=textureDistorted(textureSampler,offset,normalize(ghostDir),distortion)*weight*strength;\nghostIndice+=1.0;\n}\nvec2 haloVec=normalize(ghostDir)*haloWidth;\nfloat weight=length(vec2(0.5)-fract(uv+haloVec))/length(vec2(0.5));\nweight=pow(1.0-weight,10.0);\nresult+=textureDistorted(textureSampler,fract(uv+haloVec),normalize(ghostDir),distortion)*weight*strength;\nresult*=texture2D(lensColorSampler,vec2(length(vec2(0.5)-uv)/length(vec2(0.5))));\ngl_FragColor=result;\n}\n#endif\n#if defined(LENS_FLARE_COMPOSE)\nuniform sampler2D otherSampler;\nuniform sampler2D lensDirtSampler;\nuniform sampler2D lensStarSampler;\nuniform mat4 lensStarMatrix;\nvoid main(void)\n{\nvec2 lensFlareCoords=(lensStarMatrix*vec4(vUV,1.0,1.0)).xy;\nvec4 lensMod=texture2D(lensDirtSampler,vUV);\nlensMod+=texture2D(lensStarSampler,vUV);\nvec4 result=texture2D(textureSampler,vUV)*lensMod;\ngl_FragColor=texture2D(otherSampler,vUV)+result;\n}\n#endif\n#if defined(DEPTH_OF_FIELD)\nuniform sampler2D otherSampler;\nuniform sampler2D depthSampler;\nuniform float distance;\nvoid main(void)\n{\nvec4 sharp=texture2D(otherSampler,vUV);\nvec4 blur=texture2D(textureSampler,vUV);\nfloat dist=clamp(texture2D(depthSampler,vUV).r*distance,0.0,1.0);\nfloat factor=0.0;\nif (dist<0.05)\nfactor=1.0;\nelse if (dist<0.1)\nfactor=20.0*(0.1-dist);\nelse if (dist<0.5)\nfactor=0.0;\nelse\nfactor=2.0*(dist-0.5);\nfactor=clamp(factor,0.0,0.90);\ngl_FragColor=mix(sharp,blur,factor);\n}\n#endif\n#if defined(MOTION_BLUR)\nuniform mat4 inverseViewProjection;\nuniform mat4 prevViewProjection;\nuniform vec2 screenSize;\nuniform float motionScale;\nuniform float motionStrength;\nuniform sampler2D depthSampler;\nvoid main(void)\n{\nvec2 texelSize=1.0/screenSize;\nfloat depth=texture2D(depthSampler,vUV).r;\nvec4 cpos=vec4(vUV*2.0-1.0,depth,1.0);\ncpos=cpos*inverseViewProjection;\nvec4 ppos=cpos*prevViewProjection;\nppos.xyz/=ppos.w;\nppos.xy=ppos.xy*0.5+0.5;\nvec2 velocity=(ppos.xy-vUV)*motionScale*motionStrength;\nfloat speed=length(velocity/texelSize);\nint nSamples=int(clamp(speed,1.0,MAX_MOTION_SAMPLES));\nvec4 result=texture2D(textureSampler,vUV);\nfor (int i=1; i<int(MAX_MOTION_SAMPLES); ++i) {\nif (i>=nSamples)\nbreak;\nvec2 offset1=vUV+velocity*(float(i)/float(nSamples-1)-0.5);\nresult+=texture2D(textureSampler,offset1);\n}\ngl_FragColor=result/float(nSamples);\n}\n#endif\n",fxaaVertexShader:"\nattribute vec2 position;\nuniform vec2 texelSize;\n\nvarying vec2 vUV;\nvarying vec2 sampleCoordS;\nvarying vec2 sampleCoordE;\nvarying vec2 sampleCoordN;\nvarying vec2 sampleCoordW;\nvarying vec2 sampleCoordNW;\nvarying vec2 sampleCoordSE;\nvarying vec2 sampleCoordNE;\nvarying vec2 sampleCoordSW;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=(position*madd+madd);\nsampleCoordS=vUV+vec2( 0.0,1.0)*texelSize;\nsampleCoordE=vUV+vec2( 1.0,0.0)*texelSize;\nsampleCoordN=vUV+vec2( 0.0,-1.0)*texelSize;\nsampleCoordW=vUV+vec2(-1.0,0.0)*texelSize;\nsampleCoordNW=vUV+vec2(-1.0,-1.0)*texelSize;\nsampleCoordSE=vUV+vec2( 1.0,1.0)*texelSize;\nsampleCoordNE=vUV+vec2( 1.0,-1.0)*texelSize;\nsampleCoordSW=vUV+vec2(-1.0,1.0)*texelSize;\ngl_Position=vec4(position,0.0,1.0);\n}",fxaaPixelShader:"uniform sampler2D textureSampler;\nuniform vec2 texelSize;\nvarying vec2 vUV;\nvarying vec2 sampleCoordS;\nvarying vec2 sampleCoordE;\nvarying vec2 sampleCoordN;\nvarying vec2 sampleCoordW;\nvarying vec2 sampleCoordNW;\nvarying vec2 sampleCoordSE;\nvarying vec2 sampleCoordNE;\nvarying vec2 sampleCoordSW;\nconst float fxaaQualitySubpix=1.0;\nconst float fxaaQualityEdgeThreshold=0.166;\nconst float fxaaQualityEdgeThresholdMin=0.0833;\nconst vec3 kLumaCoefficients=vec3(0.2126,0.7152,0.0722);\n#define FxaaLuma(rgba) dot(rgba.rgb,kLumaCoefficients)\nvoid main(){\nvec2 posM;\nposM.x=vUV.x;\nposM.y=vUV.y;\nvec4 rgbyM=texture2D(textureSampler,vUV,0.0);\nfloat lumaM=FxaaLuma(rgbyM);\nfloat lumaS=FxaaLuma(texture2D(textureSampler,sampleCoordS,0.0));\nfloat lumaE=FxaaLuma(texture2D(textureSampler,sampleCoordE,0.0));\nfloat lumaN=FxaaLuma(texture2D(textureSampler,sampleCoordN,0.0));\nfloat lumaW=FxaaLuma(texture2D(textureSampler,sampleCoordW,0.0));\nfloat maxSM=max(lumaS,lumaM);\nfloat minSM=min(lumaS,lumaM);\nfloat maxESM=max(lumaE,maxSM);\nfloat minESM=min(lumaE,minSM);\nfloat maxWN=max(lumaN,lumaW);\nfloat minWN=min(lumaN,lumaW);\nfloat rangeMax=max(maxWN,maxESM);\nfloat rangeMin=min(minWN,minESM);\nfloat rangeMaxScaled=rangeMax*fxaaQualityEdgeThreshold;\nfloat range=rangeMax-rangeMin;\nfloat rangeMaxClamped=max(fxaaQualityEdgeThresholdMin,rangeMaxScaled);\nif(range<rangeMaxClamped) \n{\ngl_FragColor=rgbyM;\nreturn;\n}\nfloat lumaNW=FxaaLuma(texture2D(textureSampler,sampleCoordNW,0.0));\nfloat lumaSE=FxaaLuma(texture2D(textureSampler,sampleCoordSE,0.0));\nfloat lumaNE=FxaaLuma(texture2D(textureSampler,sampleCoordNE,0.0));\nfloat lumaSW=FxaaLuma(texture2D(textureSampler,sampleCoordSW,0.0));\nfloat lumaNS=lumaN+lumaS;\nfloat lumaWE=lumaW+lumaE;\nfloat subpixRcpRange=1.0/range;\nfloat subpixNSWE=lumaNS+lumaWE;\nfloat edgeHorz1=(-2.0*lumaM)+lumaNS;\nfloat edgeVert1=(-2.0*lumaM)+lumaWE;\nfloat lumaNESE=lumaNE+lumaSE;\nfloat lumaNWNE=lumaNW+lumaNE;\nfloat edgeHorz2=(-2.0*lumaE)+lumaNESE;\nfloat edgeVert2=(-2.0*lumaN)+lumaNWNE;\nfloat lumaNWSW=lumaNW+lumaSW;\nfloat lumaSWSE=lumaSW+lumaSE;\nfloat edgeHorz4=(abs(edgeHorz1)*2.0)+abs(edgeHorz2);\nfloat edgeVert4=(abs(edgeVert1)*2.0)+abs(edgeVert2);\nfloat edgeHorz3=(-2.0*lumaW)+lumaNWSW;\nfloat edgeVert3=(-2.0*lumaS)+lumaSWSE;\nfloat edgeHorz=abs(edgeHorz3)+edgeHorz4;\nfloat edgeVert=abs(edgeVert3)+edgeVert4;\nfloat subpixNWSWNESE=lumaNWSW+lumaNESE;\nfloat lengthSign=texelSize.x;\nbool horzSpan=edgeHorz>=edgeVert;\nfloat subpixA=subpixNSWE*2.0+subpixNWSWNESE;\nif (!horzSpan)\n{\nlumaN=lumaW;\n}\nif (!horzSpan) \n{\nlumaS=lumaE;\n}\nif (horzSpan) \n{\nlengthSign=texelSize.y;\n}\nfloat subpixB=(subpixA*(1.0/12.0))-lumaM;\nfloat gradientN=lumaN-lumaM;\nfloat gradientS=lumaS-lumaM;\nfloat lumaNN=lumaN+lumaM;\nfloat lumaSS=lumaS+lumaM;\nbool pairN=abs(gradientN)>=abs(gradientS);\nfloat gradient=max(abs(gradientN),abs(gradientS));\nif (pairN)\n{\nlengthSign=-lengthSign;\n}\nfloat subpixC=clamp(abs(subpixB)*subpixRcpRange,0.0,1.0);\nvec2 posB;\nposB.x=posM.x;\nposB.y=posM.y;\nvec2 offNP;\noffNP.x=(!horzSpan) ? 0.0 : texelSize.x;\noffNP.y=(horzSpan) ? 0.0 : texelSize.y;\nif (!horzSpan) \n{\nposB.x+=lengthSign*0.5;\n}\nif (horzSpan)\n{\nposB.y+=lengthSign*0.5;\n}\nvec2 posN;\nposN.x=posB.x-offNP.x*1.5;\nposN.y=posB.y-offNP.y*1.5;\nvec2 posP;\nposP.x=posB.x+offNP.x*1.5;\nposP.y=posB.y+offNP.y*1.5;\nfloat subpixD=((-2.0)*subpixC)+3.0;\nfloat lumaEndN=FxaaLuma(texture2D(textureSampler,posN,0.0));\nfloat subpixE=subpixC*subpixC;\nfloat lumaEndP=FxaaLuma(texture2D(textureSampler,posP,0.0));\nif (!pairN) \n{\nlumaNN=lumaSS;\n}\nfloat gradientScaled=gradient*1.0/4.0;\nfloat lumaMM=lumaM-lumaNN*0.5;\nfloat subpixF=subpixD*subpixE;\nbool lumaMLTZero=lumaMM<0.0;\nlumaEndN-=lumaNN*0.5;\nlumaEndP-=lumaNN*0.5;\nbool doneN=abs(lumaEndN)>=gradientScaled;\nbool doneP=abs(lumaEndP)>=gradientScaled;\nif (!doneN) \n{\nposN.x-=offNP.x*3.0;\n}\nif (!doneN) \n{\nposN.y-=offNP.y*3.0;\n}\nbool doneNP=(!doneN) || (!doneP);\nif (!doneP) \n{\nposP.x+=offNP.x*3.0;\n}\nif (!doneP)\n{\nposP.y+=offNP.y*3.0;\n}\nif (doneNP)\n{\nif (!doneN) lumaEndN=FxaaLuma(texture2D(textureSampler,posN.xy,0.0));\nif (!doneP) lumaEndP=FxaaLuma(texture2D(textureSampler,posP.xy,0.0));\nif (!doneN) lumaEndN=lumaEndN-lumaNN*0.5;\nif (!doneP) lumaEndP=lumaEndP-lumaNN*0.5;\ndoneN=abs(lumaEndN)>=gradientScaled;\ndoneP=abs(lumaEndP)>=gradientScaled;\nif (!doneN) posN.x-=offNP.x*12.0;\nif (!doneN) posN.y-=offNP.y*12.0;\ndoneNP=(!doneN) || (!doneP);\nif (!doneP) posP.x+=offNP.x*12.0;\nif (!doneP) posP.y+=offNP.y*12.0;\n}\nfloat dstN=posM.x-posN.x;\nfloat dstP=posP.x-posM.x;\nif (!horzSpan)\n{\ndstN=posM.y-posN.y;\n}\nif (!horzSpan) \n{\ndstP=posP.y-posM.y;\n}\nbool goodSpanN=(lumaEndN<0.0) != lumaMLTZero;\nfloat spanLength=(dstP+dstN);\nbool goodSpanP=(lumaEndP<0.0) != lumaMLTZero;\nfloat spanLengthRcp=1.0/spanLength;\nbool directionN=dstN<dstP;\nfloat dst=min(dstN,dstP);\nbool goodSpan=directionN ? goodSpanN : goodSpanP;\nfloat subpixG=subpixF*subpixF;\nfloat pixelOffset=(dst*(-spanLengthRcp))+0.5;\nfloat subpixH=subpixG*fxaaQualitySubpix;\nfloat pixelOffsetGood=goodSpan ? pixelOffset : 0.0;\nfloat pixelOffsetSubpix=max(pixelOffsetGood,subpixH);\nif (!horzSpan)\n{\nposM.x+=pixelOffsetSubpix*lengthSign;\n}\nif (horzSpan)\n{\nposM.y+=pixelOffsetSubpix*lengthSign;\n}\ngl_FragColor=texture2D(textureSampler,posM,0.0);\n}",geometryVertexShader:"precision highp float;\nprecision highp int;\n#include<bonesDeclaration>\n#include<instancesDeclaration>\nattribute vec3 position;\nattribute vec3 normal;\n#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nvarying vec2 uv;\n#endif\n#ifdef UV2\nvarying vec2 uv2;\n#endif\n#endif\n\nuniform mat4 viewProjection;\nuniform mat4 view;\nvarying vec3 vNormalV;\nvarying vec4 vViewPos;\n#ifdef POSITION\nvarying vec3 vPosition;\n#endif\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\nvec4 pos=vec4(finalWorld*vec4(position,1.0));\nvNormalV=normalize(vec3((view*finalWorld)*vec4(normal,0.0)));\nvViewPos=view*pos;\n#ifdef POSITION\nvPosition=pos.xyz/pos.w;\n#endif\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}",geometryPixelShader:"#extension GL_EXT_draw_buffers : require\nprecision highp float;\nprecision highp int;\nvarying vec3 vNormalV;\nvarying vec4 vViewPos;\n#ifdef POSITION\nvarying vec3 vPosition;\n#endif\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef POSITION\n#include<mrtFragmentDeclaration>[3]\n#else\n#include<mrtFragmentDeclaration>[2]\n#endif\nvoid main() {\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\ngl_FragData[0]=vec4(vViewPos.z/vViewPos.w,0.0,0.0,1.0);\n\ngl_FragData[1]=vec4(normalize(vNormalV),1.0);\n\n#ifdef POSITION\ngl_FragData[2]=vec4(vPosition,1.0);\n#endif\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}",blackAndWhitePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform float degree;\nvoid main(void) \n{\nvec3 color=texture2D(textureSampler,vUV).rgb;\nfloat luminance=dot(color,vec3(0.3,0.59,0.11)); \nvec3 blackAndWhite=vec3(luminance,luminance,luminance);\ngl_FragColor=vec4(color-((color-blackAndWhite)*degree),1.0);\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}",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}",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 dataSample=texture2D(lightScatteringSampler,tc)*0.4;\ndataSample*=illuminationDecay*weight;\ncolor+=dataSample;\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",colorCorrectionPixelShader:"\nuniform sampler2D textureSampler; \nuniform sampler2D colorTable; \n\nvarying vec2 vUV;\n\nconst float SLICE_COUNT=16.0; \n\nvec4 sampleAs3DTexture(sampler2D textureSampler,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(textureSampler,vec2(s0,uv.y));\nvec4 slice1Color=texture2D(textureSampler,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}",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}",displayPassPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D passSampler;\nvoid main(void)\n{\ngl_FragColor=texture2D(passSampler,vUV);\n}",highlightsPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nconst vec3 RGBLuminanceCoefficients=vec3(0.2126,0.7152,0.0722);\nvoid main(void) \n{\nvec4 tex=texture2D(textureSampler,vUV);\nvec3 c=tex.rgb;\nfloat luma=dot(c.rgb,RGBLuminanceCoefficients);\n\n\ngl_FragColor=vec4(pow(c,vec3(25.0-luma*15.0)),tex.a); \n}",imageProcessingPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n#include<imageProcessingDeclaration>\n#include<helperFunctions>\n#include<imageProcessingFunctions>\nvoid main(void)\n{\nvec4 result=texture2D(textureSampler,vUV);\n#ifdef IMAGEPROCESSING\n#ifndef FROMLINEARSPACE\n\nresult.rgb=toLinearSpace(result.rgb);\n#endif\nresult=applyImageProcessing(result);\n#else\n\n#ifdef FROMLINEARSPACE\nresult=applyImageProcessing(result);\n#endif\n#endif\ngl_FragColor=result;\n}",kernelBlurVertexShader:"\nattribute vec2 position;\n\nuniform vec2 delta;\n\nvarying vec2 sampleCenter;\n#include<kernelBlurVaryingDeclaration>[0..varyingCount]\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nsampleCenter=(position*madd+madd);\n#include<kernelBlurVertex>[0..varyingCount]\ngl_Position=vec4(position,0.0,1.0);\n}",kernelBlurPixelShader:"\nuniform sampler2D textureSampler;\nuniform vec2 delta;\n\nvarying vec2 sampleCenter;\n#include<kernelBlurVaryingDeclaration>[0..varyingCount]\n#ifdef PACKEDFLOAT\nvec4 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}\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#endif\nvoid main(void)\n{\n#ifdef PACKEDFLOAT \nfloat blend=0.;\n#else\nvec4 blend=vec4(0.);\n#endif\n#include<kernelBlurFragment>[0..varyingCount]\n#include<kernelBlurFragment2>[0..depCount]\n#ifdef PACKEDFLOAT\ngl_FragColor=pack(blend);\n#else\ngl_FragColor=blend;\n#endif\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}",lensFlarePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec4 color;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\ngl_FragColor=baseColor*color;\n}",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}",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}",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,0.0);\nelse{\ngl_FragColor=texture2D(textureSampler,tc);\n}\n}",glowBlurPostProcessPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec2 screenSize;\nuniform vec2 direction;\nuniform float blurWidth;\n\nfloat getLuminance(vec3 color)\n{\nreturn dot(color,vec3(0.2126,0.7152,0.0722));\n}\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{\n\nvec4 texel=texture2D(textureSampler,start+texelOffset);\nbaseColor.a+=texel.a*weights[i];\n\nfloat luminance=getLuminance(baseColor.rgb);\nfloat luminanceTexel=getLuminance(texel.rgb);\nfloat choice=step(luminanceTexel,luminance);\nbaseColor.rgb=choice*baseColor.rgb+(1.0-choice)*texel.rgb;\ntexelOffset+=texelStep;\n}\ngl_FragColor=baseColor;\n}",glowMapGenerationPixelShader:"#ifdef ALPHATEST\nvarying vec2 vUVDiffuse;\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;\nuniform sampler2D emissiveSampler;\n#endif\nuniform vec4 color;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUVDiffuse).a<0.4)\ndiscard;\n#endif\n#ifdef EMISSIVE\ngl_FragColor=texture2D(emissiveSampler,vUVEmissive);\n#else\ngl_FragColor=color;\n#endif\n}",glowMapGenerationVertexShader:"\nattribute vec3 position;\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\nvarying vec4 vPosition;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef ALPHATEST\nvarying vec2 vUVDiffuse;\nuniform mat4 diffuseMatrix;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;\nuniform mat4 emissiveMatrix;\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 DIFFUSEUV1\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef DIFFUSEUV2\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#ifdef EMISSIVE\n#ifdef EMISSIVEUV1\nvUVEmissive=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef EMISSIVEUV2\nvUVEmissive=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",glowMapMergePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform float offset;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\nbaseColor.a=abs(offset-baseColor.a);\ngl_FragColor=baseColor;\n}",glowMapMergeVertexShader:"\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}",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}",linePixelShader:"uniform vec4 color;\nvoid main(void) {\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\n#include<logDepthDeclaration>\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#include<logDepthVertex>\n}\n",outlinePixelShader:"#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nuniform vec4 color;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\n#include<logDepthFragment>\ngl_FragColor=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}",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}",backgroundVertexShader:"precision highp float;\n#include<__decl__backgroundVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2; \n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\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\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normal);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(position,0.0)));\n#endif\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif \n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0 \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\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",backgroundPixelShader:"#ifdef TEXTURELODSUPPORT\n#extension GL_EXT_shader_texture_lod : enable\n#endif\nprecision highp float;\n#include<__decl__backgroundFragment>\n\nuniform vec3 vEyePosition;\n\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2; \n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n\n#ifndef SHADOWONLY\n#define SHADOWONLY;\n#endif\n#include<imageProcessingDeclaration>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<helperFunctions>\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<imageProcessingFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n#ifdef REFLECTIONFRESNEL\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\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#endif\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(0.0,1.0,0.0);\n#endif\n\nfloat shadow=1.;\nfloat globalShadow=0.;\nfloat shadowLightCount=0.;\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef SHADOWINUSE\nglobalShadow/=shadowLightCount;\n#else\nglobalShadow=1.0;\n#endif\n\nvec3 reflectionColor=vec3(1.,1.,1.);\n#ifdef REFLECTION\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\n\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords=reflectionVector;\n#else\nvec2 reflectionCoords=reflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nreflectionCoords/=reflectionVector.z;\n#endif\nreflectionCoords.y=1.0-reflectionCoords.y;\n#endif\n#ifdef REFLECTIONBLUR\nfloat reflectionLOD=vReflectionInfos.y;\n#ifdef TEXTURELODSUPPORT\n\nreflectionLOD=reflectionLOD*log2(vReflectionMicrosurfaceInfos.x)*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;\nreflectionColor=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD).rgb;\n#else\nfloat lodReflectionNormalized=clamp(reflectionLOD,0.,1.);\nfloat lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;\nvec3 reflectionSpecularMid=sampleReflection(reflectionSampler,reflectionCoords).rgb;\nif(lodReflectionNormalizedDoubled<1.0){\nreflectionColor=mix(\nsampleReflection(reflectionSamplerHigh,reflectionCoords).rgb,\nreflectionSpecularMid,\nlodReflectionNormalizedDoubled\n);\n} else {\nreflectionColor=mix(\nreflectionSpecularMid,\nsampleReflection(reflectionSamplerLow,reflectionCoords).rgb,\nlodReflectionNormalizedDoubled-1.0\n);\n}\n#endif\n#else\nvec4 reflectionSample=sampleReflection(reflectionSampler,reflectionCoords);\nreflectionColor=reflectionSample.rgb;\n#endif\n#ifdef GAMMAREFLECTION\nreflectionColor=toLinearSpace(reflectionColor.rgb);\n#endif\n\nreflectionColor*=vReflectionInfos.x;\n#endif\n\nvec3 diffuseColor=vec3(1.,1.,1.);\nfloat finalAlpha=alpha;\n#ifdef DIFFUSE\nvec4 diffuseMap=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef GAMMADIFFUSE\ndiffuseMap.rgb=toLinearSpace(diffuseMap.rgb);\n#endif\n\ndiffuseMap.rgb*=vDiffuseInfos.y;\n#ifdef DIFFUSEHASALPHA\nfinalAlpha*=diffuseMap.a;\n#endif\ndiffuseColor=diffuseMap.rgb;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nvec3 colorBase=diffuseColor;\n#else\nvec3 colorBase=reflectionColor*diffuseColor;\n#endif\ncolorBase=max(colorBase,0.0);\n\n#ifdef USERGBCOLOR\nvec3 finalColor=colorBase;\n#else\nvec3 finalColor=colorBase.r*vPrimaryColor.rgb*vPrimaryColor.a;\nfinalColor+=colorBase.g*vSecondaryColor.rgb*vSecondaryColor.a;\nfinalColor+=colorBase.b*vTertiaryColor.rgb*vTertiaryColor.a;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nvec3 reflectionAmount=vReflectionControl.xxx;\nvec3 reflectionReflectance0=vReflectionControl.yyy;\nvec3 reflectionReflectance90=vReflectionControl.zzz;\nfloat VdotN=dot(normalize(vEyePosition),normalW);\nvec3 planarReflectionFresnel=fresnelSchlickEnvironmentGGX(clamp(VdotN,0.0,1.0),reflectionReflectance0,reflectionReflectance90,1.0);\nreflectionAmount*=planarReflectionFresnel;\n#ifdef REFLECTIONFALLOFF\nfloat reflectionDistanceFalloff=1.0-clamp(length(vPositionW.xyz-vBackgroundCenter)*vReflectionControl.w,0.0,1.0);\nreflectionDistanceFalloff*=reflectionDistanceFalloff;\nreflectionAmount*=reflectionDistanceFalloff;\n#endif\nfinalColor=mix(finalColor,reflectionColor,clamp(reflectionAmount,0.,1.));\n#endif\n#ifdef OPACITYFRESNEL\nfloat viewAngleToFloor=dot(normalW,normalize(vEyePosition-vBackgroundCenter));\n\nconst float startAngle=0.1;\nfloat fadeFactor=clamp(viewAngleToFloor/startAngle,0.0,1.0);\nfinalAlpha*=fadeFactor*fadeFactor;\n#endif\n\n#ifdef SHADOWINUSE\nfinalColor=mix(finalColor*shadowLevel,finalColor,globalShadow);\n#endif\n\nvec4 color=vec4(finalColor,finalAlpha);\n#include<fogFragment>\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n\n\ncolor.rgb=clamp(color.rgb,0.,30.0);\n#else\n\ncolor=applyImageProcessing(color);\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\n#ifdef NOISE\ncolor.rgb=dither(vPositionW.xy,color.rgb);\n#endif\ngl_FragColor=color;\n}"},s.Effect.IncludesShadersStore={depthPrePass:"#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);\nreturn;\n#endif",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",instancesDeclaration:"#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif",pointCloudVertexDeclaration:"#ifdef POINTSIZE\nuniform float pointSize;\n#endif",bumpVertexDeclaration:"#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n",clipPlaneVertexDeclaration:"#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif",fogVertexDeclaration:"#ifdef FOG\nvarying vec3 vFogDistance;\n#endif",morphTargetsVertexGlobalDeclaration:"#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif",morphTargetsVertexDeclaration:"#ifdef MORPHTARGETS\nattribute vec3 position{X};\n#ifdef MORPHTARGETS_NORMAL\nattribute vec3 normal{X};\n#endif\n#ifdef MORPHTARGETS_TANGENT\nattribute vec3 tangent{X};\n#endif\n#endif",logDepthDeclaration:"#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif",morphTargetsVertex:"#ifdef MORPHTARGETS\npositionUpdated+=(position{X}-position)*morphTargetInfluences[{X}];\n#ifdef MORPHTARGETS_NORMAL\nnormalUpdated+=(normal{X}-normal)*morphTargetInfluences[{X}];\n#endif\n#ifdef MORPHTARGETS_TANGENT\ntangentUpdated.xyz+=(tangent{X}-tangent.xyz)*morphTargetInfluences[{X}];\n#endif\n#endif",instancesVertex:"#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\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",bumpVertex:"#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL)\nvec3 tbnNormal=normalize(normalUpdated);\nvec3 tbnTangent=normalize(tangentUpdated.xyz);\nvec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;\nvTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);\n#endif\n#endif",clipPlaneVertex:"#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif",fogVertex:"#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif",shadowsVertex:"#ifdef SHADOWS\n#if defined(SHADOW{X}) && !defined(SHADOWCUBE{X})\nvPositionFromLight{X}=lightMatrix{X}*worldPos;\nvDepthMetric{X}=((vPositionFromLight{X}.z+light{X}.depthValues.x)/(light{X}.depthValues.y));\n#endif\n#endif",pointCloudVertex:"#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif",logDepthVertex:"#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif",helperFunctions:"const float PI=3.1415926535897932384626433832795;\nconst float LinearEncodePowerApprox=2.2;\nconst float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;\nconst vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);\nmat3 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}\n\nmat3 inverseMat3(mat3 inMatrix) {\nfloat a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];\nfloat a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];\nfloat a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];\nfloat b01=a22*a11-a12*a21;\nfloat b11=-a22*a10+a12*a20;\nfloat b21=a21*a10-a11*a20;\nfloat det=a00*b01+a01*b11+a02*b21;\nreturn mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),\nb11,(a22*a00-a02*a20),(-a12*a00+a02*a10),\nb21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;\n}\nfloat computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)\n{\nfloat mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));\nreturn mix(value,1.0,mask);\n}\nvec3 applyEaseInOut(vec3 x){\nreturn x*x*(3.0-2.0*x);\n}\nvec3 toLinearSpace(vec3 color)\n{\nreturn pow(color,vec3(LinearEncodePowerApprox));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn pow(color,vec3(GammaEncodePowerApprox));\n}\nfloat square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,LuminanceEncodeApprox),0.,1.);\n}\n\nfloat getRand(vec2 seed) {\nreturn fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);\n}\nvec3 dither(vec2 seed,vec3 color) {\nfloat rand=getRand(seed);\ncolor.rgb+=mix(-0.5/255.0,0.5/255.0,rand);\nreturn color;\n}",lightFragmentDeclaration:"#ifdef LIGHT{X}\nuniform vec4 vLightData{X};\nuniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular{X};\n#else\nvec3 vLightSpecular{X}=vec3(0.);\n#endif\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};\nuniform vec2 depthValues{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#ifdef NDOTL\nfloat ndl;\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));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\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,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\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}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\n#ifdef NDOTL\nresult.ndl=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;\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\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",lightUboDeclaration:"#ifdef LIGHT{X}\nuniform Light{X}\n{\nvec4 vLightData;\nvec4 vLightDiffuse;\nvec3 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;\n#endif\n#ifdef HEMILIGHT{X}\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;\nvec2 depthValues;\n} light{X};\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif",defaultVertexDeclaration:"\nuniform mat4 viewProjection;\nuniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n",defaultFragmentDeclaration:"uniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;\n\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifndef REFRACTIONMAP_3D\nuniform mat4 refractionMatrix;\n#endif\n#ifdef REFRACTIONFRESNEL\nuniform vec4 refractionLeftColor;\nuniform vec4 refractionRightColor;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\n#endif\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_SKYBOX\n#else\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n#endif",defaultUboDeclaration:"layout(std140,column_major) uniform;\nuniform Material\n{\nvec4 diffuseLeftColor;\nvec4 diffuseRightColor;\nvec4 opacityParts;\nvec4 reflectionLeftColor;\nvec4 reflectionRightColor;\nvec4 refractionLeftColor;\nvec4 refractionRightColor;\nvec4 emissiveLeftColor; \nvec4 emissiveRightColor;\nvec2 vDiffuseInfos;\nvec2 vAmbientInfos;\nvec2 vOpacityInfos;\nvec2 vReflectionInfos;\nvec2 vEmissiveInfos;\nvec2 vLightmapInfos;\nvec2 vSpecularInfos;\nvec3 vBumpInfos;\nmat4 diffuseMatrix;\nmat4 ambientMatrix;\nmat4 opacityMatrix;\nmat4 reflectionMatrix;\nmat4 emissiveMatrix;\nmat4 lightmapMatrix;\nmat4 specularMatrix;\nmat4 bumpMatrix; \nvec4 vTangentSpaceParams;\nmat4 refractionMatrix;\nvec4 vRefractionInfos;\nvec4 vSpecularColor;\nvec3 vEmissiveColor;\nvec4 vDiffuseColor;\nfloat pointSize; \n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};",shadowsFragmentFunctions:"#ifdef SHADOWS\n#ifndef SHADOWFLOAT\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#endif\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadow=textureCube(shadowSampler,directionToLight).x;\n#endif\nif (depth>shadow)\n{\nreturn darkness;\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\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\n#ifndef SHADOWFLOAT\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<depth) visibility-=0.25;\n#else\nif (textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize).x<depth) visibility-=0.25;\n#endif\nreturn min(1.0,visibility+darkness);\n}\nfloat computeShadowWithESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness); \nreturn esm;\n}\nfloat computeShadowWithCloseESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn esm;\n}\nfloat computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadow=texture2D(shadowSampler,uv).x;\n#endif\nif (shadowPixelDepth>shadow)\n{\nreturn computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff);\n}\nreturn 1.;\n}\nfloat computeShadowWithPCF(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\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\n#ifndef SHADOWFLOAT\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[1]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[2]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[3]*mapSize))<shadowPixelDepth) visibility-=0.25;\n#else\nif (texture2D(shadowSampler,uv+poissonDisk[0]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[1]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[2]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[3]*mapSize).x<shadowPixelDepth) visibility-=0.25;\n#endif\nreturn computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0); \n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\n#endif\n",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",reflectionFunction:"vec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)\n{\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_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;\n#ifdef REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED\nreturn vec3(1.0-s,t,0);\n#else\nreturn vec3(s,t,0);\n#endif\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR\nvec3 cameraToVertex=normalize(worldPos.xyz-vEyePosition.xyz);\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.xyz;\nvec3 coords=normalize(reflect(viewDir,worldNormal));\nreturn vec3(reflectionMatrix*vec4(coords,1));\n#endif\n#ifdef REFLECTIONMAP_CUBIC\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\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}",imageProcessingDeclaration:"#ifdef EXPOSURE\nuniform float exposureLinear;\n#endif\n#ifdef CONTRAST\nuniform float contrast;\n#endif\n#ifdef VIGNETTE\nuniform vec2 vInverseScreenSize;\nuniform vec4 vignetteSettings1;\nuniform vec4 vignetteSettings2;\n#endif\n#ifdef COLORCURVES\nuniform vec4 vCameraColorCurveNegative;\nuniform vec4 vCameraColorCurveNeutral;\nuniform vec4 vCameraColorCurvePositive;\n#endif\n#ifdef COLORGRADING\n#ifdef COLORGRADING3D\nuniform highp sampler3D txColorTransform;\n#else\nuniform sampler2D txColorTransform;\n#endif\nuniform vec4 colorTransformSettings;\n#endif",imageProcessingFunctions:"#if defined(COLORGRADING) && !defined(COLORGRADING3D)\n\nvec3 sampleTexture3D(sampler2D colorTransform,vec3 color,vec2 sampler3dSetting)\n{\nfloat sliceSize=2.0*sampler3dSetting.x; \n#ifdef SAMPLER3DGREENDEPTH\nfloat sliceContinuous=(color.g-sampler3dSetting.x)*sampler3dSetting.y;\n#else\nfloat sliceContinuous=(color.b-sampler3dSetting.x)*sampler3dSetting.y;\n#endif\nfloat sliceInteger=floor(sliceContinuous);\n\n\nfloat sliceFraction=sliceContinuous-sliceInteger;\n#ifdef SAMPLER3DGREENDEPTH\nvec2 sliceUV=color.rb;\n#else\nvec2 sliceUV=color.rg;\n#endif\nsliceUV.x*=sliceSize;\nsliceUV.x+=sliceInteger*sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice0Color=texture2D(colorTransform,sliceUV);\nsliceUV.x+=sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice1Color=texture2D(colorTransform,sliceUV);\nvec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);\n#ifdef SAMPLER3DBGRMAP\ncolor.rgb=result.rgb;\n#else\ncolor.rgb=result.bgr;\n#endif\nreturn color;\n}\n#endif\nvec4 applyImageProcessing(vec4 result) {\n#ifdef EXPOSURE\nresult.rgb*=exposureLinear;\n#endif\n#ifdef VIGNETTE\n\nvec2 viewportXY=gl_FragCoord.xy*vInverseScreenSize;\nviewportXY=viewportXY*2.0-1.0;\nvec3 vignetteXY1=vec3(viewportXY*vignetteSettings1.xy+vignetteSettings1.zw,1.0);\nfloat vignetteTerm=dot(vignetteXY1,vignetteXY1);\nfloat vignette=pow(vignetteTerm,vignetteSettings2.w);\n\nvec3 vignetteColor=vignetteSettings2.rgb;\n#ifdef VIGNETTEBLENDMODEMULTIPLY\nvec3 vignetteColorMultiplier=mix(vignetteColor,vec3(1,1,1),vignette);\nresult.rgb*=vignetteColorMultiplier;\n#endif\n#ifdef VIGNETTEBLENDMODEOPAQUE\nresult.rgb=mix(vignetteColor,result.rgb,vignette);\n#endif\n#endif\n#ifdef TONEMAPPING\nconst float tonemappingCalibration=1.590579;\nresult.rgb=1.0-exp2(-tonemappingCalibration*result.rgb);\n#endif\n\nresult.rgb=toGammaSpace(result.rgb);\nresult.rgb=clamp(result.rgb,0.0,1.0);\n#ifdef CONTRAST\n\nvec3 resultHighContrast=applyEaseInOut(result.rgb);\nif (contrast<1.0) {\n\nresult.rgb=mix(vec3(0.5,0.5,0.5),result.rgb,contrast);\n} else {\n\nresult.rgb=mix(result.rgb,resultHighContrast,contrast-1.0);\n}\n#endif\n\n#ifdef COLORGRADING\nvec3 colorTransformInput=result.rgb*colorTransformSettings.xxx+colorTransformSettings.yyy;\n#ifdef COLORGRADING3D\nvec3 colorTransformOutput=texture(txColorTransform,colorTransformInput).rgb;\n#else\nvec3 colorTransformOutput=sampleTexture3D(txColorTransform,colorTransformInput,colorTransformSettings.yz).rgb;\n#endif\nresult.rgb=mix(result.rgb,colorTransformOutput,colorTransformSettings.www);\n#endif\n#ifdef COLORCURVES\n\nfloat luma=getLuminance(result.rgb);\nvec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0),vec2(1.0));\nvec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;\nresult.rgb*=colorCurve.rgb;\nresult.rgb=mix(vec3(luma),result.rgb,colorCurve.a);\n#endif\nreturn result;\n}",bumpFragmentFunctions:"#ifdef BUMP\n#if BUMPDIRECTUV == 1\n#define vBumpUV vMainUV1\n#elif BUMPDIRECTUV == 2\n#define vBumpUV vMainUV2\n#else\nvarying vec2 vBumpUV;\n#endif\nuniform sampler2D bumpSampler;\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nuv=gl_FrontFacing ? uv : -uv;\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 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;\n\ntangent*=vTangentSpaceParams.x;\nbitangent*=vTangentSpaceParams.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));\nreturn mat3(tangent*invmax,bitangent*invmax,normal);\n}\nvec3 perturbNormal(mat3 cotangentFrame,vec2 uv)\n{\nvec3 map=texture2D(bumpSampler,uv).xyz;\nmap=map*2.0-1.0;\n#ifdef NORMALXYSCALE\nmap=normalize(map*vec3(vBumpInfos.y,vBumpInfos.y,1.0));\n#endif\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",clipPlaneFragmentDeclaration:"#ifdef CLIPPLANE\nvarying float fClipDistance;\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 vec3 vFogDistance;\nfloat CalcFogFactor()\n{\nfloat fogCoeff=1.0;\nfloat fogStart=vFogInfos.y;\nfloat fogEnd=vFogInfos.z;\nfloat fogDensity=vFogInfos.w;\nfloat fogDistance=length(vFogDistance);\nif (FOGMODE_LINEAR == vFogInfos.x)\n{\nfogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);\n}\nelse if (FOGMODE_EXP == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDensity);\n}\nelse if (FOGMODE_EXP2 == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);\n}\nreturn clamp(fogCoeff,0.0,1.0);\n}\n#endif",clipPlaneFragment:"#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif",bumpFragment:"vec2 uvOffset=vec2(0.0,0.0);\n#if defined(BUMP) || defined(PARALLAX)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\n#else \nfloat normalScale=vBumpInfos.y;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#else\nmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,vBumpUV);\n#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\n#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\n#endif\n#ifdef BUMP\nnormalW=perturbNormal(TBN,vBumpUV+uvOffset);\n#endif",lightFragment:"#ifdef LIGHT{X}\n#if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X}))\n\n#else\n#ifdef PBR\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,glossiness);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCLOSEESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithCloseESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithCloseESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else\n#ifdef SHADOWESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else \n#ifdef SHADOWPCF{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithPCFCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadowWithPCF(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#endif\n#endif\n#endif\n#ifdef SHADOWONLY\n#ifndef SHADOWINUSE\n#define SHADOWINUSE\n#endif\nglobalShadow+=shadow;\nshadowLightCount+=1.0;\n#endif\n#else\nshadow=1.;\n#endif\n#ifndef SHADOWONLY\n#ifdef CUSTOMUSERLIGHTING\ndiffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);\n#ifdef SPECULARTERM\nspecularBase+=computeCustomSpecularLighting(info,specularBase,shadow);\n#endif\n#elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\ndiffuseBase+=lightmapColor*shadow;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nspecularBase+=info.specular*shadow*lightmapColor;\n#endif\n#endif\n#else\ndiffuseBase+=info.diffuse*shadow;\n#ifdef SPECULARTERM\nspecularBase+=info.specular*shadow;\n#endif\n#endif\n#endif\n#endif",logDepthFragment:"#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif",fogFragment:"#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif",pbrVertexDeclaration:"uniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef ALBEDO\nuniform mat4 albedoMatrix;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec3 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#ifdef REFLECTIVITY \nuniform vec3 vReflectivityInfos;\nuniform mat4 reflectivityMatrix;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\nuniform mat4 microSurfaceSamplerMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\nuniform mat4 refractionMatrix;\nuniform vec3 vRefractionMicrosurfaceInfos;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n",pbrFragmentDeclaration:"uniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\n\nuniform vec4 vLightingIntensity;\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\n\n#ifdef ALBEDO\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform vec3 vAmbientInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef REFLECTIVITY\nuniform vec3 vReflectivityInfos;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\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;\nuniform mat4 refractionMatrix;\nuniform vec3 vRefractionMicrosurfaceInfos;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif",pbrUboDeclaration:"layout(std140,column_major) uniform;\nuniform Material\n{\nuniform vec2 vAlbedoInfos;\nuniform vec3 vAmbientInfos;\nuniform vec2 vOpacityInfos;\nuniform vec2 vEmissiveInfos;\nuniform vec2 vLightmapInfos;\nuniform vec3 vReflectivityInfos;\nuniform vec2 vMicroSurfaceSamplerInfos;\nuniform vec4 vRefractionInfos;\nuniform vec2 vReflectionInfos;\nuniform vec3 vBumpInfos;\nuniform mat4 albedoMatrix;\nuniform mat4 ambientMatrix;\nuniform mat4 opacityMatrix;\nuniform mat4 emissiveMatrix;\nuniform mat4 lightmapMatrix;\nuniform mat4 reflectivityMatrix;\nuniform mat4 microSurfaceSamplerMatrix;\nuniform mat4 bumpMatrix;\nuniform vec2 vTangentSpaceParams;\nuniform mat4 refractionMatrix;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\nuniform vec4 vLightingIntensity;\nuniform vec3 vRefractionMicrosurfaceInfos;\nuniform vec3 vReflectionMicrosurfaceInfos;\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\nuniform float pointSize;\n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};",pbrFunctions:"\n#define RECIPROCAL_PI2 0.15915494\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\n\nconst float kRougnhessToAlphaScale=0.1;\nconst float kRougnhessToAlphaOffset=0.29248125;\nfloat convertRoughnessToAverageSlope(float roughness)\n{\n\nconst float kMinimumVariance=0.0005;\nfloat alphaG=square(roughness)+kMinimumVariance;\nreturn alphaG;\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/(PI*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 reflectance0,vec3 reflectance90)\n{\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\nfloat distribution=normalDistributionFunction_TrowbridgeReitzGGX(NdotH,alphaG);\nfloat visibility=smithVisibilityG_TrowbridgeReitzGGX_Walter(NdotL,NdotV,alphaG);\nvisibility/=(4.0*NdotL*NdotV); \nfloat specTerm=max(0.,visibility*distribution)*NdotL;\nvec3 fresnel=fresnelSchlickGGX(VdotH,reflectance0,reflectance90);\nreturn fresnel*specTerm;\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 fresnel =\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNL) *\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNV);\nreturn fresnel*NdotL/PI;\n}\nfloat adjustRoughnessFromLightProperties(float roughness,float lightRadius,float lightDistance)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\n\nfloat lightRoughness=lightRadius/lightDistance;\n\nfloat totalRoughness=clamp(lightRoughness+roughness,0.,1.);\nreturn totalRoughness;\n#else\nreturn roughness;\n#endif\n}\nfloat computeDefaultMicroSurface(float microSurface,vec3 reflectivityColor)\n{\nconst float kReflectivityNoAlphaWorkflow_SmoothnessMax=0.95;\nfloat reflectivityLuminance=getLuminance(reflectivityColor);\nfloat reflectivityLuma=sqrt(reflectivityLuminance);\nmicroSurface=reflectivityLuma*kReflectivityNoAlphaWorkflow_SmoothnessMax;\nreturn microSurface;\n}\n\n\nfloat fresnelGrazingReflectance(float reflectance0) {\nfloat reflectance90=clamp(reflectance0*25.0,0.0,1.0);\nreturn reflectance90;\n}\n\n\n#define UNPACK_LOD(x) (1.0-x)*255.0\nfloat getLodFromAlphaG(float cubeMapDimensionPixels,float alphaG,float NdotV) {\nfloat microsurfaceAverageSlope=alphaG;\n\n\n\n\n\n\nmicrosurfaceAverageSlope*=sqrt(abs(NdotV));\nfloat microsurfaceAverageSlopeTexels=microsurfaceAverageSlope*cubeMapDimensionPixels;\nfloat lod=log2(microsurfaceAverageSlopeTexels);\nreturn lod;\n}\nfloat environmentRadianceOcclusion(float ambientOcclusion,float NdotVUnclamped) {\n\n\nfloat temp=NdotVUnclamped+ambientOcclusion;\nreturn clamp(square(temp)-1.0+ambientOcclusion,0.0,1.0);\n}\nfloat environmentHorizonOcclusion(vec3 reflection,vec3 normal) {\n\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflection.z*=-1.0;\n#endif\nfloat temp=clamp( 1.0+1.1*dot(reflection,normal),0.0,1.0);\nreturn square(temp);\n}",harmonicsFunctions:"#ifdef USESPHERICALFROMREFLECTIONMAP\nuniform vec3 vSphericalX;\nuniform vec3 vSphericalY;\nuniform vec3 vSphericalZ;\nuniform vec3 vSphericalXX_ZZ;\nuniform vec3 vSphericalYY_ZZ;\nuniform vec3 vSphericalZZ;\nuniform vec3 vSphericalXY;\nuniform vec3 vSphericalYZ;\nuniform vec3 vSphericalZX;\nvec3 quaternionVectorRotation_ScaledSqrtTwo(vec4 Q,vec3 V){\nvec3 T=cross(Q.xyz,V);\nT+=Q.www*V;\nreturn cross(Q.xyz,T)+V;\n}\nvec3 environmentIrradianceJones(vec3 normal)\n{\n\n\n\n\n\n\n\n\n\nfloat Nx=normal.x;\nfloat Ny=normal.y;\nfloat Nz=normal.z;\nvec3 C1=vSphericalZZ.rgb;\nvec3 Cx=vSphericalX.rgb;\nvec3 Cy=vSphericalY.rgb;\nvec3 Cz=vSphericalZ.rgb;\nvec3 Cxx_zz=vSphericalXX_ZZ.rgb;\nvec3 Cyy_zz=vSphericalYY_ZZ.rgb;\nvec3 Cxy=vSphericalXY.rgb;\nvec3 Cyz=vSphericalYZ.rgb;\nvec3 Czx=vSphericalZX.rgb;\nvec3 a1=Cyy_zz*Ny+Cy;\nvec3 a2=Cyz*Nz+a1;\nvec3 b1=Czx*Nz+Cx;\nvec3 b2=Cxy*Ny+b1;\nvec3 b3=Cxx_zz*Nx+b2;\nvec3 t1=Cz*Nz+C1;\nvec3 t2=a2*Ny+t1;\nvec3 t3=b3*Nx+t2;\nreturn t3;\n}\n#endif",pbrLightFunctions:"\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n};\nfloat computeDistanceLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range)\n{ \n#ifdef USEPHYSICALLIGHTFALLOFF\nfloat lightDistanceFalloff=1.0/((lightDistanceSquared+0.001));\n#else\nfloat lightDistanceFalloff=max(0.,1.0-length(lightOffset)/range);\n#endif\nreturn lightDistanceFalloff;\n}\nfloat computeDirectionalLightFalloff(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle,float exponent)\n{\nfloat falloff=0.0;\n#ifdef USEPHYSICALLIGHTFALLOFF\nconst float kMinusLog2ConeAngleIntensityRatio=6.64385618977; \n\n\n\n\n\nfloat concentrationKappa=kMinusLog2ConeAngleIntensityRatio/(1.0-cosHalfAngle);\n\n\nvec4 lightDirectionSpreadSG=vec4(-lightDirection*concentrationKappa,-concentrationKappa);\nfalloff=exp2(dot(vec4(directionToLightCenterW,1.0),lightDirectionSpreadSG));\n#else\nfloat cosAngle=max(0.000000000000001,dot(-lightDirection,directionToLightCenterW));\nif (cosAngle>=cosHalfAngle)\n{\nfalloff=max(0.,pow(cosAngle,exponent));\n}\n#endif\nreturn falloff;\n}\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float rangeRadius,float roughness,float NdotV,vec3 reflectance0,vec3 reflectance90,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=computeDistanceLightFalloff(lightOffset,lightDistanceSquared,rangeRadius);\nlightDistance=sqrt(lightDistanceSquared);\nlightDirection=normalize(lightOffset);\n}\n\nelse\n{\nlightDistance=length(-lightData.xyz);\nlightDirection=normalize(-lightData.xyz);\n}\n\nroughness=adjustRoughnessFromLightProperties(roughness,rangeRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+lightDirection);\nNdotL=clamp(dot(vNormal,lightDirection),0.00000000001,1.0);\nfloat VdotH=clamp(dot(viewDirectionW,H),0.0,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=clamp(dot(vNormal,H),0.000000000001,1.0);\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,reflectance0,reflectance90);\nresult.specular=specTerm*diffuseColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float rangeRadius,float roughness,float NdotV,vec3 reflectance0,vec3 reflectance90,out float NdotL) {\nlightingInfo result;\nvec3 lightOffset=lightData.xyz-vPositionW;\nvec3 directionToLightCenterW=normalize(lightOffset);\n\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nfloat attenuation=computeDistanceLightFalloff(lightOffset,lightDistanceSquared,rangeRadius);\n\nfloat directionalAttenuation=computeDirectionalLightFalloff(lightDirection.xyz,directionToLightCenterW,lightDirection.w,lightData.w);\nattenuation*=directionalAttenuation;\n\nfloat lightDistance=sqrt(lightDistanceSquared);\nroughness=adjustRoughnessFromLightProperties(roughness,rangeRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+directionToLightCenterW);\nNdotL=clamp(dot(vNormal,directionToLightCenterW),0.000000000001,1.0);\nfloat VdotH=clamp(dot(viewDirectionW,H),0.0,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=clamp(dot(vNormal,H),0.000000000001,1.0);\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,reflectance0,reflectance90);\nresult.specular=specTerm*diffuseColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float roughness,float NdotV,vec3 reflectance0,vec3 reflectance90,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=clamp(dot(vNormal,H),0.000000000001,1.0);\nNdotL=clamp(NdotL,0.000000000001,1.0);\nfloat VdotH=clamp(dot(viewDirectionW,H),0.0,1.0);\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,reflectance0,reflectance90);\nresult.specular=specTerm*diffuseColor;\n#endif\nreturn result;\n}",mrtFragmentDeclaration:"#if __VERSION__>=200\nlayout(location=0) out vec4 glFragData[{X}];\n#endif\n",bones300Declaration:"#if NUM_BONE_INFLUENCERS>0\nuniform mat4 mBones[BonesPerMesh];\nin vec4 matricesIndices;\nin vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nin vec4 matricesIndicesExtra;\nin vec4 matricesWeightsExtra;\n#endif\n#endif",instances300Declaration:"#ifdef INSTANCES\nin vec4 world0;\nin vec4 world1;\nin vec4 world2;\nin vec4 world3;\n#else\nuniform mat4 world;\n#endif",kernelBlurFragment:"#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCoord{X}))*KERNEL_WEIGHT{X};\n#else\nblend+=texture2D(textureSampler,sampleCoord{X})*KERNEL_WEIGHT{X};\n#endif",kernelBlurFragment2:"#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X}))*KERNEL_DEP_WEIGHT{X};\n#else\nblend+=texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X})*KERNEL_DEP_WEIGHT{X};\n#endif",kernelBlurVaryingDeclaration:"varying vec2 sampleCoord{X};",kernelBlurVertex:"sampleCoord{X}=sampleCenter+delta*KERNEL_OFFSET{X};",backgroundVertexDeclaration:"uniform mat4 view;\nuniform mat4 viewProjection;\nuniform float shadowLevel;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif",backgroundFragmentDeclaration:" uniform vec4 vPrimaryColor;\nuniform vec4 vSecondaryColor;\nuniform vec4 vTertiaryColor;\nuniform float shadowLevel;\nuniform float alpha;\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n#if defined(REFLECTIONFRESNEL) || defined(OPACITYFRESNEL)\nuniform vec3 vBackgroundCenter;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 vReflectionControl;\n#endif",backgroundUboDeclaration:"layout(std140,column_major) uniform;\nuniform Material\n{\nuniform vec4 vPrimaryColor;\nuniform vec4 vSecondaryColor;\nuniform vec4 vTertiaryColor;\nuniform vec2 vDiffuseInfos;\nuniform vec2 vReflectionInfos;\nuniform mat4 diffuseMatrix;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\nuniform float pointSize;\nuniform float shadowLevel;\nuniform float alpha;\n#if defined(REFLECTIONFRESNEL) || defined(OPACITYFRESNEL)\nuniform vec3 vBackgroundCenter;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 vReflectionControl;\n#endif\n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};"},function(i,r){var n=r();i&&i.BABYLON||((void 0!==t?t:"undefined"!=typeof window?window:this).BABYLON=n,e.exports=n)}(this,function(){return s})}).call(t,i(1))},function(e,t){var i;i=function(){return this}();try{i=i||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(0),n=i(3),o=function(){function e(){}return e.prototype.map=function(e){for(var t={},i=0;i<e.attributes.length;++i)!function(i){var r=e.attributes.item(i),o=r.nodeName.split(".");o.reduce(function(e,t,i){var s=n.kebabToCamel(t);if(i===o.length-1){var a=r.nodeValue;if("true"===a)a=!0;else if("false"===a)a=!1;else{var l=parseFloat(a);isNaN(l)||(a=l)}e[s]=a}else e[s]=e[s]||{};return e[s]},t)}(i);return t},e}(),s=function(){function e(){}return e.prototype.map=function(e){return JSON.parse(e)},e}(),a=function(){function e(){}return e.prototype.map=function(e){var t=new o,i=t.map(e),r=function(e,i){var o=e.children;if(o.length)for(var s=0;s<o.length;++s){var a=o.item(s),l=t.map(a),h=n.kebabToCamel(a.nodeName.toLowerCase());a.attributes.getNamedItem("array")&&"true"===a.attributes.getNamedItem("array").nodeValue?i[h]=[]:e.attributes.getNamedItem("array")&&"true"===e.attributes.getNamedItem("array").nodeValue?i.push(l):i[h]?(e.setAttribute("array","true"),i=[i[h],l]):i[h]=l,r(a,i[h]||l)}return i};return r(e,i),i},e}(),l=function(){function e(){this.mappers={html:new o,json:new s,dom:new a}}return e.prototype.getMapper=function(t){return this.mappers[t]||r.Tools.Error("No mapper defined for "+t),this.mappers[t]||this.mappers[e.DefaultMapper]},e.prototype.registerMapper=function(e,t){this.mappers[e]=t},e.DefaultMapper="json",e}();t.MapperManager=l,t.mapperManager=new l,t.default=t.mapperManager},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isUrl=function(e){return 0===e.indexOf("http")||0===e.indexOf("/")||0===e.indexOf("./")||0===e.indexOf("../")},t.loadFile=function(e){return new Promise(function(t,i){var r=new XMLHttpRequest;r.open("GET",e),r.send(),r.onreadystatechange=function(){4===r.readyState?200===r.status&&t(r.responseText):(console.log("Error: "+r.status,e),i("Error: "+r.status))}})},t.kebabToCamel=function(e){return e.replace(/(\-\w)/g,function(e){return e[1].toUpperCase()})},t.camelToKebab=function(e){return e?e.replace(/([A-Z])/g,function(e){return"-"+e[0].toLowerCase()}):null}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(0),n=function(){function e(){this.viewers={},this.onViewerAddedObservable=new r.Observable}return e.prototype.addViewer=function(e){this.viewers[e.getBaseId()]=e,this._onViewerAdded(e)},e.prototype.getViewerById=function(e){return this.viewers[e]},e.prototype.getViewerByHTMLElement=function(e){for(var t in this.viewers)if(this.viewers[t].containerElement===e)return this.getViewerById(t)},e.prototype.getViewerPromiseById=function(e){var t=this;return new Promise(function(i,r){var n=t.getViewerById(e);if(n)return i(n);var o=function(r){r.getBaseId()===e&&(i(r),t.onViewerAddedObservable.removeCallback(o))};t.onViewerAddedObservable.add(o)})},e.prototype._onViewerAdded=function(e){this.onViewerAdded&&this.onViewerAdded(e),this.onViewerAddedObservable.notifyObservers(e)},e}();t.viewerManager=new n},function(e,t,i){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])};return function(t,i){function r(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}();Object.defineProperty(t,"__esModule",{value:!0});var n=i(6),o=i(0),s=i(0);window.BABYLON=s;var a=function(e){function t(t,i){void 0===i&&(i={extends:"default"});var r=e.call(this,t,i)||this;return r.containerElement=t,r.onModelLoaded=function(e){return r.setModelMetaData(),setTimeout(function(){r.hideLoadingScreen()},500),r.scene.createDefaultCameraOrLight(!0,!0,!0),r.camera=r.scene.activeCamera,e[0].rotation.y+=Math.PI,r.setupCamera(e),r.setupLights(e),r.initEnvironment()},r.onModelLoadedObservable.add(r.onModelLoaded),r}return r(t,e),t.prototype.initScene=function(){var t=this;return e.prototype.initScene.call(this).then(function(){return t.extendClassWithConfig(t.scene,t.configuration.scene),t.scene})},t.prototype.onTemplatesLoaded=function(){var t=this;this.showLoadingScreen();var i=this.templateManager.getTemplate("viewer"),r=this.templateManager.getTemplate("navBar");if(i&&r){var n,o=r.parent.clientHeight+"px",s=!0,a=function(e,t){if(void 0===e&&(e=!1),r&&!(t.button>0)&&(n&&clearTimeout(n),e!==s))if(e)r.parent.style.bottom=e?"0px":"-"+o,s=e;else{var i=2e3;r.configuration.params&&void 0!==r.configuration.params.visibilityTimeout&&(i=r.configuration.params.visibilityTimeout),n=setTimeout(function(){r&&(r.parent.style.bottom="-"+o),s=e},i)}};i.parent.addEventListener("pointerout",a.bind(this,!1)),i.parent.addEventListener("pointerdown",a.bind(this,!0)),i.parent.addEventListener("pointerup",a.bind(this,!1)),r.parent.addEventListener("pointerover",a.bind(this,!0)),this.registerNavbarButtons()}var l=document.getElementById("close-button");return l&&l.addEventListener("pointerdown",function(){t.hideOverlayScreen()}),e.prototype.onTemplatesLoaded.call(this)},t.prototype.registerNavbarButtons=function(){var e=this,t=!1,i=this.templateManager.getTemplate("navBar"),r=this.templateManager.getTemplate("viewer");if(i&&r){var n=r.parent;i.onEventTriggered.add(function(i){switch(i.event.type){case"pointerdown":if(0===i.event.button)switch(i.selector){case"#fullscreen-button":t?(document.exitFullscreen||document.webkitExitFullscreen).call(document):(n.requestFullscreen||n.webkitRequestFullscreen||n.msRequestFullscreen||n.mozRequestFullScreen).call(n),t=!t;break;case"#help-button":e.showOverlayScreen("help")}}})}},t.prototype.prepareContainerElement=function(){this.containerElement.style.position="relative",this.containerElement.style.display="flex"},t.prototype.loadModel=function(t){var i=this;return void 0===t&&(t=this.configuration.model),this.showLoadingScreen(),e.prototype.loadModel.call(this,t,!0).catch(function(e){return console.log(e),i.hideLoadingScreen(),i.showOverlayScreen("error"),i.scene})},t.prototype.setModelMetaData=function(){var e=this.templateManager.getTemplate("navBar");if(e){var t=e.parent.querySelector("#model-metadata");if(t&&"object"==typeof this.configuration.model){if(this.configuration.model.title&&(i=t.querySelector("span.model-title"))&&(i.innerHTML=this.configuration.model.title),this.configuration.model.subtitle){var i=t.querySelector("span.model-subtitle");i&&(i.innerHTML=this.configuration.model.subtitle)}this.configuration.model.thumbnail&&(t.querySelector(".thumbnail").style.backgroundImage="url('"+this.configuration.model.thumbnail+"')")}}},t.prototype.initEnvironment=function(){if(this.configuration.skybox){var e=void 0;if(this.configuration.skybox.cubeTexture&&(e="string"==typeof this.configuration.skybox.cubeTexture.url?o.CubeTexture.CreateFromPrefilteredData(this.configuration.skybox.cubeTexture.url,this.scene):o.CubeTexture.CreateFromImages(this.configuration.skybox.cubeTexture.url,this.scene,this.configuration.skybox.cubeTexture.noMipMap)),e){this.extendClassWithConfig(e,this.configuration.skybox.cubeTexture);var t=this.configuration.skybox.scale||this.scene.activeCamera&&(this.scene.activeCamera.maxZ-this.scene.activeCamera.minZ)/2||1,i=this.scene.createDefaultSkybox(e,this.configuration.skybox.pbr,t,this.configuration.skybox.blur);this.configuration.skybox.material&&this.configuration.skybox.material.imageProcessingConfiguration&&i&&(i.material.imageProcessingConfiguration=new o.ImageProcessingConfiguration),this.extendClassWithConfig(i,this.configuration.skybox)}}if(this.configuration.ground){var r="boolean"==typeof this.configuration.ground?{}:this.configuration.ground,n=o.Mesh.CreateGround("ground",r.size||1e3,r.size||1e3,8,this.scene);!0===this.configuration.ground||r.shadowOnly?n.material=new o.ShadowOnlyMaterial("groundmat",this.scene):n.material=new o.StandardMaterial("groundmat",this.scene),!0===this.configuration.ground&&(n.receiveShadows=!0,n.material.alpha=.4),this.extendClassWithConfig(n,r)}return Promise.resolve(this.scene)},t.prototype.showOverlayScreen=function(e){var t=this,i=this.templateManager.getTemplate("overlay");return i?i.show(function(i){var r=t.containerElement.getBoundingClientRect();window.getComputedStyle(t.containerElement).position;i.parent.style.display="flex",i.parent.style.width=r.width+"px",i.parent.style.height=r.height+"px",i.parent.style.opacity="1";var n=t.templateManager.getTemplate(e);return n?n.show(function(e){return e.parent.style.display="flex",Promise.resolve(e)}):Promise.reject(e+" template not found")}):Promise.reject("Overlay template not found")},t.prototype.hideOverlayScreen=function(){var e=this.templateManager.getTemplate("overlay");return e?e.hide(function(e){e.parent.style.opacity="0";var t=function(){e.parent.removeEventListener("transitionend",t),e.parent.style.display="none"};e.parent.addEventListener("transitionend",t);var i=e.parent.querySelectorAll(".overlay");if(i)for(var r=0;r<i.length;++r)i.item(r).style.display="none";return Promise.resolve(e)}):Promise.reject("Overlay template not found")},t.prototype.showLoadingScreen=function(){var e=this,t=this.templateManager.getTemplate("loadingScreen");return t?t.show(function(t){var i=e.containerElement.getBoundingClientRect();window.getComputedStyle(e.containerElement).position;return t.parent.style.display="flex",t.parent.style.width=i.width+"px",t.parent.style.height=i.height+"px",t.parent.style.opacity="1",t.parent.style.backgroundColor="black",Promise.resolve(t)}):Promise.reject("oading Screen template not found")},t.prototype.hideLoadingScreen=function(){var e=this.templateManager.getTemplate("loadingScreen");return e?e.hide(function(e){e.parent.style.opacity="0";var t=function(){e.parent.removeEventListener("transitionend",t),e.parent.style.display="none"};return e.parent.addEventListener("transitionend",t),Promise.resolve(e)}):Promise.reject("oading Screen template not found")},t.prototype.setupLights=function(e){var t=this;void 0===e&&(e=[]),!(this.configuration.scene||{defaultLight:!0}).defaultLight&&this.configuration.lights&&Object.keys(this.configuration.lights).length&&(this.scene.lights.forEach(function(e){e.dispose()}),Object.keys(this.configuration.lights).forEach(function(i,r){var n=t.configuration.lights&&t.configuration.lights[i]||{name:i,type:0};n.name=i;var a=o.Light.GetConstructorFromName(n.type,n.name,t.scene);if(a){var l=a();if(l.isEnabled()!==!n.disabled&&l.setEnabled(!n.disabled),t.extendClassWithConfig(l,n),l instanceof o.ShadowLight&&n.shadowEnabled){var h=new s.ShadowGenerator(512,l);t.extendClassWithConfig(h,n.shadowConfig||{});var u=h.getShadowMap();if(!u)return;for(var c=u.renderList,f=0;f<e.length;f++)c&&c.push(e[f])}}}))},t.prototype.setupCamera=function(e){void 0===e&&(e=[]);var t=this.configuration.camera||{},i=this.configuration.scene||{autoRotate:!1,defaultCamera:!0};if(this.configuration.camera||!i.defaultCamera){if(t.position&&this.camera.position.copyFromFloats(t.position.x||0,t.position.y||0,t.position.z||0),t.rotation&&(this.camera.rotationQuaternion=new o.Quaternion(t.rotation.x||0,t.rotation.y||0,t.rotation.z||0,t.rotation.w||0)),this.camera.minZ=t.minZ||this.camera.minZ,this.camera.maxZ=t.maxZ||this.camera.maxZ,t.behaviors)for(var r in t.behaviors)this.setCameraBehavior(t.behaviors[r],e);i.autoRotate&&(this.camera.useAutoRotationBehavior=!0)}else i.autoRotate&&(this.camera.useAutoRotationBehavior=!0)},t.prototype.setCameraBehavior=function(e,t){var i,r="object"!=typeof e?e:e.type,n="object"==typeof e?e:{};switch(r){case 0:i=new o.AutoRotationBehavior;break;case 1:i=new o.BouncingBehavior;break;case 2:i=new o.FramingBehavior;break;default:i=null}switch(i&&("object"==typeof e&&this.extendClassWithConfig(i,e),this.camera.addBehavior(i)),r){case 0:case 1:break;case 2:if(n.zoomOnBoundingInfo){var s=t[0].getHierarchyBoundingVectors();i.zoomOnBoundingInfo(s.min,s.max)}}},t.prototype.extendClassWithConfig=function(e,t){var i=this;t&&Object.keys(t).forEach(function(r){if(r in e&&"function"!=typeof e[r]){if("function"==typeof e[r])return;"object"==typeof e[r]?i.extendClassWithConfig(e[r],t[r]):e[r]=t[r]}})},t}(n.AbstractViewer);t.DefaultViewer=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(4),n=i(17),o=i(19),s=i(0),a=i(28),l=function(){function e(e,t){void 0===t&&(t={});var i=this;this.containerElement=e,e.id?this.baseId=e.id:this.baseId=e.id="bjs"+Math.random().toString(32).substr(2,8),this.onSceneInitObservable=new a.PromiseObservable,this.onEngineInitObservable=new a.PromiseObservable,this.onModelLoadedObservable=new a.PromiseObservable,r.viewerManager.addViewer(this),this.templateManager=new n.TemplateManager(e),this.prepareContainerElement(),o.default.loadConfiguration(t).then(function(e){i.configuration=e,i.configuration.observers&&(i.configuration.observers.onEngineInit&&i.onEngineInitObservable.add(window[i.configuration.observers.onEngineInit]),i.configuration.observers.onSceneInit&&i.onSceneInitObservable.add(window[i.configuration.observers.onSceneInit]),i.configuration.observers.onModelLoaded&&i.onModelLoadedObservable.add(window[i.configuration.observers.onModelLoaded]));var t=i.configuration.templates||{};i.templateManager.initTemplate(t),i.templateManager.onAllLoaded.add(function(){i.onTemplatesLoaded()})})}return e.prototype.getBaseId=function(){return this.baseId},e.prototype.onTemplatesLoaded=function(){var e=this;return this.initEngine().then(function(){return e.loadModel()}).then(function(){return e})},e.prototype.initEngine=function(){var e=this,t=this.templateManager.getCanvas();if(!t)return Promise.reject("Canvas element not found!");var i=this.configuration.engine||{};this.engine=new s.Engine(t,!!i.antialiasing),s.Database.IDBStorageEnabled=!1,window.addEventListener("resize",function(){e.engine.resize()}),this.engine.runRenderLoop(function(){e.scene&&e.scene.render()});var r=Math.max(.5,1/(window.devicePixelRatio||2));return this.engine.setHardwareScalingLevel(r),this.onEngineInitObservable.notifyWithPromise(this.engine).then(function(){return e.engine})},e.prototype.initScene=function(){var e=this;return this.scene&&this.scene.dispose(),this.scene=new s.Scene(this.engine),this.scene.createDefaultCameraOrLight(!0,!0,!0),this.configuration.scene&&this.configuration.scene.debug&&this.scene.debugLayer.show(),this.onSceneInitObservable.notifyWithPromise(this.scene).then(function(){return e.scene})},e.prototype.loadModel=function(e,t){var i=this;void 0===e&&(e=this.configuration.model),void 0===t&&(t=!0);var r=("string"==typeof e?e:e.url).split("/"),n=r.pop(),o=r.join("/")+"/",a="string"==typeof e?void 0:e.loader;return Promise.resolve().then(function(){return!i.scene||t?i.initScene():i.scene}).then(function(){return new Promise(function(e,t){s.SceneLoader.ImportMesh(void 0,o,n,i.scene,function(t){e(t)},void 0,function(e,i,r){console.log(i,r),t(i)},a)})}).then(function(e){return i.onModelLoadedObservable.notifyWithPromise(e).then(function(){return i.scene})})},e}();t.AbstractViewer=l},function(e,t){e.exports="<viewer></viewer>\r\n<loading-screen></loading-screen>\r\n<overlay></overlay>"},function(e,t){e.exports='<style>\r\n /* Loading Screen element */\r\n\r\n loading-screen {\r\n position: absolute;\r\n z-index: 100;\r\n opacity: 1;\r\n pointer-events: none;\r\n display: flex;\r\n justify-content: center;\r\n align-items: center;\r\n -webkit-transition: opacity 2s ease;\r\n -moz-transition: opacity 2s ease;\r\n transition: opacity 2s ease;\r\n }\r\n\r\n img.loading-image {\r\n -webkit-animation: spin 2s linear infinite;\r\n animation: spin 2s linear infinite;\r\n }\r\n\r\n @-webkit-keyframes spin {\r\n 0% {\r\n -webkit-transform: rotate(0deg);\r\n }\r\n 100% {\r\n -webkit-transform: rotate(360deg);\r\n }\r\n }\r\n\r\n @keyframes spin {\r\n 0% {\r\n transform: rotate(0deg);\r\n }\r\n 100% {\r\n transform: rotate(360deg);\r\n }\r\n }\r\n</style>\r\n\r\n<img class="loading-image" src="{{loadingImage}}">'},function(e,t){e.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTZEaa/1AAAYq0lEQVR4Xu2dCZRcVZnHScAJUZSwjSOIbAJmEAZwQCCMoAInYRGIg8AwegQx7AFzUBBmzAFlE4EAwxz2GRk2w7AnAURZBiEOZgyEQDAQAjmEJqTpNd3V1V3Vmd+/6utKV7/1vnpVXd2p/zn3vOV+27vfu/fd/W3QQAPrBZqbm7fJZrN79vf3T+/r67uf4wO9vb37WXQDIwWtra0Tenp6voQTv5XP56/BkfcR3iLk1g6B7hEeI+zP5V+ZiAbqBZ2dnZ8lV+6Gg87CobfhpOc4byf0FjwYE9DneBkWcXrM2tmzNzTxDdQKJPyETCazI46YgiMuI9zJuXJltuChFIHsP/PSfIfTjU19A2mira1tcxy3ey6XO5vEnkV4kes11XBmENDVj97XOT2O03FmWgMuoNLzGRJva8IUnPkzjjcT/kLoKCZzfQB7XiX8M2G8md7AUJgzJ+Z6e88gZ1xGuj3HsY17PcVkrG9gp7CUF/F8PUvxqdZDrFq1ahNVfKjwTCYxZuDE2wjKlc2WViMePM+HPNsFPOdf22OPblD5OZQHvphnV65cjTMzxaQY3eA5V9OO/hmnm1lSjE7woFsQbiXki4++foHnXkW4mLC1JUl947333tsMY3emqfB9jtPJlXN5U0+bOXPmWCPxgOccSy4+AfqPio+9/oFnbyatbqVE28GSZfjQ1NT0KQzaHMcdyPfyaNoE12HcvdxT29K3Fkv8A2vWrPmcifAFZNtD91yRY+SBZ+9UsMtEgD+jTpeenp6JXI6xpKkuUDqRcA6Kr0Wpens+InQTnIpV6Fdi+BQT64ulS5eOIzefD62na7CeoGcnLCM8ykt5OWlzcPv772/BS/w3nP+K+xU11+DvQe5dcrQlTfWAwbNMb8XA8AyGX80xtLlA6TAJuteMbVhhia1v5VMcr+LWMeoZ4xiYw7q6urbhHbgG+paCkIRQehHu4pO3O5fVydEomF5Ulx548JfVD2wqfKE2I3R3ob/f2GoC1DWhdz7HG3i5j2pvb9+Z24m6HvVZQtYsZFWcowlzePEP4jJdR/OQhxTVpAs9NMXxmZxuZKo8IG4s+v8R2tUFphSBTBWzH+OAFwn/gS3TuN55xYoVqfc6dXd3fwHZ1xFaTX0iyGbwjJqXXAammxP00EXx6UMGEx7ram7+vKnzBZ/87Xiwp40tEdDTgYwlHG/CmadSjO7L+XiialOZAej7POFG2VK0Khngl6Pn8/LL0YEtlFh4n8oDAqvaAYH8tzH2iNDm1IIFn8Ax50G7xtgCAU07CfAG4RHOz+vLZL7e0dGxlYlKHaj8BHo25xgrsfV5wrYH4KmouxV+ZZDnCUdwmXxMGgFvFUVWD+jQuOot6rI0tb4gcfaG9v+MrcAn+wj38gL8C7cObmlp2ZRjOkWYD6ypuAf6zjFHLSJ0c/6YQ813DM/yZXgehreiVgP8cvSfsOeExYsXuzs6n8v9j8mqBRZQmdjXVPuira1NHSpn8UDf4Xu0vd2uCtDzacJOlDDf5ng94X8JTWarB8R1EK7ju7udiYgEz/v3pLFKm4oHUHhh3iZdfshpaEYpA4pvKLLXBujLYKRq71XLhUHg27z12rW9B6L/QhLrWWxRH7nzeDK8awi/5HRTEx0K6MZQ694LHk0DqrgfADkreIYz1q5c+UlTEQzesIuMryrggYQWjNL3RGO7p2tuFMeqjaOidgzyCz1yJMTJ6L6d66WEVCcHIO/dQkI75Chs2g97Hoc3jRz9Lge1ED5l4r0gckqRPB0gTw34t1B+h3IqxZkmrn2SULUa7ezZszdE5xfR9130Xsm5ilrnHrmkQOcKvrkncxqrIiY6wlewbw7BOUfDo/b84zzvj9C7J7eCS0NrUiRKCPjUE7ScMBdlF/B2HqBi0ERXBcuXL99YnQz9fX2ah3Up4UnsWGEmDRuUhoTn+Z5PfvbZZ2N/fuCZRJgnfhNVBu73EZoIKt7l0L2UBsYeDZg016nb5EUCWuXQewinUtTuyq2aTStF14a8SD+VDQVj6hDYxjuXf4Hjl83sSMCmTp8j4FtoMuRQ5dAZcii3kk/0s2bBhxIcBxjxUlib1hWInEDO/6qKV+y4geO5HAMntEE/pq+nZyo0ywsG1SmwL4Orf+0yqGCfmvR73LAn9lAeBjQTEhkA+1h49a08iRflcq4H5iuXFU9cz4lqihC/LXS/NZa6Bc+pz5gql5ub6VXD2tZWTSPeyS7XgeLhXrMnEhj6MSHSwaIhFGZH8oA/JzzFeexvJbRN2HW03moT6cEChx6w4QY2rurn85JWrxsiCy0FwjcIqos8w7GZNPulkawDEbFHlaBtjzODEDrVztuKXMmADPWA3RaljyJeNdKq98ilAez8iJdyGqfO31V4NoV/EvyaCqR54V2EshE5Lqcb+TrkstkTLD4WKB4PNNZQ8P05HAelMXNSPWChC8JsYvwthJo0jSoF6fIqjjqe08Aat+LIkd+AVjn09zxbZFqK3tjXAUbXUaWDjTUSyN4J45YZX2Igo4cEOVfFson2ALIxSjR0jog5YNgpfNHM90BxIjDyWIB8Z2NfB01HISJ20wPaw4w1FlavXq1v8aPGXhFw9JNRFTDItifU/RwwpfmKxYsDK180kU4x0lhAXvOSJUs+bezlIDL2N4xi4GpjK4MGCuzUA+SPxzn3m4iKgKyV2DCV08DeMWg0B+zHHOt2DpjS3Mz1BfFOM25C5ZH4LxldJBB0g7GVARkaXgv8VsKqZtIMPpN9RUnJgRzU5Wfp22vifcG3+2vQvmdsdQXsX2pm+oKX+GYjjQXkPWqsXshpRhcJ0RpbGShSHiSuheP37ZYHsGusVHOrU1lMxkO9od4eE+8LlSzQqfetpnPAooBN/2Um+gISp89MkF8K4G3RrMJYoOhbYGxlQEGhSOGogfoLwipExGtUZVVBYIVAluaAaUpuWA+YujlPF22Ra/iBLYEOsV6tV4w0FiitfmLsXiBMU0NiAVrfsp77Zd8MHPgbDoHtva6uLs1jiv1piAKy5tCG+4KJ9wVO/p6RDzvy+b5rzSwP9Okh/WKPERiCWzfk4K8bUSTiOljAyCdx5DZG4gE8W5Dov+NYUfsV/j50fUC4dmXIQDh0qQ6PVgJsOcLM8oA410Ggvo6Ojr81di+g2TKuQOiyJOKWxlpCJpM5zUjKAL3awTsamQfEbYhjtDGKa5tPsyn/wAuiURftlBO56h6aunEwCMxxvV1d+2Fr7Jce2vAu5LUtLeoGi/19gtbToCaR97BoD6BvUs+WkXqgbw6OuhC6wH5l4rRGaCFOvYnjYbyxnpcsCvDVhYOxo6+zszNwSNHVTtJEmSiwzlMAQmNPwIPW42Dds2hfEK/5WJo0Fth+5VNxFHSlkoTzFRh/N3wnq0OGWxXtdoO8enFwaI4jsyidYgNZTxhrMEjEJ4w+En65ESWRXZ7Q4K/COqDAPlhka87WedB8KawmngTIHREOJs5pMiRp+p/GGgxL1FiA9hxjK6G1tVVdhJGAV15+cPXq1f7dahVC20Wg4miCp0uTe3Xh4Hwu93rY1B7SR/t7xQbP5R1FGgpy8IlKe+MJhZ9Aa7u5jPm+pGLX2BMDOZ+hDXgQiXIJ5xoXHZg96anEEFcvOTi0SMUXS4w0FijSTzTWYEA3hkTSEtDI2qw6RoytDLA6jctCvzKqJ8oPFOO7kAhnYe9cZGiWiZ/N9ezguWaSL4h3TUfvKJIfoN0I4sjigYSdZyxlcDVMgEczEY41ER6oZFBOh2Yqegf2zYoziFC3DuZZrjSTPLDtMlxaNPmPP/54W2OPxksrVozP5fLPGr8vEOpbxJCr3jQSJyDvGRNRhv7iHh8vE5LMpKznHBz4zSTOaXwe+mXGGh9tbWvVQf+iyfCAON/ZlTj4v43ECfB94Le4CuMrWVpTtw7O9fZOM5M8oD7xVSOLBdLuNWN1g7bgJUF8+4qpBjf7Te9M6hD4tBDc0289Wh2MHbuaSR7gsHOMLBaQ9W/G6o5MJrNDPu9dcYdQ33Yc95I6OFV5hnp2cGCliDingX5KU+9MShd0dmqta/k8J4zwnV2JsuuNxAnI83VwNpO52kiSoC4djA255cuXBzYPycGzjTQWkPdNY00OfRcQVLafRnd39ySLLsG1i20AyPZ3cDb7AyNJgnp1cOhUHUhcFiL045v9jTUa8Gjlm29fsQQhb3DzJLUEhC+oiK7EISPOwapoEh+7JQJti5YfGXs0YNC62ouC1h9lsrlToClsjc/RM7uSe0kd3EmlzTO/Kqk8Q106mM/Yw2aOB9jnOg6sWTHxJ9FraSJMy6nGz7RbZUDYmN7e3BnQ5Gisez7u3J9c0JwA6Pb0aCFvNObgwKk6NoU59uJwaJ8y1viAT4vCtEFXYO8SFQGtCZpllyXQtNqL+4lmZ/BN/5qJKQFZozEHe9JtAGSaw4wsFnie4JmUQcjleh8yZq0Fnmq3y0D02IzPMgnonYqYIfA4pC+TcXrgIahLB+PEb5s5HrjaR0b7kbHGB0pK7TDO1/T39x1lUZGAPlUH0xTbz+KSoC4dDDx2DQCHzTCaWOB5zjbW+KCSpW0IS0BIJmy6zWCk7WDuxZ4r5oO6dHB7e/sBZo4H2OfUsYOv9jHW+ECJdkAtA/c6MpmMd+XaEKj7km9M4F5TEfBzSKovDLKG1cHobw+b6EDa3WOksYBPAhevBUJMxl8GJTRhFyMLBKSJFn5ls9nvmogS0DfaHOzb3h8AcUuNNBLQNiWa0gRv4MwMMyBwCqxAfCIH82JdYSJKQN+ocjA5NHD2I/e1aj/23iPyhbG6A+bAgXsZoUEII/UAkkQORu71JqIE7o22HBw4VaelpWU74mPPDc/39d1trO5Qb4vJ8QXxbwat06WofcTInMCzeToAtN4VXUn/l1AXDkan9tDSfmL6C81BZooHxDkN9CMveLFZFFAWWZtDwVta3G0sJcAbe3bmYEiniShBXabcL+wflQDD5mD0yKlvk0b/Tk33AG5F7idG+/ibRe54oEl1nLG6A+ZYe1jyAIuG/u2LB3MazxwAfL5vJFGJinxQUwcju6c/n3+FNPm5JhJyy2k/sQTp5nm+2HBJCGi1X1WpwzuBoQXAN+IcjDz8mdePKi/WhH1uxd7GcCjIVBcWpUYDfZ0VbclEJSr2akMBhVrdX6j+Jx3DpSh7vKB8CIiqKwcrcXGqdr05k3RKbU9ryTQVkUB3aHMrEshw7kGCXiv8xxG0h6Uzent6Fpn6MhA17A6GT/3yTxNO1coJbgWur3JFf1fXNuTes5AZe18xXobFHJKv04JZc3O7CtIcgGL9KW03u3QCfL4D4b292dhrpoYgsYOhEz4kaOuHqXKqiagYiN9QnUlyKgX84JUYsQFP9GKzMFRSe8XJb9upE9Dn62CK/KQT75wdTLz+NXgPNdrDuYzeUd0ByN4Wp07n+EdCRZuTY1/ymZQDwIjQye9pA32xdw6IiUgHc639mN8kzCLRjkxzQRzitUpkZ8LZBP1CILUd55EVvdgsCrzJl5i8mgCja+Zgjst4Pq3DUnMmtSWqyNIuQruRU3+CbO08n+pvBAZAjf1IU5kcGJc0YRMBfVV3MPd2RN4+YbvYukI/3sSpe+LUmbw0ryG/6ts1oSLeYrMw6C0xeaFAGc+Wq3hbfeRk582b55lrzf3UHJwWkD0Wp+6BQ3+BfXEXw6UCdHX4TVB0BoJi9Y1Cp59XbUWN8HW7lRjLli3zbINE+1hNiCRI1cGakIhT99ani/A6z1z1nDoUqNQfbO40kyqDfrCBwMg3E5rsCy+8sFlHR8dEnFzRTq/I8hQ9NFFOtGhXVOxgFeUqfknUK7Ctpjl1ANKJ/vmUkvrdwRZmWjpA4J9MTyja2toKY8TQa/ufxP/Whdd5c5cQJHIwfBsTvkKiaqd6/fRyOHKqavdL0H+V2sxmWvrQCAeKItfmQlNyDG/8SVwnetMHyxmA7lm0K2I7GFrlVBW/V6FPP9GqeU4V0Kt2+O2yhctUN6AJBEWD9ngMnessJxh5AfCoQe+8q+xQOYLuWbQrQh2MXP1XYh8S9DKC2sI1z6kCatW3/RCZ6Vj9fNPMqx2wQVNJQlcNEl/mGG5pv48bi7HxMVSOoHsW7QqPg5GlvnJtk6/B9+HMqYUfaXE6rampqWy4dVhgi8FfLprnBXEex+i/wCSkNiSNDSpUxxt7Ccj2nQQYAwUHc9yE3HEotuifDklnfFYMdGNC/lWCxotDf4PvB/jHZTs71c+f2n+ryqCPPcb5/pKdGrTvbH2MUjH4ByOLBDpON9YSFi5cuI1FOwFbbyTox5T6y+iwFL8CqvWvwVtolWgSv/N4sXbl5ZP3r8hRLT50d56KgYJDCYXVhYOhtqqReKDdZuGJtSQSOk8f67x581SspvH3lpoBe9Vefbg/lzveaXmnAf6tEDMNGRp3LnV3ch29o10lQIf+bOKZc+XnmMGARF2EK4vUwQiSw33n7ZlqDWwcaK9Ob29vd26vwj+OT8m3kKFxdd9tlILSJ1Wo8Y8RZT/YiKOY4le5P3SGZJAc7telg7FroL16Jc/n/a1cBBCxsSblwT8LOfofcCh4AQ4x1uoCXZtgVKnYDXLMUECnPSQD29VBcrhfVw7GHrVXb6WylGg0SvUZcrr+YPYuwWVfaE9ltmpA2Q6EQq2UY+yigzf2oqCH4v4MIysD94fdwdig9uqDnB4T5/d+gwHPGNVFcOopyJiPLOfmGTwa0Ek8qS8RKDKORLFWH95utwbDd94SRqqN/Cv4PDXbTFfXfUZWBvRUPJCRBJiIqfnnccy0Dz74wHkWoypY2D4ZGU8gK+kKjQKQ8RcTW1uQI2fmc7nH7LIMFEW+sw6xdyN4CgvNByNIDjp+ZyRVhzlV7dVLaZc7t1cRoW0w9of/No6ptbuRdZupqC3QPZY33HchMkbJiRPssgyaHkN82XaJXPtOJuN+JRuixQI6Cu1VXiZtJehcFGpeNPyXI6cqPWTIvsxU1R7o912akevre4OHfTHot3fEfRbD3y8+Qu0djO5Ce5UXNGl7dTt4z0RGqnOuhgLZgmcPk2FHrrd3jgwkAVQ58e1ioxjcHeMLPWQcq+5gZKm9+hJHjXo5z4xQBQsxxyDjEfir+nNq5GfQo/nYh6f9e4NUgGEFx3DEzvw1nPrOhSJ+kh6GUBUHw6//Kmls96dJ2qv6FxNF9z8g405kVLVXDfkaiFAd4JIkttYUGFpyDOf91Ch/YVEe8DA/gORpuywDfLNMjBOQt4qEupbTPTX4YeJig+/qrnoxkfMeIdH2UHGBfP0H6kFepElc1rY5lBQYXZbzuO7BWYH7b3V3d/+TX1FEG/JSExEJdOi7qsnrx3DuNM8Zdg2NqnN/BjK0EXlVhxORr56wP6Lv/DT+X1FzYLynaOWe2s1TjCQW4An9t6Jk4hBVdH6YpB9YNXoS+SRk/JaQZHd5J2CnesLuyGaze3KZ2hTemoNcpO+uB3pAQuzvC7SeJSfc0258Wo97aX9PT+TmMEMB73jsO0wJzXnVx4llL7pe5kWaFtSqGHHgu6rpPr5jsdx+hyI59G+hA4C25GDO1V69mbf/77h0+lZpzZX44B+Ye1X1cWKz92pKrYlcjtzc6gfN+ufhApd/ErcwTvuTRNI0m4c4Tg77u6gfbCHdTuQcrRFaRKiFU7Xl1O/RqX9RObevRxR43gmEBYUn9wEJIMeF/jk0yVKTta2tE0jg43kx1OatWifEYKDrHYKGDnfkMrU1xHUPaoh7k8i+030EvoV3c6i4aTCoc/9+9NVkFgh6BmZFaig08he3oxYkwBEkQGCzg7gfG6kzaDvuSyLfgIyqt1cF6SAspoS4iJf3c9xaf3JrGEgUzZcOGgvO4agzjTQUkI9V5z4851MuLhBvUUp1gR7tjXEHL+shXFZnduNIBomi6T73FVLLByQePu4N3CxMbVxyzfeQUTYZrdpA3yvoPVf/1jdTGggC6aXx0ieLSecFcWoj72vkhU4IcswU7gVORksb6FHnufbouJ4Xbv+gf1g0EADav9uSeO9YenpA3IfURFVZ0gqEms1rRg0qCzM4TuYy1T061jt0dXXpX0xJ96FMDXIqQXtJ3tSfze6OaY0KU1ogfTUgUJMK0lBIL06dS/F/LJeRe0k2kAAk7BgSWN2GVW/aCOjRuPCbBHVGBG6J3ECKIN3VlfjroguqA+RrMsFvCNqisf5mRox2qPlB4s8vuiMdIE/fVjVvLlRnhKlqYLig7QIpOiva40PAqR2E22neJFrN10AVgWMOIDgPuMOjmRFa+HVaR0fHliaugXoEOe80nBWrZg2dZkZoYffuaW5u1kCVkadmbT70AGdqJodWOhxHqP2eFg1UDvsLatnSFq41M+KKnp6eXbhsdB2OdGiCeX8+/2ecqgnmk/VXNYtqYLSAnNposzpjgw3+H/belpVa8J7TAAAAAElFTkSuQmCC"},function(e,t){e.exports='<style>\r\n viewer {\r\n position: relative;\r\n overflow: hidden;\r\n /* Start stage */\r\n flex: 1;\r\n z-index: 1;\r\n justify-content: center;\r\n align-items: center;\r\n\r\n width: 100%;\r\n height: 100%;\r\n }\r\n\r\n .babylonjs-canvas {\r\n flex: 1;\r\n width: 100%;\r\n height: 100%;\r\n touch-action: none;\r\n }\r\n</style>\r\n\r\n<canvas class="babylonjs-canvas" id="{{canvasId}}">\r\n</canvas>\r\n\r\n<nav-bar></nav-bar>'},function(e,t){e.exports='<style>\r\n overlay {\r\n position: absolute;\r\n z-index: 99;\r\n opacity: 0;\r\n display: flex;\r\n justify-content: center;\r\n align-items: center;\r\n -webkit-transition: opacity 1s ease;\r\n -moz-transition: opacity 1s ease;\r\n transition: opacity 1s ease;\r\n }\r\n\r\n .overlay-item {\r\n width: 100%;\r\n height: 100%;\r\n display: none;\r\n align-items: center;\r\n justify-content: center;\r\n background-color: rgba(121, 121, 121, 0.3);\r\n }\r\n\r\n error.overlay-item {\r\n background-color: rgba(121, 121, 121, 1);\r\n }\r\n\r\n div#close-button {\r\n position: absolute;\r\n top: 10px;\r\n right: 10px;\r\n width: 30px;\r\n height: 30px;\r\n cursor: pointer;\r\n }\r\n\r\n div#close-button img {\r\n width: 100%;\r\n }\r\n</style>\r\n\r\n<div id="close-button">\r\n <img src="{{closeImage}}" alt="{{closeText}}">\r\n</div>\r\n<help class="overlay-item"></help>\r\n<error class="overlay-item"></error>\r\n<share class="overlay-item"></share>'},function(e,t){e.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAAASAAAAEgARslrPgAAAPpJREFUaN7tmEEOgjAQAFHwh4SD/s5IPPBDMRkPlqQhYCzdtYvZORJTZtrAEqvKcRzHcZydANTAFbgorN0Cd+CkKd/z5ikZEeTHsPagEhHJT4xAJ7BuF8lP9BoBLfCY3SjrJGY7H695Fg+Qjvi5vGREMXmJiOLyORFm5LdEmJNPiTAr/02EefkoYmkgjSvXsgegVsTSSdje+YQIFfmjUsch8boNVh7Y5GFXSn6/D/GnV2XKsDMnP/uNvYiUIWUuYsuENROxRd5MRI588QgJ+WIRkvJFIviDv1Vq4Cax8wtrxycxAI14QLhRE05C/FMgnESvJu84juM4jgIvJPHlXUrVOPYAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMTAtMzBUMTA6NTQ6NDArMDA6MDBIpOL5AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTEwLTMwVDEwOjU0OjQwKzAwOjAwOflaRQAAACh0RVh0c3ZnOmJhc2UtdXJpAGZpbGU6Ly8vdG1wL21hZ2ljay1GZmF2R0Zvc8JGurIAAAAASUVORK5CYII="},function(e,t){e.exports="Error loading the model"},function(e,t,i){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0});var r=i(2);t.mapperManager=r.mapperManager;var n=i(4);t.viewerManager=n.viewerManager;var o=i(5);t.DefaultViewer=o.DefaultViewer;var s=i(6);t.AbstractViewer=s.AbstractViewer,i(0),i(29),i(30);var a=i(31);t.InitTags=a.InitTags,e.Promise=Promise||i(32).Promise,t.disableInit=!1,setTimeout(function(){t.disableInit||a.InitTags()})}).call(t,i(1))},function(e,t,i){var r;!function(t){e.exports=t()}(function(){return function e(t,i,n){function o(a,l){if(!i[a]){if(!t[a]){if(!l&&("function"==typeof r&&r))return r(a,!0);if(s)return s(a,!0);throw new Error("Cannot find module '"+a+"'")}var h=i[a]={exports:{}};t[a][0].call(h.exports,function(e){var i=t[a][1][e];return o(i||e)},h,h.exports,e,t,i,n)}return i[a].exports}for(var s="function"==typeof r&&r,a=0;a<n.length;a++)o(n[a]);return o}({1:[function(e,t,i){t.exports={name:"cannon",version:"0.6.2",description:"A lightweight 3D physics engine written in JavaScript.",homepage:"https://github.com/schteppe/cannon.js",author:"Stefan Hedman <schteppe@gmail.com> (http://steffe.se)",keywords:["cannon.js","cannon","physics","engine","3d"],main:"./build/cannon.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/schteppe/cannon.js.git"},bugs:{url:"https://github.com/schteppe/cannon.js/issues"},licenses:[{type:"MIT"}],devDependencies:{jshint:"latest","uglify-js":"latest",nodeunit:"^0.9.0",grunt:"~0.4.0","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-concat":"~0.1.3","grunt-contrib-uglify":"^0.5.1","grunt-browserify":"^2.1.4","grunt-contrib-yuidoc":"^0.5.2",browserify:"*"},dependencies:{}}},{}],2:[function(e,t,i){t.exports={version:e("../package.json").version,AABB:e("./collision/AABB"),ArrayCollisionMatrix:e("./collision/ArrayCollisionMatrix"),Body:e("./objects/Body"),Box:e("./shapes/Box"),Broadphase:e("./collision/Broadphase"),Constraint:e("./constraints/Constraint"),ContactEquation:e("./equations/ContactEquation"),Narrowphase:e("./world/Narrowphase"),ConeTwistConstraint:e("./constraints/ConeTwistConstraint"),ContactMaterial:e("./material/ContactMaterial"),ConvexPolyhedron:e("./shapes/ConvexPolyhedron"),Cylinder:e("./shapes/Cylinder"),DistanceConstraint:e("./constraints/DistanceConstraint"),Equation:e("./equations/Equation"),EventTarget:e("./utils/EventTarget"),FrictionEquation:e("./equations/FrictionEquation"),GSSolver:e("./solver/GSSolver"),GridBroadphase:e("./collision/GridBroadphase"),Heightfield:e("./shapes/Heightfield"),HingeConstraint:e("./constraints/HingeConstraint"),LockConstraint:e("./constraints/LockConstraint"),Mat3:e("./math/Mat3"),Material:e("./material/Material"),NaiveBroadphase:e("./collision/NaiveBroadphase"),ObjectCollisionMatrix:e("./collision/ObjectCollisionMatrix"),Pool:e("./utils/Pool"),Particle:e("./shapes/Particle"),Plane:e("./shapes/Plane"),PointToPointConstraint:e("./constraints/PointToPointConstraint"),Quaternion:e("./math/Quaternion"),Ray:e("./collision/Ray"),RaycastVehicle:e("./objects/RaycastVehicle"),RaycastResult:e("./collision/RaycastResult"),RigidVehicle:e("./objects/RigidVehicle"),RotationalEquation:e("./equations/RotationalEquation"),RotationalMotorEquation:e("./equations/RotationalMotorEquation"),SAPBroadphase:e("./collision/SAPBroadphase"),SPHSystem:e("./objects/SPHSystem"),Shape:e("./shapes/Shape"),Solver:e("./solver/Solver"),Sphere:e("./shapes/Sphere"),SplitSolver:e("./solver/SplitSolver"),Spring:e("./objects/Spring"),Trimesh:e("./shapes/Trimesh"),Vec3:e("./math/Vec3"),Vec3Pool:e("./utils/Vec3Pool"),World:e("./world/World")}},{"../package.json":1,"./collision/AABB":3,"./collision/ArrayCollisionMatrix":4,"./collision/Broadphase":5,"./collision/GridBroadphase":6,"./collision/NaiveBroadphase":7,"./collision/ObjectCollisionMatrix":8,"./collision/Ray":9,"./collision/RaycastResult":10,"./collision/SAPBroadphase":11,"./constraints/ConeTwistConstraint":12,"./constraints/Constraint":13,"./constraints/DistanceConstraint":14,"./constraints/HingeConstraint":15,"./constraints/LockConstraint":16,"./constraints/PointToPointConstraint":17,"./equations/ContactEquation":19,"./equations/Equation":20,"./equations/FrictionEquation":21,"./equations/RotationalEquation":22,"./equations/RotationalMotorEquation":23,"./material/ContactMaterial":24,"./material/Material":25,"./math/Mat3":27,"./math/Quaternion":28,"./math/Vec3":30,"./objects/Body":31,"./objects/RaycastVehicle":32,"./objects/RigidVehicle":33,"./objects/SPHSystem":34,"./objects/Spring":35,"./shapes/Box":37,"./shapes/ConvexPolyhedron":38,"./shapes/Cylinder":39,"./shapes/Heightfield":40,"./shapes/Particle":41,"./shapes/Plane":42,"./shapes/Shape":43,"./shapes/Sphere":44,"./shapes/Trimesh":45,"./solver/GSSolver":46,"./solver/Solver":47,"./solver/SplitSolver":48,"./utils/EventTarget":49,"./utils/Pool":51,"./utils/Vec3Pool":54,"./world/Narrowphase":55,"./world/World":56}],3:[function(e,t,i){function r(e){e=e||{},this.lowerBound=new n,e.lowerBound&&this.lowerBound.copy(e.lowerBound),this.upperBound=new n,e.upperBound&&this.upperBound.copy(e.upperBound)}var n=e("../math/Vec3");e("../utils/Utils");t.exports=r;var o=new n;r.prototype.setFromPoints=function(e,t,i,r){var n=this.lowerBound,s=this.upperBound,a=i;n.copy(e[0]),a&&a.vmult(n,n),s.copy(n);for(var l=1;l<e.length;l++){var h=e[l];a&&(a.vmult(h,o),h=o),h.x>s.x&&(s.x=h.x),h.x<n.x&&(n.x=h.x),h.y>s.y&&(s.y=h.y),h.y<n.y&&(n.y=h.y),h.z>s.z&&(s.z=h.z),h.z<n.z&&(n.z=h.z)}return t&&(t.vadd(n,n),t.vadd(s,s)),r&&(n.x-=r,n.y-=r,n.z-=r,s.x+=r,s.y+=r,s.z+=r),this},r.prototype.copy=function(e){return this.lowerBound.copy(e.lowerBound),this.upperBound.copy(e.upperBound),this},r.prototype.clone=function(){return(new r).copy(this)},r.prototype.extend=function(e){t=e.lowerBound.x;this.lowerBound.x>t&&(this.lowerBound.x=t);i=e.upperBound.x;this.upperBound.x<i&&(this.upperBound.x=i);t=e.lowerBound.y;this.lowerBound.y>t&&(this.lowerBound.y=t);i=e.upperBound.y;this.upperBound.y<i&&(this.upperBound.y=i);var t=e.lowerBound.z;this.lowerBound.z>t&&(this.lowerBound.z=t);var i=e.upperBound.z;this.upperBound.z<i&&(this.upperBound.z=i)},r.prototype.overlaps=function(e){var t=this.lowerBound,i=this.upperBound,r=e.lowerBound,n=e.upperBound;return(r.x<=i.x&&i.x<=n.x||t.x<=n.x&&n.x<=i.x)&&(r.y<=i.y&&i.y<=n.y||t.y<=n.y&&n.y<=i.y)&&(r.z<=i.z&&i.z<=n.z||t.z<=n.z&&n.z<=i.z)},r.prototype.contains=function(e){var t=this.lowerBound,i=this.upperBound,r=e.lowerBound,n=e.upperBound;return t.x<=r.x&&i.x>=n.x&&t.y<=r.y&&i.y>=n.y&&t.z<=r.z&&i.z>=n.z},r.prototype.getCorners=function(e,t,i,r,n,o,s,a){var l=this.lowerBound,h=this.upperBound;e.copy(l),t.set(h.x,l.y,l.z),i.set(h.x,h.y,l.z),r.set(l.x,h.y,h.z),n.set(h.x,l.y,l.z),o.set(l.x,h.y,l.z),s.set(l.x,l.y,h.z),a.copy(h)};var s=[new n,new n,new n,new n,new n,new n,new n,new n];r.prototype.toLocalFrame=function(e,t){var i=s,r=i[0],n=i[1],o=i[2],a=i[3],l=i[4],h=i[5],u=i[6],c=i[7];this.getCorners(r,n,o,a,l,h,u,c);for(var f=0;8!==f;f++){var p=i[f];e.pointToLocal(p,p)}return t.setFromPoints(i)},r.prototype.toWorldFrame=function(e,t){var i=s,r=i[0],n=i[1],o=i[2],a=i[3],l=i[4],h=i[5],u=i[6],c=i[7];this.getCorners(r,n,o,a,l,h,u,c);for(var f=0;8!==f;f++){var p=i[f];e.pointToWorld(p,p)}return t.setFromPoints(i)}},{"../math/Vec3":30,"../utils/Utils":53}],4:[function(e,t,i){function r(){this.matrix=[]}t.exports=r,r.prototype.get=function(e,t){if(e=e.index,(t=t.index)>e){var i=t;t=e,e=i}return this.matrix[(e*(e+1)>>1)+t-1]},r.prototype.set=function(e,t,i){if(e=e.index,(t=t.index)>e){var r=t;t=e,e=r}this.matrix[(e*(e+1)>>1)+t-1]=i?1:0},r.prototype.reset=function(){for(var e=0,t=this.matrix.length;e!==t;e++)this.matrix[e]=0},r.prototype.setNumObjects=function(e){this.matrix.length=e*(e-1)>>1}},{}],5:[function(e,t,i){function r(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}var n=e("../objects/Body"),o=e("../math/Vec3"),s=e("../math/Quaternion");e("../shapes/Shape"),e("../shapes/Plane");t.exports=r,r.prototype.collisionPairs=function(e,t,i){throw new Error("collisionPairs not implemented for this BroadPhase class!")};var a=n.STATIC|n.KINEMATIC;r.prototype.needBroadphaseCollision=function(e,t){return 0!=(e.collisionFilterGroup&t.collisionFilterMask)&&0!=(t.collisionFilterGroup&e.collisionFilterMask)&&(0==(e.type&a)&&e.sleepState!==n.SLEEPING||0==(t.type&a)&&t.sleepState!==n.SLEEPING)},r.prototype.intersectionTest=function(e,t,i,r){this.useBoundingBoxes?this.doBoundingBoxBroadphase(e,t,i,r):this.doBoundingSphereBroadphase(e,t,i,r)};var l=new o;new o,new s,new o;r.prototype.doBoundingSphereBroadphase=function(e,t,i,r){var n=l;t.position.vsub(e.position,n);var o=Math.pow(e.boundingRadius+t.boundingRadius,2);n.norm2()<o&&(i.push(e),r.push(t))},r.prototype.doBoundingBoxBroadphase=function(e,t,i,r){e.aabbNeedsUpdate&&e.computeAABB(),t.aabbNeedsUpdate&&t.computeAABB(),e.aabb.overlaps(t.aabb)&&(i.push(e),r.push(t))};var h={keys:[]},u=[],c=[];r.prototype.makePairsUnique=function(e,t){for(var i=h,r=u,n=c,o=e.length,s=0;s!==o;s++)r[s]=e[s],n[s]=t[s];e.length=0,t.length=0;for(s=0;s!==o;s++){var a=r[s].id,l=n[s].id;i[f=a<l?a+","+l:l+","+a]=s,i.keys.push(f)}for(s=0;s!==i.keys.length;s++){var f=i.keys.pop(),p=i[f];e.push(r[p]),t.push(n[p]),delete i[f]}},r.prototype.setWorld=function(e){};var f=new o;r.boundingSphereCheck=function(e,t){var i=f;return e.position.vsub(t.position,i),Math.pow(e.shape.boundingSphereRadius+t.shape.boundingSphereRadius,2)>i.norm2()},r.prototype.aabbQuery=function(e,t,i){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Plane":42,"../shapes/Shape":43}],6:[function(e,t,i){function r(e,t,i,r,s){n.apply(this),this.nx=i||10,this.ny=r||10,this.nz=s||10,this.aabbMin=e||new o(100,100,100),this.aabbMax=t||new o(-100,-100,-100);var a=this.nx*this.ny*this.nz;if(a<=0)throw"GridBroadphase: Each dimension's n must be >0";this.bins=[],this.binLengths=[],this.bins.length=a,this.binLengths.length=a;for(var l=0;l<a;l++)this.bins[l]=[],this.binLengths[l]=0}t.exports=r;var n=e("./Broadphase"),o=e("../math/Vec3"),s=e("../shapes/Shape");(r.prototype=new n).constructor=r;var a=new o;new o;r.prototype.collisionPairs=function(e,t,i){function r(e,t,i,r,n,o,s){var a=(e-y)*T|0,l=(t-x)*E|0,h=(i-b)*A|0,g=N((r-y)*T),v=N((n-x)*E),_=N((o-b)*A);a<0?a=0:a>=u&&(a=u-1),l<0?l=0:l>=c&&(l=c-1),h<0?h=0:h>=f&&(h=f-1),g<0?g=0:g>=u&&(g=u-1),v<0?v=0:v>=c&&(v=c-1),_<0?_=0:_>=f&&(_=f-1),l*=d,h*=m,g*=p,v*=d,_*=m;for(var P=a*=p;P<=g;P+=p)for(var S=l;S<=v;S+=d)for(var M=h;M<=_;M+=m){var C=P+S+M;D[C][w[C]++]=s}}for(var n=e.numObjects(),o=e.bodies,l=this.aabbMax,h=this.aabbMin,u=this.nx,c=this.ny,f=this.nz,p=c*f,d=f,m=1,g=l.x,v=l.y,_=l.z,y=h.x,x=h.y,b=h.z,T=u/(g-y),E=c/(v-x),A=f/(_-b),P=(g-y)/u,S=(v-x)/c,M=(_-b)/f,C=.5*Math.sqrt(P*P+S*S+M*M),R=s.types,I=R.SPHERE,O=R.PLANE,D=(R.BOX,R.COMPOUND,R.CONVEXPOLYHEDRON,this.bins),w=this.binLengths,L=this.bins.length,F=0;F!==L;F++)w[F]=0;for(var N=Math.ceil,h=Math.min,l=Math.max,F=0;F!==n;F++){var B=(ie=o[F]).shape;switch(B.type){case I:var V=ie.position.x,U=ie.position.y,z=ie.position.z,k=B.radius;r(V-k,U-k,z-k,V+k,U+k,z+k,ie);break;case O:B.worldNormalNeedsUpdate&&B.computeWorldNormal(ie.quaternion);var G=B.worldNormal,H=y+.5*P-ie.position.x,W=x+.5*S-ie.position.y,j=b+.5*M-ie.position.z,X=a;X.set(H,W,j);for(var Y=0,K=0;Y!==u;Y++,K+=p,X.y=W,X.x+=P)for(var Q=0,Z=0;Q!==c;Q++,Z+=d,X.z=j,X.y+=S)for(var q=0,J=0;q!==f;q++,J+=m,X.z+=M)if(X.dot(G)<C){var $=K+Z+J;D[$][w[$]++]=ie}break;default:ie.aabbNeedsUpdate&&ie.computeAABB(),r(ie.aabb.lowerBound.x,ie.aabb.lowerBound.y,ie.aabb.lowerBound.z,ie.aabb.upperBound.x,ie.aabb.upperBound.y,ie.aabb.upperBound.z,ie)}}for(F=0;F!==L;F++){var ee=w[F];if(ee>1)for(var te=D[F],Y=0;Y!==ee;Y++)for(var ie=te[Y],Q=0;Q!==Y;Q++){var re=te[Q];this.needBroadphaseCollision(ie,re)&&this.intersectionTest(ie,re,t,i)}}this.makePairsUnique(t,i)}},{"../math/Vec3":30,"../shapes/Shape":43,"./Broadphase":5}],7:[function(e,t,i){function r(){n.apply(this)}t.exports=r;var n=e("./Broadphase"),o=e("./AABB");(r.prototype=new n).constructor=r,r.prototype.collisionPairs=function(e,t,i){var r,n,o,s,a=e.bodies,l=a.length;for(r=0;r!==l;r++)for(n=0;n!==r;n++)o=a[r],s=a[n],this.needBroadphaseCollision(o,s)&&this.intersectionTest(o,s,t,i)};new o;r.prototype.aabbQuery=function(e,t,i){i=i||[];for(var r=0;r<e.bodies.length;r++){var n=e.bodies[r];n.aabbNeedsUpdate&&n.computeAABB(),n.aabb.overlaps(t)&&i.push(n)}return i}},{"./AABB":3,"./Broadphase":5}],8:[function(e,t,i){function r(){this.matrix={}}t.exports=r,r.prototype.get=function(e,t){if(e=e.id,(t=t.id)>e){var i=t;t=e,e=i}return e+"-"+t in this.matrix},r.prototype.set=function(e,t,i){if(e=e.id,(t=t.id)>e){var r=t;t=e,e=r}i?this.matrix[e+"-"+t]=!0:delete this.matrix[e+"-"+t]},r.prototype.reset=function(){this.matrix={}},r.prototype.setNumObjects=function(e){}},{}],9:[function(e,t,i){function r(e,t){this.from=e?e.clone():new s,this.to=t?t.clone():new s,this._direction=new s,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=r.ANY,this.result=new h,this.hasHit=!1,this.callback=function(e){}}function n(e,t,i,r){r.vsub(t,F),i.vsub(t,d),e.vsub(t,m);var n,o,s=F.dot(F),a=F.dot(d),l=F.dot(m),h=d.dot(d),u=d.dot(m);return(n=h*l-a*u)>=0&&(o=s*u-a*l)>=0&&n+o<s*h-a*a}function o(e,t,i){i.vsub(e,F);var r=F.dot(t);return t.mult(r,N),N.vadd(e,N),i.distanceTo(N)}t.exports=r;var s=e("../math/Vec3"),a=e("../math/Quaternion"),l=e("../math/Transform"),h=(e("../shapes/ConvexPolyhedron"),e("../shapes/Box"),e("../collision/RaycastResult")),u=e("../shapes/Shape"),c=e("../collision/AABB");r.prototype.constructor=r,r.CLOSEST=1,r.ANY=2,r.ALL=4;var f=new c,p=[];r.prototype.intersectWorld=function(e,t){return this.mode=t.mode||r.ANY,this.result=t.result||new h,this.skipBackfaces=!!t.skipBackfaces,this.collisionFilterMask=void 0!==t.collisionFilterMask?t.collisionFilterMask:-1,this.collisionFilterGroup=void 0!==t.collisionFilterGroup?t.collisionFilterGroup:-1,t.from&&this.from.copy(t.from),t.to&&this.to.copy(t.to),this.callback=t.callback||function(){},this.hasHit=!1,this.result.reset(),this._updateDirection(),this.getAABB(f),p.length=0,e.broadphase.aabbQuery(e,f,p),this.intersectBodies(p),this.hasHit};var d=new s,m=new s;r.pointInTriangle=n;var g=new s,v=new a;r.prototype.intersectBody=function(e,t){t&&(this.result=t,this._updateDirection());var i=this.checkCollisionResponse;if((!i||e.collisionResponse)&&0!=(this.collisionFilterGroup&e.collisionFilterMask)&&0!=(e.collisionFilterGroup&this.collisionFilterMask))for(var r=g,n=v,o=0,s=e.shapes.length;o<s;o++){var a=e.shapes[o];if((!i||a.collisionResponse)&&(e.quaternion.mult(e.shapeOrientations[o],n),e.quaternion.vmult(e.shapeOffsets[o],r),r.vadd(e.position,r),this.intersectShape(a,n,r,e),this.result._shouldStop))break}},r.prototype.intersectBodies=function(e,t){t&&(this.result=t,this._updateDirection());for(var i=0,r=e.length;!this.result._shouldStop&&i<r;i++)this.intersectBody(e[i])},r.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},r.prototype.intersectShape=function(e,t,i,r){if(!(o(this.from,this._direction,i)>e.boundingSphereRadius)){var n=this[e.type];n&&n.call(this,e,t,i,r)}};new s,new s;var _=new s,y=new s,x=new s,b=new s;new s,new h;r.prototype.intersectBox=function(e,t,i,r){return this.intersectConvex(e.convexPolyhedronRepresentation,t,i,r)},r.prototype[u.types.BOX]=r.prototype.intersectBox,r.prototype.intersectPlane=function(e,t,i,r){var n=this.from,o=this.to,a=this._direction,l=new s(0,0,1);t.vmult(l,l);var h=new s;n.vsub(i,h);var u=h.dot(l);if(o.vsub(i,h),!(u*h.dot(l)>0||n.distanceTo(o)<u)){var c=l.dot(a);if(!(Math.abs(c)<this.precision)){var f=new s,p=new s,d=new s;n.vsub(i,f);var m=-l.dot(f)/c;a.scale(m,p),n.vadd(p,d),this.reportIntersection(l,d,e,r,-1)}}},r.prototype[u.types.PLANE]=r.prototype.intersectPlane,r.prototype.getAABB=function(e){var t=this.to,i=this.from;e.lowerBound.x=Math.min(t.x,i.x),e.lowerBound.y=Math.min(t.y,i.y),e.lowerBound.z=Math.min(t.z,i.z),e.upperBound.x=Math.max(t.x,i.x),e.upperBound.y=Math.max(t.y,i.y),e.upperBound.z=Math.max(t.z,i.z)};var T={faceList:[0]};r.prototype.intersectHeightfield=function(e,t,i,n){e.data,e.elementSize;var o=new s,a=new r(this.from,this.to);l.pointToLocalFrame(i,t,a.from,a.from),l.pointToLocalFrame(i,t,a.to,a.to);var h=[],u=null,c=null,f=null,p=null,d=e.getIndexOfPosition(a.from.x,a.from.y,h,!1);if(d&&(u=h[0],c=h[1],f=h[0],p=h[1]),(d=e.getIndexOfPosition(a.to.x,a.to.y,h,!1))&&((null===u||h[0]<u)&&(u=h[0]),(null===f||h[0]>f)&&(f=h[0]),(null===c||h[1]<c)&&(c=h[1]),(null===p||h[1]>p)&&(p=h[1])),null!==u){var m=[];e.getRectMinMax(u,c,f,p,m);for(var g=u;g<=f;g++)for(var v=c;v<=p;v++){if(this.result._shouldStop)return;if(e.getConvexTrianglePillar(g,v,!1),l.pointToWorldFrame(i,t,e.pillarOffset,o),this.intersectConvex(e.pillarConvex,t,o,n,T),this.result._shouldStop)return;e.getConvexTrianglePillar(g,v,!0),l.pointToWorldFrame(i,t,e.pillarOffset,o),this.intersectConvex(e.pillarConvex,t,o,n,T)}}},r.prototype[u.types.HEIGHTFIELD]=r.prototype.intersectHeightfield;var E=new s,A=new s;r.prototype.intersectSphere=function(e,t,i,r){var n=this.from,o=this.to,s=e.radius,a=Math.pow(o.x-n.x,2)+Math.pow(o.y-n.y,2)+Math.pow(o.z-n.z,2),l=2*((o.x-n.x)*(n.x-i.x)+(o.y-n.y)*(n.y-i.y)+(o.z-n.z)*(n.z-i.z)),h=Math.pow(n.x-i.x,2)+Math.pow(n.y-i.y,2)+Math.pow(n.z-i.z,2)-Math.pow(s,2),u=Math.pow(l,2)-4*a*h,c=E,f=A;if(!(u<0))if(0===u)n.lerp(o,u,c),c.vsub(i,f),f.normalize(),this.reportIntersection(f,c,e,r,-1);else{var p=(-l-Math.sqrt(u))/(2*a),d=(-l+Math.sqrt(u))/(2*a);if(p>=0&&p<=1&&(n.lerp(o,p,c),c.vsub(i,f),f.normalize(),this.reportIntersection(f,c,e,r,-1)),this.result._shouldStop)return;d>=0&&d<=1&&(n.lerp(o,d,c),c.vsub(i,f),f.normalize(),this.reportIntersection(f,c,e,r,-1))}},r.prototype[u.types.SPHERE]=r.prototype.intersectSphere;var P=new s,S=(new s,new s,new s);r.prototype.intersectConvex=function(e,t,i,r,o){for(var s=P,a=S,l=o&&o.faceList||null,h=e.faces,u=e.vertices,c=e.faceNormals,f=this._direction,p=this.from,d=this.to,m=p.distanceTo(d),g=l?l.length:h.length,v=this.result,T=0;!v._shouldStop&&T<g;T++){var E=l?l[T]:T,A=h[E],M=c[E],C=t,R=i;a.copy(u[A[0]]),C.vmult(a,a),a.vadd(R,a),a.vsub(p,a),C.vmult(M,s);var I=f.dot(s);if(!(Math.abs(I)<this.precision)){var O=s.dot(a)/I;if(!(O<0)){f.mult(O,_),_.vadd(p,_),y.copy(u[A[0]]),C.vmult(y,y),R.vadd(y,y);for(var D=1;!v._shouldStop&&D<A.length-1;D++){x.copy(u[A[D]]),b.copy(u[A[D+1]]),C.vmult(x,x),C.vmult(b,b),R.vadd(x,x),R.vadd(b,b);var w=_.distanceTo(p);!n(_,y,x,b)&&!n(_,x,y,b)||w>m||this.reportIntersection(s,_,e,r,E)}}}}},r.prototype[u.types.CONVEXPOLYHEDRON]=r.prototype.intersectConvex;var M=new s,C=new s,R=new s,I=new s,O=new s,D=new s,w=(new c,[]),L=new l;r.prototype.intersectTrimesh=function(e,t,i,r,o){var s=M,a=w,h=L,u=S,c=C,f=R,p=I,d=D,m=O,g=(o&&o.faceList,e.indices),v=(e.vertices,e.faceNormals,this.from),T=this.to,E=this._direction;h.position.copy(i),h.quaternion.copy(t),l.vectorToLocalFrame(i,t,E,c),l.pointToLocalFrame(i,t,v,f),l.pointToLocalFrame(i,t,T,p);var A=f.distanceSquared(p);e.tree.rayQuery(this,h,a);for(var P=0,F=a.length;!this.result._shouldStop&&P!==F;P++){var N=a[P];e.getNormal(N,s),e.getVertex(g[3*N],y),y.vsub(f,u);var B=c.dot(s),V=s.dot(u)/B;if(!(V<0)){c.scale(V,_),_.vadd(f,_),e.getVertex(g[3*N+1],x),e.getVertex(g[3*N+2],b);var U=_.distanceSquared(f);!n(_,x,y,b)&&!n(_,y,x,b)||U>A||(l.vectorToWorldFrame(t,s,m),l.pointToWorldFrame(i,t,_,d),this.reportIntersection(m,d,e,r,N))}}a.length=0},r.prototype[u.types.TRIMESH]=r.prototype.intersectTrimesh,r.prototype.reportIntersection=function(e,t,i,n,o){var s=this.from,a=this.to,l=s.distanceTo(t),h=this.result;if(!(this.skipBackfaces&&e.dot(this._direction)>0))switch(h.hitFaceIndex=void 0!==o?o:-1,this.mode){case r.ALL:this.hasHit=!0,h.set(s,a,e,t,i,n,l),h.hasHit=!0,this.callback(h);break;case r.CLOSEST:(l<h.distance||!h.hasHit)&&(this.hasHit=!0,h.hasHit=!0,h.set(s,a,e,t,i,n,l));break;case r.ANY:this.hasHit=!0,h.hasHit=!0,h.set(s,a,e,t,i,n,l),h._shouldStop=!0}};var F=new s,N=new s},{"../collision/AABB":3,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../shapes/Box":37,"../shapes/ConvexPolyhedron":38,"../shapes/Shape":43}],10:[function(e,t,i){function r(){this.rayFromWorld=new n,this.rayToWorld=new n,this.hitNormalWorld=new n,this.hitPointWorld=new n,this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1}var n=e("../math/Vec3");t.exports=r,r.prototype.reset=function(){this.rayFromWorld.setZero(),this.rayToWorld.setZero(),this.hitNormalWorld.setZero(),this.hitPointWorld.setZero(),this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1},r.prototype.abort=function(){this._shouldStop=!0},r.prototype.set=function(e,t,i,r,n,o,s){this.rayFromWorld.copy(e),this.rayToWorld.copy(t),this.hitNormalWorld.copy(i),this.hitPointWorld.copy(r),this.shape=n,this.body=o,this.distance=s}},{"../math/Vec3":30}],11:[function(e,t,i){function r(e){n.apply(this),this.axisList=[],this.world=null,this.axisIndex=0;var t=this.axisList;this._addBodyHandler=function(e){t.push(e.body)},this._removeBodyHandler=function(e){var i=t.indexOf(e.body);-1!==i&&t.splice(i,1)},e&&this.setWorld(e)}e("../shapes/Shape");var n=e("../collision/Broadphase");t.exports=r,(r.prototype=new n).setWorld=function(e){this.axisList.length=0;for(var t=0;t<e.bodies.length;t++)this.axisList.push(e.bodies[t]);e.removeEventListener("addBody",this._addBodyHandler),e.removeEventListener("removeBody",this._removeBodyHandler),e.addEventListener("addBody",this._addBodyHandler),e.addEventListener("removeBody",this._removeBodyHandler),this.world=e,this.dirty=!0},r.insertionSortX=function(e){for(var t=1,i=e.length;t<i;t++){for(var r=e[t],n=t-1;n>=0&&!(e[n].aabb.lowerBound.x<=r.aabb.lowerBound.x);n--)e[n+1]=e[n];e[n+1]=r}return e},r.insertionSortY=function(e){for(var t=1,i=e.length;t<i;t++){for(var r=e[t],n=t-1;n>=0&&!(e[n].aabb.lowerBound.y<=r.aabb.lowerBound.y);n--)e[n+1]=e[n];e[n+1]=r}return e},r.insertionSortZ=function(e){for(var t=1,i=e.length;t<i;t++){for(var r=e[t],n=t-1;n>=0&&!(e[n].aabb.lowerBound.z<=r.aabb.lowerBound.z);n--)e[n+1]=e[n];e[n+1]=r}return e},r.prototype.collisionPairs=function(e,t,i){var n,o,s=this.axisList,a=s.length,l=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),n=0;n!==a;n++){var h=s[n];for(o=n+1;o<a;o++){var u=s[o];if(this.needBroadphaseCollision(h,u)){if(!r.checkBounds(h,u,l))break;this.intersectionTest(h,u,t,i)}}}},r.prototype.sortList=function(){for(var e=this.axisList,t=this.axisIndex,i=e.length,n=0;n!==i;n++){var o=e[n];o.aabbNeedsUpdate&&o.computeAABB()}0===t?r.insertionSortX(e):1===t?r.insertionSortY(e):2===t&&r.insertionSortZ(e)},r.checkBounds=function(e,t,i){var r,n;0===i?(r=e.position.x,n=t.position.x):1===i?(r=e.position.y,n=t.position.y):2===i&&(r=e.position.z,n=t.position.z);var o=e.boundingRadius,s=t.boundingRadius;return n-s<r+o},r.prototype.autoDetectAxis=function(){for(var e=0,t=0,i=0,r=0,n=0,o=0,s=this.axisList,a=s.length,l=1/a,h=0;h!==a;h++){var u=s[h],c=u.position.x;e+=c,t+=c*c;var f=u.position.y;i+=f,r+=f*f;var p=u.position.z;n+=p,o+=p*p}var d=t-e*e*l,m=r-i*i*l,g=o-n*n*l;this.axisIndex=d>m?d>g?0:2:m>g?1:2},r.prototype.aabbQuery=function(e,t,i){i=i||[],this.dirty&&(this.sortList(),this.dirty=!1);var r=this.axisIndex,n="x";1===r&&(n="y"),2===r&&(n="z");for(var o=this.axisList,s=(t.lowerBound[n],t.upperBound[n],0);s<o.length;s++){var a=o[s];a.aabbNeedsUpdate&&a.computeAABB(),a.aabb.overlaps(t)&&i.push(a)}return i}},{"../collision/Broadphase":5,"../shapes/Shape":43}],12:[function(e,t,i){function r(e,t,i){var r=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,l=i.pivotA?i.pivotA.clone():new a,h=i.pivotB?i.pivotB.clone():new a;this.axisA=i.axisA?i.axisA.clone():new a,this.axisB=i.axisB?i.axisB.clone():new a,n.call(this,e,l,t,h,r),this.collideConnected=!!i.collideConnected,this.angle=void 0!==i.angle?i.angle:0;var u=this.coneEquation=new o(e,t,i),c=this.twistEquation=new s(e,t,i);this.twistAngle=void 0!==i.twistAngle?i.twistAngle:0,u.maxForce=0,u.minForce=-r,c.maxForce=0,c.minForce=-r,this.equations.push(u,c)}t.exports=r;e("./Constraint");var n=e("./PointToPointConstraint"),o=e("../equations/ConeEquation"),s=e("../equations/RotationalEquation"),a=(e("../equations/ContactEquation"),e("../math/Vec3"));r.prototype=new n,r.constructor=r;new a,new a;r.prototype.update=function(){var e=this.bodyA,t=this.bodyB,i=this.coneEquation,r=this.twistEquation;n.prototype.update.call(this),e.vectorToWorldFrame(this.axisA,i.axisA),t.vectorToWorldFrame(this.axisB,i.axisB),this.axisA.tangents(r.axisA,r.axisA),e.vectorToWorldFrame(r.axisA,r.axisA),this.axisB.tangents(r.axisB,r.axisB),t.vectorToWorldFrame(r.axisB,r.axisB),i.angle=this.angle,r.maxAngle=this.twistAngle}},{"../equations/ConeEquation":18,"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],13:[function(e,t,i){function r(e,t,i){i=n.defaults(i,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=e,this.bodyB=t,this.id=r.idCounter++,this.collideConnected=i.collideConnected,i.wakeUpBodies&&(e&&e.wakeUp(),t&&t.wakeUp())}t.exports=r;var n=e("../utils/Utils");r.prototype.update=function(){throw new Error("method update() not implmemented in this Constraint subclass!")},r.prototype.enable=function(){for(var e=this.equations,t=0;t<e.length;t++)e[t].enabled=!0},r.prototype.disable=function(){for(var e=this.equations,t=0;t<e.length;t++)e[t].enabled=!1},r.idCounter=0},{"../utils/Utils":53}],14:[function(e,t,i){function r(e,t,i,r){n.call(this,e,t),void 0===i&&(i=e.position.distanceTo(t.position)),void 0===r&&(r=1e6),this.distance=i;var s=this.distanceEquation=new o(e,t);this.equations.push(s),s.minForce=-r,s.maxForce=r}t.exports=r;var n=e("./Constraint"),o=e("../equations/ContactEquation");(r.prototype=new n).update=function(){var e=this.bodyA,t=this.bodyB,i=this.distanceEquation,r=.5*this.distance,n=i.ni;t.position.vsub(e.position,n),n.normalize(),n.mult(r,i.ri),n.mult(-r,i.rj)}},{"../equations/ContactEquation":19,"./Constraint":13}],15:[function(e,t,i){function r(e,t,i){var r=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,l=i.pivotA?i.pivotA.clone():new a,h=i.pivotB?i.pivotB.clone():new a;n.call(this,e,l,t,h,r),(this.axisA=i.axisA?i.axisA.clone():new a(1,0,0)).normalize(),(this.axisB=i.axisB?i.axisB.clone():new a(1,0,0)).normalize();var u=this.rotationalEquation1=new o(e,t,i),c=this.rotationalEquation2=new o(e,t,i),f=this.motorEquation=new s(e,t,r);f.enabled=!1,this.equations.push(u,c,f)}t.exports=r;e("./Constraint");var n=e("./PointToPointConstraint"),o=e("../equations/RotationalEquation"),s=e("../equations/RotationalMotorEquation"),a=(e("../equations/ContactEquation"),e("../math/Vec3"));r.prototype=new n,r.constructor=r,r.prototype.enableMotor=function(){this.motorEquation.enabled=!0},r.prototype.disableMotor=function(){this.motorEquation.enabled=!1},r.prototype.setMotorSpeed=function(e){this.motorEquation.targetVelocity=e},r.prototype.setMotorMaxForce=function(e){this.motorEquation.maxForce=e,this.motorEquation.minForce=-e};var l=new a,h=new a;r.prototype.update=function(){var e=this.bodyA,t=this.bodyB,i=this.motorEquation,r=this.rotationalEquation1,o=this.rotationalEquation2,s=l,a=h,u=this.axisA,c=this.axisB;n.prototype.update.call(this),e.quaternion.vmult(u,s),t.quaternion.vmult(c,a),s.tangents(r.axisA,o.axisA),r.axisB.copy(a),o.axisB.copy(a),this.motorEquation.enabled&&(e.quaternion.vmult(this.axisA,i.axisA),t.quaternion.vmult(this.axisB,i.axisB))}},{"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../equations/RotationalMotorEquation":23,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],16:[function(e,t,i){function r(e,t,i){var r=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,a=new s,l=new s,h=new s;e.position.vadd(t.position,h),h.scale(.5,h),t.pointToLocalFrame(h,l),e.pointToLocalFrame(h,a),n.call(this,e,a,t,l,r);var u=this.rotationalEquation1=new o(e,t,i),c=this.rotationalEquation2=new o(e,t,i),f=this.rotationalEquation3=new o(e,t,i);this.equations.push(u,c,f)}t.exports=r;e("./Constraint");var n=e("./PointToPointConstraint"),o=e("../equations/RotationalEquation"),s=(e("../equations/RotationalMotorEquation"),e("../equations/ContactEquation"),e("../math/Vec3"));r.prototype=new n,r.constructor=r;new s,new s;r.prototype.update=function(){var e=this.bodyA,t=this.bodyB,i=(this.motorEquation,this.rotationalEquation1),r=this.rotationalEquation2,o=this.rotationalEquation3;n.prototype.update.call(this),e.vectorToWorldFrame(s.UNIT_X,i.axisA),t.vectorToWorldFrame(s.UNIT_Y,i.axisB),e.vectorToWorldFrame(s.UNIT_Y,r.axisA),t.vectorToWorldFrame(s.UNIT_Z,r.axisB),e.vectorToWorldFrame(s.UNIT_Z,o.axisA),t.vectorToWorldFrame(s.UNIT_X,o.axisB)}},{"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../equations/RotationalMotorEquation":23,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],17:[function(e,t,i){function r(e,t,i,r,a){n.call(this,e,i),a=void 0!==a?a:1e6,this.pivotA=t?t.clone():new s,this.pivotB=r?r.clone():new s;var l=this.equationX=new o(e,i),h=this.equationY=new o(e,i),u=this.equationZ=new o(e,i);this.equations.push(l,h,u),l.minForce=h.minForce=u.minForce=-a,l.maxForce=h.maxForce=u.maxForce=a,l.ni.set(1,0,0),h.ni.set(0,1,0),u.ni.set(0,0,1)}t.exports=r;var n=e("./Constraint"),o=e("../equations/ContactEquation"),s=e("../math/Vec3");(r.prototype=new n).update=function(){var e=this.bodyA,t=this.bodyB,i=this.equationX,r=this.equationY,n=this.equationZ;e.quaternion.vmult(this.pivotA,i.ri),t.quaternion.vmult(this.pivotB,i.rj),r.ri.copy(i.ri),r.rj.copy(i.rj),n.ri.copy(i.ri),n.rj.copy(i.rj)}},{"../equations/ContactEquation":19,"../math/Vec3":30,"./Constraint":13}],18:[function(e,t,i){function r(e,t,i){var r=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;o.call(this,e,t,-r,r),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.angle=void 0!==i.angle?i.angle:0}t.exports=r;var n=e("../math/Vec3"),o=(e("../math/Mat3"),e("./Equation"));(r.prototype=new o).constructor=r;var s=new n,a=new n;r.prototype.computeB=function(e){var t=this.a,i=this.b,r=this.axisA,n=this.axisB,o=s,l=a,h=this.jacobianElementA,u=this.jacobianElementB;return r.cross(n,o),n.cross(r,l),h.rotational.copy(l),u.rotational.copy(o),-(Math.cos(this.angle)-r.dot(n))*t-this.computeGW()*i-e*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],19:[function(e,t,i){function r(e,t,i){i=void 0!==i?i:1e6,n.call(this,e,t,0,i),this.restitution=0,this.ri=new o,this.rj=new o,this.ni=new o}t.exports=r;var n=e("./Equation"),o=e("../math/Vec3");e("../math/Mat3");(r.prototype=new n).constructor=r;var s=new o,a=new o,l=new o;r.prototype.computeB=function(e){var t=this.a,i=this.b,r=this.bi,n=this.bj,o=this.ri,h=this.rj,u=s,c=a,f=r.velocity,p=r.angularVelocity,d=(r.force,r.torque,n.velocity),m=n.angularVelocity,g=(n.force,n.torque,l),v=this.jacobianElementA,_=this.jacobianElementB,y=this.ni;o.cross(y,u),h.cross(y,c),y.negate(v.spatial),u.negate(v.rotational),_.spatial.copy(y),_.rotational.copy(c),g.copy(n.position),g.vadd(h,g),g.vsub(r.position,g),g.vsub(o,g);var x=y.dot(g),b=this.restitution+1;return-x*t-(b*d.dot(y)-b*f.dot(y)+m.dot(c)-p.dot(u))*i-e*this.computeGiMf()};var h=new o,u=new o,c=new o,f=new o,p=new o;r.prototype.getImpactVelocityAlongNormal=function(){var e=h,t=u,i=c,r=f,n=p;return this.bi.position.vadd(this.ri,i),this.bj.position.vadd(this.rj,r),this.bi.getVelocityAtWorldPoint(i,e),this.bj.getVelocityAtWorldPoint(r,t),e.vsub(t,n),this.ni.dot(n)}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],20:[function(e,t,i){function r(e,t,i,o){this.id=r.id++,this.minForce=void 0===i?-1e6:i,this.maxForce=void 0===o?1e6:o,this.bi=e,this.bj=t,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new n,this.jacobianElementB=new n,this.enabled=!0,this.setSpookParams(1e7,4,1/60)}t.exports=r;var n=e("../math/JacobianElement"),o=e("../math/Vec3");r.prototype.constructor=r,r.id=0,r.prototype.setSpookParams=function(e,t,i){var r=t,n=e,o=i;this.a=4/(o*(1+4*r)),this.b=4*r/(1+4*r),this.eps=4/(o*o*n*(1+4*r))},r.prototype.computeB=function(e,t,i){var r=this.computeGW();return-this.computeGq()*e-r*t-this.computeGiMf()*i},r.prototype.computeGq=function(){var e=this.jacobianElementA,t=this.jacobianElementB,i=this.bi,r=this.bj,n=i.position,o=r.position;return e.spatial.dot(n)+t.spatial.dot(o)};var s=new o;r.prototype.computeGW=function(){var e=this.jacobianElementA,t=this.jacobianElementB,i=this.bi,r=this.bj,n=i.velocity,o=r.velocity,a=i.angularVelocity||s,l=r.angularVelocity||s;return e.multiplyVectors(n,a)+t.multiplyVectors(o,l)},r.prototype.computeGWlambda=function(){var e=this.jacobianElementA,t=this.jacobianElementB,i=this.bi,r=this.bj,n=i.vlambda,o=r.vlambda,a=i.wlambda||s,l=r.wlambda||s;return e.multiplyVectors(n,a)+t.multiplyVectors(o,l)};var a=new o,l=new o,h=new o,u=new o;r.prototype.computeGiMf=function(){var e=this.jacobianElementA,t=this.jacobianElementB,i=this.bi,r=this.bj,n=i.force,o=i.torque,s=r.force,c=r.torque,f=i.invMassSolve,p=r.invMassSolve;return i.invInertiaWorldSolve?i.invInertiaWorldSolve.vmult(o,h):h.set(0,0,0),r.invInertiaWorldSolve?r.invInertiaWorldSolve.vmult(c,u):u.set(0,0,0),n.mult(f,a),s.mult(p,l),e.multiplyVectors(a,h)+t.multiplyVectors(l,u)};var c=new o;r.prototype.computeGiMGt=function(){var e=this.jacobianElementA,t=this.jacobianElementB,i=this.bi,r=this.bj,n=i.invMassSolve,o=r.invMassSolve,s=i.invInertiaWorldSolve,a=r.invInertiaWorldSolve,l=n+o;return s&&(s.vmult(e.rotational,c),l+=c.dot(e.rotational)),a&&(a.vmult(t.rotational,c),l+=c.dot(t.rotational)),l};var f=new o;new o,new o,new o,new o,new o;r.prototype.addToWlambda=function(e){var t=this.jacobianElementA,i=this.jacobianElementB,r=this.bi,n=this.bj,o=f;t.spatial.mult(r.invMassSolve*e,o),r.vlambda.vadd(o,r.vlambda),i.spatial.mult(n.invMassSolve*e,o),n.vlambda.vadd(o,n.vlambda),r.invInertiaWorldSolve&&(r.invInertiaWorldSolve.vmult(t.rotational,o),o.mult(e,o),r.wlambda.vadd(o,r.wlambda)),n.invInertiaWorldSolve&&(n.invInertiaWorldSolve.vmult(i.rotational,o),o.mult(e,o),n.wlambda.vadd(o,n.wlambda))},r.prototype.computeC=function(){return this.computeGiMGt()+this.eps}},{"../math/JacobianElement":26,"../math/Vec3":30}],21:[function(e,t,i){function r(e,t,i){n.call(this,e,t,-i,i),this.ri=new o,this.rj=new o,this.t=new o}t.exports=r;var n=e("./Equation"),o=e("../math/Vec3");e("../math/Mat3");(r.prototype=new n).constructor=r;var s=new o,a=new o;r.prototype.computeB=function(e){this.a;var t=this.b,i=(this.bi,this.bj,this.ri),r=this.rj,n=s,o=a,l=this.t;i.cross(l,n),r.cross(l,o);var h=this.jacobianElementA,u=this.jacobianElementB;return l.negate(h.spatial),n.negate(h.rotational),u.spatial.copy(l),u.rotational.copy(o),-this.computeGW()*t-e*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],22:[function(e,t,i){function r(e,t,i){var r=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;o.call(this,e,t,-r,r),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.maxAngle=Math.PI/2}t.exports=r;var n=e("../math/Vec3"),o=(e("../math/Mat3"),e("./Equation"));(r.prototype=new o).constructor=r;var s=new n,a=new n;r.prototype.computeB=function(e){var t=this.a,i=this.b,r=this.axisA,n=this.axisB,o=s,l=a,h=this.jacobianElementA,u=this.jacobianElementB;return r.cross(n,o),n.cross(r,l),h.rotational.copy(l),u.rotational.copy(o),-(Math.cos(this.maxAngle)-r.dot(n))*t-this.computeGW()*i-e*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],23:[function(e,t,i){function r(e,t,i){i=void 0!==i?i:1e6,o.call(this,e,t,-i,i),this.axisA=new n,this.axisB=new n,this.targetVelocity=0}t.exports=r;var n=e("../math/Vec3"),o=(e("../math/Mat3"),e("./Equation"));(r.prototype=new o).constructor=r,r.prototype.computeB=function(e){this.a;var t=this.b,i=(this.bi,this.bj,this.axisA),r=this.axisB,n=this.jacobianElementA,o=this.jacobianElementB;return n.rotational.copy(i),r.negate(o.rotational),-(this.computeGW()-this.targetVelocity)*t-e*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],24:[function(e,t,i){function r(e,t,i){i=n.defaults(i,{friction:.3,restitution:.3,contactEquationStiffness:1e7,contactEquationRelaxation:3,frictionEquationStiffness:1e7,frictionEquationRelaxation:3}),this.id=r.idCounter++,this.materials=[e,t],this.friction=i.friction,this.restitution=i.restitution,this.contactEquationStiffness=i.contactEquationStiffness,this.contactEquationRelaxation=i.contactEquationRelaxation,this.frictionEquationStiffness=i.frictionEquationStiffness,this.frictionEquationRelaxation=i.frictionEquationRelaxation}var n=e("../utils/Utils");t.exports=r,r.idCounter=0},{"../utils/Utils":53}],25:[function(e,t,i){function r(e){var t="";"string"==typeof(e=e||{})?(t=e,e={}):"object"==typeof e&&(t=""),this.name=t,this.id=r.idCounter++,this.friction=void 0!==e.friction?e.friction:-1,this.restitution=void 0!==e.restitution?e.restitution:-1}t.exports=r,r.idCounter=0},{}],26:[function(e,t,i){function r(){this.spatial=new n,this.rotational=new n}t.exports=r;var n=e("./Vec3");r.prototype.multiplyElement=function(e){return e.spatial.dot(this.spatial)+e.rotational.dot(this.rotational)},r.prototype.multiplyVectors=function(e,t){return e.dot(this.spatial)+t.dot(this.rotational)}},{"./Vec3":30}],27:[function(e,t,i){function r(e){this.elements=e||[0,0,0,0,0,0,0,0,0]}t.exports=r;var n=e("./Vec3");r.prototype.identity=function(){var e=this.elements;e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1},r.prototype.setZero=function(){var e=this.elements;e[0]=0,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=0,e[6]=0,e[7]=0,e[8]=0},r.prototype.setTrace=function(e){var t=this.elements;t[0]=e.x,t[4]=e.y,t[8]=e.z},r.prototype.getTrace=function(e){var e=e||new n,t=this.elements;e.x=t[0],e.y=t[4],e.z=t[8]},r.prototype.vmult=function(e,t){t=t||new n;var i=this.elements,r=e.x,o=e.y,s=e.z;return t.x=i[0]*r+i[1]*o+i[2]*s,t.y=i[3]*r+i[4]*o+i[5]*s,t.z=i[6]*r+i[7]*o+i[8]*s,t},r.prototype.smult=function(e){for(var t=0;t<this.elements.length;t++)this.elements[t]*=e},r.prototype.mmult=function(e,t){for(var i=t||new r,n=0;n<3;n++)for(var o=0;o<3;o++){for(var s=0,a=0;a<3;a++)s+=e.elements[n+3*a]*this.elements[a+3*o];i.elements[n+3*o]=s}return i},r.prototype.scale=function(e,t){t=t||new r;for(var i=this.elements,n=t.elements,o=0;3!==o;o++)n[3*o+0]=e.x*i[3*o+0],n[3*o+1]=e.y*i[3*o+1],n[3*o+2]=e.z*i[3*o+2];return t},r.prototype.solve=function(e,t){t=t||new n;for(var i=[],r=0;r<12;r++)i.push(0);var o;for(r=0;r<3;r++)for(o=0;o<3;o++)i[r+4*o]=this.elements[r+3*o];i[3]=e.x,i[7]=e.y,i[11]=e.z;var s,a,l=3,h=l;do{if(r=h-l,0===i[r+4*r])for(o=r+1;o<h;o++)if(0!==i[r+4*o]){s=4;do{i[(a=4-s)+4*r]+=i[a+4*o]}while(--s);break}if(0!==i[r+4*r])for(o=r+1;o<h;o++){var u=i[r+4*o]/i[r+4*r];s=4;do{i[(a=4-s)+4*o]=a<=r?0:i[a+4*o]-i[a+4*r]*u}while(--s)}}while(--l);if(t.z=i[11]/i[10],t.y=(i[7]-i[6]*t.z)/i[5],t.x=(i[3]-i[2]*t.z-i[1]*t.y)/i[0],isNaN(t.x)||isNaN(t.y)||isNaN(t.z)||t.x===1/0||t.y===1/0||t.z===1/0)throw"Could not solve equation! Got x=["+t.toString()+"], b=["+e.toString()+"], A=["+this.toString()+"]";return t},r.prototype.e=function(e,t,i){if(void 0===i)return this.elements[t+3*e];this.elements[t+3*e]=i},r.prototype.copy=function(e){for(var t=0;t<e.elements.length;t++)this.elements[t]=e.elements[t];return this},r.prototype.toString=function(){for(var e="",t=0;t<9;t++)e+=this.elements[t]+",";return e},r.prototype.reverse=function(e){e=e||new r;for(var t=[],i=0;i<18;i++)t.push(0);var n;for(i=0;i<3;i++)for(n=0;n<3;n++)t[i+6*n]=this.elements[i+3*n];t[3]=1,t[9]=0,t[15]=0,t[4]=0,t[10]=1,t[16]=0,t[5]=0,t[11]=0,t[17]=1;var o,s,a=3,l=a;do{if(i=l-a,0===t[i+6*i])for(n=i+1;n<l;n++)if(0!==t[i+6*n]){o=6;do{t[(s=6-o)+6*i]+=t[s+6*n]}while(--o);break}if(0!==t[i+6*i])for(n=i+1;n<l;n++){h=t[i+6*n]/t[i+6*i];o=6;do{t[(s=6-o)+6*n]=s<=i?0:t[s+6*n]-t[s+6*i]*h}while(--o)}}while(--a);i=2;do{n=i-1;do{h=t[i+6*n]/t[i+6*i];o=6;do{t[(s=6-o)+6*n]=t[s+6*n]-t[s+6*i]*h}while(--o)}while(n--)}while(--i);i=2;do{var h=1/t[i+6*i];o=6;do{t[(s=6-o)+6*i]=t[s+6*i]*h}while(--o)}while(i--);i=2;do{n=2;do{if(s=t[3+n+6*i],isNaN(s)||s===1/0)throw"Could not reverse! A=["+this.toString()+"]";e.e(i,n,s)}while(n--)}while(i--);return e},r.prototype.setRotationFromQuaternion=function(e){var t=e.x,i=e.y,r=e.z,n=e.w,o=t+t,s=i+i,a=r+r,l=t*o,h=t*s,u=t*a,c=i*s,f=i*a,p=r*a,d=n*o,m=n*s,g=n*a,v=this.elements;return v[0]=1-(c+p),v[1]=h-g,v[2]=u+m,v[3]=h+g,v[4]=1-(l+p),v[5]=f-d,v[6]=u-m,v[7]=f+d,v[8]=1-(l+c),this},r.prototype.transpose=function(e){for(var t=(e=e||new r).elements,i=this.elements,n=0;3!==n;n++)for(var o=0;3!==o;o++)t[3*n+o]=i[3*o+n];return e}},{"./Vec3":30}],28:[function(e,t,i){function r(e,t,i,r){this.x=void 0!==e?e:0,this.y=void 0!==t?t:0,this.z=void 0!==i?i:0,this.w=void 0!==r?r:1}t.exports=r;var n=e("./Vec3");r.prototype.set=function(e,t,i,r){this.x=e,this.y=t,this.z=i,this.w=r},r.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},r.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]},r.prototype.setFromAxisAngle=function(e,t){var i=Math.sin(.5*t);this.x=e.x*i,this.y=e.y*i,this.z=e.z*i,this.w=Math.cos(.5*t)},r.prototype.toAxisAngle=function(e){e=e||new n,this.normalize();var t=2*Math.acos(this.w),i=Math.sqrt(1-this.w*this.w);return i<.001?(e.x=this.x,e.y=this.y,e.z=this.z):(e.x=this.x/i,e.y=this.y/i,e.z=this.z/i),[e,t]};var o=new n,s=new n;r.prototype.setFromVectors=function(e,t){if(e.isAntiparallelTo(t)){var i=o,r=s;e.tangents(i,r),this.setFromAxisAngle(i,Math.PI)}else{var n=e.cross(t);this.x=n.x,this.y=n.y,this.z=n.z,this.w=Math.sqrt(Math.pow(e.norm(),2)*Math.pow(t.norm(),2))+e.dot(t),this.normalize()}};var a=new n,l=new n,h=new n;r.prototype.mult=function(e,t){t=t||new r;var i=this.w,n=a,o=l,s=h;return n.set(this.x,this.y,this.z),o.set(e.x,e.y,e.z),t.w=i*e.w-n.dot(o),n.cross(o,s),t.x=i*o.x+e.w*n.x+s.x,t.y=i*o.y+e.w*n.y+s.y,t.z=i*o.z+e.w*n.z+s.z,t},r.prototype.inverse=function(e){var t=this.x,i=this.y,n=this.z,o=this.w;e=e||new r,this.conjugate(e);var s=1/(t*t+i*i+n*n+o*o);return e.x*=s,e.y*=s,e.z*=s,e.w*=s,e},r.prototype.conjugate=function(e){return e=e||new r,e.x=-this.x,e.y=-this.y,e.z=-this.z,e.w=this.w,e},r.prototype.normalize=function(){var e=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);0===e?(this.x=0,this.y=0,this.z=0,this.w=0):(e=1/e,this.x*=e,this.y*=e,this.z*=e,this.w*=e)},r.prototype.normalizeFast=function(){var e=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;0===e?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=e,this.y*=e,this.z*=e,this.w*=e)},r.prototype.vmult=function(e,t){t=t||new n;var i=e.x,r=e.y,o=e.z,s=this.x,a=this.y,l=this.z,h=this.w,u=h*i+a*o-l*r,c=h*r+l*i-s*o,f=h*o+s*r-a*i,p=-s*i-a*r-l*o;return t.x=u*h+p*-s+c*-l-f*-a,t.y=c*h+p*-a+f*-s-u*-l,t.z=f*h+p*-l+u*-a-c*-s,t},r.prototype.copy=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},r.prototype.toEuler=function(e,t){t=t||"YZX";var i,r,n,o=this.x,s=this.y,a=this.z,l=this.w;switch(t){case"YZX":var h=o*s+a*l;if(h>.499&&(i=2*Math.atan2(o,l),r=Math.PI/2,n=0),h<-.499&&(i=-2*Math.atan2(o,l),r=-Math.PI/2,n=0),isNaN(i)){var u=o*o,c=s*s,f=a*a;i=Math.atan2(2*s*l-2*o*a,1-2*c-2*f),r=Math.asin(2*h),n=Math.atan2(2*o*l-2*s*a,1-2*u-2*f)}break;default:throw new Error("Euler order "+t+" not supported yet.")}e.y=i,e.z=r,e.x=n},r.prototype.setFromEuler=function(e,t,i,r){r=r||"XYZ";var n=Math.cos(e/2),o=Math.cos(t/2),s=Math.cos(i/2),a=Math.sin(e/2),l=Math.sin(t/2),h=Math.sin(i/2);return"XYZ"===r?(this.x=a*o*s+n*l*h,this.y=n*l*s-a*o*h,this.z=n*o*h+a*l*s,this.w=n*o*s-a*l*h):"YXZ"===r?(this.x=a*o*s+n*l*h,this.y=n*l*s-a*o*h,this.z=n*o*h-a*l*s,this.w=n*o*s+a*l*h):"ZXY"===r?(this.x=a*o*s-n*l*h,this.y=n*l*s+a*o*h,this.z=n*o*h+a*l*s,this.w=n*o*s-a*l*h):"ZYX"===r?(this.x=a*o*s-n*l*h,this.y=n*l*s+a*o*h,this.z=n*o*h-a*l*s,this.w=n*o*s+a*l*h):"YZX"===r?(this.x=a*o*s+n*l*h,this.y=n*l*s+a*o*h,this.z=n*o*h-a*l*s,this.w=n*o*s-a*l*h):"XZY"===r&&(this.x=a*o*s-n*l*h,this.y=n*l*s-a*o*h,this.z=n*o*h+a*l*s,this.w=n*o*s+a*l*h),this},r.prototype.clone=function(){return new r(this.x,this.y,this.z,this.w)}},{"./Vec3":30}],29:[function(e,t,i){function r(e){e=e||{},this.position=new n,e.position&&this.position.copy(e.position),this.quaternion=new o,e.quaternion&&this.quaternion.copy(e.quaternion)}var n=e("./Vec3"),o=e("./Quaternion");t.exports=r;var s=new o;r.pointToLocalFrame=function(e,t,i,r){var r=r||new n;return i.vsub(e,r),t.conjugate(s),s.vmult(r,r),r},r.prototype.pointToLocal=function(e,t){return r.pointToLocalFrame(this.position,this.quaternion,e,t)},r.pointToWorldFrame=function(e,t,i,r){var r=r||new n;return t.vmult(i,r),r.vadd(e,r),r},r.prototype.pointToWorld=function(e,t){return r.pointToWorldFrame(this.position,this.quaternion,e,t)},r.prototype.vectorToWorldFrame=function(e,t){var t=t||new n;return this.quaternion.vmult(e,t),t},r.vectorToWorldFrame=function(e,t,i){return e.vmult(t,i),i},r.vectorToLocalFrame=function(e,t,i,r){var r=r||new n;return t.w*=-1,t.vmult(i,r),t.w*=-1,r}},{"./Quaternion":28,"./Vec3":30}],30:[function(e,t,i){function r(e,t,i){this.x=e||0,this.y=t||0,this.z=i||0}t.exports=r;var n=e("./Mat3");r.ZERO=new r(0,0,0),r.UNIT_X=new r(1,0,0),r.UNIT_Y=new r(0,1,0),r.UNIT_Z=new r(0,0,1),r.prototype.cross=function(e,t){var i=e.x,n=e.y,o=e.z,s=this.x,a=this.y,l=this.z;return t=t||new r,t.x=a*o-l*n,t.y=l*i-s*o,t.z=s*n-a*i,t},r.prototype.set=function(e,t,i){return this.x=e,this.y=t,this.z=i,this},r.prototype.setZero=function(){this.x=this.y=this.z=0},r.prototype.vadd=function(e,t){if(!t)return new r(this.x+e.x,this.y+e.y,this.z+e.z);t.x=e.x+this.x,t.y=e.y+this.y,t.z=e.z+this.z},r.prototype.vsub=function(e,t){if(!t)return new r(this.x-e.x,this.y-e.y,this.z-e.z);t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z},r.prototype.crossmat=function(){return new n([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},r.prototype.normalize=function(){var e=this.x,t=this.y,i=this.z,r=Math.sqrt(e*e+t*t+i*i);if(r>0){var n=1/r;this.x*=n,this.y*=n,this.z*=n}else this.x=0,this.y=0,this.z=0;return r},r.prototype.unit=function(e){e=e||new r;var t=this.x,i=this.y,n=this.z,o=Math.sqrt(t*t+i*i+n*n);return o>0?(o=1/o,e.x=t*o,e.y=i*o,e.z=n*o):(e.x=1,e.y=0,e.z=0),e},r.prototype.norm=function(){var e=this.x,t=this.y,i=this.z;return Math.sqrt(e*e+t*t+i*i)},r.prototype.length=r.prototype.norm,r.prototype.norm2=function(){return this.dot(this)},r.prototype.lengthSquared=r.prototype.norm2,r.prototype.distanceTo=function(e){var t=this.x,i=this.y,r=this.z,n=e.x,o=e.y,s=e.z;return Math.sqrt((n-t)*(n-t)+(o-i)*(o-i)+(s-r)*(s-r))},r.prototype.distanceSquared=function(e){var t=this.x,i=this.y,r=this.z,n=e.x,o=e.y,s=e.z;return(n-t)*(n-t)+(o-i)*(o-i)+(s-r)*(s-r)},r.prototype.mult=function(e,t){t=t||new r;var i=this.x,n=this.y,o=this.z;return t.x=e*i,t.y=e*n,t.z=e*o,t},r.prototype.scale=r.prototype.mult,r.prototype.dot=function(e){return this.x*e.x+this.y*e.y+this.z*e.z},r.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},r.prototype.negate=function(e){return e=e||new r,e.x=-this.x,e.y=-this.y,e.z=-this.z,e};var o=new r,s=new r;r.prototype.tangents=function(e,t){var i=this.norm();if(i>0){var r=o,n=1/i;r.set(this.x*n,this.y*n,this.z*n);var a=s;Math.abs(r.x)<.9?(a.set(1,0,0),r.cross(a,e)):(a.set(0,1,0),r.cross(a,e)),r.cross(e,t)}else e.set(1,0,0),t.set(0,1,0)},r.prototype.toString=function(){return this.x+","+this.y+","+this.z},r.prototype.toArray=function(){return[this.x,this.y,this.z]},r.prototype.copy=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},r.prototype.lerp=function(e,t,i){var r=this.x,n=this.y,o=this.z;i.x=r+(e.x-r)*t,i.y=n+(e.y-n)*t,i.z=o+(e.z-o)*t},r.prototype.almostEquals=function(e,t){return void 0===t&&(t=1e-6),!(Math.abs(this.x-e.x)>t||Math.abs(this.y-e.y)>t||Math.abs(this.z-e.z)>t)},r.prototype.almostZero=function(e){return void 0===e&&(e=1e-6),!(Math.abs(this.x)>e||Math.abs(this.y)>e||Math.abs(this.z)>e)};var a=new r;r.prototype.isAntiparallelTo=function(e,t){return this.negate(a),a.almostEquals(e,t)},r.prototype.clone=function(){return new r(this.x,this.y,this.z)}},{"./Mat3":27}],31:[function(e,t,i){function r(e){e=e||{},n.apply(this),this.id=r.idCounter++,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new o,this.collisionFilterGroup="number"==typeof e.collisionFilterGroup?e.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof e.collisionFilterMask?e.collisionFilterMask:1,this.collisionResponse=!0,this.position=new o,e.position&&this.position.copy(e.position),this.previousPosition=new o,this.initPosition=new o,this.velocity=new o,e.velocity&&this.velocity.copy(e.velocity),this.initVelocity=new o,this.force=new o;var t="number"==typeof e.mass?e.mass:0;this.mass=t,this.invMass=t>0?1/t:0,this.material=e.material||null,this.linearDamping="number"==typeof e.linearDamping?e.linearDamping:.01,this.type=t<=0?r.STATIC:r.DYNAMIC,typeof e.type==typeof r.STATIC&&(this.type=e.type),this.allowSleep=void 0===e.allowSleep||e.allowSleep,this.sleepState=0,this.sleepSpeedLimit=void 0!==e.sleepSpeedLimit?e.sleepSpeedLimit:.1,this.sleepTimeLimit=void 0!==e.sleepTimeLimit?e.sleepTimeLimit:1,this.timeLastSleepy=0,this._wakeUpAfterNarrowphase=!1,this.torque=new o,this.quaternion=new a,e.quaternion&&this.quaternion.copy(e.quaternion),this.initQuaternion=new a,this.angularVelocity=new o,e.angularVelocity&&this.angularVelocity.copy(e.angularVelocity),this.initAngularVelocity=new o,this.interpolatedPosition=new o,this.interpolatedQuaternion=new a,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new o,this.invInertia=new o,this.invInertiaWorld=new s,this.invMassSolve=0,this.invInertiaSolve=new o,this.invInertiaWorldSolve=new s,this.fixedRotation=void 0!==e.fixedRotation&&e.fixedRotation,this.angularDamping=void 0!==e.angularDamping?e.angularDamping:.01,this.aabb=new l,this.aabbNeedsUpdate=!0,this.wlambda=new o,e.shape&&this.addShape(e.shape),this.updateMassProperties()}t.exports=r;var n=e("../utils/EventTarget"),o=(e("../shapes/Shape"),e("../math/Vec3")),s=e("../math/Mat3"),a=e("../math/Quaternion"),l=(e("../material/Material"),e("../collision/AABB")),h=e("../shapes/Box");r.prototype=new n,r.prototype.constructor=r,r.DYNAMIC=1,r.STATIC=2,r.KINEMATIC=4,r.AWAKE=0,r.SLEEPY=1,r.SLEEPING=2,r.idCounter=0,r.prototype.wakeUp=function(){var e=this.sleepState;this.sleepState=0,e===r.SLEEPING&&this.dispatchEvent({type:"wakeup"})},r.prototype.sleep=function(){this.sleepState=r.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0)},r.sleepyEvent={type:"sleepy"},r.sleepEvent={type:"sleep"},r.prototype.sleepTick=function(e){if(this.allowSleep){var t=this.sleepState,i=this.velocity.norm2()+this.angularVelocity.norm2(),n=Math.pow(this.sleepSpeedLimit,2);t===r.AWAKE&&i<n?(this.sleepState=r.SLEEPY,this.timeLastSleepy=e,this.dispatchEvent(r.sleepyEvent)):t===r.SLEEPY&&i>n?this.wakeUp():t===r.SLEEPY&&e-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(r.sleepEvent))}},r.prototype.updateSolveMassProperties=function(){this.sleepState===r.SLEEPING||this.type===r.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},r.prototype.pointToLocalFrame=function(e,t){var t=t||new o;return e.vsub(this.position,t),this.quaternion.conjugate().vmult(t,t),t},r.prototype.vectorToLocalFrame=function(e,t){var t=t||new o;return this.quaternion.conjugate().vmult(e,t),t},r.prototype.pointToWorldFrame=function(e,t){var t=t||new o;return this.quaternion.vmult(e,t),t.vadd(this.position,t),t},r.prototype.vectorToWorldFrame=function(e,t){var t=t||new o;return this.quaternion.vmult(e,t),t};var u=new o,c=new a;r.prototype.addShape=function(e,t,i){var r=new o,n=new a;return t&&r.copy(t),i&&n.copy(i),this.shapes.push(e),this.shapeOffsets.push(r),this.shapeOrientations.push(n),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,this},r.prototype.updateBoundingRadius=function(){for(var e=this.shapes,t=this.shapeOffsets,i=e.length,r=0,n=0;n!==i;n++){var o=e[n];o.updateBoundingSphereRadius();var s=t[n].norm(),a=o.boundingSphereRadius;s+a>r&&(r=s+a)}this.boundingRadius=r};var f=new l;r.prototype.computeAABB=function(){for(var e=this.shapes,t=this.shapeOffsets,i=this.shapeOrientations,r=e.length,n=u,o=c,s=this.quaternion,a=this.aabb,l=f,h=0;h!==r;h++){var p=e[h];i[h].mult(s,o),o.vmult(t[h],n),n.vadd(this.position,n),p.calculateWorldAABB(n,o,l.lowerBound,l.upperBound),0===h?a.copy(l):a.extend(l)}this.aabbNeedsUpdate=!1};var p=new s,d=new s;new s;r.prototype.updateInertiaWorld=function(e){var t=this.invInertia;if(t.x!==t.y||t.y!==t.z||e){var i=p,r=d;i.setRotationFromQuaternion(this.quaternion),i.transpose(r),i.scale(t,i),i.mmult(r,this.invInertiaWorld)}else;};var m=new o,g=new o;r.prototype.applyForce=function(e,t){if(this.type===r.DYNAMIC){var i=m;t.vsub(this.position,i);var n=g;i.cross(e,n),this.force.vadd(e,this.force),this.torque.vadd(n,this.torque)}};var v=new o,_=new o;r.prototype.applyLocalForce=function(e,t){if(this.type===r.DYNAMIC){var i=v,n=_;this.vectorToWorldFrame(e,i),this.pointToWorldFrame(t,n),this.applyForce(i,n)}};var y=new o,x=new o,b=new o;r.prototype.applyImpulse=function(e,t){if(this.type===r.DYNAMIC){var i=y;t.vsub(this.position,i);var n=x;n.copy(e),n.mult(this.invMass,n),this.velocity.vadd(n,this.velocity);var o=b;i.cross(e,o),this.invInertiaWorld.vmult(o,o),this.angularVelocity.vadd(o,this.angularVelocity)}};var T=new o,E=new o;r.prototype.applyLocalImpulse=function(e,t){if(this.type===r.DYNAMIC){var i=T,n=E;this.vectorToWorldFrame(e,i),this.pointToWorldFrame(t,n),this.applyImpulse(i,n)}};var A=new o;r.prototype.updateMassProperties=function(){var e=A;this.invMass=this.mass>0?1/this.mass:0;var t=this.inertia,i=this.fixedRotation;this.computeAABB(),e.set((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2),h.calculateInertia(e,this.mass,t),this.invInertia.set(t.x>0&&!i?1/t.x:0,t.y>0&&!i?1/t.y:0,t.z>0&&!i?1/t.z:0),this.updateInertiaWorld(!0)},r.prototype.getVelocityAtWorldPoint=function(e,t){var i=new o;return e.vsub(this.position,i),this.angularVelocity.cross(i,t),this.velocity.vadd(t,t),t}},{"../collision/AABB":3,"../material/Material":25,"../math/Mat3":27,"../math/Quaternion":28,"../math/Vec3":30,"../shapes/Box":37,"../shapes/Shape":43,"../utils/EventTarget":49}],32:[function(e,t,i){function r(e){this.chassisBody=e.chassisBody,this.wheelInfos=[],this.sliding=!1,this.world=null,this.indexRightAxis=void 0!==e.indexRightAxis?e.indexRightAxis:1,this.indexForwardAxis=void 0!==e.indexForwardAxis?e.indexForwardAxis:0,this.indexUpAxis=void 0!==e.indexUpAxis?e.indexUpAxis:2}function n(e,t,i,r,n){var s=0,a=i,l=x,h=b,u=T;e.getVelocityAtWorldPoint(a,l),t.getVelocityAtWorldPoint(a,h),l.vsub(h,u);return s=-r.dot(u)*(1/(o(e,i,r)+o(t,i,r))),n<s&&(s=n),s<-n&&(s=-n),s}function o(e,t,i){var r=E,n=A,o=P,s=S;return t.vsub(e.position,r),r.cross(i,n),e.invInertiaWorld.vmult(n,s),s.cross(r,o),e.invMass+i.dot(o)}function s(e,t,i,r,n,o){if(n.norm2()>1.1)return 0;var s=M,a=C,l=R;e.getVelocityAtWorldPoint(t,s),i.getVelocityAtWorldPoint(r,a),s.vsub(a,l);return-.2*n.dot(l)*(1/(e.invMass+i.invMass))}e("./Body");var a=e("../math/Vec3"),l=e("../math/Quaternion"),h=(e("../collision/RaycastResult"),e("../collision/Ray")),u=e("../objects/WheelInfo");t.exports=r;new a,new a,new a;var c=new a,f=new a,p=new a;new h;r.prototype.addWheel=function(e){var t=new u(e=e||{}),i=this.wheelInfos.length;return this.wheelInfos.push(t),i},r.prototype.setSteeringValue=function(e,t){this.wheelInfos[t].steering=e};new a;r.prototype.applyEngineForce=function(e,t){this.wheelInfos[t].engineForce=e},r.prototype.setBrake=function(e,t){this.wheelInfos[t].brake=e},r.prototype.addToWorld=function(e){this.constraints;e.add(this.chassisBody);var t=this;this.preStepCallback=function(){t.updateVehicle(e.dt)},e.addEventListener("preStep",this.preStepCallback),this.world=e},r.prototype.getVehicleAxisWorld=function(e,t){t.set(0===e?1:0,1===e?1:0,2===e?1:0),this.chassisBody.vectorToWorldFrame(t,t)},r.prototype.updateVehicle=function(e){for(var t=this.wheelInfos,i=t.length,r=this.chassisBody,n=0;n<i;n++)this.updateWheelTransform(n);this.currentVehicleSpeedKmHour=3.6*r.velocity.norm();var o=new a;this.getVehicleAxisWorld(this.indexForwardAxis,o),o.dot(r.velocity)<0&&(this.currentVehicleSpeedKmHour*=-1);for(n=0;n<i;n++)this.castRay(t[n]);this.updateSuspension(e);for(var s=new a,l=new a,n=0;n<i;n++){var h=(p=t[n]).suspensionForce;h>p.maxSuspensionForce&&(h=p.maxSuspensionForce),p.raycastResult.hitNormalWorld.scale(h*e,s),p.raycastResult.hitPointWorld.vsub(r.position,l),r.applyImpulse(s,p.raycastResult.hitPointWorld)}this.updateFriction(e);var u=new a,c=new a,f=new a;for(n=0;n<i;n++){var p=t[n];r.getVelocityAtWorldPoint(p.chassisConnectionPointWorld,f);var d=1;switch(this.indexUpAxis){case 1:d=-1}if(p.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,c);var m=c.dot(p.raycastResult.hitNormalWorld);p.raycastResult.hitNormalWorld.scale(m,u),c.vsub(u,c);var g=c.dot(f);p.deltaRotation=d*g*e/p.radius}!p.sliding&&p.isInContact||0===p.engineForce||!p.useCustomSlidingRotationalSpeed||(p.deltaRotation=(p.engineForce>0?1:-1)*p.customSlidingRotationalSpeed*e),Math.abs(p.brake)>Math.abs(p.engineForce)&&(p.deltaRotation=0),p.rotation+=p.deltaRotation,p.deltaRotation*=.99}},r.prototype.updateSuspension=function(e){for(var t=this.chassisBody.mass,i=this.wheelInfos,r=i.length,n=0;n<r;n++){var o=i[n];if(o.isInContact){var s,a=o.suspensionRestLength-o.suspensionLength;s=o.suspensionStiffness*a*o.clippedInvContactDotSuspension;var l=o.suspensionRelativeVelocity;s-=(l<0?o.dampingCompression:o.dampingRelaxation)*l,o.suspensionForce=s*t,o.suspensionForce<0&&(o.suspensionForce=0)}else o.suspensionForce=0}},r.prototype.removeFromWorld=function(e){this.constraints;e.remove(this.chassisBody),e.removeEventListener("preStep",this.preStepCallback),this.world=null};var d=new a,m=new a;r.prototype.castRay=function(e){var t=d,i=m;this.updateWheelTransformWorld(e);var r=this.chassisBody,n=-1,o=e.suspensionRestLength+e.radius;e.directionWorld.scale(o,t);var s=e.chassisConnectionPointWorld;s.vadd(t,i);var l=e.raycastResult;l.reset();var h=r.collisionResponse;r.collisionResponse=!1,this.world.rayTest(s,i,l),r.collisionResponse=h;var u=l.body;if(e.raycastResult.groundObject=0,u){n=l.distance,e.raycastResult.hitNormalWorld=l.hitNormalWorld,e.isInContact=!0;var c=l.distance;e.suspensionLength=c-e.radius;var f=e.suspensionRestLength-e.maxSuspensionTravel,p=e.suspensionRestLength+e.maxSuspensionTravel;e.suspensionLength<f&&(e.suspensionLength=f),e.suspensionLength>p&&(e.suspensionLength=p,e.raycastResult.reset());var g=e.raycastResult.hitNormalWorld.dot(e.directionWorld),v=new a;r.getVelocityAtWorldPoint(e.raycastResult.hitPointWorld,v);var _=e.raycastResult.hitNormalWorld.dot(v);if(g>=-.1)e.suspensionRelativeVelocity=0,e.clippedInvContactDotSuspension=10;else{var y=-1/g;e.suspensionRelativeVelocity=_*y,e.clippedInvContactDotSuspension=y}}else e.suspensionLength=e.suspensionRestLength+0*e.maxSuspensionTravel,e.suspensionRelativeVelocity=0,e.directionWorld.scale(-1,e.raycastResult.hitNormalWorld),e.clippedInvContactDotSuspension=1;return n},r.prototype.updateWheelTransformWorld=function(e){e.isInContact=!1;var t=this.chassisBody;t.pointToWorldFrame(e.chassisConnectionPointLocal,e.chassisConnectionPointWorld),t.vectorToWorldFrame(e.directionLocal,e.directionWorld),t.vectorToWorldFrame(e.axleLocal,e.axleWorld)},r.prototype.updateWheelTransform=function(e){var t=c,i=f,r=p,n=this.wheelInfos[e];this.updateWheelTransformWorld(n),n.directionLocal.scale(-1,t),i.copy(n.axleLocal),t.cross(i,r),r.normalize(),i.normalize();var o=n.steering,s=new l;s.setFromAxisAngle(t,o);var a=new l;a.setFromAxisAngle(i,n.rotation);var h=n.worldTransform.quaternion;this.chassisBody.quaternion.mult(s,h),h.mult(a,h),h.normalize();var u=n.worldTransform.position;u.copy(n.directionWorld),u.scale(n.suspensionLength,u),u.vadd(n.chassisConnectionPointWorld,u)};var g=[new a(1,0,0),new a(0,1,0),new a(0,0,1)];r.prototype.getWheelTransformWorld=function(e){return this.wheelInfos[e].worldTransform};var v=new a,_=[],y=[];r.prototype.updateFriction=function(e){for(var t=v,i=this.wheelInfos,r=i.length,o=this.chassisBody,l=y,h=_,u=0;u<r;u++)(d=(M=i[u]).raycastResult.body)&&0,M.sideImpulse=0,M.forwardImpulse=0,l[u]||(l[u]=new a),h[u]||(h[u]=new a);for(u=0;u<r;u++)if(d=(M=i[u]).raycastResult.body){var c=h[u];this.getWheelTransformWorld(u).vectorToWorldFrame(g[this.indexRightAxis],c);var f=M.raycastResult.hitNormalWorld,p=c.dot(f);f.scale(p,t),c.vsub(t,c),c.normalize(),f.cross(c,l[u]),l[u].normalize(),M.sideImpulse=s(o,M.raycastResult.hitPointWorld,d,M.raycastResult.hitPointWorld,c),M.sideImpulse*=1}this.sliding=!1;for(u=0;u<r;u++){var d=(M=i[u]).raycastResult.body,m=0;if(M.slipInfo=1,d){var x=M.brake?M.brake:0;m=n(o,d,M.raycastResult.hitPointWorld,l[u],x);S=x/(m+=M.engineForce*e);M.slipInfo*=S}if(M.forwardImpulse=0,M.skidInfo=1,d){M.skidInfo=1;var b=M.suspensionForce*e*M.frictionSlip,T=b*b;M.forwardImpulse=m;var E=.5*M.forwardImpulse,A=1*M.sideImpulse,P=E*E+A*A;if(M.sliding=!1,P>T){this.sliding=!0,M.sliding=!0;var S=b/Math.sqrt(P);M.skidInfo*=S}}}if(this.sliding)for(u=0;u<r;u++)0!==(M=i[u]).sideImpulse&&M.skidInfo<1&&(M.forwardImpulse*=M.skidInfo,M.sideImpulse*=M.skidInfo);for(u=0;u<r;u++){var M=i[u],C=new a;if(C.copy(M.raycastResult.hitPointWorld),0!==M.forwardImpulse){var R=new a;l[u].scale(M.forwardImpulse,R),o.applyImpulse(R,C)}if(0!==M.sideImpulse){var d=M.raycastResult.body,I=new a;I.copy(M.raycastResult.hitPointWorld);var O=new a;h[u].scale(M.sideImpulse,O),o.pointToLocalFrame(C,C),C["xyz"[this.indexUpAxis]]*=M.rollInfluence,o.pointToWorldFrame(C,C),o.applyImpulse(O,C),O.scale(-1,O),d.applyImpulse(O,I)}}};var x=new a,b=new a,T=new a,E=new a,A=new a,P=new a,S=new a,M=new a,C=new a,R=new a},{"../collision/Ray":9,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Vec3":30,"../objects/WheelInfo":36,"./Body":31}],33:[function(e,t,i){function r(e){if(this.wheelBodies=[],this.coordinateSystem=void 0===e.coordinateSystem?new a(1,2,3):e.coordinateSystem.clone(),this.chassisBody=e.chassisBody,!this.chassisBody){var t=new s(new a(5,2,.5));this.chassisBody=new n(1,t)}this.constraints=[],this.wheelAxes=[],this.wheelForces=[]}var n=e("./Body"),o=e("../shapes/Sphere"),s=e("../shapes/Box"),a=e("../math/Vec3"),l=e("../constraints/HingeConstraint");t.exports=r,r.prototype.addWheel=function(e){var t=(e=e||{}).body;t||(t=new n(1,new o(1.2))),this.wheelBodies.push(t),this.wheelForces.push(0);new a;var i=void 0!==e.position?e.position.clone():new a,r=new a;this.chassisBody.pointToWorldFrame(i,r),t.position.set(r.x,r.y,r.z);var s=void 0!==e.axis?e.axis.clone():new a(0,1,0);this.wheelAxes.push(s);var h=new l(this.chassisBody,t,{pivotA:i,axisA:s,pivotB:a.ZERO,axisB:s,collideConnected:!1});return this.constraints.push(h),this.wheelBodies.length-1},r.prototype.setSteeringValue=function(e,t){var i=this.wheelAxes[t],r=Math.cos(e),n=Math.sin(e),o=i.x,s=i.y;this.constraints[t].axisA.set(r*o-n*s,n*o+r*s,0)},r.prototype.setMotorSpeed=function(e,t){var i=this.constraints[t];i.enableMotor(),i.motorTargetVelocity=e},r.prototype.disableMotor=function(e){this.constraints[e].disableMotor()};var h=new a;r.prototype.setWheelForce=function(e,t){this.wheelForces[t]=e},r.prototype.applyWheelForce=function(e,t){var i=this.wheelAxes[t],r=this.wheelBodies[t],n=r.torque;i.scale(e,h),r.vectorToWorldFrame(h,h),n.vadd(h,n)},r.prototype.addToWorld=function(e){for(var t=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),r=0;r<i.length;r++)e.add(i[r]);for(r=0;r<t.length;r++)e.addConstraint(t[r]);e.addEventListener("preStep",this._update.bind(this))},r.prototype._update=function(){for(var e=this.wheelForces,t=0;t<e.length;t++)this.applyWheelForce(e[t],t)},r.prototype.removeFromWorld=function(e){for(var t=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),r=0;r<i.length;r++)e.remove(i[r]);for(r=0;r<t.length;r++)e.removeConstraint(t[r])};var u=new a;r.prototype.getWheelSpeed=function(e){var t=this.wheelAxes[e],i=this.wheelBodies[e].angularVelocity;return this.chassisBody.vectorToWorldFrame(t,u),i.dot(u)}},{"../constraints/HingeConstraint":15,"../math/Vec3":30,"../shapes/Box":37,"../shapes/Sphere":44,"./Body":31}],34:[function(e,t,i){function r(){this.particles=[],this.density=1,this.smoothingRadius=1,this.speedOfSound=1,this.viscosity=.01,this.eps=1e-6,this.pressures=[],this.densities=[],this.neighbors=[]}t.exports=r;e("../shapes/Shape");var n=e("../math/Vec3");e("../math/Quaternion"),e("../shapes/Particle"),e("../objects/Body"),e("../material/Material");r.prototype.add=function(e){this.particles.push(e),this.neighbors.length<this.particles.length&&this.neighbors.push([])},r.prototype.remove=function(e){var t=this.particles.indexOf(e);-1!==t&&(this.particles.splice(t,1),this.neighbors.length>this.particles.length&&this.neighbors.pop())};var o=new n;r.prototype.getNeighbors=function(e,t){for(var i=this.particles.length,r=e.id,n=this.smoothingRadius*this.smoothingRadius,s=o,a=0;a!==i;a++){var l=this.particles[a];l.position.vsub(e.position,s),r!==l.id&&s.norm2()<n&&t.push(l)}};var s=new n,a=new n,l=new n,h=new n,u=new n,c=new n;r.prototype.update=function(){for(var e=this.particles.length,t=s,i=this.speedOfSound,r=this.eps,n=0;n!==e;n++){var o=this.particles[n];(P=this.neighbors[n]).length=0,this.getNeighbors(o,P),P.push(this.particles[n]);for(var f=P.length,p=0,d=0;d!==f;d++){o.position.vsub(P[d].position,t);var m=t.norm(),g=this.w(m);p+=P[d].mass*g}this.densities[n]=p,this.pressures[n]=i*i*(this.densities[n]-this.density)}for(var v=a,_=l,y=h,x=u,b=c,n=0;n!==e;n++){var T=this.particles[n];v.set(0,0,0),_.set(0,0,0);for(var E,A,P=this.neighbors[n],f=P.length,d=0;d!==f;d++){var S=P[d];T.position.vsub(S.position,x);var M=x.norm();E=-S.mass*(this.pressures[n]/(this.densities[n]*this.densities[n]+r)+this.pressures[d]/(this.densities[d]*this.densities[d]+r)),this.gradw(x,y),y.mult(E,y),v.vadd(y,v),S.velocity.vsub(T.velocity,b),b.mult(1/(1e-4+this.densities[n]*this.densities[d])*this.viscosity*S.mass,b),A=this.nablaw(M),b.mult(A,b),_.vadd(b,_)}_.mult(T.mass,_),v.mult(T.mass,v),T.force.vadd(_,T.force),T.force.vadd(v,T.force)}},r.prototype.w=function(e){var t=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(t,9))*Math.pow(t*t-e*e,3)},r.prototype.gradw=function(e,t){var i=e.norm(),r=this.smoothingRadius;e.mult(945/(32*Math.PI*Math.pow(r,9))*Math.pow(r*r-i*i,2),t)},r.prototype.nablaw=function(e){var t=this.smoothingRadius;return 945/(32*Math.PI*Math.pow(t,9))*(t*t-e*e)*(7*e*e-3*t*t)}},{"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Particle":41,"../shapes/Shape":43}],35:[function(e,t,i){function r(e,t,i){i=i||{},this.restLength="number"==typeof i.restLength?i.restLength:1,this.stiffness=i.stiffness||100,this.damping=i.damping||1,this.bodyA=e,this.bodyB=t,this.localAnchorA=new n,this.localAnchorB=new n,i.localAnchorA&&this.localAnchorA.copy(i.localAnchorA),i.localAnchorB&&this.localAnchorB.copy(i.localAnchorB),i.worldAnchorA&&this.setWorldAnchorA(i.worldAnchorA),i.worldAnchorB&&this.setWorldAnchorB(i.worldAnchorB)}var n=e("../math/Vec3");t.exports=r,r.prototype.setWorldAnchorA=function(e){this.bodyA.pointToLocalFrame(e,this.localAnchorA)},r.prototype.setWorldAnchorB=function(e){this.bodyB.pointToLocalFrame(e,this.localAnchorB)},r.prototype.getWorldAnchorA=function(e){this.bodyA.pointToWorldFrame(this.localAnchorA,e)},r.prototype.getWorldAnchorB=function(e){this.bodyB.pointToWorldFrame(this.localAnchorB,e)};var o=new n,s=new n,a=new n,l=new n,h=new n,u=new n,c=new n,f=new n,p=new n,d=new n,m=new n;r.prototype.applyForce=function(){var e=this.stiffness,t=this.damping,i=this.restLength,r=this.bodyA,n=this.bodyB,g=o,v=s,_=a,y=l,x=m,b=h,T=u,E=c,A=f,P=p,S=d;this.getWorldAnchorA(b),this.getWorldAnchorB(T),b.vsub(r.position,E),T.vsub(n.position,A),T.vsub(b,g);var M=g.norm();v.copy(g),v.normalize(),n.velocity.vsub(r.velocity,_),n.angularVelocity.cross(A,x),_.vadd(x,_),r.angularVelocity.cross(E,x),_.vsub(x,_),v.mult(-e*(M-i)-t*_.dot(v),y),r.force.vsub(y,r.force),n.force.vadd(y,n.force),E.cross(y,P),A.cross(y,S),r.torque.vsub(P,r.torque),n.torque.vadd(S,n.torque)}},{"../math/Vec3":30}],36:[function(e,t,i){function r(e){e=a.defaults(e,{chassisConnectionPointLocal:new n,chassisConnectionPointWorld:new n,directionLocal:new n,directionWorld:new n,axleLocal:new n,axleWorld:new n,suspensionRestLength:1,suspensionMaxLength:2,radius:1,suspensionStiffness:100,dampingCompression:10,dampingRelaxation:10,frictionSlip:1e4,steering:0,rotation:0,deltaRotation:0,rollInfluence:.01,maxSuspensionForce:Number.MAX_VALUE,isFrontWheel:!0,clippedInvContactDotSuspension:1,suspensionRelativeVelocity:0,suspensionForce:0,skidInfo:0,suspensionLength:0,maxSuspensionTravel:1,useCustomSlidingRotationalSpeed:!1,customSlidingRotationalSpeed:-.1}),this.maxSuspensionTravel=e.maxSuspensionTravel,this.customSlidingRotationalSpeed=e.customSlidingRotationalSpeed,this.useCustomSlidingRotationalSpeed=e.useCustomSlidingRotationalSpeed,this.sliding=!1,this.chassisConnectionPointLocal=e.chassisConnectionPointLocal.clone(),this.chassisConnectionPointWorld=e.chassisConnectionPointWorld.clone(),this.directionLocal=e.directionLocal.clone(),this.directionWorld=e.directionWorld.clone(),this.axleLocal=e.axleLocal.clone(),this.axleWorld=e.axleWorld.clone(),this.suspensionRestLength=e.suspensionRestLength,this.suspensionMaxLength=e.suspensionMaxLength,this.radius=e.radius,this.suspensionStiffness=e.suspensionStiffness,this.dampingCompression=e.dampingCompression,this.dampingRelaxation=e.dampingRelaxation,this.frictionSlip=e.frictionSlip,this.steering=0,this.rotation=0,this.deltaRotation=0,this.rollInfluence=e.rollInfluence,this.maxSuspensionForce=e.maxSuspensionForce,this.engineForce=0,this.brake=0,this.isFrontWheel=e.isFrontWheel,this.clippedInvContactDotSuspension=1,this.suspensionRelativeVelocity=0,this.suspensionForce=0,this.skidInfo=0,this.suspensionLength=0,this.sideImpulse=0,this.forwardImpulse=0,this.raycastResult=new s,this.worldTransform=new o,this.isInContact=!1}var n=e("../math/Vec3"),o=e("../math/Transform"),s=e("../collision/RaycastResult"),a=e("../utils/Utils");t.exports=r;var l=new n,h=new n,l=new n;r.prototype.updateWheel=function(e){var t=this.raycastResult;if(this.isInContact){var i=t.hitNormalWorld.dot(t.directionWorld);t.hitPointWorld.vsub(e.position,h),e.getVelocityAtWorldPoint(h,l);var r=t.hitNormalWorld.dot(l);if(i>=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var n=-1/i;this.suspensionRelativeVelocity=r*n,this.clippedInvContactDotSuspension=n}}else t.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,t.directionWorld.scale(-1,t.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":10,"../math/Transform":29,"../math/Vec3":30,"../utils/Utils":53}],37:[function(e,t,i){function r(e){n.call(this),this.type=n.types.BOX,this.halfExtents=e,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}t.exports=r;var n=e("./Shape"),o=e("../math/Vec3"),s=e("./ConvexPolyhedron");(r.prototype=new n).constructor=r,r.prototype.updateConvexPolyhedronRepresentation=function(){var e=this.halfExtents.x,t=this.halfExtents.y,i=this.halfExtents.z,r=o,n=[new r(-e,-t,-i),new r(e,-t,-i),new r(e,t,-i),new r(-e,t,-i),new r(-e,-t,i),new r(e,-t,i),new r(e,t,i),new r(-e,t,i)],a=(new r(0,0,1),new r(0,1,0),new r(1,0,0),new s(n,[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]]));this.convexPolyhedronRepresentation=a,a.material=this.material},r.prototype.calculateLocalInertia=function(e,t){return t=t||new o,r.calculateInertia(this.halfExtents,e,t),t},r.calculateInertia=function(e,t,i){var r=e;i.x=1/12*t*(2*r.y*2*r.y+2*r.z*2*r.z),i.y=1/12*t*(2*r.x*2*r.x+2*r.z*2*r.z),i.z=1/12*t*(2*r.y*2*r.y+2*r.x*2*r.x)},r.prototype.getSideNormals=function(e,t){var i=e,r=this.halfExtents;if(i[0].set(r.x,0,0),i[1].set(0,r.y,0),i[2].set(0,0,r.z),i[3].set(-r.x,0,0),i[4].set(0,-r.y,0),i[5].set(0,0,-r.z),void 0!==t)for(var n=0;n!==i.length;n++)t.vmult(i[n],i[n]);return i},r.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},r.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};var a=new o;new o;r.prototype.forEachWorldCorner=function(e,t,i){for(var r=this.halfExtents,n=[[r.x,r.y,r.z],[-r.x,r.y,r.z],[-r.x,-r.y,r.z],[-r.x,-r.y,-r.z],[r.x,-r.y,-r.z],[r.x,r.y,-r.z],[-r.x,r.y,-r.z],[r.x,-r.y,r.z]],o=0;o<n.length;o++)a.set(n[o][0],n[o][1],n[o][2]),t.vmult(a,a),e.vadd(a,a),i(a.x,a.y,a.z)};var l=[new o,new o,new o,new o,new o,new o,new o,new o];r.prototype.calculateWorldAABB=function(e,t,i,r){var n=this.halfExtents;l[0].set(n.x,n.y,n.z),l[1].set(-n.x,n.y,n.z),l[2].set(-n.x,-n.y,n.z),l[3].set(-n.x,-n.y,-n.z),l[4].set(n.x,-n.y,-n.z),l[5].set(n.x,n.y,-n.z),l[6].set(-n.x,n.y,-n.z),l[7].set(n.x,-n.y,n.z);s=l[0];t.vmult(s,s),e.vadd(s,s),r.copy(s),i.copy(s);for(var o=1;o<8;o++){var s=l[o];t.vmult(s,s),e.vadd(s,s);var a=s.x,h=s.y,u=s.z;a>r.x&&(r.x=a),h>r.y&&(r.y=h),u>r.z&&(r.z=u),a<i.x&&(i.x=a),h<i.y&&(i.y=h),u<i.z&&(i.z=u)}}},{"../math/Vec3":30,"./ConvexPolyhedron":38,"./Shape":43}],38:[function(e,t,i){function r(e,t,i){n.call(this),this.type=n.types.CONVEXPOLYHEDRON,this.vertices=e||[],this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.faces=t||[],this.faceNormals=[],this.computeNormals(),this.worldFaceNormalsNeedsUpdate=!0,this.worldFaceNormals=[],this.uniqueEdges=[],this.uniqueAxes=i?i.slice():null,this.computeEdges(),this.updateBoundingSphereRadius()}t.exports=r;var n=e("./Shape"),o=e("../math/Vec3"),s=(e("../math/Quaternion"),e("../math/Transform"));(r.prototype=new n).constructor=r;var a=new o;r.prototype.computeEdges=function(){var e=this.faces,t=this.vertices,i=(t.length,this.uniqueEdges);i.length=0;for(var r=a,n=0;n!==e.length;n++)for(var o=e[n],s=o.length,l=0;l!==s;l++){var h=(l+1)%s;t[o[l]].vsub(t[o[h]],r),r.normalize();for(var u=!1,c=0;c!==i.length;c++)if(i[c].almostEquals(r)||i[c].almostEquals(r)){u=!0;break}u||i.push(r.clone())}},r.prototype.computeNormals=function(){this.faceNormals.length=this.faces.length;for(var e=0;e<this.faces.length;e++){for(r=0;r<this.faces[e].length;r++)if(!this.vertices[this.faces[e][r]])throw new Error("Vertex "+this.faces[e][r]+" not found!");var t=this.faceNormals[e]||new o;this.getFaceNormal(e,t),t.negate(t),this.faceNormals[e]=t;var i=this.vertices[this.faces[e][0]];if(t.dot(i)<0){console.error(".faceNormals["+e+"] = Vec3("+t.toString()+") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.");for(var r=0;r<this.faces[e].length;r++)console.warn(".vertices["+this.faces[e][r]+"] = Vec3("+this.vertices[this.faces[e][r]].toString()+")")}}};var l=new o,h=new o;r.computeNormal=function(e,t,i,r){t.vsub(e,h),i.vsub(t,l),l.cross(h,r),r.isZero()||r.normalize()},r.prototype.getFaceNormal=function(e,t){var i=this.faces[e],n=this.vertices[i[0]],o=this.vertices[i[1]],s=this.vertices[i[2]];return r.computeNormal(n,o,s,t)};var u=new o;r.prototype.clipAgainstHull=function(e,t,i,r,n,s,a,l,h){for(var c=u,f=-1,p=-Number.MAX_VALUE,d=0;d<i.faces.length;d++){c.copy(i.faceNormals[d]),n.vmult(c,c);var m=c.dot(s);m>p&&(p=m,f=d)}for(var g=[],v=i.faces[f],_=v.length,y=0;y<_;y++){var x=i.vertices[v[y]],b=new o;b.copy(x),n.vmult(b,b),r.vadd(b,b),g.push(b)}f>=0&&this.clipFaceAgainstHull(s,e,t,g,a,l,h)};var c=new o,f=new o,p=new o,d=new o,m=new o,g=new o;r.prototype.findSeparatingAxis=function(e,t,i,r,n,o,s,a){var l=c,h=f,u=p,v=d,_=m,y=g,x=Number.MAX_VALUE,b=this;if(b.uniqueAxes)for(E=0;E!==b.uniqueAxes.length;E++){if(i.vmult(b.uniqueAxes[E],l),!1===(A=b.testSepAxis(l,e,t,i,r,n)))return!1;A<x&&(x=A,o.copy(l))}else for(var T=s?s.length:b.faces.length,E=0;E<T;E++){S=s?s[E]:E;if(l.copy(b.faceNormals[S]),i.vmult(l,l),!1===(A=b.testSepAxis(l,e,t,i,r,n)))return!1;A<x&&(x=A,o.copy(l))}if(e.uniqueAxes)for(E=0;E!==e.uniqueAxes.length;E++){n.vmult(e.uniqueAxes[E],h),0;var A=b.testSepAxis(h,e,t,i,r,n);if(!1===A)return!1;A<x&&(x=A,o.copy(h))}else for(var P=a?a.length:e.faces.length,E=0;E<P;E++){var S=a?a[E]:E;if(h.copy(e.faceNormals[S]),n.vmult(h,h),0,!1===(A=b.testSepAxis(h,e,t,i,r,n)))return!1;A<x&&(x=A,o.copy(h))}for(var M=0;M!==b.uniqueEdges.length;M++){i.vmult(b.uniqueEdges[M],v);for(var C=0;C!==e.uniqueEdges.length;C++)if(n.vmult(e.uniqueEdges[C],_),v.cross(_,y),!y.almostZero()){y.normalize();var R=b.testSepAxis(y,e,t,i,r,n);if(!1===R)return!1;R<x&&(x=R,o.copy(y))}}return r.vsub(t,u),u.dot(o)>0&&o.negate(o),!0};var v=[],_=[];r.prototype.testSepAxis=function(e,t,i,n,o,s){r.project(this,e,i,n,v),r.project(t,e,o,s,_);var a=v[0],l=v[1],h=_[0],u=_[1];if(a<u||h<l)return!1;var c=a-u,f=h-l;return c<f?c:f};var y=new o,x=new o;r.prototype.calculateLocalInertia=function(e,t){this.computeLocalAABB(y,x);var i=x.x-y.x,r=x.y-y.y,n=x.z-y.z;t.x=1/12*e*(2*r*2*r+2*n*2*n),t.y=1/12*e*(2*i*2*i+2*n*2*n),t.z=1/12*e*(2*r*2*r+2*i*2*i)},r.prototype.getPlaneConstantOfFace=function(e){var t=this.faces[e],i=this.faceNormals[e],r=this.vertices[t[0]];return-i.dot(r)};var b=new o,T=new o,E=new o,A=new o,P=new o,S=new o,M=new o,C=new o;r.prototype.clipFaceAgainstHull=function(e,t,i,r,n,o,s){for(var a=b,l=T,h=E,u=A,c=P,f=S,p=M,d=C,m=this,g=r,v=[],_=-1,y=Number.MAX_VALUE,x=0;x<m.faces.length;x++){a.copy(m.faceNormals[x]),i.vmult(a,a);var R=a.dot(e);R<y&&(y=R,_=x)}if(!(_<0)){var I=m.faces[_];I.connectedFaces=[];for(U=0;U<m.faces.length;U++)for(var O=0;O<m.faces[U].length;O++)-1!==I.indexOf(m.faces[U][O])&&U!==_&&-1===I.connectedFaces.indexOf(U)&&I.connectedFaces.push(U);g.length;for(var D=I.length,w=0;w<D;w++){var L=m.vertices[I[w]],F=m.vertices[I[(w+1)%D]];L.vsub(F,l),h.copy(l),i.vmult(h,h),t.vadd(h,h),u.copy(this.faceNormals[_]),i.vmult(u,u),t.vadd(u,u),h.cross(u,c),c.negate(c),f.copy(L),i.vmult(f,f),t.vadd(f,f);f.dot(c);var N=I.connectedFaces[w];p.copy(this.faceNormals[N]);B=this.getPlaneConstantOfFace(N);d.copy(p),i.vmult(d,d);V=B-d.dot(t);for(this.clipFaceAgainstPlane(g,v,d,V);g.length;)g.shift();for(;v.length;)g.push(v.shift())}p.copy(this.faceNormals[_]);var B=this.getPlaneConstantOfFace(_);d.copy(p),i.vmult(d,d);for(var V=B-d.dot(t),U=0;U<g.length;U++){var z=d.dot(g[U])+V;if(z<=n&&(console.log("clamped: depth="+z+" to minDist="+n),z=n),z<=o){var k=g[U];if(z<=0){var G={point:k,normal:d,depth:z};s.push(G)}}}}},r.prototype.clipFaceAgainstPlane=function(e,t,i,r){var n,s,a=e.length;if(a<2)return t;var l=e[e.length-1],h=e[0];n=i.dot(l)+r;for(var u=0;u<a;u++){if(h=e[u],s=i.dot(h)+r,n<0)if(s<0)(c=new o).copy(h),t.push(c);else{c=new o;l.lerp(h,n/(n-s),c),t.push(c)}else if(s<0){var c=new o;l.lerp(h,n/(n-s),c),t.push(c),t.push(h)}l=h,n=s}return t},r.prototype.computeWorldVertices=function(e,t){for(var i=this.vertices.length;this.worldVertices.length<i;)this.worldVertices.push(new o);for(var r=this.vertices,n=this.worldVertices,s=0;s!==i;s++)t.vmult(r[s],n[s]),e.vadd(n[s],n[s]);this.worldVerticesNeedsUpdate=!1};new o;r.prototype.computeLocalAABB=function(e,t){var i=this.vertices.length,r=this.vertices;e.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),t.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(var n=0;n<i;n++){var o=r[n];o.x<e.x?e.x=o.x:o.x>t.x&&(t.x=o.x),o.y<e.y?e.y=o.y:o.y>t.y&&(t.y=o.y),o.z<e.z?e.z=o.z:o.z>t.z&&(t.z=o.z)}},r.prototype.computeWorldFaceNormals=function(e){for(var t=this.faceNormals.length;this.worldFaceNormals.length<t;)this.worldFaceNormals.push(new o);for(var i=this.faceNormals,r=this.worldFaceNormals,n=0;n!==t;n++)e.vmult(i[n],r[n]);this.worldFaceNormalsNeedsUpdate=!1},r.prototype.updateBoundingSphereRadius=function(){for(var e=0,t=this.vertices,i=0,r=t.length;i!==r;i++){var n=t[i].norm2();n>e&&(e=n)}this.boundingSphereRadius=Math.sqrt(e)};var R=new o;r.prototype.calculateWorldAABB=function(e,t,i,r){for(var n,o,s,a,l,h,u=this.vertices.length,c=this.vertices,f=0;f<u;f++){R.copy(c[f]),t.vmult(R,R),e.vadd(R,R);var p=R;p.x<n||void 0===n?n=p.x:(p.x>a||void 0===a)&&(a=p.x),p.y<o||void 0===o?o=p.y:(p.y>l||void 0===l)&&(l=p.y),p.z<s||void 0===s?s=p.z:(p.z>h||void 0===h)&&(h=p.z)}i.set(n,o,s),r.set(a,l,h)},r.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},r.prototype.getAveragePointLocal=function(e){e=e||new o;for(var t=this.vertices.length,i=this.vertices,r=0;r<t;r++)e.vadd(i[r],e);return e.mult(1/t,e),e},r.prototype.transformAllPoints=function(e,t){var i=this.vertices.length,r=this.vertices;if(t){for(o=0;o<i;o++){n=r[o];t.vmult(n,n)}for(o=0;o<this.faceNormals.length;o++){var n=this.faceNormals[o];t.vmult(n,n)}}if(e)for(var o=0;o<i;o++)(n=r[o]).vadd(e,n)};var I=new o,O=new o,D=new o;r.prototype.pointIsInside=function(e){var t=this.vertices.length,i=this.vertices,r=this.faces,n=this.faceNormals,o=this.faces.length,s=I;this.getAveragePointLocal(s);for(var a=0;a<o;a++){this.faces[a].length;var t=n[a],l=i[r[a][0]],h=O;e.vsub(l,h);var u=t.dot(h),c=D;s.vsub(l,c);var f=t.dot(c);if(u<0&&f>0||u>0&&f<0)return!1}return-1};new o;var w=new o,L=new o;r.project=function(e,t,i,r,n){var o=e.vertices.length,a=w,l=0,h=0,u=L,c=e.vertices;u.setZero(),s.vectorToLocalFrame(i,r,t,a),s.pointToLocalFrame(i,r,u,u);var f=u.dot(a);h=l=c[0].dot(a);for(var p=1;p<o;p++){var d=c[p].dot(a);d>l&&(l=d),d<h&&(h=d)}if(h-=f,l-=f,h>l){var m=h;h=l,l=m}n[0]=l,n[1]=h}},{"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"./Shape":43}],39:[function(e,t,i){function r(e,t,i,r){var a=r,l=[],h=[],u=[],c=[],f=[],p=Math.cos,d=Math.sin;l.push(new o(t*p(0),t*d(0),.5*-i)),c.push(0),l.push(new o(e*p(0),e*d(0),.5*i)),f.push(1);for(_=0;_<a;_++){var m=2*Math.PI/a*(_+1),g=2*Math.PI/a*(_+.5);_<a-1?(l.push(new o(t*p(m),t*d(m),.5*-i)),c.push(2*_+2),l.push(new o(e*p(m),e*d(m),.5*i)),f.push(2*_+3),u.push([2*_+2,2*_+3,2*_+1,2*_])):u.push([0,1,2*_+1,2*_]),(a%2==1||_<a/2)&&h.push(new o(p(g),d(g),0))}u.push(f),h.push(new o(0,0,1));for(var v=[],_=0;_<c.length;_++)v.push(c[c.length-_-1]);u.push(v),this.type=n.types.CONVEXPOLYHEDRON,s.call(this,l,u,h)}t.exports=r;var n=e("./Shape"),o=e("../math/Vec3"),s=(e("../math/Quaternion"),e("./ConvexPolyhedron"));r.prototype=new s},{"../math/Quaternion":28,"../math/Vec3":30,"./ConvexPolyhedron":38,"./Shape":43}],40:[function(e,t,i){function r(e,t){t=a.defaults(t,{maxValue:null,minValue:null,elementSize:1}),this.data=e,this.maxValue=t.maxValue,this.minValue=t.minValue,this.elementSize=t.elementSize,null===t.minValue&&this.updateMinValue(),null===t.maxValue&&this.updateMaxValue(),this.cacheEnabled=!0,n.call(this),this.pillarConvex=new o,this.pillarOffset=new s,this.type=n.types.HEIGHTFIELD,this.updateBoundingSphereRadius(),this._cachedPillars={}}var n=e("./Shape"),o=e("./ConvexPolyhedron"),s=e("../math/Vec3"),a=e("../utils/Utils");t.exports=r,(r.prototype=new n).update=function(){this._cachedPillars={}},r.prototype.updateMinValue=function(){for(var e=this.data,t=e[0][0],i=0;i!==e.length;i++)for(var r=0;r!==e[i].length;r++){var n=e[i][r];n<t&&(t=n)}this.minValue=t},r.prototype.updateMaxValue=function(){for(var e=this.data,t=e[0][0],i=0;i!==e.length;i++)for(var r=0;r!==e[i].length;r++){var n=e[i][r];n>t&&(t=n)}this.maxValue=t},r.prototype.setHeightValueAtIndex=function(e,t,i){this.data[e][t]=i,this.clearCachedConvexTrianglePillar(e,t,!1),e>0&&(this.clearCachedConvexTrianglePillar(e-1,t,!0),this.clearCachedConvexTrianglePillar(e-1,t,!1)),t>0&&(this.clearCachedConvexTrianglePillar(e,t-1,!0),this.clearCachedConvexTrianglePillar(e,t-1,!1)),t>0&&e>0&&this.clearCachedConvexTrianglePillar(e-1,t-1,!0)},r.prototype.getRectMinMax=function(e,t,i,r,n){n=n||[];for(var o=this.data,s=this.minValue,a=e;a<=i;a++)for(var l=t;l<=r;l++){var h=o[a][l];h>s&&(s=h)}n[0]=this.minValue,n[1]=s},r.prototype.getIndexOfPosition=function(e,t,i,r){var n=this.elementSize,o=this.data,s=Math.floor(e/n),a=Math.floor(t/n);return i[0]=s,i[1]=a,r&&(s<0&&(s=0),a<0&&(a=0),s>=o.length-1&&(s=o.length-1),a>=o[0].length-1&&(a=o[0].length-1)),!(s<0||a<0||s>=o.length-1||a>=o[0].length-1)},r.prototype.getHeightAt=function(e,t,i){var r=[];this.getIndexOfPosition(e,t,r,i);var n=[];return this.getRectMinMax(r[0],r[1]+1,r[0],r[1]+1,n),(n[0]+n[1])/2},r.prototype.getCacheConvexTrianglePillarKey=function(e,t,i){return e+"_"+t+"_"+(i?1:0)},r.prototype.getCachedConvexTrianglePillar=function(e,t,i){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,t,i)]},r.prototype.setCachedConvexTrianglePillar=function(e,t,i,r,n){this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,t,i)]={convex:r,offset:n}},r.prototype.clearCachedConvexTrianglePillar=function(e,t,i){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,t,i)]},r.prototype.getConvexTrianglePillar=function(e,t,i){var r=this.pillarConvex,n=this.pillarOffset;if(this.cacheEnabled){if(a=this.getCachedConvexTrianglePillar(e,t,i))return this.pillarConvex=a.convex,void(this.pillarOffset=a.offset);r=new o,n=new s,this.pillarConvex=r,this.pillarOffset=n}var a=this.data,l=this.elementSize,h=r.faces;r.vertices.length=6;for(u=0;u<6;u++)r.vertices[u]||(r.vertices[u]=new s);h.length=5;for(var u=0;u<5;u++)h[u]||(h[u]=[]);var c=r.vertices,f=(Math.min(a[e][t],a[e+1][t],a[e][t+1],a[e+1][t+1])-this.minValue)/2+this.minValue;i?(n.set((e+.75)*l,(t+.75)*l,f),c[0].set(.25*l,.25*l,a[e+1][t+1]-f),c[1].set(-.75*l,.25*l,a[e][t+1]-f),c[2].set(.25*l,-.75*l,a[e+1][t]-f),c[3].set(.25*l,.25*l,-f-1),c[4].set(-.75*l,.25*l,-f-1),c[5].set(.25*l,-.75*l,-f-1),h[0][0]=0,h[0][1]=1,h[0][2]=2,h[1][0]=5,h[1][1]=4,h[1][2]=3,h[2][0]=2,h[2][1]=5,h[2][2]=3,h[2][3]=0,h[3][0]=3,h[3][1]=4,h[3][2]=1,h[3][3]=0,h[4][0]=1,h[4][1]=4,h[4][2]=5,h[4][3]=2):(n.set((e+.25)*l,(t+.25)*l,f),c[0].set(-.25*l,-.25*l,a[e][t]-f),c[1].set(.75*l,-.25*l,a[e+1][t]-f),c[2].set(-.25*l,.75*l,a[e][t+1]-f),c[3].set(-.25*l,-.25*l,-f-1),c[4].set(.75*l,-.25*l,-f-1),c[5].set(-.25*l,.75*l,-f-1),h[0][0]=0,h[0][1]=1,h[0][2]=2,h[1][0]=5,h[1][1]=4,h[1][2]=3,h[2][0]=0,h[2][1]=2,h[2][2]=5,h[2][3]=3,h[3][0]=1,h[3][1]=0,h[3][2]=3,h[3][3]=4,h[4][0]=4,h[4][1]=5,h[4][2]=2,h[4][3]=1),r.computeNormals(),r.computeEdges(),r.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(e,t,i,r,n)},r.prototype.calculateLocalInertia=function(e,t){return(t=t||new s).set(0,0,0),t},r.prototype.volume=function(){return Number.MAX_VALUE},r.prototype.calculateWorldAABB=function(e,t,i,r){i.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),r.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},r.prototype.updateBoundingSphereRadius=function(){var e=this.data,t=this.elementSize;this.boundingSphereRadius=new s(e.length*t,e[0].length*t,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).norm()}},{"../math/Vec3":30,"../utils/Utils":53,"./ConvexPolyhedron":38,"./Shape":43}],41:[function(e,t,i){function r(){n.call(this),this.type=n.types.PARTICLE}t.exports=r;var n=e("./Shape"),o=e("../math/Vec3");(r.prototype=new n).constructor=r,r.prototype.calculateLocalInertia=function(e,t){return(t=t||new o).set(0,0,0),t},r.prototype.volume=function(){return 0},r.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0},r.prototype.calculateWorldAABB=function(e,t,i,r){i.copy(e),r.copy(e)}},{"../math/Vec3":30,"./Shape":43}],42:[function(e,t,i){function r(){n.call(this),this.type=n.types.PLANE,this.worldNormal=new o,this.worldNormalNeedsUpdate=!0,this.boundingSphereRadius=Number.MAX_VALUE}t.exports=r;var n=e("./Shape"),o=e("../math/Vec3");(r.prototype=new n).constructor=r,r.prototype.computeWorldNormal=function(e){var t=this.worldNormal;t.set(0,0,1),e.vmult(t,t),this.worldNormalNeedsUpdate=!1},r.prototype.calculateLocalInertia=function(e,t){return t=t||new o},r.prototype.volume=function(){return Number.MAX_VALUE};var s=new o;r.prototype.calculateWorldAABB=function(e,t,i,r){s.set(0,0,1),t.vmult(s,s);var n=Number.MAX_VALUE;i.set(-n,-n,-n),r.set(n,n,n),1===s.x&&(r.x=e.x),1===s.y&&(r.y=e.y),1===s.z&&(r.z=e.z),-1===s.x&&(i.x=e.x),-1===s.y&&(i.y=e.y),-1===s.z&&(i.z=e.z)},r.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":30,"./Shape":43}],43:[function(e,t,i){function r(){this.id=r.idCounter++,this.type=0,this.boundingSphereRadius=0,this.collisionResponse=!0,this.material=null}t.exports=r;var r=e("./Shape");e("../math/Vec3"),e("../math/Quaternion"),e("../material/Material");r.prototype.constructor=r,r.prototype.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type},r.prototype.volume=function(){throw"volume() not implemented for shape type "+this.type},r.prototype.calculateLocalInertia=function(e,t){throw"calculateLocalInertia() not implemented for shape type "+this.type},r.idCounter=0,r.types={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256}},{"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"./Shape":43}],44:[function(e,t,i){function r(e){if(n.call(this),this.radius=void 0!==e?Number(e):1,this.type=n.types.SPHERE,this.radius<0)throw new Error("The sphere radius cannot be negative.");this.updateBoundingSphereRadius()}t.exports=r;var n=e("./Shape"),o=e("../math/Vec3");(r.prototype=new n).constructor=r,r.prototype.calculateLocalInertia=function(e,t){t=t||new o;var i=2*e*this.radius*this.radius/5;return t.x=i,t.y=i,t.z=i,t},r.prototype.volume=function(){return 4*Math.PI*this.radius/3},r.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius},r.prototype.calculateWorldAABB=function(e,t,i,r){for(var n=this.radius,o=["x","y","z"],s=0;s<o.length;s++){var a=o[s];i[a]=e[a]-n,r[a]=e[a]+n}}},{"../math/Vec3":30,"./Shape":43}],45:[function(e,t,i){function r(e,t){n.call(this),this.type=n.types.TRIMESH,this.vertices=new Float32Array(e),this.indices=new Int16Array(t),this.normals=new Float32Array(t.length),this.aabb=new a,this.edges=null,this.scale=new o(1,1,1),this.tree=new l,this.updateEdges(),this.updateNormals(),this.updateAABB(),this.updateBoundingSphereRadius(),this.updateTree()}t.exports=r;var n=e("./Shape"),o=e("../math/Vec3"),s=(e("../math/Quaternion"),e("../math/Transform")),a=e("../collision/AABB"),l=e("../utils/Octree");(r.prototype=new n).constructor=r;var h=new o;r.prototype.updateTree=function(){var e=this.tree;e.reset(),e.aabb.copy(this.aabb);var t=this.scale;e.aabb.lowerBound.x*=1/t.x,e.aabb.lowerBound.y*=1/t.y,e.aabb.lowerBound.z*=1/t.z,e.aabb.upperBound.x*=1/t.x,e.aabb.upperBound.y*=1/t.y,e.aabb.upperBound.z*=1/t.z;for(var i=new a,r=new o,n=new o,s=new o,l=[r,n,s],h=0;h<this.indices.length/3;h++){var u=3*h;this._getUnscaledVertex(this.indices[u],r),this._getUnscaledVertex(this.indices[u+1],n),this._getUnscaledVertex(this.indices[u+2],s),i.setFromPoints(l),e.insert(i,h)}e.removeEmptyNodes()};var u=new a;r.prototype.getTrianglesInAABB=function(e,t){u.copy(e);var i=this.scale,r=i.x,n=i.y,o=i.z,s=u.lowerBound,a=u.upperBound;return s.x/=r,s.y/=n,s.z/=o,a.x/=r,a.y/=n,a.z/=o,this.tree.aabbQuery(u,t)},r.prototype.setScale=function(e){var t=this.scale.x===this.scale.y===this.scale.z,i=e.x===e.y===e.z;t&&i||this.updateNormals(),this.scale.copy(e),this.updateAABB(),this.updateBoundingSphereRadius()},r.prototype.updateNormals=function(){for(var e=h,t=this.normals,i=0;i<this.indices.length/3;i++){var n=3*i,o=this.indices[n],s=this.indices[n+1],a=this.indices[n+2];this.getVertex(o,m),this.getVertex(s,g),this.getVertex(a,v),r.computeNormal(g,m,v,e),t[n]=e.x,t[n+1]=e.y,t[n+2]=e.z}},r.prototype.updateEdges=function(){for(var e={},t=function(t,i){e[n<o?n+"_"+o:o+"_"+n]=!0},i=0;i<this.indices.length/3;i++){var r=3*i,n=this.indices[r],o=this.indices[r+1];this.indices[r+2];t(),t(),t()}var s=Object.keys(e);this.edges=new Int16Array(2*s.length);for(i=0;i<s.length;i++){var a=s[i].split("_");this.edges[2*i]=parseInt(a[0],10),this.edges[2*i+1]=parseInt(a[1],10)}},r.prototype.getEdgeVertex=function(e,t,i){var r=this.edges[2*e+(t?1:0)];this.getVertex(r,i)};var c=new o,f=new o;r.prototype.getEdgeVector=function(e,t){var i=c,r=f;this.getEdgeVertex(e,0,i),this.getEdgeVertex(e,1,r),r.vsub(i,t)};var p=new o,d=new o;r.computeNormal=function(e,t,i,r){t.vsub(e,d),i.vsub(t,p),p.cross(d,r),r.isZero()||r.normalize()};var m=new o,g=new o,v=new o;r.prototype.getVertex=function(e,t){var i=this.scale;return this._getUnscaledVertex(e,t),t.x*=i.x,t.y*=i.y,t.z*=i.z,t},r.prototype._getUnscaledVertex=function(e,t){var i=3*e,r=this.vertices;return t.set(r[i],r[i+1],r[i+2])},r.prototype.getWorldVertex=function(e,t,i,r){return this.getVertex(e,r),s.pointToWorldFrame(t,i,r,r),r},r.prototype.getTriangleVertices=function(e,t,i,r){var n=3*e;this.getVertex(this.indices[n],t),this.getVertex(this.indices[n+1],i),this.getVertex(this.indices[n+2],r)},r.prototype.getNormal=function(e,t){var i=3*e;return t.set(this.normals[i],this.normals[i+1],this.normals[i+2])};var _=new a;r.prototype.calculateLocalInertia=function(e,t){this.computeLocalAABB(_);var i=_.upperBound.x-_.lowerBound.x,r=_.upperBound.y-_.lowerBound.y,n=_.upperBound.z-_.lowerBound.z;return t.set(1/12*e*(2*r*2*r+2*n*2*n),1/12*e*(2*i*2*i+2*n*2*n),1/12*e*(2*r*2*r+2*i*2*i))};var y=new o;r.prototype.computeLocalAABB=function(e){var t=e.lowerBound,i=e.upperBound,r=this.vertices.length,n=(this.vertices,y);this.getVertex(0,n),t.copy(n),i.copy(n);for(var o=0;o!==r;o++)this.getVertex(o,n),n.x<t.x?t.x=n.x:n.x>i.x&&(i.x=n.x),n.y<t.y?t.y=n.y:n.y>i.y&&(i.y=n.y),n.z<t.z?t.z=n.z:n.z>i.z&&(i.z=n.z)},r.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},r.prototype.updateBoundingSphereRadius=function(){for(var e=0,t=this.vertices,i=new o,r=0,n=t.length/3;r!==n;r++){this.getVertex(r,i);var s=i.norm2();s>e&&(e=s)}this.boundingSphereRadius=Math.sqrt(e)};new o;var x=new s,b=new a;r.prototype.calculateWorldAABB=function(e,t,i,r){var n=x,o=b;n.position=e,n.quaternion=t,this.aabb.toWorldFrame(n,o),i.copy(o.lowerBound),r.copy(o.upperBound)},r.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},r.createTorus=function(e,t,i,n,o){e=e||1,t=t||.5,i=i||8,n=n||6,o=o||2*Math.PI;for(var s=[],a=[],l=0;l<=i;l++)for(d=0;d<=n;d++){var h=d/n*o,u=l/i*Math.PI*2,c=(e+t*Math.cos(u))*Math.cos(h),f=(e+t*Math.cos(u))*Math.sin(h),p=t*Math.sin(u);s.push(c,f,p)}for(l=1;l<=i;l++)for(var d=1;d<=n;d++){var m=(n+1)*l+d-1,g=(n+1)*(l-1)+d-1,v=(n+1)*(l-1)+d,_=(n+1)*l+d;a.push(m,g,_),a.push(g,v,_)}return new r(s,a)}},{"../collision/AABB":3,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../utils/Octree":50,"./Shape":43}],46:[function(e,t,i){function r(){n.call(this),this.iterations=10,this.tolerance=1e-7}t.exports=r;e("../math/Vec3"),e("../math/Quaternion");var n=e("./Solver"),o=[],s=[],a=[];(r.prototype=new n).solve=function(e,t){var i,r,n,l,h,u=0,c=this.iterations,f=this.tolerance*this.tolerance,p=this.equations,d=p.length,m=t.bodies,g=m.length,v=e;if(0!==d)for(P=0;P!==g;P++)m[P].updateSolveMassProperties();var _=s,y=a,x=o;_.length=d,y.length=d,x.length=d;for(P=0;P!==d;P++){A=p[P];x[P]=0,y[P]=A.computeB(v),_[P]=1/A.computeC()}if(0!==d){for(P=0;P!==g;P++){var b=(S=m[P]).vlambda,T=S.wlambda;b.set(0,0,0),T&&T.set(0,0,0)}for(u=0;u!==c;u++){l=0;for(var E=0;E!==d;E++){var A=p[E];i=y[E],r=_[E],(h=x[E])+(n=r*(i-A.computeGWlambda()-A.eps*h))<A.minForce?n=A.minForce-h:h+n>A.maxForce&&(n=A.maxForce-h),x[E]+=n,l+=n>0?n:-n,A.addToWlambda(n)}if(l*l<f)break}for(var P=0;P!==g;P++){var S=m[P],M=S.velocity,C=S.angularVelocity;M.vadd(S.vlambda,M),C&&C.vadd(S.wlambda,C)}}return u}},{"../math/Quaternion":28,"../math/Vec3":30,"./Solver":47}],47:[function(e,t,i){function r(){this.equations=[]}t.exports=r,r.prototype.solve=function(e,t){return 0},r.prototype.addEquation=function(e){e.enabled&&this.equations.push(e)},r.prototype.removeEquation=function(e){var t=this.equations,i=t.indexOf(e);-1!==i&&t.splice(i,1)},r.prototype.removeAllEquations=function(){this.equations.length=0}},{}],48:[function(e,t,i){function r(e){for(l.call(this),this.iterations=10,this.tolerance=1e-7,this.subsolver=e,this.nodes=[],this.nodePool=[];this.nodePool.length<128;)this.nodePool.push(this.createNode())}function n(e){for(var t=e.length,i=0;i!==t;i++){var r=e[i];if(!(r.visited||r.body.type&p))return r}return!1}function o(e,t,i,r){for(d.push(e),e.visited=!0,t(e,i,r);d.length;)for(var o,s=d.pop();o=n(s.children);)o.visited=!0,t(o,i,r),d.push(o)}function s(e,t,i){t.push(e.body);for(var r=e.eqs.length,n=0;n!==r;n++){var o=e.eqs[n];-1===i.indexOf(o)&&i.push(o)}}function a(e,t){return t.id-e.id}t.exports=r;e("../math/Vec3"),e("../math/Quaternion");var l=e("./Solver"),h=e("../objects/Body");r.prototype=new l;var u=[],c=[],f={bodies:[]},p=h.STATIC,d=[];r.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}},r.prototype.solve=function(e,t){for(var i=u,r=this.nodePool,l=t.bodies,h=this.equations,p=h.length,d=l.length,m=this.subsolver;r.length<d;)r.push(this.createNode());i.length=d;for(y=0;y<d;y++)i[y]=r[y];for(y=0;y!==d;y++){var g=i[y];g.body=l[y],g.children.length=0,g.eqs.length=0,g.visited=!1}for(var v=0;v!==p;v++){var _=h[v],y=l.indexOf(_.bi),x=l.indexOf(_.bj),b=i[y],T=i[x];b.children.push(T),b.eqs.push(_),T.children.push(b),T.eqs.push(_)}var E,A=0,P=c;m.tolerance=this.tolerance,m.iterations=this.iterations;for(var S=f;E=n(i);){P.length=0,S.bodies.length=0,o(E,s,S.bodies,P);var M=P.length;P=P.sort(a);for(y=0;y!==M;y++)m.addEquation(P[y]);m.solve(e,S);m.removeAllEquations(),A++}return A}},{"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"./Solver":47}],49:[function(e,t,i){var r=function(){};t.exports=r,r.prototype={constructor:r,addEventListener:function(e,t){void 0===this._listeners&&(this._listeners={});var i=this._listeners;return void 0===i[e]&&(i[e]=[]),-1===i[e].indexOf(t)&&i[e].push(t),this},hasEventListener:function(e,t){if(void 0===this._listeners)return!1;var i=this._listeners;return void 0!==i[e]&&-1!==i[e].indexOf(t)},removeEventListener:function(e,t){if(void 0===this._listeners)return this;var i=this._listeners;if(void 0===i[e])return this;var r=i[e].indexOf(t);return-1!==r&&i[e].splice(r,1),this},dispatchEvent:function(e){if(void 0===this._listeners)return this;var t=this._listeners[e.type];if(void 0!==t){e.target=this;for(var i=0,r=t.length;i<r;i++)t[i].call(this,e)}return this}}},{}],50:[function(e,t,i){function r(e){e=e||{},this.root=e.root||null,this.aabb=e.aabb?e.aabb.clone():new o,this.data=[],this.children=[]}function n(e,t){(t=t||{}).root=null,t.aabb=e,r.call(this,t),this.maxDepth=void 0!==t.maxDepth?t.maxDepth:8}var o=e("../collision/AABB"),s=e("../math/Vec3");t.exports=n,n.prototype=new r,r.prototype.reset=function(e,t){this.children.length=this.data.length=0},r.prototype.insert=function(e,t,i){var r=this.data;if(i=i||0,!this.aabb.contains(e))return!1;var n=this.children;if(i<(this.maxDepth||this.root.maxDepth)){var o=!1;n.length||(this.subdivide(),o=!0);for(var s=0;8!==s;s++)if(n[s].insert(e,t,i+1))return!0;o&&(n.length=0)}return r.push(t),!0};var a=new s;r.prototype.subdivide=function(){var e=this.aabb,t=e.lowerBound,i=e.upperBound,n=this.children;n.push(new r({aabb:new o({lowerBound:new s(0,0,0)})}),new r({aabb:new o({lowerBound:new s(1,0,0)})}),new r({aabb:new o({lowerBound:new s(1,1,0)})}),new r({aabb:new o({lowerBound:new s(1,1,1)})}),new r({aabb:new o({lowerBound:new s(0,1,1)})}),new r({aabb:new o({lowerBound:new s(0,0,1)})}),new r({aabb:new o({lowerBound:new s(1,0,1)})}),new r({aabb:new o({lowerBound:new s(0,1,0)})})),i.vsub(t,a),a.scale(.5,a);for(var l=this.root||this,h=0;8!==h;h++){var u=n[h];u.root=l;var c=u.aabb.lowerBound;c.x*=a.x,c.y*=a.y,c.z*=a.z,c.vadd(t,c),c.vadd(a,u.aabb.upperBound)}},r.prototype.aabbQuery=function(e,t){this.data,this.children;for(var i=[this];i.length;){var r=i.pop();r.aabb.overlaps(e)&&Array.prototype.push.apply(t,r.data),Array.prototype.push.apply(i,r.children)}return t};var l=new o;r.prototype.rayQuery=function(e,t,i){return e.getAABB(l),l.toLocalFrame(t,l),this.aabbQuery(l,i),i},r.prototype.removeEmptyNodes=function(){for(var e=[this];e.length;){for(var t=e.pop(),i=t.children.length-1;i>=0;i--)t.children[i].data.length||t.children.splice(i,1);Array.prototype.push.apply(e,t.children)}}},{"../collision/AABB":3,"../math/Vec3":30}],51:[function(e,t,i){function r(){this.objects=[],this.type=Object}t.exports=r,r.prototype.release=function(){for(var e=arguments.length,t=0;t!==e;t++)this.objects.push(arguments[t])},r.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},r.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")}},{}],52:[function(e,t,i){function r(){this.data={keys:[]}}t.exports=r,r.prototype.get=function(e,t){if(e>t){var i=t;t=e,e=i}return this.data[e+"-"+t]},r.prototype.set=function(e,t,i){if(e>t){var r=t;t=e,e=r}var n=e+"-"+t;this.get(e,t)||this.data.keys.push(n),this.data[n]=i},r.prototype.reset=function(){for(var e=this.data,t=e.keys;t.length>0;)delete e[t.pop()]}},{}],53:[function(e,t,i){function r(){}t.exports=r,r.defaults=function(e,t){e=e||{};for(var i in t)i in e||(e[i]=t[i]);return e}},{}],54:[function(e,t,i){function r(){o.call(this),this.type=n}t.exports=r;var n=e("../math/Vec3"),o=e("./Pool");(r.prototype=new o).constructObject=function(){return new n}},{"../math/Vec3":30,"./Pool":51}],55:[function(e,t,i){function r(e){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new c,this.world=e,this.currentContactMaterial=null,this.enableFrictionReduction=!1}function n(e,t,i){for(var r=null,n=e.length,o=0;o!==n;o++){var s=e[o],a=k;e[(o+1)%n].vsub(s,a);var l=G;a.cross(t,l);var h=H;i.vsub(s,h);var u=l.dot(h);if(!(null===r||u>0&&!0===r||u<=0&&!1===r))return!1;null===r&&(r=u>0)}return!0}t.exports=r;var o=e("../collision/AABB"),s=e("../shapes/Shape"),a=e("../collision/Ray"),l=e("../math/Vec3"),h=e("../math/Transform"),u=(e("../shapes/ConvexPolyhedron"),e("../math/Quaternion")),c=(e("../solver/Solver"),e("../utils/Vec3Pool")),f=e("../equations/ContactEquation"),p=e("../equations/FrictionEquation");r.prototype.createContactEquation=function(e,t,i,r,n,o){var s;this.contactPointPool.length?((s=this.contactPointPool.pop()).bi=e,s.bj=t):s=new f(e,t),s.enabled=e.collisionResponse&&t.collisionResponse&&i.collisionResponse&&r.collisionResponse;var a=this.currentContactMaterial;s.restitution=a.restitution,s.setSpookParams(a.contactEquationStiffness,a.contactEquationRelaxation,this.world.dt);var l=i.material||e.material,h=r.material||t.material;return l&&h&&l.restitution>=0&&h.restitution>=0&&(s.restitution=l.restitution*h.restitution),s.si=n||i,s.sj=o||r,s},r.prototype.createFrictionEquationsFromContact=function(e,t){var i=e.bi,r=e.bj,n=e.si,o=e.sj,s=this.world,a=this.currentContactMaterial,l=a.friction,h=n.material||i.material,u=o.material||r.material;if(h&&u&&h.friction>=0&&u.friction>=0&&(l=h.friction*u.friction),l>0){var c=l*s.gravity.length(),f=i.invMass+r.invMass;f>0&&(f=1/f);var d=this.frictionEquationPool,m=d.length?d.pop():new p(i,r,c*f),g=d.length?d.pop():new p(i,r,c*f);return m.bi=g.bi=i,m.bj=g.bj=r,m.minForce=g.minForce=-c*f,m.maxForce=g.maxForce=c*f,m.ri.copy(e.ri),m.rj.copy(e.rj),g.ri.copy(e.ri),g.rj.copy(e.rj),e.ni.tangents(m.t,g.t),m.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,s.dt),g.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,s.dt),m.enabled=g.enabled=e.enabled,t.push(m,g),!0}return!1};var d=new l,m=new l,g=new l;r.prototype.createFrictionFromAverage=function(e){var t=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(t,this.frictionResult)&&1!==e){var i=this.frictionResult[this.frictionResult.length-2],r=this.frictionResult[this.frictionResult.length-1];d.setZero(),m.setZero(),g.setZero();for(var n=t.bi,o=(t.bj,0);o!==e;o++)(t=this.result[this.result.length-1-o]).bodyA!==n?(d.vadd(t.ni,d),m.vadd(t.ri,m),g.vadd(t.rj,g)):(d.vsub(t.ni,d),m.vadd(t.rj,m),g.vadd(t.ri,g));var s=1/e;m.scale(s,i.ri),g.scale(s,i.rj),r.ri.copy(i.ri),r.rj.copy(i.rj),d.normalize(),d.tangents(i.t,r.t)}};var v=new l,_=new l,y=new u,x=new u;r.prototype.getContacts=function(e,t,i,r,n,o,s){this.contactPointPool=n,this.frictionEquationPool=s,this.result=r,this.frictionResult=o;for(var a=y,l=x,h=v,u=_,c=0,f=e.length;c!==f;c++){var p=e[c],d=t[c],m=null;p.material&&d.material&&(m=i.getContactMaterial(p.material,d.material)||null);for(var g=0;g<p.shapes.length;g++){p.quaternion.mult(p.shapeOrientations[g],a),p.quaternion.vmult(p.shapeOffsets[g],h),h.vadd(p.position,h);for(var b=p.shapes[g],T=0;T<d.shapes.length;T++){d.quaternion.mult(d.shapeOrientations[T],l),d.quaternion.vmult(d.shapeOffsets[T],u),u.vadd(d.position,u);var E=d.shapes[T];if(!(h.distanceTo(u)>b.boundingSphereRadius+E.boundingSphereRadius)){var A=null;b.material&&E.material&&(A=i.getContactMaterial(b.material,E.material)||null),this.currentContactMaterial=A||m||i.defaultContactMaterial;var P=this[b.type|E.type];P&&(b.type<E.type?P.call(this,b,E,h,u,a,l,p,d,b,E):P.call(this,E,b,u,h,l,a,d,p,b,E))}}}}};r.prototype[s.types.BOX|s.types.BOX]=r.prototype.boxBox=function(e,t,i,r,n,o,s,a){e.convexPolyhedronRepresentation.material=e.material,t.convexPolyhedronRepresentation.material=t.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexConvex(e.convexPolyhedronRepresentation,t.convexPolyhedronRepresentation,i,r,n,o,s,a,e,t)},r.prototype[s.types.BOX|s.types.CONVEXPOLYHEDRON]=r.prototype.boxConvex=function(e,t,i,r,n,o,s,a){e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexConvex(e.convexPolyhedronRepresentation,t,i,r,n,o,s,a,e,t)},r.prototype[s.types.BOX|s.types.PARTICLE]=r.prototype.boxParticle=function(e,t,i,r,n,o,s,a){e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexParticle(e.convexPolyhedronRepresentation,t,i,r,n,o,s,a,e,t)},r.prototype[s.types.SPHERE]=r.prototype.sphereSphere=function(e,t,i,r,n,o,s,a){var l=this.createContactEquation(s,a,e,t);r.vsub(i,l.ni),l.ni.normalize(),l.ri.copy(l.ni),l.rj.copy(l.ni),l.ri.mult(e.radius,l.ri),l.rj.mult(-t.radius,l.rj),l.ri.vadd(i,l.ri),l.ri.vsub(s.position,l.ri),l.rj.vadd(r,l.rj),l.rj.vsub(a.position,l.rj),this.result.push(l),this.createFrictionEquationsFromContact(l,this.frictionResult)};var b=new l,T=new l,E=new l;r.prototype[s.types.PLANE|s.types.TRIMESH]=r.prototype.planeTrimesh=function(e,t,i,r,n,o,s,a){var u=new l,c=b;c.set(0,0,1),n.vmult(c,c);for(var f=0;f<t.vertices.length/3;f++){t.getVertex(f,u);var p=new l;p.copy(u),h.pointToWorldFrame(r,o,p,u);var d=T;if(u.vsub(i,d),c.dot(d)<=0){var m=this.createContactEquation(s,a,e,t);m.ni.copy(c);var g=E;c.scale(d.dot(c),g),u.vsub(g,g),m.ri.copy(g),m.ri.vsub(s.position,m.ri),m.rj.copy(u),m.rj.vsub(a.position,m.rj),this.result.push(m),this.createFrictionEquationsFromContact(m,this.frictionResult)}}};var A=new l,P=new l,S=(new l,new l),M=new l,C=new l,R=new l,I=new l,O=new l,D=new l,w=new l,L=new l,F=new l,N=new l,B=new o,V=[];r.prototype[s.types.SPHERE|s.types.TRIMESH]=r.prototype.sphereTrimesh=function(e,t,i,r,n,o,s,l){var u=C,c=R,f=I,p=O,d=D,m=w,g=B,v=M,_=P,y=V;h.pointToLocalFrame(r,o,i,d);var x=e.radius;g.lowerBound.set(d.x-x,d.y-x,d.z-x),g.upperBound.set(d.x+x,d.y+x,d.z+x),t.getTrianglesInAABB(g,y);for(var b=S,T=e.radius*e.radius,E=0;E<y.length;E++)for(U=0;U<3;U++)t.getVertex(t.indices[3*y[E]+U],b),b.vsub(d,_),_.norm2()<=T&&(v.copy(b),h.pointToWorldFrame(r,o,v,b),b.vsub(i,_),(K=this.createContactEquation(s,l,e,t)).ni.copy(_),K.ni.normalize(),K.ri.copy(K.ni),K.ri.scale(e.radius,K.ri),K.ri.vadd(i,K.ri),K.ri.vsub(s.position,K.ri),K.rj.copy(b),K.rj.vsub(l.position,K.rj),this.result.push(K),this.createFrictionEquationsFromContact(K,this.frictionResult));for(E=0;E<y.length;E++)for(var U=0;U<3;U++){t.getVertex(t.indices[3*y[E]+U],u),t.getVertex(t.indices[3*y[E]+(U+1)%3],c),c.vsub(u,f),d.vsub(c,m);var z=m.dot(f);d.vsub(u,m);var k=m.dot(f);if(k>0&&z<0&&(d.vsub(u,m),p.copy(f),p.normalize(),k=m.dot(p),p.scale(k,m),m.vadd(u,m),(Y=m.distanceTo(d))<e.radius)){K=this.createContactEquation(s,l,e,t);m.vsub(d,K.ni),K.ni.normalize(),K.ni.scale(e.radius,K.ri),h.pointToWorldFrame(r,o,m,m),m.vsub(l.position,K.rj),h.vectorToWorldFrame(o,K.ni,K.ni),h.vectorToWorldFrame(o,K.ri,K.ri),this.result.push(K),this.createFrictionEquationsFromContact(K,this.frictionResult)}}for(var G=L,H=F,W=N,j=A,E=0,X=y.length;E!==X;E++){t.getTriangleVertices(y[E],G,H,W),t.getNormal(y[E],j),d.vsub(G,m);var Y=m.dot(j);if(j.scale(Y,m),d.vsub(m,m),Y=m.distanceTo(d),a.pointInTriangle(m,G,H,W)&&Y<e.radius){var K=this.createContactEquation(s,l,e,t);m.vsub(d,K.ni),K.ni.normalize(),K.ni.scale(e.radius,K.ri),h.pointToWorldFrame(r,o,m,m),m.vsub(l.position,K.rj),h.vectorToWorldFrame(o,K.ni,K.ni),h.vectorToWorldFrame(o,K.ri,K.ri),this.result.push(K),this.createFrictionEquationsFromContact(K,this.frictionResult)}}y.length=0};var U=new l,z=new l;r.prototype[s.types.SPHERE|s.types.PLANE]=r.prototype.spherePlane=function(e,t,i,r,n,o,s,a){var l=this.createContactEquation(s,a,e,t);if(l.ni.set(0,0,1),o.vmult(l.ni,l.ni),l.ni.negate(l.ni),l.ni.normalize(),l.ni.mult(e.radius,l.ri),i.vsub(r,U),l.ni.mult(l.ni.dot(U),z),U.vsub(z,l.rj),-U.dot(l.ni)<=e.radius){var h=l.ri,u=l.rj;h.vadd(i,h),h.vsub(s.position,h),u.vadd(r,u),u.vsub(a.position,u),this.result.push(l),this.createFrictionEquationsFromContact(l,this.frictionResult)}};var k=new l,G=new l,H=new l,W=new l,j=new l,X=new l,Y=new l,K=[new l,new l,new l,new l,new l,new l],Q=new l,Z=new l,q=new l,J=new l;r.prototype[s.types.SPHERE|s.types.BOX]=r.prototype.sphereBox=function(e,t,i,r,n,o,s,a){var l=this.v3pool,h=K;i.vsub(r,W),t.getSideNormals(h,o);for(var u=e.radius,c=!1,f=Z,p=q,d=J,m=null,g=0,v=0,_=0,y=null,x=0,b=h.length;x!==b&&!1===c;x++){var T=j;T.copy(h[x]);var E=T.norm();T.normalize();var A=W.dot(T);if(A<E+u&&A>0){var P=X,S=Y;P.copy(h[(x+1)%3]),S.copy(h[(x+2)%3]);var M=P.norm(),C=S.norm();P.normalize(),S.normalize();var R=W.dot(P),I=W.dot(S);if(R<M&&R>-M&&I<C&&I>-C){V=Math.abs(A-E-u);(null===y||V<y)&&(y=V,v=R,_=I,m=E,f.copy(T),p.copy(P),d.copy(S),g++)}}}if(g){c=!0;N=this.createContactEquation(s,a,e,t);f.mult(-u,N.ri),N.ni.copy(f),N.ni.negate(N.ni),f.mult(m,f),p.mult(v,p),f.vadd(p,f),d.mult(_,d),f.vadd(d,N.rj),N.ri.vadd(i,N.ri),N.ri.vsub(s.position,N.ri),N.rj.vadd(r,N.rj),N.rj.vsub(a.position,N.rj),this.result.push(N),this.createFrictionEquationsFromContact(N,this.frictionResult)}for(var O=l.get(),D=Q,w=0;2!==w&&!c;w++)for(z=0;2!==z&&!c;z++)for(G=0;2!==G&&!c;G++)O.set(0,0,0),w?O.vadd(h[0],O):O.vsub(h[0],O),z?O.vadd(h[1],O):O.vsub(h[1],O),G?O.vadd(h[2],O):O.vsub(h[2],O),r.vadd(O,D),D.vsub(i,D),D.norm2()<u*u&&(c=!0,(N=this.createContactEquation(s,a,e,t)).ri.copy(D),N.ri.normalize(),N.ni.copy(N.ri),N.ri.mult(u,N.ri),N.rj.copy(O),N.ri.vadd(i,N.ri),N.ri.vsub(s.position,N.ri),N.rj.vadd(r,N.rj),N.rj.vsub(a.position,N.rj),this.result.push(N),this.createFrictionEquationsFromContact(N,this.frictionResult));l.release(O),O=null;for(var L=l.get(),F=l.get(),N=l.get(),B=l.get(),V=l.get(),U=h.length,w=0;w!==U&&!c;w++)for(var z=0;z!==U&&!c;z++)if(w%3!=z%3){h[z].cross(h[w],L),L.normalize(),h[w].vadd(h[z],F),N.copy(i),N.vsub(F,N),N.vsub(r,N);var k=N.dot(L);L.mult(k,B);for(var G=0;G===w%3||G===z%3;)G++;V.copy(i),V.vsub(B,V),V.vsub(F,V),V.vsub(r,V);var H=Math.abs(k),$=V.norm();if(H<h[G].norm()&&$<u){c=!0;var ee=this.createContactEquation(s,a,e,t);F.vadd(B,ee.rj),ee.rj.copy(ee.rj),V.negate(ee.ni),ee.ni.normalize(),ee.ri.copy(ee.rj),ee.ri.vadd(r,ee.ri),ee.ri.vsub(i,ee.ri),ee.ri.normalize(),ee.ri.mult(u,ee.ri),ee.ri.vadd(i,ee.ri),ee.ri.vsub(s.position,ee.ri),ee.rj.vadd(r,ee.rj),ee.rj.vsub(a.position,ee.rj),this.result.push(ee),this.createFrictionEquationsFromContact(ee,this.frictionResult)}}l.release(L,F,N,B,V)};var $=new l,ee=new l,te=new l,ie=new l,re=new l,ne=new l,oe=new l,se=new l,ae=new l,le=new l;r.prototype[s.types.SPHERE|s.types.CONVEXPOLYHEDRON]=r.prototype.sphereConvex=function(e,t,i,r,o,s,a,l){var h=this.v3pool;i.vsub(r,$);for(var u=t.faceNormals,c=t.faces,f=t.vertices,p=e.radius,d=0;d!==f.length;d++){var m=f[d],g=re;s.vmult(m,g),r.vadd(g,g);var v=ie;if(g.vsub(i,v),v.norm2()<p*p)return _=!0,(H=this.createContactEquation(a,l,e,t)).ri.copy(v),H.ri.normalize(),H.ni.copy(H.ri),H.ri.mult(p,H.ri),g.vsub(r,H.rj),H.ri.vadd(i,H.ri),H.ri.vsub(a.position,H.ri),H.rj.vadd(r,H.rj),H.rj.vsub(l.position,H.rj),this.result.push(H),void this.createFrictionEquationsFromContact(H,this.frictionResult)}for(var _=!1,d=0,y=c.length;d!==y&&!1===_;d++){var x=u[d],b=c[d],T=ne;s.vmult(x,T);var E=oe;s.vmult(f[b[0]],E),E.vadd(r,E);var A=se;T.mult(-p,A),i.vadd(A,A);var P=ae;A.vsub(E,P);var S=P.dot(T),M=le;if(i.vsub(E,M),S<0&&M.dot(T)>0){for(var C=[],R=0,I=b.length;R!==I;R++){var O=h.get();s.vmult(f[b[R]],O),r.vadd(O,O),C.push(O)}if(n(C,T,i)){_=!0;H=this.createContactEquation(a,l,e,t);T.mult(-p,H.ri),T.negate(H.ni);var D=h.get();T.mult(-S,D);var w=h.get();T.mult(-p,w),i.vsub(r,H.rj),H.rj.vadd(w,H.rj),H.rj.vadd(D,H.rj),H.rj.vadd(r,H.rj),H.rj.vsub(l.position,H.rj),H.ri.vadd(i,H.ri),H.ri.vsub(a.position,H.ri),h.release(D),h.release(w),this.result.push(H),this.createFrictionEquationsFromContact(H,this.frictionResult);for(var R=0,L=C.length;R!==L;R++)h.release(C[R]);return}for(R=0;R!==b.length;R++){var F=h.get(),N=h.get();s.vmult(f[b[(R+1)%b.length]],F),s.vmult(f[b[(R+2)%b.length]],N),r.vadd(F,F),r.vadd(N,N);var B=ee;N.vsub(F,B);var V=te;B.unit(V);var U=h.get(),z=h.get();i.vsub(F,z);var k=z.dot(V);V.mult(k,U),U.vadd(F,U);var G=h.get();if(U.vsub(i,G),k>0&&k*k<B.norm2()&&G.norm2()<p*p){var H=this.createContactEquation(a,l,e,t);U.vsub(r,H.rj),U.vsub(i,H.ni),H.ni.normalize(),H.ni.mult(p,H.ri),H.rj.vadd(r,H.rj),H.rj.vsub(l.position,H.rj),H.ri.vadd(i,H.ri),H.ri.vsub(a.position,H.ri),this.result.push(H),this.createFrictionEquationsFromContact(H,this.frictionResult);for(var R=0,L=C.length;R!==L;R++)h.release(C[R]);return h.release(F),h.release(N),h.release(U),h.release(G),void h.release(z)}h.release(F),h.release(N),h.release(U),h.release(G),h.release(z)}for(var R=0,L=C.length;R!==L;R++)h.release(C[R])}}};new l,new l;r.prototype[s.types.PLANE|s.types.BOX]=r.prototype.planeBox=function(e,t,i,r,n,o,s,a){t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.planeConvex(e,t.convexPolyhedronRepresentation,i,r,n,o,s,a)};var he=new l,ue=new l,ce=new l,fe=new l;r.prototype[s.types.PLANE|s.types.CONVEXPOLYHEDRON]=r.prototype.planeConvex=function(e,t,i,r,n,o,s,a){var l=he,h=ue;h.set(0,0,1),n.vmult(h,h);for(var u=0,c=ce,f=0;f!==t.vertices.length;f++)if(l.copy(t.vertices[f]),o.vmult(l,l),r.vadd(l,l),l.vsub(i,c),h.dot(c)<=0){var p=this.createContactEquation(s,a,e,t),d=fe;h.mult(h.dot(c),d),l.vsub(d,d),d.vsub(i,p.ri),p.ni.copy(h),l.vsub(r,p.rj),p.ri.vadd(i,p.ri),p.ri.vsub(s.position,p.ri),p.rj.vadd(r,p.rj),p.rj.vsub(a.position,p.rj),this.result.push(p),u++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(p,this.frictionResult)}this.enableFrictionReduction&&u&&this.createFrictionFromAverage(u)};var pe=new l,de=new l;r.prototype[s.types.CONVEXPOLYHEDRON]=r.prototype.convexConvex=function(e,t,i,r,n,o,s,a,l,h,u,c){var f=pe;if(!(i.distanceTo(r)>e.boundingSphereRadius+t.boundingSphereRadius)&&e.findSeparatingAxis(t,i,n,r,o,f,u,c)){var p=[],d=de;e.clipAgainstHull(i,n,t,r,o,f,-100,100,p);for(var m=0,g=0;g!==p.length;g++){var v=this.createContactEquation(s,a,e,t,l,h),_=v.ri,y=v.rj;f.negate(v.ni),p[g].normal.negate(d),d.mult(p[g].depth,d),p[g].point.vadd(d,_),y.copy(p[g].point),_.vsub(i,_),y.vsub(r,y),_.vadd(i,_),_.vsub(s.position,_),y.vadd(r,y),y.vsub(a.position,y),this.result.push(v),m++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(v,this.frictionResult)}this.enableFrictionReduction&&m&&this.createFrictionFromAverage(m)}};var me=new l,ge=new l,ve=new l;r.prototype[s.types.PLANE|s.types.PARTICLE]=r.prototype.planeParticle=function(e,t,i,r,n,o,s,a){var l=me;l.set(0,0,1),s.quaternion.vmult(l,l);var h=ge;if(r.vsub(s.position,h),l.dot(h)<=0){var u=this.createContactEquation(a,s,t,e);u.ni.copy(l),u.ni.negate(u.ni),u.ri.set(0,0,0);var c=ve;l.mult(l.dot(r),c),r.vsub(c,c),u.rj.copy(c),this.result.push(u),this.createFrictionEquationsFromContact(u,this.frictionResult)}};var _e=new l;r.prototype[s.types.PARTICLE|s.types.SPHERE]=r.prototype.sphereParticle=function(e,t,i,r,n,o,s,a){var l=_e;if(l.set(0,0,1),r.vsub(i,l),l.norm2()<=e.radius*e.radius){var h=this.createContactEquation(a,s,t,e);l.normalize(),h.rj.copy(l),h.rj.mult(e.radius,h.rj),h.ni.copy(l),h.ni.negate(h.ni),h.ri.set(0,0,0),this.result.push(h),this.createFrictionEquationsFromContact(h,this.frictionResult)}};var ye=new u,xe=new l,be=(new l,new l),Te=new l,Ee=new l;r.prototype[s.types.PARTICLE|s.types.CONVEXPOLYHEDRON]=r.prototype.convexParticle=function(e,t,i,r,n,o,s,a){var l=-1,h=be,u=Ee,c=null,f=xe;if(f.copy(r),f.vsub(i,f),n.conjugate(ye),ye.vmult(f,f),e.pointIsInside(f)){e.worldVerticesNeedsUpdate&&e.computeWorldVertices(i,n),e.worldFaceNormalsNeedsUpdate&&e.computeWorldFaceNormals(n);for(var p=0,d=e.faces.length;p!==d;p++){var m=[e.worldVertices[e.faces[p][0]]],g=e.worldFaceNormals[p];r.vsub(m[0],Te);var v=-g.dot(Te);(null===c||Math.abs(v)<Math.abs(c))&&(c=v,l=p,h.copy(g),0)}if(-1!==l){var _=this.createContactEquation(a,s,t,e);h.mult(c,u),u.vadd(r,u),u.vsub(i,u),_.rj.copy(u),h.negate(_.ni),_.ri.set(0,0,0);var y=_.ri,x=_.rj;y.vadd(r,y),y.vsub(a.position,y),x.vadd(i,x),x.vsub(s.position,x),this.result.push(_),this.createFrictionEquationsFromContact(_,this.frictionResult)}else console.warn("Point found inside convex, but did not find penetrating face!")}},r.prototype[s.types.BOX|s.types.HEIGHTFIELD]=r.prototype.boxHeightfield=function(e,t,i,r,n,o,s,a){e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexHeightfield(e.convexPolyhedronRepresentation,t,i,r,n,o,s,a)};var Ae=new l,Pe=new l,Se=[0];r.prototype[s.types.CONVEXPOLYHEDRON|s.types.HEIGHTFIELD]=r.prototype.convexHeightfield=function(e,t,i,r,n,o,s,a){var l=t.data,u=t.elementSize,c=e.boundingSphereRadius,f=Pe,p=Se,d=Ae;h.pointToLocalFrame(r,o,i,d);var m=Math.floor((d.x-c)/u)-1,g=Math.ceil((d.x+c)/u)+1,v=Math.floor((d.y-c)/u)-1,_=Math.ceil((d.y+c)/u)+1;if(!(g<0||_<0||m>l.length||v>l[0].length)){m<0&&(m=0),g<0&&(g=0),v<0&&(v=0),_<0&&(_=0),m>=l.length&&(m=l.length-1),g>=l.length&&(g=l.length-1),_>=l[0].length&&(_=l[0].length-1),v>=l[0].length&&(v=l[0].length-1);var y=[];t.getRectMinMax(m,v,g,_,y);var x=y[0],b=y[1];if(!(d.z-c>b||d.z+c<x))for(var T=m;T<g;T++)for(var E=v;E<_;E++)t.getConvexTrianglePillar(T,E,!1),h.pointToWorldFrame(r,o,t.pillarOffset,f),i.distanceTo(f)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&this.convexConvex(e,t.pillarConvex,i,f,n,o,s,a,null,null,p,null),t.getConvexTrianglePillar(T,E,!0),h.pointToWorldFrame(r,o,t.pillarOffset,f),i.distanceTo(f)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&this.convexConvex(e,t.pillarConvex,i,f,n,o,s,a,null,null,p,null)}};var Me=new l,Ce=new l;r.prototype[s.types.SPHERE|s.types.HEIGHTFIELD]=r.prototype.sphereHeightfield=function(e,t,i,r,n,o,s,a){var l=t.data,u=e.radius,c=t.elementSize,f=Ce,p=Me;h.pointToLocalFrame(r,o,i,p);var d=Math.floor((p.x-u)/c)-1,m=Math.ceil((p.x+u)/c)+1,g=Math.floor((p.y-u)/c)-1,v=Math.ceil((p.y+u)/c)+1;if(!(m<0||v<0||d>l.length||v>l[0].length)){d<0&&(d=0),m<0&&(m=0),g<0&&(g=0),v<0&&(v=0),d>=l.length&&(d=l.length-1),m>=l.length&&(m=l.length-1),v>=l[0].length&&(v=l[0].length-1),g>=l[0].length&&(g=l[0].length-1);var _=[];t.getRectMinMax(d,g,m,v,_);var y=_[0],x=_[1];if(!(p.z-u>x||p.z+u<y))for(var b=this.result,T=d;T<m;T++)for(var E=g;E<v;E++){var A=b.length;if(t.getConvexTrianglePillar(T,E,!1),h.pointToWorldFrame(r,o,t.pillarOffset,f),i.distanceTo(f)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&this.sphereConvex(e,t.pillarConvex,i,f,n,o,s,a),t.getConvexTrianglePillar(T,E,!0),h.pointToWorldFrame(r,o,t.pillarOffset,f),i.distanceTo(f)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&this.sphereConvex(e,t.pillarConvex,i,f,n,o,s,a),b.length-A>2)return}}}},{"../collision/AABB":3,"../collision/Ray":9,"../equations/ContactEquation":19,"../equations/FrictionEquation":21,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../shapes/ConvexPolyhedron":38,"../shapes/Shape":43,"../solver/Solver":47,"../utils/Vec3Pool":54}],56:[function(e,t,i){function r(){h.apply(this),this.dt=-1,this.allowSleep=!1,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=0,this.quatNormalizeFast=!1,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new o,this.broadphase=new _,this.bodies=[],this.solver=new a,this.constraints=[],this.narrowphase=new l(this),this.collisionMatrix=new u,this.collisionMatrixPrevious=new u,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new d,this.defaultMaterial=new c("default"),this.defaultContactMaterial=new f(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.subsystems=[],this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null}}t.exports=r;var n=e("../shapes/Shape"),o=e("../math/Vec3"),s=e("../math/Quaternion"),a=e("../solver/GSSolver"),l=(e("../utils/Vec3Pool"),e("../equations/ContactEquation"),e("../equations/FrictionEquation"),e("./Narrowphase")),h=e("../utils/EventTarget"),u=e("../collision/ArrayCollisionMatrix"),c=e("../material/Material"),f=e("../material/ContactMaterial"),p=e("../objects/Body"),d=e("../utils/TupleDictionary"),m=e("../collision/RaycastResult"),g=e("../collision/AABB"),v=e("../collision/Ray"),_=e("../collision/NaiveBroadphase");r.prototype=new h;new g;var y=new v;if(r.prototype.getContactMaterial=function(e,t){return this.contactMaterialTable.get(e.id,t.id)},r.prototype.numObjects=function(){return this.bodies.length},r.prototype.collisionMatrixTick=function(){var e=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=e,this.collisionMatrix.reset()},r.prototype.add=r.prototype.addBody=function(e){-1===this.bodies.indexOf(e)&&(e.index=this.bodies.length,this.bodies.push(e),e.world=this,e.initPosition.copy(e.position),e.initVelocity.copy(e.velocity),e.timeLastSleepy=this.time,e instanceof p&&(e.initAngularVelocity.copy(e.angularVelocity),e.initQuaternion.copy(e.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=e,this.dispatchEvent(this.addBodyEvent))},r.prototype.addConstraint=function(e){this.constraints.push(e)},r.prototype.removeConstraint=function(e){var t=this.constraints.indexOf(e);-1!==t&&this.constraints.splice(t,1)},r.prototype.rayTest=function(e,t,i){i instanceof m?this.raycastClosest(e,t,{skipBackfaces:!0},i):this.raycastAll(e,t,{skipBackfaces:!0},i)},r.prototype.raycastAll=function(e,t,i,r){return i.mode=v.ALL,i.from=e,i.to=t,i.callback=r,y.intersectWorld(this,i)},r.prototype.raycastAny=function(e,t,i,r){return i.mode=v.ANY,i.from=e,i.to=t,i.result=r,y.intersectWorld(this,i)},r.prototype.raycastClosest=function(e,t,i,r){return i.mode=v.CLOSEST,i.from=e,i.to=t,i.result=r,y.intersectWorld(this,i)},r.prototype.remove=function(e){e.world=null;var t=this.bodies.length-1,i=this.bodies,r=i.indexOf(e);if(-1!==r){i.splice(r,1);for(var n=0;n!==i.length;n++)i[n].index=n;this.collisionMatrix.setNumObjects(t),this.removeBodyEvent.body=e,this.dispatchEvent(this.removeBodyEvent)}},r.prototype.removeBody=r.prototype.remove,r.prototype.addMaterial=function(e){this.materials.push(e)},r.prototype.addContactMaterial=function(e){this.contactmaterials.push(e),this.contactMaterialTable.set(e.materials[0].id,e.materials[1].id,e)},"undefined"==typeof performance&&(performance={}),!performance.now){var x=Date.now();performance.timing&&performance.timing.navigationStart&&(x=performance.timing.navigationStart),performance.now=function(){return Date.now()-x}}var b=new o;r.prototype.step=function(e,t,i){if(i=i||10,0===(t=t||0))this.internalStep(e),this.time+=e;else{var r=Math.floor((this.time+t)/e)-Math.floor(this.time/e);r=Math.min(r,i);for(var n=performance.now(),o=0;o!==r&&(this.internalStep(e),!(performance.now()-n>1e3*e));o++);this.time+=t;for(var s=this.time%e/e,a=b,l=this.bodies,h=0;h!==l.length;h++){var u=l[h];u.type!==p.STATIC&&u.sleepState!==p.SLEEPING?(u.position.vsub(u.previousPosition,a),a.scale(s,a),u.position.vadd(a,u.interpolatedPosition)):(u.interpolatedPosition.copy(u.position),u.interpolatedQuaternion.copy(u.quaternion))}}};var T={type:"postStep"},E={type:"preStep"},A={type:"collide",body:null,contact:null},P=[],S=[],M=[],C=[],R=(new o,new o,new o,new o,new o,new o,new o,new o,new o,new s,new s),I=new s,O=new o;r.prototype.internalStep=function(e){this.dt=e;var t,i=this.contacts,r=M,o=C,s=this.numObjects(),a=this.bodies,l=this.solver,h=this.gravity,u=this.doProfiling,c=this.profile,f=p.DYNAMIC,d=this.constraints,m=S,g=(h.norm(),h.x),v=h.y,_=h.z,y=0;for(u&&(t=performance.now()),y=0;y!==s;y++)if((V=a[y]).type&f){var x=V.force,b=V.mass;x.x+=b*g,x.y+=b*v,x.z+=b*_}for(var y=0,D=this.subsystems.length;y!==D;y++)this.subsystems[y].update();u&&(t=performance.now()),r.length=0,o.length=0,this.broadphase.collisionPairs(this,r,o),u&&(c.broadphase=performance.now()-t);z=d.length;for(y=0;y!==z;y++)if(!(k=d[y]).collideConnected)for(G=r.length-1;G>=0;G-=1)(k.bodyA===r[G]&&k.bodyB===o[G]||k.bodyB===r[G]&&k.bodyA===o[G])&&(r.splice(G,1),o.splice(G,1));this.collisionMatrixTick(),u&&(t=performance.now());var w=P,L=i.length;for(y=0;y!==L;y++)w.push(i[y]);i.length=0;var F=this.frictionEquations.length;for(y=0;y!==F;y++)m.push(this.frictionEquations[y]);this.frictionEquations.length=0,this.narrowphase.getContacts(r,o,this,i,w,this.frictionEquations,m),u&&(c.narrowphase=performance.now()-t),u&&(t=performance.now());for(y=0;y<this.frictionEquations.length;y++)l.addEquation(this.frictionEquations[y]);for(var N=i.length,B=0;B!==N;B++){var V=(k=i[B]).bi,U=k.bj;k.si,k.sj,(V.material&&U.material?this.getContactMaterial(V.material,U.material)||this.defaultContactMaterial:this.defaultContactMaterial).friction;V.material&&U.material&&(V.material.friction>=0&&U.material.friction>=0&&V.material.friction*U.material.friction,V.material.restitution>=0&&U.material.restitution>=0&&(k.restitution=V.material.restitution*U.material.restitution)),l.addEquation(k),V.allowSleep&&V.type===p.DYNAMIC&&V.sleepState===p.SLEEPING&&U.sleepState===p.AWAKE&&U.type!==p.STATIC&&U.velocity.norm2()+U.angularVelocity.norm2()>=2*Math.pow(U.sleepSpeedLimit,2)&&(V._wakeUpAfterNarrowphase=!0),U.allowSleep&&U.type===p.DYNAMIC&&U.sleepState===p.SLEEPING&&V.sleepState===p.AWAKE&&V.type!==p.STATIC&&V.velocity.norm2()+V.angularVelocity.norm2()>=2*Math.pow(V.sleepSpeedLimit,2)&&(U._wakeUpAfterNarrowphase=!0),this.collisionMatrix.set(V,U,!0),this.collisionMatrixPrevious.get(V,U)||(A.body=U,A.contact=k,V.dispatchEvent(A),A.body=V,U.dispatchEvent(A))}for(u&&(c.makeContactConstraints=performance.now()-t,t=performance.now()),y=0;y!==s;y++)(V=a[y])._wakeUpAfterNarrowphase&&(V.wakeUp(),V._wakeUpAfterNarrowphase=!1);var z=d.length;for(y=0;y!==z;y++){var k=d[y];k.update();for(var G=0,H=k.equations.length;G!==H;G++){var W=k.equations[G];l.addEquation(W)}}l.solve(e,this),u&&(c.solve=performance.now()-t),l.removeAllEquations();var j=Math.pow;for(y=0;y!==s;y++)if((V=a[y]).type&f){var X=j(1-V.linearDamping,e),Y=V.velocity;Y.mult(X,Y);var K=V.angularVelocity;if(K){var Q=j(1-V.angularDamping,e);K.mult(Q,K)}}for(this.dispatchEvent(E),y=0;y!==s;y++)(V=a[y]).preStep&&V.preStep.call(V);u&&(t=performance.now());var Z=R,q=I,J=this.stepnumber,$=p.DYNAMIC|p.KINEMATIC,ee=J%(this.quatNormalizeSkip+1)==0,te=this.quatNormalizeFast,ie=.5*e;n.types.PLANE,n.types.CONVEXPOLYHEDRON;for(y=0;y!==s;y++){var re=a[y],ne=re.force,oe=re.torque;if(re.type&$&&re.sleepState!==p.SLEEPING){var se=re.velocity,ae=re.angularVelocity,le=re.position,he=re.quaternion,ue=re.invMass,ce=re.invInertiaWorld;se.x+=ne.x*ue*e,se.y+=ne.y*ue*e,se.z+=ne.z*ue*e,re.angularVelocity&&(ce.vmult(oe,O),O.mult(e,O),O.vadd(ae,ae)),le.x+=se.x*e,le.y+=se.y*e,le.z+=se.z*e,re.angularVelocity&&(Z.set(ae.x,ae.y,ae.z,0),Z.mult(he,q),he.x+=ie*q.x,he.y+=ie*q.y,he.z+=ie*q.z,he.w+=ie*q.w,ee&&(te?he.normalizeFast():he.normalize())),re.aabb&&(re.aabbNeedsUpdate=!0),re.updateInertiaWorld&&re.updateInertiaWorld()}}for(this.clearForces(),this.broadphase.dirty=!0,u&&(c.integrate=performance.now()-t),this.time+=e,this.stepnumber+=1,this.dispatchEvent(T),y=0;y!==s;y++){var fe=(V=a[y]).postStep;fe&&fe.call(V)}if(this.allowSleep)for(y=0;y!==s;y++)a[y].sleepTick(this.time)},r.prototype.clearForces=function(){for(var e=this.bodies,t=e.length,i=0;i!==t;i++){var r=e[i];r.force,r.torque;r.force.set(0,0,0),r.torque.set(0,0,0)}}},{"../collision/AABB":3,"../collision/ArrayCollisionMatrix":4,"../collision/NaiveBroadphase":7,"../collision/Ray":9,"../collision/RaycastResult":10,"../equations/ContactEquation":19,"../equations/FrictionEquation":21,"../material/ContactMaterial":24,"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Shape":43,"../solver/GSSolver":46,"../utils/EventTarget":49,"../utils/TupleDictionary":52,"../utils/Vec3Pool":54,"./Narrowphase":55}]},{},[2])(2)})},function(e,t,i){function r(e,t,i){return{a:e,b:t,c:i}}function n(e,t,i,r){var n=.5*(-i.y*r.x+t.y*(-i.x+r.x)+t.x*(i.y-r.y)+i.x*r.y),o=n<0?-1:1,s=(t.y*r.x-t.x*r.y+(r.y-t.y)*e.x+(t.x-r.x)*e.y)*o,a=(t.x*i.y-t.y*i.x+(t.y-i.y)*e.x+(i.x-t.x)*e.y)*o;return s>0&&a>0&&s+a<2*n*o}function o(e,t){return{x:e,y:t}}var s,a={REVISION:"1.2",nextID:0,proxyID:0,BR_NULL:0,BR_BRUTE_FORCE:1,BR_SWEEP_AND_PRUNE:2,BR_BOUNDING_VOLUME_TREE:3,BODY_NULL:0,BODY_DYNAMIC:1,BODY_STATIC:2,SHAPE_NULL:0,SHAPE_SPHERE:1,SHAPE_BOX:2,SHAPE_CYLINDER:3,SHAPE_TETRA:4,JOINT_NULL:0,JOINT_DISTANCE:1,JOINT_BALL_AND_SOCKET:2,JOINT_HINGE:3,JOINT_WHEEL:4,JOINT_SLIDER:5,JOINT_PRISMATIC:6,WORLD_SCALE:100,INV_SCALE:.01,AABB_PROX:.005,sqrt:Math.sqrt,abs:Math.abs,floor:Math.floor,cos:Math.cos,sin:Math.sin,acos:Math.acos,asin:Math.asin,atan2:Math.atan2,round:Math.round,pow:Math.pow,max:Math.max,min:Math.min,random:Math.random,lerp:function(e,t,i){return e+(t-e)*i},rand:function(e,t){return a.lerp(e,t,a.random())},randInt:function(e,t,i){return 1*a.lerp(e,t,a.random()).toFixed(i||0)},int:function(e){return~~e},fix:function(e,t){return e.toFixed(t||3,10)},clamp:function(e,t,i){return a.max(t,a.min(i,e))},degtorad:.017453292519943295,radtodeg:57.29577951308232,PI:3.141592653589793,TwoPI:6.283185307179586,PI90:1.570796326794896,PI270:4.712388980384689,CustomError:null,Error:function(e,t){null==a.CustomError?console.error(e,t):a.CustomError.innerHTML+=e+" - "+t+"<br>"}};s||(s="undefined"!=typeof Float32Array?Float32Array:Array);try{!function(e){var t,i=["now","webkitNow","msNow","mozNow"];if(e.performance)for(var r=0;r<i.length;++r){var n=i[r];if(e.performance[n]){t=function(){return e.performance[n]()};break}}t||(t=Date.now),a.now=t}(window)}catch(e){a.now=function(){return 0}}a.World=function(e,t,i,r){switch(this.timeStep=e||.01666,this.numIterations=i||8,t||2){case 1:this.broadPhase=new a.BruteForceBroadPhase;break;case 2:default:this.broadPhase=new a.SAPBroadPhase;break;case 3:this.broadPhase=new a.DBVTBroadPhase}this.performance=null,this.isNoStat=r||!1,this.isNoStat||(this.performance=new a.Performance(this)),this.enableRandomizer=!0,this.rigidBodies=null,this.numRigidBodies=0,this.contacts=null,this.unusedContacts=null,this.numContacts=0,this.numContactPoints=0,this.joints=null,this.numJoints=0,this.numIslands=0,this.gravity=new a.Vec3(0,-9.80665,0);this.detectors=[],this.detectors.length=5;for(var n=5;n--;)this.detectors[n]=[],this.detectors[n].length=5;this.detectors[a.SHAPE_SPHERE][a.SHAPE_SPHERE]=new a.SphereSphereCollisionDetector,this.detectors[a.SHAPE_SPHERE][a.SHAPE_BOX]=new a.SphereBoxCollisionDetector(!1),this.detectors[a.SHAPE_BOX][a.SHAPE_SPHERE]=new a.SphereBoxCollisionDetector(!0),this.detectors[a.SHAPE_BOX][a.SHAPE_BOX]=new a.BoxBoxCollisionDetector,this.detectors[a.SHAPE_CYLINDER][a.SHAPE_CYLINDER]=new a.CylinderCylinderCollisionDetector,this.detectors[a.SHAPE_CYLINDER][a.SHAPE_BOX]=new a.BoxCylinderCollisionDetector(!0),this.detectors[a.SHAPE_BOX][a.SHAPE_CYLINDER]=new a.BoxCylinderCollisionDetector(!1),this.detectors[a.SHAPE_CYLINDER][a.SHAPE_SPHERE]=new a.SphereCylinderCollisionDetector(!0),this.detectors[a.SHAPE_SPHERE][a.SHAPE_CYLINDER]=new a.SphereCylinderCollisionDetector(!1),this.detectors[a.SHAPE_TETRA][a.SHAPE_TETRA]=new a.TetraTetraCollisionDetector,this.randX=65535,this.randA=98765,this.randB=123456789,this.islandRigidBodies=[],this.islandStack=[],this.islandConstraints=[]},a.World.prototype={constructor:a.World,clear:function(){for(this.randX=65535;null!==this.joints;)this.removeJoint(this.joints);for(;null!==this.contacts;)this.removeContact(this.contacts);for(;null!==this.rigidBodies;)this.removeRigidBody(this.rigidBodies);a.nextID=0,a.proxyID=0},addRigidBody:function(e){e.parent&&a.Error("World","It is not possible to be added to more than one world one of the rigid body"),e.parent=this,e.awake();for(var t=e.shapes;null!==t;t=t.next)this.addShape(t);null!==this.rigidBodies&&((this.rigidBodies.prev=e).next=this.rigidBodies),this.rigidBodies=e,this.numRigidBodies++},removeRigidBody:function(e){var t=e;if(t.parent===this){t.awake();for(var i=t.jointLink;null!=i;){var r=i.joint;i=i.next,this.removeJoint(r)}for(var n=e.shapes;null!==n;n=n.next)this.removeShape(n);var o=t.prev,s=t.next;null!==o&&(o.next=s),null!==s&&(s.prev=o),this.rigidBodies==t&&(this.rigidBodies=s),t.prev=null,t.next=null,t.parent=null,this.numRigidBodies--}},getByName:function(e){for(var t=null,i=this.rigidBodies;null!==i;)" "!==i.name&&i.name===e&&(t=i),i=i.next;for(var r=this.joints;null!==r;)""!==r.name&&r.name===e&&(t=r),r=r.next;return t},addShape:function(e){e.parent&&e.parent.parent||a.Error("World","It is not possible to be added alone to shape world"),e.proxy=this.broadPhase.createProxy(e),e.updateProxy(),this.broadPhase.addProxy(e.proxy)},removeShape:function(e){this.broadPhase.removeProxy(e.proxy),e.proxy=null},addJoint:function(e){e.parent&&a.Error("World","It is not possible to be added to more than one world one of the joint"),null!=this.joints&&((this.joints.prev=e).next=this.joints),this.joints=e,e.parent=this,this.numJoints++,e.awake(),e.attach()},removeJoint:function(e){var t=e,i=t.prev,r=t.next;null!==i&&(i.next=r),null!==r&&(r.prev=i),this.joints==t&&(this.joints=r),t.prev=null,t.next=null,this.numJoints--,t.awake(),t.detach(),t.parent=null},worldscale:function(e){a.WORLD_SCALE=e||100,a.INV_SCALE=1/a.WORLD_SCALE},addContact:function(e,t){var i;null!==this.unusedContacts?(i=this.unusedContacts,this.unusedContacts=this.unusedContacts.next):i=new a.Contact,i.attach(e,t),i.detector=this.detectors[e.type][t.type],this.contacts&&((this.contacts.prev=i).next=this.contacts),this.contacts=i,this.numContacts++},removeContact:function(e){var t=e.prev,i=e.next;i&&(i.prev=t),t&&(t.next=i),this.contacts==e&&(this.contacts=i),e.prev=null,e.next=null,e.detach(),e.next=this.unusedContacts,this.unusedContacts=e,this.numContacts--},checkContact:function(e,t){for(var i,r,n=this.contacts;null!==n;){if(i=n.body1.name||" ",r=n.body2.name||" ",i==e&&r==t||r==e&&i==t)return!!n.touching;n=n.next}return!1},callSleep:function(e){return!!e.allowSleep&&(!(e.linearVelocity.lengthSq()>.04)&&!(e.angularVelocity.lengthSq()>.25))},step:function(){var e,t,i,r,n=!this.isNoStat;n&&(e=a.now());for(var o=this.rigidBodies;null!==o;)o.addedToIsland=!1,o.sleeping&&(o.linearVelocity.testZero()||o.angularVelocity.testZero()||o.position.testDiff(o.sleepPosition)||o.orientation.testDiff(o.sleepOrientation))&&o.awake(),o=o.next;n&&(t=a.now()),this.broadPhase.detectPairs();for(var s=this.broadPhase.pairs,l=this.broadPhase.numPairs;l--;){var h,u,c=s[l];c.shape1.id<c.shape2.id?(h=c.shape1,u=c.shape2):(h=c.shape2,u=c.shape1);var f;f=h.numContacts<u.numContacts?h.contactLink:u.contactLink;for(var p=!1;f;){if((P=f.contact).shape1==h&&P.shape2==u){P.persisting=!0,p=!0;break}f=f.next}p||this.addContact(h,u)}for(n&&(i=a.now(),this.performance.broadPhaseTime=i-t),this.numContactPoints=0,P=this.contacts;null!==P;)if(P.persisting||!P.shape1.aabb.intersectTest(P.shape2.aabb)){var d=P.body1,m=P.body2;(d.isDynamic&&!d.sleeping||m.isDynamic&&!m.sleeping)&&P.updateManifold(),this.numContactPoints+=P.manifold.numPoints,P.persisting=!1,P.constraint.addedToIsland=!1,P=P.next}else{var g=P.next;this.removeContact(P),P=g}n&&(r=a.now(),this.performance.narrowPhaseTime=r-i);var v,_,y=1/this.timeStep;for(v=this.joints;null!==v;v=v.next)v.addedToIsland=!1;this.islandRigidBodies=[],this.islandConstraints=[],this.islandStack=[],t=a.now(),this.numIslands=0;for(var x=this.rigidBodies;null!==x;x=x.next)if(!(x.addedToIsland||x.isStatic||x.sleeping))if(x.isLonely())x.isDynamic&&x.linearVelocity.addTime(this.gravity,this.timeStep),this.callSleep(x)?(x.sleepTime+=this.timeStep,x.sleepTime>.5?x.sleep():x.updatePosition(this.timeStep)):(x.sleepTime=0,x.updatePosition(this.timeStep)),this.numIslands++;else{var b=0,T=0,E=1;this.islandStack[0]=x,x.addedToIsland=!0;do{if(o=this.islandStack[--E],this.islandStack[E]=null,o.sleeping=!1,this.islandRigidBodies[b++]=o,!o.isStatic){for(var A=o.contactLink;null!==A;A=A.next){var P=A.contact;!(_=P.constraint).addedToIsland&&P.touching&&(this.islandConstraints[T++]=_,_.addedToIsland=!0,(g=A.body).addedToIsland||(this.islandStack[E++]=g,g.addedToIsland=!0))}for(var S=o.jointLink;null!==S;S=S.next)(_=S.joint).addedToIsland||(this.islandConstraints[T++]=_,_.addedToIsland=!0,!(g=S.body).addedToIsland&&g.isDynamic&&(this.islandStack[E++]=g,g.addedToIsland=!0))}}while(0!=E);for(var M=(new a.Vec3).addTime(this.gravity,this.timeStep),C=b;C--;)(o=this.islandRigidBodies[C]).isDynamic&&o.linearVelocity.addEqual(M);if(this.enableRandomizer)for(C=T;C--;)if(0!==C){var R=(this.randX=this.randX*this.randA+this.randB&2147483647)/2147483648*C|0;_=this.islandConstraints[C],this.islandConstraints[C]=this.islandConstraints[R],this.islandConstraints[R]=_}for(C=T;C--;)this.islandConstraints[C].preSolve(this.timeStep,y);for(var I=this.numIterations;I--;)for(C=T;C--;)this.islandConstraints[C].solve();for(C=T;C--;)this.islandConstraints[C].postSolve(),this.islandConstraints[C]=null;var O=10;for(C=b;C--;)o=this.islandRigidBodies[C],this.callSleep(o)?(o.sleepTime+=this.timeStep,o.sleepTime<O&&(O=o.sleepTime)):(o.sleepTime=0,O=0);if(O>.5)for(C=b;C--;)this.islandRigidBodies[C].sleep(),this.islandRigidBodies[C]=null;else for(C=b;C--;)this.islandRigidBodies[C].updatePosition(this.timeStep),this.islandRigidBodies[C]=null;this.numIslands++}n&&(i=a.now(),this.performance.solvingTime=i-t,i=a.now(),this.performance.upfps(),this.performance.totalTime=i-e)}},a.RigidBody=function(e,t,i,r,n,o,s){this.name=" ",this.MAX_SHAPES=64,this.prev=null,this.next=null,this.type=a.BODY_NULL,this.massInfo=new a.MassInfo,this.position=new a.Vec3(e,t,i),this.orientation=this.rotationAxisToQuad(r||0,n||0,o||0,s||0),this.newPosition=new a.Vec3,this.controlPos=!1,this.newOrientation=new a.Quat,this.newRotation=new a.Vec3,this.currentRotation=new a.Vec3,this.controlRot=!1,this.controlRotInTime=!1,this.linearVelocity=new a.Vec3,this.angularVelocity=new a.Vec3,this.matrix=new a.Mat44,this.parent=null,this.contactLink=null,this.numContacts=0,this.shapes=null,this.numShapes=0,this.jointLink=null,this.numJoints=0,this.sleepPosition=new a.Vec3,this.sleepOrientation=new a.Quat,this.isStatic=!1,this.isDynamic=!1,this.rotation=new a.Mat33,this.mass=NaN,this.inverseMass=NaN,this.inverseInertia=new a.Mat33,this.localInertia=new a.Mat33,this.inverseLocalInertia=new a.Mat33,this.addedToIsland=!1,this.allowSleep=!0,this.sleepTime=0,this.sleeping=!1},a.RigidBody.prototype={constructor:a.RigidBody,addShape:function(e){e.parent&&a.Error("RigidBody","It is not possible that you add to the multi-rigid body the shape of one"),null!=this.shapes&&((this.shapes.prev=e).next=this.shapes),this.shapes=e,e.parent=this,this.parent&&this.parent.addShape(e),this.numShapes++},removeShape:function(e){var t=e;if(t.parent==this){var i=t.prev,r=t.next;null!=i&&(i.next=r),null!=r&&(r.prev=i),this.shapes==t&&(this.shapes=r),t.prev=null,t.next=null,t.parent=null,this.parent&&this.parent.removeShape(t),this.numShapes--}},remove:function(){this.dispose()},dispose:function(){this.parent.removeRigidBody(this)},checkContact:function(e){this.parent.checkContact(this.name,e)},setupMass:function(e,t){var i=void 0===t||t;this.type=e||a.BODY_DYNAMIC,this.isDynamic=this.type==a.BODY_DYNAMIC,this.isStatic=this.type==a.BODY_STATIC,this.mass=0,this.localInertia.set(0,0,0,0,0,0,0,0,0);for(var r=this.localInertia.elements,n=new a.Mat33,o=new a.Vec3,s=this.shapes;null!=s;s=s.next){s.calculateMassInfo(this.massInfo);var l=this.massInfo.mass,h=s.relativePosition.x,u=s.relativePosition.y,c=s.relativePosition.z;o.addScale(s.relativePosition,l),this.mass+=l,this.rotateInertia(s.relativeRotation,this.massInfo.inertia,n),this.localInertia.addEqual(n),r[0]+=l*(u*u+c*c),r[4]+=l*(h*h+c*c),r[8]+=l*(h*h+u*u);var f=l*h*u,p=l*u*c,d=l*c*h;r[1]-=f,r[3]-=f,r[2]-=p,r[6]-=p,r[5]-=d,r[7]-=d}if(this.inverseMass=1/this.mass,o.scaleEqual(this.inverseMass),i){for(this.position.addEqual(o),s=this.shapes;null!=s;s=s.next)s.relativePosition.subEqual(o);h=o.x,u=o.y,c=o.z,r[0]-=this.mass*(u*u+c*c),r[4]-=this.mass*(h*h+c*c),r[8]-=this.mass*(h*h+u*u),f=this.mass*h*u,p=this.mass*u*c,d=this.mass*c*h,r[1]+=f,r[3]+=f,r[2]+=p,r[6]+=p,r[5]+=d,r[7]+=d}this.inverseLocalInertia.invert(this.localInertia),this.type==a.BODY_STATIC&&(this.inverseMass=0,this.inverseLocalInertia.set(0,0,0,0,0,0,0,0,0)),this.syncShapes(),this.awake()},awake:function(){if(this.allowSleep&&this.sleeping){this.sleeping=!1,this.sleepTime=0;for(var e=this.contactLink;null!=e;)e.body.sleepTime=0,e.body.sleeping=!1,e=e.next;for(var t=this.jointLink;null!=t;)t.body.sleepTime=0,t.body.sleeping=!1,t=t.next;for(var i=this.shapes;null!=i;i=i.next)i.updateProxy()}},sleep:function(){if(this.allowSleep&&!this.sleeping){this.linearVelocity.set(0,0,0),this.angularVelocity.set(0,0,0),this.sleepPosition.copy(this.position),this.sleepOrientation.copy(this.orientation),this.sleepTime=0,this.sleeping=!0;for(var e=this.shapes;null!=e;e=e.next)e.updateProxy()}},isLonely:function(){return 0==this.numJoints&&0==this.numContacts},updatePosition:function(e){switch(this.type){case a.BODY_STATIC:this.linearVelocity.set(0,0,0),this.angularVelocity.set(0,0,0),this.controlPos&&(this.position.copy(this.newPosition),this.controlPos=!1),this.controlRot&&(this.orientation.copy(this.newOrientation),this.controlRot=!1);break;case a.BODY_DYNAMIC:this.controlPos&&(this.angularVelocity.set(0,0,0),this.linearVelocity.set(0,0,0),this.linearVelocity.x=(this.newPosition.x-this.position.x)/e,this.linearVelocity.y=(this.newPosition.y-this.position.y)/e,this.linearVelocity.z=(this.newPosition.z-this.position.z)/e,this.controlPos=!1),this.controlRot&&(this.angularVelocity.set(0,0,0),this.orientation.copy(this.newOrientation),this.controlRot=!1),this.position.addTime(this.linearVelocity,e),this.orientation.addTime(this.angularVelocity,e);break;default:a.Error("RigidBody","Invalid type.")}this.syncShapes()},rotateInertia:function(e,t,i){var r=e.elements,n=t.elements,o=r[0],s=r[3],a=r[6],l=r[1],h=r[4],u=r[7],c=r[2],f=r[5],p=r[8],d=n[0],m=n[3],g=n[6],v=n[1],_=n[4],y=n[7],x=n[2],b=n[5],T=n[8],E=o*d+l*m+c*g,A=o*v+l*_+c*y,P=o*x+l*b+c*T,S=s*d+h*m+f*g,M=s*v+h*_+f*y,C=s*x+h*b+f*T,R=a*d+u*m+p*g,I=a*v+u*_+p*y,O=a*x+u*b+p*T,D=i.elements;D[0]=E*o+A*l+P*c,D[1]=E*s+A*h+P*f,D[2]=E*a+A*u+P*p,D[3]=S*o+M*l+C*c,D[4]=S*s+M*h+C*f,D[5]=S*a+M*u+C*p,D[6]=R*o+I*l+O*c,D[7]=R*s+I*h+O*f,D[8]=R*a+I*u+O*p},syncShapes:function(){var e=this.orientation.s,t=this.orientation.x,i=this.orientation.y,r=this.orientation.z,n=2*t,o=2*i,s=2*r,a=t*n,l=i*o,h=r*s,u=t*o,c=i*s,f=t*s,p=e*n,d=e*o,m=e*s,g=this.rotation.elements;g[0]=1-l-h,g[1]=u-m,g[2]=f+d,g[3]=u+m,g[4]=1-a-h,g[5]=c-p,g[6]=f-d,g[7]=c+p,g[8]=1-a-l,this.rotateInertia(this.rotation,this.inverseLocalInertia,this.inverseInertia);for(var v=this.shapes;null!=v;v=v.next)v.position.mul(this.position,v.relativePosition,this.rotation),v.rotation.mul(this.rotation,v.relativeRotation),v.updateProxy()},applyImpulse:function(e,t){this.linearVelocity.addScale(t,this.inverseMass);var i=new a.Vec3;i.sub(e,this.position).cross(i,t).mulMat(this.inverseInertia,i),this.angularVelocity.addEqual(i)},rotationVectToQuad:function(e){var t=a.EulerToAxis(e.x*a.degtorad,e.y*a.degtorad,e.z*a.degtorad);return this.rotationAxisToQuad(t[0],t[1],t[2],t[3])},rotationAxisToQuad:function(e,t,i,r){var n=t*t+i*i+r*r;n>0&&(t*=n=1/a.sqrt(n),i*=n,r*=n);var o=a.sin(.5*e),s=a.cos(.5*e);return new a.Quat(s,o*t,o*i,o*r)},setPosition:function(e){this.newPosition.copy(e).multiplyScalar(a.INV_SCALE),this.controlPos=!0},setQuaternion:function(e){this.newOrientation.set(e.x,e.y,e.z,e.w),this.controlRot=!0},setRotation:function(e){this.newOrientation=this.rotationVectToQuad(e),this.controlRot=!0},resetPosition:function(e,t,i){this.linearVelocity.set(0,0,0),this.angularVelocity.set(0,0,0),this.position.set(e,t,i).multiplyScalar(a.INV_SCALE),this.awake()},resetQuaternion:function(e){this.angularVelocity.set(0,0,0),this.orientation=new a.Quat(e.w,e.x,e.y,e.z),this.awake()},resetRotation:function(e,t,i){this.angularVelocity.set(0,0,0),this.orientation=this.rotationVectToQuad(new a.Vec3(e,t,i)),this.awake()},getPosition:function(){return(new a.Vec3).scale(this.position,a.WORLD_SCALE)},getRotation:function(){return(new a.Euler).setFromRotationMatrix(this.rotation)},getQuaternion:function(){return(new a.Quaternion).setFromRotationMatrix(this.rotation)},getMatrix:function(){var e,t,i=this.matrix.elements;return this.sleeping?i[15]=1:(e=this.rotation.elements,i[0]=e[0],i[1]=e[3],i[2]=e[6],i[3]=0,i[4]=e[1],i[5]=e[4],i[6]=e[7],i[7]=0,i[8]=e[2],i[9]=e[5],i[10]=e[8],i[11]=0,t=this.position,i[12]=t.x*a.WORLD_SCALE,i[13]=t.y*a.WORLD_SCALE,i[14]=t.z*a.WORLD_SCALE,i[15]=0),i}},a.Body=function(e){var t=e||{};t.world&&(void 0===t.type&&(t.type="box"),this.name=t.name||"",this.body=t.world.add(t))},a.Body.prototype={constructor:a.Body,setPosition:function(e){this.body.setPosition(e)},setQuaternion:function(e){this.body.setQuaternion(e)},setRotation:function(e){this.body.setRotation(e)},getPosition:function(){return this.body.getPosition()},getRotation:function(){return this.body.getRotation()},getQuaternion:function(){return this.body.getQuaternion()},getMatrix:function(){return this.body.getMatrix()},getSleep:function(){return this.body.sleeping},resetPosition:function(e,t,i){this.body.resetPosition(e,t,i)},resetRotation:function(e,t,i){this.body.resetRotation(e,t,i)},awake:function(){this.body.awake()},remove:function(){this.body.dispose()},checkContact:function(e){this.body.checkContact(e)}},a.Link=function(e){var t=e||{};t.world&&(void 0===t.type&&(t.type="jointHinge"),this.name=t.name||"",this.joint=t.world.add(t))},a.Link.prototype={constructor:a.Link,getPosition:function(){return this.joint.getPosition()},getMatrix:function(){return this.joint.getMatrix()},remove:function(){this.joint.dispose()},awake:function(){this.joint.awake()}},a.Dictionary=function(){this.data={},this.keys=[]},a.Dictionary.prototype={constructor:a.Dictionary,set:function(e){var t=e.id;this.get[t]||this.keys.push(t),this.data[t]=e},get:function(e){return this.data[e]},del:function(e){var t=this.keys,i=t.indexOf(e.id);i>-1&&(delete this.data[t[i]],t.splice(i,1))},reset:function(){for(var e=this.data,t=this.keys;t.length>0;)delete e[t.pop()]}},a.Performance=function(e){this.parent=e,this.infos=new s(13),this.f=[0,0,0],this.types=["None","BruteForce","Sweep & Prune","Bounding Volume Tree"],this.broadPhase=this.types[this.parent.broadPhase.types],this.version=a.REVISION,this.fps=0,this.broadPhaseTime=0,this.narrowPhaseTime=0,this.solvingTime=0,this.totalTime=0},a.Performance.prototype={upfps:function(){this.f[1]=Date.now(),this.f[1]-1e3>this.f[0]&&(this.f[0]=this.f[1],this.fps=this.f[2],this.f[2]=0),this.f[2]++},updatingTime:function(){return a.fix(this.totalTime-(this.broadPhaseTime+this.narrowPhaseTime+this.solvingTime))},show:function(){return["Oimo.js "+this.version+"<br>",this.broadPhase+"<br><br>","FPS: "+this.fps+" fps<br><br>","rigidbody "+this.parent.numRigidBodies+"<br>","contact &nbsp;&nbsp;"+this.parent.numContacts+"<br>","ct-point &nbsp;"+this.parent.numContactPoints+"<br>","paircheck "+this.parent.broadPhase.numPairChecks+"<br>","island &nbsp;&nbsp;&nbsp;"+this.parent.numIslands+"<br><br>","Time in milliseconde<br><br>","broad-phase &nbsp;"+a.fix(this.broadPhaseTime)+"<br>","narrow-phase "+a.fix(this.narrowPhaseTime)+"<br>","solving &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+a.fix(this.solvingTime)+"<br>","total &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+a.fix(this.totalTime)+"<br>","updating &nbsp;&nbsp;&nbsp;&nbsp;"+this.updatingTime()+"<br>"].join("\n")},toArray:function(){return this.infos[0]=this.parent.broadPhase.types,this.infos[1]=this.parent.numRigidBodies,this.infos[2]=this.parent.numContacts,this.infos[3]=this.parent.broadPhase.numPairChecks,this.infos[4]=this.parent.numContactPoints,this.infos[5]=this.parent.numIslands,this.infos[6]=this.broadPhaseTime,this.infos[7]=this.narrowPhaseTime,this.infos[8]=this.solvingTime,this.infos[9]=this.updatingTime(),this.infos[10]=this.totalTime,this.infos[11]=this.fps,this.infos}},a.Mat44=function(e,t,i,r,n,o,a,l,h,u,c,f,p,d,m,g){this.elements=new s(16);var v=this.elements;v[0]=void 0!==e?e:1,v[4]=t||0,v[8]=i||0,v[12]=r||0,v[1]=n||0,v[5]=void 0!==o?o:1,v[9]=a||0,v[13]=l||0,v[2]=h||0,v[6]=u||0,v[10]=void 0!==c?c:1,v[14]=f||0,v[3]=p||0,v[7]=d||0,v[11]=m||0,v[15]=void 0!==g?g:1},a.Mat44.prototype={constructor:a.Mat44,set:function(e,t,i,r,n,o,s,a,l,h,u,c,f,p,d,m){var g=this.elements;return g[0]=e,g[4]=t,g[8]=i,g[12]=r,g[1]=n,g[5]=o,g[9]=s,g[13]=a,g[2]=l,g[6]=h,g[10]=u,g[14]=c,g[3]=f,g[7]=p,g[11]=d,g[15]=m,this}},a.Mat33=function(e,t,i,r,n,o,a,l,h){this.elements=new s(9);this.elements;this.init(void 0!==e?e:1,t||0,i||0,r||0,void 0!==n?n:1,o||0,a||0,l||0,void 0!==h?h:1)},a.Mat33.prototype={constructor:a.Mat33,set:function(e,t,i,r,n,o,s,a,l){var h=this.elements;return h[0]=e,h[1]=t,h[2]=i,h[3]=r,h[4]=n,h[5]=o,h[6]=s,h[7]=a,h[8]=l,this},init:function(e,t,i,r,n,o,s,a,l){var h=this.elements;return h[0]=e,h[1]=t,h[2]=i,h[3]=r,h[4]=n,h[5]=o,h[6]=s,h[7]=a,h[8]=l,this},multiply:function(e){var t=this.elements;return t[0]*=e,t[1]*=e,t[2]*=e,t[3]*=e,t[4]*=e,t[5]*=e,t[6]*=e,t[7]*=e,t[8]*=e,this},add:function(e,t){var i=this.elements,r=e.elements,n=t.elements;return i[0]=r[0]+n[0],i[1]=r[1]+n[1],i[2]=r[2]+n[2],i[3]=r[3]+n[3],i[4]=r[4]+n[4],i[5]=r[5]+n[5],i[6]=r[6]+n[6],i[7]=r[7]+n[7],i[8]=r[8]+n[8],this},addEqual:function(e){var t=this.elements,i=e.elements;return t[0]+=i[0],t[1]+=i[1],t[2]+=i[2],t[3]+=i[3],t[4]+=i[4],t[5]+=i[5],t[6]+=i[6],t[7]+=i[7],t[8]+=i[8],this},sub:function(e,t){var i=this.elements,r=e.elements,n=t.elements;return i[0]=r[0]-n[0],i[1]=r[1]-n[1],i[2]=r[2]-n[2],i[3]=r[3]-n[3],i[4]=r[4]-n[4],i[5]=r[5]-n[5],i[6]=r[6]-n[6],i[7]=r[7]-n[7],i[8]=r[8]-n[8],this},subEqual:function(e){var t=this.elements,i=e.elements;return t[0]-=i[0],t[1]-=i[1],t[2]-=i[2],t[3]-=i[3],t[4]-=i[4],t[5]-=i[5],t[6]-=i[6],t[7]-=i[7],t[8]-=i[8],this},scale:function(e,t){var i=this.elements,r=e.elements;return i[0]=r[0]*t,i[1]=r[1]*t,i[2]=r[2]*t,i[3]=r[3]*t,i[4]=r[4]*t,i[5]=r[5]*t,i[6]=r[6]*t,i[7]=r[7]*t,i[8]=r[8]*t,this},scaleEqual:function(e){var t=this.elements;return t[0]*=e,t[1]*=e,t[2]*=e,t[3]*=e,t[4]*=e,t[5]*=e,t[6]*=e,t[7]*=e,t[8]*=e,this},mul:function(e,t){var i=this.elements,r=e.elements,n=t.elements,o=r[0],s=r[3],a=r[6],l=r[1],h=r[4],u=r[7],c=r[2],f=r[5],p=r[8],d=n[0],m=n[3],g=n[6],v=n[1],_=n[4],y=n[7],x=n[2],b=n[5],T=n[8];return i[0]=o*d+l*m+c*g,i[1]=o*v+l*_+c*y,i[2]=o*x+l*b+c*T,i[3]=s*d+h*m+f*g,i[4]=s*v+h*_+f*y,i[5]=s*x+h*b+f*T,i[6]=a*d+u*m+p*g,i[7]=a*v+u*_+p*y,i[8]=a*x+u*b+p*T,this},mulScale:function(e,t,i,r,n){var o=n||!1,s=this.elements,a=e.elements;return o?(s[0]=t*a[0],s[1]=t*a[1],s[2]=t*a[2],s[3]=i*a[3],s[4]=i*a[4],s[5]=i*a[5],s[6]=r*a[6],s[7]=r*a[7],s[8]=r*a[8]):(s[0]=a[0]*t,s[1]=a[1]*i,s[2]=a[2]*r,s[3]=a[3]*t,s[4]=a[4]*i,s[5]=a[5]*r,s[6]=a[6]*t,s[7]=a[7]*i,s[8]=a[8]*r),this},mulRotate:function(e,t,i,r,n,o){var s=o||!1,l=a.sin(t),h=a.cos(t),u=1-h,c=i*i*u+h,f=i*r*u-n*l,p=i*n*u+r*l,d=r*i*u+n*l,m=r*r*u+h,g=r*n*u-i*l,v=n*i*u-r*l,_=n*r*u+i*l,y=n*n*u+h,x=e.elements,b=x[0],T=x[3],E=x[6],A=x[1],P=x[4],S=x[7],M=x[2],C=x[5],R=x[8],I=this.elements;return s?(I[0]=c*b+f*T+p*E,I[1]=c*A+f*P+p*S,I[2]=c*M+f*C+p*R,I[3]=d*b+m*T+g*E,I[4]=d*A+m*P+g*S,I[5]=d*M+m*C+g*R,I[6]=v*b+_*T+y*E,I[7]=v*A+_*P+y*S,I[8]=v*M+_*C+y*R):(I[0]=b*c+A*d+M*v,I[1]=b*f+A*m+M*_,I[2]=b*p+A*g+M*y,I[3]=T*c+P*d+C*v,I[4]=T*f+P*m+C*_,I[5]=T*p+P*g+C*y,I[6]=E*c+S*d+R*v,I[7]=E*f+S*m+R*_,I[8]=E*p+S*g+R*y),this},transpose:function(e){var t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[3],t[2]=i[6],t[3]=i[1],t[4]=i[4],t[5]=i[7],t[6]=i[2],t[7]=i[5],t[8]=i[8],this},setQuat:function(e){var t=this.elements,i=2*e.x,r=2*e.y,n=2*e.z,o=e.x*i,s=e.y*r,a=e.z*n,l=e.x*r,h=e.y*n,u=e.x*n,c=e.s*i,f=e.s*r,p=e.s*n;return t[0]=1-s-a,t[1]=l-p,t[2]=u+f,t[3]=l+p,t[4]=1-o-a,t[5]=h-c,t[6]=u-f,t[7]=h+c,t[8]=1-o-s,this},invert:function(e){var t=this.elements,i=e.elements,r=i[0],n=i[3],o=i[6],s=i[1],a=i[4],l=i[7],h=i[2],u=i[5],c=i[8],f=a*c-l*u,p=l*h-s*c,d=s*u-a*h,m=r*f+n*p+o*d;return 0!=m&&(m=1/m),t[0]=m*f,t[1]=m*p,t[2]=m*d,t[3]=m*(u*o-n*c),t[4]=m*(r*c-h*o),t[5]=m*(h*n-r*u),t[6]=m*(n*l-a*o),t[7]=m*(s*o-r*l),t[8]=m*(r*a-s*n),this},toEuler:function(){var e=this.elements,t=e[0],i=e[3],r=e[6],n=(e[1],e[4]),o=e[7],s=(e[2],e[5]),l=e[8],h=new a.Vec3;new a.Quat;return h.y=a.asin(function(e){return a.min(a.max(e,-1),1)}(r)),a.abs(r)<.99999?(h.x=a.atan2(-o,l),h.z=a.atan2(-i,t)):(h.x=a.atan2(s,n),h.z=0),h},toString:function(){var e=this.elements;return"Mat33|"+e[0].toFixed(4)+", "+e[1].toFixed(4)+", "+e[2].toFixed(4)+"|\n |"+e[3].toFixed(4)+", "+e[4].toFixed(4)+", "+e[5].toFixed(4)+"|\n |"+e[6].toFixed(4)+", "+e[7].toFixed(4)+", "+e[8].toFixed(4)+"|"},multiplyScalar:function(e){var t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this},identity:function(){return this.set(1,0,0,0,1,0,0,0,1),this},clone:function(){return(new this.constructor).fromArray(this.elements)},copy:function(e){var t=e.elements;return this.set(t[0],t[3],t[6],t[1],t[4],t[7],t[2],t[5],t[8]),this},fromArray:function(e){return this.elements.set(e),this},toArray:function(){var e=this.elements;return[e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8]]}},a.Quat=function(e,t,i,r){this.s=void 0!==e?e:1,this.x=t||0,this.y=i||0,this.z=r||0},a.Quat.prototype={constructor:a.Quat,set:function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.s=r,this},init:function(e,t,i,r){return this.s=void 0!==e?e:1,this.x=t||0,this.y=i||0,this.z=r||0,this},add:function(e,t){return this.s=e.s+t.s,this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this},addTime:function(e,t){var i=e.x,r=e.y,n=e.z,o=this.s,s=this.x,l=this.y,h=this.z,u=(i*o+r*h-n*l)*(t*=.5),c=(-i*h+r*o+n*s)*t,f=(i*l-r*s+n*o)*t;o+=(-i*s-r*l-n*h)*t,s+=u,l+=c,h+=f;var p=1/a.sqrt(o*o+s*s+l*l+h*h);return this.s=o*p,this.x=s*p,this.y=l*p,this.z=h*p,this},sub:function(e,t){return this.s=e.s-t.s,this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this},scale:function(e,t){return this.s=e.s*t,this.x=e.x*t,this.y=e.y*t,this.z=e.z*t,this},mul:function(e,t){var i=e.x,r=e.y,n=e.z,o=e.s,s=t.x,a=t.y,l=t.z,h=t.s;return this.x=i*h+o*s+r*l-n*a,this.y=r*h+o*a+n*s-i*l,this.z=n*h+o*l+i*a-r*s,this.s=o*h-i*s-r*a-n*l,this},arc:function(e,t){var i=e.x,r=e.y,n=e.z,o=t.x,s=t.y,l=t.z,h=i*o+r*s+n*l;if(-1==h)return o=r*i-n*n,s=-n*r-i*i,l=i*n+r*r,h=1/a.sqrt(o*o+s*s+l*l),this.s=0,this.x=o*h,this.y=s*h,this.z=l*h,this;var u=r*l-n*s,c=n*o-i*l,f=i*s-r*o;return this.s=a.sqrt(.5*(1+h)),h=.5/this.s,this.x=u*h,this.y=c*h,this.z=f*h,this},normalize:function(e){var t=a.sqrt(e.s*e.s+e.x*e.x+e.y*e.y+e.z*e.z);return t>0&&(t=1/t),this.s=e.s*t,this.x=e.x*t,this.y=e.y*t,this.z=e.z*t,this},invert:function(e){return this.s=e.s,this.x=-e.x,this.y=-e.y,this.z=-e.z,this},length:function(){return a.sqrt(this.s*this.s+this.x*this.x+this.y*this.y+this.z*this.z)},copy:function(e){return this.s=e.s,this.x=e.x,this.y=e.y,this.z=e.z,this},testDiff:function(e){return this.s!==e.s||this.x!==e.x||this.y!==e.y||this.z!==e.z},clone:function(e){return new a.Quat(this.s,this.x,this.y,this.z)},toString:function(){return"Quat["+this.s.toFixed(4)+", ("+this.x.toFixed(4)+", "+this.y.toFixed(4)+", "+this.z.toFixed(4)+")]"}},a.Quaternion=function(e,t,i,r){this.x=e||0,this.y=t||0,this.z=i||0,this.w=void 0!==r?r:1},a.Quaternion.prototype={constructor:a.Quaternion,setFromRotationMatrix:function(e){var t,i=e.elements,r=i[0],n=i[1],o=i[2],s=i[3],l=i[4],h=i[5],u=i[6],c=i[7],f=i[8],p=r+l+f;return p>0?(t=.5/a.sqrt(p+1),this.w=.25/t,this.x=(c-h)*t,this.y=(o-u)*t,this.z=(s-n)*t):r>l&&r>f?(t=2*a.sqrt(1+r-l-f),this.w=(c-h)/t,this.x=.25*t,this.y=(n+s)/t,this.z=(o+u)/t):l>f?(t=2*a.sqrt(1+l-r-f),this.w=(o-u)/t,this.x=(n+s)/t,this.y=.25*t,this.z=(h+c)/t):(t=2*a.sqrt(1+f-r-l),this.w=(s-n)/t,this.x=(o+u)/t,this.y=(h+c)/t,this.z=.25*t),this}},a.Vec3=function(e,t,i){this.x=e||0,this.y=t||0,this.z=i||0},a.Vec3.prototype={constructor:a.Vec3,init:function(e,t,i){return this.x=e||0,this.y=t||0,this.z=i||0,this},set:function(e,t,i){return this.x=e,this.y=t,this.z=i,this},add:function(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this},addEqual:function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},addTime:function(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this},sub:function(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this},subEqual:function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this},addScale:function(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this},scale:function(e,t){return this.x=e.x*t,this.y=e.y*t,this.z=e.z*t,this},scaleEqual:function(e){return this.x*=e,this.y*=e,this.z*=e,this},cross:function(e,t){var i=e.x,r=e.y,n=e.z,o=t.x,s=t.y,a=t.z;return this.x=r*a-n*s,this.y=n*o-i*a,this.z=i*s-r*o,this},mul:function(e,t,i){var r=i.elements;return this.x=e.x+t.x*r[0]+t.y*r[1]+t.z*r[2],this.y=e.y+t.x*r[3]+t.y*r[4]+t.z*r[5],this.z=e.z+t.x*r[6]+t.y*r[7]+t.z*r[8],this},mulMat:function(e,t){var i=e.elements;return this.x=i[0]*t.x+i[1]*t.y+i[2]*t.z,this.y=i[3]*t.x+i[4]*t.y+i[5]*t.z,this.z=i[6]*t.x+i[7]*t.y+i[8]*t.z,this},normalize:function(e){var t=e.x,i=e.y,r=e.z,n=t*t+i*i+r*r;return n>0&&(n=1/a.sqrt(n),this.x=t*n,this.y=i*n,this.z=r*n),this},invert:function(e){return this.x=-e.x,this.y=-e.y,this.z=-e.z,this},negate:function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},dot:function(e){return this.x*e.x+this.y*e.y+this.z*e.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return a.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},copy:function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},applyQuaternion:function(e){var t=this.x,i=this.y,r=this.z,n=e.x,o=e.y,s=e.z,a=e.s,l=a*t+o*r-s*i,h=a*i+s*t-n*r,u=a*r+n*i-o*t,c=-n*t-o*i-s*r;return this.x=l*a+c*-n+h*-s-u*-o,this.y=h*a+c*-o+u*-n-l*-s,this.z=u*a+c*-s+l*-o-h*-n,this},testZero:function(){return 0!==this.x||0!==this.y||0!==this.z},testDiff:function(e){return e.x!==this.x||e.y!==this.y||e.z!==this.z},equals:function(e){return e.x===this.x&&e.y===this.y&&e.z===this.z},clone:function(){return new this.constructor(this.x,this.y,this.z)},toString:function(){return"Vec3["+this.x.toFixed(4)+", "+this.y.toFixed(4)+", "+this.z.toFixed(4)+"]"},multiplyScalar:function(e){return isFinite(e)?(this.x*=e,this.y*=e,this.z*=e):(this.x=0,this.y=0,this.z=0),this},divideScalar:function(e){return this.multiplyScalar(1/e)},norm:function(){return this.divideScalar(this.length())}},a.Euler=function(e,t,i,r){this._x=e||0,this._y=t||0,this._z=i||0,this._order=r||a.Euler.DefaultOrder},a.Euler.RotationOrders=["XYZ","YZX","ZXY","XZY","YXZ","ZYX"],a.Euler.DefaultOrder="XYZ",a.clamp=function(e,t,i){return e<t?t:e>i?i:e},a.Euler.prototype={constructor:a.Euler,_x:0,_y:0,_z:0,_order:a.Euler.DefaultOrder,get x(){return this._x},set x(e){this._x=e,this.onChangeCallback()},get y(){return this._y},set y(e){this._y=e,this.onChangeCallback()},get z(){return this._z},set z(e){this._z=e,this.onChangeCallback()},get order(){return this._order},set order(e){this._order=e,this.onChangeCallback()},set:function(e,t,i,r){return this._x=e,this._y=t,this._z=i,this._order=r||this._order,this.onChangeCallback(),this},copy:function(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this.onChangeCallback(),this},setFromRotationMatrix:function(e,t){var i=a.clamp,r=e.elements,n=r[0],o=r[1],s=r[2],l=r[3],h=r[4],u=r[5],c=r[6],f=r[7],p=r[8];return"XYZ"===(t=t||this._order)?(this._y=a.asin(i(s,-1,1)),a.abs(s)<.99999?(this._x=a.atan2(-u,p),this._z=a.atan2(-o,n)):(this._x=a.atan2(f,h),this._z=0)):"YXZ"===t?(this._x=a.asin(-i(u,-1,1)),a.abs(u)<.99999?(this._y=a.atan2(s,p),this._z=a.atan2(l,h)):(this._y=a.atan2(-c,n),this._z=0)):"ZXY"===t?(this._x=a.asin(i(f,-1,1)),a.abs(f)<.99999?(this._y=a.atan2(-c,p),this._z=a.atan2(-o,h)):(this._y=0,this._z=a.atan2(l,n))):"ZYX"===t?(this._y=a.asin(-i(c,-1,1)),a.abs(c)<.99999?(this._x=a.atan2(f,p),this._z=a.atan2(l,n)):(this._x=0,this._z=a.atan2(-o,h))):"YZX"===t?(this._z=a.asin(i(l,-1,1)),a.abs(l)<.99999?(this._x=a.atan2(-u,h),this._y=a.atan2(-c,n)):(this._x=0,this._y=a.atan2(s,p))):"XZY"===t?(this._z=a.asin(-i(o,-1,1)),a.abs(o)<.99999?(this._x=a.atan2(f,h),this._y=a.atan2(s,n)):(this._x=a.atan2(-u,p),this._y=0)):console.warn("THREE.Euler: .setFromRotationMatrix() given unsupported order: "+t),this._order=t,this.onChangeCallback(),this},setFromQuaternion:function(e,t,i){var r=a.clamp,n=e.x*e.x,o=e.y*e.y,s=e.z*e.z,l=e.s*e.s;return"XYZ"===(t=t||this._order)?(this._x=a.atan2(2*(e.x*e.s-e.y*e.z),l-n-o+s),this._y=a.asin(r(2*(e.x*e.z+e.y*e.s),-1,1)),this._z=a.atan2(2*(e.z*e.s-e.x*e.y),l+n-o-s)):"YXZ"===t?(this._x=a.asin(r(2*(e.x*e.s-e.y*e.z),-1,1)),this._y=a.atan2(2*(e.x*e.z+e.y*e.s),l-n-o+s),this._z=a.atan2(2*(e.x*e.y+e.z*e.s),l-n+o-s)):"ZXY"===t?(this._x=a.asin(r(2*(e.x*e.s+e.y*e.z),-1,1)),this._y=a.atan2(2*(e.y*e.s-e.z*e.x),l-n-o+s),this._z=a.atan2(2*(e.z*e.s-e.x*e.y),l-n+o-s)):"ZYX"===t?(this._x=a.atan2(2*(e.x*e.s+e.z*e.y),l-n-o+s),this._y=a.asin(r(2*(e.y*e.s-e.x*e.z),-1,1)),this._z=a.atan2(2*(e.x*e.y+e.z*e.s),l+n-o-s)):"YZX"===t?(this._x=a.atan2(2*(e.x*e.s-e.z*e.y),l-n+o-s),this._y=a.atan2(2*(e.y*e.s-e.x*e.z),l+n-o-s),this._z=a.asin(r(2*(e.x*e.y+e.z*e.s),-1,1))):"XZY"===t?(this._x=a.atan2(2*(e.x*e.s+e.y*e.z),l-n+o-s),this._y=a.atan2(2*(e.x*e.z+e.y*e.s),l+n-o-s),this._z=a.asin(r(2*(e.z*e.s-e.x*e.y),-1,1))):console.warn("OIMO.Euler: .setFromQuaternion() given unsupported order: "+t),this._order=t,!1!==i&&this.onChangeCallback(),this},reorder:function(){var e=new a.Quat;return function(t){e.setFromEuler(this),this.setFromQuaternion(e,t)}}(),equals:function(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order},fromArray:function(e){return this._x=e[0],this._y=e[1],this._z=e[2],void 0!==e[3]&&(this._order=e[3]),this.onChangeCallback(),this},toArray:function(){return[this._x,this._y,this._z,this._order]},onChange:function(e){return this.onChangeCallback=e,this},onChangeCallback:function(){},clone:function(){return new a.Euler(this._x,this._y,this._z,this._order)}},a.EulerToAxis=function(e,t,i){var r=a.cos(.5*t),n=a.sin(.5*t),o=a.cos(.5*i),s=a.sin(.5*i),l=a.cos(.5*e),h=a.sin(.5*e),u=r*o,c=n*s,f=u*l-c*h,p=u*h+c*l,d=n*o*l+r*s*h,m=r*s*l-n*o*h,g=2*a.acos(f),v=p*p+d*d+m*m;return v<.001?(p=1,d=m=0):(p/=v=a.sqrt(v),d/=v,m/=v),[g,p,d,m]},a.EulerToMatrix=function(e,t,i){var r=a.cos(t),n=a.sin(t),o=a.cos(i),s=a.sin(i),l=a.cos(e),h=a.sin(e),u=new a.Mat33,c=u.elements;return c[0]=r*o,c[1]=n*h-r*s*l,c[2]=r*s*h+n*l,c[3]=s,c[4]=o*l,c[5]=-o*h,c[6]=-n*o,c[7]=n*s*l+r*h,c[8]=-n*s*h+r*l,u},a.MatrixToEuler=function(e){var t,i,r,n=e.elements;return n[3]>.998?(i=a.atan2(n[2],n[8]),r=a.PI/2,t=0):n[3]<-.998?(i=a.atan2(n[2],n[8]),r=-a.PI/2,t=0):(i=a.atan2(-n[6],n[0]),t=a.atan2(-n[5],n[4]),r=a.asin(n[3])),[t,i,r]},a.unwrapDegrees=function(e){return(e%=360)>180&&(e-=360),e<-180&&(e+=360),e},a.unwrapRadian=function(e){return(e%=a.TwoPI)>a.PI&&(e-=a.TwoPI),e<-a.PI&&(e+=a.TwoPI),e},a.Distance3d=function(e,t){var i=t[0]-e[0],r=t[1]-e[1],n=t[2]-e[2];return a.sqrt(i*i+r*r+n*n)},a.Constraint=function(){this.parent=null,this.body1=null,this.body2=null,this.addedToIsland=!1},a.Constraint.prototype={constructor:a.Constraint,preSolve:function(e,t){a.Error("Constraint","Inheritance error.")},solve:function(){a.Error("Constraint","Inheritance error.")},postSolve:function(){a.Error("Constraint","Inheritance error.")}},a.Joint=function(e){a.Constraint.call(this),this.name="",this.type=a.JOINT_NULL,this.prev=null,this.next=null,this.body1=e.body1,this.body2=e.body2,this.localAnchorPoint1=(new a.Vec3).copy(e.localAnchorPoint1),this.localAnchorPoint2=(new a.Vec3).copy(e.localAnchorPoint2),this.relativeAnchorPoint1=new a.Vec3,this.relativeAnchorPoint2=new a.Vec3,this.anchorPoint1=new a.Vec3,this.anchorPoint2=new a.Vec3,this.allowCollision=e.allowCollision,this.b1Link=new a.JointLink(this),this.b2Link=new a.JointLink(this),this.matrix=new a.Mat44},a.Joint.prototype=Object.create(a.Constraint.prototype),a.Joint.prototype.constructor=a.Joint,a.Joint.prototype.updateAnchorPoints=function(){this.relativeAnchorPoint1.mulMat(this.body1.rotation,this.localAnchorPoint1),this.relativeAnchorPoint2.mulMat(this.body2.rotation,this.localAnchorPoint2),this.anchorPoint1.add(this.relativeAnchorPoint1,this.body1.position),this.anchorPoint2.add(this.relativeAnchorPoint2,this.body2.position)},a.Joint.prototype.attach=function(){this.b1Link.body=this.body2,this.b2Link.body=this.body1,null!=this.body1.jointLink?(this.b1Link.next=this.body1.jointLink).prev=this.b1Link:this.b1Link.next=null,this.body1.jointLink=this.b1Link,this.body1.numJoints++,null!=this.body2.jointLink?(this.b2Link.next=this.body2.jointLink).prev=this.b2Link:this.b2Link.next=null,this.body2.jointLink=this.b2Link,this.body2.numJoints++},a.Joint.prototype.detach=function(){var e=this.b1Link.prev,t=this.b1Link.next;null!=e&&(e.next=t),null!=t&&(t.prev=e),this.body1.jointLink==this.b1Link&&(this.body1.jointLink=t),this.b1Link.prev=null,this.b1Link.next=null,this.b1Link.body=null,this.body1.numJoints--,e=this.b2Link.prev,t=this.b2Link.next,null!=e&&(e.next=t),null!=t&&(t.prev=e),this.body2.jointLink==this.b2Link&&(this.body2.jointLink=t),this.b2Link.prev=null,this.b2Link.next=null,this.b2Link.body=null,this.body2.numJoints--,this.b1Link.body=null,this.b2Link.body=null},a.Joint.prototype.awake=function(){this.body1.awake(),this.body2.awake()},a.Joint.prototype.preSolve=function(e,t){},a.Joint.prototype.solve=function(){},a.Joint.prototype.postSolve=function(){},a.Joint.prototype.remove=function(){this.dispose()},a.Joint.prototype.dispose=function(){this.parent.removeJoint(this)},a.Joint.prototype.getPosition=function(){return[(new a.Vec3).scale(this.anchorPoint1,a.WORLD_SCALE),(new a.Vec3).scale(this.anchorPoint2,a.WORLD_SCALE)]},a.Joint.prototype.getMatrix=function(){var e=this.matrix.elements,t=this.anchorPoint1,i=this.anchorPoint2;return e[0]=t.x*a.WORLD_SCALE,e[1]=t.y*a.WORLD_SCALE,e[2]=t.z*a.WORLD_SCALE,e[3]=0,e[4]=i.x*a.WORLD_SCALE,e[5]=i.y*a.WORLD_SCALE,e[6]=i.z*a.WORLD_SCALE,e[7]=0,e},a.JointConfig=function(){this.body1=null,this.body2=null,this.localAnchorPoint1=new a.Vec3,this.localAnchorPoint2=new a.Vec3,this.localAxis1=new a.Vec3,this.localAxis2=new a.Vec3,this.allowCollision=!1},a.JointLink=function(e){this.prev=null,this.next=null,this.body=null,this.joint=e},a.LimitMotor=function(e,t){t=t||!1,this.axis=e,this.angle=0,this.lowerLimit=t?0:1,this.upperLimit=0,this.motorSpeed=0,this.maxMotorForce=0,this.frequency=0,this.dampingRatio=0},a.LimitMotor.prototype={constructor:a.LimitMotor,setLimit:function(e,t){this.lowerLimit=e,this.upperLimit=t},setMotor:function(e,t){this.motorSpeed=e,this.maxMotorForce=t},setSpring:function(e,t){this.frequency=e,this.dampingRatio=t}},a.BallAndSocketJoint=function(e){a.Joint.call(this,e),this.type=a.JOINT_BALL_AND_SOCKET,this.lc=new a.LinearConstraint(this)},a.BallAndSocketJoint.prototype=Object.create(a.Joint.prototype),a.BallAndSocketJoint.prototype.constructor=a.BallAndSocketJoint,a.BallAndSocketJoint.prototype.preSolve=function(e,t){this.updateAnchorPoints(),this.lc.preSolve(e,t)},a.BallAndSocketJoint.prototype.solve=function(){this.lc.solve()},a.BallAndSocketJoint.prototype.postSolve=function(){},a.DistanceJoint=function(e,t,i){a.Joint.call(this,e),this.type=a.JOINT_DISTANCE,this.normal=new a.Vec3,this.nr=new a.Vec3,this.limitMotor=new a.LimitMotor(this.normal,!0),this.limitMotor.lowerLimit=t,this.limitMotor.upperLimit=i,this.t=new a.TranslationalConstraint(this,this.limitMotor)},a.DistanceJoint.prototype=Object.create(a.Joint.prototype),a.DistanceJoint.prototype.constructor=a.DistanceJoint,a.DistanceJoint.prototype.preSolve=function(e,t){this.updateAnchorPoints(),this.nr.sub(this.anchorPoint2,this.anchorPoint1),this.normal.normalize(this.nr),this.t.preSolve(e,t)},a.DistanceJoint.prototype.solve=function(){this.t.solve()},a.DistanceJoint.prototype.postSolve=function(){},a.HingeJoint=function(e,t,i){a.Joint.call(this,e),this.type=a.JOINT_HINGE,this.localAxis1=e.localAxis1.clone().norm(),this.localAxis2=e.localAxis2.clone().norm(),this.localAngle1=new a.Vec3(this.localAxis1.y*this.localAxis1.x-this.localAxis1.z*this.localAxis1.z,-this.localAxis1.z*this.localAxis1.y-this.localAxis1.x*this.localAxis1.x,this.localAxis1.x*this.localAxis1.z+this.localAxis1.y*this.localAxis1.y).norm();var r=(new a.Mat33).setQuat((new a.Quat).arc(this.localAxis1,this.localAxis2));this.localAngle2=(new a.Vec3).mulMat(r,this.localAngle1),this.nor=new a.Vec3,this.tan=new a.Vec3,this.bin=new a.Vec3,this.ax1=new a.Vec3,this.ax2=new a.Vec3,this.an1=new a.Vec3,this.an2=new a.Vec3,this.limitMotor=new a.LimitMotor(this.nor,!1),this.limitMotor.lowerLimit=t,this.limitMotor.upperLimit=i,this.lc=new a.LinearConstraint(this),this.r3=new a.Rotational3Constraint(this,this.limitMotor,new a.LimitMotor(this.tan,!0),new a.LimitMotor(this.bin,!0))},a.HingeJoint.prototype=Object.create(a.Joint.prototype),a.HingeJoint.prototype.constructor=a.HingeJoint,a.HingeJoint.prototype.preSolve=function(e,t){var i,r,n,o;this.updateAnchorPoints(),this.ax1.mulMat(this.body1.rotation,this.localAxis1),this.ax2.mulMat(this.body2.rotation,this.localAxis2),this.an1.mulMat(this.body1.rotation,this.localAngle1),this.an2.mulMat(this.body2.rotation,this.localAngle2),this.nor.set(this.ax1.x*this.body2.inverseMass+this.ax2.x*this.body1.inverseMass,this.ax1.y*this.body2.inverseMass+this.ax2.y*this.body1.inverseMass,this.ax1.z*this.body2.inverseMass+this.ax2.z*this.body1.inverseMass).norm(),this.tan.set(this.nor.y*this.nor.x-this.nor.z*this.nor.z,-this.nor.z*this.nor.y-this.nor.x*this.nor.x,this.nor.x*this.nor.z+this.nor.y*this.nor.y).norm(),this.bin.set(this.nor.y*this.tan.z-this.nor.z*this.tan.y,this.nor.z*this.tan.x-this.nor.x*this.tan.z,this.nor.x*this.tan.y-this.nor.y*this.tan.x),o=this.acosClamp(this.an1.x*this.an2.x+this.an1.y*this.an2.y+this.an1.z*this.an2.z),this.nor.x*(this.an1.y*this.an2.z-this.an1.z*this.an2.y)+this.nor.y*(this.an1.z*this.an2.x-this.an1.x*this.an2.z)+this.nor.z*(this.an1.x*this.an2.y-this.an1.y*this.an2.x)<0?this.limitMotor.angle=-o:this.limitMotor.angle=o,i=this.ax1.y*this.ax2.z-this.ax1.z*this.ax2.y,r=this.ax1.z*this.ax2.x-this.ax1.x*this.ax2.z,n=this.ax1.x*this.ax2.y-this.ax1.y*this.ax2.x,this.r3.limitMotor2.angle=this.tan.x*i+this.tan.y*r+this.tan.z*n,this.r3.limitMotor3.angle=this.bin.x*i+this.bin.y*r+this.bin.z*n,this.r3.preSolve(e,t),this.lc.preSolve(e,t)},a.HingeJoint.prototype.solve=function(){this.r3.solve(),this.lc.solve()},a.HingeJoint.prototype.postSolve=function(){},a.HingeJoint.prototype.acosClamp=function(e){return e>1?0:e<-1?a.PI:a.acos(e)},a.PrismaticJoint=function(e,t,i){a.Joint.call(this,e),this.type=a.JOINT_PRISMATIC,this.localAxis1=(new a.Vec3).normalize(e.localAxis1),this.localAxis2=(new a.Vec3).normalize(e.localAxis2),this.localAxis1X=this.localAxis1.x,this.localAxis1Y=this.localAxis1.y,this.localAxis1Z=this.localAxis1.z,this.localAxis2X=this.localAxis2.x,this.localAxis2Y=this.localAxis2.y,this.localAxis2Z=this.localAxis2.z,this.nor=new a.Vec3,this.tan=new a.Vec3,this.bin=new a.Vec3,this.ac=new a.AngularConstraint(this,(new a.Quat).arc(this.localAxis1,this.localAxis2)),this.limitMotor=new a.LimitMotor(this.nor,!0),this.limitMotor.lowerLimit=t,this.limitMotor.upperLimit=i,this.t3=new a.Translational3Constraint(this,this.limitMotor,new a.LimitMotor(this.tan,!0),new a.LimitMotor(this.bin,!0))},a.PrismaticJoint.prototype=Object.create(a.Joint.prototype),a.PrismaticJoint.prototype.constructor=a.PrismaticJoint,a.PrismaticJoint.prototype.preSolve=function(e,t){var i,r;this.updateAnchorPoints(),i=this.body1.rotation.elements;var n=this.localAxis1X*i[0]+this.localAxis1Y*i[1]+this.localAxis1Z*i[2],o=this.localAxis1X*i[3]+this.localAxis1Y*i[4]+this.localAxis1Z*i[5],s=this.localAxis1X*i[6]+this.localAxis1Y*i[7]+this.localAxis1Z*i[8];i=this.body2.rotation.elements;var l=this.localAxis2X*i[0]+this.localAxis2Y*i[1]+this.localAxis2Z*i[2],h=this.localAxis2X*i[3]+this.localAxis2Y*i[4]+this.localAxis2Z*i[5],u=this.localAxis2X*i[6]+this.localAxis2Y*i[7]+this.localAxis2Z*i[8],c=n*this.body2.inverseMass+l*this.body1.inverseMass,f=o*this.body2.inverseMass+h*this.body1.inverseMass,p=s*this.body2.inverseMass+u*this.body1.inverseMass;(r=a.sqrt(c*c+f*f+p*p))>0&&(r=1/r);var d=(f*=r)*(c*=r)-(p*=r)*p,m=-p*f-c*c,g=c*p+f*f,v=f*(g*=r=1/a.sqrt(d*d+m*m+g*g))-p*(m*=r),_=p*(d*=r)-c*g,y=c*m-f*d;this.nor.init(c,f,p),this.tan.init(d,m,g),this.bin.init(v,_,y),this.ac.preSolve(e,t),this.t3.preSolve(e,t)},a.PrismaticJoint.prototype.solve=function(){this.ac.solve(),this.t3.solve()},a.PrismaticJoint.prototype.postSolve=function(){},a.SliderJoint=function(e,t,i){a.Joint.call(this,e),this.type=a.JOINT_SLIDER,this.localAxis1=(new a.Vec3).normalize(e.localAxis1),this.localAxis2=(new a.Vec3).normalize(e.localAxis2);var r;this.localAxis1X=this.localAxis1.x,this.localAxis1Y=this.localAxis1.y,this.localAxis1Z=this.localAxis1.z,this.localAngAxis1X=this.localAxis1Y*this.localAxis1X-this.localAxis1Z*this.localAxis1Z,this.localAngAxis1Y=-this.localAxis1Z*this.localAxis1Y-this.localAxis1X*this.localAxis1X,this.localAngAxis1Z=this.localAxis1X*this.localAxis1Z+this.localAxis1Y*this.localAxis1Y,r=1/a.sqrt(this.localAngAxis1X*this.localAngAxis1X+this.localAngAxis1Y*this.localAngAxis1Y+this.localAngAxis1Z*this.localAngAxis1Z),this.localAngAxis1X*=r,this.localAngAxis1Y*=r,this.localAngAxis1Z*=r,this.localAxis2X=this.localAxis2.x,this.localAxis2Y=this.localAxis2.y,this.localAxis2Z=this.localAxis2.z;var n=(new a.Mat33).setQuat((new a.Quat).arc(this.localAxis1,this.localAxis2)).elements;this.localAngAxis2X=this.localAngAxis1X*n[0]+this.localAngAxis1Y*n[1]+this.localAngAxis1Z*n[2],this.localAngAxis2Y=this.localAngAxis1X*n[3]+this.localAngAxis1Y*n[4]+this.localAngAxis1Z*n[5],this.localAngAxis2Z=this.localAngAxis1X*n[6]+this.localAngAxis1Y*n[7]+this.localAngAxis1Z*n[8],this.nor=new a.Vec3,this.tan=new a.Vec3,this.bin=new a.Vec3,this.rotationalLimitMotor=new a.LimitMotor(this.nor,!1),this.r3=new a.Rotational3Constraint(this,this.rotationalLimitMotor,new a.LimitMotor(this.tan,!0),new a.LimitMotor(this.bin,!0)),this.translationalLimitMotor=new a.LimitMotor(this.nor,!0),this.translationalLimitMotor.lowerLimit=t,this.translationalLimitMotor.upperLimit=i,this.t3=new a.Translational3Constraint(this,this.translationalLimitMotor,new a.LimitMotor(this.tan,!0),new a.LimitMotor(this.bin,!0))},a.SliderJoint.prototype=Object.create(a.Joint.prototype),a.SliderJoint.prototype.constructor=a.SliderJoint,a.SliderJoint.prototype.preSolve=function(e,t){var i,r,n,o;this.updateAnchorPoints(),i=this.body1.rotation.elements;var s=this.localAxis1X*i[0]+this.localAxis1Y*i[1]+this.localAxis1Z*i[2],l=this.localAxis1X*i[3]+this.localAxis1Y*i[4]+this.localAxis1Z*i[5],h=this.localAxis1X*i[6]+this.localAxis1Y*i[7]+this.localAxis1Z*i[8],u=this.localAngAxis1X*i[0]+this.localAngAxis1Y*i[1]+this.localAngAxis1Z*i[2],c=this.localAngAxis1X*i[3]+this.localAngAxis1Y*i[4]+this.localAngAxis1Z*i[5],f=this.localAngAxis1X*i[6]+this.localAngAxis1Y*i[7]+this.localAngAxis1Z*i[8];i=this.body2.rotation.elements;var p=this.localAxis2X*i[0]+this.localAxis2Y*i[1]+this.localAxis2Z*i[2],d=this.localAxis2X*i[3]+this.localAxis2Y*i[4]+this.localAxis2Z*i[5],m=this.localAxis2X*i[6]+this.localAxis2Y*i[7]+this.localAxis2Z*i[8],g=this.localAngAxis2X*i[0]+this.localAngAxis2Y*i[1]+this.localAngAxis2Z*i[2],v=this.localAngAxis2X*i[3]+this.localAngAxis2Y*i[4]+this.localAngAxis2Z*i[5],_=this.localAngAxis2X*i[6]+this.localAngAxis2Y*i[7]+this.localAngAxis2Z*i[8],y=s*this.body2.inverseMass+p*this.body1.inverseMass,x=l*this.body2.inverseMass+d*this.body1.inverseMass,b=h*this.body2.inverseMass+m*this.body1.inverseMass;(r=a.sqrt(y*y+x*x+b*b))>0&&(r=1/r);var T=(x*=r)*(y*=r)-(b*=r)*b,E=-b*x-y*y,A=y*b+x*x,P=x*(A*=r=1/a.sqrt(T*T+E*E+A*A))-b*(E*=r),S=b*(T*=r)-y*A,M=y*E-x*T;this.nor.init(y,x,b),this.tan.init(T,E,A),this.bin.init(P,S,M),this.rotationalLimitMotor.angle=y*(c*_-f*v)+x*(f*g-u*_)+b*(u*v-c*g)<0?-this.acosClamp(u*g+c*v+f*_):this.acosClamp(u*g+c*v+f*_),r=l*m-h*d,n=h*p-s*m,o=s*d-l*p,this.r3.limitMotor2.angle=T*r+E*n+A*o,this.r3.limitMotor3.angle=P*r+S*n+M*o,this.r3.preSolve(e,t),this.t3.preSolve(e,t)},a.SliderJoint.prototype.solve=function(){this.r3.solve(),this.t3.solve()},a.SliderJoint.prototype.postSolve=function(){},a.SliderJoint.prototype.acosClamp=function(e){return e>1?0:e<-1?a.PI:a.acos(e)},a.WheelJoint=function(e){a.Joint.call(this,e),this.type=a.JOINT_WHEEL,this.localAxis1=(new a.Vec3).normalize(e.localAxis1),this.localAxis2=(new a.Vec3).normalize(e.localAxis2);var t;this.localAxis1X=this.localAxis1.x,this.localAxis1Y=this.localAxis1.y,this.localAxis1Z=this.localAxis1.z,this.localAxis2X=this.localAxis2.x,this.localAxis2Y=this.localAxis2.y,this.localAxis2Z=this.localAxis2.z;var i=this.localAxis1X*this.localAxis2X+this.localAxis1Y*this.localAxis2Y+this.localAxis1Z*this.localAxis2Z;if(i>-1&&i<1)this.localAngAxis1X=this.localAxis2X-i*this.localAxis1X,this.localAngAxis1Y=this.localAxis2Y-i*this.localAxis1Y,this.localAngAxis1Z=this.localAxis2Z-i*this.localAxis1Z,this.localAngAxis2X=this.localAxis1X-i*this.localAxis2X,this.localAngAxis2Y=this.localAxis1Y-i*this.localAxis2Y,this.localAngAxis2Z=this.localAxis1Z-i*this.localAxis2Z,t=1/a.sqrt(this.localAngAxis1X*this.localAngAxis1X+this.localAngAxis1Y*this.localAngAxis1Y+this.localAngAxis1Z*this.localAngAxis1Z),this.localAngAxis1X*=t,this.localAngAxis1Y*=t,this.localAngAxis1Z*=t,t=1/a.sqrt(this.localAngAxis2X*this.localAngAxis2X+this.localAngAxis2Y*this.localAngAxis2Y+this.localAngAxis2Z*this.localAngAxis2Z),this.localAngAxis2X*=t,this.localAngAxis2Y*=t,this.localAngAxis2Z*=t;else{this.localAngAxis1X=this.localAxis1Y*this.localAxis1X-this.localAxis1Z*this.localAxis1Z,this.localAngAxis1Y=-this.localAxis1Z*this.localAxis1Y-this.localAxis1X*this.localAxis1X,this.localAngAxis1Z=this.localAxis1X*this.localAxis1Z+this.localAxis1Y*this.localAxis1Y,t=1/a.sqrt(this.localAngAxis1X*this.localAngAxis1X+this.localAngAxis1Y*this.localAngAxis1Y+this.localAngAxis1Z*this.localAngAxis1Z),this.localAngAxis1X*=t,this.localAngAxis1Y*=t,this.localAngAxis1Z*=t;var r=(new a.Mat33).setQuat((new a.Quat).arc(this.localAxis1,this.localAxis2)).elements;this.localAngAxis2X=this.localAngAxis1X*r[0]+this.localAngAxis1Y*r[1]+this.localAngAxis1Z*r[2],this.localAngAxis2Y=this.localAngAxis1X*r[3]+this.localAngAxis1Y*r[4]+this.localAngAxis1Z*r[5],this.localAngAxis2Z=this.localAngAxis1X*r[6]+this.localAngAxis1Y*r[7]+this.localAngAxis1Z*r[8]}this.nor=new a.Vec3,this.tan=new a.Vec3,this.bin=new a.Vec3,this.translationalLimitMotor=new a.LimitMotor(this.tan,!0),this.translationalLimitMotor.frequency=8,this.translationalLimitMotor.dampingRatio=1,this.rotationalLimitMotor1=new a.LimitMotor(this.tan,!1),this.rotationalLimitMotor2=new a.LimitMotor(this.bin,!1),this.t3=new a.Translational3Constraint(this,new a.LimitMotor(this.nor,!0),this.translationalLimitMotor,new a.LimitMotor(this.bin,!0)),this.t3.weight=1,this.r3=new a.Rotational3Constraint(this,new a.LimitMotor(this.nor,!0),this.rotationalLimitMotor1,this.rotationalLimitMotor2)},a.WheelJoint.prototype=Object.create(a.Joint.prototype),a.WheelJoint.prototype.constructor=a.WheelJoint,a.WheelJoint.prototype.preSolve=function(e,t){var i,r;this.updateAnchorPoints(),i=this.body1.rotation.elements;var n=this.localAxis1X*i[0]+this.localAxis1Y*i[1]+this.localAxis1Z*i[2],o=this.localAxis1X*i[3]+this.localAxis1Y*i[4]+this.localAxis1Z*i[5],s=this.localAxis1X*i[6]+this.localAxis1Y*i[7]+this.localAxis1Z*i[8],l=this.localAngAxis1X*i[0]+this.localAngAxis1Y*i[1]+this.localAngAxis1Z*i[2],h=this.localAngAxis1X*i[3]+this.localAngAxis1Y*i[4]+this.localAngAxis1Z*i[5],u=this.localAngAxis1X*i[6]+this.localAngAxis1Y*i[7]+this.localAngAxis1Z*i[8];i=this.body2.rotation.elements;var c=this.localAxis2X*i[0]+this.localAxis2Y*i[1]+this.localAxis2Z*i[2],f=this.localAxis2X*i[3]+this.localAxis2Y*i[4]+this.localAxis2Z*i[5],p=this.localAxis2X*i[6]+this.localAxis2Y*i[7]+this.localAxis2Z*i[8],d=this.localAngAxis2X*i[0]+this.localAngAxis2Y*i[1]+this.localAngAxis2Z*i[2],m=this.localAngAxis2X*i[3]+this.localAngAxis2Y*i[4]+this.localAngAxis2Z*i[5],g=this.localAngAxis2X*i[6]+this.localAngAxis2Y*i[7]+this.localAngAxis2Z*i[8];this.r3.limitMotor1.angle=n*c+o*f+s*p,this.rotationalLimitMotor1.angle=n*(h*p-u*f)+o*(u*c-l*p)+s*(l*f-h*c)<0?-this.acosClamp(l*c+h*f+u*p):this.acosClamp(l*c+h*f+u*p),this.rotationalLimitMotor2.angle=c*(m*s-g*o)+f*(g*n-d*s)+p*(d*o-m*n)<0?this.acosClamp(d*n+m*o+g*s):-this.acosClamp(d*n+m*o+g*s);var v=f*s-p*o,_=p*n-c*s,y=c*o-f*n;(r=a.sqrt(v*v+_*_+y*y))>0&&(r=1/r);var x=(_*=r)*p-(y*=r)*f,b=y*c-(v*=r)*p,T=v*f-_*c;(r=a.sqrt(x*x+b*b+T*T))>0&&(r=1/r),x*=r,b*=r,T*=r;var E=o*y-s*_,A=s*v-n*y,P=n*_-o*v;(r=a.sqrt(E*E+A*A+P*P))>0&&(r=1/r),E*=r,A*=r,P*=r,this.nor.init(v,_,y),this.tan.init(x,b,T),this.bin.init(E,A,P),this.r3.preSolve(e,t),this.t3.preSolve(e,t)},a.WheelJoint.prototype.solve=function(){this.r3.solve(),this.t3.solve()},a.WheelJoint.prototype.postSolve=function(){},a.WheelJoint.prototype.acosClamp=function(e){return e>1?0:e<-1?a.PI:a.acos(e)},a.AngularConstraint=function(e,t){this.joint=e,this.targetOrientation=(new a.Quat).invert(t),this.relativeOrientation=new a.Quat,this.ii1=null,this.ii2=null,this.dd=null,this.vel=new a.Vec3,this.imp=new a.Vec3,this.rn0=new a.Vec3,this.rn1=new a.Vec3,this.rn2=new a.Vec3,this.b1=e.body1,this.b2=e.body2,this.a1=this.b1.angularVelocity,this.a2=this.b2.angularVelocity,this.i1=this.b1.inverseInertia,this.i2=this.b2.inverseInertia},a.AngularConstraint.prototype={constructor:a.AngularConstraint,preSolve:function(e,t){var i,r,n;this.ii1=this.i1.clone(),this.ii2=this.i2.clone(),i=1/((n=(new a.Mat33).add(this.ii1,this.ii2).elements)[0]*(n[4]*n[8]-n[7]*n[5])+n[3]*(n[7]*n[2]-n[1]*n[8])+n[6]*(n[1]*n[5]-n[4]*n[2])),this.dd=new a.Mat33(n[4]*n[8]-n[5]*n[7],n[2]*n[7]-n[1]*n[8],n[1]*n[5]-n[2]*n[4],n[5]*n[6]-n[3]*n[8],n[0]*n[8]-n[2]*n[6],n[2]*n[3]-n[0]*n[5],n[3]*n[7]-n[4]*n[6],n[1]*n[6]-n[0]*n[7],n[0]*n[4]-n[1]*n[3]).multiply(i),this.relativeOrientation.invert(this.b1.orientation),this.relativeOrientation.mul(this.targetOrientation,this.relativeOrientation),this.relativeOrientation.mul(this.b2.orientation,this.relativeOrientation),i=2*this.relativeOrientation.s,this.vel.scale(this.relativeOrientation,i),(r=this.vel.length())>.02?(r=(.02-r)/r*t*.05,this.vel.scaleEqual(r)):this.vel.init(),this.rn1.mulMat(this.ii1,this.imp),this.rn2.mulMat(this.ii2,this.imp),this.a1.addEqual(this.rn1),this.a2.subEqual(this.rn2)},solve:function(){var e=this.a2.clone().subEqual(this.a1).subEqual(this.vel);this.rn0.mulMat(this.dd,e),this.rn1.mulMat(this.ii1,this.rn0),this.rn2.mulMat(this.ii2,this.rn0),this.imp.addEqual(this.rn0),this.a1.addEqual(this.rn1),this.a2.subEqual(this.rn2)}},a.LinearConstraint=function(e){this.m1=NaN,this.m2=NaN,this.ii1=null,this.ii2=null,this.dd=null,this.r1x=NaN,this.r1y=NaN,this.r1z=NaN,this.r2x=NaN,this.r2y=NaN,this.r2z=NaN,this.ax1x=NaN,this.ax1y=NaN,this.ax1z=NaN,this.ay1x=NaN,this.ay1y=NaN,this.ay1z=NaN,this.az1x=NaN,this.az1y=NaN,this.az1z=NaN,this.ax2x=NaN,this.ax2y=NaN,this.ax2z=NaN,this.ay2x=NaN,this.ay2y=NaN,this.ay2z=NaN,this.az2x=NaN,this.az2y=NaN,this.az2z=NaN,this.vel=NaN,this.velx=NaN,this.vely=NaN,this.velz=NaN,this.joint=e,this.r1=e.relativeAnchorPoint1,this.r2=e.relativeAnchorPoint2,this.p1=e.anchorPoint1,this.p2=e.anchorPoint2,this.b1=e.body1,this.b2=e.body2,this.l1=this.b1.linearVelocity,this.l2=this.b2.linearVelocity,this.a1=this.b1.angularVelocity,this.a2=this.b2.angularVelocity,this.i1=this.b1.inverseInertia,this.i2=this.b2.inverseInertia,this.impx=0,this.impy=0,this.impz=0},a.LinearConstraint.prototype={constructor:a.LinearConstraint,preSolve:function(e,t){this.r1x=this.r1.x,this.r1y=this.r1.y,this.r1z=this.r1.z,this.r2x=this.r2.x,this.r2y=this.r2.y,this.r2z=this.r2.z,this.m1=this.b1.inverseMass,this.m2=this.b2.inverseMass,this.ii1=this.i1.clone(),this.ii2=this.i2.clone();var i=this.ii1.elements,r=this.ii2.elements;this.ax1x=this.r1z*i[1]+-this.r1y*i[2],this.ax1y=this.r1z*i[4]+-this.r1y*i[5],this.ax1z=this.r1z*i[7]+-this.r1y*i[8],this.ay1x=-this.r1z*i[0]+this.r1x*i[2],this.ay1y=-this.r1z*i[3]+this.r1x*i[5],this.ay1z=-this.r1z*i[6]+this.r1x*i[8],this.az1x=this.r1y*i[0]+-this.r1x*i[1],this.az1y=this.r1y*i[3]+-this.r1x*i[4],this.az1z=this.r1y*i[6]+-this.r1x*i[7],this.ax2x=this.r2z*r[1]+-this.r2y*r[2],this.ax2y=this.r2z*r[4]+-this.r2y*r[5],this.ax2z=this.r2z*r[7]+-this.r2y*r[8],this.ay2x=-this.r2z*r[0]+this.r2x*r[2],this.ay2y=-this.r2z*r[3]+this.r2x*r[5],this.ay2z=-this.r2z*r[6]+this.r2x*r[8],this.az2x=this.r2y*r[0]+-this.r2x*r[1],this.az2y=this.r2y*r[3]+-this.r2x*r[4],this.az2z=this.r2y*r[6]+-this.r2x*r[7];var n=this.m1+this.m2,o=new a.Mat33(n,0,0,0,n,0,0,0,n).elements;o[0]+=i[4]*this.r1z*this.r1z-(i[7]+i[5])*this.r1y*this.r1z+i[8]*this.r1y*this.r1y,o[1]+=(i[6]*this.r1y+i[5]*this.r1x)*this.r1z-i[3]*this.r1z*this.r1z-i[8]*this.r1x*this.r1y,o[2]+=(i[3]*this.r1y-i[4]*this.r1x)*this.r1z-i[6]*this.r1y*this.r1y+i[7]*this.r1x*this.r1y,o[3]+=(i[2]*this.r1y+i[7]*this.r1x)*this.r1z-i[1]*this.r1z*this.r1z-i[8]*this.r1x*this.r1y,o[4]+=i[0]*this.r1z*this.r1z-(i[6]+i[2])*this.r1x*this.r1z+i[8]*this.r1x*this.r1x,o[5]+=(i[1]*this.r1x-i[0]*this.r1y)*this.r1z-i[7]*this.r1x*this.r1x+i[6]*this.r1x*this.r1y,o[6]+=(i[1]*this.r1y-i[4]*this.r1x)*this.r1z-i[2]*this.r1y*this.r1y+i[5]*this.r1x*this.r1y,o[7]+=(i[3]*this.r1x-i[0]*this.r1y)*this.r1z-i[5]*this.r1x*this.r1x+i[2]*this.r1x*this.r1y,o[8]+=i[0]*this.r1y*this.r1y-(i[3]+i[1])*this.r1x*this.r1y+i[4]*this.r1x*this.r1x,o[0]+=r[4]*this.r2z*this.r2z-(r[7]+r[5])*this.r2y*this.r2z+r[8]*this.r2y*this.r2y,o[1]+=(r[6]*this.r2y+r[5]*this.r2x)*this.r2z-r[3]*this.r2z*this.r2z-r[8]*this.r2x*this.r2y,o[2]+=(r[3]*this.r2y-r[4]*this.r2x)*this.r2z-r[6]*this.r2y*this.r2y+r[7]*this.r2x*this.r2y,o[3]+=(r[2]*this.r2y+r[7]*this.r2x)*this.r2z-r[1]*this.r2z*this.r2z-r[8]*this.r2x*this.r2y,o[4]+=r[0]*this.r2z*this.r2z-(r[6]+r[2])*this.r2x*this.r2z+r[8]*this.r2x*this.r2x,o[5]+=(r[1]*this.r2x-r[0]*this.r2y)*this.r2z-r[7]*this.r2x*this.r2x+r[6]*this.r2x*this.r2y,o[6]+=(r[1]*this.r2y-r[4]*this.r2x)*this.r2z-r[2]*this.r2y*this.r2y+r[5]*this.r2x*this.r2y,o[7]+=(r[3]*this.r2x-r[0]*this.r2y)*this.r2z-r[5]*this.r2x*this.r2x+r[2]*this.r2x*this.r2y,o[8]+=r[0]*this.r2y*this.r2y-(r[3]+r[1])*this.r2x*this.r2y+r[4]*this.r2x*this.r2x;var s=1/(o[0]*(o[4]*o[8]-o[7]*o[5])+o[3]*(o[7]*o[2]-o[1]*o[8])+o[6]*(o[1]*o[5]-o[4]*o[2]));this.dd=new a.Mat33(o[4]*o[8]-o[5]*o[7],o[2]*o[7]-o[1]*o[8],o[1]*o[5]-o[2]*o[4],o[5]*o[6]-o[3]*o[8],o[0]*o[8]-o[2]*o[6],o[2]*o[3]-o[0]*o[5],o[3]*o[7]-o[4]*o[6],o[1]*o[6]-o[0]*o[7],o[0]*o[4]-o[1]*o[3]).multiply(s),this.velx=this.p2.x-this.p1.x,this.vely=this.p2.y-this.p1.y,this.velz=this.p2.z-this.p1.z;var l=a.sqrt(this.velx*this.velx+this.vely*this.vely+this.velz*this.velz);l>.005?(l=(.005-l)/l*t*.05,this.velx*=l,this.vely*=l,this.velz*=l):(this.velx=0,this.vely=0,this.velz=0),this.impx*=.95,this.impy*=.95,this.impz*=.95,this.l1.x+=this.impx*this.m1,this.l1.y+=this.impy*this.m1,this.l1.z+=this.impz*this.m1,this.a1.x+=this.impx*this.ax1x+this.impy*this.ay1x+this.impz*this.az1x,this.a1.y+=this.impx*this.ax1y+this.impy*this.ay1y+this.impz*this.az1y,this.a1.z+=this.impx*this.ax1z+this.impy*this.ay1z+this.impz*this.az1z,this.l2.x-=this.impx*this.m2,this.l2.y-=this.impy*this.m2,this.l2.z-=this.impz*this.m2,this.a2.x-=this.impx*this.ax2x+this.impy*this.ay2x+this.impz*this.az2x,this.a2.y-=this.impx*this.ax2y+this.impy*this.ay2y+this.impz*this.az2y,this.a2.z-=this.impx*this.ax2z+this.impy*this.ay2z+this.impz*this.az2z},solve:function(){var e=this.dd.elements,t=this.l2.x-this.l1.x+this.a2.y*this.r2z-this.a2.z*this.r2y-this.a1.y*this.r1z+this.a1.z*this.r1y-this.velx,i=this.l2.y-this.l1.y+this.a2.z*this.r2x-this.a2.x*this.r2z-this.a1.z*this.r1x+this.a1.x*this.r1z-this.vely,r=this.l2.z-this.l1.z+this.a2.x*this.r2y-this.a2.y*this.r2x-this.a1.x*this.r1y+this.a1.y*this.r1x-this.velz,n=t*e[0]+i*e[1]+r*e[2],o=t*e[3]+i*e[4]+r*e[5],s=t*e[6]+i*e[7]+r*e[8];this.impx+=n,this.impy+=o,this.impz+=s,this.l1.x+=n*this.m1,this.l1.y+=o*this.m1,this.l1.z+=s*this.m1,this.a1.x+=n*this.ax1x+o*this.ay1x+s*this.az1x,this.a1.y+=n*this.ax1y+o*this.ay1y+s*this.az1y,this.a1.z+=n*this.ax1z+o*this.ay1z+s*this.az1z,this.l2.x-=n*this.m2,this.l2.y-=o*this.m2,this.l2.z-=s*this.m2,this.a2.x-=n*this.ax2x+o*this.ay2x+s*this.az2x,this.a2.y-=n*this.ax2y+o*this.ay2y+s*this.az2y,this.a2.z-=n*this.ax2z+o*this.ay2z+s*this.az2z}},a.Rotational3Constraint=function(e,t,i,r){this.cfm1=NaN,this.cfm2=NaN,this.cfm3=NaN,this.i1e00=NaN,this.i1e01=NaN,this.i1e02=NaN,this.i1e10=NaN,this.i1e11=NaN,this.i1e12=NaN,this.i1e20=NaN,this.i1e21=NaN,this.i1e22=NaN,this.i2e00=NaN,this.i2e01=NaN,this.i2e02=NaN,this.i2e10=NaN,this.i2e11=NaN,this.i2e12=NaN,this.i2e20=NaN,this.i2e21=NaN,this.i2e22=NaN,this.ax1=NaN,this.ay1=NaN,this.az1=NaN,this.ax2=NaN,this.ay2=NaN,this.az2=NaN,this.ax3=NaN,this.ay3=NaN,this.az3=NaN,this.a1x1=NaN,this.a1y1=NaN,this.a1z1=NaN,this.a2x1=NaN,this.a2y1=NaN,this.a2z1=NaN,this.a1x2=NaN,this.a1y2=NaN,this.a1z2=NaN,this.a2x2=NaN,this.a2y2=NaN,this.a2z2=NaN,this.a1x3=NaN,this.a1y3=NaN,this.a1z3=NaN,this.a2x3=NaN,this.a2y3=NaN,this.a2z3=NaN,this.lowerLimit1=NaN,this.upperLimit1=NaN,this.limitVelocity1=NaN,this.limitState1=0,this.enableMotor1=!1,this.motorSpeed1=NaN,this.maxMotorForce1=NaN,this.maxMotorImpulse1=NaN,this.lowerLimit2=NaN,this.upperLimit2=NaN,this.limitVelocity2=NaN,this.limitState2=0,this.enableMotor2=!1,this.motorSpeed2=NaN,this.maxMotorForce2=NaN,this.maxMotorImpulse2=NaN,this.lowerLimit3=NaN,this.upperLimit3=NaN,this.limitVelocity3=NaN,this.limitState3=0,this.enableMotor3=!1,this.motorSpeed3=NaN,this.maxMotorForce3=NaN,this.maxMotorImpulse3=NaN,this.k00=NaN,this.k01=NaN,this.k02=NaN,this.k10=NaN,this.k11=NaN,this.k12=NaN,this.k20=NaN,this.k21=NaN,this.k22=NaN,this.kv00=NaN,this.kv11=NaN,this.kv22=NaN,this.dv00=NaN,this.dv11=NaN,this.dv22=NaN,this.d00=NaN,this.d01=NaN,this.d02=NaN,this.d10=NaN,this.d11=NaN,this.d12=NaN,this.d20=NaN,this.d21=NaN,this.d22=NaN,this.limitMotor1=t,this.limitMotor2=i,this.limitMotor3=r,this.b1=e.body1,this.b2=e.body2,this.a1=this.b1.angularVelocity,this.a2=this.b2.angularVelocity,this.i1=this.b1.inverseInertia,this.i2=this.b2.inverseInertia,this.limitImpulse1=0,this.motorImpulse1=0,this.limitImpulse2=0,this.motorImpulse2=0,this.limitImpulse3=0,this.motorImpulse3=0},a.Rotational3Constraint.prototype={constructor:a.Rotational3Constraint,preSolve:function(e,t){this.ax1=this.limitMotor1.axis.x,this.ay1=this.limitMotor1.axis.y,this.az1=this.limitMotor1.axis.z,this.ax2=this.limitMotor2.axis.x,this.ay2=this.limitMotor2.axis.y,this.az2=this.limitMotor2.axis.z,this.ax3=this.limitMotor3.axis.x,this.ay3=this.limitMotor3.axis.y,this.az3=this.limitMotor3.axis.z,this.lowerLimit1=this.limitMotor1.lowerLimit,this.upperLimit1=this.limitMotor1.upperLimit,this.motorSpeed1=this.limitMotor1.motorSpeed,this.maxMotorForce1=this.limitMotor1.maxMotorForce,this.enableMotor1=this.maxMotorForce1>0,this.lowerLimit2=this.limitMotor2.lowerLimit,this.upperLimit2=this.limitMotor2.upperLimit,this.motorSpeed2=this.limitMotor2.motorSpeed,this.maxMotorForce2=this.limitMotor2.maxMotorForce,this.enableMotor2=this.maxMotorForce2>0,this.lowerLimit3=this.limitMotor3.lowerLimit,this.upperLimit3=this.limitMotor3.upperLimit,this.motorSpeed3=this.limitMotor3.motorSpeed,this.maxMotorForce3=this.limitMotor3.maxMotorForce,this.enableMotor3=this.maxMotorForce3>0;var i=this.i1.elements,r=this.i2.elements;this.i1e00=i[0],this.i1e01=i[1],this.i1e02=i[2],this.i1e10=i[3],this.i1e11=i[4],this.i1e12=i[5],this.i1e20=i[6],this.i1e21=i[7],this.i1e22=i[8],this.i2e00=r[0],this.i2e01=r[1],this.i2e02=r[2],this.i2e10=r[3],this.i2e11=r[4],this.i2e12=r[5],this.i2e20=r[6],this.i2e21=r[7],this.i2e22=r[8];var n=this.limitMotor1.frequency,o=this.limitMotor2.frequency,s=this.limitMotor3.frequency,a=n>0,l=o>0,h=s>0,u=this.lowerLimit1<=this.upperLimit1,c=this.lowerLimit2<=this.upperLimit2,f=this.lowerLimit3<=this.upperLimit3,p=this.limitMotor1.angle;u?(this.lowerLimit1==this.upperLimit1?(0!=this.limitState1&&(this.limitState1=0,this.limitImpulse1=0),this.limitVelocity1=this.lowerLimit1-p):p<this.lowerLimit1?(-1!=this.limitState1&&(this.limitState1=-1,this.limitImpulse1=0),this.limitVelocity1=this.lowerLimit1-p):p>this.upperLimit1?(1!=this.limitState1&&(this.limitState1=1,this.limitImpulse1=0),this.limitVelocity1=this.upperLimit1-p):(this.limitState1=2,this.limitImpulse1=0,this.limitVelocity1=0),a||(this.limitVelocity1>.02?this.limitVelocity1-=.02:this.limitVelocity1<-.02?this.limitVelocity1+=.02:this.limitVelocity1=0)):(this.limitState1=2,this.limitImpulse1=0);var d=this.limitMotor2.angle;c?(this.lowerLimit2==this.upperLimit2?(0!=this.limitState2&&(this.limitState2=0,this.limitImpulse2=0),this.limitVelocity2=this.lowerLimit2-d):d<this.lowerLimit2?(-1!=this.limitState2&&(this.limitState2=-1,this.limitImpulse2=0),this.limitVelocity2=this.lowerLimit2-d):d>this.upperLimit2?(1!=this.limitState2&&(this.limitState2=1,this.limitImpulse2=0),this.limitVelocity2=this.upperLimit2-d):(this.limitState2=2,this.limitImpulse2=0,this.limitVelocity2=0),l||(this.limitVelocity2>.02?this.limitVelocity2-=.02:this.limitVelocity2<-.02?this.limitVelocity2+=.02:this.limitVelocity2=0)):(this.limitState2=2,this.limitImpulse2=0);var m=this.limitMotor3.angle;if(f?(this.lowerLimit3==this.upperLimit3?(0!=this.limitState3&&(this.limitState3=0,this.limitImpulse3=0),this.limitVelocity3=this.lowerLimit3-m):m<this.lowerLimit3?(-1!=this.limitState3&&(this.limitState3=-1,this.limitImpulse3=0),this.limitVelocity3=this.lowerLimit3-m):m>this.upperLimit3?(1!=this.limitState3&&(this.limitState3=1,this.limitImpulse3=0),this.limitVelocity3=this.upperLimit3-m):(this.limitState3=2,this.limitImpulse3=0,this.limitVelocity3=0),h||(this.limitVelocity3>.02?this.limitVelocity3-=.02:this.limitVelocity3<-.02?this.limitVelocity3+=.02:this.limitVelocity3=0)):(this.limitState3=2,this.limitImpulse3=0),this.enableMotor1&&(0!=this.limitState1||a)?this.maxMotorImpulse1=this.maxMotorForce1*e:(this.motorImpulse1=0,this.maxMotorImpulse1=0),this.enableMotor2&&(0!=this.limitState2||l)?this.maxMotorImpulse2=this.maxMotorForce2*e:(this.motorImpulse2=0,this.maxMotorImpulse2=0),this.enableMotor3&&(0!=this.limitState3||h)?this.maxMotorImpulse3=this.maxMotorForce3*e:(this.motorImpulse3=0,this.maxMotorImpulse3=0),this.a1x1=this.ax1*this.i1e00+this.ay1*this.i1e01+this.az1*this.i1e02,this.a1y1=this.ax1*this.i1e10+this.ay1*this.i1e11+this.az1*this.i1e12,this.a1z1=this.ax1*this.i1e20+this.ay1*this.i1e21+this.az1*this.i1e22,this.a2x1=this.ax1*this.i2e00+this.ay1*this.i2e01+this.az1*this.i2e02,this.a2y1=this.ax1*this.i2e10+this.ay1*this.i2e11+this.az1*this.i2e12,this.a2z1=this.ax1*this.i2e20+this.ay1*this.i2e21+this.az1*this.i2e22,this.a1x2=this.ax2*this.i1e00+this.ay2*this.i1e01+this.az2*this.i1e02,this.a1y2=this.ax2*this.i1e10+this.ay2*this.i1e11+this.az2*this.i1e12,this.a1z2=this.ax2*this.i1e20+this.ay2*this.i1e21+this.az2*this.i1e22,this.a2x2=this.ax2*this.i2e00+this.ay2*this.i2e01+this.az2*this.i2e02,this.a2y2=this.ax2*this.i2e10+this.ay2*this.i2e11+this.az2*this.i2e12,this.a2z2=this.ax2*this.i2e20+this.ay2*this.i2e21+this.az2*this.i2e22,this.a1x3=this.ax3*this.i1e00+this.ay3*this.i1e01+this.az3*this.i1e02,this.a1y3=this.ax3*this.i1e10+this.ay3*this.i1e11+this.az3*this.i1e12,this.a1z3=this.ax3*this.i1e20+this.ay3*this.i1e21+this.az3*this.i1e22,this.a2x3=this.ax3*this.i2e00+this.ay3*this.i2e01+this.az3*this.i2e02,this.a2y3=this.ax3*this.i2e10+this.ay3*this.i2e11+this.az3*this.i2e12,this.a2z3=this.ax3*this.i2e20+this.ay3*this.i2e21+this.az3*this.i2e22,this.k00=this.ax1*(this.a1x1+this.a2x1)+this.ay1*(this.a1y1+this.a2y1)+this.az1*(this.a1z1+this.a2z1),this.k01=this.ax1*(this.a1x2+this.a2x2)+this.ay1*(this.a1y2+this.a2y2)+this.az1*(this.a1z2+this.a2z2),this.k02=this.ax1*(this.a1x3+this.a2x3)+this.ay1*(this.a1y3+this.a2y3)+this.az1*(this.a1z3+this.a2z3),this.k10=this.ax2*(this.a1x1+this.a2x1)+this.ay2*(this.a1y1+this.a2y1)+this.az2*(this.a1z1+this.a2z1),this.k11=this.ax2*(this.a1x2+this.a2x2)+this.ay2*(this.a1y2+this.a2y2)+this.az2*(this.a1z2+this.a2z2),this.k12=this.ax2*(this.a1x3+this.a2x3)+this.ay2*(this.a1y3+this.a2y3)+this.az2*(this.a1z3+this.a2z3),this.k20=this.ax3*(this.a1x1+this.a2x1)+this.ay3*(this.a1y1+this.a2y1)+this.az3*(this.a1z1+this.a2z1),this.k21=this.ax3*(this.a1x2+this.a2x2)+this.ay3*(this.a1y2+this.a2y2)+this.az3*(this.a1z2+this.a2z2),this.k22=this.ax3*(this.a1x3+this.a2x3)+this.ay3*(this.a1y3+this.a2y3)+this.az3*(this.a1z3+this.a2z3),this.kv00=this.k00,this.kv11=this.k11,this.kv22=this.k22,this.dv00=1/this.kv00,this.dv11=1/this.kv11,this.dv22=1/this.kv22,a&&2!=this.limitState1){var g=6.2831853*n,v=g*g*e,_=t/(v+2*this.limitMotor1.dampingRatio*g);this.cfm1=this.kv00*_,this.limitVelocity1*=v*_}else this.cfm1=0,this.limitVelocity1*=.05*t;l&&2!=this.limitState2?(_=t/((v=(g=6.2831853*o)*g*e)+2*this.limitMotor2.dampingRatio*g),this.cfm2=this.kv11*_,this.limitVelocity2*=v*_):(this.cfm2=0,this.limitVelocity2*=.05*t),h&&2!=this.limitState3?(_=t/((v=(g=6.2831853*s)*g*e)+2*this.limitMotor3.dampingRatio*g),this.cfm3=this.kv22*_,this.limitVelocity3*=v*_):(this.cfm3=0,this.limitVelocity3*=.05*t),this.k00+=this.cfm1,this.k11+=this.cfm2,this.k22+=this.cfm3;var y=1/(this.k00*(this.k11*this.k22-this.k21*this.k12)+this.k10*(this.k21*this.k02-this.k01*this.k22)+this.k20*(this.k01*this.k12-this.k11*this.k02));this.d00=(this.k11*this.k22-this.k12*this.k21)*y,this.d01=(this.k02*this.k21-this.k01*this.k22)*y,this.d02=(this.k01*this.k12-this.k02*this.k11)*y,this.d10=(this.k12*this.k20-this.k10*this.k22)*y,this.d11=(this.k00*this.k22-this.k02*this.k20)*y,this.d12=(this.k02*this.k10-this.k00*this.k12)*y,this.d20=(this.k10*this.k21-this.k11*this.k20)*y,this.d21=(this.k01*this.k20-this.k00*this.k21)*y,this.d22=(this.k00*this.k11-this.k01*this.k10)*y,this.limitImpulse1*=.95,this.motorImpulse1*=.95,this.limitImpulse2*=.95,this.motorImpulse2*=.95,this.limitImpulse3*=.95,this.motorImpulse3*=.95;var x=this.limitImpulse1+this.motorImpulse1,b=this.limitImpulse2+this.motorImpulse2,T=this.limitImpulse3+this.motorImpulse3;this.a1.x+=x*this.a1x1+b*this.a1x2+T*this.a1x3,this.a1.y+=x*this.a1y1+b*this.a1y2+T*this.a1y3,this.a1.z+=x*this.a1z1+b*this.a1z2+T*this.a1z3,this.a2.x-=x*this.a2x1+b*this.a2x2+T*this.a2x3,this.a2.y-=x*this.a2y1+b*this.a2y2+T*this.a2y3,this.a2.z-=x*this.a2z1+b*this.a2z2+T*this.a2z3},solve_:function(){var e=this.a2.x-this.a1.x,t=this.a2.y-this.a1.y,i=this.a2.z-this.a1.z;this.limitVelocity3=30;var r=e*this.ax1+t*this.ay1+i*this.az1-this.limitVelocity1,n=e*this.ax2+t*this.ay2+i*this.az2-this.limitVelocity2,o=e*this.ax3+t*this.ay3+i*this.az3-this.limitVelocity3,s=r*this.d00+n*this.d01+o*this.d02,a=r*this.d10+n*this.d11+o*this.d12,l=r*this.d20+n*this.d21+o*this.d22;this.limitImpulse1+=s,this.limitImpulse2+=a,this.limitImpulse3+=l,this.a1.x+=s*this.a1x1+a*this.a1x2+l*this.a1x3,this.a1.y+=s*this.a1y1+a*this.a1y2+l*this.a1y3,this.a1.z+=s*this.a1z1+a*this.a1z2+l*this.a1z3,this.a2.x-=s*this.a2x1+a*this.a2x2+l*this.a2x3,this.a2.y-=s*this.a2y1+a*this.a2y2+l*this.a2y3,this.a2.z-=s*this.a2z1+a*this.a2z2+l*this.a2z3},solve:function(){var e=this.a2.x-this.a1.x,t=this.a2.y-this.a1.y,i=this.a2.z-this.a1.z,r=e*this.ax1+t*this.ay1+i*this.az1,n=e*this.ax2+t*this.ay2+i*this.az2,o=e*this.ax3+t*this.ay3+i*this.az3,s=this.motorImpulse1,a=this.motorImpulse2,l=this.motorImpulse3,h=0,u=0,c=0;this.enableMotor1&&(h=(r-this.motorSpeed1)*this.dv00,this.motorImpulse1+=h,this.motorImpulse1>this.maxMotorImpulse1?this.motorImpulse1=this.maxMotorImpulse1:this.motorImpulse1<-this.maxMotorImpulse1&&(this.motorImpulse1=-this.maxMotorImpulse1),h=this.motorImpulse1-s),this.enableMotor2&&(u=(n-this.motorSpeed2)*this.dv11,this.motorImpulse2+=u,this.motorImpulse2>this.maxMotorImpulse2?this.motorImpulse2=this.maxMotorImpulse2:this.motorImpulse2<-this.maxMotorImpulse2&&(this.motorImpulse2=-this.maxMotorImpulse2),u=this.motorImpulse2-a),this.enableMotor3&&(c=(o-this.motorSpeed3)*this.dv22,this.motorImpulse3+=c,this.motorImpulse3>this.maxMotorImpulse3?this.motorImpulse3=this.maxMotorImpulse3:this.motorImpulse3<-this.maxMotorImpulse3&&(this.motorImpulse3=-this.maxMotorImpulse3),c=this.motorImpulse3-l),r+=h*this.kv00+u*this.k01+c*this.k02,n+=h*this.k10+u*this.kv11+c*this.k12,o+=h*this.k20+u*this.k21+c*this.kv22,r-=this.limitVelocity1+this.limitImpulse1*this.cfm1,n-=this.limitVelocity2+this.limitImpulse2*this.cfm2,o-=this.limitVelocity3+this.limitImpulse3*this.cfm3;var f=this.limitImpulse1,p=this.limitImpulse2,d=this.limitImpulse3,m=r*this.d00+n*this.d01+o*this.d02,g=r*this.d10+n*this.d11+o*this.d12,v=r*this.d20+n*this.d21+o*this.d22;this.limitImpulse1+=m,this.limitImpulse2+=g,this.limitImpulse3+=v;var _=0;(2==this.limitState1||this.limitImpulse1*this.limitState1<0)&&(n+=(m=-f)*this.k10,o+=m*this.k20,_|=1),(2==this.limitState2||this.limitImpulse2*this.limitState2<0)&&(r+=(g=-p)*this.k01,o+=g*this.k21,_|=2),(2==this.limitState3||this.limitImpulse3*this.limitState3<0)&&(r+=(v=-d)*this.k02,n+=v*this.k12,_|=4);var y;switch(_){case 1:y=1/(this.k11*this.k22-this.k12*this.k21),g=(this.k22*n+-this.k12*o)*y,v=(-this.k21*n+this.k11*o)*y;break;case 2:y=1/(this.k00*this.k22-this.k02*this.k20),m=(this.k22*r+-this.k02*o)*y,v=(-this.k20*r+this.k00*o)*y;break;case 3:v=o/this.k22;break;case 4:y=1/(this.k00*this.k11-this.k01*this.k10),m=(this.k11*r+-this.k01*n)*y,g=(-this.k10*r+this.k00*n)*y;break;case 5:g=n/this.k11;break;case 6:m=r/this.k00}this.limitImpulse1=m+f,this.limitImpulse2=g+p,this.limitImpulse3=v+d;var x=h+m,b=u+g,T=c+v;this.a1.x+=x*this.a1x1+b*this.a1x2+T*this.a1x3,this.a1.y+=x*this.a1y1+b*this.a1y2+T*this.a1y3,this.a1.z+=x*this.a1z1+b*this.a1z2+T*this.a1z3,this.a2.x-=x*this.a2x1+b*this.a2x2+T*this.a2x3,this.a2.y-=x*this.a2y1+b*this.a2y2+T*this.a2y3,this.a2.z-=x*this.a2z1+b*this.a2z2+T*this.a2z3,e=this.a2.x-this.a1.x,t=this.a2.y-this.a1.y,i=this.a2.z-this.a1.z,n=e*this.ax2+t*this.ay2+i*this.az2}},a.RotationalConstraint=function(e,t){this.cfm=NaN,this.i1e00=NaN,this.i1e01=NaN,this.i1e02=NaN,this.i1e10=NaN,this.i1e11=NaN,this.i1e12=NaN,this.i1e20=NaN,this.i1e21=NaN,this.i1e22=NaN,this.i2e00=NaN,this.i2e01=NaN,this.i2e02=NaN,this.i2e10=NaN,this.i2e11=NaN,this.i2e12=NaN,this.i2e20=NaN,this.i2e21=NaN,this.i2e22=NaN,this.motorDenom=NaN,this.invMotorDenom=NaN,this.invDenom=NaN,this.ax=NaN,this.ay=NaN,this.az=NaN,this.a1x=NaN,this.a1y=NaN,this.a1z=NaN,this.a2x=NaN,this.a2y=NaN,this.a2z=NaN,this.enableLimit=!1,this.lowerLimit=NaN,this.upperLimit=NaN,this.limitVelocity=NaN,this.limitState=0,this.enableMotor=!1,this.motorSpeed=NaN,this.maxMotorForce=NaN,this.maxMotorImpulse=NaN,this.limitMotor=t,this.b1=e.body1,this.b2=e.body2,this.a1=this.b1.angularVelocity,this.a2=this.b2.angularVelocity,this.i1=this.b1.inverseInertia,this.i2=this.b2.inverseInertia,this.limitImpulse=0,this.motorImpulse=0},a.RotationalConstraint.prototype={constructor:a.RotationalConstraint,preSolve:function(e,t){this.ax=this.limitMotor.axis.x,this.ay=this.limitMotor.axis.y,this.az=this.limitMotor.axis.z,this.lowerLimit=this.limitMotor.lowerLimit,this.upperLimit=this.limitMotor.upperLimit,this.motorSpeed=this.limitMotor.motorSpeed,this.maxMotorForce=this.limitMotor.maxMotorForce,this.enableMotor=this.maxMotorForce>0;var i=this.i1.elements,r=this.i2.elements;this.i1e00=i[0],this.i1e01=i[1],this.i1e02=i[2],this.i1e10=i[3],this.i1e11=i[4],this.i1e12=i[5],this.i1e20=i[6],this.i1e21=i[7],this.i1e22=i[8],this.i2e00=r[0],this.i2e01=r[1],this.i2e02=r[2],this.i2e10=r[3],this.i2e11=r[4],this.i2e12=r[5],this.i2e20=r[6],this.i2e21=r[7],this.i2e22=r[8];var n=this.limitMotor.frequency,o=n>0,s=this.lowerLimit<=this.upperLimit,a=this.limitMotor.angle;if(s?(this.lowerLimit==this.upperLimit?(0!=this.limitState&&(this.limitState=0,this.limitImpulse=0),this.limitVelocity=this.lowerLimit-a):a<this.lowerLimit?(-1!=this.limitState&&(this.limitState=-1,this.limitImpulse=0),this.limitVelocity=this.lowerLimit-a):a>this.upperLimit?(1!=this.limitState&&(this.limitState=1,this.limitImpulse=0),this.limitVelocity=this.upperLimit-a):(this.limitState=2,this.limitImpulse=0,this.limitVelocity=0),o||(this.limitVelocity>.02?this.limitVelocity-=.02:this.limitVelocity<-.02?this.limitVelocity+=.02:this.limitVelocity=0)):(this.limitState=2,this.limitImpulse=0),this.enableMotor&&(0!=this.limitState||o)?this.maxMotorImpulse=this.maxMotorForce*e:(this.motorImpulse=0,this.maxMotorImpulse=0),this.a1x=this.ax*this.i1e00+this.ay*this.i1e01+this.az*this.i1e02,this.a1y=this.ax*this.i1e10+this.ay*this.i1e11+this.az*this.i1e12,this.a1z=this.ax*this.i1e20+this.ay*this.i1e21+this.az*this.i1e22,this.a2x=this.ax*this.i2e00+this.ay*this.i2e01+this.az*this.i2e02,this.a2y=this.ax*this.i2e10+this.ay*this.i2e11+this.az*this.i2e12,this.a2z=this.ax*this.i2e20+this.ay*this.i2e21+this.az*this.i2e22,this.motorDenom=this.ax*(this.a1x+this.a2x)+this.ay*(this.a1y+this.a2y)+this.az*(this.a1z+this.a2z),this.invMotorDenom=1/this.motorDenom,o&&2!=this.limitState){var l=6.2831853*n,h=l*l*e,u=t/(h+2*this.limitMotor.dampingRatio*l);this.cfm=this.motorDenom*u,this.limitVelocity*=h*u}else this.cfm=0,this.limitVelocity*=.05*t;this.invDenom=1/(this.motorDenom+this.cfm),this.limitImpulse*=.95,this.motorImpulse*=.95;var c=this.limitImpulse+this.motorImpulse;this.a1.x+=c*this.a1x,this.a1.y+=c*this.a1y,this.a1.z+=c*this.a1z,this.a2.x-=c*this.a2x,this.a2.y-=c*this.a2y,this.a2.z-=c*this.a2z},solve:function(){var e,t=this.ax*(this.a2.x-this.a1.x)+this.ay*(this.a2.y-this.a1.y)+this.az*(this.a2.z-this.a1.z);if(this.enableMotor){e=(t-this.motorSpeed)*this.invMotorDenom;var i=this.motorImpulse;this.motorImpulse+=e,this.motorImpulse>this.maxMotorImpulse?this.motorImpulse=this.maxMotorImpulse:this.motorImpulse<-this.maxMotorImpulse&&(this.motorImpulse=-this.maxMotorImpulse),t-=(e=this.motorImpulse-i)*this.motorDenom}else e=0;var r;if(2!=this.limitState){r=(t-this.limitVelocity-this.limitImpulse*this.cfm)*this.invDenom;var n=this.limitImpulse;this.limitImpulse+=r,this.limitImpulse*this.limitState<0&&(this.limitImpulse=0),r=this.limitImpulse-n}else r=0;var o=r+e;this.a1.x+=o*this.a1x,this.a1.y+=o*this.a1y,this.a1.z+=o*this.a1z,this.a2.x-=o*this.a2x,this.a2.y-=o*this.a2y,this.a2.z-=o*this.a2z}},a.Translational3Constraint=function(e,t,i,r){this.m1=NaN,this.m2=NaN,this.i1e00=NaN,this.i1e01=NaN,this.i1e02=NaN,this.i1e10=NaN,this.i1e11=NaN,this.i1e12=NaN,this.i1e20=NaN,this.i1e21=NaN,this.i1e22=NaN,this.i2e00=NaN,this.i2e01=NaN,this.i2e02=NaN,this.i2e10=NaN,this.i2e11=NaN,this.i2e12=NaN,this.i2e20=NaN,this.i2e21=NaN,this.i2e22=NaN,this.ax1=NaN,this.ay1=NaN,this.az1=NaN,this.ax2=NaN,this.ay2=NaN,this.az2=NaN,this.ax3=NaN,this.ay3=NaN,this.az3=NaN,this.r1x=NaN,this.r1y=NaN,this.r1z=NaN,this.r2x=NaN,this.r2y=NaN,this.r2z=NaN,this.t1x1=NaN,this.t1y1=NaN,this.t1z1=NaN,this.t2x1=NaN,this.t2y1=NaN,this.t2z1=NaN,this.l1x1=NaN,this.l1y1=NaN,this.l1z1=NaN,this.l2x1=NaN,this.l2y1=NaN,this.l2z1=NaN,this.a1x1=NaN,this.a1y1=NaN,this.a1z1=NaN,this.a2x1=NaN,this.a2y1=NaN,this.a2z1=NaN,this.t1x2=NaN,this.t1y2=NaN,this.t1z2=NaN,this.t2x2=NaN,this.t2y2=NaN,this.t2z2=NaN,this.l1x2=NaN,this.l1y2=NaN,this.l1z2=NaN,this.l2x2=NaN,this.l2y2=NaN,this.l2z2=NaN,this.a1x2=NaN,this.a1y2=NaN,this.a1z2=NaN,this.a2x2=NaN,this.a2y2=NaN,this.a2z2=NaN,this.t1x3=NaN,this.t1y3=NaN,this.t1z3=NaN,this.t2x3=NaN,this.t2y3=NaN,this.t2z3=NaN,this.l1x3=NaN,this.l1y3=NaN,this.l1z3=NaN,this.l2x3=NaN,this.l2y3=NaN,this.l2z3=NaN,this.a1x3=NaN,this.a1y3=NaN,this.a1z3=NaN,this.a2x3=NaN,this.a2y3=NaN,this.a2z3=NaN,this.lowerLimit1=NaN,this.upperLimit1=NaN,this.limitVelocity1=NaN,this.limitState1=0,this.enableMotor1=!1,this.motorSpeed1=NaN,this.maxMotorForce1=NaN,this.maxMotorImpulse1=NaN,this.lowerLimit2=NaN,this.upperLimit2=NaN,this.limitVelocity2=NaN,this.limitState2=0,this.enableMotor2=!1,this.motorSpeed2=NaN,this.maxMotorForce2=NaN,this.maxMotorImpulse2=NaN,this.lowerLimit3=NaN,this.upperLimit3=NaN,this.limitVelocity3=NaN,this.limitState3=0,this.enableMotor3=!1,this.motorSpeed3=NaN,this.maxMotorForce3=NaN,this.maxMotorImpulse3=NaN,this.k00=NaN,this.k01=NaN,this.k02=NaN,this.k10=NaN,this.k11=NaN,this.k12=NaN,this.k20=NaN,this.k21=NaN,this.k22=NaN,this.kv00=NaN,this.kv11=NaN,this.kv22=NaN,this.dv00=NaN,this.dv11=NaN,this.dv22=NaN,this.d00=NaN,this.d01=NaN,this.d02=NaN,this.d10=NaN,this.d11=NaN,this.d12=NaN,this.d20=NaN,this.d21=NaN,this.d22=NaN,this.limitMotor1=t,this.limitMotor2=i,this.limitMotor3=r,this.b1=e.body1,this.b2=e.body2,this.p1=e.anchorPoint1,this.p2=e.anchorPoint2,this.r1=e.relativeAnchorPoint1,this.r2=e.relativeAnchorPoint2,this.l1=this.b1.linearVelocity,this.l2=this.b2.linearVelocity,this.a1=this.b1.angularVelocity,this.a2=this.b2.angularVelocity,this.i1=this.b1.inverseInertia,this.i2=this.b2.inverseInertia,this.limitImpulse1=0,this.motorImpulse1=0,this.limitImpulse2=0,this.motorImpulse2=0,this.limitImpulse3=0,this.motorImpulse3=0,this.cfm1=0,this.cfm2=0,this.cfm3=0,this.weight=-1},a.Translational3Constraint.prototype={constructor:a.Translational3Constraint,preSolve:function(e,t){this.ax1=this.limitMotor1.axis.x,this.ay1=this.limitMotor1.axis.y,this.az1=this.limitMotor1.axis.z,this.ax2=this.limitMotor2.axis.x,this.ay2=this.limitMotor2.axis.y,this.az2=this.limitMotor2.axis.z,this.ax3=this.limitMotor3.axis.x,this.ay3=this.limitMotor3.axis.y,this.az3=this.limitMotor3.axis.z,this.lowerLimit1=this.limitMotor1.lowerLimit,this.upperLimit1=this.limitMotor1.upperLimit,this.motorSpeed1=this.limitMotor1.motorSpeed,this.maxMotorForce1=this.limitMotor1.maxMotorForce,this.enableMotor1=this.maxMotorForce1>0,this.lowerLimit2=this.limitMotor2.lowerLimit,this.upperLimit2=this.limitMotor2.upperLimit,this.motorSpeed2=this.limitMotor2.motorSpeed,this.maxMotorForce2=this.limitMotor2.maxMotorForce,this.enableMotor2=this.maxMotorForce2>0,this.lowerLimit3=this.limitMotor3.lowerLimit,this.upperLimit3=this.limitMotor3.upperLimit,this.motorSpeed3=this.limitMotor3.motorSpeed,this.maxMotorForce3=this.limitMotor3.maxMotorForce,this.enableMotor3=this.maxMotorForce3>0,this.m1=this.b1.inverseMass,this.m2=this.b2.inverseMass;var i=this.i1.elements,r=this.i2.elements;this.i1e00=i[0],this.i1e01=i[1],this.i1e02=i[2],this.i1e10=i[3],this.i1e11=i[4],this.i1e12=i[5],this.i1e20=i[6],this.i1e21=i[7],this.i1e22=i[8],this.i2e00=r[0],this.i2e01=r[1],this.i2e02=r[2],this.i2e10=r[3],this.i2e11=r[4],this.i2e12=r[5],this.i2e20=r[6],this.i2e21=r[7],this.i2e22=r[8];var n=this.p2.x-this.p1.x,o=this.p2.y-this.p1.y,s=this.p2.z-this.p1.z,a=n*this.ax1+o*this.ay1+s*this.az1,l=n*this.ax2+o*this.ay2+s*this.az2,h=n*this.ax3+o*this.ay3+s*this.az3,u=this.limitMotor1.frequency,c=this.limitMotor2.frequency,f=this.limitMotor3.frequency,p=u>0,d=c>0,m=f>0,g=this.lowerLimit1<=this.upperLimit1,v=this.lowerLimit2<=this.upperLimit2,_=this.lowerLimit3<=this.upperLimit3;(p&&a>20||a<-20)&&(p=!1),(d&&l>20||l<-20)&&(d=!1),(m&&h>20||h<-20)&&(m=!1),g?(this.lowerLimit1==this.upperLimit1?(0!=this.limitState1&&(this.limitState1=0,this.limitImpulse1=0),this.limitVelocity1=this.lowerLimit1-a,p||(a=this.lowerLimit1)):a<this.lowerLimit1?(-1!=this.limitState1&&(this.limitState1=-1,this.limitImpulse1=0),this.limitVelocity1=this.lowerLimit1-a,p||(a=this.lowerLimit1)):a>this.upperLimit1?(1!=this.limitState1&&(this.limitState1=1,this.limitImpulse1=0),this.limitVelocity1=this.upperLimit1-a,p||(a=this.upperLimit1)):(this.limitState1=2,this.limitImpulse1=0,this.limitVelocity1=0),p||(this.limitVelocity1>.005?this.limitVelocity1-=.005:this.limitVelocity1<-.005?this.limitVelocity1+=.005:this.limitVelocity1=0)):(this.limitState1=2,this.limitImpulse1=0),v?(this.lowerLimit2==this.upperLimit2?(0!=this.limitState2&&(this.limitState2=0,this.limitImpulse2=0),this.limitVelocity2=this.lowerLimit2-l,d||(l=this.lowerLimit2)):l<this.lowerLimit2?(-1!=this.limitState2&&(this.limitState2=-1,this.limitImpulse2=0),this.limitVelocity2=this.lowerLimit2-l,d||(l=this.lowerLimit2)):l>this.upperLimit2?(1!=this.limitState2&&(this.limitState2=1,this.limitImpulse2=0),this.limitVelocity2=this.upperLimit2-l,d||(l=this.upperLimit2)):(this.limitState2=2,this.limitImpulse2=0,this.limitVelocity2=0),d||(this.limitVelocity2>.005?this.limitVelocity2-=.005:this.limitVelocity2<-.005?this.limitVelocity2+=.005:this.limitVelocity2=0)):(this.limitState2=2,this.limitImpulse2=0),_?(this.lowerLimit3==this.upperLimit3?(0!=this.limitState3&&(this.limitState3=0,this.limitImpulse3=0),this.limitVelocity3=this.lowerLimit3-h,m||(h=this.lowerLimit3)):h<this.lowerLimit3?(-1!=this.limitState3&&(this.limitState3=-1,this.limitImpulse3=0),this.limitVelocity3=this.lowerLimit3-h,m||(h=this.lowerLimit3)):h>this.upperLimit3?(1!=this.limitState3&&(this.limitState3=1,this.limitImpulse3=0),this.limitVelocity3=this.upperLimit3-h,m||(h=this.upperLimit3)):(this.limitState3=2,this.limitImpulse3=0,this.limitVelocity3=0),m||(this.limitVelocity3>.005?this.limitVelocity3-=.005:this.limitVelocity3<-.005?this.limitVelocity3+=.005:this.limitVelocity3=0)):(this.limitState3=2,this.limitImpulse3=0),this.enableMotor1&&(0!=this.limitState1||p)?this.maxMotorImpulse1=this.maxMotorForce1*e:(this.motorImpulse1=0,this.maxMotorImpulse1=0),this.enableMotor2&&(0!=this.limitState2||d)?this.maxMotorImpulse2=this.maxMotorForce2*e:(this.motorImpulse2=0,this.maxMotorImpulse2=0),this.enableMotor3&&(0!=this.limitState3||m)?this.maxMotorImpulse3=this.maxMotorForce3*e:(this.motorImpulse3=0,this.maxMotorImpulse3=0);var y=a*this.ax1+l*this.ax2+h*this.ax2,x=a*this.ay1+l*this.ay2+h*this.ay2,b=a*this.az1+l*this.az2+h*this.az2,T=this.m2/(this.m1+this.m2);this.weight>=0&&(T=this.weight);var E=1-T;this.r1x=this.r1.x+y*T,this.r1y=this.r1.y+x*T,this.r1z=this.r1.z+b*T,this.r2x=this.r2.x-y*E,this.r2y=this.r2.y-x*E,this.r2z=this.r2.z-b*E,this.t1x1=this.r1y*this.az1-this.r1z*this.ay1,this.t1y1=this.r1z*this.ax1-this.r1x*this.az1,this.t1z1=this.r1x*this.ay1-this.r1y*this.ax1,this.t2x1=this.r2y*this.az1-this.r2z*this.ay1,this.t2y1=this.r2z*this.ax1-this.r2x*this.az1,this.t2z1=this.r2x*this.ay1-this.r2y*this.ax1,this.l1x1=this.ax1*this.m1,this.l1y1=this.ay1*this.m1,this.l1z1=this.az1*this.m1,this.l2x1=this.ax1*this.m2,this.l2y1=this.ay1*this.m2,this.l2z1=this.az1*this.m2,this.a1x1=this.t1x1*this.i1e00+this.t1y1*this.i1e01+this.t1z1*this.i1e02,this.a1y1=this.t1x1*this.i1e10+this.t1y1*this.i1e11+this.t1z1*this.i1e12,this.a1z1=this.t1x1*this.i1e20+this.t1y1*this.i1e21+this.t1z1*this.i1e22,this.a2x1=this.t2x1*this.i2e00+this.t2y1*this.i2e01+this.t2z1*this.i2e02,this.a2y1=this.t2x1*this.i2e10+this.t2y1*this.i2e11+this.t2z1*this.i2e12,this.a2z1=this.t2x1*this.i2e20+this.t2y1*this.i2e21+this.t2z1*this.i2e22,this.t1x2=this.r1y*this.az2-this.r1z*this.ay2,this.t1y2=this.r1z*this.ax2-this.r1x*this.az2,this.t1z2=this.r1x*this.ay2-this.r1y*this.ax2,this.t2x2=this.r2y*this.az2-this.r2z*this.ay2,this.t2y2=this.r2z*this.ax2-this.r2x*this.az2,this.t2z2=this.r2x*this.ay2-this.r2y*this.ax2,this.l1x2=this.ax2*this.m1,this.l1y2=this.ay2*this.m1,this.l1z2=this.az2*this.m1,this.l2x2=this.ax2*this.m2,this.l2y2=this.ay2*this.m2,this.l2z2=this.az2*this.m2,this.a1x2=this.t1x2*this.i1e00+this.t1y2*this.i1e01+this.t1z2*this.i1e02,this.a1y2=this.t1x2*this.i1e10+this.t1y2*this.i1e11+this.t1z2*this.i1e12,this.a1z2=this.t1x2*this.i1e20+this.t1y2*this.i1e21+this.t1z2*this.i1e22,this.a2x2=this.t2x2*this.i2e00+this.t2y2*this.i2e01+this.t2z2*this.i2e02,this.a2y2=this.t2x2*this.i2e10+this.t2y2*this.i2e11+this.t2z2*this.i2e12,this.a2z2=this.t2x2*this.i2e20+this.t2y2*this.i2e21+this.t2z2*this.i2e22,this.t1x3=this.r1y*this.az3-this.r1z*this.ay3,this.t1y3=this.r1z*this.ax3-this.r1x*this.az3,this.t1z3=this.r1x*this.ay3-this.r1y*this.ax3,this.t2x3=this.r2y*this.az3-this.r2z*this.ay3,this.t2y3=this.r2z*this.ax3-this.r2x*this.az3,this.t2z3=this.r2x*this.ay3-this.r2y*this.ax3,this.l1x3=this.ax3*this.m1,this.l1y3=this.ay3*this.m1,this.l1z3=this.az3*this.m1,this.l2x3=this.ax3*this.m2,this.l2y3=this.ay3*this.m2,this.l2z3=this.az3*this.m2,this.a1x3=this.t1x3*this.i1e00+this.t1y3*this.i1e01+this.t1z3*this.i1e02,this.a1y3=this.t1x3*this.i1e10+this.t1y3*this.i1e11+this.t1z3*this.i1e12,this.a1z3=this.t1x3*this.i1e20+this.t1y3*this.i1e21+this.t1z3*this.i1e22,this.a2x3=this.t2x3*this.i2e00+this.t2y3*this.i2e01+this.t2z3*this.i2e02,this.a2y3=this.t2x3*this.i2e10+this.t2y3*this.i2e11+this.t2z3*this.i2e12,this.a2z3=this.t2x3*this.i2e20+this.t2y3*this.i2e21+this.t2z3*this.i2e22;var A=this.m1+this.m2;if(this.k00=(this.ax1*this.ax1+this.ay1*this.ay1+this.az1*this.az1)*A,this.k01=(this.ax1*this.ax2+this.ay1*this.ay2+this.az1*this.az2)*A,this.k02=(this.ax1*this.ax3+this.ay1*this.ay3+this.az1*this.az3)*A,this.k10=(this.ax2*this.ax1+this.ay2*this.ay1+this.az2*this.az1)*A,this.k11=(this.ax2*this.ax2+this.ay2*this.ay2+this.az2*this.az2)*A,this.k12=(this.ax2*this.ax3+this.ay2*this.ay3+this.az2*this.az3)*A,this.k20=(this.ax3*this.ax1+this.ay3*this.ay1+this.az3*this.az1)*A,this.k21=(this.ax3*this.ax2+this.ay3*this.ay2+this.az3*this.az2)*A,this.k22=(this.ax3*this.ax3+this.ay3*this.ay3+this.az3*this.az3)*A,this.k00+=this.t1x1*this.a1x1+this.t1y1*this.a1y1+this.t1z1*this.a1z1,this.k01+=this.t1x1*this.a1x2+this.t1y1*this.a1y2+this.t1z1*this.a1z2,this.k02+=this.t1x1*this.a1x3+this.t1y1*this.a1y3+this.t1z1*this.a1z3,this.k10+=this.t1x2*this.a1x1+this.t1y2*this.a1y1+this.t1z2*this.a1z1,this.k11+=this.t1x2*this.a1x2+this.t1y2*this.a1y2+this.t1z2*this.a1z2,this.k12+=this.t1x2*this.a1x3+this.t1y2*this.a1y3+this.t1z2*this.a1z3,this.k20+=this.t1x3*this.a1x1+this.t1y3*this.a1y1+this.t1z3*this.a1z1,this.k21+=this.t1x3*this.a1x2+this.t1y3*this.a1y2+this.t1z3*this.a1z2,this.k22+=this.t1x3*this.a1x3+this.t1y3*this.a1y3+this.t1z3*this.a1z3,this.k00+=this.t2x1*this.a2x1+this.t2y1*this.a2y1+this.t2z1*this.a2z1,this.k01+=this.t2x1*this.a2x2+this.t2y1*this.a2y2+this.t2z1*this.a2z2,this.k02+=this.t2x1*this.a2x3+this.t2y1*this.a2y3+this.t2z1*this.a2z3,this.k10+=this.t2x2*this.a2x1+this.t2y2*this.a2y1+this.t2z2*this.a2z1,this.k11+=this.t2x2*this.a2x2+this.t2y2*this.a2y2+this.t2z2*this.a2z2,this.k12+=this.t2x2*this.a2x3+this.t2y2*this.a2y3+this.t2z2*this.a2z3,this.k20+=this.t2x3*this.a2x1+this.t2y3*this.a2y1+this.t2z3*this.a2z1,this.k21+=this.t2x3*this.a2x2+this.t2y3*this.a2y2+this.t2z3*this.a2z2,this.k22+=this.t2x3*this.a2x3+this.t2y3*this.a2y3+this.t2z3*this.a2z3,this.kv00=this.k00,this.kv11=this.k11,this.kv22=this.k22,this.dv00=1/this.kv00,this.dv11=1/this.kv11,this.dv22=1/this.kv22,p&&2!=this.limitState1){var P=6.2831853*u,S=P*P*e,M=t/(S+2*this.limitMotor1.dampingRatio*P);this.cfm1=this.kv00*M,this.limitVelocity1*=S*M}else this.cfm1=0,this.limitVelocity1*=.05*t;d&&2!=this.limitState2?(M=t/((S=(P=6.2831853*c)*P*e)+2*this.limitMotor2.dampingRatio*P),this.cfm2=this.kv11*M,this.limitVelocity2*=S*M):(this.cfm2=0,this.limitVelocity2*=.05*t),m&&2!=this.limitState3?(M=t/((S=(P=6.2831853*f)*P*e)+2*this.limitMotor3.dampingRatio*P),this.cfm3=this.kv22*M,this.limitVelocity3*=S*M):(this.cfm3=0,this.limitVelocity3*=.05*t),this.k00+=this.cfm1,this.k11+=this.cfm2,this.k22+=this.cfm3;var C=1/(this.k00*(this.k11*this.k22-this.k21*this.k12)+this.k10*(this.k21*this.k02-this.k01*this.k22)+this.k20*(this.k01*this.k12-this.k11*this.k02));this.d00=(this.k11*this.k22-this.k12*this.k21)*C,this.d01=(this.k02*this.k21-this.k01*this.k22)*C,this.d02=(this.k01*this.k12-this.k02*this.k11)*C,this.d10=(this.k12*this.k20-this.k10*this.k22)*C,this.d11=(this.k00*this.k22-this.k02*this.k20)*C,this.d12=(this.k02*this.k10-this.k00*this.k12)*C,this.d20=(this.k10*this.k21-this.k11*this.k20)*C,this.d21=(this.k01*this.k20-this.k00*this.k21)*C,this.d22=(this.k00*this.k11-this.k01*this.k10)*C;var R=this.limitImpulse1+this.motorImpulse1,I=this.limitImpulse2+this.motorImpulse2,O=this.limitImpulse3+this.motorImpulse3;this.l1.x+=R*this.l1x1+I*this.l1x2+O*this.l1x3,this.l1.y+=R*this.l1y1+I*this.l1y2+O*this.l1y3,this.l1.z+=R*this.l1z1+I*this.l1z2+O*this.l1z3,this.a1.x+=R*this.a1x1+I*this.a1x2+O*this.a1x3,this.a1.y+=R*this.a1y1+I*this.a1y2+O*this.a1y3,this.a1.z+=R*this.a1z1+I*this.a1z2+O*this.a1z3,this.l2.x-=R*this.l2x1+I*this.l2x2+O*this.l2x3,this.l2.y-=R*this.l2y1+I*this.l2y2+O*this.l2y3,this.l2.z-=R*this.l2z1+I*this.l2z2+O*this.l2z3,this.a2.x-=R*this.a2x1+I*this.a2x2+O*this.a2x3,this.a2.y-=R*this.a2y1+I*this.a2y2+O*this.a2y3,this.a2.z-=R*this.a2z1+I*this.a2z2+O*this.a2z3},solve:function(){var e=this.l2.x-this.l1.x+this.a2.y*this.r2z-this.a2.z*this.r2y-this.a1.y*this.r1z+this.a1.z*this.r1y,t=this.l2.y-this.l1.y+this.a2.z*this.r2x-this.a2.x*this.r2z-this.a1.z*this.r1x+this.a1.x*this.r1z,i=this.l2.z-this.l1.z+this.a2.x*this.r2y-this.a2.y*this.r2x-this.a1.x*this.r1y+this.a1.y*this.r1x,r=e*this.ax1+t*this.ay1+i*this.az1,n=e*this.ax2+t*this.ay2+i*this.az2,o=e*this.ax3+t*this.ay3+i*this.az3,s=this.motorImpulse1,a=this.motorImpulse2,l=this.motorImpulse3,h=0,u=0,c=0;this.enableMotor1&&(h=(r-this.motorSpeed1)*this.dv00,this.motorImpulse1+=h,this.motorImpulse1>this.maxMotorImpulse1?this.motorImpulse1=this.maxMotorImpulse1:this.motorImpulse1<-this.maxMotorImpulse1&&(this.motorImpulse1=-this.maxMotorImpulse1),h=this.motorImpulse1-s),this.enableMotor2&&(u=(n-this.motorSpeed2)*this.dv11,this.motorImpulse2+=u,this.motorImpulse2>this.maxMotorImpulse2?this.motorImpulse2=this.maxMotorImpulse2:this.motorImpulse2<-this.maxMotorImpulse2&&(this.motorImpulse2=-this.maxMotorImpulse2),u=this.motorImpulse2-a),this.enableMotor3&&(c=(o-this.motorSpeed3)*this.dv22,this.motorImpulse3+=c,this.motorImpulse3>this.maxMotorImpulse3?this.motorImpulse3=this.maxMotorImpulse3:this.motorImpulse3<-this.maxMotorImpulse3&&(this.motorImpulse3=-this.maxMotorImpulse3),c=this.motorImpulse3-l),r+=h*this.kv00+u*this.k01+c*this.k02,n+=h*this.k10+u*this.kv11+c*this.k12,o+=h*this.k20+u*this.k21+c*this.kv22,r-=this.limitVelocity1+this.limitImpulse1*this.cfm1,n-=this.limitVelocity2+this.limitImpulse2*this.cfm2,o-=this.limitVelocity3+this.limitImpulse3*this.cfm3;var f=this.limitImpulse1,p=this.limitImpulse2,d=this.limitImpulse3,m=r*this.d00+n*this.d01+o*this.d02,g=r*this.d10+n*this.d11+o*this.d12,v=r*this.d20+n*this.d21+o*this.d22;this.limitImpulse1+=m,this.limitImpulse2+=g,this.limitImpulse3+=v;var _=0;(2==this.limitState1||this.limitImpulse1*this.limitState1<0)&&(n+=(m=-f)*this.k10,o+=m*this.k20,_|=1),(2==this.limitState2||this.limitImpulse2*this.limitState2<0)&&(r+=(g=-p)*this.k01,o+=g*this.k21,_|=2),(2==this.limitState3||this.limitImpulse3*this.limitState3<0)&&(r+=(v=-d)*this.k02,n+=v*this.k12,_|=4);var y;switch(_){case 1:y=1/(this.k11*this.k22-this.k12*this.k21),g=(this.k22*n+-this.k12*o)*y,v=(-this.k21*n+this.k11*o)*y;break;case 2:y=1/(this.k00*this.k22-this.k02*this.k20),m=(this.k22*r+-this.k02*o)*y,v=(-this.k20*r+this.k00*o)*y;break;case 3:v=o/this.k22;break;case 4:y=1/(this.k00*this.k11-this.k01*this.k10),m=(this.k11*r+-this.k01*n)*y,g=(-this.k10*r+this.k00*n)*y;break;case 5:g=n/this.k11;break;case 6:m=r/this.k00}this.limitImpulse1=f+m,this.limitImpulse2=p+g,this.limitImpulse3=d+v;var x=h+m,b=u+g,T=c+v;this.l1.x+=x*this.l1x1+b*this.l1x2+T*this.l1x3,this.l1.y+=x*this.l1y1+b*this.l1y2+T*this.l1y3,this.l1.z+=x*this.l1z1+b*this.l1z2+T*this.l1z3,this.a1.x+=x*this.a1x1+b*this.a1x2+T*this.a1x3,this.a1.y+=x*this.a1y1+b*this.a1y2+T*this.a1y3,this.a1.z+=x*this.a1z1+b*this.a1z2+T*this.a1z3,this.l2.x-=x*this.l2x1+b*this.l2x2+T*this.l2x3,this.l2.y-=x*this.l2y1+b*this.l2y2+T*this.l2y3,this.l2.z-=x*this.l2z1+b*this.l2z2+T*this.l2z3,this.a2.x-=x*this.a2x1+b*this.a2x2+T*this.a2x3,this.a2.y-=x*this.a2y1+b*this.a2y2+T*this.a2y3,this.a2.z-=x*this.a2z1+b*this.a2z2+T*this.a2z3}},a.TranslationalConstraint=function(e,t){this.cfm=NaN,this.m1=NaN,this.m2=NaN,this.i1e00=NaN,this.i1e01=NaN,this.i1e02=NaN,this.i1e10=NaN,this.i1e11=NaN,this.i1e12=NaN,this.i1e20=NaN,this.i1e21=NaN,this.i1e22=NaN,this.i2e00=NaN,this.i2e01=NaN,this.i2e02=NaN,this.i2e10=NaN,this.i2e11=NaN,this.i2e12=NaN,this.i2e20=NaN,this.i2e21=NaN,this.i2e22=NaN,this.motorDenom=NaN,this.invMotorDenom=NaN,this.invDenom=NaN,this.ax=NaN,this.ay=NaN,this.az=NaN,this.r1x=NaN,this.r1y=NaN,this.r1z=NaN,this.r2x=NaN,this.r2y=NaN,this.r2z=NaN,this.t1x=NaN,this.t1y=NaN,this.t1z=NaN,this.t2x=NaN,this.t2y=NaN,this.t2z=NaN,this.l1x=NaN,this.l1y=NaN,this.l1z=NaN,this.l2x=NaN,this.l2y=NaN,this.l2z=NaN,this.a1x=NaN,this.a1y=NaN,this.a1z=NaN,this.a2x=NaN,this.a2y=NaN,this.a2z=NaN,this.lowerLimit=NaN,this.upperLimit=NaN,this.limitVelocity=NaN,this.limitState=0,this.enableMotor=!1,this.motorSpeed=NaN,this.maxMotorForce=NaN,this.maxMotorImpulse=NaN,this.limitMotor=t,this.b1=e.body1,this.b2=e.body2,this.p1=e.anchorPoint1,this.p2=e.anchorPoint2,this.r1=e.relativeAnchorPoint1,this.r2=e.relativeAnchorPoint2,this.l1=this.b1.linearVelocity,this.l2=this.b2.linearVelocity,this.a1=this.b1.angularVelocity,this.a2=this.b2.angularVelocity,this.i1=this.b1.inverseInertia,this.i2=this.b2.inverseInertia,this.limitImpulse=0,this.motorImpulse=0},a.TranslationalConstraint.prototype={constructor:a.TranslationalConstraint,preSolve:function(e,t){this.ax=this.limitMotor.axis.x,this.ay=this.limitMotor.axis.y,this.az=this.limitMotor.axis.z,this.lowerLimit=this.limitMotor.lowerLimit,this.upperLimit=this.limitMotor.upperLimit,this.motorSpeed=this.limitMotor.motorSpeed,this.maxMotorForce=this.limitMotor.maxMotorForce,this.enableMotor=this.maxMotorForce>0,this.m1=this.b1.inverseMass,this.m2=this.b2.inverseMass;var i=this.i1.elements,r=this.i2.elements;this.i1e00=i[0],this.i1e01=i[1],this.i1e02=i[2],this.i1e10=i[3],this.i1e11=i[4],this.i1e12=i[5],this.i1e20=i[6],this.i1e21=i[7],this.i1e22=i[8],this.i2e00=r[0],this.i2e01=r[1],this.i2e02=r[2],this.i2e10=r[3],this.i2e11=r[4],this.i2e12=r[5],this.i2e20=r[6],this.i2e21=r[7],this.i2e22=r[8];var n=this.p2.x-this.p1.x,o=this.p2.y-this.p1.y,s=this.p2.z-this.p1.z,a=n*this.ax+o*this.ay+s*this.az,l=this.limitMotor.frequency,h=l>0,u=this.lowerLimit<=this.upperLimit;(h&&a>20||a<-20)&&(h=!1),u?(this.lowerLimit==this.upperLimit?(0!=this.limitState&&(this.limitState=0,this.limitImpulse=0),this.limitVelocity=this.lowerLimit-a,h||(a=this.lowerLimit)):a<this.lowerLimit?(-1!=this.limitState&&(this.limitState=-1,this.limitImpulse=0),this.limitVelocity=this.lowerLimit-a,h||(a=this.lowerLimit)):a>this.upperLimit?(1!=this.limitState&&(this.limitState=1,this.limitImpulse=0),this.limitVelocity=this.upperLimit-a,h||(a=this.upperLimit)):(this.limitState=2,this.limitImpulse=0,this.limitVelocity=0),h||(this.limitVelocity>.005?this.limitVelocity-=.005:this.limitVelocity<-.005?this.limitVelocity+=.005:this.limitVelocity=0)):(this.limitState=2,this.limitImpulse=0),this.enableMotor&&(0!=this.limitState||h)?this.maxMotorImpulse=this.maxMotorForce*e:(this.motorImpulse=0,this.maxMotorImpulse=0);var c=a*this.ax,f=a*this.ay,p=a*this.az,d=this.m1/(this.m1+this.m2),m=1-d;if(this.r1x=this.r1.x+c*d,this.r1y=this.r1.y+f*d,this.r1z=this.r1.z+p*d,this.r2x=this.r2.x-c*m,this.r2y=this.r2.y-f*m,this.r2z=this.r2.z-p*m,this.t1x=this.r1y*this.az-this.r1z*this.ay,this.t1y=this.r1z*this.ax-this.r1x*this.az,this.t1z=this.r1x*this.ay-this.r1y*this.ax,this.t2x=this.r2y*this.az-this.r2z*this.ay,this.t2y=this.r2z*this.ax-this.r2x*this.az,this.t2z=this.r2x*this.ay-this.r2y*this.ax,this.l1x=this.ax*this.m1,this.l1y=this.ay*this.m1,this.l1z=this.az*this.m1,this.l2x=this.ax*this.m2,this.l2y=this.ay*this.m2,this.l2z=this.az*this.m2,this.a1x=this.t1x*this.i1e00+this.t1y*this.i1e01+this.t1z*this.i1e02,this.a1y=this.t1x*this.i1e10+this.t1y*this.i1e11+this.t1z*this.i1e12,this.a1z=this.t1x*this.i1e20+this.t1y*this.i1e21+this.t1z*this.i1e22,this.a2x=this.t2x*this.i2e00+this.t2y*this.i2e01+this.t2z*this.i2e02,this.a2y=this.t2x*this.i2e10+this.t2y*this.i2e11+this.t2z*this.i2e12,this.a2z=this.t2x*this.i2e20+this.t2y*this.i2e21+this.t2z*this.i2e22,this.motorDenom=this.m1+this.m2+this.ax*(this.a1y*this.r1z-this.a1z*this.r1y+this.a2y*this.r2z-this.a2z*this.r2y)+this.ay*(this.a1z*this.r1x-this.a1x*this.r1z+this.a2z*this.r2x-this.a2x*this.r2z)+this.az*(this.a1x*this.r1y-this.a1y*this.r1x+this.a2x*this.r2y-this.a2y*this.r2x),this.invMotorDenom=1/this.motorDenom,h&&2!=this.limitState){var g=6.2831853*l,v=g*g*e,_=t/(v+2*this.limitMotor.dampingRatio*g);this.cfm=this.motorDenom*_,this.limitVelocity*=v*_}else this.cfm=0,this.limitVelocity*=.05*t;this.invDenom=1/(this.motorDenom+this.cfm);var y=this.limitImpulse+this.motorImpulse;this.l1.x+=y*this.l1x,this.l1.y+=y*this.l1y,this.l1.z+=y*this.l1z,this.a1.x+=y*this.a1x,this.a1.y+=y*this.a1y,this.a1.z+=y*this.a1z,this.l2.x-=y*this.l2x,this.l2.y-=y*this.l2y,this.l2.z-=y*this.l2z,this.a2.x-=y*this.a2x,this.a2.y-=y*this.a2y,this.a2.z-=y*this.a2z},solve:function(){var e,t=this.ax*(this.l2.x-this.l1.x)+this.ay*(this.l2.y-this.l1.y)+this.az*(this.l2.z-this.l1.z)+this.t2x*this.a2.x-this.t1x*this.a1.x+this.t2y*this.a2.y-this.t1y*this.a1.y+this.t2z*this.a2.z-this.t1z*this.a1.z;if(this.enableMotor){e=(t-this.motorSpeed)*this.invMotorDenom;var i=this.motorImpulse;this.motorImpulse+=e,this.motorImpulse>this.maxMotorImpulse?this.motorImpulse=this.maxMotorImpulse:this.motorImpulse<-this.maxMotorImpulse&&(this.motorImpulse=-this.maxMotorImpulse),t-=(e=this.motorImpulse-i)*this.motorDenom}else e=0;var r;if(2!=this.limitState){r=(t-this.limitVelocity-this.limitImpulse*this.cfm)*this.invDenom;var n=this.limitImpulse;this.limitImpulse+=r,this.limitImpulse*this.limitState<0&&(this.limitImpulse=0),r=this.limitImpulse-n}else r=0;var o=r+e;this.l1.x+=o*this.l1x,this.l1.y+=o*this.l1y,this.l1.z+=o*this.l1z,this.a1.x+=o*this.a1x,this.a1.y+=o*this.a1y,this.a1.z+=o*this.a1z,this.l2.x-=o*this.l2x,this.l2.y-=o*this.l2y,this.l2.z-=o*this.l2z,this.a2.x-=o*this.a2x,this.a2.y-=o*this.a2y,this.a2.z-=o*this.a2z}},a.Contact=function(){this.shape1=null,this.shape2=null,this.body1=null,this.body2=null,this.prev=null,this.next=null,this.persisting=!1,this.sleeping=!1,this.detector=null,this.constraint=null,this.touching=!1,this.b1Link=new a.ContactLink(this),this.b2Link=new a.ContactLink(this),this.s1Link=new a.ContactLink(this),this.s2Link=new a.ContactLink(this),this.manifold=new a.ContactManifold,this.buffer=[],this.buffer.length=4,this.buffer[0]=new a.ImpulseDataBuffer,this.buffer[1]=new a.ImpulseDataBuffer,this.buffer[2]=new a.ImpulseDataBuffer,this.buffer[3]=new a.ImpulseDataBuffer,this.points=this.manifold.points,this.constraint=new a.ContactConstraint(this.manifold)},a.Contact.prototype={constructor:a.Contact,mixRestitution:function(e,t){return a.sqrt(e*t)},mixFriction:function(e,t){return a.sqrt(e*t)},updateManifold:function(){this.constraint.restitution=this.mixRestitution(this.shape1.restitution,this.shape2.restitution),this.constraint.friction=this.mixFriction(this.shape1.friction,this.shape2.friction);for(var e=this.manifold.numPoints,t=e;t--;){var i=this.buffer[t],r=this.points[t];i.lp1X=r.localPoint1.x,i.lp1Y=r.localPoint1.y,i.lp1Z=r.localPoint1.z,i.lp2X=r.localPoint2.x,i.lp2Y=r.localPoint2.y,i.lp2Z=r.localPoint2.z,i.impulse=r.normalImpulse}this.manifold.numPoints=0,this.detector.detectCollision(this.shape1,this.shape2,this.manifold);var n=this.manifold.numPoints;if(0!=n)for(this.touching=!0,t=n;t--;){for(var o=(r=this.points[t]).localPoint1.x,s=r.localPoint1.y,a=r.localPoint1.z,l=r.localPoint2.x,h=r.localPoint2.y,u=r.localPoint2.z,c=-1,f=4e-4,p=e;p--;){var d=(i=this.buffer[p]).lp1X-o,m=i.lp1Y-s,g=i.lp1Z-a,v=d*d+m*m+g*g,_=(d=i.lp2X-l)*d+(m=i.lp2Y-h)*m+(g=i.lp2Z-u)*g;v<_?v<f&&(f=v,c=p):_<f&&(f=_,c=p)}if(-1!=c){var y=this.buffer[c];this.buffer[c]=this.buffer[--e],this.buffer[e]=y,r.normalImpulse=y.impulse,r.warmStarted=!0}else r.normalImpulse=0,r.warmStarted=!1}else this.touching=!1},attach:function(e,t){this.shape1=e,this.shape2=t,this.body1=e.parent,this.body2=t.parent,this.manifold.body1=this.body1,this.manifold.body2=this.body2,this.constraint.body1=this.body1,this.constraint.body2=this.body2,this.constraint.attach(),this.s1Link.shape=t,this.s1Link.body=this.body2,this.s2Link.shape=e,this.s2Link.body=this.body1,null!=e.contactLink?(this.s1Link.next=e.contactLink).prev=this.s1Link:this.s1Link.next=null,e.contactLink=this.s1Link,e.numContacts++,null!=t.contactLink?(this.s2Link.next=t.contactLink).prev=this.s2Link:this.s2Link.next=null,t.contactLink=this.s2Link,t.numContacts++,this.b1Link.shape=t,this.b1Link.body=this.body2,this.b2Link.shape=e,this.b2Link.body=this.body1,null!=this.body1.contactLink?(this.b1Link.next=this.body1.contactLink).prev=this.b1Link:this.b1Link.next=null,this.body1.contactLink=this.b1Link,this.body1.numContacts++,null!=this.body2.contactLink?(this.b2Link.next=this.body2.contactLink).prev=this.b2Link:this.b2Link.next=null,this.body2.contactLink=this.b2Link,this.body2.numContacts++,this.prev=null,this.next=null,this.persisting=!0,this.sleeping=this.body1.sleeping&&this.body2.sleeping,this.manifold.numPoints=0},detach:function(){var e=this.s1Link.prev,t=this.s1Link.next;null!==e&&(e.next=t),null!==t&&(t.prev=e),this.shape1.contactLink==this.s1Link&&(this.shape1.contactLink=t),this.s1Link.prev=null,this.s1Link.next=null,this.s1Link.shape=null,this.s1Link.body=null,this.shape1.numContacts--,e=this.s2Link.prev,t=this.s2Link.next,null!==e&&(e.next=t),null!==t&&(t.prev=e),this.shape2.contactLink==this.s2Link&&(this.shape2.contactLink=t),this.s2Link.prev=null,this.s2Link.next=null,this.s2Link.shape=null,this.s2Link.body=null,this.shape2.numContacts--,e=this.b1Link.prev,t=this.b1Link.next,null!==e&&(e.next=t),null!==t&&(t.prev=e),this.body1.contactLink==this.b1Link&&(this.body1.contactLink=t),this.b1Link.prev=null,this.b1Link.next=null,this.b1Link.shape=null,this.b1Link.body=null,this.body1.numContacts--,e=this.b2Link.prev,t=this.b2Link.next,null!==e&&(e.next=t),null!==t&&(t.prev=e),this.body2.contactLink==this.b2Link&&(this.body2.contactLink=t),this.b2Link.prev=null,this.b2Link.next=null,this.b2Link.shape=null,this.b2Link.body=null,this.body2.numContacts--,this.manifold.body1=null,this.manifold.body2=null,this.constraint.body1=null,this.constraint.body2=null,this.constraint.detach(),this.shape1=null,this.shape2=null,this.body1=null,this.body2=null}},a.ContactConstraint=function(e){a.Constraint.call(this),this.manifold=e,this.restitution=NaN,this.friction=NaN,this.p1=null,this.p2=null,this.lv1=null,this.lv2=null,this.av1=null,this.av2=null,this.i1=null,this.i2=null,this.ii1=null,this.ii2=null,this.m1=NaN,this.m2=NaN,this.num=0,this.ps=e.points,this.cs=new a.ContactPointDataBuffer,this.cs.next=new a.ContactPointDataBuffer,this.cs.next.next=new a.ContactPointDataBuffer,this.cs.next.next.next=new a.ContactPointDataBuffer},a.ContactConstraint.prototype=Object.create(a.Constraint.prototype),a.ContactConstraint.prototype.attach=function(){this.p1=this.body1.position,this.p2=this.body2.position,this.lv1=this.body1.linearVelocity,this.av1=this.body1.angularVelocity,this.lv2=this.body2.linearVelocity,this.av2=this.body2.angularVelocity,this.i1=this.body1.inverseInertia,this.i2=this.body2.inverseInertia},a.ContactConstraint.prototype.detach=function(){this.p1=null,this.p2=null,this.lv1=null,this.lv2=null,this.av1=null,this.av2=null,this.i1=null,this.i2=null},a.ContactConstraint.prototype.preSolve=function(e,t){this.m1=this.body1.inverseMass,this.m2=this.body2.inverseMass,this.ii1=this.i1.clone(),this.ii2=this.i2.clone();var i=this.ii1.elements,r=this.ii2.elements,n=this.p1.x,o=this.p1.y,s=this.p1.z,l=this.p2.x,h=this.p2.y,u=this.p2.z,c=this.m1+this.m2;this.num=this.manifold.numPoints;for(var f=this.cs,p=0;p<this.num;p++){var d,m,g,v,_,y,x=this.ps[p],b=(d=x.position.x)-n,T=(m=x.position.y)-o,E=(g=x.position.z)-s,A=d-l,P=m-h,S=g-u;f.rp1X=b,f.rp1Y=T,f.rp1Z=E,f.rp2X=A,f.rp2Y=P,f.rp2Z=S,f.norImp=x.normalImpulse,f.tanImp=x.tangentImpulse,f.binImp=x.binormalImpulse;var M=x.normal.x,C=x.normal.y,R=x.normal.z,I=this.lv2.x+this.av2.y*S-this.av2.z*P-(this.lv1.x+this.av1.y*E-this.av1.z*T),O=this.lv2.y+this.av2.z*A-this.av2.x*S-(this.lv1.y+this.av1.z*b-this.av1.x*E),D=this.lv2.z+this.av2.x*P-this.av2.y*A-(this.lv1.z+this.av1.x*T-this.av1.y*b),w=M*I+C*O+R*D,L=I-w*M,F=O-w*C,N=D-w*R,B=L*L+F*F+N*N;B>.04?B=1/a.sqrt(B):(L=C*M-R*R,F=-R*C-M*M,N=M*R+C*C,B=1/a.sqrt(L*L+F*F+N*N));var V=C*(N*=B)-R*(F*=B),U=R*(L*=B)-M*N,z=M*F-C*L;f.norX=M,f.norY=C,f.norZ=R,f.tanX=L,f.tanY=F,f.tanZ=N,f.binX=V,f.binY=U,f.binZ=z,f.norU1X=M*this.m1,f.norU1Y=C*this.m1,f.norU1Z=R*this.m1,f.norU2X=M*this.m2,f.norU2Y=C*this.m2,f.norU2Z=R*this.m2,f.tanU1X=L*this.m1,f.tanU1Y=F*this.m1,f.tanU1Z=N*this.m1,f.tanU2X=L*this.m2,f.tanU2Y=F*this.m2,f.tanU2Z=N*this.m2,f.binU1X=V*this.m1,f.binU1Y=U*this.m1,f.binU1Z=z*this.m1,f.binU2X=V*this.m2,f.binU2Y=U*this.m2,f.binU2Z=z*this.m2;var k=T*R-E*C,G=E*M-b*R,H=b*C-T*M,W=P*R-S*C,j=S*M-A*R,X=A*C-P*M,Y=T*N-E*F,K=E*L-b*N,Q=b*F-T*L,Z=P*N-S*F,q=S*L-A*N,J=A*F-P*L,$=T*z-E*U,ee=E*V-b*z,te=b*U-T*V,ie=P*z-S*U,re=S*V-A*z,ne=A*U-P*V,oe=k*i[0]+G*i[1]+H*i[2],se=k*i[3]+G*i[4]+H*i[5],ae=k*i[6]+G*i[7]+H*i[8],le=W*r[0]+j*r[1]+X*r[2],he=W*r[3]+j*r[4]+X*r[5],ue=W*r[6]+j*r[7]+X*r[8],ce=Y*i[0]+K*i[1]+Q*i[2],fe=Y*i[3]+K*i[4]+Q*i[5],pe=Y*i[6]+K*i[7]+Q*i[8],de=Z*r[0]+q*r[1]+J*r[2],me=Z*r[3]+q*r[4]+J*r[5],ge=Z*r[6]+q*r[7]+J*r[8],ve=$*i[0]+ee*i[1]+te*i[2],_e=$*i[3]+ee*i[4]+te*i[5],ye=$*i[6]+ee*i[7]+te*i[8],xe=ie*r[0]+re*r[1]+ne*r[2],be=ie*r[3]+re*r[4]+ne*r[5],Te=ie*r[6]+re*r[7]+ne*r[8];f.norT1X=k,f.norT1Y=G,f.norT1Z=H,f.tanT1X=Y,f.tanT1Y=K,f.tanT1Z=Q,f.binT1X=$,f.binT1Y=ee,f.binT1Z=te,f.norT2X=W,f.norT2Y=j,f.norT2Z=X,f.tanT2X=Z,f.tanT2Y=q,f.tanT2Z=J,f.binT2X=ie,f.binT2Y=re,f.binT2Z=ne,f.norTU1X=oe,f.norTU1Y=se,f.norTU1Z=ae,f.tanTU1X=ce,f.tanTU1Y=fe,f.tanTU1Z=pe,f.binTU1X=ve,f.binTU1Y=_e,f.binTU1Z=ye,f.norTU2X=le,f.norTU2Y=he,f.norTU2Z=ue,f.tanTU2X=de,f.tanTU2Y=me,f.tanTU2Z=ge,f.binTU2X=xe,f.binTU2Y=be,f.binTU2Z=Te,d=k*i[0]+G*i[1]+H*i[2],v=(m=k*i[3]+G*i[4]+H*i[5])*E-(g=k*i[6]+G*i[7]+H*i[8])*T,_=g*b-d*E,y=d*T-m*b,d=W*r[0]+j*r[1]+X*r[2];var Ee=1/(c+M*(v+=(m=W*r[3]+j*r[4]+X*r[5])*S-(g=W*r[6]+j*r[7]+X*r[8])*P)+C*(_+=g*A-d*S)+R*(y+=d*P-m*A));d=Y*i[0]+K*i[1]+Q*i[2],v=(m=Y*i[3]+K*i[4]+Q*i[5])*E-(g=Y*i[6]+K*i[7]+Q*i[8])*T,_=g*b-d*E,y=d*T-m*b,d=Z*r[0]+q*r[1]+J*r[2];var Ae=1/(c+L*(v+=(m=Z*r[3]+q*r[4]+J*r[5])*S-(g=Z*r[6]+q*r[7]+J*r[8])*P)+F*(_+=g*A-d*S)+N*(y+=d*P-m*A));d=$*i[0]+ee*i[1]+te*i[2],v=(m=$*i[3]+ee*i[4]+te*i[5])*E-(g=$*i[6]+ee*i[7]+te*i[8])*T,_=g*b-d*E,y=d*T-m*b,d=ie*r[0]+re*r[1]+ne*r[2];var Pe=1/(c+V*(v+=(m=ie*r[3]+re*r[4]+ne*r[5])*S-(g=ie*r[6]+re*r[7]+ne*r[8])*P)+U*(_+=g*A-d*S)+z*(y+=d*P-m*A));if(f.norDen=Ee,f.tanDen=Ae,f.binDen=Pe,x.warmStarted){var Se=x.normalImpulse;this.lv1.x+=f.norU1X*Se,this.lv1.y+=f.norU1Y*Se,this.lv1.z+=f.norU1Z*Se,this.av1.x+=oe*Se,this.av1.y+=se*Se,this.av1.z+=ae*Se,this.lv2.x-=f.norU2X*Se,this.lv2.y-=f.norU2Y*Se,this.lv2.z-=f.norU2Z*Se,this.av2.x-=le*Se,this.av2.y-=he*Se,this.av2.z-=ue*Se,f.norImp=Se,f.tanImp=0,f.binImp=0,w=0}else f.norImp=0,f.tanImp=0,f.binImp=0;w>-1&&(w=0);var Me=this.restitution*-w,Ce=-(x.penetration+.005)*t*.05;Me<Ce&&(Me=Ce),f.norTar=Me,f.last=p==this.num-1,f=f.next}},a.ContactConstraint.prototype.solve=function(){for(var e=this.lv1.x,t=this.lv1.y,i=this.lv1.z,r=this.lv2.x,n=this.lv2.y,o=this.lv2.z,s=this.av1.x,l=this.av1.y,h=this.av1.z,u=this.av2.x,c=this.av2.y,f=this.av2.z,p=this.cs;;){var d,m,g,v,_,y=p.norImp,x=p.tanImp,b=p.binImp,T=-y*this.friction,E=r-e,A=n-t,P=o-i;d=x,g=b;var S=(x+=m=(_=E*p.tanX+A*p.tanY+P*p.tanZ+u*p.tanT2X+c*p.tanT2Y+f*p.tanT2Z-s*p.tanT1X-l*p.tanT1Y-h*p.tanT1Z)*p.tanDen)*x+(b+=v=(_=E*p.binX+A*p.binY+P*p.binZ+u*p.binT2X+c*p.binT2Y+f*p.binT2Z-s*p.binT1X-l*p.binT1Y-h*p.binT1Z)*p.binDen)*b;if(S>T*T&&(x*=S=T/a.sqrt(S),b*=S),m=x-d,v=b-g,e+=p.tanU1X*m+p.binU1X*v,t+=p.tanU1Y*m+p.binU1Y*v,i+=p.tanU1Z*m+p.binU1Z*v,s+=p.tanTU1X*m+p.binTU1X*v,l+=p.tanTU1Y*m+p.binTU1Y*v,h+=p.tanTU1Z*m+p.binTU1Z*v,r-=p.tanU2X*m+p.binU2X*v,n-=p.tanU2Y*m+p.binU2Y*v,o-=p.tanU2Z*m+p.binU2Z*v,u-=p.tanTU2X*m+p.binTU2X*v,c-=p.tanTU2Y*m+p.binTU2Y*v,f-=p.tanTU2Z*m+p.binTU2Z*v,_=(r-e)*p.norX+(n-t)*p.norY+(o-i)*p.norZ+u*p.norT2X+c*p.norT2Y+f*p.norT2Z-s*p.norT1X-l*p.norT1Y-h*p.norT1Z,d=y,m=(_-p.norTar)*p.norDen,(y+=m)>0&&(y=0),m=y-d,e+=p.norU1X*m,t+=p.norU1Y*m,i+=p.norU1Z*m,s+=p.norTU1X*m,l+=p.norTU1Y*m,h+=p.norTU1Z*m,r-=p.norU2X*m,n-=p.norU2Y*m,o-=p.norU2Z*m,u-=p.norTU2X*m,c-=p.norTU2Y*m,f-=p.norTU2Z*m,p.norImp=y,p.tanImp=x,p.binImp=b,p.last)break;p=p.next}this.lv1.x=e,this.lv1.y=t,this.lv1.z=i,this.lv2.x=r,this.lv2.y=n,this.lv2.z=o,this.av1.x=s,this.av1.y=l,this.av1.z=h,this.av2.x=u,this.av2.y=c,this.av2.z=f},a.ContactConstraint.prototype.postSolve=function(){for(var e=this.cs,t=this.num;t--;){var i=this.ps[t];i.normal.x=e.norX,i.normal.y=e.norY,i.normal.z=e.norZ,i.tangent.x=e.tanX,i.tangent.y=e.tanY,i.tangent.z=e.tanZ,i.binormal.x=e.binX,i.binormal.y=e.binY,i.binormal.z=e.binZ,i.normalImpulse=e.norImp,i.tangentImpulse=e.tanImp,i.binormalImpulse=e.binImp,i.normalDenominator=e.norDen,i.tangentDenominator=e.tanDen,i.binormalDenominator=e.binDen,e=e.next}},a.ContactLink=function(e){this.prev=null,this.next=null,this.shape=null,this.body=null,this.contact=e},a.ContactManifold=function(){this.body1=null,this.body2=null,this.numPoints=0,this.points=[],this.points.length=4,this.points[0]=new a.ManifoldPoint,this.points[1]=new a.ManifoldPoint,this.points[2]=new a.ManifoldPoint,this.points[3]=new a.ManifoldPoint},a.ContactManifold.prototype={constructor:a.ContactManifold,reset:function(e,t){this.body1=e.parent,this.body2=t.parent,this.numPoints=0},addPoint:function(e,t,i,r,n,o,s,a){var l=this.points[this.numPoints++];l.position.x=e,l.position.y=t,l.position.z=i;var h=this.body1.rotation,u=e-this.body1.position.x,c=t-this.body1.position.y,f=i-this.body1.position.z,p=h.elements;l.localPoint1.x=u*p[0]+c*p[3]+f*p[6],l.localPoint1.y=u*p[1]+c*p[4]+f*p[7],l.localPoint1.z=u*p[2]+c*p[5]+f*p[8],h=this.body2.rotation,u=e-this.body2.position.x,c=t-this.body2.position.y,f=i-this.body2.position.z,l.localPoint2.x=u*p[0]+c*p[3]+f*p[6],l.localPoint2.y=u*p[1]+c*p[4]+f*p[7],l.localPoint2.z=u*p[2]+c*p[5]+f*p[8],l.normalImpulse=0,a?(l.normal.x=-r,l.normal.y=-n,l.normal.z=-o):(l.normal.x=r,l.normal.y=n,l.normal.z=o),l.penetration=s,l.warmStarted=!1}},a.ContactPointDataBuffer=function(){this.norX=NaN,this.norY=NaN,this.norZ=NaN,this.tanX=NaN,this.tanY=NaN,this.tanZ=NaN,this.binX=NaN,this.binY=NaN,this.binZ=NaN,this.rp1X=NaN,this.rp1Y=NaN,this.rp1Z=NaN,this.rp2X=NaN,this.rp2Y=NaN,this.rp2Z=NaN,this.norU1X=NaN,this.norU1Y=NaN,this.norU1Z=NaN,this.norU2X=NaN,this.norU2Y=NaN,this.norU2Z=NaN,this.tanU1X=NaN,this.tanU1Y=NaN,this.tanU1Z=NaN,this.tanU2X=NaN,this.tanU2Y=NaN,this.tanU2Z=NaN,this.binU1X=NaN,this.binU1Y=NaN,this.binU1Z=NaN,this.binU2X=NaN,this.binU2Y=NaN,this.binU2Z=NaN,this.norT1X=NaN,this.norT1Y=NaN,this.norT1Z=NaN,this.norT2X=NaN,this.norT2Y=NaN,this.norT2Z=NaN,this.tanT1X=NaN,this.tanT1Y=NaN,this.tanT1Z=NaN,this.tanT2X=NaN,this.tanT2Y=NaN,this.tanT2Z=NaN,this.binT1X=NaN,this.binT1Y=NaN,this.binT1Z=NaN,this.binT2X=NaN,this.binT2Y=NaN,this.binT2Z=NaN,this.norTU1X=NaN,this.norTU1Y=NaN,this.norTU1Z=NaN,this.norTU2X=NaN,this.norTU2Y=NaN,this.norTU2Z=NaN,this.tanTU1X=NaN,this.tanTU1Y=NaN,this.tanTU1Z=NaN,this.tanTU2X=NaN,this.tanTU2Y=NaN,this.tanTU2Z=NaN,this.binTU1X=NaN,this.binTU1Y=NaN,this.binTU1Z=NaN,this.binTU2X=NaN,this.binTU2Y=NaN,this.binTU2Z=NaN,this.norImp=NaN,this.tanImp=NaN,this.binImp=NaN,this.norDen=NaN,this.tanDen=NaN,this.binDen=NaN,this.norTar=NaN,this.next=null,this.last=!1},a.ImpulseDataBuffer=function(){this.lp1X=NaN,this.lp1Y=NaN,this.lp1Z=NaN,this.lp2X=NaN,this.lp2Y=NaN,this.lp2Z=NaN,this.impulse=NaN},a.ManifoldPoint=function(){this.warmStarted=!1,this.position=new a.Vec3,this.localPoint1=new a.Vec3,this.localPoint2=new a.Vec3,this.normal=new a.Vec3,this.tangent=new a.Vec3,this.binormal=new a.Vec3,this.normalImpulse=0,this.tangentImpulse=0,this.binormalImpulse=0,this.normalDenominator=0,this.tangentDenominator=0,this.binormalDenominator=0,this.penetration=0},a.MassInfo=function(){this.mass=0,this.inertia=new a.Mat33},a.Shape=function(e){this.type=a.SHAPE_NULL,this.id=a.nextID++,this.prev=null,this.next=null,this.proxy=null,this.parent=null,this.contactLink=null,this.numContacts=0,this.position=new a.Vec3,this.rotation=new a.Mat33,this.relativePosition=(new a.Vec3).copy(e.relativePosition),this.relativeRotation=(new a.Mat33).copy(e.relativeRotation),this.aabb=new a.AABB,this.density=e.density,this.friction=e.friction,this.restitution=e.restitution,this.belongsTo=e.belongsTo,this.collidesWith=e.collidesWith},a.Shape.prototype={constructor:a.Shape,calculateMassInfo:function(e){a.Error("Shape","Inheritance error.")},updateProxy:function(){a.Error("Shape","Inheritance error.")}},a.ShapeConfig=function(){this.relativePosition=new a.Vec3,this.relativeRotation=new a.Mat33,this.friction=.4,this.restitution=.2,this.density=1,this.belongsTo=1,this.collidesWith=4294967295},a.BoxShape=function(e,t,i,r){a.Shape.call(this,e),this.type=a.SHAPE_BOX,this.width=t,this.height=i,this.depth=r,this.halfWidth=.5*t,this.halfHeight=.5*i,this.halfDepth=.5*r,this.dimentions=new s(18),this.elements=new s(24)},a.BoxShape.prototype=Object.create(a.Shape.prototype),a.BoxShape.prototype.constructor=a.BoxShape,a.BoxShape.prototype.calculateMassInfo=function(e){var t=this.width*this.height*this.depth*this.density;e.mass=t,e.inertia.set(t*(this.height*this.height+this.depth*this.depth)*(1/12),0,0,0,t*(this.width*this.width+this.depth*this.depth)*(1/12),0,0,0,t*(this.width*this.width+this.height*this.height)*(1/12))},a.BoxShape.prototype.updateProxy=function(){var e=this.rotation.elements,t=this.dimentions;t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],t[9]=e[0]*this.halfWidth,t[10]=e[3]*this.halfWidth,t[11]=e[6]*this.halfWidth,t[12]=e[1]*this.halfHeight,t[13]=e[4]*this.halfHeight,t[14]=e[7]*this.halfHeight,t[15]=e[2]*this.halfDepth,t[16]=e[5]*this.halfDepth,t[17]=e[8]*this.halfDepth;var i=t[9],r=t[10],n=t[11],o=t[12],s=t[13],l=t[14],h=t[15],u=t[16],c=t[17],f=this.position.x,p=this.position.y,d=this.position.z,m=this.elements;m[0]=f+i+o+h,m[1]=p+r+s+u,m[2]=d+n+l+c,m[3]=f+i+o-h,m[4]=p+r+s-u,m[5]=d+n+l-c,m[6]=f+i-o+h,m[7]=p+r-s+u,m[8]=d+n-l+c,m[9]=f+i-o-h,m[10]=p+r-s-u,m[11]=d+n-l-c,m[12]=f-i+o+h,m[13]=p-r+s+u,m[14]=d-n+l+c,m[15]=f-i+o-h,m[16]=p-r+s-u,m[17]=d-n+l-c,m[18]=f-i-o+h,m[19]=p-r-s+u,m[20]=d-n-l+c,m[21]=f-i-o-h,m[22]=p-r-s-u,m[23]=d-n-l-c;var g=t[9]<0?-t[9]:t[9],v=t[10]<0?-t[10]:t[10],_=t[11]<0?-t[11]:t[11];g=t[12]<0?g-t[12]:g+t[12],v=t[13]<0?v-t[13]:v+t[13],_=t[14]<0?_-t[14]:_+t[14],g=t[15]<0?g-t[15]:g+t[15],v=t[16]<0?v-t[16]:v+t[16],_=t[17]<0?_-t[17]:_+t[17];var y=a.AABB_PROX;this.aabb.set(this.position.x-g-y,this.position.x+g+y,this.position.y-v-y,this.position.y+v+y,this.position.z-_-y,this.position.z+_+y),null!=this.proxy&&this.proxy.update()},a.SphereShape=function(e,t){a.Shape.call(this,e),this.type=a.SHAPE_SPHERE,this.radius=t},a.SphereShape.prototype=Object.create(a.Shape.prototype),a.SphereShape.prototype.constructor=a.SphereShape,a.SphereShape.prototype.calculateMassInfo=function(e){var t=1.333*a.PI*this.radius*this.radius*this.radius*this.density;e.mass=t;var i=t*this.radius*this.radius*.4;e.inertia.set(i,0,0,0,i,0,0,0,i)},a.SphereShape.prototype.updateProxy=function(){var e=a.AABB_PROX;this.aabb.set(this.position.x-this.radius-e,this.position.x+this.radius+e,this.position.y-this.radius-e,this.position.y+this.radius+e,this.position.z-this.radius-e,this.position.z+this.radius+e),null!=this.proxy&&this.proxy.update()},a.CylinderShape=function(e,t,i){a.Shape.call(this,e),this.type=a.SHAPE_CYLINDER,this.radius=t,this.height=i,this.halfHeight=.5*i,this.normalDirection=new a.Vec3,this.halfDirection=new a.Vec3},a.CylinderShape.prototype=Object.create(a.Shape.prototype),a.CylinderShape.prototype.constructor=a.CylinderShape,a.CylinderShape.prototype.calculateMassInfo=function(e){var t=this.radius*this.radius,i=a.PI*t*this.height*this.density,r=(.25*t+.0833*this.height*this.height)*i,n=.5*t;e.mass=i,e.inertia.set(r,0,0,0,n,0,0,0,r)},a.CylinderShape.prototype.updateProxy=function(){var e,t,i,r,n,o,s,l,h,u,c,f=this.rotation.elements;n=f[1]*f[1],o=f[4]*f[4],s=f[7]*f[7],this.normalDirection.set(f[1],f[4],f[7]),this.halfDirection.scale(this.normalDirection,this.halfHeight),t=1-n,(e=a.sqrt(t*t+n*o+n*s))>0&&(e=this.radius/e),t*=e,i=1-o,(e=a.sqrt(o*n+i*i+o*s))>0&&(e=this.radius/e),i*=e,r=1-s,(e=a.sqrt(s*n+s*o+r*r))>0&&(e=this.radius/e),r*=e,l=this.halfDirection.x<0?-this.halfDirection.x:this.halfDirection.x,h=this.halfDirection.y<0?-this.halfDirection.y:this.halfDirection.y,u=this.halfDirection.z<0?-this.halfDirection.z:this.halfDirection.z,l=t<0?l-t:l+t,h=i<0?h-i:h+i,u=r<0?u-r:u+r,c=a.AABB_PROX,this.aabb.set(this.position.x-l-c,this.position.x+l+c,this.position.y-h-c,this.position.y+h+c,this.position.z-u-c,this.position.z+u+c),null!=this.proxy&&this.proxy.update()},a.TetraShape=function(e,t,i,n,o){a.Shape.call(this,e),this.type=a.SHAPE_TETRA,this.verts=[t,i,n,o],this.faces=[r(0,1,2),r(1,2,3),r(2,3,4),r(4,0,1)]},a.TetraShape.prototype=Object.create(a.Shape.prototype),a.TetraShape.prototype.constructor=a.TetraShape,a.TetraShape.prototype.calculateMassInfo=function(){},a.TetraShape.prototype.updateProxy=function(){this.aabb.setFromPoints(this.verts),null!==this.proxy&&this.proxy.update()},a.CollisionDetector=function(){this.flip=!1},a.CollisionDetector.prototype={constructor:a.CollisionDetector,detectCollision:function(e,t,i){a.Error("CollisionDetector","Inheritance error.")}},a.BoxBoxCollisionDetector=function(){a.CollisionDetector.call(this),this.clipVertices1=new s(24),this.clipVertices2=new s(24),this.used=new s(8),this.INF=1/0},a.BoxBoxCollisionDetector.prototype=Object.create(a.CollisionDetector.prototype),a.BoxBoxCollisionDetector.prototype.constructor=a.BoxBoxCollisionDetector,a.BoxBoxCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n;e.id<t.id?(r=e,n=t):(r=t,n=e);var o,s,l,h,u,c,f,p,d,m,g,v,_,y,x,b,T,E,A,P,S,M,C,R,I,O,D,w,L,F,N,B,V,U,z,k,G=r.elements,H=n.elements,W=r.dimentions,j=n.dimentions,X=r.position,Y=n.position,K=X.x,Q=X.y,Z=X.z,q=Y.x,J=Y.y,$=Y.z,ee=q-K,te=J-Q,ie=$-Z,re=r.halfWidth,ne=r.halfHeight,oe=r.halfDepth,se=n.halfWidth,ae=n.halfHeight,le=n.halfDepth,he=W[0],ue=W[1],ce=W[2],fe=W[3],pe=W[4],de=W[5],me=W[6],ge=W[7],ve=W[8],_e=W[9],ye=W[10],xe=W[11],be=W[12],Te=W[13],Ee=W[14],Ae=W[15],Pe=W[16],Se=W[17],Me=j[0],Ce=j[1],Re=j[2],Ie=j[3],Oe=j[4],De=j[5],we=j[6],Le=j[7],Fe=j[8],Ne=j[9],Be=j[10],Ve=j[11],Ue=j[12],ze=j[13],ke=j[14],Ge=j[15],He=j[16],We=j[17],je=ue*Re-ce*Ce,Xe=ce*Me-he*Re,Ye=he*Ce-ue*Me,Ke=ue*De-ce*Oe,Qe=ce*Ie-he*De,Ze=he*Oe-ue*Ie,qe=ue*Fe-ce*Le,Je=ce*we-he*Fe,$e=he*Le-ue*we,et=pe*Re-de*Ce,tt=de*Me-fe*Re,it=fe*Ce-pe*Me,rt=pe*De-de*Oe,nt=de*Ie-fe*De,ot=fe*Oe-pe*Ie,st=pe*Fe-de*Le,at=de*we-fe*Fe,lt=fe*Le-pe*we,ht=ge*Re-ve*Ce,ut=ve*Me-me*Re,ct=me*Ce-ge*Me,ft=ge*De-ve*Oe,pt=ve*Ie-me*De,dt=me*Oe-ge*Ie,mt=ge*Fe-ve*Le,gt=ve*we-me*Fe,vt=me*Le-ge*we,_t=!1,yt=!1,xt=!1,bt=!1,Tt=!1,Et=!1,At=!1,Pt=!1,St=!1;if(N=he*ee+ue*te+ce*ie,(o=N>0)||(N=-N),B=re,U=he*Me+ue*Ce+ce*Re,z=he*Ie+ue*Oe+ce*De,k=he*we+ue*Le+ce*Fe,U<0&&(U=-U),z<0&&(z=-z),k<0&&(k=-k),V=U*se+z*ae+k*le,!((b=N-B-V)>0||(N=fe*ee+pe*te+de*ie,(s=N>0)||(N=-N),B=ne,U=fe*Me+pe*Ce+de*Re,z=fe*Ie+pe*Oe+de*De,k=fe*we+pe*Le+de*Fe,U<0&&(U=-U),z<0&&(z=-z),k<0&&(k=-k),V=U*se+z*ae+k*le,(T=N-B-V)>0||(N=me*ee+ge*te+ve*ie,(l=N>0)||(N=-N),B=oe,U=me*Me+ge*Ce+ve*Re,z=me*Ie+ge*Oe+ve*De,k=me*we+ge*Le+ve*Fe,U<0&&(U=-U),z<0&&(z=-z),k<0&&(k=-k),V=U*se+z*ae+k*le,(E=N-B-V)>0||(N=Me*ee+Ce*te+Re*ie,(h=N>0)||(N=-N),U=Me*he+Ce*ue+Re*ce,z=Me*fe+Ce*pe+Re*de,k=Me*me+Ce*ge+Re*ve,U<0&&(U=-U),z<0&&(z=-z),k<0&&(k=-k),B=U*re+z*ne+k*oe,V=se,(A=1*(N-B-V))>0||(N=Ie*ee+Oe*te+De*ie,(u=N>0)||(N=-N),U=Ie*he+Oe*ue+De*ce,z=Ie*fe+Oe*pe+De*de,k=Ie*me+Oe*ge+De*ve,U<0&&(U=-U),z<0&&(z=-z),k<0&&(k=-k),B=U*re+z*ne+k*oe,V=ae,(P=1*(N-B-V))>0||(N=we*ee+Le*te+Fe*ie,(c=N>0)||(N=-N),U=we*he+Le*ue+Fe*ce,z=we*fe+Le*pe+Fe*de,k=we*me+Le*ge+Fe*ve,U<0&&(U=-U),z<0&&(z=-z),k<0&&(k=-k),B=U*re+z*ne+k*oe,V=le,(S=1*(N-B-V))>0))))))){if((N=je*je+Xe*Xe+Ye*Ye)>1e-5){if(N=1/a.sqrt(N),je*=N,Xe*=N,Ye*=N,N=je*ee+Xe*te+Ye*ie,(f=N>0)||(N=-N),U=je*fe+Xe*pe+Ye*de,z=je*me+Xe*ge+Ye*ve,U<0&&(U=-U),z<0&&(z=-z),B=U*ne+z*oe,U=je*Ie+Xe*Oe+Ye*De,z=je*we+Xe*Le+Ye*Fe,U<0&&(U=-U),z<0&&(z=-z),V=U*ae+z*le,(M=N-B-V)>0)return}else f=!1,M=0,_t=!0;if((N=Ke*Ke+Qe*Qe+Ze*Ze)>1e-5){if(N=1/a.sqrt(N),Ke*=N,Qe*=N,Ze*=N,N=Ke*ee+Qe*te+Ze*ie,(p=N>0)||(N=-N),U=Ke*fe+Qe*pe+Ze*de,z=Ke*me+Qe*ge+Ze*ve,U<0&&(U=-U),z<0&&(z=-z),B=U*ne+z*oe,U=Ke*Me+Qe*Ce+Ze*Re,z=Ke*we+Qe*Le+Ze*Fe,U<0&&(U=-U),z<0&&(z=-z),V=U*se+z*le,(C=N-B-V)>0)return}else p=!1,C=0,yt=!0;if((N=qe*qe+Je*Je+$e*$e)>1e-5){if(N=1/a.sqrt(N),qe*=N,Je*=N,$e*=N,N=qe*ee+Je*te+$e*ie,(d=N>0)||(N=-N),U=qe*fe+Je*pe+$e*de,z=qe*me+Je*ge+$e*ve,U<0&&(U=-U),z<0&&(z=-z),B=U*ne+z*oe,U=qe*Me+Je*Ce+$e*Re,z=qe*Ie+Je*Oe+$e*De,U<0&&(U=-U),z<0&&(z=-z),V=U*se+z*ae,(R=N-B-V)>0)return}else d=!1,R=0,xt=!0;if((N=et*et+tt*tt+it*it)>1e-5){if(N=1/a.sqrt(N),et*=N,tt*=N,it*=N,N=et*ee+tt*te+it*ie,(m=N>0)||(N=-N),U=et*he+tt*ue+it*ce,z=et*me+tt*ge+it*ve,U<0&&(U=-U),z<0&&(z=-z),B=U*re+z*oe,U=et*Ie+tt*Oe+it*De,z=et*we+tt*Le+it*Fe,U<0&&(U=-U),z<0&&(z=-z),V=U*ae+z*le,(I=N-B-V)>0)return}else m=!1,I=0,bt=!0;if((N=rt*rt+nt*nt+ot*ot)>1e-5){if(N=1/a.sqrt(N),rt*=N,nt*=N,ot*=N,N=rt*ee+nt*te+ot*ie,(g=N>0)||(N=-N),U=rt*he+nt*ue+ot*ce,z=rt*me+nt*ge+ot*ve,U<0&&(U=-U),z<0&&(z=-z),B=U*re+z*oe,U=rt*Me+nt*Ce+ot*Re,z=rt*we+nt*Le+ot*Fe,U<0&&(U=-U),z<0&&(z=-z),V=U*se+z*le,(O=N-B-V)>0)return}else g=!1,O=0,Tt=!0;if((N=st*st+at*at+lt*lt)>1e-5){if(N=1/a.sqrt(N),st*=N,at*=N,lt*=N,N=st*ee+at*te+lt*ie,(v=N>0)||(N=-N),U=st*he+at*ue+lt*ce,z=st*me+at*ge+lt*ve,U<0&&(U=-U),z<0&&(z=-z),B=U*re+z*oe,U=st*Me+at*Ce+lt*Re,z=st*Ie+at*Oe+lt*De,U<0&&(U=-U),z<0&&(z=-z),V=U*se+z*ae,(D=N-B-V)>0)return}else v=!1,D=0,Et=!0;if((N=ht*ht+ut*ut+ct*ct)>1e-5){if(N=1/a.sqrt(N),ht*=N,ut*=N,ct*=N,N=ht*ee+ut*te+ct*ie,(_=N>0)||(N=-N),U=ht*he+ut*ue+ct*ce,z=ht*fe+ut*pe+ct*de,U<0&&(U=-U),z<0&&(z=-z),B=U*re+z*ne,U=ht*Ie+ut*Oe+ct*De,z=ht*we+ut*Le+ct*Fe,U<0&&(U=-U),z<0&&(z=-z),V=U*ae+z*le,(w=N-B-V)>0)return}else _=!1,w=0,At=!0;if((N=ft*ft+pt*pt+dt*dt)>1e-5){if(N=1/a.sqrt(N),ft*=N,pt*=N,dt*=N,N=ft*ee+pt*te+dt*ie,(y=N>0)||(N=-N),U=ft*he+pt*ue+dt*ce,z=ft*fe+pt*pe+dt*de,U<0&&(U=-U),z<0&&(z=-z),B=U*re+z*ne,U=ft*Me+pt*Ce+dt*Re,z=ft*we+pt*Le+dt*Fe,U<0&&(U=-U),z<0&&(z=-z),V=U*se+z*le,(L=N-B-V)>0)return}else y=!1,L=0,Pt=!0;if((N=mt*mt+gt*gt+vt*vt)>1e-5){if(N=1/a.sqrt(N),mt*=N,gt*=N,vt*=N,N=mt*ee+gt*te+vt*ie,(x=N>0)||(N=-N),U=mt*he+gt*ue+vt*ce,z=mt*fe+gt*pe+vt*de,U<0&&(U=-U),z<0&&(z=-z),B=U*re+z*ne,U=mt*Me+gt*Ce+vt*Re,z=mt*Ie+gt*Oe+vt*De,U<0&&(U=-U),z<0&&(z=-z),V=U*se+z*ae,(F=N-B-V)>0)return}else x=!1,F=0,St=!0;var Mt=b,Ct=b,Rt=0,It=o;T>Ct&&(Mt=T,Ct=T,Rt=1,It=s),E>Ct&&(Mt=E,Ct=E,Rt=2,It=l),A>Ct&&(Mt=A,Ct=A,Rt=3,It=h),P>Ct&&(Mt=P,Ct=P,Rt=4,It=u),S>Ct&&(Mt=S,Ct=S,Rt=5,It=c),M-.01>Ct&&!_t&&(Mt=M,Ct=M-.01,Rt=6,It=f),C-.01>Ct&&!yt&&(Mt=C,Ct=C-.01,Rt=7,It=p),R-.01>Ct&&!xt&&(Mt=R,Ct=R-.01,Rt=8,It=d),I-.01>Ct&&!bt&&(Mt=I,Ct=I-.01,Rt=9,It=m),O-.01>Ct&&!Tt&&(Mt=O,Ct=O-.01,Rt=10,It=g),D-.01>Ct&&!Et&&(Mt=D,Ct=D-.01,Rt=11,It=v),w-.01>Ct&&!At&&(Mt=w,Ct=w-.01,Rt=12,It=_),L-.01>Ct&&!Pt&&(Mt=L,Ct=L-.01,Rt=13,It=y),F-.01>Ct&&!St&&(Mt=F,Rt=14,It=x);var Ot=0,Dt=0,wt=0,Lt=0,Ft=0,Nt=0,Bt=0,Vt=0,Ut=0,zt=0,kt=0,Gt=0,Ht=0,Wt=0,jt=0,Xt=0,Yt=0,Kt=0,Qt=!1;0==Rt?(It?(zt=K+_e,kt=Q+ye,Gt=Z+xe,Ot=he,Dt=ue,wt=ce):(zt=K-_e,kt=Q-ye,Gt=Z-xe,Ot=-he,Dt=-ue,wt=-ce),Ht=be,Wt=Te,jt=Ee,Lt=-fe,Ft=-pe,Nt=-de,Xt=Ae,Yt=Pe,Kt=Se,Bt=-me,Vt=-ge,Ut=-ve):1==Rt?(It?(zt=K+be,kt=Q+Te,Gt=Z+Ee,Ot=fe,Dt=pe,wt=de):(zt=K-be,kt=Q-Te,Gt=Z-Ee,Ot=-fe,Dt=-pe,wt=-de),Ht=_e,Wt=ye,jt=xe,Lt=-he,Ft=-ue,Nt=-ce,Xt=Ae,Yt=Pe,Kt=Se,Bt=-me,Vt=-ge,Ut=-ve):2==Rt?(It?(zt=K+Ae,kt=Q+Pe,Gt=Z+Se,Ot=me,Dt=ge,wt=ve):(zt=K-Ae,kt=Q-Pe,Gt=Z-Se,Ot=-me,Dt=-ge,wt=-ve),Ht=_e,Wt=ye,jt=xe,Lt=-he,Ft=-ue,Nt=-ce,Xt=be,Yt=Te,Kt=Ee,Bt=-fe,Vt=-pe,Ut=-de):3==Rt?(Qt=!0,It?(zt=q-Ne,kt=J-Be,Gt=$-Ve,Ot=-Me,Dt=-Ce,wt=-Re):(zt=q+Ne,kt=J+Be,Gt=$+Ve,Ot=Me,Dt=Ce,wt=Re),Ht=Ue,Wt=ze,jt=ke,Lt=-Ie,Ft=-Oe,Nt=-De,Xt=Ge,Yt=He,Kt=We,Bt=-we,Vt=-Le,Ut=-Fe):4==Rt?(Qt=!0,It?(zt=q-Ue,kt=J-ze,Gt=$-ke,Ot=-Ie,Dt=-Oe,wt=-De):(zt=q+Ue,kt=J+ze,Gt=$+ke,Ot=Ie,Dt=Oe,wt=De),Ht=Ne,Wt=Be,jt=Ve,Lt=-Me,Ft=-Ce,Nt=-Re,Xt=Ge,Yt=He,Kt=We,Bt=-we,Vt=-Le,Ut=-Fe):5==Rt?(Qt=!0,It?(zt=q-Ge,kt=J-He,Gt=$-We,Ot=-we,Dt=-Le,wt=-Fe):(zt=q+Ge,kt=J+He,Gt=$+We,Ot=we,Dt=Le,wt=Fe),Ht=Ne,Wt=Be,jt=Ve,Lt=-Me,Ft=-Ce,Nt=-Re,Xt=Ue,Yt=ze,Kt=ke,Bt=-Ie,Vt=-Oe,Ut=-De):6==Rt?(Ot=je,Dt=Xe,wt=Ye,Lt=he,Ft=ue,Nt=ce,Bt=Me,Vt=Ce,Ut=Re):7==Rt?(Ot=Ke,Dt=Qe,wt=Ze,Lt=he,Ft=ue,Nt=ce,Bt=Ie,Vt=Oe,Ut=De):8==Rt?(Ot=qe,Dt=Je,wt=$e,Lt=he,Ft=ue,Nt=ce,Bt=we,Vt=Le,Ut=Fe):9==Rt?(Ot=et,Dt=tt,wt=it,Lt=fe,Ft=pe,Nt=de,Bt=Me,Vt=Ce,Ut=Re):10==Rt?(Ot=rt,Dt=nt,wt=ot,Lt=fe,Ft=pe,Nt=de,Bt=Ie,Vt=Oe,Ut=De):11==Rt?(Ot=st,Dt=at,wt=lt,Lt=fe,Ft=pe,Nt=de,Bt=we,Vt=Le,Ut=Fe):12==Rt?(Ot=ht,Dt=ut,wt=ct,Lt=me,Ft=ge,Nt=ve,Bt=Me,Vt=Ce,Ut=Re):13==Rt?(Ot=ft,Dt=pt,wt=dt,Lt=me,Ft=ge,Nt=ve,Bt=Ie,Vt=Oe,Ut=De):14==Rt&&(Ot=mt,Dt=gt,wt=vt,Lt=me,Ft=ge,Nt=ve,Bt=we,Vt=Le,Ut=Fe);if(Rt>5){It||(Ot=-Ot,Dt=-Dt,wt=-wt);var Zt,qt,Jt,$t,ei,ti,ii,ri,ni,oi,si;qt=Ot*(ti=G[0])+Dt*(ii=G[1])+wt*(ri=G[2]),(Zt=Ot*(Jt=G[3])+Dt*($t=G[4])+wt*(ei=G[5]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[6])+Dt*($t=G[7])+wt*(ei=G[8]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[9])+Dt*($t=G[10])+wt*(ei=G[11]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[12])+Dt*($t=G[13])+wt*(ei=G[14]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[15])+Dt*($t=G[16])+wt*(ei=G[17]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[18])+Dt*($t=G[19])+wt*(ei=G[20]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[21])+Dt*($t=G[22])+wt*(ei=G[23]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),qt=Ot*(ni=H[0])+Dt*(oi=H[1])+wt*(si=H[2]),(Zt=Ot*(Jt=H[3])+Dt*($t=H[4])+wt*(ei=H[5]))<qt&&(qt=Zt,ni=Jt,oi=$t,si=ei),(Zt=Ot*(Jt=H[6])+Dt*($t=H[7])+wt*(ei=H[8]))<qt&&(qt=Zt,ni=Jt,oi=$t,si=ei),(Zt=Ot*(Jt=H[9])+Dt*($t=H[10])+wt*(ei=H[11]))<qt&&(qt=Zt,ni=Jt,oi=$t,si=ei),(Zt=Ot*(Jt=H[12])+Dt*($t=H[13])+wt*(ei=H[14]))<qt&&(qt=Zt,ni=Jt,oi=$t,si=ei),(Zt=Ot*(Jt=H[15])+Dt*($t=H[16])+wt*(ei=H[17]))<qt&&(qt=Zt,ni=Jt,oi=$t,si=ei),(Zt=Ot*(Jt=H[18])+Dt*($t=H[19])+wt*(ei=H[20]))<qt&&(qt=Zt,ni=Jt,oi=$t,si=ei),(Zt=Ot*(Jt=H[21])+Dt*($t=H[22])+wt*(ei=H[23]))<qt&&(qt=Zt,ni=Jt,oi=$t,si=ei);var ai=((Jt=ni-ti)*(Lt-Bt*(U=Lt*Bt+Ft*Vt+Nt*Ut))+($t=oi-ii)*(Ft-Vt*U)+(ei=si-ri)*(Nt-Ut*U))/(1-U*U);i.addPoint(ti+Lt*ai+Ot*Mt*.5,ii+Ft*ai+Dt*Mt*.5,ri+Nt*ai+wt*Mt*.5,Ot,Dt,wt,Mt,!1)}else{var li,hi,ui,ci,fi,pi,di,mi,gi,vi,_i,yi,xi=1,bi=0,Ti=0;Qt?((bi=he*Ot+ue*Dt+ce*wt)<xi&&(xi=bi,Ti=0),-bi<xi&&(xi=-bi,Ti=1),(bi=fe*Ot+pe*Dt+de*wt)<xi&&(xi=bi,Ti=2),-bi<xi&&(xi=-bi,Ti=3),(bi=me*Ot+ge*Dt+ve*wt)<xi&&(xi=bi,Ti=4),-bi<xi&&(xi=-bi,Ti=5),0==Ti?(li=G[0],hi=G[1],ui=G[2],ci=G[6],fi=G[7],pi=G[8],di=G[9],mi=G[10],gi=G[11],vi=G[3],_i=G[4],yi=G[5]):1==Ti?(li=G[15],hi=G[16],ui=G[17],ci=G[21],fi=G[22],pi=G[23],di=G[18],mi=G[19],gi=G[20],vi=G[12],_i=G[13],yi=G[14]):2==Ti?(li=G[12],hi=G[13],ui=G[14],ci=G[0],fi=G[1],pi=G[2],di=G[3],mi=G[4],gi=G[5],vi=G[15],_i=G[16],yi=G[17]):3==Ti?(li=G[21],hi=G[22],ui=G[23],ci=G[9],fi=G[10],pi=G[11],di=G[6],mi=G[7],gi=G[8],vi=G[18],_i=G[19],yi=G[20]):4==Ti?(li=G[12],hi=G[13],ui=G[14],ci=G[18],fi=G[19],pi=G[20],di=G[6],mi=G[7],gi=G[8],vi=G[0],_i=G[1],yi=G[2]):5==Ti&&(li=G[3],hi=G[4],ui=G[5],ci=G[6],fi=G[7],pi=G[8],di=G[21],mi=G[22],gi=G[23],vi=G[15],_i=G[16],yi=G[17])):((bi=Me*Ot+Ce*Dt+Re*wt)<xi&&(xi=bi,Ti=0),-bi<xi&&(xi=-bi,Ti=1),(bi=Ie*Ot+Oe*Dt+De*wt)<xi&&(xi=bi,Ti=2),-bi<xi&&(xi=-bi,Ti=3),(bi=we*Ot+Le*Dt+Fe*wt)<xi&&(xi=bi,Ti=4),-bi<xi&&(xi=-bi,Ti=5),0==Ti?(li=H[0],hi=H[1],ui=H[2],ci=H[6],fi=H[7],pi=H[8],di=H[9],mi=H[10],gi=H[11],vi=H[3],_i=H[4],yi=H[5]):1==Ti?(li=H[15],hi=H[16],ui=H[17],ci=H[21],fi=H[22],pi=H[23],di=H[18],mi=H[19],gi=H[20],vi=H[12],_i=H[13],yi=H[14]):2==Ti?(li=H[12],hi=H[13],ui=H[14],ci=H[0],fi=H[1],pi=H[2],di=H[3],mi=H[4],gi=H[5],vi=H[15],_i=H[16],yi=H[17]):3==Ti?(li=H[21],hi=H[22],ui=H[23],ci=H[9],fi=H[10],pi=H[11],di=H[6],mi=H[7],gi=H[8],vi=H[18],_i=H[19],yi=H[20]):4==Ti?(li=H[12],hi=H[13],ui=H[14],ci=H[18],fi=H[19],pi=H[20],di=H[6],mi=H[7],gi=H[8],vi=H[0],_i=H[1],yi=H[2]):5==Ti&&(li=H[3],hi=H[4],ui=H[5],ci=H[9],fi=H[10],pi=H[11],di=H[21],mi=H[22],gi=H[23],vi=H[15],_i=H[16],yi=H[17]));var Ei,Ai,Pi,Si,Mi,Ci,Ri,Ii,Oi;this.clipVertices1[0]=li,this.clipVertices1[1]=hi,this.clipVertices1[2]=ui,this.clipVertices1[3]=ci,this.clipVertices1[4]=fi,this.clipVertices1[5]=pi,this.clipVertices1[6]=di,this.clipVertices1[7]=mi,this.clipVertices1[8]=gi,this.clipVertices1[9]=vi,this.clipVertices1[10]=_i,this.clipVertices1[11]=yi,Ai=0,U=((Si=this.clipVertices1[9])-zt-Ht)*Lt+((Mi=this.clipVertices1[10])-kt-Wt)*Ft+((Ci=this.clipVertices1[11])-Gt-jt)*Nt;for(var Di=0;Di<4;Di++)Pi=3*Di,z=((Ri=this.clipVertices1[Pi])-zt-Ht)*Lt+((Ii=this.clipVertices1[Pi+1])-kt-Wt)*Ft+((Oi=this.clipVertices1[Pi+2])-Gt-jt)*Nt,U>0?z>0?(Pi=3*Ai,Ai++,this.clipVertices2[Pi]=Ri,this.clipVertices2[Pi+1]=Ii,this.clipVertices2[Pi+2]=Oi):(Pi=3*Ai,Ai++,ai=U/(U-z),this.clipVertices2[Pi]=Si+(Ri-Si)*ai,this.clipVertices2[Pi+1]=Mi+(Ii-Mi)*ai,this.clipVertices2[Pi+2]=Ci+(Oi-Ci)*ai):z>0&&(Pi=3*Ai,Ai++,ai=U/(U-z),this.clipVertices2[Pi]=Si+(Ri-Si)*ai,this.clipVertices2[Pi+1]=Mi+(Ii-Mi)*ai,this.clipVertices2[Pi+2]=Ci+(Oi-Ci)*ai,Pi=3*Ai,Ai++,this.clipVertices2[Pi]=Ri,this.clipVertices2[Pi+1]=Ii,this.clipVertices2[Pi+2]=Oi),Si=Ri,Mi=Ii,Ci=Oi,U=z;if(0!=(Ei=Ai)){for(Ai=0,Pi=3*(Ei-1),U=((Si=this.clipVertices2[Pi])-zt-Xt)*Bt+((Mi=this.clipVertices2[Pi+1])-kt-Yt)*Vt+((Ci=this.clipVertices2[Pi+2])-Gt-Kt)*Ut,Di=0;Di<Ei;Di++)Pi=3*Di,z=((Ri=this.clipVertices2[Pi])-zt-Xt)*Bt+((Ii=this.clipVertices2[Pi+1])-kt-Yt)*Vt+((Oi=this.clipVertices2[Pi+2])-Gt-Kt)*Ut,U>0?z>0?(Pi=3*Ai,Ai++,this.clipVertices1[Pi]=Ri,this.clipVertices1[Pi+1]=Ii,this.clipVertices1[Pi+2]=Oi):(Pi=3*Ai,Ai++,ai=U/(U-z),this.clipVertices1[Pi]=Si+(Ri-Si)*ai,this.clipVertices1[Pi+1]=Mi+(Ii-Mi)*ai,this.clipVertices1[Pi+2]=Ci+(Oi-Ci)*ai):z>0&&(Pi=3*Ai,Ai++,ai=U/(U-z),this.clipVertices1[Pi]=Si+(Ri-Si)*ai,this.clipVertices1[Pi+1]=Mi+(Ii-Mi)*ai,this.clipVertices1[Pi+2]=Ci+(Oi-Ci)*ai,Pi=3*Ai,Ai++,this.clipVertices1[Pi]=Ri,this.clipVertices1[Pi+1]=Ii,this.clipVertices1[Pi+2]=Oi),Si=Ri,Mi=Ii,Ci=Oi,U=z;if(0!=(Ei=Ai)){for(Ai=0,Pi=3*(Ei-1),U=((Si=this.clipVertices1[Pi])-zt+Ht)*-Lt+((Mi=this.clipVertices1[Pi+1])-kt+Wt)*-Ft+((Ci=this.clipVertices1[Pi+2])-Gt+jt)*-Nt,Di=0;Di<Ei;Di++)Pi=3*Di,z=((Ri=this.clipVertices1[Pi])-zt+Ht)*-Lt+((Ii=this.clipVertices1[Pi+1])-kt+Wt)*-Ft+((Oi=this.clipVertices1[Pi+2])-Gt+jt)*-Nt,U>0?z>0?(Pi=3*Ai,Ai++,this.clipVertices2[Pi]=Ri,this.clipVertices2[Pi+1]=Ii,this.clipVertices2[Pi+2]=Oi):(Pi=3*Ai,Ai++,ai=U/(U-z),this.clipVertices2[Pi]=Si+(Ri-Si)*ai,this.clipVertices2[Pi+1]=Mi+(Ii-Mi)*ai,this.clipVertices2[Pi+2]=Ci+(Oi-Ci)*ai):z>0&&(Pi=3*Ai,Ai++,ai=U/(U-z),this.clipVertices2[Pi]=Si+(Ri-Si)*ai,this.clipVertices2[Pi+1]=Mi+(Ii-Mi)*ai,this.clipVertices2[Pi+2]=Ci+(Oi-Ci)*ai,Pi=3*Ai,Ai++,this.clipVertices2[Pi]=Ri,this.clipVertices2[Pi+1]=Ii,this.clipVertices2[Pi+2]=Oi),Si=Ri,Mi=Ii,Ci=Oi,U=z;if(0!=(Ei=Ai)){for(Ai=0,Pi=3*(Ei-1),U=((Si=this.clipVertices2[Pi])-zt+Xt)*-Bt+((Mi=this.clipVertices2[Pi+1])-kt+Yt)*-Vt+((Ci=this.clipVertices2[Pi+2])-Gt+Kt)*-Ut,Di=0;Di<Ei;Di++)Pi=3*Di,z=((Ri=this.clipVertices2[Pi])-zt+Xt)*-Bt+((Ii=this.clipVertices2[Pi+1])-kt+Yt)*-Vt+((Oi=this.clipVertices2[Pi+2])-Gt+Kt)*-Ut,U>0?z>0?(Pi=3*Ai,Ai++,this.clipVertices1[Pi]=Ri,this.clipVertices1[Pi+1]=Ii,this.clipVertices1[Pi+2]=Oi):(Pi=3*Ai,Ai++,ai=U/(U-z),this.clipVertices1[Pi]=Si+(Ri-Si)*ai,this.clipVertices1[Pi+1]=Mi+(Ii-Mi)*ai,this.clipVertices1[Pi+2]=Ci+(Oi-Ci)*ai):z>0&&(Pi=3*Ai,Ai++,ai=U/(U-z),this.clipVertices1[Pi]=Si+(Ri-Si)*ai,this.clipVertices1[Pi+1]=Mi+(Ii-Mi)*ai,this.clipVertices1[Pi+2]=Ci+(Oi-Ci)*ai,Pi=3*Ai,Ai++,this.clipVertices1[Pi]=Ri,this.clipVertices1[Pi+1]=Ii,this.clipVertices1[Pi+2]=Oi),Si=Ri,Mi=Ii,Ci=Oi,U=z;if(Ei=Ai,Qt){var wi=r;r=n,n=wi}if(0!=Ei){var Li=r!=e;if(Ei>4){Lt=li-(Si=.25*(li+ci+di+vi)),Ft=hi-(Mi=.25*(hi+fi+mi+_i)),Nt=ui-(Ci=.25*(ui+pi+gi+yi)),Bt=ci-Si,Vt=fi-Mi,Ut=pi-Ci;var Fi=0,Ni=0,Bi=0,Vi=0,Ui=-this.INF;for(xi=this.INF,Di=0;Di<Ei;Di++)this.used[Di]=!1,Pi=3*Di,(bi=(Si=this.clipVertices1[Pi])*Lt+(Mi=this.clipVertices1[Pi+1])*Ft+(Ci=this.clipVertices1[Pi+2])*Nt)<xi&&(xi=bi,Fi=Di),bi>Ui&&(Ui=bi,Bi=Di);for(this.used[Fi]=!0,this.used[Bi]=!0,Ui=-this.INF,xi=this.INF,Di=0;Di<Ei;Di++)this.used[Di]||(Pi=3*Di,(bi=(Si=this.clipVertices1[Pi])*Bt+(Mi=this.clipVertices1[Pi+1])*Vt+(Ci=this.clipVertices1[Pi+2])*Ut)<xi&&(xi=bi,Ni=Di),bi>Ui&&(Ui=bi,Vi=Di));Pi=3*Fi,(bi=((Si=this.clipVertices1[Pi])-zt)*Ot+((Mi=this.clipVertices1[Pi+1])-kt)*Dt+((Ci=this.clipVertices1[Pi+2])-Gt)*wt)<0&&i.addPoint(Si,Mi,Ci,Ot,Dt,wt,bi,Li),Pi=3*Ni,(bi=((Si=this.clipVertices1[Pi])-zt)*Ot+((Mi=this.clipVertices1[Pi+1])-kt)*Dt+((Ci=this.clipVertices1[Pi+2])-Gt)*wt)<0&&i.addPoint(Si,Mi,Ci,Ot,Dt,wt,bi,Li),Pi=3*Bi,(bi=((Si=this.clipVertices1[Pi])-zt)*Ot+((Mi=this.clipVertices1[Pi+1])-kt)*Dt+((Ci=this.clipVertices1[Pi+2])-Gt)*wt)<0&&i.addPoint(Si,Mi,Ci,Ot,Dt,wt,bi,Li),Pi=3*Vi,(bi=((Si=this.clipVertices1[Pi])-zt)*Ot+((Mi=this.clipVertices1[Pi+1])-kt)*Dt+((Ci=this.clipVertices1[Pi+2])-Gt)*wt)<0&&i.addPoint(Si,Mi,Ci,Ot,Dt,wt,bi,Li)}else for(Di=0;Di<Ei;Di++)Pi=3*Di,(bi=((Si=this.clipVertices1[Pi])-zt)*Ot+((Mi=this.clipVertices1[Pi+1])-kt)*Dt+((Ci=this.clipVertices1[Pi+2])-Gt)*wt)<0&&i.addPoint(Si,Mi,Ci,Ot,Dt,wt,bi,Li)}}}}}}},a.SphereBoxCollisionDetector=function(e){a.CollisionDetector.call(this),this.flip=e},a.SphereBoxCollisionDetector.prototype=Object.create(a.CollisionDetector.prototype),a.SphereBoxCollisionDetector.prototype.constructor=a.SphereBoxCollisionDetector,a.SphereBoxCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n;this.flip?(r=t,n=e):(r=e,n=t);var o,s,l,h,u,c=n.dimentions,f=r.position,p=f.x,d=f.y,m=f.z,g=n.position,v=g.x,_=g.y,y=g.z,x=r.radius,b=n.halfWidth,T=n.halfHeight,E=n.halfDepth,A=p-v,P=d-_,S=m-y,M=c[0]*A+c[1]*P+c[2]*S,C=c[3]*A+c[4]*P+c[5]*S,R=c[6]*A+c[7]*P+c[8]*S,I=0;M>b?M=b:M<-b?M=-b:I=1,C>T?C=T:C<-T?C=-T:I|=2,R>E?R=E:R<-E?R=-E:I|=4,7==I?(A=M<0?b+M:b-M,P=C<0?T+C:T-C,S=R<0?E+R:E-R,A<P?A<S?(h=A-b,M<0?(M=-b,A=c[0],P=c[1],S=c[2]):(M=b,A=-c[0],P=-c[1],S=-c[2])):(h=S-E,R<0?(R=-E,A=c[6],P=c[7],S=c[8]):(R=E,A=-c[6],P=-c[7],S=-c[8])):P<S?(h=P-T,C<0?(C=-T,A=c[3],P=c[4],S=c[5]):(C=T,A=-c[3],P=-c[4],S=-c[5])):(h=S-E,R<0?(R=-E,A=c[6],P=c[7],S=c[8]):(R=E,A=-c[6],P=-c[7],S=-c[8])),o=v+M*c[0]+C*c[3]+R*c[6],s=_+M*c[1]+C*c[4]+R*c[7],l=y+M*c[2]+C*c[5]+R*c[8],i.addPoint(p+x*A,d+x*P,m+x*S,A,P,S,h-x,this.flip)):(o=v+M*c[0]+C*c[3]+R*c[6],s=_+M*c[1]+C*c[4]+R*c[7],l=y+M*c[2]+C*c[5]+R*c[8],(h=(A=o-f.x)*A+(P=s-f.y)*P+(S=l-f.z)*S)>0&&h<x*x&&(A*=u=1/(h=a.sqrt(h)),P*=u,S*=u,i.addPoint(p+x*A,d+x*P,m+x*S,A,P,S,h-x,this.flip)))},a.SphereSphereCollisionDetector=function(){a.CollisionDetector.call(this)},a.SphereSphereCollisionDetector.prototype=Object.create(a.CollisionDetector.prototype),a.SphereSphereCollisionDetector.prototype.constructor=a.SphereSphereCollisionDetector,a.SphereSphereCollisionDetector.prototype.detectCollision=function(e,t,i){var r=e,n=t,o=r.position,s=n.position,l=s.x-o.x,h=s.y-o.y,u=s.z-o.z,c=l*l+h*h+u*u,f=r.radius,p=f+n.radius;if(c>0&&c<p*p){var d=1/(c=a.sqrt(c));l*=d,h*=d,u*=d,i.addPoint(o.x+l*f,o.y+h*f,o.z+u*f,l,h,u,c-p,!1)}},a.BoxCylinderCollisionDetector=function(e){a.CollisionDetector.call(this),this.flip=e},a.BoxCylinderCollisionDetector.prototype=Object.create(a.CollisionDetector.prototype),a.BoxCylinderCollisionDetector.prototype.constructor=a.BoxCylinderCollisionDetector,a.BoxCylinderCollisionDetector.prototype.getSep=function(e,t,i,r,n){var o,s,l,h,u,c,f,p,d,m,g,v,_,y=new a.Vec3,x=e.position.x,b=e.position.y,T=e.position.z,E=t.position.x,A=t.position.y,P=t.position.z,S=E-x,M=A-b,C=P-T;S*S+M*M+C*C==0&&(M=.001);var R=-S,I=-M,O=-C;this.supportPointB(e,-R,-I,-O,y);var D=y.x,w=y.y,L=y.z;this.supportPointC(t,R,I,O,y);var F=y.x,N=y.y,B=y.z,V=F-D,U=N-w,z=B-L;if(V*R+U*I+z*O<=0)return!1;if(R=U*C-z*M,I=z*S-V*C,O=V*M-U*S,R*R+I*I+O*O==0)return i.init(V-S,U-M,z-C),i.normalize(i),r.init(.5*(D+F),.5*(w+N),.5*(L+B)),!0;this.supportPointB(e,-R,-I,-O,y);var k=y.x,G=y.y,H=y.z;this.supportPointC(t,R,I,O,y);var W=y.x,j=y.y,X=y.z,Y=W-k,K=j-G,Q=X-H;if(Y*R+K*I+Q*O<=0)return!1;(R=(s=U-M)*(c=Q-C)-(l=z-C)*(u=K-M))*S+(I=l*(h=Y-S)-(o=V-S)*c)*M+(O=o*u-s*h)*C>0&&(o=V,s=U,l=z,V=Y,U=K,z=Q,Y=o,K=s,Q=l,o=D,s=w,l=L,D=k,w=G,L=H,k=o,G=s,H=l,o=F,s=N,l=B,F=W,N=j,B=X,W=o,j=s,X=l,R=-R,I=-I,O=-O);for(var Z=0;;){if(++Z>100)return!1;this.supportPointB(e,-R,-I,-O,y);var q=y.x,J=y.y,$=y.z;this.supportPointC(t,R,I,O,y);var ee=y.x,te=y.y,ie=y.z,re=ee-q,ne=te-J,oe=ie-$;if(re*R+ne*I+oe*O<=0)return!1;if((U*oe-z*ne)*S+(z*re-V*oe)*M+(V*ne-U*re)*C<0)Y=re,K=ne,Q=oe,k=q,G=J,H=$,W=ee,j=te,X=ie,R=(s=U-M)*(c=oe-C)-(l=z-C)*(u=ne-M),I=l*(h=re-S)-(o=V-S)*c,O=o*u-s*h;else if((ne*Q-oe*K)*S+(oe*Y-re*Q)*M+(re*K-ne*Y)*C<0)V=re,U=ne,z=oe,D=q,w=J,L=$,F=ee,N=te,B=ie,R=(s=ne-M)*(c=Q-C)-(l=oe-C)*(u=K-M),I=l*(h=Y-S)-(o=re-S)*c,O=o*u-s*h;else for(var se=!1;;){if(o=Y-V,s=K-U,l=Q-z,h=re-V,u=ne-U,c=oe-z,R=s*c-l*u,I=l*h-o*c,O=o*u-s*h,f=1/a.sqrt(R*R+I*I+O*O),R*=f,I*=f,O*=f,R*V+I*U+O*z>=0&&!se){var ae=(U*Q-z*K)*re+(z*Y-V*Q)*ne+(V*K-U*Y)*oe,le=(ne*Q-oe*K)*S+(oe*Y-re*Q)*M+(re*K-ne*Y)*C,he=(M*z-C*U)*re+(C*V-S*z)*ne+(S*U-M*V)*oe,ue=(K*z-Q*U)*S+(Q*V-Y*z)*M+(Y*U-K*V)*C,ce=ae+le+he+ue;ce<=0&&(ae=0,ce=(le=(K*oe-Q*ne)*R+(Q*re-Y*oe)*I+(Y*ne-K*re)*O)+(he=(ne*Q-oe*K)*R+(oe*Y-re*Q)*I+(re*K-ne*Y)*O)+(ue=(U*Q-z*K)*R+(z*Y-V*Q)*I+(V*K-U*Y)*O));var fe=1/ce;p=(x*ae+D*le+k*he+q*ue)*fe,d=(b*ae+w*le+G*he+J*ue)*fe,m=(T*ae+L*le+H*he+$*ue)*fe,g=(E*ae+F*le+W*he+ee*ue)*fe,v=(A*ae+N*le+j*he+te*ue)*fe,_=(P*ae+B*le+X*he+ie*ue)*fe,se=!0}this.supportPointB(e,-R,-I,-O,y);var pe=y.x,de=y.y,me=y.z;this.supportPointC(t,R,I,O,y);var ge=y.x,ve=y.y,_e=y.z,ye=ge-pe,xe=ve-de,be=_e-me,Te=-(ye*R+xe*I+be*O);if((ye-re)*R+(xe-ne)*I+(be-oe)*O<=.01||Te>=0)return!!se&&(i.init(-R,-I,-O),r.init(.5*(p+g),.5*(d+v),.5*(m+_)),n.x=Te,!0);(xe*z-be*U)*S+(be*V-ye*z)*M+(ye*U-xe*V)*C<0?(xe*Q-be*K)*S+(be*Y-ye*Q)*M+(ye*K-xe*Y)*C<0?(V=ye,U=xe,z=be,D=pe,w=de,L=me,F=ge,N=ve,B=_e):(re=ye,ne=xe,oe=be,q=pe,J=de,$=me,ee=ge,te=ve,ie=_e):(xe*oe-be*ne)*S+(be*re-ye*oe)*M+(ye*ne-xe*re)*C<0?(Y=ye,K=xe,Q=be,k=pe,G=de,H=me,W=ge,j=ve,X=_e):(V=ye,U=xe,z=be,D=pe,w=de,L=me,F=ge,N=ve,B=_e)}}},a.BoxCylinderCollisionDetector.prototype.supportPointB=function(e,t,i,r,n){var o,s,a,l=e.rotation.elements,h=l[0]*t+l[3]*i+l[6]*r,u=l[1]*t+l[4]*i+l[7]*r,c=l[2]*t+l[5]*i+l[8]*r,f=e.halfWidth,p=e.halfHeight,d=e.halfDepth;o=h<0?-f:f,s=u<0?-p:p,a=c<0?-d:d,h=l[0]*o+l[1]*s+l[2]*a+e.position.x,u=l[3]*o+l[4]*s+l[5]*a+e.position.y,c=l[6]*o+l[7]*s+l[8]*a+e.position.z,n.init(h,u,c)},a.BoxCylinderCollisionDetector.prototype.supportPointC=function(e,t,i,r,n){var o,s,l,h=e.rotation.elements,u=h[0]*t+h[3]*i+h[6]*r,c=h[1]*t+h[4]*i+h[7]*r,f=h[2]*t+h[5]*i+h[8]*r,p=u,d=f,m=p*p+d*d,g=e.radius,v=e.halfHeight;0==m?c<0?(o=g,s=-v,l=0):(o=g,s=v,l=0):(m=e.radius/a.sqrt(m),c<0?(o=p*m,s=-v,l=d*m):(o=p*m,s=v,l=d*m)),u=h[0]*o+h[1]*s+h[2]*l+e.position.x,c=h[3]*o+h[4]*s+h[5]*l+e.position.y,f=h[6]*o+h[7]*s+h[8]*l+e.position.z,n.init(u,c,f)},a.BoxCylinderCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n;this.flip?(r=t,n=e):(r=e,n=t);var o=new a.Vec3,s=new a.Vec3,l=new a.Vec3;if(this.getSep(r,n,o,s,l)){var h=r.position.x,u=r.position.y,c=r.position.z,f=n.position.x,p=n.position.y,d=n.position.z,m=r.halfWidth,g=r.halfHeight,v=r.halfDepth,_=n.halfHeight,y=n.radius,x=r.dimentions,b=x[0],T=x[1],E=x[2],A=x[3],P=x[4],S=x[5],M=x[6],C=x[7],R=x[8],I=x[9],O=x[10],D=x[11],w=x[12],L=x[13],F=x[14],N=x[15],B=x[16],V=x[17],U=n.normalDirection.x,z=n.normalDirection.y,k=n.normalDirection.z,G=n.halfDirection.x,H=n.halfDirection.y,W=n.halfDirection.z,j=o.x,X=o.y,Y=o.z,K=j*b+X*T+Y*E,Q=j*A+X*P+Y*S,Z=j*M+X*C+Y*R,q=j*U+X*z+Y*k,J=K>0,$=Q>0,ee=Z>0,te=q>0;J||(K=-K),$||(Q=-Q),ee||(Z=-Z),te||(q=-q);var ie=0;q>.999?ie=K>.999?K>q?1:4:Q>.999?Q>q?2:4:Z>.999&&Z>q?3:4:K>.999?ie=1:Q>.999?ie=2:Z>.999&&(ie=3);var re,ne,oe,se,ae,le,he,ue,ce,fe,pe,de,me,ge,ve,_e,ye,xe,be,Te,Ee,Ae,Pe,Se,Me,Ce,Re,Ie,Oe,De,we,Le,Fe,Ne,Be,Ve,Ue,ze,ke,Ge,He,We,je,Xe,Ye,Ke,Qe,Ze,qe,Je,$e,et,tt;if(0==ie)i.addPoint(s.x,s.y,s.z,j,X,Y,l.x,this.flip);else if(4==ie){te?(se=f-G,ae=p-H,le=d-W,j=-U,X=-z,Y=-k):(se=f+G,ae=p+H,le=d+W,j=U,X=z,Y=k);var it,rt,nt,ot,st,at,lt,ht,ut,ct,ft,pt;ie=0,(je=b*j+T*X+E*Y)<(Te=1)&&(Te=je,ie=0),-je<Te&&(Te=-je,ie=1),(je=A*j+P*X+S*Y)<Te&&(Te=je,ie=2),-je<Te&&(Te=-je,ie=3),(je=M*j+C*X+R*Y)<Te&&(Te=je,ie=4),-je<Te&&(Te=-je,ie=5);var dt=r.elements;switch(ie){case 0:it=dt[0],rt=dt[1],nt=dt[2],ot=dt[6],st=dt[7],at=dt[8],lt=dt[9],ht=dt[10],ut=dt[11],ct=dt[3],ft=dt[4],pt=dt[5];break;case 1:it=dt[15],rt=dt[16],nt=dt[17],ot=dt[21],st=dt[22],at=dt[23],lt=dt[18],ht=dt[19],ut=dt[20],ct=dt[12],ft=dt[13],pt=dt[14];break;case 2:it=dt[12],rt=dt[13],nt=dt[14],ot=dt[0],st=dt[1],at=dt[2],lt=dt[3],ht=dt[4],ut=dt[5],ct=dt[15],ft=dt[16],pt=dt[17];break;case 3:it=dt[21],rt=dt[22],nt=dt[23],ot=dt[9],st=dt[10],at=dt[11],lt=dt[6],ht=dt[7],ut=dt[8],ct=dt[18],ft=dt[19],pt=dt[20];break;case 4:it=dt[12],rt=dt[13],nt=dt[14],ot=dt[18],st=dt[19],at=dt[20],lt=dt[6],ht=dt[7],ut=dt[8],ct=dt[0],ft=dt[1],pt=dt[2];break;case 5:it=dt[3],rt=dt[4],nt=dt[5],ot=dt[9],st=dt[10],at=dt[11],lt=dt[21],ht=dt[22],ut=dt[23],ct=dt[15],ft=dt[16],pt=dt[17]}(be=j*(it-se)+X*(rt-ae)+Y*(nt-le))<=0&&i.addPoint(it,rt,nt,-j,-X,-Y,be,this.flip),(be=j*(ot-se)+X*(st-ae)+Y*(at-le))<=0&&i.addPoint(ot,st,at,-j,-X,-Y,be,this.flip),(be=j*(lt-se)+X*(ht-ae)+Y*(ut-le))<=0&&i.addPoint(lt,ht,ut,-j,-X,-Y,be,this.flip),(be=j*(ct-se)+X*(ft-ae)+Y*(pt-le))<=0&&i.addPoint(ct,ft,pt,-j,-X,-Y,be,this.flip)}else{switch(ie){case 1:J?(re=h+I,ne=u+O,oe=c+D,j=b,X=T,Y=E):(re=h-I,ne=u-O,oe=c-D,j=-b,X=-T,Y=-E),Ke=A,Qe=P,Ze=S,et=g,qe=M,Je=C,$e=R,tt=v;break;case 2:$?(re=h+w,ne=u+L,oe=c+F,j=A,X=P,Y=S):(re=h-w,ne=u-L,oe=c-F,j=-A,X=-P,Y=-S),Ke=b,Qe=T,Ze=E,et=m,qe=M,Je=C,$e=R,tt=v;break;case 3:ee?(re=h+N,ne=u+B,oe=c+V,j=M,X=C,Y=R):(re=h-N,ne=u-B,oe=c-V,j=-M,X=-C,Y=-R),Ke=b,Qe=T,Ze=E,et=m,qe=A,Je=P,$e=S,tt=g}if(Te=j*U+X*z+Y*k,Ee=Te<0?_:-_,se=f+Ee*U,ae=p+Ee*z,le=d+Ee*k,q>=.999999?(Ae=-X,Pe=Y,Se=j):(Ae=j,Pe=X,Se=Y),Ee=Ae*U+Pe*z+Se*k,Ce=Ee*U-Ae,Re=Ee*z-Pe,Ie=Ee*k-Se,0==(Ee=a.sqrt(Ce*Ce+Re*Re+Ie*Ie)))return;if(Ee=y/Ee,Ce*=Ee,Re*=Ee,Ie*=Ee,Ae=se+Ce,Pe=ae+Re,Se=le+Ie,Te<-.96||Te>.96)he=U*U*1.5-.5,ue=U*z*1.5-.866025403*k,ce=U*k*1.5+.866025403*z,fe=z*U*1.5+.866025403*k,pe=z*z*1.5-.5,de=z*k*1.5-.866025403*U,me=k*U*1.5-.866025403*z,ge=k*z*1.5+.866025403*U,ve=k*k*1.5-.5,We=qe*(Ae=(_e=Ae)-(be=j*(_e-re)+X*((ye=Pe)-ne)+Y*((xe=Se)-oe))*j-re)+Je*(Pe=ye-be*X-ne)+$e*(Se=xe-be*Y-oe),(ze=Ke*Ae+Qe*Pe+Ze*Se)<-et?ze=-et:ze>et&&(ze=et),We<-tt?We=-tt:We>tt&&(We=tt),_e=re+(Ae=ze*Ke+We*qe),ye=ne+(Pe=ze*Qe+We*Je),xe=oe+(Se=ze*Ze+We*$e),i.addPoint(_e,ye,xe,j,X,Y,be,this.flip),ye=Ce*fe+Re*pe+Ie*de,xe=Ce*me+Re*ge+Ie*ve,(be=j*((_e=(Ce=_e=Ce*he+Re*ue+Ie*ce)+se)-re)+X*((ye=(Re=ye)+ae)-ne)+Y*((xe=(Ie=xe)+le)-oe))<=0&&(We=qe*(Ae=_e-be*j-re)+Je*(Pe=ye-be*X-ne)+$e*(Se=xe-be*Y-oe),(ze=Ke*Ae+Qe*Pe+Ze*Se)<-et?ze=-et:ze>et&&(ze=et),We<-tt?We=-tt:We>tt&&(We=tt),_e=re+(Ae=ze*Ke+We*qe),ye=ne+(Pe=ze*Qe+We*Je),xe=oe+(Se=ze*Ze+We*$e),i.addPoint(_e,ye,xe,j,X,Y,be,this.flip)),ye=Ce*fe+Re*pe+Ie*de,xe=Ce*me+Re*ge+Ie*ve,(be=j*((_e=(Ce=_e=Ce*he+Re*ue+Ie*ce)+se)-re)+X*((ye=(Re=ye)+ae)-ne)+Y*((xe=(Ie=xe)+le)-oe))<=0&&(We=qe*(Ae=_e-be*j-re)+Je*(Pe=ye-be*X-ne)+$e*(Se=xe-be*Y-oe),(ze=Ke*Ae+Qe*Pe+Ze*Se)<-et?ze=-et:ze>et&&(ze=et),We<-tt?We=-tt:We>tt&&(We=tt),_e=re+(Ae=ze*Ke+We*qe),ye=ne+(Pe=ze*Qe+We*Je),xe=oe+(Se=ze*Ze+We*$e),i.addPoint(_e,ye,xe,j,X,Y,be,this.flip));else{if(Be=Ae,Ve=Pe,Ue=Se,ze=j*(Be-re)+X*(Ve-ne)+Y*(Ue-oe),Be-=ze*j,Ve-=ze*X,Ue-=ze*Y,Te>0?(ke=Ae+2*G,Ge=Pe+2*H,He=Se+2*W):(ke=Ae-2*G,Ge=Pe-2*H,He=Se-2*W),We=j*(ke-re)+X*(Ge-ne)+Y*(He-oe),ke-=We*j,Ge-=We*X,He-=We*Y,Oe=Be-re,De=Ve-ne,we=Ue-oe,Le=ke-re,Fe=Ge-ne,Ne=He-oe,Ae=ke-Be,Pe=Ge-Ve,Se=He-Ue,Me=We-ze,K=Oe*Ke+De*Qe+we*Ze,Q=Le*Ke+Fe*Qe+Ne*Ze,je=K-et,Xe=Q-et,je>0){if(Xe>0)return;K=(Oe=(Be+=Ae*(Ye=je/(je-Xe)))-re)*Ke+(De=(Ve+=Pe*Ye)-ne)*Qe+(we=(Ue+=Se*Ye)-oe)*Ze,Ae=ke-Be,Pe=Ge-Ve,Se=He-Ue,Me=We-(ze+=Me*Ye)}else Xe>0&&(Q=(Le=(ke=Be+Ae*(Ye=je/(je-Xe)))-re)*Ke+(Fe=(Ge=Ve+Pe*Ye)-ne)*Qe+(Ne=(He=Ue+Se*Ye)-oe)*Ze,Ae=ke-Be,Pe=Ge-Ve,Se=He-Ue,Me=(We=ze+Me*Ye)-ze);if(je=K+et,Xe=Q+et,je<0){if(Xe<0)return;Oe=(Be+=Ae*(Ye=je/(je-Xe)))-re,De=(Ve+=Pe*Ye)-ne,we=(Ue+=Se*Ye)-oe,Ae=ke-Be,Pe=Ge-Ve,Se=He-Ue,Me=We-(ze+=Me*Ye)}else Xe<0&&(Le=(ke=Be+Ae*(Ye=je/(je-Xe)))-re,Fe=(Ge=Ve+Pe*Ye)-ne,Ne=(He=Ue+Se*Ye)-oe,Ae=ke-Be,Pe=Ge-Ve,Se=He-Ue,Me=(We=ze+Me*Ye)-ze);if(K=Oe*qe+De*Je+we*$e,Q=Le*qe+Fe*Je+Ne*$e,je=K-tt,Xe=Q-tt,je>0){if(Xe>0)return;K=(Oe=(Be+=Ae*(Ye=je/(je-Xe)))-re)*qe+(De=(Ve+=Pe*Ye)-ne)*Je+(we=(Ue+=Se*Ye)-oe)*$e,Ae=ke-Be,Pe=Ge-Ve,Se=He-Ue,Me=We-(ze+=Me*Ye)}else Xe>0&&(Q=(Le=(ke=Be+Ae*(Ye=je/(je-Xe)))-re)*qe+(Fe=(Ge=Ve+Pe*Ye)-ne)*Je+(Ne=(He=Ue+Se*Ye)-oe)*$e,Ae=ke-Be,Pe=Ge-Ve,Se=He-Ue,Me=(We=ze+Me*Ye)-ze);if(je=K+tt,Xe=Q+tt,je<0){if(Xe<0)return;Be+=Ae*(Ye=je/(je-Xe)),Ve+=Pe*Ye,Ue+=Se*Ye,ze+=Me*Ye}else Xe<0&&(ke=Be+Ae*(Ye=je/(je-Xe)),Ge=Ve+Pe*Ye,He=Ue+Se*Ye,We=ze+Me*Ye);ze<0&&i.addPoint(Be,Ve,Ue,j,X,Y,ze,this.flip),We<0&&i.addPoint(ke,Ge,He,j,X,Y,We,this.flip)}}}},a.CylinderCylinderCollisionDetector=function(){a.CollisionDetector.call(this)},a.CylinderCylinderCollisionDetector.prototype=Object.create(a.CollisionDetector.prototype),a.CylinderCylinderCollisionDetector.prototype.constructor=a.CylinderCylinderCollisionDetector,a.CylinderCylinderCollisionDetector.prototype.getSep=function(e,t,i,r,n){var o,s,l,h,u,c,f,p,d,m,g,v,_,y=new a.Vec3,x=e.position.x,b=e.position.y,T=e.position.z,E=t.position.x,A=t.position.y,P=t.position.z,S=E-x,M=A-b,C=P-T;S*S+M*M+C*C==0&&(M=.001);var R=-S,I=-M,O=-C;this.supportPoint(e,-R,-I,-O,y);var D=y.x,w=y.y,L=y.z;this.supportPoint(t,R,I,O,y);var F=y.x,N=y.y,B=y.z,V=F-D,U=N-w,z=B-L;if(V*R+U*I+z*O<=0)return!1;if(R=U*C-z*M,I=z*S-V*C,O=V*M-U*S,R*R+I*I+O*O==0)return i.init(V-S,U-M,z-C),i.normalize(i),r.init(.5*(D+F),.5*(w+N),.5*(L+B)),!0;this.supportPoint(e,-R,-I,-O,y);var k=y.x,G=y.y,H=y.z;this.supportPoint(t,R,I,O,y);var W=y.x,j=y.y,X=y.z,Y=W-k,K=j-G,Q=X-H;if(Y*R+K*I+Q*O<=0)return!1;(R=(s=U-M)*(c=Q-C)-(l=z-C)*(u=K-M))*S+(I=l*(h=Y-S)-(o=V-S)*c)*M+(O=o*u-s*h)*C>0&&(o=V,s=U,l=z,V=Y,U=K,z=Q,Y=o,K=s,Q=l,o=D,s=w,l=L,D=k,w=G,L=H,k=o,G=s,H=l,o=F,s=N,l=B,F=W,N=j,B=X,W=o,j=s,X=l,R=-R,I=-I,O=-O);for(var Z=0;;){if(++Z>100)return!1;this.supportPoint(e,-R,-I,-O,y);var q=y.x,J=y.y,$=y.z;this.supportPoint(t,R,I,O,y);var ee=y.x,te=y.y,ie=y.z,re=ee-q,ne=te-J,oe=ie-$;if(re*R+ne*I+oe*O<=0)return!1;if((U*oe-z*ne)*S+(z*re-V*oe)*M+(V*ne-U*re)*C<0)Y=re,K=ne,Q=oe,k=q,G=J,H=$,W=ee,j=te,X=ie,R=(s=U-M)*(c=oe-C)-(l=z-C)*(u=ne-M),I=l*(h=re-S)-(o=V-S)*c,O=o*u-s*h;else if((ne*Q-oe*K)*S+(oe*Y-re*Q)*M+(re*K-ne*Y)*C<0)V=re,U=ne,z=oe,D=q,w=J,L=$,F=ee,N=te,B=ie,R=(s=ne-M)*(c=Q-C)-(l=oe-C)*(u=K-M),I=l*(h=Y-S)-(o=re-S)*c,O=o*u-s*h;else for(var se=!1;;){if(o=Y-V,s=K-U,l=Q-z,h=re-V,u=ne-U,c=oe-z,R=s*c-l*u,I=l*h-o*c,O=o*u-s*h,f=1/a.sqrt(R*R+I*I+O*O),R*=f,I*=f,O*=f,R*V+I*U+O*z>=0&&!se){var ae=(U*Q-z*K)*re+(z*Y-V*Q)*ne+(V*K-U*Y)*oe,le=(ne*Q-oe*K)*S+(oe*Y-re*Q)*M+(re*K-ne*Y)*C,he=(M*z-C*U)*re+(C*V-S*z)*ne+(S*U-M*V)*oe,ue=(K*z-Q*U)*S+(Q*V-Y*z)*M+(Y*U-K*V)*C,ce=ae+le+he+ue;ce<=0&&(ae=0,ce=(le=(K*oe-Q*ne)*R+(Q*re-Y*oe)*I+(Y*ne-K*re)*O)+(he=(ne*Q-oe*K)*R+(oe*Y-re*Q)*I+(re*K-ne*Y)*O)+(ue=(U*Q-z*K)*R+(z*Y-V*Q)*I+(V*K-U*Y)*O));var fe=1/ce;p=(x*ae+D*le+k*he+q*ue)*fe,d=(b*ae+w*le+G*he+J*ue)*fe,m=(T*ae+L*le+H*he+$*ue)*fe,g=(E*ae+F*le+W*he+ee*ue)*fe,v=(A*ae+N*le+j*he+te*ue)*fe,_=(P*ae+B*le+X*he+ie*ue)*fe,se=!0}this.supportPoint(e,-R,-I,-O,y);var pe=y.x,de=y.y,me=y.z;this.supportPoint(t,R,I,O,y);var ge=y.x,ve=y.y,_e=y.z,ye=ge-pe,xe=ve-de,be=_e-me,Te=-(ye*R+xe*I+be*O);if((ye-re)*R+(xe-ne)*I+(be-oe)*O<=.01||Te>=0)return!!se&&(i.init(-R,-I,-O),r.init(.5*(p+g),.5*(d+v),.5*(m+_)),n.x=Te,!0);(xe*z-be*U)*S+(be*V-ye*z)*M+(ye*U-xe*V)*C<0?(xe*Q-be*K)*S+(be*Y-ye*Q)*M+(ye*K-xe*Y)*C<0?(V=ye,U=xe,z=be,D=pe,w=de,L=me,F=ge,N=ve,B=_e):(re=ye,ne=xe,oe=be,q=pe,J=de,$=me,ee=ge,te=ve,ie=_e):(xe*oe-be*ne)*S+(be*re-ye*oe)*M+(ye*ne-xe*re)*C<0?(Y=ye,K=xe,Q=be,k=pe,G=de,H=me,W=ge,j=ve,X=_e):(V=ye,U=xe,z=be,D=pe,w=de,L=me,F=ge,N=ve,B=_e)}}},a.CylinderCylinderCollisionDetector.prototype.supportPoint=function(e,t,i,r,n){var o,s,l,h=e.rotation.elements,u=h[0]*t+h[3]*i+h[6]*r,c=h[1]*t+h[4]*i+h[7]*r,f=h[2]*t+h[5]*i+h[8]*r,p=u,d=f,m=p*p+d*d,g=e.radius,v=e.halfHeight;0==m?c<0?(o=g,s=-v,l=0):(o=g,s=v,l=0):(m=e.radius/a.sqrt(m),c<0?(o=p*m,s=-v,l=d*m):(o=p*m,s=v,l=d*m)),u=h[0]*o+h[1]*s+h[2]*l+e.position.x,c=h[3]*o+h[4]*s+h[5]*l+e.position.y,f=h[6]*o+h[7]*s+h[8]*l+e.position.z,n.init(u,c,f)},a.CylinderCylinderCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n;e.id<t.id?(r=e,n=t):(r=t,n=e);var o,s,l,h,u,c,f,p,d,m,g,v,_,y,x,b,T,E,A,P,S,M=r.position,C=n.position,R=M.x,I=M.y,O=M.z,D=C.x,w=C.y,L=C.z,F=r.halfHeight,N=n.halfHeight,B=r.normalDirection,V=n.normalDirection,U=r.halfDirection,z=n.halfDirection,k=r.radius,G=n.radius,H=B.x,W=B.y,j=B.z,X=V.x,Y=V.y,K=V.z,Q=U.x,Z=U.y,q=U.z,J=z.x,$=z.y,ee=z.z,te=R-D,ie=I-w,re=O-L,ne=new a.Vec3,oe=new a.Vec3,se=new a.Vec3;if(this.getSep(r,n,ne,oe,se)){var ae=ne.x*H+ne.y*W+ne.z*j,le=ne.x*X+ne.y*Y+ne.z*K,he=ae>0,ue=le>0;he||(ae=-ae),ue||(le=-le);var ce=0;(ae>.999||le>.999)&&(ce=ae>le?1:2);var fe,pe,de,me,ge,ve,_e,ye,xe,be,Te,Ee,Ae,Pe,Se,Me,Ce,Re,Ie,Oe,De=se.x;switch(fe=ne.x,pe=ne.y,de=ne.z,ce){case 0:i.addPoint(oe.x,oe.y,oe.z,fe,pe,de,De,!1);break;case 1:if(he?(s=R+Q,l=I+Z,h=O+q,fe=H,pe=W,de=j):(s=R-Q,l=I-Z,h=O-q,fe=-H,pe=-W,de=-j),A=fe*X+pe*Y+de*K,o=A<0?N:-N,u=D+o*X,c=w+o*Y,f=L+o*K,le>=.999999?(p=-pe,d=de,m=fe):(p=fe,d=pe,m=de),o=p*X+d*Y+m*K,te=o*X-p,ie=o*Y-d,re=o*K-m,0==(o=a.sqrt(te*te+ie*ie+re*re)))break;if(o=G/o,te*=o,ie*=o,re*=o,p=u+te,d=c+ie,m=f+re,A<-.96||A>.96)me=X*X*1.5-.5,ge=X*Y*1.5-.866025403*K,ve=X*K*1.5+.866025403*Y,_e=Y*X*1.5+.866025403*K,ye=Y*Y*1.5-.5,xe=Y*K*1.5-.866025403*X,be=K*X*1.5-.866025403*Y,Te=K*Y*1.5+.866025403*X,Ee=K*K*1.5-.5,(o=(p=(Ae=p)-(Me=fe*(Ae-s)+pe*((Pe=d)-l)+de*((Se=m)-h))*fe-s)*p+(d=Pe-Me*pe-l)*d+(m=Se-Me*de-h)*m)>k*k&&(p*=o=k/a.sqrt(o),d*=o,m*=o),Ae=s+p,Pe=l+d,Se=h+m,i.addPoint(Ae,Pe,Se,fe,pe,de,Me,!1),Pe=te*_e+ie*ye+re*xe,Se=te*be+ie*Te+re*Ee,(Me=fe*((Ae=(te=Ae=te*me+ie*ge+re*ve)+u)-s)+pe*((Pe=(ie=Pe)+c)-l)+de*((Se=(re=Se)+f)-h))<=0&&((o=(p=Ae-Me*fe-s)*p+(d=Pe-Me*pe-l)*d+(m=Se-Me*de-h)*m)>k*k&&(p*=o=k/a.sqrt(o),d*=o,m*=o),Ae=s+p,Pe=l+d,Se=h+m,i.addPoint(Ae,Pe,Se,fe,pe,de,Me,!1)),Pe=te*_e+ie*ye+re*xe,Se=te*be+ie*Te+re*Ee,(Me=fe*((Ae=(te=Ae=te*me+ie*ge+re*ve)+u)-s)+pe*((Pe=(ie=Pe)+c)-l)+de*((Se=(re=Se)+f)-h))<=0&&((o=(p=Ae-Me*fe-s)*p+(d=Pe-Me*pe-l)*d+(m=Se-Me*de-h)*m)>k*k&&(p*=o=k/a.sqrt(o),d*=o,m*=o),Ae=s+p,Pe=l+d,Se=h+m,i.addPoint(Ae,Pe,Se,fe,pe,de,Me,!1));else{if(g=p,v=d,_=m,T=fe*(g-s)+pe*(v-l)+de*(_-h),g-=T*fe,v-=T*pe,_-=T*de,A>0?(y=p+X*N*2,x=d+Y*N*2,b=m+K*N*2):(y=p-X*N*2,x=d-Y*N*2,b=m-K*N*2),E=fe*(y-s)+pe*(x-l)+de*(b-h),y-=E*fe,x-=E*pe,b-=E*de,te=s-g,ie=l-v,re=h-_,p=y-g,d=x-v,m=b-_,Ce=te*te+ie*ie+re*re,Re=te*p+ie*d+re*m,Ie=p*p+d*d+m*m,(Oe=Re*Re-Ie*(Ce-k*k))<0)break;(S=(Re-(Oe=a.sqrt(Oe)))/Ie)<(P=(Re+Oe)/Ie)&&(o=P,P=S,S=o),S>1&&(S=1),P<0&&(P=0),p=g+(y-g)*P,d=v+(x-v)*P,m=_+(b-_)*P,y=g+(y-g)*S,x=v+(x-v)*S,b=_+(b-_)*S,g=p,v=d,_=m,o=T+(E-T)*P,E=T+(E-T)*S,(T=o)<0&&i.addPoint(g,v,_,fe,pe,de,Me,!1),E<0&&i.addPoint(y,x,b,fe,pe,de,Me,!1)}break;case 2:if(ue?(u=D-J,c=w-$,f=L-ee,fe=-X,pe=-Y,de=-K):(u=D+J,c=w+$,f=L+ee,fe=X,pe=Y,de=K),A=fe*H+pe*W+de*j,o=A<0?F:-F,s=R+o*H,l=I+o*W,h=O+o*j,ae>=.999999?(p=-pe,d=de,m=fe):(p=fe,d=pe,m=de),o=p*H+d*W+m*j,te=o*H-p,ie=o*W-d,re=o*j-m,0==(o=a.sqrt(te*te+ie*ie+re*re)))break;if(o=k/o,te*=o,ie*=o,re*=o,p=s+te,d=l+ie,m=h+re,A<-.96||A>.96)me=H*H*1.5-.5,ge=H*W*1.5-.866025403*j,ve=H*j*1.5+.866025403*W,_e=W*H*1.5+.866025403*j,ye=W*W*1.5-.5,xe=W*j*1.5-.866025403*H,be=j*H*1.5-.866025403*W,Te=j*W*1.5+.866025403*H,Ee=j*j*1.5-.5,(o=(p=(Ae=p)-(Me=fe*(Ae-u)+pe*((Pe=d)-c)+de*((Se=m)-f))*fe-u)*p+(d=Pe-Me*pe-c)*d+(m=Se-Me*de-f)*m)>G*G&&(p*=o=G/a.sqrt(o),d*=o,m*=o),Ae=u+p,Pe=c+d,Se=f+m,i.addPoint(Ae,Pe,Se,-fe,-pe,-de,Me,!1),Pe=te*_e+ie*ye+re*xe,Se=te*be+ie*Te+re*Ee,(Me=fe*((Ae=(te=Ae=te*me+ie*ge+re*ve)+s)-u)+pe*((Pe=(ie=Pe)+l)-c)+de*((Se=(re=Se)+h)-f))<=0&&((o=(p=Ae-Me*fe-u)*p+(d=Pe-Me*pe-c)*d+(m=Se-Me*de-f)*m)>G*G&&(p*=o=G/a.sqrt(o),d*=o,m*=o),Ae=u+p,Pe=c+d,Se=f+m,i.addPoint(Ae,Pe,Se,-fe,-pe,-de,Me,!1)),Pe=te*_e+ie*ye+re*xe,Se=te*be+ie*Te+re*Ee,(Me=fe*((Ae=(te=Ae=te*me+ie*ge+re*ve)+s)-u)+pe*((Pe=(ie=Pe)+l)-c)+de*((Se=(re=Se)+h)-f))<=0&&((o=(p=Ae-Me*fe-u)*p+(d=Pe-Me*pe-c)*d+(m=Se-Me*de-f)*m)>G*G&&(p*=o=G/a.sqrt(o),d*=o,m*=o),Ae=u+p,Pe=c+d,Se=f+m,i.addPoint(Ae,Pe,Se,-fe,-pe,-de,Me,!1));else{if(g=p,v=d,_=m,T=fe*(g-u)+pe*(v-c)+de*(_-f),g-=T*fe,v-=T*pe,_-=T*de,A>0?(y=p+H*F*2,x=d+W*F*2,b=m+j*F*2):(y=p-H*F*2,x=d-W*F*2,b=m-j*F*2),E=fe*(y-u)+pe*(x-c)+de*(b-f),y-=E*fe,x-=E*pe,b-=E*de,te=u-g,ie=c-v,re=f-_,p=y-g,d=x-v,m=b-_,Ce=te*te+ie*ie+re*re,Re=te*p+ie*d+re*m,Ie=p*p+d*d+m*m,(Oe=Re*Re-Ie*(Ce-G*G))<0)break;(S=(Re-(Oe=a.sqrt(Oe)))/Ie)<(P=(Re+Oe)/Ie)&&(o=P,P=S,S=o),S>1&&(S=1),P<0&&(P=0),p=g+(y-g)*P,d=v+(x-v)*P,m=_+(b-_)*P,y=g+(y-g)*S,x=v+(x-v)*S,b=_+(b-_)*S,g=p,v=d,_=m,o=T+(E-T)*P,E=T+(E-T)*S,(T=o)<0&&i.addPoint(g,v,_,-fe,-pe,-de,T,!1),E<0&&i.addPoint(y,x,b,-fe,-pe,-de,E,!1)}}}},a.SphereCylinderCollisionDetector=function(e){a.CollisionDetector.call(this),this.flip=e},a.SphereCylinderCollisionDetector.prototype=Object.create(a.CollisionDetector.prototype),a.SphereCylinderCollisionDetector.prototype.constructor=a.SphereCylinderCollisionDetector,a.SphereCylinderCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n;this.flip?(r=t,n=e):(r=e,n=t);var o=r.position,s=o.x,l=o.y,h=o.z,u=n.position,c=u.x,f=u.y,p=u.z,d=n.normalDirection.x,m=n.normalDirection.y,g=n.normalDirection.z,v=r.radius,_=n.radius,y=v+_,x=n.halfHeight,b=s-c,T=l-f,E=h-p,A=b*d+T*m+E*g;if(!(A<-x-v||A>x+v)){var P=c+A*d,S=f+A*m,M=p+A*g,C=s-P,R=l-S,I=h-M,O=C*C+R*R+I*I;if(!(O>y*y)){O>_*_&&(C*=O=_/a.sqrt(O),R*=O,I*=O),A<-x?A=-x:A>x&&(A=x);var D;(O=(b=(P=c+A*d+C)-s)*b+(T=(S=f+A*m+R)-l)*T+(E=(M=p+A*g+I)-h)*E)>0&&O<v*v&&(b*=D=1/(O=a.sqrt(O)),T*=D,E*=D,i.addPoint(s+b*v,l+T*v,h+E*v,b,T,E,O-v,this.flip))}}},a.TetraTetraCollisionDetector=function(){a.CollisionDetector.call(this)},a.TetraTetraCollisionDetector.prototype=Object.create(a.CollisionDetector.prototype),a.TetraTetraCollisionDetector.prototype.constructor=a.TetraTetraCollisionDetector,a.TetraTetraCollisionDetector.prototype.detectCollision=function(e,t,i){var r,s,a,l,h,u,c=e.faces,f=e.verts,p=(t.faces,t.verts),d=0,m=c;for(r=0;r<4;r++)for(a=f[r],s=0;s<4;s++)l=p[m[r].a],h=p[m[r].b],u=p[m[r].c],n(o(a.x,a.y),o(l.x,l.y),o(h.x,h.y),o(u.x,u.y))&&n(o(a.x,a.z),o(l.x,l.z),o(h.x,h.z),o(u.x,u.z))&&n(o(a.z,a.y),o(l.z,l.y),o(h.z,h.y),o(u.z,u.y))&&d++,4===d&&i.addPoint(a)},a.AABB=function(e,t,i,r,n,o){this.elements=new s(6);var a=this.elements;a[0]=e||0,a[1]=i||0,a[2]=n||0,a[3]=t||0,a[4]=r||0,a[5]=o||0},a.AABB.prototype={constructor:a.AABB,set:function(e,t,i,r,n,o){var s=this.elements;return s[0]=e,s[3]=t,s[1]=i,s[4]=r,s[2]=n,s[5]=o,this},intersectTest:function(e){var t=this.elements,i=e.elements;return t[0]>i[3]||t[1]>i[4]||t[2]>i[5]||t[3]<i[0]||t[4]<i[1]||t[5]<i[2]},intersectTestTwo:function(e){var t=this.elements,i=e.elements;return t[0]<i[0]||t[1]<i[1]||t[2]<i[2]||t[3]>i[3]||t[4]>i[4]||t[5]>i[5]},clone:function(){return(new this.constructor).fromArray(this.elements)},copy:function(e,t){var i=t||0,r=e.elements;return this.set(r[0]-i,r[3]+i,r[1]-i,r[4]+i,r[2]-i,r[5]+i),this},fromArray:function(e){return this.elements.set(e),this},combine:function(e,t){var i=e.elements,r=t.elements,n=this.elements;return n[0]=i[0]<r[0]?i[0]:r[0],n[1]=i[1]<r[1]?i[1]:r[1],n[2]=i[2]<r[2]?i[2]:r[2],n[3]=i[3]>r[3]?i[3]:r[3],n[4]=i[4]>r[4]?i[4]:r[4],n[5]=i[5]>r[5]?i[5]:r[5],this},surfaceArea:function(){var e=this.elements,t=e[3]-e[0],i=e[4]-e[1],r=e[5]-e[2];return 2*(t*(i+r)+i*r)},intersectsWithPoint:function(e,t,i){var r=this.elements;return e>=r[0]&&e<=r[3]&&t>=r[1]&&t<=r[4]&&i>=r[2]&&i<=r[5]},setFromPoints:function(e){this.makeEmpty();for(var t=0;t<e.length;t++)this.expandByPoint(e[t])},makeEmpty:function(){this.set(-1/0,-1/0,-1/0,1/0,1/0,1/0)},expandByPoint:function(e){var t=this.elements;this.set(a.min(t[0],e.x),a.min(t[1],e.y),a.min(t[2],e.z),a.max(t[3],e.x),a.max(t[4],e.y),a.max(t[5],e.z))}},a.Proxy=function(e){this.shape=e,this.aabb=e.aabb},a.Proxy.prototype={constructor:a.Proxy,update:function(){a.Error("Proxy","Inheritance error.")}},a.BasicProxy=function(e){a.Proxy.call(this,e),this.id=a.proxyID++},a.BasicProxy.prototype=Object.create(a.Proxy.prototype),a.BasicProxy.prototype.constructor=a.BasicProxy,a.BasicProxy.prototype.update=function(){},a.BroadPhase=function(){this.types=a.BR_NULL,this.numPairChecks=0,this.numPairs=0,this.pairs=[]},a.BroadPhase.prototype={constructor:a.BroadPhase,createProxy:function(e){a.Error("BroadPhase","Inheritance error.")},addProxy:function(e){a.Error("BroadPhase","Inheritance error.")},removeProxy:function(e){a.Error("BroadPhase","Inheritance error.")},isAvailablePair:function(e,t){var i=e.parent,r=t.parent;if(i==r||!i.isDynamic&&!r.isDynamic||0==(e.belongsTo&t.collidesWith)||0==(t.belongsTo&e.collidesWith))return!1;var n;for(n=i.numJoints<r.numJoints?i.jointLink:r.jointLink;null!==n;){var o=n.joint;if(!o.allowCollision&&(o.body1==i&&o.body2==r||o.body1==r&&o.body2==i))return!1;n=n.next}return!0},detectPairs:function(){this.pairs=[],this.numPairs=0,this.numPairChecks=0,this.collectPairs()},collectPairs:function(){a.Error("BroadPhase","Inheritance error.")},addPair:function(e,t){var i=new a.Pair(e,t);this.pairs.push(i),this.numPairs++}},a.BruteForceBroadPhase=function(){a.BroadPhase.call(this),this.types=a.BR_BRUTE_FORCE,this.proxies=[]},a.BruteForceBroadPhase.prototype=Object.create(a.BroadPhase.prototype),a.BruteForceBroadPhase.prototype.constructor=a.BruteForceBroadPhase,a.BruteForceBroadPhase.prototype.createProxy=function(e){return new a.BasicProxy(e)},a.BruteForceBroadPhase.prototype.addProxy=function(e){this.proxies.push(e)},a.BruteForceBroadPhase.prototype.removeProxy=function(e){var t=this.proxies.indexOf(e);t>-1&&this.proxies.splice(t,1)},a.BruteForceBroadPhase.prototype.collectPairs=function(){var e,t,i,r=0,n=this.proxies,o=n.length;for(this.numPairChecks=o*(o-1)>>1;r<o;)for(t=n[r++],e=r+1;e<o;)i=n[e++],!t.aabb.intersectTest(i.aabb)&&this.isAvailablePair(t.shape,i.shape)&&this.addPair(t.shape,i.shape)},a.Pair=function(e,t){this.shape1=e||null,this.shape2=t||null},a.SAPAxis=function(){this.numElements=0,this.bufferSize=256,this.elements=[],this.elements.length=this.bufferSize,this.stack=new s(64)},a.SAPAxis.prototype={constructor:a.SAPAxis,addElements:function(e,t){if(this.numElements+2>=this.bufferSize){this.bufferSize*=2;for(var i=[],r=this.numElements;r--;)i[r]=this.elements[r]}this.elements[this.numElements++]=e,this.elements[this.numElements++]=t},removeElements:function(e,t){for(var i=-1,r=-1,n=0,o=this.numElements;n<o;n++){var s=this.elements[n];if(s==e||s==t){if(-1!=i){r=n;break}i=n}}for(n=i+1,o=r;n<o;n++)this.elements[n-1]=this.elements[n];for(n=r+1,o=this.numElements;n<o;n++)this.elements[n-2]=this.elements[n];this.elements[--this.numElements]=null,this.elements[--this.numElements]=null},sort:function(){for(var e=0,t=1;this.numElements>>t!=0;)t++;t=t*this.numElements>>2,e=0;for(var i=!1,r=this.elements,n=1,o=this.numElements;n<o;n++){var s=r[n],l=s.value,h=r[n-1];if(h.value>l){var u=n;do{if(r[u]=h,0==--u)break;h=r[u-1]}while(h.value>l);if(r[u]=s,(e+=n-u)>t){i=!0;break}}}if(i){e=2;var c=this.stack;for(c[0]=0,c[1]=this.numElements-1;e>0;){var f=c[--e],p=c[--e],d=f-p;if(d>16){var m=p+a.floor(.5*d);for(s=r[m],r[m]=r[f],r[f]=s,l=s.value,n=p-1,u=f;;){var g,v;do{g=r[++n]}while(g.value<l);do{v=r[--u]}while(l<v.value&&u!=p);if(n>=u)break;r[n]=v,r[u]=g}r[f]=r[n],r[n]=s,n-p>f-n?(c[e++]=p,c[e++]=n-1,c[e++]=n+1,c[e++]=f):(c[e++]=n+1,c[e++]=f,c[e++]=p,c[e++]=n-1)}else for(n=p+1;n<=f;n++)if(s=r[n],l=s.value,(h=r[n-1]).value>l){u=n;do{if(r[u]=h,0==--u)break;h=r[u-1]}while(h.value>l);r[u]=s}}}},calculateTestCount:function(){for(var e=1,t=0,i=1,r=this.numElements;i<r;i++)this.elements[i].max?e--:(t+=e,e++);return t}},a.SAPBroadPhase=function(){a.BroadPhase.call(this),this.types=a.BR_SWEEP_AND_PRUNE,this.numElementsD=0,this.numElementsS=0,this.axesD=[new a.SAPAxis,new a.SAPAxis,new a.SAPAxis],this.axesS=[new a.SAPAxis,new a.SAPAxis,new a.SAPAxis],this.index1=0,this.index2=1},a.SAPBroadPhase.prototype=Object.create(a.BroadPhase.prototype),a.SAPBroadPhase.prototype.constructor=a.SAPBroadPhase,a.SAPBroadPhase.prototype.createProxy=function(e){return new a.SAPProxy(this,e)},a.SAPBroadPhase.prototype.addProxy=function(e){var t=e;t.isDynamic()?(this.axesD[0].addElements(t.min[0],t.max[0]),this.axesD[1].addElements(t.min[1],t.max[1]),this.axesD[2].addElements(t.min[2],t.max[2]),t.belongsTo=1,this.numElementsD+=2):(this.axesS[0].addElements(t.min[0],t.max[0]),this.axesS[1].addElements(t.min[1],t.max[1]),this.axesS[2].addElements(t.min[2],t.max[2]),t.belongsTo=2,this.numElementsS+=2)},a.SAPBroadPhase.prototype.removeProxy=function(e){var t=e;if(0!=t.belongsTo){switch(t.belongsTo){case 1:this.axesD[0].removeElements(t.min[0],t.max[0]),this.axesD[1].removeElements(t.min[1],t.max[1]),this.axesD[2].removeElements(t.min[2],t.max[2]),this.numElementsD-=2;break;case 2:this.axesS[0].removeElements(t.min[0],t.max[0]),this.axesS[1].removeElements(t.min[1],t.max[1]),this.axesS[2].removeElements(t.min[2],t.max[2]),this.numElementsS-=2}t.belongsTo=0}},a.SAPBroadPhase.prototype.collectPairs=function(){if(0!=this.numElementsD){var e=this.axesD[this.index1],t=this.axesD[this.index2];e.sort(),t.sort();var i,r;e.calculateTestCount()<=t.calculateTestCount()?((t=this.axesS[this.index1]).sort(),i=e.elements,r=t.elements):((e=this.axesS[this.index2]).sort(),i=t.elements,r=e.elements,this.index1^=this.index2,this.index2^=this.index1,this.index1^=this.index2);for(var n,o,s=0,a=0;s<this.numElementsD;){var l,h;if(a==this.numElementsS)l=i[s],h=!0,s++;else{var u=i[s],c=r[a];u.value<c.value?(l=u,h=!0,s++):(l=c,h=!1,a++)}if(l.max){var f=l.pair;if(h){if(f==n){n=n.pair;continue}l=n}else{if(f==o){o=o.pair;continue}l=o}do{if((_=l.pair)==f){l.pair=_.pair;break}l=_}while(null!=l)}else{for(var p=l.proxy.shape,d=l.min1.value,m=l.max1.value,g=l.min2.value,v=l.max2.value,_=n;null!=_;_=_.pair){var y=_.proxy.shape;this.numPairChecks++,d>_.max1.value||m<_.min1.value||g>_.max2.value||v<_.min2.value||!this.isAvailablePair(p,y)||this.addPair(p,y)}if(h){for(_=o;null!=_;_=_.pair)y=_.proxy.shape,this.numPairChecks++,d>_.max1.value||m<_.min1.value||g>_.max2.value||v<_.min2.value||!this.isAvailablePair(p,y)||this.addPair(p,y);l.pair=n,n=l}else l.pair=o,o=l}}this.index2=3^(this.index1|this.index2)}},a.SAPElement=function(e,t){this.proxy=e,this.pair=null,this.min1=null,this.max1=null,this.min2=null,this.max2=null,this.max=t,this.value=0},a.SAPProxy=function(e,t){a.Proxy.call(this,t),this.belongsTo=0,this.max=[],this.min=[],this.sap=e,this.min[0]=new a.SAPElement(this,!1),this.max[0]=new a.SAPElement(this,!0),this.min[1]=new a.SAPElement(this,!1),this.max[1]=new a.SAPElement(this,!0),this.min[2]=new a.SAPElement(this,!1),this.max[2]=new a.SAPElement(this,!0),this.max[0].pair=this.min[0],this.max[1].pair=this.min[1],this.max[2].pair=this.min[2],this.min[0].min1=this.min[1],this.min[0].max1=this.max[1],this.min[0].min2=this.min[2],this.min[0].max2=this.max[2],this.min[1].min1=this.min[0],this.min[1].max1=this.max[0],this.min[1].min2=this.min[2],this.min[1].max2=this.max[2],this.min[2].min1=this.min[0],this.min[2].max1=this.max[0],this.min[2].min2=this.min[1],this.min[2].max2=this.max[1]},a.SAPProxy.prototype=Object.create(a.Proxy.prototype),a.SAPProxy.prototype.constructor=a.SAPProxy,a.SAPProxy.prototype.isDynamic=function(){var e=this.shape.parent;return e.isDynamic&&!e.sleeping},a.SAPProxy.prototype.update=function(){var e=this.aabb.elements;this.min[0].value=e[0],this.min[1].value=e[1],this.min[2].value=e[2],this.max[0].value=e[3],this.max[1].value=e[4],this.max[2].value=e[5],(1==this.belongsTo&&!this.isDynamic()||2==this.belongsTo&&this.isDynamic())&&(this.sap.removeProxy(this),this.sap.addProxy(this))},a.DBVT=function(){this.root=null,this.freeNodes=[],this.freeNodes.length=16384,this.numFreeNodes=0,this.aabb=new a.AABB},a.DBVT.prototype={constructor:a.DBVT,moveLeaf:function(e){this.deleteLeaf(e),this.insertLeaf(e)},insertLeaf:function(e){if(null!=this.root){for(var t,i,r=e.aabb,n=this.root;null==n.proxy;){var o=n.child1,s=n.child2,l=n.aabb,h=o.aabb,u=s.aabb;t=l.surfaceArea(),this.aabb.combine(r,l);var c=2*(i=this.aabb.surfaceArea()),f=2*(i-t),p=f;this.aabb.combine(r,h),null!=o.proxy?p+=this.aabb.surfaceArea():p+=this.aabb.surfaceArea()-h.surfaceArea();var d=f;if(this.aabb.combine(r,u),null!=s.proxy?d+=this.aabb.surfaceArea():d+=this.aabb.surfaceArea()-u.surfaceArea(),p<d){if(c<p)break;n=o}else{if(c<d)break;n=s}}var m,g=n.parent;(m=this.numFreeNodes>0?this.freeNodes[--this.numFreeNodes]:new a.DBVTNode).parent=g,m.child1=e,m.child2=n,m.aabb.combine(e.aabb,n.aabb),m.height=n.height+1,n.parent=m,e.parent=m,n==this.root?this.root=m:g.child1==n?g.child1=m:g.child2=m;do{m=this.balance(m),this.fix(m),m=m.parent}while(null!=m)}else this.root=e},getBalance:function(e){return null!=e.proxy?0:e.child1.height-e.child2.height},deleteLeaf:function(e){if(e!=this.root){var t,i=e.parent;if(t=i.child1==e?i.child2:i.child1,i==this.root)return this.root=t,void(t.parent=null);var r=i.parent;t.parent=r,r.child1==i?r.child1=t:r.child2=t,this.numFreeNodes<16384&&(this.freeNodes[this.numFreeNodes++]=i);do{r=this.balance(r),this.fix(r),r=r.parent}while(null!=r)}else this.root=null},balance:function(e){var t=e.height;if(t<2)return e;var i,r=e.parent,n=e.child1,o=e.child2,s=n.height,a=o.height,l=s-a;if(l>1){var h=n.child1,u=n.child2,c=h.height,f=u.height;return c>f?(n.child2=e,e.parent=n,e.child1=u,u.parent=e,e.aabb.combine(u.aabb,o.aabb),i=f-a,e.height=f-(i&i>>31)+1,n.aabb.combine(h.aabb,e.aabb),i=c-t,n.height=c-(i&i>>31)+1):(n.child1=e,e.parent=n,e.child1=h,h.parent=e,e.aabb.combine(h.aabb,o.aabb),i=c-a,e.height=c-(i&i>>31)+1,n.aabb.combine(e.aabb,u.aabb),i=t-f,n.height=t-(i&i>>31)+1),null!=r?r.child1==e?r.child1=n:r.child2=n:this.root=n,n.parent=r,n}if(l<-1){var p=o.child1,d=o.child2,m=p.height,g=d.height;return m>g?(o.child2=e,e.parent=o,e.child2=d,d.parent=e,e.aabb.combine(n.aabb,d.aabb),i=s-g,e.height=s-(i&i>>31)+1,o.aabb.combine(p.aabb,e.aabb),i=m-t,o.height=m-(i&i>>31)+1):(o.child1=e,e.parent=o,e.child2=p,p.parent=e,e.aabb.combine(n.aabb,p.aabb),i=s-m,e.height=s-(i&i>>31)+1,o.aabb.combine(e.aabb,d.aabb),i=t-g,o.height=t-(i&i>>31)+1),null!=r?r.child1==e?r.child1=o:r.child2=o:this.root=o,o.parent=r,o}return e},fix:function(e){var t=e.child1,i=e.child2;e.aabb.combine(t.aabb,i.aabb),e.height=t.height<i.height?i.height+1:t.height+1}},a.DBVTBroadPhase=function(){a.BroadPhase.call(this),this.types=a.BR_BOUNDING_VOLUME_TREE,this.tree=new a.DBVT,this.stack=[],this.leaves=[],this.numLeaves=0},a.DBVTBroadPhase.prototype=Object.create(a.BroadPhase.prototype),a.DBVTBroadPhase.prototype.constructor=a.DBVTBroadPhase,a.DBVTBroadPhase.prototype.createProxy=function(e){return new a.DBVTProxy(e)},a.DBVTBroadPhase.prototype.addProxy=function(e){this.tree.insertLeaf(e.leaf),this.leaves.push(e.leaf),this.numLeaves++},a.DBVTBroadPhase.prototype.removeProxy=function(e){this.tree.deleteLeaf(e.leaf);var t=this.leaves.indexOf(e.leaf);t>-1&&(this.leaves.splice(t,1),this.numLeaves--)},a.DBVTBroadPhase.prototype.collectPairs=function(){if(!(this.numLeaves<2))for(var e,t=this.numLeaves;t--;)(e=this.leaves[t]).proxy.aabb.intersectTestTwo(e.aabb)&&(e.aabb.copy(e.proxy.aabb,.1),this.tree.deleteLeaf(e),this.tree.insertLeaf(e),this.collide(e,this.tree.root))},a.DBVTBroadPhase.prototype.collide=function(e,t){var i,r,n,o,s,a,l=2;for(this.stack[0]=e,this.stack[1]=t;l>0;)if(n=this.stack[--l],o=this.stack[--l],s=null!=n.proxy,a=null!=o.proxy,this.numPairChecks++,s&&a){if(i=n.proxy.shape,r=o.proxy.shape,i==r||i.aabb.intersectTest(r.aabb)||!this.isAvailablePair(i,r))continue;this.addPair(i,r)}else{if(n.aabb.intersectTest(o.aabb))continue;a||!s&&n.aabb.surfaceArea()>o.aabb.surfaceArea()?(this.stack[l++]=n.child1,this.stack[l++]=o,this.stack[l++]=n.child2,this.stack[l++]=o):(this.stack[l++]=n,this.stack[l++]=o.child1,this.stack[l++]=n,this.stack[l++]=o.child2)}},a.DBVTNode=function(){this.child1=null,this.child2=null,this.parent=null,this.proxy=null,this.height=0,this.aabb=new a.AABB},a.DBVTProxy=function(e){a.Proxy.call(this,e),this.leaf=new a.DBVTNode,this.leaf.proxy=this},a.DBVTProxy.prototype=Object.create(a.Proxy.prototype),a.DBVTProxy.prototype.constructor=a.DBVTProxy,a.DBVTProxy.prototype.update=function(){},a.World.prototype.add=function(e){var t=(e=e||{}).type||"box";if("string"==typeof t&&(t=[t]),"joint"==t[0].substring(0,5)){"joint"===t[0]&&(t[0]="jointHinge");var i=e.axe1||[1,0,0],r=e.axe2||[1,0,0],n=e.pos1||[0,0,0],o=e.pos2||[0,0,0];n=n.map(function(e){return e*a.INV_SCALE}),o=o.map(function(e){return e*a.INV_SCALE});var s,l;"jointDistance"===t[0]?(s=e.min||0,l=e.max||10,s*=a.INV_SCALE,l*=a.INV_SCALE):(s=e.min||57.29578,l=e.max||0,s*=a.degtorad,l*=a.degtorad);var h=e.limit||null,u=e.spring||null,c=e.motor||null,f=new a.JointConfig;f.allowCollision=e.collision||!1,f.localAxis1.init(i[0],i[1],i[2]),f.localAxis2.init(r[0],r[1],r[2]),f.localAnchorPoint1.init(n[0],n[1],n[2]),f.localAnchorPoint2.init(o[0],o[1],o[2]),("string"==typeof e.body1||e.body1 instanceof String)&&(e.body1=this.getByName(e.body1)),("string"==typeof e.body2||e.body2 instanceof String)&&(e.body2=this.getByName(e.body2)),f.body1=e.body1,f.body2=e.body2;var p;switch(t[0]){case"jointDistance":p=new a.DistanceJoint(f,s,l),null!==u&&p.limitMotor.setSpring(u[0],u[1]),null!==c&&p.limitMotor.setSpring(c[0],c[1]);break;case"jointHinge":p=new a.HingeJoint(f,s,l),null!==u&&p.limitMotor.setSpring(u[0],u[1]),null!==c&&p.limitMotor.setSpring(c[0],c[1]);break;case"jointPrisme":p=new a.PrismaticJoint(f,s,l);break;case"jointSlide":p=new a.SliderJoint(f,s,l);break;case"jointBall":p=new a.BallAndSocketJoint(f);break;case"jointWheel":p=new a.WheelJoint(f),null!==h&&p.rotationalLimitMotor1.setLimit(h[0],h[1]),null!==u&&p.rotationalLimitMotor1.setSpring(u[0],u[1]),null!==c&&p.rotationalLimitMotor1.setSpring(c[0],c[1])}return p.name=e.name||"",this.addJoint(p),p}var d=e.move||!1,m=e.noSleep||!1,g=e.pos||[0,0,0];g=g.map(function(e){return e*a.INV_SCALE});var v=e.size||[1,1,1];v=v.map(function(e){return e*a.INV_SCALE});var _=e.rot||[0,0,0];_=_.map(function(e){return e*a.degtorad});for(var y=[],x=0;x<_.length/3;x++){var b=a.EulerToAxis(_[x+0],_[x+1],_[x+2]);y.push(b[0]),y.push(b[1]),y.push(b[2]),y.push(b[3])}var T=new a.ShapeConfig;void 0!==e.sc&&(T=e.sc),e.config&&(T.density=void 0===e.config[0]?1:e.config[0],T.friction=void 0===e.config[1]?.4:e.config[1],T.restitution=void 0===e.config[2]?.2:e.config[2],T.belongsTo=e.config[3]||1,T.collidesWith=e.config[4]||4294967295),void 0!==e.density&&(T.density=e.density),void 0!==e.friction&&(T.friction=e.friction),void 0!==e.restitution&&(T.restitution=e.restitution),void 0!==e.belongsTo&&(T.belongsTo=e.belongsTo),void 0!==e.collidesWith&&(T.collidesWith=e.collidesWith),e.massPos&&(e.massPos=e.massPos.map(function(e){return e*a.INV_SCALE}),T.relativePosition.init(e.massPos[0],e.massPos[1],e.massPos[2])),e.massRot&&(e.massRot=e.massRot.map(function(e){return e*a.degtorad}),T.relativeRotation=a.EulerToMatrix(e.massRot[0],e.massRot[1],e.massRot[2]));for(var E,A,P=new a.RigidBody(g[0],g[1],g[2],y[0],y[1],y[2],y[3]),S=[],x=0;x<t.length;x++){switch(E=3*x,A=4*x,t[x]){case"sphere":S[x]=new a.SphereShape(T,v[E]);break;case"cylinder":S[x]=new a.CylinderShape(T,v[E],v[E+1]);break;case"box":S[x]=new a.BoxShape(T,v[E],v[E+1],v[E+2])}P.addShape(S[x]),x>0&&(S[x].relativePosition=new a.Vec3(g[E],g[E+1],g[E+2]),y[A+0]&&(S[x].relativeRotation=[y[A],y[A+1],y[A+2],y[A+3]]))}return d?(e.massPos||e.massRot?P.setupMass(1,!1):P.setupMass(1,!0),P.allowSleep=!m):P.setupMass(2),P.name=e.name||" ",this.addRigidBody(P),P};var l=this;l.OIMO||(e.exports=a)},function(e,t,i){"use strict";function r(e){if(e){if(e.html)return Promise.resolve(e.html);var t=n(e);if(s.isUrl(t))return s.loadFile(t);t=t.replace("#","");var i=document.getElementById(t);return i?Promise.resolve(i.innerHTML):Promise.reject("Template ID not found")}return Promise.reject("No templateConfig provided")}function n(e){return e&&"string"!=typeof e?e.location:e}Object.defineProperty(t,"__esModule",{value:!0});var o=i(0),s=i(3),a=function(){function e(e){this.containerElement=e,this.templates={},this.onInit=new o.Observable,this.onLoaded=new o.Observable,this.onStateChange=new o.Observable,this.onAllLoaded=new o.Observable}return e.prototype.initTemplate=function(e){var t=this,i=function(e,r,n){var o=t.templates[r],a=(Object.keys(e).map(function(t){return i(e[t],t,o)}),function(){var e=n&&n.parent.querySelector(s.camelToKebab(r))||t.containerElement;o.appendTo(e),t.checkLoadedState()});return n&&!n.parent?n.onAppended.add(function(){a()}):a(),o};this.buildHTMLTree(e).then(function(e){i(e,"main")})},e.prototype.buildHTMLTree=function(e){var t=this,i=Object.keys(e).map(function(i){var r=new h(i,e[i]);return t.templates[i]=r,r.initPromise});return Promise.all(i).then(function(){var e={},i=function(e,r){t.templates[r].getChildElements().filter(function(e){return!!t.templates[e]}).forEach(function(t){e[t]={},i(e[t],t)})};return i(e,"main"),e})},e.prototype.getCanvas=function(){return this.containerElement.querySelector("canvas")},e.prototype.getTemplate=function(e){return this.templates[e]},e.prototype.checkLoadedState=function(){var e=this;Object.keys(this.templates).every(function(t){return e.templates[t].isLoaded&&!!e.templates[t].parent})&&this.onAllLoaded.notifyObservers(this)},e}();t.TemplateManager=a;var l=i(18),h=function(){function e(e,t){var i=this;this.name=e,this._configuration=t,this.onInit=new o.Observable,this.onLoaded=new o.Observable,this.onAppended=new o.Observable,this.onStateChange=new o.Observable,this.onEventTriggered=new o.Observable,this.isLoaded=!1,this.onInit.notifyObservers(this);var n=r(t);this.initPromise=n.then(function(e){if(e){var t=l.compile(e)(i._configuration.params||{});i.fragment=document.createRange().createContextualFragment(t),i.isLoaded=!0,i.onLoaded.notifyObservers(i)}return i})}return Object.defineProperty(e.prototype,"configuration",{get:function(){return this._configuration},enumerable:!0,configurable:!0}),e.prototype.getChildElements=function(){var e=[],t=this.fragment.children;t||(t=this.fragment.querySelectorAll("*"));for(var i=0;i<t.length;++i)e.push(s.kebabToCamel(t.item(i).nodeName.toLowerCase()));return e},e.prototype.appendTo=function(e){var t=this;this.parent?console.error("Already appanded to ",this.parent):(this.parent=e,this._configuration.id&&(this.parent.id=this._configuration.id),this.parent.appendChild(this.fragment),setTimeout(function(){t.registerEvents(),t.onAppended.notifyObservers(t)}))},e.prototype.show=function(e){var t=this;return e?e(this).then(function(){return t.onStateChange.notifyObservers(t),t}):(this.parent.style.display="flex",this.onStateChange.notifyObservers(this),Promise.resolve(this))},e.prototype.hide=function(e){var t=this;return e?e(this).then(function(){return t.onStateChange.notifyObservers(t),t}):(this.parent.style.display="none",this.onStateChange.notifyObservers(this),Promise.resolve(this))},e.prototype.registerEvents=function(){var e=this;if(this._configuration.events){var t=function(t){if(i._configuration.events&&i._configuration.events[t]){var r=function(t,i){e.onEventTriggered.notifyObservers({event:i,template:e,selector:t})};if("boolean"==typeof i._configuration.events[t])i.parent.addEventListener(t,r.bind(i,"#"+i.parent.id),!1);else if("object"==typeof i._configuration.events[t]){var n=Object.keys(i._configuration.events[t]||{}),o=i._configuration.events[t]||{};n.filter(function(e){return o[e]}).forEach(function(i){0!==i.indexOf("#")&&(i="#"+i);var n=e.parent.querySelector(i);n&&n.addEventListener(t,r.bind(e,i),!1)})}}},i=this;for(var r in this._configuration.events)t(r)}},e}();t.Template=h,t.getTemplateAsHtml=r,t.getTemplateLocation=n},function(e,t,i){/**!
  2. @license
  3. handlebars v4.0.11
  4. Copyright (C) 2011-2017 by Yehuda Katz
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. */
  21. !function(t,i){e.exports=i()}(0,function(){return function(e){function t(r){if(i[r])return i[r].exports;var n=i[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t,i){"use strict";function r(){var e=f();return e.compile=function(t,i){return l.compile(t,i,e)},e.precompile=function(t,i){return l.precompile(t,i,e)},e.AST=s.default,e.Compiler=l.Compiler,e.JavaScriptCompiler=h.default,e.Parser=a.parser,e.parse=a.parse,e}var n=i(1).default;t.__esModule=!0;var o=n(i(2)),s=n(i(35)),a=i(36),l=i(41),h=n(i(42)),u=n(i(39)),c=n(i(34)),f=o.default.create,p=r();p.create=r,c.default(p),p.Visitor=u.default,p.default=p,t.default=p,e.exports=t.default},function(e,t){"use strict";t.default=function(e){return e&&e.__esModule?e:{default:e}},t.__esModule=!0},function(e,t,i){"use strict";function r(){var e=new s.HandlebarsEnvironment;return h.extend(e,s),e.SafeString=a.default,e.Exception=l.default,e.Utils=h,e.escapeExpression=h.escapeExpression,e.VM=u,e.template=function(t){return u.template(t,e)},e}var n=i(3).default,o=i(1).default;t.__esModule=!0;var s=n(i(4)),a=o(i(21)),l=o(i(6)),h=n(i(5)),u=n(i(22)),c=o(i(34)),f=r();f.create=r,c.default(f),f.default=f,t.default=f,e.exports=t.default},function(e,t){"use strict";t.default=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t.default=e,t},t.__esModule=!0},function(e,t,i){"use strict";function r(e,t,i){this.helpers=e||{},this.partials=t||{},this.decorators=i||{},a.registerDefaultHelpers(this),l.registerDefaultDecorators(this)}var n=i(1).default;t.__esModule=!0,t.HandlebarsEnvironment=r;var o=i(5),s=n(i(6)),a=i(10),l=i(18),h=n(i(20));t.VERSION="4.0.11";t.COMPILER_REVISION=7;t.REVISION_CHANGES={1:"<= 1.0.rc.2",2:"== 1.0.0-rc.3",3:"== 1.0.0-rc.4",4:"== 1.x.x",5:"== 2.0.0-alpha.x",6:">= 2.0.0-beta.1",7:">= 4.0.0"};var u="[object Object]";r.prototype={constructor:r,logger:h.default,log:h.default.log,registerHelper:function(e,t){if(o.toString.call(e)===u){if(t)throw new s.default("Arg not supported with multiple helpers");o.extend(this.helpers,e)}else this.helpers[e]=t},unregisterHelper:function(e){delete this.helpers[e]},registerPartial:function(e,t){if(o.toString.call(e)===u)o.extend(this.partials,e);else{if(void 0===t)throw new s.default('Attempting to register a partial called "'+e+'" as undefined');this.partials[e]=t}},unregisterPartial:function(e){delete this.partials[e]},registerDecorator:function(e,t){if(o.toString.call(e)===u){if(t)throw new s.default("Arg not supported with multiple decorators");o.extend(this.decorators,e)}else this.decorators[e]=t},unregisterDecorator:function(e){delete this.decorators[e]}};var c=h.default.log;t.log=c,t.createFrame=o.createFrame,t.logger=h.default},function(e,t){"use strict";function i(e){return n[e]}function r(e){for(var t=1;t<arguments.length;t++)for(var i in arguments[t])Object.prototype.hasOwnProperty.call(arguments[t],i)&&(e[i]=arguments[t][i]);return e}t.__esModule=!0,t.extend=r,t.indexOf=function(e,t){for(var i=0,r=e.length;i<r;i++)if(e[i]===t)return i;return-1},t.escapeExpression=function(e){if("string"!=typeof e){if(e&&e.toHTML)return e.toHTML();if(null==e)return"";if(!e)return e+"";e=""+e}return s.test(e)?e.replace(o,i):e},t.isEmpty=function(e){return!e&&0!==e||!(!h(e)||0!==e.length)},t.createFrame=function(e){var t=r({},e);return t._parent=e,t},t.blockParams=function(e,t){return e.path=t,e},t.appendContextPath=function(e,t){return(e?e+".":"")+t};var n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;","=":"&#x3D;"},o=/[&<>"'`=]/g,s=/[&<>"'`=]/,a=Object.prototype.toString;t.toString=a;var l=function(e){return"function"==typeof e};l(/x/)&&(t.isFunction=l=function(e){return"function"==typeof e&&"[object Function]"===a.call(e)}),t.isFunction=l;var h=Array.isArray||function(e){return!(!e||"object"!=typeof e)&&"[object Array]"===a.call(e)};t.isArray=h},function(e,t,i){"use strict";function r(e,t){var i=t&&t.loc,s=void 0,a=void 0;i&&(s=i.start.line,a=i.start.column,e+=" - "+s+":"+a);for(var l=Error.prototype.constructor.call(this,e),h=0;h<o.length;h++)this[o[h]]=l[o[h]];Error.captureStackTrace&&Error.captureStackTrace(this,r);try{i&&(this.lineNumber=s,n?Object.defineProperty(this,"column",{value:a,enumerable:!0}):this.column=a)}catch(e){}}var n=i(7).default;t.__esModule=!0;var o=["description","fileName","lineNumber","message","name","number","stack"];r.prototype=new Error,t.default=r,e.exports=t.default},function(e,t,i){e.exports={default:i(8),__esModule:!0}},function(e,t,i){var r=i(9);e.exports=function(e,t,i){return r.setDesc(e,t,i)}},function(e,t){var i=Object;e.exports={create:i.create,getProto:i.getPrototypeOf,isEnum:{}.propertyIsEnumerable,getDesc:i.getOwnPropertyDescriptor,setDesc:i.defineProperty,setDescs:i.defineProperties,getKeys:i.keys,getNames:i.getOwnPropertyNames,getSymbols:i.getOwnPropertySymbols,each:[].forEach}},function(e,t,i){"use strict";var r=i(1).default;t.__esModule=!0,t.registerDefaultHelpers=function(e){n.default(e),o.default(e),s.default(e),a.default(e),l.default(e),h.default(e),u.default(e)};var n=r(i(11)),o=r(i(12)),s=r(i(13)),a=r(i(14)),l=r(i(15)),h=r(i(16)),u=r(i(17))},function(e,t,i){"use strict";t.__esModule=!0;var r=i(5);t.default=function(e){e.registerHelper("blockHelperMissing",function(t,i){var n=i.inverse,o=i.fn;if(!0===t)return o(this);if(!1===t||null==t)return n(this);if(r.isArray(t))return t.length>0?(i.ids&&(i.ids=[i.name]),e.helpers.each(t,i)):n(this);if(i.data&&i.ids){var s=r.createFrame(i.data);s.contextPath=r.appendContextPath(i.data.contextPath,i.name),i={data:s}}return o(t,i)})},e.exports=t.default},function(e,t,i){"use strict";var r=i(1).default;t.__esModule=!0;var n=i(5),o=r(i(6));t.default=function(e){e.registerHelper("each",function(e,t){function i(t,i,o){h&&(h.key=t,h.index=i,h.first=0===i,h.last=!!o,u&&(h.contextPath=u+t)),l+=r(e[t],{data:h,blockParams:n.blockParams([e[t],t],[u+t,null])})}if(!t)throw new o.default("Must pass iterator to #each");var r=t.fn,s=t.inverse,a=0,l="",h=void 0,u=void 0;if(t.data&&t.ids&&(u=n.appendContextPath(t.data.contextPath,t.ids[0])+"."),n.isFunction(e)&&(e=e.call(this)),t.data&&(h=n.createFrame(t.data)),e&&"object"==typeof e)if(n.isArray(e))for(var c=e.length;a<c;a++)a in e&&i(a,a,a===e.length-1);else{var f=void 0;for(var p in e)e.hasOwnProperty(p)&&(void 0!==f&&i(f,a-1),f=p,a++);void 0!==f&&i(f,a-1,!0)}return 0===a&&(l=s(this)),l})},e.exports=t.default},function(e,t,i){"use strict";var r=i(1).default;t.__esModule=!0;var n=r(i(6));t.default=function(e){e.registerHelper("helperMissing",function(){if(1!==arguments.length)throw new n.default('Missing helper: "'+arguments[arguments.length-1].name+'"')})},e.exports=t.default},function(e,t,i){"use strict";t.__esModule=!0;var r=i(5);t.default=function(e){e.registerHelper("if",function(e,t){return r.isFunction(e)&&(e=e.call(this)),!t.hash.includeZero&&!e||r.isEmpty(e)?t.inverse(this):t.fn(this)}),e.registerHelper("unless",function(t,i){return e.helpers.if.call(this,t,{fn:i.inverse,inverse:i.fn,hash:i.hash})})},e.exports=t.default},function(e,t){"use strict";t.__esModule=!0,t.default=function(e){e.registerHelper("log",function(){for(var t=[void 0],i=arguments[arguments.length-1],r=0;r<arguments.length-1;r++)t.push(arguments[r]);var n=1;null!=i.hash.level?n=i.hash.level:i.data&&null!=i.data.level&&(n=i.data.level),t[0]=n,e.log.apply(e,t)})},e.exports=t.default},function(e,t){"use strict";t.__esModule=!0,t.default=function(e){e.registerHelper("lookup",function(e,t){return e&&e[t]})},e.exports=t.default},function(e,t,i){"use strict";t.__esModule=!0;var r=i(5);t.default=function(e){e.registerHelper("with",function(e,t){r.isFunction(e)&&(e=e.call(this));var i=t.fn;if(r.isEmpty(e))return t.inverse(this);var n=t.data;return t.data&&t.ids&&(n=r.createFrame(t.data),n.contextPath=r.appendContextPath(t.data.contextPath,t.ids[0])),i(e,{data:n,blockParams:r.blockParams([e],[n&&n.contextPath])})})},e.exports=t.default},function(e,t,i){"use strict";var r=i(1).default;t.__esModule=!0,t.registerDefaultDecorators=function(e){n.default(e)};var n=r(i(19))},function(e,t,i){"use strict";t.__esModule=!0;var r=i(5);t.default=function(e){e.registerDecorator("inline",function(e,t,i,n){var o=e;return t.partials||(t.partials={},o=function(n,o){var s=i.partials;i.partials=r.extend({},s,t.partials);var a=e(n,o);return i.partials=s,a}),t.partials[n.args[0]]=n.fn,o})},e.exports=t.default},function(e,t,i){"use strict";t.__esModule=!0;var r=i(5),n={methodMap:["debug","info","warn","error"],level:"info",lookupLevel:function(e){if("string"==typeof e){var t=r.indexOf(n.methodMap,e.toLowerCase());e=t>=0?t:parseInt(e,10)}return e},log:function(e){if(e=n.lookupLevel(e),"undefined"!=typeof console&&n.lookupLevel(n.level)<=e){var t=n.methodMap[e];console[t]||(t="log");for(var i=arguments.length,r=Array(i>1?i-1:0),o=1;o<i;o++)r[o-1]=arguments[o];console[t].apply(console,r)}}};t.default=n,e.exports=t.default},function(e,t){"use strict";function i(e){this.string=e}t.__esModule=!0,i.prototype.toString=i.prototype.toHTML=function(){return""+this.string},t.default=i,e.exports=t.default},function(e,t,i){"use strict";function r(e,t,i,r,n,o,a){function l(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],s=a;return!a||t==a[0]||t===e.nullContext&&null===a[0]||(s=[t].concat(a)),i(e,t,e.helpers,e.partials,n.data||r,o&&[n.blockParams].concat(o),s)}return l=s(i,l,e,a,r,o),l.program=t,l.depth=a?a.length:0,l.blockParams=n||0,l}function n(){return""}function o(e,t){return t&&"root"in t||(t=t?f.createFrame(t):{},t.root=e),t}function s(e,t,i,r,n,o){if(e.decorator){var s={};t=e.decorator(t,s,i,r&&r[0],n,o,r),u.extend(t,s)}return t}var a=i(23).default,l=i(3).default,h=i(1).default;t.__esModule=!0,t.checkRevision=function(e){var t=e&&e[0]||1,i=f.COMPILER_REVISION;if(t!==i){if(t<i){var r=f.REVISION_CHANGES[i],n=f.REVISION_CHANGES[t];throw new c.default("Template was precompiled with an older version of Handlebars than the current runtime. Please update your precompiler to a newer version ("+r+") or downgrade your runtime to an older version ("+n+").")}throw new c.default("Template was precompiled with a newer version of Handlebars than the current runtime. Please update your runtime to a newer version ("+e[1]+").")}},t.template=function(e,t){function i(t){function r(t){return""+e.main(n,t,n.helpers,n.partials,l,u,h)}var a=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],l=a.data;i._setup(a),!a.partial&&e.useData&&(l=o(t,l));var h=void 0,u=e.useBlockParams?[]:void 0;return e.useDepths&&(h=a.depths?t!=a.depths[0]?[t].concat(a.depths):a.depths:[t]),(r=s(e.main,r,n,a.depths||[],l,u))(t,a)}if(!t)throw new c.default("No environment passed to template");if(!e||!e.main)throw new c.default("Unknown template object: "+typeof e);e.main.decorator=e.main_d,t.VM.checkRevision(e.compiler);var n={strict:function(e,t){if(!(t in e))throw new c.default('"'+t+'" not defined in '+e);return e[t]},lookup:function(e,t){for(var i=e.length,r=0;r<i;r++)if(e[r]&&null!=e[r][t])return e[r][t]},lambda:function(e,t){return"function"==typeof e?e.call(t):e},escapeExpression:u.escapeExpression,invokePartial:function(i,r,n){n.hash&&(r=u.extend({},r,n.hash),n.ids&&(n.ids[0]=!0)),i=t.VM.resolvePartial.call(this,i,r,n);var o=t.VM.invokePartial.call(this,i,r,n);if(null==o&&t.compile&&(n.partials[n.name]=t.compile(i,e.compilerOptions,t),o=n.partials[n.name](r,n)),null!=o){if(n.indent){for(var s=o.split("\n"),a=0,l=s.length;a<l&&(s[a]||a+1!==l);a++)s[a]=n.indent+s[a];o=s.join("\n")}return o}throw new c.default("The partial "+n.name+" could not be compiled when running in runtime-only mode")},fn:function(t){var i=e[t];return i.decorator=e[t+"_d"],i},programs:[],program:function(e,t,i,n,o){var s=this.programs[e],a=this.fn(e);return t||o||n||i?s=r(this,e,a,t,i,n,o):s||(s=this.programs[e]=r(this,e,a)),s},data:function(e,t){for(;e&&t--;)e=e._parent;return e},merge:function(e,t){var i=e||t;return e&&t&&e!==t&&(i=u.extend({},t,e)),i},nullContext:a({}),noop:t.VM.noop,compilerInfo:e.compiler};return i.isTop=!0,i._setup=function(i){i.partial?(n.helpers=i.helpers,n.partials=i.partials,n.decorators=i.decorators):(n.helpers=n.merge(i.helpers,t.helpers),e.usePartial&&(n.partials=n.merge(i.partials,t.partials)),(e.usePartial||e.useDecorators)&&(n.decorators=n.merge(i.decorators,t.decorators)))},i._child=function(t,i,o,s){if(e.useBlockParams&&!o)throw new c.default("must pass block params");if(e.useDepths&&!s)throw new c.default("must pass parent depths");return r(n,t,e[t],i,0,o,s)},i},t.wrapProgram=r,t.resolvePartial=function(e,t,i){return e?e.call||i.name||(i.name=e,e=i.partials[e]):e="@partial-block"===i.name?i.data["partial-block"]:i.partials[i.name],e},t.invokePartial=function(e,t,i){var r=i.data&&i.data["partial-block"];i.partial=!0,i.ids&&(i.data.contextPath=i.ids[0]||i.data.contextPath);var o=void 0;if(i.fn&&i.fn!==n&&function(){i.data=f.createFrame(i.data);var e=i.fn;o=i.data["partial-block"]=function(t){var i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return i.data=f.createFrame(i.data),i.data["partial-block"]=r,e(t,i)},e.partials&&(i.partials=u.extend({},i.partials,e.partials))}(),void 0===e&&o&&(e=o),void 0===e)throw new c.default("The partial "+i.name+" could not be found");if(e instanceof Function)return e(t,i)},t.noop=n;var u=l(i(5)),c=h(i(6)),f=i(4)},function(e,t,i){e.exports={default:i(24),__esModule:!0}},function(e,t,i){i(25),e.exports=i(30).Object.seal},function(e,t,i){var r=i(26);i(27)("seal",function(e){return function(t){return e&&r(t)?e(t):t}})},function(e,t){e.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},function(e,t,i){var r=i(28),n=i(30),o=i(33);e.exports=function(e,t){var i=(n.Object||{})[e]||Object[e],s={};s[e]=t(i),r(r.S+r.F*o(function(){i(1)}),"Object",s)}},function(e,t,i){var r=i(29),n=i(30),o=i(31),s="prototype",a=function(e,t,i){var l,h,u,c=e&a.F,f=e&a.G,p=e&a.S,d=e&a.P,m=e&a.B,g=e&a.W,v=f?n:n[t]||(n[t]={}),_=f?r:p?r[t]:(r[t]||{})[s];f&&(i=t);for(l in i)(h=!c&&_&&l in _)&&l in v||(u=h?_[l]:i[l],v[l]=f&&"function"!=typeof _[l]?i[l]:m&&h?o(u,r):g&&_[l]==u?function(e){var t=function(t){return this instanceof e?new e(t):e(t)};return t[s]=e[s],t}(u):d&&"function"==typeof u?o(Function.call,u):u,d&&((v[s]||(v[s]={}))[l]=u))};a.F=1,a.G=2,a.S=4,a.P=8,a.B=16,a.W=32,e.exports=a},function(e,t){var i=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=i)},function(e,t){var i=e.exports={version:"1.2.6"};"number"==typeof __e&&(__e=i)},function(e,t,i){var r=i(32);e.exports=function(e,t,i){if(r(e),void 0===t)return e;switch(i){case 1:return function(i){return e.call(t,i)};case 2:return function(i,r){return e.call(t,i,r)};case 3:return function(i,r,n){return e.call(t,i,r,n)}}return function(){return e.apply(t,arguments)}}},function(e,t){e.exports=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e}},function(e,t){e.exports=function(e){try{return!!e()}catch(e){return!0}}},function(e,t){(function(i){"use strict";t.__esModule=!0,t.default=function(e){var t=void 0!==i?i:window,r=t.Handlebars;e.noConflict=function(){return t.Handlebars===e&&(t.Handlebars=r),e}},e.exports=t.default}).call(t,function(){return this}())},function(e,t){"use strict";t.__esModule=!0;var i={helpers:{helperExpression:function(e){return"SubExpression"===e.type||("MustacheStatement"===e.type||"BlockStatement"===e.type)&&!!(e.params&&e.params.length||e.hash)},scopedId:function(e){return/^\.|this\b/.test(e.original)},simpleId:function(e){return 1===e.parts.length&&!i.helpers.scopedId(e)&&!e.depth}}};t.default=i,e.exports=t.default},function(e,t,i){"use strict";var r=i(1).default,n=i(3).default;t.__esModule=!0,t.parse=function(e,t){return"Program"===e.type?e:(o.default.yy=h,h.locInfo=function(e){return new h.SourceLocation(t&&t.srcName,e)},new s.default(t).accept(o.default.parse(e)))};var o=r(i(37)),s=r(i(38)),a=n(i(40)),l=i(5);t.parser=o.default;var h={};l.extend(h,a)},function(e,t){"use strict";t.__esModule=!0;var i=function(){function e(){this.yy={}}var t={trace:function(){},yy:{},symbols_:{error:2,root:3,program:4,EOF:5,program_repetition0:6,statement:7,mustache:8,block:9,rawBlock:10,partial:11,partialBlock:12,content:13,COMMENT:14,CONTENT:15,openRawBlock:16,rawBlock_repetition_plus0:17,END_RAW_BLOCK:18,OPEN_RAW_BLOCK:19,helperName:20,openRawBlock_repetition0:21,openRawBlock_option0:22,CLOSE_RAW_BLOCK:23,openBlock:24,block_option0:25,closeBlock:26,openInverse:27,block_option1:28,OPEN_BLOCK:29,openBlock_repetition0:30,openBlock_option0:31,openBlock_option1:32,CLOSE:33,OPEN_INVERSE:34,openInverse_repetition0:35,openInverse_option0:36,openInverse_option1:37,openInverseChain:38,OPEN_INVERSE_CHAIN:39,openInverseChain_repetition0:40,openInverseChain_option0:41,openInverseChain_option1:42,inverseAndProgram:43,INVERSE:44,inverseChain:45,inverseChain_option0:46,OPEN_ENDBLOCK:47,OPEN:48,mustache_repetition0:49,mustache_option0:50,OPEN_UNESCAPED:51,mustache_repetition1:52,mustache_option1:53,CLOSE_UNESCAPED:54,OPEN_PARTIAL:55,partialName:56,partial_repetition0:57,partial_option0:58,openPartialBlock:59,OPEN_PARTIAL_BLOCK:60,openPartialBlock_repetition0:61,openPartialBlock_option0:62,param:63,sexpr:64,OPEN_SEXPR:65,sexpr_repetition0:66,sexpr_option0:67,CLOSE_SEXPR:68,hash:69,hash_repetition_plus0:70,hashSegment:71,ID:72,EQUALS:73,blockParams:74,OPEN_BLOCK_PARAMS:75,blockParams_repetition_plus0:76,CLOSE_BLOCK_PARAMS:77,path:78,dataName:79,STRING:80,NUMBER:81,BOOLEAN:82,UNDEFINED:83,NULL:84,DATA:85,pathSegments:86,SEP:87,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",14:"COMMENT",15:"CONTENT",18:"END_RAW_BLOCK",19:"OPEN_RAW_BLOCK",23:"CLOSE_RAW_BLOCK",29:"OPEN_BLOCK",33:"CLOSE",34:"OPEN_INVERSE",39:"OPEN_INVERSE_CHAIN",44:"INVERSE",47:"OPEN_ENDBLOCK",48:"OPEN",51:"OPEN_UNESCAPED",54:"CLOSE_UNESCAPED",55:"OPEN_PARTIAL",60:"OPEN_PARTIAL_BLOCK",65:"OPEN_SEXPR",68:"CLOSE_SEXPR",72:"ID",73:"EQUALS",75:"OPEN_BLOCK_PARAMS",77:"CLOSE_BLOCK_PARAMS",80:"STRING",81:"NUMBER",82:"BOOLEAN",83:"UNDEFINED",84:"NULL",85:"DATA",87:"SEP"},productions_:[0,[3,2],[4,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[13,1],[10,3],[16,5],[9,4],[9,4],[24,6],[27,6],[38,6],[43,2],[45,3],[45,1],[26,3],[8,5],[8,5],[11,5],[12,3],[59,5],[63,1],[63,1],[64,5],[69,1],[71,3],[74,3],[20,1],[20,1],[20,1],[20,1],[20,1],[20,1],[20,1],[56,1],[56,1],[79,2],[78,1],[86,3],[86,1],[6,0],[6,2],[17,1],[17,2],[21,0],[21,2],[22,0],[22,1],[25,0],[25,1],[28,0],[28,1],[30,0],[30,2],[31,0],[31,1],[32,0],[32,1],[35,0],[35,2],[36,0],[36,1],[37,0],[37,1],[40,0],[40,2],[41,0],[41,1],[42,0],[42,1],[46,0],[46,1],[49,0],[49,2],[50,0],[50,1],[52,0],[52,2],[53,0],[53,1],[57,0],[57,2],[58,0],[58,1],[61,0],[61,2],[62,0],[62,1],[66,0],[66,2],[67,0],[67,1],[70,1],[70,2],[76,1],[76,2]],performAction:function(e,t,i,r,n,o,s){var a=o.length-1;switch(n){case 1:return o[a-1];case 2:this.$=r.prepareProgram(o[a]);break;case 3:case 4:case 5:case 6:case 7:case 8:this.$=o[a];break;case 9:this.$={type:"CommentStatement",value:r.stripComment(o[a]),strip:r.stripFlags(o[a],o[a]),loc:r.locInfo(this._$)};break;case 10:this.$={type:"ContentStatement",original:o[a],value:o[a],loc:r.locInfo(this._$)};break;case 11:this.$=r.prepareRawBlock(o[a-2],o[a-1],o[a],this._$);break;case 12:this.$={path:o[a-3],params:o[a-2],hash:o[a-1]};break;case 13:this.$=r.prepareBlock(o[a-3],o[a-2],o[a-1],o[a],!1,this._$);break;case 14:this.$=r.prepareBlock(o[a-3],o[a-2],o[a-1],o[a],!0,this._$);break;case 15:this.$={open:o[a-5],path:o[a-4],params:o[a-3],hash:o[a-2],blockParams:o[a-1],strip:r.stripFlags(o[a-5],o[a])};break;case 16:case 17:this.$={path:o[a-4],params:o[a-3],hash:o[a-2],blockParams:o[a-1],strip:r.stripFlags(o[a-5],o[a])};break;case 18:this.$={strip:r.stripFlags(o[a-1],o[a-1]),program:o[a]};break;case 19:var l=r.prepareBlock(o[a-2],o[a-1],o[a],o[a],!1,this._$),h=r.prepareProgram([l],o[a-1].loc);h.chained=!0,this.$={strip:o[a-2].strip,program:h,chain:!0};break;case 20:this.$=o[a];break;case 21:this.$={path:o[a-1],strip:r.stripFlags(o[a-2],o[a])};break;case 22:case 23:this.$=r.prepareMustache(o[a-3],o[a-2],o[a-1],o[a-4],r.stripFlags(o[a-4],o[a]),this._$);break;case 24:this.$={type:"PartialStatement",name:o[a-3],params:o[a-2],hash:o[a-1],indent:"",strip:r.stripFlags(o[a-4],o[a]),loc:r.locInfo(this._$)};break;case 25:this.$=r.preparePartialBlock(o[a-2],o[a-1],o[a],this._$);break;case 26:this.$={path:o[a-3],params:o[a-2],hash:o[a-1],strip:r.stripFlags(o[a-4],o[a])};break;case 27:case 28:this.$=o[a];break;case 29:this.$={type:"SubExpression",path:o[a-3],params:o[a-2],hash:o[a-1],loc:r.locInfo(this._$)};break;case 30:this.$={type:"Hash",pairs:o[a],loc:r.locInfo(this._$)};break;case 31:this.$={type:"HashPair",key:r.id(o[a-2]),value:o[a],loc:r.locInfo(this._$)};break;case 32:this.$=r.id(o[a-1]);break;case 33:case 34:this.$=o[a];break;case 35:this.$={type:"StringLiteral",value:o[a],original:o[a],loc:r.locInfo(this._$)};break;case 36:this.$={type:"NumberLiteral",value:Number(o[a]),original:Number(o[a]),loc:r.locInfo(this._$)};break;case 37:this.$={type:"BooleanLiteral",value:"true"===o[a],original:"true"===o[a],loc:r.locInfo(this._$)};break;case 38:this.$={type:"UndefinedLiteral",original:void 0,value:void 0,loc:r.locInfo(this._$)};break;case 39:this.$={type:"NullLiteral",original:null,value:null,loc:r.locInfo(this._$)};break;case 40:case 41:this.$=o[a];break;case 42:this.$=r.preparePath(!0,o[a],this._$);break;case 43:this.$=r.preparePath(!1,o[a],this._$);break;case 44:o[a-2].push({part:r.id(o[a]),original:o[a],separator:o[a-1]}),this.$=o[a-2];break;case 45:this.$=[{part:r.id(o[a]),original:o[a]}];break;case 46:this.$=[];break;case 47:o[a-1].push(o[a]);break;case 48:this.$=[o[a]];break;case 49:o[a-1].push(o[a]);break;case 50:this.$=[];break;case 51:o[a-1].push(o[a]);break;case 58:this.$=[];break;case 59:o[a-1].push(o[a]);break;case 64:this.$=[];break;case 65:o[a-1].push(o[a]);break;case 70:this.$=[];break;case 71:o[a-1].push(o[a]);break;case 78:this.$=[];break;case 79:o[a-1].push(o[a]);break;case 82:this.$=[];break;case 83:o[a-1].push(o[a]);break;case 86:this.$=[];break;case 87:o[a-1].push(o[a]);break;case 90:this.$=[];break;case 91:o[a-1].push(o[a]);break;case 94:this.$=[];break;case 95:o[a-1].push(o[a]);break;case 98:this.$=[o[a]];break;case 99:o[a-1].push(o[a]);break;case 100:this.$=[o[a]];break;case 101:o[a-1].push(o[a])}},table:[{3:1,4:2,5:[2,46],6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{1:[3]},{5:[1,4]},{5:[2,2],7:5,8:6,9:7,10:8,11:9,12:10,13:11,14:[1,12],15:[1,20],16:17,19:[1,23],24:15,27:16,29:[1,21],34:[1,22],39:[2,2],44:[2,2],47:[2,2],48:[1,13],51:[1,14],55:[1,18],59:19,60:[1,24]},{1:[2,1]},{5:[2,47],14:[2,47],15:[2,47],19:[2,47],29:[2,47],34:[2,47],39:[2,47],44:[2,47],47:[2,47],48:[2,47],51:[2,47],55:[2,47],60:[2,47]},{5:[2,3],14:[2,3],15:[2,3],19:[2,3],29:[2,3],34:[2,3],39:[2,3],44:[2,3],47:[2,3],48:[2,3],51:[2,3],55:[2,3],60:[2,3]},{5:[2,4],14:[2,4],15:[2,4],19:[2,4],29:[2,4],34:[2,4],39:[2,4],44:[2,4],47:[2,4],48:[2,4],51:[2,4],55:[2,4],60:[2,4]},{5:[2,5],14:[2,5],15:[2,5],19:[2,5],29:[2,5],34:[2,5],39:[2,5],44:[2,5],47:[2,5],48:[2,5],51:[2,5],55:[2,5],60:[2,5]},{5:[2,6],14:[2,6],15:[2,6],19:[2,6],29:[2,6],34:[2,6],39:[2,6],44:[2,6],47:[2,6],48:[2,6],51:[2,6],55:[2,6],60:[2,6]},{5:[2,7],14:[2,7],15:[2,7],19:[2,7],29:[2,7],34:[2,7],39:[2,7],44:[2,7],47:[2,7],48:[2,7],51:[2,7],55:[2,7],60:[2,7]},{5:[2,8],14:[2,8],15:[2,8],19:[2,8],29:[2,8],34:[2,8],39:[2,8],44:[2,8],47:[2,8],48:[2,8],51:[2,8],55:[2,8],60:[2,8]},{5:[2,9],14:[2,9],15:[2,9],19:[2,9],29:[2,9],34:[2,9],39:[2,9],44:[2,9],47:[2,9],48:[2,9],51:[2,9],55:[2,9],60:[2,9]},{20:25,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:36,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{4:37,6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],39:[2,46],44:[2,46],47:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{4:38,6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],44:[2,46],47:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{13:40,15:[1,20],17:39},{20:42,56:41,64:43,65:[1,44],72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{4:45,6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],47:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{5:[2,10],14:[2,10],15:[2,10],18:[2,10],19:[2,10],29:[2,10],34:[2,10],39:[2,10],44:[2,10],47:[2,10],48:[2,10],51:[2,10],55:[2,10],60:[2,10]},{20:46,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:47,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:48,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:42,56:49,64:43,65:[1,44],72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{33:[2,78],49:50,65:[2,78],72:[2,78],80:[2,78],81:[2,78],82:[2,78],83:[2,78],84:[2,78],85:[2,78]},{23:[2,33],33:[2,33],54:[2,33],65:[2,33],68:[2,33],72:[2,33],75:[2,33],80:[2,33],81:[2,33],82:[2,33],83:[2,33],84:[2,33],85:[2,33]},{23:[2,34],33:[2,34],54:[2,34],65:[2,34],68:[2,34],72:[2,34],75:[2,34],80:[2,34],81:[2,34],82:[2,34],83:[2,34],84:[2,34],85:[2,34]},{23:[2,35],33:[2,35],54:[2,35],65:[2,35],68:[2,35],72:[2,35],75:[2,35],80:[2,35],81:[2,35],82:[2,35],83:[2,35],84:[2,35],85:[2,35]},{23:[2,36],33:[2,36],54:[2,36],65:[2,36],68:[2,36],72:[2,36],75:[2,36],80:[2,36],81:[2,36],82:[2,36],83:[2,36],84:[2,36],85:[2,36]},{23:[2,37],33:[2,37],54:[2,37],65:[2,37],68:[2,37],72:[2,37],75:[2,37],80:[2,37],81:[2,37],82:[2,37],83:[2,37],84:[2,37],85:[2,37]},{23:[2,38],33:[2,38],54:[2,38],65:[2,38],68:[2,38],72:[2,38],75:[2,38],80:[2,38],81:[2,38],82:[2,38],83:[2,38],84:[2,38],85:[2,38]},{23:[2,39],33:[2,39],54:[2,39],65:[2,39],68:[2,39],72:[2,39],75:[2,39],80:[2,39],81:[2,39],82:[2,39],83:[2,39],84:[2,39],85:[2,39]},{23:[2,43],33:[2,43],54:[2,43],65:[2,43],68:[2,43],72:[2,43],75:[2,43],80:[2,43],81:[2,43],82:[2,43],83:[2,43],84:[2,43],85:[2,43],87:[1,51]},{72:[1,35],86:52},{23:[2,45],33:[2,45],54:[2,45],65:[2,45],68:[2,45],72:[2,45],75:[2,45],80:[2,45],81:[2,45],82:[2,45],83:[2,45],84:[2,45],85:[2,45],87:[2,45]},{52:53,54:[2,82],65:[2,82],72:[2,82],80:[2,82],81:[2,82],82:[2,82],83:[2,82],84:[2,82],85:[2,82]},{25:54,38:56,39:[1,58],43:57,44:[1,59],45:55,47:[2,54]},{28:60,43:61,44:[1,59],47:[2,56]},{13:63,15:[1,20],18:[1,62]},{15:[2,48],18:[2,48]},{33:[2,86],57:64,65:[2,86],72:[2,86],80:[2,86],81:[2,86],82:[2,86],83:[2,86],84:[2,86],85:[2,86]},{33:[2,40],65:[2,40],72:[2,40],80:[2,40],81:[2,40],82:[2,40],83:[2,40],84:[2,40],85:[2,40]},{33:[2,41],65:[2,41],72:[2,41],80:[2,41],81:[2,41],82:[2,41],83:[2,41],84:[2,41],85:[2,41]},{20:65,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{26:66,47:[1,67]},{30:68,33:[2,58],65:[2,58],72:[2,58],75:[2,58],80:[2,58],81:[2,58],82:[2,58],83:[2,58],84:[2,58],85:[2,58]},{33:[2,64],35:69,65:[2,64],72:[2,64],75:[2,64],80:[2,64],81:[2,64],82:[2,64],83:[2,64],84:[2,64],85:[2,64]},{21:70,23:[2,50],65:[2,50],72:[2,50],80:[2,50],81:[2,50],82:[2,50],83:[2,50],84:[2,50],85:[2,50]},{33:[2,90],61:71,65:[2,90],72:[2,90],80:[2,90],81:[2,90],82:[2,90],83:[2,90],84:[2,90],85:[2,90]},{20:75,33:[2,80],50:72,63:73,64:76,65:[1,44],69:74,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{72:[1,80]},{23:[2,42],33:[2,42],54:[2,42],65:[2,42],68:[2,42],72:[2,42],75:[2,42],80:[2,42],81:[2,42],82:[2,42],83:[2,42],84:[2,42],85:[2,42],87:[1,51]},{20:75,53:81,54:[2,84],63:82,64:76,65:[1,44],69:83,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{26:84,47:[1,67]},{47:[2,55]},{4:85,6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],39:[2,46],44:[2,46],47:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{47:[2,20]},{20:86,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{4:87,6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],47:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{26:88,47:[1,67]},{47:[2,57]},{5:[2,11],14:[2,11],15:[2,11],19:[2,11],29:[2,11],34:[2,11],39:[2,11],44:[2,11],47:[2,11],48:[2,11],51:[2,11],55:[2,11],60:[2,11]},{15:[2,49],18:[2,49]},{20:75,33:[2,88],58:89,63:90,64:76,65:[1,44],69:91,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{65:[2,94],66:92,68:[2,94],72:[2,94],80:[2,94],81:[2,94],82:[2,94],83:[2,94],84:[2,94],85:[2,94]},{5:[2,25],14:[2,25],15:[2,25],19:[2,25],29:[2,25],34:[2,25],39:[2,25],44:[2,25],47:[2,25],48:[2,25],51:[2,25],55:[2,25],60:[2,25]},{20:93,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:75,31:94,33:[2,60],63:95,64:76,65:[1,44],69:96,70:77,71:78,72:[1,79],75:[2,60],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:75,33:[2,66],36:97,63:98,64:76,65:[1,44],69:99,70:77,71:78,72:[1,79],75:[2,66],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:75,22:100,23:[2,52],63:101,64:76,65:[1,44],69:102,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:75,33:[2,92],62:103,63:104,64:76,65:[1,44],69:105,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{33:[1,106]},{33:[2,79],65:[2,79],72:[2,79],80:[2,79],81:[2,79],82:[2,79],83:[2,79],84:[2,79],85:[2,79]},{33:[2,81]},{23:[2,27],33:[2,27],54:[2,27],65:[2,27],68:[2,27],72:[2,27],75:[2,27],80:[2,27],81:[2,27],82:[2,27],83:[2,27],84:[2,27],85:[2,27]},{23:[2,28],33:[2,28],54:[2,28],65:[2,28],68:[2,28],72:[2,28],75:[2,28],80:[2,28],81:[2,28],82:[2,28],83:[2,28],84:[2,28],85:[2,28]},{23:[2,30],33:[2,30],54:[2,30],68:[2,30],71:107,72:[1,108],75:[2,30]},{23:[2,98],33:[2,98],54:[2,98],68:[2,98],72:[2,98],75:[2,98]},{23:[2,45],33:[2,45],54:[2,45],65:[2,45],68:[2,45],72:[2,45],73:[1,109],75:[2,45],80:[2,45],81:[2,45],82:[2,45],83:[2,45],84:[2,45],85:[2,45],87:[2,45]},{23:[2,44],33:[2,44],54:[2,44],65:[2,44],68:[2,44],72:[2,44],75:[2,44],80:[2,44],81:[2,44],82:[2,44],83:[2,44],84:[2,44],85:[2,44],87:[2,44]},{54:[1,110]},{54:[2,83],65:[2,83],72:[2,83],80:[2,83],81:[2,83],82:[2,83],83:[2,83],84:[2,83],85:[2,83]},{54:[2,85]},{5:[2,13],14:[2,13],15:[2,13],19:[2,13],29:[2,13],34:[2,13],39:[2,13],44:[2,13],47:[2,13],48:[2,13],51:[2,13],55:[2,13],60:[2,13]},{38:56,39:[1,58],43:57,44:[1,59],45:112,46:111,47:[2,76]},{33:[2,70],40:113,65:[2,70],72:[2,70],75:[2,70],80:[2,70],81:[2,70],82:[2,70],83:[2,70],84:[2,70],85:[2,70]},{47:[2,18]},{5:[2,14],14:[2,14],15:[2,14],19:[2,14],29:[2,14],34:[2,14],39:[2,14],44:[2,14],47:[2,14],48:[2,14],51:[2,14],55:[2,14],60:[2,14]},{33:[1,114]},{33:[2,87],65:[2,87],72:[2,87],80:[2,87],81:[2,87],82:[2,87],83:[2,87],84:[2,87],85:[2,87]},{33:[2,89]},{20:75,63:116,64:76,65:[1,44],67:115,68:[2,96],69:117,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{33:[1,118]},{32:119,33:[2,62],74:120,75:[1,121]},{33:[2,59],65:[2,59],72:[2,59],75:[2,59],80:[2,59],81:[2,59],82:[2,59],83:[2,59],84:[2,59],85:[2,59]},{33:[2,61],75:[2,61]},{33:[2,68],37:122,74:123,75:[1,121]},{33:[2,65],65:[2,65],72:[2,65],75:[2,65],80:[2,65],81:[2,65],82:[2,65],83:[2,65],84:[2,65],85:[2,65]},{33:[2,67],75:[2,67]},{23:[1,124]},{23:[2,51],65:[2,51],72:[2,51],80:[2,51],81:[2,51],82:[2,51],83:[2,51],84:[2,51],85:[2,51]},{23:[2,53]},{33:[1,125]},{33:[2,91],65:[2,91],72:[2,91],80:[2,91],81:[2,91],82:[2,91],83:[2,91],84:[2,91],85:[2,91]},{33:[2,93]},{5:[2,22],14:[2,22],15:[2,22],19:[2,22],29:[2,22],34:[2,22],39:[2,22],44:[2,22],47:[2,22],48:[2,22],51:[2,22],55:[2,22],60:[2,22]},{23:[2,99],33:[2,99],54:[2,99],68:[2,99],72:[2,99],75:[2,99]},{73:[1,109]},{20:75,63:126,64:76,65:[1,44],72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{5:[2,23],14:[2,23],15:[2,23],19:[2,23],29:[2,23],34:[2,23],39:[2,23],44:[2,23],47:[2,23],48:[2,23],51:[2,23],55:[2,23],60:[2,23]},{47:[2,19]},{47:[2,77]},{20:75,33:[2,72],41:127,63:128,64:76,65:[1,44],69:129,70:77,71:78,72:[1,79],75:[2,72],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{5:[2,24],14:[2,24],15:[2,24],19:[2,24],29:[2,24],34:[2,24],39:[2,24],44:[2,24],47:[2,24],48:[2,24],51:[2,24],55:[2,24],60:[2,24]},{68:[1,130]},{65:[2,95],68:[2,95],72:[2,95],80:[2,95],81:[2,95],82:[2,95],83:[2,95],84:[2,95],85:[2,95]},{68:[2,97]},{5:[2,21],14:[2,21],15:[2,21],19:[2,21],29:[2,21],34:[2,21],39:[2,21],44:[2,21],47:[2,21],48:[2,21],51:[2,21],55:[2,21],60:[2,21]},{33:[1,131]},{33:[2,63]},{72:[1,133],76:132},{33:[1,134]},{33:[2,69]},{15:[2,12]},{14:[2,26],15:[2,26],19:[2,26],29:[2,26],34:[2,26],47:[2,26],48:[2,26],51:[2,26],55:[2,26],60:[2,26]},{23:[2,31],33:[2,31],54:[2,31],68:[2,31],72:[2,31],75:[2,31]},{33:[2,74],42:135,74:136,75:[1,121]},{33:[2,71],65:[2,71],72:[2,71],75:[2,71],80:[2,71],81:[2,71],82:[2,71],83:[2,71],84:[2,71],85:[2,71]},{33:[2,73],75:[2,73]},{23:[2,29],33:[2,29],54:[2,29],65:[2,29],68:[2,29],72:[2,29],75:[2,29],80:[2,29],81:[2,29],82:[2,29],83:[2,29],84:[2,29],85:[2,29]},{14:[2,15],15:[2,15],19:[2,15],29:[2,15],34:[2,15],39:[2,15],44:[2,15],47:[2,15],48:[2,15],51:[2,15],55:[2,15],60:[2,15]},{72:[1,138],77:[1,137]},{72:[2,100],77:[2,100]},{14:[2,16],15:[2,16],19:[2,16],29:[2,16],34:[2,16],44:[2,16],47:[2,16],48:[2,16],51:[2,16],55:[2,16],60:[2,16]},{33:[1,139]},{33:[2,75]},{33:[2,32]},{72:[2,101],77:[2,101]},{14:[2,17],15:[2,17],19:[2,17],29:[2,17],34:[2,17],39:[2,17],44:[2,17],47:[2,17],48:[2,17],51:[2,17],55:[2,17],60:[2,17]}],defaultActions:{4:[2,1],55:[2,55],57:[2,20],61:[2,57],74:[2,81],83:[2,85],87:[2,18],91:[2,89],102:[2,53],105:[2,93],111:[2,19],112:[2,77],117:[2,97],120:[2,63],123:[2,69],124:[2,12],136:[2,75],137:[2,32]},parseError:function(e,t){throw new Error(e)},parse:function(e){var t=this,i=[0],r=[null],n=[],o=this.table,s="",a=0,l=0,h=0;this.lexer.setInput(e),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,this.yy.parser=this,void 0===this.lexer.yylloc&&(this.lexer.yylloc={});var u=this.lexer.yylloc;n.push(u);var c=this.lexer.options&&this.lexer.options.ranges;"function"==typeof this.yy.parseError&&(this.parseError=this.yy.parseError);for(var f,p,d,m,g,v,_,y,x,b={};;){if(d=i[i.length-1],this.defaultActions[d]?m=this.defaultActions[d]:(null!==f&&void 0!==f||(f=function(){var e;return"number"!=typeof(e=t.lexer.lex()||1)&&(e=t.symbols_[e]||e),e}()),m=o[d]&&o[d][f]),void 0===m||!m.length||!m[0]){var T="";if(!h){x=[];for(v in o[d])this.terminals_[v]&&v>2&&x.push("'"+this.terminals_[v]+"'");T=this.lexer.showPosition?"Parse error on line "+(a+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+x.join(", ")+", got '"+(this.terminals_[f]||f)+"'":"Parse error on line "+(a+1)+": Unexpected "+(1==f?"end of input":"'"+(this.terminals_[f]||f)+"'"),this.parseError(T,{text:this.lexer.match,token:this.terminals_[f]||f,line:this.lexer.yylineno,loc:u,expected:x})}}if(m[0]instanceof Array&&m.length>1)throw new Error("Parse Error: multiple actions possible at state: "+d+", token: "+f);switch(m[0]){case 1:i.push(f),r.push(this.lexer.yytext),n.push(this.lexer.yylloc),i.push(m[1]),f=null,p?(f=p,p=null):(l=this.lexer.yyleng,s=this.lexer.yytext,a=this.lexer.yylineno,u=this.lexer.yylloc,h>0&&h--);break;case 2:if(_=this.productions_[m[1]][1],b.$=r[r.length-_],b._$={first_line:n[n.length-(_||1)].first_line,last_line:n[n.length-1].last_line,first_column:n[n.length-(_||1)].first_column,last_column:n[n.length-1].last_column},c&&(b._$.range=[n[n.length-(_||1)].range[0],n[n.length-1].range[1]]),void 0!==(g=this.performAction.call(b,s,l,a,this.yy,m[1],r,n)))return g;_&&(i=i.slice(0,-1*_*2),r=r.slice(0,-1*_),n=n.slice(0,-1*_)),i.push(this.productions_[m[1]][0]),r.push(b.$),n.push(b._$),y=o[i[i.length-2]][i[i.length-1]],i.push(y);break;case 3:return!0}}return!0}},i=function(){var e={EOF:1,parseError:function(e,t){if(!this.yy.parser)throw new Error(e);this.yy.parser.parseError(e,t)},setInput:function(e){return this._input=e,this._more=this._less=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var e=this._input[0];return this.yytext+=e,this.yyleng++,this.offset++,this.match+=e,this.matched+=e,e.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),e},unput:function(e){var t=e.length,i=e.split(/(?:\r\n?|\n)/g);this._input=e+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-t-1),this.offset-=t;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),i.length-1&&(this.yylineno-=i.length-1);var n=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:i?(i.length===r.length?this.yylloc.first_column:0)+r[r.length-i.length].length-i[0].length:this.yylloc.first_column-t},this.options.ranges&&(this.yylloc.range=[n[0],n[0]+this.yyleng-t]),this},more:function(){return this._more=!0,this},less:function(e){this.unput(this.match.slice(e))},pastInput:function(){var e=this.matched.substr(0,this.matched.length-this.match.length);return(e.length>20?"...":"")+e.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var e=this.match;return e.length<20&&(e+=this._input.substr(0,20-e.length)),(e.substr(0,20)+(e.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var e=this.pastInput(),t=new Array(e.length+1).join("-");return e+this.upcomingInput()+"\n"+t+"^"},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var e,t,i,r,n;this._more||(this.yytext="",this.match="");for(var o=this._currentRules(),s=0;s<o.length&&(!(i=this._input.match(this.rules[o[s]]))||t&&!(i[0].length>t[0].length)||(t=i,r=s,this.options.flex));s++);return t?((n=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=n.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:n?n[n.length-1].length-n[n.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],e=this.performAction.call(this,this.yy,this,o[r],this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),e||void 0):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var e=this.next();return void 0!==e?e:this.lex()},begin:function(e){this.conditionStack.push(e)},popState:function(){return this.conditionStack.pop()},_currentRules:function(){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules},topState:function(){return this.conditionStack[this.conditionStack.length-2]},pushState:function(e){this.begin(e)}};return e.options={},e.performAction=function(e,t,i,r){function n(e,i){return t.yytext=t.yytext.substr(e,t.yyleng-i)}switch(i){case 0:if("\\\\"===t.yytext.slice(-2)?(n(0,1),this.begin("mu")):"\\"===t.yytext.slice(-1)?(n(0,1),this.begin("emu")):this.begin("mu"),t.yytext)return 15;break;case 1:return 15;case 2:return this.popState(),15;case 3:return this.begin("raw"),15;case 4:return this.popState(),"raw"===this.conditionStack[this.conditionStack.length-1]?15:(t.yytext=t.yytext.substr(5,t.yyleng-9),"END_RAW_BLOCK");case 5:return 15;case 6:return this.popState(),14;case 7:return 65;case 8:return 68;case 9:return 19;case 10:return this.popState(),this.begin("raw"),23;case 11:return 55;case 12:return 60;case 13:return 29;case 14:return 47;case 15:case 16:return this.popState(),44;case 17:return 34;case 18:return 39;case 19:return 51;case 20:return 48;case 21:this.unput(t.yytext),this.popState(),this.begin("com");break;case 22:return this.popState(),14;case 23:return 48;case 24:return 73;case 25:case 26:return 72;case 27:return 87;case 28:break;case 29:return this.popState(),54;case 30:return this.popState(),33;case 31:return t.yytext=n(1,2).replace(/\\"/g,'"'),80;case 32:return t.yytext=n(1,2).replace(/\\'/g,"'"),80;case 33:return 85;case 34:case 35:return 82;case 36:return 83;case 37:return 84;case 38:return 81;case 39:return 75;case 40:return 77;case 41:return 72;case 42:return t.yytext=t.yytext.replace(/\\([\\\]])/g,"$1"),72;case 43:return"INVALID";case 44:return 5}},e.rules=[/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|\\\{\{|\\\\\{\{|$)))/,/^(?:\{\{\{\{(?=[^\/]))/,/^(?:\{\{\{\{\/[^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=[=}\s\/.])\}\}\}\})/,/^(?:[^\x00]*?(?=(\{\{\{\{)))/,/^(?:[\s\S]*?--(~)?\}\})/,/^(?:\()/,/^(?:\))/,/^(?:\{\{\{\{)/,/^(?:\}\}\}\})/,/^(?:\{\{(~)?>)/,/^(?:\{\{(~)?#>)/,/^(?:\{\{(~)?#\*?)/,/^(?:\{\{(~)?\/)/,/^(?:\{\{(~)?\^\s*(~)?\}\})/,/^(?:\{\{(~)?\s*else\s*(~)?\}\})/,/^(?:\{\{(~)?\^)/,/^(?:\{\{(~)?\s*else\b)/,/^(?:\{\{(~)?\{)/,/^(?:\{\{(~)?&)/,/^(?:\{\{(~)?!--)/,/^(?:\{\{(~)?![\s\S]*?\}\})/,/^(?:\{\{(~)?\*?)/,/^(?:=)/,/^(?:\.\.)/,/^(?:\.(?=([=~}\s\/.)|])))/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}(~)?\}\})/,/^(?:(~)?\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@)/,/^(?:true(?=([~}\s)])))/,/^(?:false(?=([~}\s)])))/,/^(?:undefined(?=([~}\s)])))/,/^(?:null(?=([~}\s)])))/,/^(?:-?[0-9]+(?:\.[0-9]+)?(?=([~}\s)])))/,/^(?:as\s+\|)/,/^(?:\|)/,/^(?:([^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=([=~}\s\/.)|]))))/,/^(?:\[(\\\]|[^\]])*\])/,/^(?:.)/,/^(?:$)/],e.conditions={mu:{rules:[7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44],inclusive:!1},emu:{rules:[2],inclusive:!1},com:{rules:[6],inclusive:!1},raw:{rules:[3,4,5],inclusive:!1},INITIAL:{rules:[0,1,44],inclusive:!0}},e}();return t.lexer=i,e.prototype=t,t.Parser=e,new e}();t.default=i,e.exports=t.default},function(e,t,i){"use strict";function r(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.options=e}function n(e,t,i){void 0===t&&(t=e.length);var r=e[t-1],n=e[t-2];return r?"ContentStatement"===r.type?(n||!i?/\r?\n\s*?$/:/(^|\r?\n)\s*?$/).test(r.original):void 0:i}function o(e,t,i){void 0===t&&(t=-1);var r=e[t+1],n=e[t+2];return r?"ContentStatement"===r.type?(n||!i?/^\s*?\r?\n/:/^\s*?(\r?\n|$)/).test(r.original):void 0:i}function s(e,t,i){var r=e[null==t?0:t+1];if(r&&"ContentStatement"===r.type&&(i||!r.rightStripped)){var n=r.value;r.value=r.value.replace(i?/^\s+/:/^[ \t]*\r?\n?/,""),r.rightStripped=r.value!==n}}function a(e,t,i){var r=e[null==t?e.length-1:t-1];if(r&&"ContentStatement"===r.type&&(i||!r.leftStripped)){var n=r.value;return r.value=r.value.replace(i?/\s+$/:/[ \t]+$/,""),r.leftStripped=r.value!==n,r.leftStripped}}var l=i(1).default;t.__esModule=!0;var h=l(i(39));(r.prototype=new h.default).Program=function(e){var t=!this.options.ignoreStandalone,i=!this.isRootSeen;this.isRootSeen=!0;for(var r=e.body,l=0,h=r.length;l<h;l++){var u=r[l],c=this.accept(u);if(c){var f=n(r,l,i),p=o(r,l,i),d=c.openStandalone&&f,m=c.closeStandalone&&p,g=c.inlineStandalone&&f&&p;c.close&&s(r,l,!0),c.open&&a(r,l,!0),t&&g&&(s(r,l),a(r,l)&&"PartialStatement"===u.type&&(u.indent=/([ \t]+$)/.exec(r[l-1].original)[1])),t&&d&&(s((u.program||u.inverse).body),a(r,l)),t&&m&&(s(r,l),a((u.inverse||u.program).body))}}return e},r.prototype.BlockStatement=r.prototype.DecoratorBlock=r.prototype.PartialBlockStatement=function(e){this.accept(e.program),this.accept(e.inverse);var t=e.program||e.inverse,i=e.program&&e.inverse,r=i,l=i;if(i&&i.chained)for(r=i.body[0].program;l.chained;)l=l.body[l.body.length-1].program;var h={open:e.openStrip.open,close:e.closeStrip.close,openStandalone:o(t.body),closeStandalone:n((r||t).body)};if(e.openStrip.close&&s(t.body,null,!0),i){var u=e.inverseStrip;u.open&&a(t.body,null,!0),u.close&&s(r.body,null,!0),e.closeStrip.open&&a(l.body,null,!0),!this.options.ignoreStandalone&&n(t.body)&&o(r.body)&&(a(t.body),s(r.body))}else e.closeStrip.open&&a(t.body,null,!0);return h},r.prototype.Decorator=r.prototype.MustacheStatement=function(e){return e.strip},r.prototype.PartialStatement=r.prototype.CommentStatement=function(e){var t=e.strip||{};return{inlineStandalone:!0,open:t.open,close:t.close}},t.default=r,e.exports=t.default},function(e,t,i){"use strict";function r(){this.parents=[]}function n(e){this.acceptRequired(e,"path"),this.acceptArray(e.params),this.acceptKey(e,"hash")}function o(e){n.call(this,e),this.acceptKey(e,"program"),this.acceptKey(e,"inverse")}function s(e){this.acceptRequired(e,"name"),this.acceptArray(e.params),this.acceptKey(e,"hash")}var a=i(1).default;t.__esModule=!0;var l=a(i(6));r.prototype={constructor:r,mutating:!1,acceptKey:function(e,t){var i=this.accept(e[t]);if(this.mutating){if(i&&!r.prototype[i.type])throw new l.default('Unexpected node type "'+i.type+'" found when accepting '+t+" on "+e.type);e[t]=i}},acceptRequired:function(e,t){if(this.acceptKey(e,t),!e[t])throw new l.default(e.type+" requires "+t)},acceptArray:function(e){for(var t=0,i=e.length;t<i;t++)this.acceptKey(e,t),e[t]||(e.splice(t,1),t--,i--)},accept:function(e){if(e){if(!this[e.type])throw new l.default("Unknown type: "+e.type,e);this.current&&this.parents.unshift(this.current),this.current=e;var t=this[e.type](e);return this.current=this.parents.shift(),!this.mutating||t?t:!1!==t?e:void 0}},Program:function(e){this.acceptArray(e.body)},MustacheStatement:n,Decorator:n,BlockStatement:o,DecoratorBlock:o,PartialStatement:s,PartialBlockStatement:function(e){s.call(this,e),this.acceptKey(e,"program")},ContentStatement:function(){},CommentStatement:function(){},SubExpression:n,PathExpression:function(){},StringLiteral:function(){},NumberLiteral:function(){},BooleanLiteral:function(){},UndefinedLiteral:function(){},NullLiteral:function(){},Hash:function(e){this.acceptArray(e.pairs)},HashPair:function(e){this.acceptRequired(e,"value")}},t.default=r,e.exports=t.default},function(e,t,i){"use strict";function r(e,t){if(t=t.path?t.path.original:t,e.path.original!==t){var i={loc:e.path.loc};throw new o.default(e.path.original+" doesn't match "+t,i)}}var n=i(1).default;t.__esModule=!0,t.SourceLocation=function(e,t){this.source=e,this.start={line:t.first_line,column:t.first_column},this.end={line:t.last_line,column:t.last_column}},t.id=function(e){return/^\[.*\]$/.test(e)?e.substr(1,e.length-2):e},t.stripFlags=function(e,t){return{open:"~"===e.charAt(2),close:"~"===t.charAt(t.length-3)}},t.stripComment=function(e){return e.replace(/^\{\{~?\!-?-?/,"").replace(/-?-?~?\}\}$/,"")},t.preparePath=function(e,t,i){i=this.locInfo(i);for(var r=e?"@":"",n=[],s=0,a=0,l=t.length;a<l;a++){var h=t[a].part,u=t[a].original!==h;if(r+=(t[a].separator||"")+h,u||".."!==h&&"."!==h&&"this"!==h)n.push(h);else{if(n.length>0)throw new o.default("Invalid path: "+r,{loc:i});".."===h&&s++}}return{type:"PathExpression",data:e,depth:s,parts:n,original:r,loc:i}},t.prepareMustache=function(e,t,i,r,n,o){var s=r.charAt(3)||r.charAt(2),a="{"!==s&&"&"!==s;return{type:/\*/.test(r)?"Decorator":"MustacheStatement",path:e,params:t,hash:i,escaped:a,strip:n,loc:this.locInfo(o)}},t.prepareRawBlock=function(e,t,i,n){r(e,i);var o={type:"Program",body:t,strip:{},loc:n=this.locInfo(n)};return{type:"BlockStatement",path:e.path,params:e.params,hash:e.hash,program:o,openStrip:{},inverseStrip:{},closeStrip:{},loc:n}},t.prepareBlock=function(e,t,i,n,s,a){n&&n.path&&r(e,n);var l=/\*/.test(e.open);t.blockParams=e.blockParams;var h=void 0,u=void 0;if(i){if(l)throw new o.default("Unexpected inverse block on decorator",i);i.chain&&(i.program.body[0].closeStrip=n.strip),u=i.strip,h=i.program}return s&&(s=h,h=t,t=s),{type:l?"DecoratorBlock":"BlockStatement",path:e.path,params:e.params,hash:e.hash,program:t,inverse:h,openStrip:e.strip,inverseStrip:u,closeStrip:n&&n.strip,loc:this.locInfo(a)}},t.prepareProgram=function(e,t){if(!t&&e.length){var i=e[0].loc,r=e[e.length-1].loc;i&&r&&(t={source:i.source,start:{line:i.start.line,column:i.start.column},end:{line:r.end.line,column:r.end.column}})}return{type:"Program",body:e,strip:{},loc:t}},t.preparePartialBlock=function(e,t,i,n){return r(e,i),{type:"PartialBlockStatement",name:e.path,params:e.params,hash:e.hash,program:t,openStrip:e.strip,closeStrip:i&&i.strip,loc:this.locInfo(n)}};var o=n(i(6))},function(e,t,i){"use strict";function r(){}function n(e,t){if(e===t)return!0;if(l.isArray(e)&&l.isArray(t)&&e.length===t.length){for(var i=0;i<e.length;i++)if(!n(e[i],t[i]))return!1;return!0}}function o(e){if(!e.path.parts){var t=e.path;e.path={type:"PathExpression",data:!1,depth:0,parts:[t.original+""],original:t.original+"",loc:t.loc}}}var s=i(1).default;t.__esModule=!0,t.Compiler=r,t.precompile=function(e,t,i){if(null==e||"string"!=typeof e&&"Program"!==e.type)throw new a.default("You must pass a string or Handlebars AST to Handlebars.precompile. You passed "+e);"data"in(t=t||{})||(t.data=!0),t.compat&&(t.useDepths=!0);var r=i.parse(e,t),n=(new i.Compiler).compile(r,t);return(new i.JavaScriptCompiler).compile(n,t)},t.compile=function(e,t,i){function r(){var r=i.parse(e,t),n=(new i.Compiler).compile(r,t),o=(new i.JavaScriptCompiler).compile(n,t,void 0,!0);return i.template(o)}function n(e,t){return o||(o=r()),o.call(this,e,t)}if(void 0===t&&(t={}),null==e||"string"!=typeof e&&"Program"!==e.type)throw new a.default("You must pass a string or Handlebars AST to Handlebars.compile. You passed "+e);"data"in(t=l.extend({},t))||(t.data=!0),t.compat&&(t.useDepths=!0);var o=void 0;return n._setup=function(e){return o||(o=r()),o._setup(e)},n._child=function(e,t,i,n){return o||(o=r()),o._child(e,t,i,n)},n};var a=s(i(6)),l=i(5),h=s(i(35)),u=[].slice;r.prototype={compiler:r,equals:function(e){var t=this.opcodes.length;if(e.opcodes.length!==t)return!1;for(o=0;o<t;o++){var i=this.opcodes[o],r=e.opcodes[o];if(i.opcode!==r.opcode||!n(i.args,r.args))return!1}t=this.children.length;for(var o=0;o<t;o++)if(!this.children[o].equals(e.children[o]))return!1;return!0},guid:0,compile:function(e,t){this.sourceNode=[],this.opcodes=[],this.children=[],this.options=t,this.stringParams=t.stringParams,this.trackIds=t.trackIds,t.blockParams=t.blockParams||[];var i=t.knownHelpers;if(t.knownHelpers={helperMissing:!0,blockHelperMissing:!0,each:!0,if:!0,unless:!0,with:!0,log:!0,lookup:!0},i)for(var r in i)r in i&&(this.options.knownHelpers[r]=i[r]);return this.accept(e)},compileProgram:function(e){var t=(new this.compiler).compile(e,this.options),i=this.guid++;return this.usePartial=this.usePartial||t.usePartial,this.children[i]=t,this.useDepths=this.useDepths||t.useDepths,i},accept:function(e){if(!this[e.type])throw new a.default("Unknown type: "+e.type,e);this.sourceNode.unshift(e);var t=this[e.type](e);return this.sourceNode.shift(),t},Program:function(e){this.options.blockParams.unshift(e.blockParams);for(var t=e.body,i=t.length,r=0;r<i;r++)this.accept(t[r]);return this.options.blockParams.shift(),this.isSimple=1===i,this.blockParams=e.blockParams?e.blockParams.length:0,this},BlockStatement:function(e){o(e);var t=e.program,i=e.inverse;t=t&&this.compileProgram(t),i=i&&this.compileProgram(i);var r=this.classifySexpr(e);"helper"===r?this.helperSexpr(e,t,i):"simple"===r?(this.simpleSexpr(e),this.opcode("pushProgram",t),this.opcode("pushProgram",i),this.opcode("emptyHash"),this.opcode("blockValue",e.path.original)):(this.ambiguousSexpr(e,t,i),this.opcode("pushProgram",t),this.opcode("pushProgram",i),this.opcode("emptyHash"),this.opcode("ambiguousBlockValue")),this.opcode("append")},DecoratorBlock:function(e){var t=e.program&&this.compileProgram(e.program),i=this.setupFullMustacheParams(e,t,void 0),r=e.path;this.useDecorators=!0,this.opcode("registerDecorator",i.length,r.original)},PartialStatement:function(e){this.usePartial=!0;var t=e.program;t&&(t=this.compileProgram(e.program));var i=e.params;if(i.length>1)throw new a.default("Unsupported number of partial arguments: "+i.length,e);i.length||(this.options.explicitPartialContext?this.opcode("pushLiteral","undefined"):i.push({type:"PathExpression",parts:[],depth:0}));var r=e.name.original,n="SubExpression"===e.name.type;n&&this.accept(e.name),this.setupFullMustacheParams(e,t,void 0,!0);var o=e.indent||"";this.options.preventIndent&&o&&(this.opcode("appendContent",o),o=""),this.opcode("invokePartial",n,r,o),this.opcode("append")},PartialBlockStatement:function(e){this.PartialStatement(e)},MustacheStatement:function(e){this.SubExpression(e),e.escaped&&!this.options.noEscape?this.opcode("appendEscaped"):this.opcode("append")},Decorator:function(e){this.DecoratorBlock(e)},ContentStatement:function(e){e.value&&this.opcode("appendContent",e.value)},CommentStatement:function(){},SubExpression:function(e){o(e);var t=this.classifySexpr(e);"simple"===t?this.simpleSexpr(e):"helper"===t?this.helperSexpr(e):this.ambiguousSexpr(e)},ambiguousSexpr:function(e,t,i){var r=e.path,n=r.parts[0],o=null!=t||null!=i;this.opcode("getContext",r.depth),this.opcode("pushProgram",t),this.opcode("pushProgram",i),r.strict=!0,this.accept(r),this.opcode("invokeAmbiguous",n,o)},simpleSexpr:function(e){var t=e.path;t.strict=!0,this.accept(t),this.opcode("resolvePossibleLambda")},helperSexpr:function(e,t,i){var r=this.setupFullMustacheParams(e,t,i),n=e.path,o=n.parts[0];if(this.options.knownHelpers[o])this.opcode("invokeKnownHelper",r.length,o);else{if(this.options.knownHelpersOnly)throw new a.default("You specified knownHelpersOnly, but used the unknown helper "+o,e);n.strict=!0,n.falsy=!0,this.accept(n),this.opcode("invokeHelper",r.length,n.original,h.default.helpers.simpleId(n))}},PathExpression:function(e){this.addDepth(e.depth),this.opcode("getContext",e.depth);var t=e.parts[0],i=h.default.helpers.scopedId(e),r=!e.depth&&!i&&this.blockParamIndex(t);r?this.opcode("lookupBlockParam",r,e.parts):t?e.data?(this.options.data=!0,this.opcode("lookupData",e.depth,e.parts,e.strict)):this.opcode("lookupOnContext",e.parts,e.falsy,e.strict,i):this.opcode("pushContext")},StringLiteral:function(e){this.opcode("pushString",e.value)},NumberLiteral:function(e){this.opcode("pushLiteral",e.value)},BooleanLiteral:function(e){this.opcode("pushLiteral",e.value)},UndefinedLiteral:function(){this.opcode("pushLiteral","undefined")},NullLiteral:function(){this.opcode("pushLiteral","null")},Hash:function(e){var t=e.pairs,i=0,r=t.length;for(this.opcode("pushHash");i<r;i++)this.pushParam(t[i].value);for(;i--;)this.opcode("assignToHash",t[i].key);this.opcode("popHash")},opcode:function(e){this.opcodes.push({opcode:e,args:u.call(arguments,1),loc:this.sourceNode[0].loc})},addDepth:function(e){e&&(this.useDepths=!0)},classifySexpr:function(e){var t=h.default.helpers.simpleId(e.path),i=t&&!!this.blockParamIndex(e.path.parts[0]),r=!i&&h.default.helpers.helperExpression(e),n=!i&&(r||t);if(n&&!r){var o=e.path.parts[0],s=this.options;s.knownHelpers[o]?r=!0:s.knownHelpersOnly&&(n=!1)}return r?"helper":n?"ambiguous":"simple"},pushParams:function(e){for(var t=0,i=e.length;t<i;t++)this.pushParam(e[t])},pushParam:function(e){var t=null!=e.value?e.value:e.original||"";if(this.stringParams)t.replace&&(t=t.replace(/^(\.?\.\/)*/g,"").replace(/\//g,".")),e.depth&&this.addDepth(e.depth),this.opcode("getContext",e.depth||0),this.opcode("pushStringParam",t,e.type),"SubExpression"===e.type&&this.accept(e);else{if(this.trackIds){var i=void 0;if(!e.parts||h.default.helpers.scopedId(e)||e.depth||(i=this.blockParamIndex(e.parts[0])),i){var r=e.parts.slice(1).join(".");this.opcode("pushId","BlockParam",i,r)}else(t=e.original||t).replace&&(t=t.replace(/^this(?:\.|$)/,"").replace(/^\.\//,"").replace(/^\.$/,"")),this.opcode("pushId",e.type,t)}this.accept(e)}},setupFullMustacheParams:function(e,t,i,r){var n=e.params;return this.pushParams(n),this.opcode("pushProgram",t),this.opcode("pushProgram",i),e.hash?this.accept(e.hash):this.opcode("emptyHash",r),n},blockParamIndex:function(e){for(var t=0,i=this.options.blockParams.length;t<i;t++){var r=this.options.blockParams[t],n=r&&l.indexOf(r,e);if(r&&n>=0)return[t,n]}}}},function(e,t,i){"use strict";function r(e){this.value=e}function n(){}function o(e,t,i,r){var n=t.popStack(),o=0,s=i.length;for(e&&s--;o<s;o++)n=t.nameLookup(n,i[o],r);return e?[t.aliasable("container.strict"),"(",n,", ",t.quotedString(i[o]),")"]:n}var s=i(1).default;t.__esModule=!0;var a=i(4),l=s(i(6)),h=i(5),u=s(i(43));n.prototype={nameLookup:function(e,t){return n.isValidJavaScriptVariableName(t)?[e,".",t]:[e,"[",JSON.stringify(t),"]"]},depthedLookup:function(e){return[this.aliasable("container.lookup"),'(depths, "',e,'")']},compilerInfo:function(){var e=a.COMPILER_REVISION;return[e,a.REVISION_CHANGES[e]]},appendToBuffer:function(e,t,i){return h.isArray(e)||(e=[e]),e=this.source.wrap(e,t),this.environment.isSimple?["return ",e,";"]:i?["buffer += ",e,";"]:(e.appendToBuffer=!0,e)},initializeBuffer:function(){return this.quotedString("")},compile:function(e,t,i,r){this.environment=e,this.options=t,this.stringParams=this.options.stringParams,this.trackIds=this.options.trackIds,this.precompile=!r,this.name=this.environment.name,this.isChild=!!i,this.context=i||{decorators:[],programs:[],environments:[]},this.preamble(),this.stackSlot=0,this.stackVars=[],this.aliases={},this.registers={list:[]},this.hashes=[],this.compileStack=[],this.inlineStack=[],this.blockParams=[],this.compileChildren(e,t),this.useDepths=this.useDepths||e.useDepths||e.useDecorators||this.options.compat,this.useBlockParams=this.useBlockParams||e.useBlockParams;var n=e.opcodes,o=void 0,s=void 0,a=void 0,h=void 0;for(a=0,h=n.length;a<h;a++)o=n[a],this.source.currentLocation=o.loc,s=s||o.loc,this[o.opcode].apply(this,o.args);if(this.source.currentLocation=s,this.pushSource(""),this.stackSlot||this.inlineStack.length||this.compileStack.length)throw new l.default("Compile completed with content left on stack");this.decorators.isEmpty()?this.decorators=void 0:(this.useDecorators=!0,this.decorators.prepend("var decorators = container.decorators;\n"),this.decorators.push("return fn;"),r?this.decorators=Function.apply(this,["fn","props","container","depth0","data","blockParams","depths",this.decorators.merge()]):(this.decorators.prepend("function(fn, props, container, depth0, data, blockParams, depths) {\n"),this.decorators.push("}\n"),this.decorators=this.decorators.merge()));var u=this.createFunctionContext(r);if(this.isChild)return u;var c={compiler:this.compilerInfo(),main:u};this.decorators&&(c.main_d=this.decorators,c.useDecorators=!0);var f=this.context,p=f.programs,d=f.decorators;for(a=0,h=p.length;a<h;a++)p[a]&&(c[a]=p[a],d[a]&&(c[a+"_d"]=d[a],c.useDecorators=!0));return this.environment.usePartial&&(c.usePartial=!0),this.options.data&&(c.useData=!0),this.useDepths&&(c.useDepths=!0),this.useBlockParams&&(c.useBlockParams=!0),this.options.compat&&(c.compat=!0),r?c.compilerOptions=this.options:(c.compiler=JSON.stringify(c.compiler),this.source.currentLocation={start:{line:1,column:0}},c=this.objectLiteral(c),t.srcName?(c=c.toStringWithSourceMap({file:t.destName}),c.map=c.map&&c.map.toString()):c=c.toString()),c},preamble:function(){this.lastContext=0,this.source=new u.default(this.options.srcName),this.decorators=new u.default(this.options.srcName)},createFunctionContext:function(e){var t="",i=this.stackVars.concat(this.registers.list);i.length>0&&(t+=", "+i.join(", "));var r=0;for(var n in this.aliases){var o=this.aliases[n];this.aliases.hasOwnProperty(n)&&o.children&&o.referenceCount>1&&(t+=", alias"+ ++r+"="+n,o.children[0]="alias"+r)}var s=["container","depth0","helpers","partials","data"];(this.useBlockParams||this.useDepths)&&s.push("blockParams"),this.useDepths&&s.push("depths");var a=this.mergeSource(t);return e?(s.push(a),Function.apply(this,s)):this.source.wrap(["function(",s.join(","),") {\n ",a,"}"])},mergeSource:function(e){var t=this.environment.isSimple,i=!this.forceBuffer,r=void 0,n=void 0,o=void 0,s=void 0;return this.source.each(function(e){e.appendToBuffer?(o?e.prepend(" + "):o=e,s=e):(o&&(n?o.prepend("buffer += "):r=!0,s.add(";"),o=s=void 0),n=!0,t||(i=!1))}),i?o?(o.prepend("return "),s.add(";")):n||this.source.push('return "";'):(e+=", buffer = "+(r?"":this.initializeBuffer()),o?(o.prepend("return buffer + "),s.add(";")):this.source.push("return buffer;")),e&&this.source.prepend("var "+e.substring(2)+(r?"":";\n")),this.source.merge()},blockValue:function(e){var t=this.aliasable("helpers.blockHelperMissing"),i=[this.contextName(0)];this.setupHelperArgs(e,0,i);var r=this.popStack();i.splice(1,0,r),this.push(this.source.functionCall(t,"call",i))},ambiguousBlockValue:function(){var e=this.aliasable("helpers.blockHelperMissing"),t=[this.contextName(0)];this.setupHelperArgs("",0,t,!0),this.flushInline();var i=this.topStack();t.splice(1,0,i),this.pushSource(["if (!",this.lastHelper,") { ",i," = ",this.source.functionCall(e,"call",t),"}"])},appendContent:function(e){this.pendingContent?e=this.pendingContent+e:this.pendingLocation=this.source.currentLocation,this.pendingContent=e},append:function(){if(this.isInline())this.replaceStack(function(e){return[" != null ? ",e,' : ""']}),this.pushSource(this.appendToBuffer(this.popStack()));else{var e=this.popStack();this.pushSource(["if (",e," != null) { ",this.appendToBuffer(e,void 0,!0)," }"]),this.environment.isSimple&&this.pushSource(["else { ",this.appendToBuffer("''",void 0,!0)," }"])}},appendEscaped:function(){this.pushSource(this.appendToBuffer([this.aliasable("container.escapeExpression"),"(",this.popStack(),")"]))},getContext:function(e){this.lastContext=e},pushContext:function(){this.pushStackLiteral(this.contextName(this.lastContext))},lookupOnContext:function(e,t,i,r){var n=0;r||!this.options.compat||this.lastContext?this.pushContext():this.push(this.depthedLookup(e[n++])),this.resolvePath("context",e,n,t,i)},lookupBlockParam:function(e,t){this.useBlockParams=!0,this.push(["blockParams[",e[0],"][",e[1],"]"]),this.resolvePath("context",t,1)},lookupData:function(e,t,i){e?this.pushStackLiteral("container.data(data, "+e+")"):this.pushStackLiteral("data"),this.resolvePath("data",t,0,!0,i)},resolvePath:function(e,t,i,r,n){var s=this;if(this.options.strict||this.options.assumeObjects)this.push(o(this.options.strict&&n,this,t,e));else for(var a=t.length;i<a;i++)this.replaceStack(function(n){var o=s.nameLookup(n,t[i],e);return r?[" && ",o]:[" != null ? ",o," : ",n]})},resolvePossibleLambda:function(){this.push([this.aliasable("container.lambda"),"(",this.popStack(),", ",this.contextName(0),")"])},pushStringParam:function(e,t){this.pushContext(),this.pushString(t),"SubExpression"!==t&&("string"==typeof e?this.pushString(e):this.pushStackLiteral(e))},emptyHash:function(e){this.trackIds&&this.push("{}"),this.stringParams&&(this.push("{}"),this.push("{}")),this.pushStackLiteral(e?"undefined":"{}")},pushHash:function(){this.hash&&this.hashes.push(this.hash),this.hash={values:[],types:[],contexts:[],ids:[]}},popHash:function(){var e=this.hash;this.hash=this.hashes.pop(),this.trackIds&&this.push(this.objectLiteral(e.ids)),this.stringParams&&(this.push(this.objectLiteral(e.contexts)),this.push(this.objectLiteral(e.types))),this.push(this.objectLiteral(e.values))},pushString:function(e){this.pushStackLiteral(this.quotedString(e))},pushLiteral:function(e){this.pushStackLiteral(e)},pushProgram:function(e){null!=e?this.pushStackLiteral(this.programExpression(e)):this.pushStackLiteral(null)},registerDecorator:function(e,t){var i=this.nameLookup("decorators",t,"decorator"),r=this.setupHelperArgs(t,e);this.decorators.push(["fn = ",this.decorators.functionCall(i,"",["fn","props","container",r])," || fn;"])},invokeHelper:function(e,t,i){var r=this.popStack(),n=this.setupHelper(e,t),o=i?[n.name," || "]:"",s=["("].concat(o,r);this.options.strict||s.push(" || ",this.aliasable("helpers.helperMissing")),s.push(")"),this.push(this.source.functionCall(s,"call",n.callParams))},invokeKnownHelper:function(e,t){var i=this.setupHelper(e,t);this.push(this.source.functionCall(i.name,"call",i.callParams))},invokeAmbiguous:function(e,t){this.useRegister("helper");var i=this.popStack();this.emptyHash();var r=this.setupHelper(0,e,t),n=["(","(helper = ",this.lastHelper=this.nameLookup("helpers",e,"helper")," || ",i,")"];this.options.strict||(n[0]="(helper = ",n.push(" != null ? helper : ",this.aliasable("helpers.helperMissing"))),this.push(["(",n,r.paramsInit?["),(",r.paramsInit]:[],"),","(typeof helper === ",this.aliasable('"function"')," ? ",this.source.functionCall("helper","call",r.callParams)," : helper))"])},invokePartial:function(e,t,i){var r=[],n=this.setupParams(t,1,r);e&&(t=this.popStack(),delete n.name),i&&(n.indent=JSON.stringify(i)),n.helpers="helpers",n.partials="partials",n.decorators="container.decorators",e?r.unshift(t):r.unshift(this.nameLookup("partials",t,"partial")),this.options.compat&&(n.depths="depths"),n=this.objectLiteral(n),r.push(n),this.push(this.source.functionCall("container.invokePartial","",r))},assignToHash:function(e){var t=this.popStack(),i=void 0,r=void 0,n=void 0;this.trackIds&&(n=this.popStack()),this.stringParams&&(r=this.popStack(),i=this.popStack());var o=this.hash;i&&(o.contexts[e]=i),r&&(o.types[e]=r),n&&(o.ids[e]=n),o.values[e]=t},pushId:function(e,t,i){"BlockParam"===e?this.pushStackLiteral("blockParams["+t[0]+"].path["+t[1]+"]"+(i?" + "+JSON.stringify("."+i):"")):"PathExpression"===e?this.pushString(t):"SubExpression"===e?this.pushStackLiteral("true"):this.pushStackLiteral("null")},compiler:n,compileChildren:function(e,t){for(var i=e.children,r=void 0,n=void 0,o=0,s=i.length;o<s;o++){r=i[o],n=new this.compiler;var a=this.matchExistingProgram(r);if(null==a){this.context.programs.push("");var l=this.context.programs.length;r.index=l,r.name="program"+l,this.context.programs[l]=n.compile(r,t,this.context,!this.precompile),this.context.decorators[l]=n.decorators,this.context.environments[l]=r,this.useDepths=this.useDepths||n.useDepths,this.useBlockParams=this.useBlockParams||n.useBlockParams,r.useDepths=this.useDepths,r.useBlockParams=this.useBlockParams}else r.index=a.index,r.name="program"+a.index,this.useDepths=this.useDepths||a.useDepths,this.useBlockParams=this.useBlockParams||a.useBlockParams}},matchExistingProgram:function(e){for(var t=0,i=this.context.environments.length;t<i;t++){var r=this.context.environments[t];if(r&&r.equals(e))return r}},programExpression:function(e){var t=this.environment.children[e],i=[t.index,"data",t.blockParams];return(this.useBlockParams||this.useDepths)&&i.push("blockParams"),this.useDepths&&i.push("depths"),"container.program("+i.join(", ")+")"},useRegister:function(e){this.registers[e]||(this.registers[e]=!0,this.registers.list.push(e))},push:function(e){return e instanceof r||(e=this.source.wrap(e)),this.inlineStack.push(e),e},pushStackLiteral:function(e){this.push(new r(e))},pushSource:function(e){this.pendingContent&&(this.source.push(this.appendToBuffer(this.source.quotedString(this.pendingContent),this.pendingLocation)),this.pendingContent=void 0),e&&this.source.push(e)},replaceStack:function(e){var t=["("],i=void 0,n=void 0,o=void 0;if(!this.isInline())throw new l.default("replaceStack on non-inline");var s=this.popStack(!0);if(s instanceof r)i=[s.value],t=["(",i],o=!0;else{n=!0;var a=this.incrStack();t=["((",this.push(a)," = ",s,")"],i=this.topStack()}var h=e.call(this,i);o||this.popStack(),n&&this.stackSlot--,this.push(t.concat(h,")"))},incrStack:function(){return this.stackSlot++,this.stackSlot>this.stackVars.length&&this.stackVars.push("stack"+this.stackSlot),this.topStackName()},topStackName:function(){return"stack"+this.stackSlot},flushInline:function(){var e=this.inlineStack;this.inlineStack=[];for(var t=0,i=e.length;t<i;t++){var n=e[t];if(n instanceof r)this.compileStack.push(n);else{var o=this.incrStack();this.pushSource([o," = ",n,";"]),this.compileStack.push(o)}}},isInline:function(){return this.inlineStack.length},popStack:function(e){var t=this.isInline(),i=(t?this.inlineStack:this.compileStack).pop();if(!e&&i instanceof r)return i.value;if(!t){if(!this.stackSlot)throw new l.default("Invalid stack pop");this.stackSlot--}return i},topStack:function(){var e=this.isInline()?this.inlineStack:this.compileStack,t=e[e.length-1];return t instanceof r?t.value:t},contextName:function(e){return this.useDepths&&e?"depths["+e+"]":"depth"+e},quotedString:function(e){return this.source.quotedString(e)},objectLiteral:function(e){return this.source.objectLiteral(e)},aliasable:function(e){var t=this.aliases[e];return t?(t.referenceCount++,t):(t=this.aliases[e]=this.source.wrap(e),t.aliasable=!0,t.referenceCount=1,t)},setupHelper:function(e,t,i){var r=[];return{params:r,paramsInit:this.setupHelperArgs(t,e,r,i),name:this.nameLookup("helpers",t,"helper"),callParams:[this.aliasable(this.contextName(0)+" != null ? "+this.contextName(0)+" : (container.nullContext || {})")].concat(r)}},setupParams:function(e,t,i){var r={},n=[],o=[],s=[],a=!i,l=void 0;a&&(i=[]),r.name=this.quotedString(e),r.hash=this.popStack(),this.trackIds&&(r.hashIds=this.popStack()),this.stringParams&&(r.hashTypes=this.popStack(),r.hashContexts=this.popStack());var h=this.popStack(),u=this.popStack();(u||h)&&(r.fn=u||"container.noop",r.inverse=h||"container.noop");for(var c=t;c--;)l=this.popStack(),i[c]=l,this.trackIds&&(s[c]=this.popStack()),this.stringParams&&(o[c]=this.popStack(),n[c]=this.popStack());return a&&(r.args=this.source.generateArray(i)),this.trackIds&&(r.ids=this.source.generateArray(s)),this.stringParams&&(r.types=this.source.generateArray(o),r.contexts=this.source.generateArray(n)),this.options.data&&(r.data="data"),this.useBlockParams&&(r.blockParams="blockParams"),r},setupHelperArgs:function(e,t,i,r){var n=this.setupParams(e,t,i);return n=this.objectLiteral(n),r?(this.useRegister("options"),i.push("options"),["options=",n]):i?(i.push(n),""):n}},function(){for(var e="break else new var case finally return void catch for switch while continue function this with default if throw delete in try do instanceof typeof abstract enum int short boolean export interface static byte extends long super char final native synchronized class float package throws const goto private transient debugger implements protected volatile double import public let yield await null true false".split(" "),t=n.RESERVED_WORDS={},i=0,r=e.length;i<r;i++)t[e[i]]=!0}(),n.isValidJavaScriptVariableName=function(e){return!n.RESERVED_WORDS[e]&&/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(e)},t.default=n,e.exports=t.default},function(e,t,i){"use strict";function r(e,t,i){if(o.isArray(e)){for(var r=[],n=0,s=e.length;n<s;n++)r.push(t.wrap(e[n],i));return r}return"boolean"==typeof e||"number"==typeof e?e+"":e}function n(e){this.srcFile=e,this.source=[]}t.__esModule=!0;var o=i(5),s=void 0;s||(s=function(e,t,i,r){this.src="",r&&this.add(r)},s.prototype={add:function(e){o.isArray(e)&&(e=e.join("")),this.src+=e},prepend:function(e){o.isArray(e)&&(e=e.join("")),this.src=e+this.src},toStringWithSourceMap:function(){return{code:this.toString()}},toString:function(){return this.src}}),n.prototype={isEmpty:function(){return!this.source.length},prepend:function(e,t){this.source.unshift(this.wrap(e,t))},push:function(e,t){this.source.push(this.wrap(e,t))},merge:function(){var e=this.empty();return this.each(function(t){e.add([" ",t,"\n"])}),e},each:function(e){for(var t=0,i=this.source.length;t<i;t++)e(this.source[t])},empty:function(){var e=this.currentLocation||{start:{}};return new s(e.start.line,e.start.column,this.srcFile)},wrap:function(e){var t=arguments.length<=1||void 0===arguments[1]?this.currentLocation||{start:{}}:arguments[1];return e instanceof s?e:(e=r(e,this,t),new s(t.start.line,t.start.column,this.srcFile,e))},functionCall:function(e,t,i){return i=this.generateList(i),this.wrap([e,t?"."+t+"(":"(",i,")"])},quotedString:function(e){return'"'+(e+"").replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")+'"'},objectLiteral:function(e){var t=[];for(var i in e)if(e.hasOwnProperty(i)){var n=r(e[i],this);"undefined"!==n&&t.push([this.quotedString(i),":",n])}var o=this.generateList(t);return o.prepend("{"),o.add("}"),o},generateList:function(e){for(var t=this.empty(),i=0,n=e.length;i<n;i++)i&&t.add(","),t.add(r(e[i],this));return t},generateArray:function(e){var t=this.generateList(e);return t.prepend("["),t.add("]"),t}},t.default=n,e.exports=t.default}])})},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(2),n=i(20),o=i(27),s=function(){function e(){}return e.prototype.loadConfiguration=function(e){void 0===e&&(e={});var t=o.default({},e),i=n.getConfigurationType(t&&t.extends);if((t=o.default(i,t)).configuration){var s="json",a=t.configuration;t.configuration.url&&(a=t.configuration.url,(s=t.configuration.mapper)||(s=t.configuration.url.split(".").pop()));var l=r.mapperManager.getMapper(s);return this.loadFile(a).then(function(e){var i=l.map(e);return o.default(t,i)})}return Promise.resolve(t)},e.prototype.getConfigurationType=function(e){},e.prototype.loadFile=function(e){var t=this.configurationCache;return t[e]?Promise.resolve(t[e]):new Promise(function(i,r){var n=new XMLHttpRequest;n.open("GET",e),n.send(),n.onreadystatechange=function(){4===n.readyState?200===n.status&&(t[e]=n.responseText,i(n.responseText)):(console.log("Error: "+n.status,e),r("Error: "+n.status))}})},e}();t.ConfigurationLoader=s,t.configurationLoader=new s,t.default=t.configurationLoader},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(21);t.minimalConfiguration=r.minimalConfiguration;var n=i(22);t.defaultConfiguration=n.defaultConfiguration;t.getConfigurationType=function(e){switch(e){case"default":return n.defaultConfiguration;case"minimal":return r.minimalConfiguration;default:return n.defaultConfiguration}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.minimalConfiguration={version:"0.1",templates:{main:{html:i(7)},loadingScreen:{html:i(8),params:{backgroundColor:"#000000",loadingImage:i(9)}},viewer:{html:i(10)},overlay:{html:i(11),params:{closeImage:i(12),closeText:"Close"}},error:{html:i(13)}},engine:{antialiasing:!0}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.defaultConfiguration={version:"0.1",templates:{main:{html:i(7)},loadingScreen:{html:i(8),params:{backgroundColor:"#000000",loadingImage:i(9)}},viewer:{html:i(10)},navBar:{html:i(23),params:{buttons:[{id:"fullscreen-button",altText:"Fullscreen",image:i(24)}],visibilityTimeout:2e3},events:{pointerdown:{"fullscreen-button":!0}}},overlay:{html:i(11),params:{closeImage:i(12),closeText:"Close"}},help:{html:i(25)},share:{html:i(26)},error:{html:i(13)}},camera:{behaviors:{autoRotate:0,framing:{type:2,zoomOnBoundingInfo:!0,zoomStopsAnimation:!1}}},skybox:{cubeTexture:{url:"https://playground.babylonjs.com/textures/environment.dds",gammaSpace:!1},pbr:!0,blur:.7,infiniteDIstance:!1,material:{imageProcessingConfiguration:{colorCurves:{globalDensity:89,globalHue:58.88,globalSaturation:94},colorCurvesEnabled:!0,exposure:1.5,contrast:1.66,toneMappingEnabled:!0,vignetteEnabled:!0,vignetteWeight:5,vignetteColor:{r:.8,g:.6,b:.4},vignetteM:!0}}},ground:!0,engine:{antialiasing:!0},scene:{imageProcessingConfiguration:{exposure:1.4,contrast:1.66,toneMappingEnabled:!0}}}},function(e,t){e.exports='<style>\r\n nav-bar {\r\n position: absolute;\r\n height: 160px;\r\n width: 100%;\r\n bottom: 0;\r\n background-color: rgba(0, 0, 0, 0.3);\r\n color: white;\r\n transition: 1s;\r\n align-items: flex-start;\r\n justify-content: space-around;\r\n display: flex;\r\n\r\n flex-direction: column;\r\n }\r\n\r\n /* Big screens have room for the entire navbar */\r\n\r\n @media screen and (min-width: 768px) {\r\n nav-bar {\r\n align-items: center;\r\n flex-direction: row;\r\n justify-content: space-between;\r\n height: 80px;\r\n }\r\n }\r\n\r\n div.flex-container {\r\n display: flex;\r\n width: 100%;\r\n }\r\n\r\n div.thumbnail {\r\n position: relative;\r\n overflow: hidden;\r\n display: block;\r\n width: 40px;\r\n height: 40px;\r\n background-size: cover;\r\n background-position: center;\r\n border-radius: 20px;\r\n margin: 0 10px;\r\n }\r\n\r\n div.title-container {\r\n flex-direction: column;\r\n display: flex;\r\n justify-content: space-between;\r\n }\r\n\r\n span.model-title {\r\n font-size: 125%;\r\n }\r\n\r\n span.model-subtitle {\r\n font-size: 90%;\r\n }\r\n\r\n div.button-container {\r\n align-items: center;\r\n justify-content: flex-end;\r\n }\r\n\r\n div.button {\r\n cursor: pointer;\r\n height: 30px;\r\n margin: 0 10px;\r\n }\r\n\r\n div.button img {\r\n height: 100%;\r\n }\r\n</style>\r\n\r\n{{#if disableOnFullscreen}}\r\n<style>\r\n viewer:fullscreen nav-bar {\r\n display: none;\r\n }\r\n\r\n viewer:-moz-full-screen nav-bar {\r\n display: none;\r\n }\r\n\r\n viewer:-webkit-full-screen nav-bar {\r\n display: none;\r\n }\r\n</style>\r\n{{/if}}\r\n\r\n<div class="flex-container" id="model-metadata">\r\n \x3c!-- holding the description --\x3e\r\n <div class="thumbnail">\r\n \x3c!-- holding the thumbnail \r\n <img src="{{thumbnail}}" alt="{{title}}">--\x3e\r\n </div>\r\n <div class="title-container">\r\n\r\n <span class="model-title">{{#if title}}{{title}}{{/if}}</span>\r\n <span class="model-subtitle"> {{#if subtitle}}{{subtitle}} {{/if}}</span>\r\n </div>\r\n</div>\r\n<div class="button-container flex-container">\r\n \x3c!-- holding the buttons --\x3e\r\n {{#each buttons}}\r\n <div id="{{id}}" class="button">\r\n {{#if text}}\r\n <span>{{text}}</span>> {{/if}} {{#if image}}\r\n <img src="{{image}}" alt="{{altText}}"> {{/if}}\r\n </div>\r\n {{/each}}\r\n</div>'},function(e,t){e.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAAASAAAAEgARslrPgAAAG5JREFUaN7t2NEKgCAMBVAX/f8v21MvQTDEHNI5z21wU7HVGgBQJ7IP9t57qmFErOhzO758OysIUO0cLczu0Wxd9mw8bb8CAlQTAAAqDU9ko1+js/tvfxMLUE2AasMz8dsMO+u/UNb2KyAAAPBnFyAoHCsn18AtAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE3LTEwLTI0VDA5OjI5OjA3KzAwOjAwnIEg5AAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxNy0xMC0yNFQwOToyOTowNyswMDowMO3cmFgAAAAodEVYdHN2ZzpiYXNlLXVyaQBmaWxlOi8vL3RtcC9tYWdpY2stYU9TenZXZUYevZw/AAAAAElFTkSuQmCC"},function(e,t){e.exports="HELP"},function(e,t){e.exports="SHARE"},function(e,t,i){"use strict";function r(e){return!!e&&"object"==typeof e}function n(e){var t=Object.prototype.toString.call(e);return"[object RegExp]"===t||"[object Date]"===t||o(e)}function o(e){return e.$$typeof===f}function s(e){return Array.isArray(e)?[]:{}}function a(e,t){return(!t||!1!==t.clone)&&c(e)?u(s(e),e,t):e}function l(e,t,i){return e.concat(t).map(function(e){return a(e,i)})}function h(e,t,i){var r={};return c(e)&&Object.keys(e).forEach(function(t){r[t]=a(e[t],i)}),Object.keys(t).forEach(function(n){c(t[n])&&e[n]?r[n]=u(e[n],t[n],i):r[n]=a(t[n],i)}),r}function u(e,t,i){var r=Array.isArray(t);return r===Array.isArray(e)?r?((i||{arrayMerge:l}).arrayMerge||l)(e,t,i):h(e,t,i):a(t,i)}Object.defineProperty(t,"__esModule",{value:!0});var c=function(e){return r(e)&&!n(e)},f="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;u.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce(function(e,i){return u(e,i,t)},{})};var p=u;t.default=p},function(e,t,i){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])};return function(t,i){function r(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}();Object.defineProperty(t,"__esModule",{value:!0});var n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.prototype.notifyWithPromise=function(e,t,i,r){void 0===t&&(t=-1);var n=Promise.resolve();if(!this._observers.length)return n;var o=this._eventState;return o.mask=t,o.target=i,o.currentTarget=r,o.skipNextObservers=!1,this._observers.forEach(function(i){o.skipNextObservers||i.mask&t&&(n=i.scope?n.then(function(){return i.callback.apply(i.scope,[e,o])}):n.then(function(){return i.callback(e,o)}))}),n},t}(i(0).Observable);t.PromiseObservable=n},function(e,t,i){(function(t){var r=void 0!==t?t:"undefined"!=typeof window?window:this,n=r&&r.BABYLON||n||i(0),o=(this&&this.__decorate,this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])};return function(t,i){function r(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}());!function(e){var t=function(){function t(){this.solidPattern=/solid (\S*)([\S\s]*)endsolid[ ]*(\S*)/g,this.facetsPattern=/facet([\s\S]*?)endfacet/g,this.normalPattern=/normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g,this.vertexPattern=/vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g,this.name="stl",this.extensions={".stl":{isBinary:!0}}}return t.prototype.importMesh=function(t,i,r,n,o,s,a){var l;if(this.isBinary(r)){p=new e.Mesh("stlmesh",i);return this.parseBinary(p,r),o&&o.push(p),!0}for(var h=new Uint8Array(r),u="",c=0;c<r.byteLength;c++)u+=String.fromCharCode(h[c]);for(r=u;l=this.solidPattern.exec(r);){var f=l[1];if(f!=l[3])return e.Tools.Error("Error in STL, solid name != endsolid name"),!1;if(t&&f)if(t instanceof Array){if(!t.indexOf(f))continue}else if(f!==t)continue;f=f||"stlmesh";var p=new e.Mesh(f,i);this.parseASCII(p,l[2]),o&&o.push(p)}return!0},t.prototype.load=function(e,t,i){var r=this.importMesh(null,e,t,i,null,null,null);return r&&e.createDefaultCameraOrLight(),r},t.prototype.isBinary=function(e){var t;if(t=new DataView(e),50,84+50*t.getUint32(80,!0)===t.byteLength)return!0;for(var i=t.byteLength,r=0;r<i;r++)if(t.getUint8(r)>127)return!0;return!1},t.prototype.parseBinary=function(t,i){for(var r=new DataView(i),n=r.getUint32(80,!0),o=0,s=new Float32Array(3*n*3),a=new Float32Array(3*n*3),l=new Uint32Array(3*n),h=0,u=0;u<n;u++){for(var c=84+50*u,f=r.getFloat32(c,!0),p=r.getFloat32(c+4,!0),d=r.getFloat32(c+8,!0),m=1;m<=3;m++){var g=c+12*m;s[o]=r.getFloat32(g,!0),s[o+2]=r.getFloat32(g+4,!0),s[o+1]=r.getFloat32(g+8,!0),a[o]=f,a[o+2]=p,a[o+1]=d,o+=3}l[h]=h++,l[h]=h++,l[h]=h++}t.setVerticesData(e.VertexBuffer.PositionKind,s),t.setVerticesData(e.VertexBuffer.NormalKind,a),t.setIndices(l),t.computeWorldMatrix(!0)},t.prototype.parseASCII=function(t,i){for(var r,n=[],o=[],s=[],a=0;r=this.facetsPattern.exec(i);){var l=r[1],h=this.normalPattern.exec(l);if(this.normalPattern.lastIndex=0,h){for(var u,c=[Number(h[1]),Number(h[5]),Number(h[3])];u=this.vertexPattern.exec(l);)n.push(Number(u[1]),Number(u[5]),Number(u[3])),o.push(c[0],c[1],c[2]);s.push(a++,a++,a++),this.vertexPattern.lastIndex=0}}this.facetsPattern.lastIndex=0,t.setVerticesData(e.VertexBuffer.PositionKind,n),t.setVerticesData(e.VertexBuffer.NormalKind,o),t.setIndices(s),t.computeWorldMatrix(!0)},t}();e.STLFileLoader=t,e.SceneLoader&&e.SceneLoader.RegisterPlugin(new t)}(n||(n={}));!function(e){var t=function(){function t(){this.materials=[]}return t.prototype.parseMTL=function(i,r,n){for(var o,s=r.split("\n"),a=/\s+/,l=null,h=0;h<s.length;h++){var u=s[h].trim();if(0!==u.length&&"#"!==u.charAt(0)){var c=u.indexOf(" "),f=c>=0?u.substring(0,c):u;f=f.toLowerCase();var p=c>=0?u.substring(c+1).trim():"";"newmtl"===f?(l&&this.materials.push(l),l=new e.StandardMaterial(p,i)):"kd"===f&&l?(o=p.split(a,3).map(parseFloat),l.diffuseColor=e.Color3.FromArray(o)):"ka"===f&&l?(o=p.split(a,3).map(parseFloat),l.ambientColor=e.Color3.FromArray(o)):"ks"===f&&l?(o=p.split(a,3).map(parseFloat),l.specularColor=e.Color3.FromArray(o)):"ke"===f&&l?(o=p.split(a,3).map(parseFloat),l.emissiveColor=e.Color3.FromArray(o)):"ns"===f&&l?l.specularPower=parseFloat(p):"d"===f&&l?l.alpha=parseFloat(p):"map_ka"===f&&l?l.ambientTexture=t._getTexture(n,p,i):"map_kd"===f&&l?l.diffuseTexture=t._getTexture(n,p,i):"map_ks"===f&&l?l.specularTexture=t._getTexture(n,p,i):"map_ns"===f||("map_bump"===f&&l?l.bumpTexture=t._getTexture(n,p,i):"map_d"===f&&l&&(l.opacityTexture=t._getTexture(n,p,i)))}}l&&this.materials.push(l)},t._getTexture=function(t,i,r){if(!i)return null;var n=t;if("file:"===t){var o=i.lastIndexOf("\\");-1===o&&(o=i.lastIndexOf("/")),n+=o>-1?i.substr(o+1):i}else n+=i;return new e.Texture(n,r)},t}();e.MTLFileLoader=t;var i=function(){function i(){this.name="obj",this.extensions=".obj",this.obj=/^o/,this.group=/^g/,this.mtllib=/^mtllib /,this.usemtl=/^usemtl /,this.smooth=/^s /,this.vertexPattern=/v( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.normalPattern=/vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.uvPattern=/vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.facePattern1=/f\s+(([\d]{1,}[\s]?){3,})+/,this.facePattern2=/f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,this.facePattern3=/f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,this.facePattern4=/f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/}return i.prototype._loadMTL=function(t,i,r){var n=e.Tools.BaseUrl+i+t;e.Tools.LoadFile(n,r,void 0,void 0,!1,function(){console.warn("Error - Unable to load "+n)})},i.prototype.importMesh=function(e,t,i,r,n,o,s){var a=this._parseSolid(e,t,i,r);return n&&a.forEach(function(e){n.push(e)}),!0},i.prototype.load=function(e,t,i){return this.importMesh(null,e,t,i,null,null,null)},i.prototype._parseSolid=function(r,n,o,s){for(var a,l=[],h=[],u=[],c=[],f=[],p=[],d=[],m=[],g=[],v=0,_=!1,y=[],x=[],b=[],T=[],E="",A="",P=new t,S=1,M=!0,C=function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[]});var i=e[t[0]].normals.indexOf(t[1]);return-1===i?-1:e[t[0]].idx[i]},R=function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[],uv:[]});var i=e[t[0]].normals.indexOf(t[1]);return 1!=i&&t[2]==e[t[0]].uv[i]?e[t[0]].idx[i]:-1},I=function(e,t,r,n,o,s){var a;-1==(a=i.OPTIMIZE_WITH_UV?R(g,[e,r,t]):C(g,[e,r]))?(f.push(p.length),p.push(n),d.push(o),m.push(s),g[e].normals.push(r),g[e].idx.push(v++),i.OPTIMIZE_WITH_UV&&g[e].uv.push(t)):f.push(a)},O=function(){for(var e=0;e<p.length;e++)y.push(p[e].x,p[e].y,p[e].z),x.push(m[e].x,m[e].y,m[e].z),b.push(d[e].x,d[e].y);p=[],m=[],d=[],g=[],v=0},D=function(e,t){t+1<e.length&&(T.push(e[0],e[t],e[t+1]),t+=1,D(e,t))},w=function(){c.length>0&&(a=c[c.length-1],O(),f.reverse(),a.indices=f.slice(),a.positions=y.slice(),a.normals=x.slice(),a.uvs=b.slice(),f=[],y=[],x=[],b=[])},L=o.split("\n"),F=0;F<L.length;F++){var N,B=L[F].trim();if(0!==B.length&&"#"!==B.charAt(0))if(null!==(N=this.vertexPattern.exec(B)))l.push(new e.Vector3(parseFloat(N[1]),parseFloat(N[2]),parseFloat(N[3])));else if(null!==(N=this.normalPattern.exec(B)))h.push(new e.Vector3(parseFloat(N[1]),parseFloat(N[2]),parseFloat(N[3])));else if(null!==(N=this.uvPattern.exec(B)))u.push(new e.Vector2(parseFloat(N[1]),parseFloat(N[2])));else if(null!==(N=this.facePattern3.exec(B)))!function(e,t){D(e,1);for(var i=0;i<T.length;i++){var r=T[i].split("/"),n=parseInt(r[0])-1,o=parseInt(r[1])-1,s=parseInt(r[2])-1;I(n,o,s,l[n],u[o],h[s])}T=[]}(N[1].trim().split(" "));else if(null!==(N=this.facePattern4.exec(B)))!function(t,i){D(t,1);for(var r=0;r<T.length;r++){var n=T[r].split("//"),o=parseInt(n[0])-1,s=parseInt(n[1])-1;I(o,1,s,l[o],e.Vector2.Zero(),h[s])}T=[]}(N[1].trim().split(" "));else if(null!==(N=this.facePattern2.exec(B)))!function(t,i){D(t,1);for(var r=0;r<T.length;r++){var n=T[r].split("/"),o=parseInt(n[0])-1,s=parseInt(n[1])-1;I(o,s,0,l[o],u[s],e.Vector3.Up())}T=[]}(N[1].trim().split(" "));else if(null!==(N=this.facePattern1.exec(B)))!function(t,i){D(t,1);for(var r=0;r<T.length;r++){var n=parseInt(T[r])-1;I(n,0,0,l[n],e.Vector2.Zero(),e.Vector3.Up())}T=[]}(N[1].trim().split(" "));else if(this.group.test(B)||this.obj.test(B)){V={name:B.substring(2).trim(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:""};w(),c.push(V),_=!0,M=!0,S=1}else if(this.usemtl.test(B)){if(E=B.substring(7).trim(),!M){w();var V={name:"_mm"+S.toString(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:E};S++,c.push(V)}_&&M&&(c[c.length-1].materialName=E,M=!1)}else this.mtllib.test(B)?A=B.substring(7).trim():this.smooth.test(B)||console.log("Unhandled expression at line : "+B)}_&&(a=c[c.length-1],f.reverse(),O(),a.indices=f,a.positions=y,a.normals=x,a.uvs=b),_||(f.reverse(),O(),c.push({name:e.Geometry.RandomId(),indices:f,positions:y,normals:x,uvs:b,materialName:E}));for(var U=[],z=new Array,k=0;k<c.length;k++){if(r&&c[k].name)if(r instanceof Array){if(-1==r.indexOf(c[k].name))continue}else if(c[k].name!==r)continue;a=c[k];var G=new e.Mesh(c[k].name,n);z.push(c[k].materialName);var H=new e.VertexData;H.positions=a.positions,H.normals=a.normals,H.uvs=a.uvs,H.indices=a.indices,H.applyToMesh(G),U.push(G)}return""!==A&&this._loadMTL(A,s,function(e){P.parseMTL(n,e,s);for(var t=0;t<P.materials.length;t++){for(var i,r=0,o=[];(i=z.indexOf(P.materials[t].name,r))>-1;)o.push(i),r=i+1;if(-1==i&&0==o.length)P.materials[t].dispose();else for(var a=0;a<o.length;a++)U[o[a]].material=P.materials[t]}}),U},i.OPTIMIZE_WITH_UV=!1,i}();e.OBJFileLoader=i,e.SceneLoader&&e.SceneLoader.RegisterPlugin(new i)}(n||(n={}));!function(e){var t;!function(e){e[e.AUTO=0]="AUTO",e[e.PASS_THROUGH=1]="PASS_THROUGH",e[e.FORCE_RIGHT_HANDED=2]="FORCE_RIGHT_HANDED"}(t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var i=function(){function e(){this.coordinateSystemMode=t.AUTO,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return e.prototype.dispose=function(){this._loader&&this._loader.dispose()},e.prototype.importMeshAsync=function(t,i,r,n,o,s,a){try{var l=e._parse(r);this.onParsed&&this.onParsed(l),this._loader=this._getLoader(l),this._loader.importMeshAsync(t,i,l,n,o,s,a)}catch(e){a(e.message)}},e.prototype.loadAsync=function(t,i,r,n,o,s){try{var a=e._parse(i);this.onParsed&&this.onParsed(a),this._loader=this._getLoader(a),this._loader.loadAsync(t,a,r,n,o,s)}catch(e){s(e.message)}},e.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},e.prototype.createPlugin=function(){return new e},e._parse=function(t){return t instanceof ArrayBuffer?e._parseBinary(t):{json:JSON.parse(t),bin:null}},e.prototype._getLoader=function(t){var i={major:2,minor:0},r=t.json.asset||{},n=e._parseVersion(r.version);if(!n)throw new Error("Invalid version: "+r.version);if(void 0!==r.minVersion){var o=e._parseVersion(r.minVersion);if(!o)throw new Error("Invalid minimum version: "+r.minVersion);if(e._compareVersion(o,i)>0)throw new Error("Incompatible minimum version: "+r.minVersion)}var s={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2}[n.major];if(!s)throw new Error("Unsupported version: "+r.version);return s(this)},e._parseBinary=function(t){var i=new r(t),n=i.readUint32();if(1179937895!==n)throw new Error("Unexpected magic: "+n);var o=i.readUint32();switch(o){case 1:return e._parseV1(i);case 2:return e._parseV2(i)}throw new Error("Unsupported version: "+o)},e._parseV1=function(t){var i={JSON:0},r=t.readUint32();if(r!=t.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+t.getLength());var n,o=t.readUint32(),s=t.readUint32();switch(s){case i.JSON:n=JSON.parse(e._decodeBufferToText(t.readUint8Array(o)));break;default:throw new Error("Unexpected content format: "+s)}var a=t.getLength()-t.getPosition();return{json:n,bin:t.readUint8Array(a)}},e._parseV2=function(t){var i={JSON:1313821514,BIN:5130562},r=t.readUint32();if(r!==t.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+t.getLength());var n=t.readUint32();if(t.readUint32()!==i.JSON)throw new Error("First chunk format is not JSON");for(var o=JSON.parse(e._decodeBufferToText(t.readUint8Array(n))),s=null;t.getPosition()<t.getLength();){var a=t.readUint32();switch(t.readUint32()){case i.JSON:throw new Error("Unexpected JSON chunk");case i.BIN:s=t.readUint8Array(a);break;default:t.skipBytes(a)}}return{json:o,bin:s}},e._parseVersion=function(e){var t=(e+"").match(/^(\d+)\.(\d+)$/);return t?{major:parseInt(t[1]),minor:parseInt(t[2])}:null},e._compareVersion=function(e,t){return e.major>t.major?1:e.major<t.major?-1:e.minor>t.minor?1:e.minor<t.minor?-1:0},e._decodeBufferToText=function(e){for(var t="",i=e.byteLength,r=0;r<i;r++)t+=String.fromCharCode(e[r]);return t},e.HomogeneousCoordinates=!1,e.IncrementalLoading=!0,e}();e.GLTFFileLoader=i;var r=function(){function e(e){this._arrayBuffer=e,this._dataView=new DataView(e),this._byteOffset=0}return e.prototype.getPosition=function(){return this._byteOffset},e.prototype.getLength=function(){return this._arrayBuffer.byteLength},e.prototype.readUint32=function(){var e=this._dataView.getUint32(this._byteOffset,!0);return this._byteOffset+=4,e},e.prototype.readUint8Array=function(e){var t=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,t},e.prototype.skipBytes=function(e){this._byteOffset+=e},e}();e.SceneLoader&&e.SceneLoader.RegisterPlugin(new i)}(n||(n={}));!function(e){!function(e){!function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.FLOAT=5126]="FLOAT"}(e.EComponentType||(e.EComponentType={})),function(e){e[e.FRAGMENT=35632]="FRAGMENT",e[e.VERTEX=35633]="VERTEX"}(e.EShaderType||(e.EShaderType={})),function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.INT=5124]="INT",e[e.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.FLOAT=5126]="FLOAT",e[e.FLOAT_VEC2=35664]="FLOAT_VEC2",e[e.FLOAT_VEC3=35665]="FLOAT_VEC3",e[e.FLOAT_VEC4=35666]="FLOAT_VEC4",e[e.INT_VEC2=35667]="INT_VEC2",e[e.INT_VEC3=35668]="INT_VEC3",e[e.INT_VEC4=35669]="INT_VEC4",e[e.BOOL=35670]="BOOL",e[e.BOOL_VEC2=35671]="BOOL_VEC2",e[e.BOOL_VEC3=35672]="BOOL_VEC3",e[e.BOOL_VEC4=35673]="BOOL_VEC4",e[e.FLOAT_MAT2=35674]="FLOAT_MAT2",e[e.FLOAT_MAT3=35675]="FLOAT_MAT3",e[e.FLOAT_MAT4=35676]="FLOAT_MAT4",e[e.SAMPLER_2D=35678]="SAMPLER_2D"}(e.EParameterType||(e.EParameterType={})),function(e){e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.REPEAT=10497]="REPEAT"}(e.ETextureWrapMode||(e.ETextureWrapMode={})),function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9728]="LINEAR",e[e.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",e[e.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR"}(e.ETextureFilterType||(e.ETextureFilterType={})),function(e){e[e.ALPHA=6406]="ALPHA",e[e.RGB=6407]="RGB",e[e.RGBA=6408]="RGBA",e[e.LUMINANCE=6409]="LUMINANCE",e[e.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA"}(e.ETextureFormat||(e.ETextureFormat={})),function(e){e[e.FRONT=1028]="FRONT",e[e.BACK=1029]="BACK",e[e.FRONT_AND_BACK=1032]="FRONT_AND_BACK"}(e.ECullingType||(e.ECullingType={})),function(e){e[e.ZERO=0]="ZERO",e[e.ONE=1]="ONE",e[e.SRC_COLOR=768]="SRC_COLOR",e[e.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",e[e.DST_COLOR=774]="DST_COLOR",e[e.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",e[e.SRC_ALPHA=770]="SRC_ALPHA",e[e.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",e[e.DST_ALPHA=772]="DST_ALPHA",e[e.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",e[e.CONSTANT_COLOR=32769]="CONSTANT_COLOR",e[e.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",e[e.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",e[e.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",e[e.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE"}(e.EBlendingFunction||(e.EBlendingFunction={}))}(e.GLTF1||(e.GLTF1={}))}(n||(n={}));!function(e){!function(t){var i;!function(e){e[e.IDENTIFIER=1]="IDENTIFIER",e[e.UNKNOWN=2]="UNKNOWN",e[e.END_OF_INPUT=3]="END_OF_INPUT"}(i||(i={}));var r=function(){function e(e){this._pos=0,this.isLetterOrDigitPattern=/^[a-zA-Z0-9]+$/,this._toParse=e,this._maxPos=e.length}return e.prototype.getNextToken=function(){if(this.isEnd())return i.END_OF_INPUT;if(this.currentString=this.read(),this.currentToken=i.UNKNOWN,"_"===this.currentString||this.isLetterOrDigitPattern.test(this.currentString))for(this.currentToken=i.IDENTIFIER,this.currentIdentifier=this.currentString;!this.isEnd()&&(this.isLetterOrDigitPattern.test(this.currentString=this.peek())||"_"===this.currentString);)this.currentIdentifier+=this.currentString,this.forward();return this.currentToken},e.prototype.peek=function(){return this._toParse[this._pos]},e.prototype.read=function(){return this._toParse[this._pos++]},e.prototype.forward=function(){this._pos++},e.prototype.isEnd=function(){return this._pos>=this._maxPos},e}(),n=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],o=["world","view","projection","worldView","worldViewProjection","mBones"],s=["translation","rotation","scale"],a=["position","rotationQuaternion","scaling"],l=function(e,t){for(var i in e){var r=e[i];t.buffers[i]=r,t.buffersCount++}},h=function(e,t){for(var i in e){var r=e[i];t.shaders[i]=r,t.shaderscount++}},u=function(e,t,i){for(var r in e){var n=e[r];i[t][r]=n}},c=function(e){if(e)for(var t=0;t<e.length/2;t++)e[2*t+1]=1-e[2*t+1]},f=function(e){if("NORMAL"===e.semantic)return"normal";if("POSITION"===e.semantic)return"position";if("JOINT"===e.semantic)return"matricesIndices";if("WEIGHT"===e.semantic)return"matricesWeights";if("COLOR"===e.semantic)return"color";if(e.semantic&&-1!==e.semantic.indexOf("TEXCOORD_")){var t=Number(e.semantic.split("_")[1]);return"uv"+(0===t?"":t+1)}return null},p=function(i){for(var r in i.animations){var n=i.animations[r];if(n.channels&&n.samplers)for(var o=null,l=0;l<n.channels.length;l++){var h=n.channels[l],u=n.samplers[h.sampler];if(u){var c=null,f=null;n.parameters?(c=n.parameters[u.input],f=n.parameters[u.output]):(c=u.input,f=u.output);var p=t.GLTFUtils.GetBufferFromAccessor(i,i.accessors[c]),d=t.GLTFUtils.GetBufferFromAccessor(i,i.accessors[f]),m=h.target.id,g=i.scene.getNodeByID(m);if(null===g&&(g=i.scene.getNodeByName(m)),null!==g){var v=g instanceof e.Bone,_=h.target.path,y=s.indexOf(_);-1!==y&&(_=a[y]);var x=e.Animation.ANIMATIONTYPE_MATRIX;v||("rotationQuaternion"===_?(x=e.Animation.ANIMATIONTYPE_QUATERNION,g.rotationQuaternion=new e.Quaternion):x=e.Animation.ANIMATIONTYPE_VECTOR3);var b=null,T=[],E=0,A=!1;v&&o&&o.getKeys().length===p.length&&(b=o,A=!0),A||(b=new e.Animation(r,v?"_matrix":_,1,x,e.Animation.ANIMATIONLOOPMODE_CYCLE));for(var P=0;P<p.length;P++){var S=null;if("rotationQuaternion"===_?(S=e.Quaternion.FromArray([d[E],d[E+1],d[E+2],d[E+3]]),E+=4):(S=e.Vector3.FromArray([d[E],d[E+1],d[E+2]]),E+=3),v){var M=g,C=e.Vector3.Zero(),R=new e.Quaternion,I=e.Vector3.Zero(),O=M.getBaseMatrix();A&&o&&(O=o.getKeys()[P].value),O.decompose(I,R,C),"position"===_?C=S:"rotationQuaternion"===_?R=S:I=S,S=e.Matrix.Compose(I,R,C)}A?o&&(o.getKeys()[P].value=S):T.push({frame:p[P],value:S})}!A&&b&&(b.setKeys(T),g.animations.push(b)),o=b,i.scene.stopAnimation(g),i.scene.beginAnimation(g,0,p[p.length-1],!0,1)}else e.Tools.Warn("Creating animation named "+r+". But cannot find node named "+m+" to attach to")}}}},d=function(t){var i=null;if(t.translation||t.rotation||t.scale){var r=e.Vector3.FromArray(t.scale||[1,1,1]),n=e.Quaternion.FromArray(t.rotation||[0,0,0,1]),o=e.Vector3.FromArray(t.translation||[0,0,0]);i=e.Matrix.Compose(r,n,o)}else i=e.Matrix.FromArray(t.matrix);return i},m=function(t,i,r,n){for(h=0;h<n.bones.length;h++)if(n.bones[h].name===r)return n.bones[h];var o=t.nodes;for(var s in o){var a=o[s];if(a.jointName)for(var l=a.children,h=0;h<l.length;h++){var u=t.nodes[l[h]];if(u.jointName&&u.jointName===r){var c=d(a),f=new e.Bone(a.name||"",n,m(t,i,a.jointName,n),c);return f.id=s,f}}}return null},g=function(e,t){for(var i=0;i<e.length;i++)for(var r=e[i],n=0;n<r.node.children.length;n++)if(r.node.children[n]===t)return r.bone;return null},v=function(e,t){var i=e.nodes,r=i[t];if(r)return{node:r,id:t};for(var n in i)if((r=i[n]).jointName===t)return{node:r,id:n};return null},_=function(e,t){for(var i=0;i<e.jointNames.length;i++)if(e.jointNames[i]===t)return!0;return!1},y=function(t,i,r,n){for(var o in t.nodes){var s=t.nodes[o],a=o;if(s.jointName&&!_(r,s.jointName)){var l=d(s),h=new e.Bone(s.name||"",i,null,l);h.id=a,n.push({bone:h,node:s,id:a})}}for(var u=0;u<n.length;u++)for(var c=n[u],f=c.node.children,p=0;p<f.length;p++){for(var m=null,g=0;g<n.length;g++)if(n[g].id===f[p]){m=n[g];break}m&&(m.bone._parent=c.bone,c.bone.children.push(m.bone))}},x=function(t,i,r,n,o){if(n||(n=new e.Skeleton(i.name||"","",t.scene)),!i.babylonSkeleton)return n;var s=[],a=[];y(t,n,i,s),n.bones=[];for(P=0;P<i.jointNames.length;P++)if(A=v(t,i.jointNames[P])){var l=A.node;if(l){var o=A.id,h=t.scene.getBoneByID(o);if(h)n.bones.push(h);else{for(var u=!1,c=null,f=0;f<P;f++){var p=v(t,i.jointNames[f]);if(p){var _=p.node;if(_){var x=_.children;if(x){u=!1;for(var b=0;b<x.length;b++)if(x[b]===o){c=m(t,i,i.jointNames[f],n),u=!0;break}if(u)break}}else e.Tools.Warn("Joint named "+i.jointNames[f]+" does not exist when looking for parent")}}var T=d(l);!c&&s.length>0&&(c=g(s,o))&&-1===a.indexOf(c)&&a.push(c),new e.Bone(l.jointName||"",n,c,T).id=o}}else e.Tools.Warn("Joint named "+i.jointNames[P]+" does not exist")}var E=n.bones;n.bones=[];for(P=0;P<i.jointNames.length;P++){var A=v(t,i.jointNames[P]);if(A)for(f=0;f<E.length;f++)if(E[f].id===A.id){n.bones.push(E[f]);break}}n.prepare();for(var P=0;P<a.length;P++)n.bones.push(a[P]);return n},b=function(i,r,n,o,s){if(s||(s=new e.Mesh(r.name||"",i.scene),s.id=o),!r.babylonNode)return s;var a=new e.MultiMaterial("multimat"+o,i.scene);s.material||(s.material=a);for(var l=new e.VertexData,h=new e.Geometry(o,i.scene,l,!1,s),u=new Array,f=new Array,p=new Array,d=new Array,m=0;m<n.length;m++){R=n[m];if(I=i.meshes[R])for(O=0;O<I.primitives.length;O++){var g=new e.VertexData,v=I.primitives[O];v.mode;var _=v.attributes,y=null,x=null;for(var b in _)if(y=i.accessors[_[b]],x=t.GLTFUtils.GetBufferFromAccessor(i,y),"NORMAL"===b)g.normals=new Float32Array(x.length),g.normals.set(x);else if("POSITION"===b){if(e.GLTFFileLoader.HomogeneousCoordinates){g.positions=new Float32Array(x.length-x.length/4);for(S=0;S<x.length;S+=4)g.positions[S]=x[S],g.positions[S+1]=x[S+1],g.positions[S+2]=x[S+2]}else g.positions=new Float32Array(x.length),g.positions.set(x);f.push(g.positions.length)}else if(-1!==b.indexOf("TEXCOORD_")){var T=Number(b.split("_")[1]),E=e.VertexBuffer.UVKind+(0===T?"":T+1),A=new Float32Array(x.length);A.set(x),c(A),g.set(A,E)}else"JOINT"===b?(g.matricesIndices=new Float32Array(x.length),g.matricesIndices.set(x)):"WEIGHT"===b?(g.matricesWeights=new Float32Array(x.length),g.matricesWeights.set(x)):"COLOR"===b&&(g.colors=new Float32Array(x.length),g.colors.set(x));if(y=i.accessors[v.indices])x=t.GLTFUtils.GetBufferFromAccessor(i,y),g.indices=new Int32Array(x.length),g.indices.set(x),d.push(g.indices.length);else{for(var P=[],S=0;S<g.positions.length/3;S++)P.push(S);g.indices=new Int32Array(P),d.push(g.indices.length)}l.merge(g);var M=i.scene.getMaterialByID(v.material);a.subMaterials.push(null===M?t.GLTFUtils.GetDefaultMaterial(i.scene):M),u.push(0===u.length?0:u[u.length-1]+f[f.length-2]),p.push(0===p.length?0:p[p.length-1]+d[d.length-2])}}h.setAllVerticesData(l,!1),s.computeWorldMatrix(!0),s.subMeshes=[];for(var C=0,m=0;m<n.length;m++){var R=n[m],I=i.meshes[R];if(I)for(var O=0;O<I.primitives.length;O++)I.primitives[O].mode,e.SubMesh.AddToMesh(C,u[C],f[C],p[C],d[C],s,s,!0),C++}return s},T=function(e,t,i,r){e.position&&(e.position=t),(e.rotationQuaternion||e.rotation)&&(e.rotationQuaternion=i),e.scaling&&(e.scaling=r)},E=function(t,i,r){if(i.matrix){var n=new e.Vector3(0,0,0),o=new e.Quaternion,s=new e.Vector3(0,0,0);e.Matrix.FromArray(i.matrix).decompose(s,o,n),T(t,n,o,s)}else i.translation&&i.rotation&&i.scale&&T(t,e.Vector3.FromArray(i.translation),e.Quaternion.FromArray(i.rotation),e.Vector3.FromArray(i.scale));t.computeWorldMatrix(!0)},A=function(t,i,r,n){var o=null;if(t.importOnlyMeshes&&(i.skin||i.meshes)&&t.importMeshesNames&&t.importMeshesNames.length>0&&-1===t.importMeshesNames.indexOf(i.name||""))return null;if(i.skin){if(i.meshes){var s=t.skins[i.skin];(a=b(t,i,i.meshes,r,i.babylonNode)).skeleton=t.scene.getLastSkeletonByID(i.skin),null===a.skeleton&&s.babylonSkeleton&&(a.skeleton=x(t,s,0,s.babylonSkeleton,i.skin),s.babylonSkeleton||(s.babylonSkeleton=a.skeleton)),o=a}}else if(i.meshes){var a=b(t,i,i.mesh?[i.mesh]:i.meshes,r,i.babylonNode);o=a}else if(!i.light||i.babylonNode||t.importOnlyMeshes){if(i.camera&&!i.babylonNode&&!t.importOnlyMeshes){var l=t.cameras[i.camera];if(l)if("orthographic"===l.type){var h=new e.FreeCamera(i.camera,e.Vector3.Zero(),t.scene);h.name=i.name||"",h.mode=e.Camera.ORTHOGRAPHIC_CAMERA,h.attachControl(t.scene.getEngine().getRenderingCanvas()),o=h}else if("perspective"===l.type){var u=l[l.type],c=new e.FreeCamera(i.camera,e.Vector3.Zero(),t.scene);c.name=i.name||"",c.attachControl(t.scene.getEngine().getRenderingCanvas()),u.aspectRatio||(u.aspectRatio=t.scene.getEngine().getRenderWidth()/t.scene.getEngine().getRenderHeight()),u.znear&&u.zfar&&(c.maxZ=u.zfar,c.minZ=u.znear),o=c}}}else{var f=t.lights[i.light];if(f)if("ambient"===f.type){var p=f[f.type],d=new e.HemisphericLight(i.light,e.Vector3.Zero(),t.scene);d.name=i.name||"",p.color&&(d.diffuse=e.Color3.FromArray(p.color)),o=d}else if("directional"===f.type){var m=f[f.type],g=new e.DirectionalLight(i.light,e.Vector3.Zero(),t.scene);g.name=i.name||"",m.color&&(g.diffuse=e.Color3.FromArray(m.color)),o=g}else if("point"===f.type){var v=f[f.type],_=new e.PointLight(i.light,e.Vector3.Zero(),t.scene);_.name=i.name||"",v.color&&(_.diffuse=e.Color3.FromArray(v.color)),o=_}else if("spot"===f.type){var y=f[f.type],A=new e.SpotLight(i.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);A.name=i.name||"",y.color&&(A.diffuse=e.Color3.FromArray(y.color)),y.fallOfAngle&&(A.angle=y.fallOfAngle),y.fallOffExponent&&(A.exponent=y.fallOffExponent),o=A}}if(!i.jointName){if(i.babylonNode)return i.babylonNode;if(null===o){var P=new e.Mesh(i.name||"",t.scene);i.babylonNode=P,o=P}}if(null!==o){if(i.matrix&&o instanceof e.Mesh)E(o,i);else{var S=i.translation||[0,0,0],M=i.rotation||[0,0,0,1],C=i.scale||[1,1,1];T(o,e.Vector3.FromArray(S),e.Quaternion.FromArray(M),e.Vector3.FromArray(C))}o.updateCache(!0),i.babylonNode=o}return o},P=function(e,t,i,r){void 0===r&&(r=!1);var n=e.nodes[t],o=null;if(r=!(e.importOnlyMeshes&&!r&&e.importMeshesNames)||-1!==e.importMeshesNames.indexOf(n.name||"")||0===e.importMeshesNames.length,!n.jointName&&r&&null!==(o=A(e,n,t))&&(o.id=t,o.parent=i),n.children)for(var s=0;s<n.children.length;s++)P(e,n.children[s],o,r)},S=function(e){var t=e.currentScene;if(t)for(r=0;r<t.nodes.length;r++)P(e,t.nodes[r],null);else for(var i in e.scenes){t=e.scenes[i];for(r=0;r<t.nodes.length;r++)P(e,t.nodes[r],null)}p(e);for(var r=0;r<e.scene.skeletons.length;r++){var n=e.scene.skeletons[r];e.scene.beginAnimation(n,0,Number.MAX_VALUE,!0,1)}},M=function(e,i,r,n,o,s,a){var l=s.values||o.parameters;for(var h in r){var u=r[h],c=u.type;if(c===t.EParameterType.FLOAT_MAT2||c===t.EParameterType.FLOAT_MAT3||c===t.EParameterType.FLOAT_MAT4)if(!u.semantic||u.source||u.node){if(u.semantic&&(u.source||u.node)){var f=i.scene.getNodeByName(u.source||u.node||"");if(null===f&&(f=i.scene.getNodeByID(u.source||u.node||"")),null===f)continue;t.GLTFUtils.SetMatrix(i.scene,f,u,h,n.getEffect())}}else t.GLTFUtils.SetMatrix(i.scene,e,u,h,n.getEffect());else{var p=l[o.uniforms[h]];if(!p)continue;if(c===t.EParameterType.SAMPLER_2D){var d=i.textures[s.values?p:u.value].babylonTexture;if(null===d||void 0===d)continue;n.getEffect().setTexture(h,d)}else t.GLTFUtils.SetUniform(n.getEffect(),h,p,c)}}a(n)},C=function(e,i,r,n,o){var s=n.values||r.parameters,a=r.uniforms;for(var l in o){var h=o[l],u=h.type,c=s[a[l]];if(void 0===c&&(c=h.value),c){var f=function(e){return function(t){h.value&&e&&(i.setTexture(e,t),delete o[e])}};u===t.EParameterType.SAMPLER_2D?t.GLTFLoaderExtension.LoadTextureAsync(e,n.values?c:h.value,f(l),function(){return f(null)}):h.value&&t.GLTFUtils.SetUniform(i,l,n.values?c:h.value,u)&&delete o[l]}}},R=function(e,t,i){return function(r,n){t.dispose(!0),i("Cannot compile program named "+e.name+". Error: "+n+". Default material will be applied")}},I=function(e,t,i,r,n,o){return function(s){C(e,t,i,r,n),t.onBind=function(s){M(s,e,n,t,i,r,o)}}},O=function(e,t,i){for(var r in t.uniforms){var s=t.uniforms[r],a=t.parameters[s];if(e.currentIdentifier===r&&a.semantic&&!a.source&&!a.node){var l=n.indexOf(a.semantic);if(-1!==l)return delete i[r],o[l]}}return e.currentIdentifier},D=function(e){for(var i in e.materials)t.GLTFLoaderExtension.LoadMaterialAsync(e,i,function(e){},function(){})},w=function(){function s(){}return s.CreateRuntime=function(e,t,i){var r={extensions:{},accessors:{},buffers:{},bufferViews:{},meshes:{},lights:{},cameras:{},nodes:{},images:{},textures:{},shaders:{},programs:{},samplers:{},techniques:{},materials:{},animations:{},skins:{},extensionsUsed:[],scenes:{},buffersCount:0,shaderscount:0,scene:t,rootUrl:i,loadedBufferCount:0,loadedBufferViews:{},loadedShaderCount:0,importOnlyMeshes:!1,dummyNodes:[]};return e.extensions&&u(e.extensions,"extensions",r),e.extensionsUsed&&u(e.extensionsUsed,"extensionsUsed",r),e.buffers&&l(e.buffers,r),e.bufferViews&&u(e.bufferViews,"bufferViews",r),e.accessors&&u(e.accessors,"accessors",r),e.meshes&&u(e.meshes,"meshes",r),e.lights&&u(e.lights,"lights",r),e.cameras&&u(e.cameras,"cameras",r),e.nodes&&u(e.nodes,"nodes",r),e.images&&u(e.images,"images",r),e.textures&&u(e.textures,"textures",r),e.shaders&&h(e.shaders,r),e.programs&&u(e.programs,"programs",r),e.samplers&&u(e.samplers,"samplers",r),e.techniques&&u(e.techniques,"techniques",r),e.materials&&u(e.materials,"materials",r),e.animations&&u(e.animations,"animations",r),e.skins&&u(e.skins,"skins",r),e.scenes&&(r.scenes=e.scenes),e.scene&&e.scenes&&(r.currentScene=e.scenes[e.scene]),r},s.LoadBufferAsync=function(i,r,n,o,s){var a=i.buffers[r];t.GLTFUtils.IsBase64(a.uri)?setTimeout(function(){return n(new Uint8Array(t.GLTFUtils.DecodeBase64(a.uri)))}):e.Tools.LoadFile(i.rootUrl+a.uri,function(e){return n(new Uint8Array(e))},s,void 0,!0,function(e){e&&o(e.status+" "+e.statusText)})},s.LoadTextureBufferAsync=function(i,r,n,o){var s=i.textures[r];if(s&&s.source)if(s.babylonTexture)n(null);else{var a=i.images[s.source];t.GLTFUtils.IsBase64(a.uri)?setTimeout(function(){return n(new Uint8Array(t.GLTFUtils.DecodeBase64(a.uri)))}):e.Tools.LoadFile(i.rootUrl+a.uri,function(e){return n(new Uint8Array(e))},void 0,void 0,!0,function(e){e&&o(e.status+" "+e.statusText)})}else o("")},s.CreateTextureAsync=function(i,r,n,o,s){var a=i.textures[r];if(a.babylonTexture)o(a.babylonTexture);else{var l=i.samplers[a.sampler],h=l.minFilter===t.ETextureFilterType.NEAREST_MIPMAP_NEAREST||l.minFilter===t.ETextureFilterType.NEAREST_MIPMAP_LINEAR||l.minFilter===t.ETextureFilterType.LINEAR_MIPMAP_NEAREST||l.minFilter===t.ETextureFilterType.LINEAR_MIPMAP_LINEAR,u=e.Texture.BILINEAR_SAMPLINGMODE,c=new Blob([n]),f=URL.createObjectURL(c),p=function(){return URL.revokeObjectURL(f)},d=new e.Texture(f,i.scene,!h,!0,u,p,p);void 0!==l.wrapS&&(d.wrapU=t.GLTFUtils.GetWrapMode(l.wrapS)),void 0!==l.wrapT&&(d.wrapV=t.GLTFUtils.GetWrapMode(l.wrapT)),d.name=r,a.babylonTexture=d,o(d)}},s.LoadShaderStringAsync=function(i,r,n,o){var s=i.shaders[r];t.GLTFUtils.IsBase64(s.uri)?n(atob(s.uri.split(",")[1])):e.Tools.LoadFile(i.rootUrl+s.uri,n,void 0,void 0,!1,function(e){e&&o(e.status+" "+e.statusText)})},s.LoadMaterialAsync=function(s,a,l,h){var u=s.materials[a];if(u.technique){var c=s.techniques[u.technique];if(!c){var p=new e.StandardMaterial(a,s.scene);return p.diffuseColor=new e.Color3(.5,.5,.5),p.sideOrientation=e.Material.CounterClockWiseSideOrientation,void l(p)}var d=s.programs[c.program],m=c.states,g=e.Effect.ShadersStore[d.vertexShader+"VertexShader"],v=e.Effect.ShadersStore[d.fragmentShader+"PixelShader"],_="",y="",x=new r(g),b=new r(v),T={},E=[],A=[],P=[];for(var S in c.uniforms){var M=c.uniforms[S],C=c.parameters[M];if(T[S]=C,!C.semantic||C.node||C.source)C.type===t.EParameterType.SAMPLER_2D?P.push(S):E.push(S);else{var D=n.indexOf(C.semantic);-1!==D?(E.push(o[D]),delete T[S]):E.push(S)}}for(var w in c.attributes){F=c.attributes[w];(N=c.parameters[F]).semantic&&A.push(f(N))}for(;!x.isEnd()&&x.getNextToken();)if((B=x.currentToken)===i.IDENTIFIER){var L=!1;for(var w in c.attributes){var F=c.attributes[w],N=c.parameters[F];if(x.currentIdentifier===w&&N.semantic){_+=f(N),L=!0;break}}L||(_+=O(x,c,T))}else _+=x.currentString;for(;!b.isEnd()&&b.getNextToken();){var B=b.currentToken;B===i.IDENTIFIER?y+=O(b,c,T):y+=b.currentString}var V={vertex:d.vertexShader+a,fragment:d.fragmentShader+a},U={attributes:A,uniforms:E,samplers:P,needAlphaBlending:m&&m.enable&&-1!==m.enable.indexOf(3042)};e.Effect.ShadersStore[d.vertexShader+a+"VertexShader"]=_,e.Effect.ShadersStore[d.fragmentShader+a+"PixelShader"]=y;var z=new e.ShaderMaterial(a,s.scene,V,U);if(z.onError=R(d,z,h),z.onCompiled=I(s,z,c,u,T,l),z.sideOrientation=e.Material.CounterClockWiseSideOrientation,m&&m.functions){var k=m.functions;k.cullFace&&k.cullFace[0]!==t.ECullingType.BACK&&(z.backFaceCulling=!1);var G=k.blendFuncSeparate;G&&(G[0]===t.EBlendingFunction.SRC_ALPHA&&G[1]===t.EBlendingFunction.ONE_MINUS_SRC_ALPHA&&G[2]===t.EBlendingFunction.ONE&&G[3]===t.EBlendingFunction.ONE?z.alphaMode=e.Engine.ALPHA_COMBINE:G[0]===t.EBlendingFunction.ONE&&G[1]===t.EBlendingFunction.ONE&&G[2]===t.EBlendingFunction.ZERO&&G[3]===t.EBlendingFunction.ONE?z.alphaMode=e.Engine.ALPHA_ONEONE:G[0]===t.EBlendingFunction.SRC_ALPHA&&G[1]===t.EBlendingFunction.ONE&&G[2]===t.EBlendingFunction.ZERO&&G[3]===t.EBlendingFunction.ONE?z.alphaMode=e.Engine.ALPHA_ADD:G[0]===t.EBlendingFunction.ZERO&&G[1]===t.EBlendingFunction.ONE_MINUS_SRC_COLOR&&G[2]===t.EBlendingFunction.ONE&&G[3]===t.EBlendingFunction.ONE?z.alphaMode=e.Engine.ALPHA_SUBTRACT:G[0]===t.EBlendingFunction.DST_COLOR&&G[1]===t.EBlendingFunction.ZERO&&G[2]===t.EBlendingFunction.ONE&&G[3]===t.EBlendingFunction.ONE?z.alphaMode=e.Engine.ALPHA_MULTIPLY:G[0]===t.EBlendingFunction.SRC_ALPHA&&G[1]===t.EBlendingFunction.ONE_MINUS_SRC_COLOR&&G[2]===t.EBlendingFunction.ONE&&G[3]===t.EBlendingFunction.ONE&&(z.alphaMode=e.Engine.ALPHA_MAXIMIZED))}}else h&&h("No technique found.")},s}();t.GLTFLoaderBase=w;var L=function(){function i(){}return i.RegisterExtension=function(t){i.Extensions[t.name]?e.Tools.Error('Tool with the same name "'+t.name+'" already exists'):i.Extensions[t.name]=t},i.prototype.dispose=function(){},i.prototype.importMeshAsync=function(i,r,n,o,s,a,l){var h=this;return r.useRightHandedSystem=!0,t.GLTFLoaderExtension.LoadRuntimeAsync(r,n,o,function(t){t.importOnlyMeshes=!0,""===i?t.importMeshesNames=[]:"string"==typeof i?t.importMeshesNames=[i]:!i||i instanceof Array?(t.importMeshesNames=[],e.Tools.Warn("Argument meshesNames must be of type string or string[]")):t.importMeshesNames=[i],h._createNodes(t);var r=new Array,n=new Array;for(var o in t.nodes){var l=t.nodes[o];l.babylonNode instanceof e.AbstractMesh&&r.push(l.babylonNode)}for(var u in t.skins){var c=t.skins[u];c.babylonSkeleton instanceof e.Skeleton&&n.push(c.babylonSkeleton)}h._loadBuffersAsync(t,function(){h._loadShadersAsync(t,function(){D(t),S(t),!e.GLTFFileLoader.IncrementalLoading&&s&&s(r,[],n)})},a),e.GLTFFileLoader.IncrementalLoading&&s&&s(r,[],n)},l),!0},i.prototype.loadAsync=function(i,r,n,o,s,a){var l=this;i.useRightHandedSystem=!0,t.GLTFLoaderExtension.LoadRuntimeAsync(i,r,n,function(i){t.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(i,function(){l._createNodes(i),l._loadBuffersAsync(i,function(){l._loadShadersAsync(i,function(){D(i),S(i),e.GLTFFileLoader.IncrementalLoading||o()})}),e.GLTFFileLoader.IncrementalLoading&&o()},a)},a)},i.prototype._loadShadersAsync=function(i,r){var n=!1;for(var o in i.shaders){n=!0;var s=i.shaders[o];s?function(n,o){t.GLTFLoaderExtension.LoadShaderStringAsync(i,n,function(s){i.loadedShaderCount++,s&&(e.Effect.ShadersStore[n+(o.type===t.EShaderType.VERTEX?"VertexShader":"PixelShader")]=s),i.loadedShaderCount===i.shaderscount&&r()},function(){e.Tools.Error("Error when loading shader program named "+n+" located at "+o.uri)})}.bind(this,o,s)():e.Tools.Error("No shader named: "+o)}n||r()},i.prototype._loadBuffersAsync=function(i,r,n){var o=!1;for(var s in i.buffers){o=!0;var a=i.buffers[s];a?function(n,o){t.GLTFLoaderExtension.LoadBufferAsync(i,n,function(t){i.loadedBufferCount++,t&&(t.byteLength!=i.buffers[n].byteLength&&e.Tools.Error("Buffer named "+n+" is length "+t.byteLength+". Expected: "+o.byteLength),i.loadedBufferViews[n]=t),i.loadedBufferCount===i.buffersCount&&r()},function(){e.Tools.Error("Error when loading buffer named "+n+" located at "+o.uri)})}.bind(this,s,a)():e.Tools.Error("No buffer named: "+s)}o||r()},i.prototype._createNodes=function(e){var t=e.currentScene;if(t)for(r=0;r<t.nodes.length;r++)P(e,t.nodes[r],null);else for(var i in e.scenes){t=e.scenes[i];for(var r=0;r<t.nodes.length;r++)P(e,t.nodes[r],null)}},i.Extensions={},i}();t.GLTFLoader=L,e.GLTFFileLoader.CreateGLTFLoaderV1=function(){return new L}}(e.GLTF1||(e.GLTF1={}))}(n||(n={}));!function(e){!function(t){var i=function(){function i(){}return i.SetMatrix=function(i,r,n,o,s){var a=null;if("MODEL"===n.semantic?a=r.getWorldMatrix():"PROJECTION"===n.semantic?a=i.getProjectionMatrix():"VIEW"===n.semantic?a=i.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===n.semantic?a=e.Matrix.Transpose(r.getWorldMatrix().multiply(i.getViewMatrix()).invert()):"MODELVIEW"===n.semantic?a=r.getWorldMatrix().multiply(i.getViewMatrix()):"MODELVIEWPROJECTION"===n.semantic?a=r.getWorldMatrix().multiply(i.getTransformMatrix()):"MODELINVERSE"===n.semantic?a=r.getWorldMatrix().invert():"VIEWINVERSE"===n.semantic?a=i.getViewMatrix().invert():"PROJECTIONINVERSE"===n.semantic?a=i.getProjectionMatrix().invert():"MODELVIEWINVERSE"===n.semantic?a=r.getWorldMatrix().multiply(i.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===n.semantic?a=r.getWorldMatrix().multiply(i.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===n.semantic&&(a=e.Matrix.Transpose(r.getWorldMatrix().invert())),a)switch(n.type){case t.EParameterType.FLOAT_MAT2:s.setMatrix2x2(o,e.Matrix.GetAsMatrix2x2(a));break;case t.EParameterType.FLOAT_MAT3:s.setMatrix3x3(o,e.Matrix.GetAsMatrix3x3(a));break;case t.EParameterType.FLOAT_MAT4:s.setMatrix(o,a)}},i.SetUniform=function(i,r,n,o){switch(o){case t.EParameterType.FLOAT:return i.setFloat(r,n),!0;case t.EParameterType.FLOAT_VEC2:return i.setVector2(r,e.Vector2.FromArray(n)),!0;case t.EParameterType.FLOAT_VEC3:return i.setVector3(r,e.Vector3.FromArray(n)),!0;case t.EParameterType.FLOAT_VEC4:return i.setVector4(r,e.Vector4.FromArray(n)),!0;default:return!1}},i.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},i.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),i=t.length,r=new Uint8Array(new ArrayBuffer(i)),n=0;n<i;n++)r[n]=t.charCodeAt(n);return r.buffer},i.GetWrapMode=function(i){switch(i){case t.ETextureWrapMode.CLAMP_TO_EDGE:return e.Texture.CLAMP_ADDRESSMODE;case t.ETextureWrapMode.MIRRORED_REPEAT:return e.Texture.MIRROR_ADDRESSMODE;case t.ETextureWrapMode.REPEAT:default:return e.Texture.WRAP_ADDRESSMODE}},i.GetByteStrideFromType=function(e){switch(e.type){case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return 1}},i.GetTextureFilterMode=function(i){switch(i){case t.ETextureFilterType.LINEAR:case t.ETextureFilterType.LINEAR_MIPMAP_NEAREST:case t.ETextureFilterType.LINEAR_MIPMAP_LINEAR:return e.Texture.TRILINEAR_SAMPLINGMODE;case t.ETextureFilterType.NEAREST:case t.ETextureFilterType.NEAREST_MIPMAP_NEAREST:return e.Texture.NEAREST_SAMPLINGMODE;default:return e.Texture.BILINEAR_SAMPLINGMODE}},i.GetBufferFromBufferView=function(e,i,r,n,o){var r=i.byteOffset+r,s=e.loadedBufferViews[i.buffer];if(r+n>s.byteLength)throw new Error("Buffer access is out of range");var a=s.buffer;switch(r+=s.byteOffset,o){case t.EComponentType.BYTE:return new Int8Array(a,r,n);case t.EComponentType.UNSIGNED_BYTE:return new Uint8Array(a,r,n);case t.EComponentType.SHORT:return new Int16Array(a,r,n);case t.EComponentType.UNSIGNED_SHORT:return new Uint16Array(a,r,n);default:return new Float32Array(a,r,n)}},i.GetBufferFromAccessor=function(e,t){var r=e.bufferViews[t.bufferView],n=t.count*i.GetByteStrideFromType(t);return i.GetBufferFromBufferView(e,r,t.byteOffset,n,t.componentType)},i.DecodeBufferToText=function(e){for(var t="",i=e.byteLength,r=0;r<i;++r)t+=String.fromCharCode(e[r]);return t},i.GetDefaultMaterial=function(t){if(!i._DefaultMaterial){e.Effect.ShadersStore.GLTFDefaultMaterialVertexShader=["precision highp float;","","uniform mat4 worldView;","uniform mat4 projection;","","attribute vec3 position;","","void main(void)","{"," gl_Position = projection * worldView * vec4(position, 1.0);","}"].join("\n"),e.Effect.ShadersStore.GLTFDefaultMaterialPixelShader=["precision highp float;","","uniform vec4 u_emission;","","void main(void)","{"," gl_FragColor = u_emission;","}"].join("\n");var r={vertex:"GLTFDefaultMaterial",fragment:"GLTFDefaultMaterial"},n={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:new Array,needAlphaBlending:!1};(i._DefaultMaterial=new e.ShaderMaterial("GLTFDefaultMaterial",t,r,n)).setColor4("u_emission",new e.Color4(.5,.5,.5,1))}return i._DefaultMaterial},i._DefaultMaterial=null,i}();t.GLTFUtils=i}(e.GLTF1||(e.GLTF1={}))}(n||(n={}));!function(e){!function(e){var t=function(){function t(e){this._name=e}return Object.defineProperty(t.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),t.prototype.loadRuntimeAsync=function(e,t,i,r,n){return!1},t.prototype.loadRuntimeExtensionsAsync=function(e,t,i){return!1},t.prototype.loadBufferAsync=function(e,t,i,r,n){return!1},t.prototype.loadTextureBufferAsync=function(e,t,i,r){return!1},t.prototype.createTextureAsync=function(e,t,i,r,n){return!1},t.prototype.loadShaderStringAsync=function(e,t,i,r){return!1},t.prototype.loadMaterialAsync=function(e,t,i,r){return!1},t.LoadRuntimeAsync=function(i,r,n,o,s){t.ApplyExtensions(function(e){return e.loadRuntimeAsync(i,r,n,o,s)},function(){setTimeout(function(){o(e.GLTFLoaderBase.CreateRuntime(r.json,i,n))})})},t.LoadRuntimeExtensionsAsync=function(e,i,r){t.ApplyExtensions(function(t){return t.loadRuntimeExtensionsAsync(e,i,r)},function(){setTimeout(function(){i()})})},t.LoadBufferAsync=function(i,r,n,o,s){t.ApplyExtensions(function(e){return e.loadBufferAsync(i,r,n,o,s)},function(){e.GLTFLoaderBase.LoadBufferAsync(i,r,n,o,s)})},t.LoadTextureAsync=function(e,i,r,n){t.LoadTextureBufferAsync(e,i,function(o){return t.CreateTextureAsync(e,i,o,r,n)},n)},t.LoadShaderStringAsync=function(i,r,n,o){t.ApplyExtensions(function(e){return e.loadShaderStringAsync(i,r,n,o)},function(){e.GLTFLoaderBase.LoadShaderStringAsync(i,r,n,o)})},t.LoadMaterialAsync=function(i,r,n,o){t.ApplyExtensions(function(e){return e.loadMaterialAsync(i,r,n,o)},function(){e.GLTFLoaderBase.LoadMaterialAsync(i,r,n,o)})},t.LoadTextureBufferAsync=function(i,r,n,o){t.ApplyExtensions(function(e){return e.loadTextureBufferAsync(i,r,n,o)},function(){e.GLTFLoaderBase.LoadTextureBufferAsync(i,r,n,o)})},t.CreateTextureAsync=function(i,r,n,o,s){t.ApplyExtensions(function(e){return e.createTextureAsync(i,r,n,o,s)},function(){e.GLTFLoaderBase.CreateTextureAsync(i,r,n,o,s)})},t.ApplyExtensions=function(t,i){for(var r in e.GLTFLoader.Extensions)if(t(e.GLTFLoader.Extensions[r]))return;i()},t}();e.GLTFLoaderExtension=t}(e.GLTF1||(e.GLTF1={}))}(n||(n={}));!function(e){!function(e){var t=function(t){function i(){return t.call(this,"KHR_binary_glTF")||this}return o(i,t),i.prototype.loadRuntimeAsync=function(t,i,r,n,o){var s=i.json.extensionsUsed;return!(!s||-1===s.indexOf(this.name)||!i.bin||(this._bin=i.bin,n(e.GLTFLoaderBase.CreateRuntime(i.json,t,r)),0))},i.prototype.loadBufferAsync=function(e,t,i,r){return-1!==e.extensionsUsed.indexOf(this.name)&&"binary_glTF"===t&&(i(this._bin),!0)},i.prototype.loadTextureBufferAsync=function(t,i,r,n){var o=t.textures[i],s=t.images[o.source];if(!(s.extensions&&this.name in s.extensions))return!1;var a=s.extensions[this.name],l=t.bufferViews[a.bufferView];return r(e.GLTFUtils.GetBufferFromBufferView(t,l,0,l.byteLength,e.EComponentType.UNSIGNED_BYTE)),!0},i.prototype.loadShaderStringAsync=function(t,i,r,n){var o=t.shaders[i];if(!(o.extensions&&this.name in o.extensions))return!1;var s=o.extensions[this.name],a=t.bufferViews[s.bufferView],l=e.GLTFUtils.GetBufferFromBufferView(t,a,0,a.byteLength,e.EComponentType.UNSIGNED_BYTE);return setTimeout(function(){var t=e.GLTFUtils.DecodeBufferToText(l);r(t)}),!0},i}(e.GLTFLoaderExtension);e.GLTFBinaryExtension=t,e.GLTFLoader.RegisterExtension(new t)}(e.GLTF1||(e.GLTF1={}))}(n||(n={}));!function(e){!function(t){var i=function(i){function r(){return i.call(this,"KHR_materials_common")||this}return o(r,i),r.prototype.loadRuntimeExtensionsAsync=function(t,i,r){if(!t.extensions)return!1;var n=t.extensions[this.name];if(!n)return!1;var o=n.lights;if(o)for(var s in o){var a=o[s];switch(a.type){case"ambient":var l=new e.HemisphericLight(a.name,new e.Vector3(0,1,0),t.scene),h=a.ambient;h&&(l.diffuse=e.Color3.FromArray(h.color||[1,1,1]));break;case"point":var u=new e.PointLight(a.name,new e.Vector3(10,10,10),t.scene),c=a.point;c&&(u.diffuse=e.Color3.FromArray(c.color||[1,1,1]));break;case"directional":var f=new e.DirectionalLight(a.name,new e.Vector3(0,-1,0),t.scene),p=a.directional;p&&(f.diffuse=e.Color3.FromArray(p.color||[1,1,1]));break;case"spot":var d=a.spot;d&&(new e.SpotLight(a.name,new e.Vector3(0,10,0),new e.Vector3(0,-1,0),d.fallOffAngle||Math.PI,d.fallOffExponent||0,t.scene).diffuse=e.Color3.FromArray(d.color||[1,1,1]));break;default:e.Tools.Warn('GLTF Material Common extension: light type "'+a.type+"” not supported")}}return!1},r.prototype.loadMaterialAsync=function(t,i,r,n){var o=t.materials[i];if(!o||!o.extensions)return!1;var s=o.extensions[this.name];if(!s)return!1;var a=new e.StandardMaterial(i,t.scene);return a.sideOrientation=e.Material.CounterClockWiseSideOrientation,"CONSTANT"===s.technique&&(a.disableLighting=!0),a.backFaceCulling=void 0!==s.doubleSided&&!s.doubleSided,a.alpha=void 0===s.values.transparency?1:s.values.transparency,a.specularPower=void 0===s.values.shininess?0:s.values.shininess,"string"==typeof s.values.ambient?this._loadTexture(t,s.values.ambient,a,"ambientTexture",n):a.ambientColor=e.Color3.FromArray(s.values.ambient||[0,0,0]),"string"==typeof s.values.diffuse?this._loadTexture(t,s.values.diffuse,a,"diffuseTexture",n):a.diffuseColor=e.Color3.FromArray(s.values.diffuse||[0,0,0]),"string"==typeof s.values.emission?this._loadTexture(t,s.values.emission,a,"emissiveTexture",n):a.emissiveColor=e.Color3.FromArray(s.values.emission||[0,0,0]),"string"==typeof s.values.specular?this._loadTexture(t,s.values.specular,a,"specularTexture",n):a.specularColor=e.Color3.FromArray(s.values.specular||[0,0,0]),!0},r.prototype._loadTexture=function(e,i,r,n,o){t.GLTFLoaderBase.LoadTextureBufferAsync(e,i,function(s){t.GLTFLoaderBase.CreateTextureAsync(e,i,s,function(e){return r[n]=e},o)},o)},r}(t.GLTFLoaderExtension);t.GLTFMaterialsCommonExtension=i,t.GLTFLoader.RegisterExtension(new i)}(e.GLTF1||(e.GLTF1={}))}(n||(n={}));!function(e){!function(e){!function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.FLOAT=5126]="FLOAT"}(e.EComponentType||(e.EComponentType={})),function(e){e[e.POINTS=0]="POINTS",e[e.LINES=1]="LINES",e[e.LINE_LOOP=2]="LINE_LOOP",e[e.LINE_STRIP=3]="LINE_STRIP",e[e.TRIANGLES=4]="TRIANGLES",e[e.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",e[e.TRIANGLE_FAN=6]="TRIANGLE_FAN"}(e.EMeshPrimitiveMode||(e.EMeshPrimitiveMode={})),function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9729]="LINEAR"}(e.ETextureMagFilter||(e.ETextureMagFilter={})),function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9729]="LINEAR",e[e.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",e[e.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR"}(e.ETextureMinFilter||(e.ETextureMinFilter={})),function(e){e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.REPEAT=10497]="REPEAT"}(e.ETextureWrapMode||(e.ETextureWrapMode={}))}(e.GLTF2||(e.GLTF2={}))}(n||(n={}));!function(e){!function(t){var i=function(){function e(e){this._pendingCount=0,this._callback=e}return e.prototype._addPendingData=function(e){this._pendingCount++},e.prototype._removePendingData=function(e){0==--this._pendingCount&&this._callback()},e}(),r=function(){function r(t){this._disposed=!1,this._renderReady=!1,this._requests=new Array,this._renderReadyObservable=new e.Observable,this._renderPendingCount=0,this._loaderPendingCount=0,this._loaderTrackers=new Array,this._parent=t}return r.RegisterExtension=function(i){r.Extensions[i.name]?e.Tools.Error("Extension with the same name '"+i.name+"' already exists"):(r.Extensions[i.name]=i,t.GLTFLoaderExtension._Extensions.push(i))},r.prototype.dispose=function(){if(!this._disposed){this._disposed=!0;for(var e=0,t=this._requests;e<t.length;e++){var i=t[e];i.readyState!==(XMLHttpRequest.DONE||4)&&i.abort()}if(this._gltf.textures)for(var r=0,n=this._gltf.textures;r<n.length;r++){var o=n[r];o.url&&URL.revokeObjectURL(o.url)}}},r.prototype.importMeshAsync=function(e,t,i,r,n,o,s){var a=this;this._loadAsync(e,t,i,r,function(){n(a._getMeshes(),[],a._getSkeletons())},o,s)},r.prototype.loadAsync=function(e,t,i,r,n,o){this._loadAsync(null,e,t,i,r,n,o)},r.prototype._loadAsync=function(e,t,i,r,n,o,s){var a=this;this._tryCatchOnError(function(){a._loadData(i),a._babylonScene=t,a._rootUrl=r,a._successCallback=n,a._progressCallback=o,a._errorCallback=s,a._addPendingData(a),a._loadDefaultScene(e),a._loadAnimations(),a._removePendingData(a)})},r.prototype._onProgress=function(e){this._progressCallback&&this._progressCallback(e)},r.prototype._executeWhenRenderReady=function(e){this._renderReady?e():this._renderReadyObservable.add(e)},r.prototype._onRenderReady=function(){this._rootNode.babylonMesh.setEnabled(!0),this._startAnimations(),this._successCallback(),this._renderReadyObservable.notifyObservers(this)},r.prototype._onComplete=function(){this._parent.onComplete&&this._parent.onComplete(),this.dispose()},r.prototype._loadData=function(t){if(this._gltf=t.json,r._AssignIndices(this._gltf.accessors),r._AssignIndices(this._gltf.animations),r._AssignIndices(this._gltf.buffers),r._AssignIndices(this._gltf.bufferViews),r._AssignIndices(this._gltf.images),r._AssignIndices(this._gltf.materials),r._AssignIndices(this._gltf.meshes),r._AssignIndices(this._gltf.nodes),r._AssignIndices(this._gltf.scenes),r._AssignIndices(this._gltf.skins),r._AssignIndices(this._gltf.textures),t.bin){var i=this._gltf.buffers;if(i&&i[0]&&!i[0].uri){var n=i[0];n.byteLength!=t.bin.byteLength&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),n.loadedData=t.bin}else e.Tools.Warn("Unexpected BIN chunk")}},r.prototype._getMeshes=function(){var e=new Array;e.push(this._rootNode.babylonMesh);var t=this._gltf.nodes;if(t)for(var i=0,r=t;i<r.length;i++){var n=r[i];n.babylonMesh&&e.push(n.babylonMesh)}return e},r.prototype._getSkeletons=function(){var e=new Array,t=this._gltf.skins;if(t)for(var i=0,r=t;i<r.length;i++){var n=r[i];n.babylonSkeleton&&e.push(n.babylonSkeleton)}return e},r.prototype._getAnimationTargets=function(){var e=new Array,t=this._gltf.animations;if(t)for(var i=0,r=t;i<r.length;i++){var n=r[i];e.push.apply(e,n.targets)}return e},r.prototype._startAnimations=function(){for(var e=0,t=this._getAnimationTargets();e<t.length;e++){var i=t[e];this._babylonScene.beginAnimation(i,0,Number.MAX_VALUE,!0)}},r.prototype._loadDefaultScene=function(e){var t=r._GetProperty(this._gltf.scenes,this._gltf.scene||0);if(!t)throw new Error("Failed to find scene "+(this._gltf.scene||0));this._loadScene("#/scenes/"+t.index,t,e)},r.prototype._loadScene=function(t,i,n){switch(this._rootNode={babylonMesh:new e.Mesh("__root__",this._babylonScene)},this._parent.coordinateSystemMode){case e.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||(this._rootNode.babylonMesh.rotation=new e.Vector3(0,Math.PI,0),this._rootNode.babylonMesh.scaling=new e.Vector3(1,1,-1));break;case e.GLTFLoaderCoordinateSystemMode.PASS_THROUGH:break;case e.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:return void e.Tools.Error("Invalid coordinate system mode "+this._parent.coordinateSystemMode)}var o=i.nodes;if(this._traverseNodes(t,o,function(e,t){return e.parent=t,!0},this._rootNode),n){n instanceof Array||(n=[n]);var s=new Array;this._traverseNodes(t,o,function(e){return-1===n.indexOf(e.name)||(s.push(e.index),!1)},this._rootNode),o=s}for(var a=0,l=o;a<l.length;a++){var h=l[a],u=r._GetProperty(this._gltf.nodes,h);if(!u)throw new Error(t+": Failed to find node "+h);this._loadNode("#/nodes/"+h,u)}this._rootNode.babylonMesh.setEnabled(!1)},r.prototype._loadNode=function(i,n){if(!t.GLTFLoaderExtension.LoadNode(this,i,n)){if(n.babylonMesh=new e.Mesh(n.name||"mesh"+n.index,this._babylonScene),n.babylonMesh.hasVertexAlpha=!0,this._loadTransform(n),null!=n.mesh){var o=r._GetProperty(this._gltf.meshes,n.mesh);if(!o)throw new Error(i+": Failed to find mesh "+n.mesh);this._loadMesh("#/meshes/"+n.mesh,n,o)}if(n.babylonMesh.parent=n.parent?n.parent.babylonMesh:null,n.babylonAnimationTargets=n.babylonAnimationTargets||[],n.babylonAnimationTargets.push(n.babylonMesh),null!=n.skin){var s=r._GetProperty(this._gltf.skins,n.skin);if(!s)throw new Error(i+": Failed to find skin "+n.skin);n.babylonMesh.skeleton=this._loadSkin("#/skins/"+n.skin,s)}if(n.camera,n.children)for(var a=0,l=n.children;a<l.length;a++){var h=l[a],u=r._GetProperty(this._gltf.nodes,h);if(!u)throw new Error(i+": Failed to find child node "+h);this._loadNode("#/nodes/"+h,u)}}},r.prototype._loadMesh=function(t,i,n){var o=this,s=n.primitives;if(!s||0===s.length)throw new Error(t+": Primitives are missing");this._createMorphTargets(t,i,n),this._loadAllVertexDataAsync(t,n,function(){o._loadMorphTargets(t,i,n);for(var r=new e.VertexData,a=0,l=s;a<l.length;a++){var h=l[a];r.merge(h.vertexData)}new e.Geometry(i.babylonMesh.name,o._babylonScene,r,!1,i.babylonMesh),i.babylonMesh.subMeshes=[];for(var u=0,c=0,f=0;f<s.length;f++){var p=s[f].vertexData,d=p.positions.length,m=p.indices.length;e.SubMesh.AddToMesh(f,u,d,c,m,i.babylonMesh),u+=d,c+=m}});var a=new e.MultiMaterial(i.babylonMesh.name,this._babylonScene);i.babylonMesh.material=a;for(var l=a.subMaterials,h=this,u=0;u<s.length;u++)!function(e){var n=s[e];if(null==n.material)l[e]=h._getDefaultMaterial();else{var a=r._GetProperty(h._gltf.materials,n.material);if(!a)throw new Error(t+": Failed to find material "+n.material);h._loadMaterial("#/materials/"+a.index,a,function(t,r){r&&o._parent.onMaterialLoaded&&o._parent.onMaterialLoaded(t),o._parent.onBeforeMaterialReadyAsync?(o._addLoaderPendingData(a),o._parent.onBeforeMaterialReadyAsync(t,i.babylonMesh,null!=l[e],function(){o._tryCatchOnError(function(){l[e]=t,o._removeLoaderPendingData(a)})})):l[e]=t})}}(u)},r.prototype._loadAllVertexDataAsync=function(e,t,i){for(var r=t.primitives,n=r.length,o=this,s=0;s<r.length;s++)!function(s){var a=r[s];o._loadVertexDataAsync(e+"/primitive/"+s,t,a,function(e){a.vertexData=e,0==--n&&i()})}(s)},r.prototype._convertToFloat4TextureCoordArray=function(e,i,r){if(r.componentType==t.EComponentType.FLOAT)return i;var n=i,o=1;switch(r.componentType){case t.EComponentType.UNSIGNED_BYTE:o=1/255;break;case t.EComponentType.UNSIGNED_SHORT:o=1/65535;break;default:throw new Error(e+": Invalid component type ("+r.componentType+")")}for(var s=new Float32Array(2*r.count),a=0;a<s.length;++a)s[a]=n[a]*o;return s},r.prototype._convertToFloat4ColorArray=function(e,i,n){var o=r._GetNumComponents(n.type);if(4===o&&n.componentType===t.EComponentType.FLOAT)return i;var s=i,a=1;switch(n.componentType){case t.EComponentType.FLOAT:a=1;break;case t.EComponentType.UNSIGNED_BYTE:a=1/255;break;case t.EComponentType.UNSIGNED_SHORT:a=1/65535;break;default:throw new Error(e+": Invalid component type ("+n.componentType+")")}var l=new Float32Array(4*n.count);if(4===o)for(u=0;u<l.length;++u)l[u]=s[u]*a;else for(var h=0,u=0;u<l.length;++u)l[u]=(u+1)%4==0?1:s[h++]*a;return l},r.prototype._loadVertexDataAsync=function(i,n,o,s){var a=this,l=o.attributes;if(!l)throw new Error(i+": Attributes are missing");if(o.mode&&o.mode!==t.EMeshPrimitiveMode.TRIANGLES)throw new Error(i+": Mode "+o.mode+" is not currently supported");var h=new e.VertexData,u=Object.keys(l).length,c=this;for(var f in l)!function(t){var n=r._GetProperty(c._gltf.accessors,l[t]);if(!n)throw new Error(i+": Failed to find attribute '"+t+"' accessor "+l[t]);c._loadAccessorAsync("#/accessors/"+n.index,n,function(l){switch(t){case"POSITION":h.positions=l;break;case"NORMAL":h.normals=l;break;case"TANGENT":h.tangents=l;break;case"TEXCOORD_0":h.uvs=a._convertToFloat4TextureCoordArray(i,l,n);break;case"TEXCOORD_1":h.uvs2=a._convertToFloat4TextureCoordArray(i,l,n);break;case"JOINTS_0":h.matricesIndices=new Float32Array(Array.prototype.slice.apply(l));break;case"WEIGHTS_0":h.matricesWeights=l;break;case"COLOR_0":h.colors=a._convertToFloat4ColorArray(i,l,n);break;default:e.Tools.Warn("Ignoring unrecognized attribute '"+t+"'")}if(0==--u)if(null==o.indices){h.indices=new Uint32Array(h.positions.length/3);for(var c=0;c<h.indices.length;c++)h.indices[c]=c;s(h)}else{var f=r._GetProperty(a._gltf.accessors,o.indices);if(!f)throw new Error(i+": Failed to find indices accessor "+o.indices);a._loadAccessorAsync("#/accessors/"+f.index,f,function(e){h.indices=e,s(h)})}})}(f)},r.prototype._createMorphTargets=function(t,i,r){var n=r.primitives,o=n[0].targets;if(o){for(var s=0,a=n;s<a.length;s++){var l=a[s];if(!l.targets||l.targets.length!=o.length)throw new Error(t+": All primitives are required to list the same number of targets")}var h=new e.MorphTargetManager;i.babylonMesh.morphTargetManager=h;for(var u=0;u<o.length;u++){var c=i.weights?i.weights[u]:r.weights?r.weights[u]:0;h.addTarget(new e.MorphTarget("morphTarget"+u,c))}}},r.prototype._loadMorphTargets=function(t,i,r){var n=i.babylonMesh.morphTargetManager;n&&this._loadAllMorphTargetVertexDataAsync(t,i,r,function(){for(var i=n.numTargets,o=0;o<i;o++){for(var s=new e.VertexData,a=0,l=r.primitives;a<l.length;a++){var h=l[a];s.merge(h.targetsVertexData[o],{tangentLength:3})}if(!s.positions)throw new Error(t+": Positions are missing");var u=n.getTarget(o);u.setPositions(s.positions),u.setNormals(s.normals),u.setTangents(s.tangents)}})},r.prototype._loadAllMorphTargetVertexDataAsync=function(e,t,i,r){for(var n=i.primitives.length*t.babylonMesh.morphTargetManager.numTargets,o=this,s=0,a=i.primitives;s<a.length;s++)!function(t){var i=t.targets;t.targetsVertexData=new Array(i.length);for(var s=0;s<i.length;s++)!function(s){o._loadMorphTargetVertexDataAsync(e+"/targets/"+s,t.vertexData,i[s],function(e){t.targetsVertexData[s]=e,0==--n&&r()})}(s)}(a[s])},r.prototype._loadMorphTargetVertexDataAsync=function(t,i,n,o){var s=new e.VertexData,a=Object.keys(n).length,l=this;for(var h in n)!function(h){var u=r._GetProperty(l._gltf.accessors,n[h]);if(!u)throw new Error(t+": Failed to find attribute '"+h+"' accessor "+n[h]);l._loadAccessorAsync("#/accessors/"+u.index,u,function(t){var r=t;switch(h){case"POSITION":for(n=0;n<r.length;n++)r[n]+=i.positions[n];s.positions=r;break;case"NORMAL":for(n=0;n<r.length;n++)r[n]+=i.normals[n];s.normals=r;break;case"TANGENT":for(var n=0,l=0;n<r.length;n++,l++)r[n]+=i.tangents[l],(n+1)%3==0&&l++;s.tangents=r;break;default:e.Tools.Warn("Ignoring unrecognized attribute '"+h+"'")}0==--a&&o(s)})}(h)},r.prototype._loadTransform=function(t){var i=e.Vector3.Zero(),r=e.Quaternion.Identity(),n=e.Vector3.One();t.matrix?e.Matrix.FromArray(t.matrix).decompose(n,r,i):(t.translation&&(i=e.Vector3.FromArray(t.translation)),t.rotation&&(r=e.Quaternion.FromArray(t.rotation)),t.scale&&(n=e.Vector3.FromArray(t.scale))),t.babylonMesh.position=i,t.babylonMesh.rotationQuaternion=r,t.babylonMesh.scaling=n},r.prototype._loadSkin=function(t,i){var n=this,o="skeleton"+i.index;if(i.babylonSkeleton=new e.Skeleton(i.name||o,o,this._babylonScene),null==i.inverseBindMatrices)this._loadBones(t,i,null);else{var s=r._GetProperty(this._gltf.accessors,i.inverseBindMatrices);if(!s)throw new Error(t+": Failed to find inverse bind matrices attribute "+i.inverseBindMatrices);this._loadAccessorAsync("#/accessors/"+s.index,s,function(e){n._loadBones(t,i,e)})}return i.babylonSkeleton},r.prototype._createBone=function(t,i,r,n,o,s){var a=new e.Bone(t.name||"bone"+t.index,i.babylonSkeleton,r,n,null,o,s);return t.babylonBones=t.babylonBones||{},t.babylonBones[i.index]=a,t.babylonAnimationTargets=t.babylonAnimationTargets||[],t.babylonAnimationTargets.push(a),a},r.prototype._loadBones=function(e,t,i){for(var n={},o=0,s=t.joints;o<s.length;o++){var a=s[o],l=r._GetProperty(this._gltf.nodes,a);if(!l)throw new Error(e+": Failed to find joint "+a);this._loadBone(l,t,i,n)}},r.prototype._loadBone=function(t,i,r,n){var o=n[t.index];if(o)return o;var s=i.joints.indexOf(t.index),a=e.Matrix.Identity();r&&-1!==s&&(a=e.Matrix.FromArray(r,16*s)).invertToRef(a);var l=null;return t.index!==i.skeleton&&t.parent&&t.parent!==this._rootNode&&(l=this._loadBone(t.parent,i,r,n),a.multiplyToRef(l.getInvertedAbsoluteTransform(),a)),o=this._createBone(t,i,l,this._getNodeMatrix(t),a,s),n[t.index]=o,o},r.prototype._getNodeMatrix=function(t){return t.matrix?e.Matrix.FromArray(t.matrix):e.Matrix.Compose(t.scale?e.Vector3.FromArray(t.scale):e.Vector3.One(),t.rotation?e.Quaternion.FromArray(t.rotation):e.Quaternion.Identity(),t.translation?e.Vector3.FromArray(t.translation):e.Vector3.Zero())},r.prototype._traverseNodes=function(e,t,i,n){void 0===n&&(n=null);for(var o=0,s=t;o<s.length;o++){var a=s[o],l=r._GetProperty(this._gltf.nodes,a);if(!l)throw new Error(e+": Failed to find node "+a);this._traverseNode(e,l,i,n)}},r.prototype._traverseNode=function(e,i,r,n){void 0===n&&(n=null),t.GLTFLoaderExtension.TraverseNode(this,e,i,r,n)||r(i,n)&&i.children&&this._traverseNodes(e,i.children,r,i)},r.prototype._loadAnimations=function(){var e=this._gltf.animations;if(e)for(var t=0;t<e.length;t++){var i=e[t];this._loadAnimation("#/animations/"+t,i)}},r.prototype._loadAnimation=function(e,t){t.targets=[];for(var i=0;i<t.channels.length;i++){var n=r._GetProperty(t.channels,i);if(!n)throw new Error(e+": Failed to find channel "+i);var o=r._GetProperty(t.samplers,n.sampler);if(!o)throw new Error(e+": Failed to find sampler "+n.sampler);this._loadAnimationChannel(t,e+"/channels/"+i,n,e+"/samplers/"+n.sampler,o)}},r.prototype._loadAnimationChannel=function(t,i,n,o,s){var a=r._GetProperty(this._gltf.nodes,n.target.node);if(!a)throw new Error(i+": Failed to find target node "+n.target.node);var l,h;switch(n.target.path){case"translation":l="position",h=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"rotation":l="rotationQuaternion",h=e.Animation.ANIMATIONTYPE_QUATERNION;break;case"scale":l="scaling",h=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"weights":l="influence",h=e.Animation.ANIMATIONTYPE_FLOAT;break;default:throw new Error(i+": Invalid target path "+n.target.path)}var u,c,f=function(){if(u&&c){var i,r=0;switch(l){case"position":i=function(){var t=e.Vector3.FromArray(c,r);return r+=3,t};break;case"rotationQuaternion":i=function(){var t=e.Quaternion.FromArray(c,r);return r+=4,t};break;case"scaling":i=function(){var t=e.Vector3.FromArray(c,r);return r+=3,t};break;case"influence":i=function(){for(var e=a.babylonMesh.morphTargetManager.numTargets,t=new Array(e),i=0;i<e;i++)t[i]=c[r++];return t}}var n;switch(s.interpolation){case"LINEAR":n=function(e){return{frame:u[e],value:i()}};break;case"CUBICSPLINE":n=function(e){return{frame:u[e],inTangent:i(),value:i(),outTangent:i()}};break;default:throw new Error(o+": Invalid interpolation "+s.interpolation)}for(var f=new Array(u.length),p=0;p<u.length;p++)f[p]=n(p);if("influence"===l)for(var d=a.babylonMesh.morphTargetManager,m=0;m<d.numTargets;m++)!function(i){var r=d.getTarget(i),n=(t.name||"anim"+t.index)+"_"+i,o=new e.Animation(n,l,1,h);o.setKeys(f.map(function(e){return{frame:e.frame,inTangent:e.inTangent?e.inTangent[i]:void 0,value:e.value[i],outTangent:e.outTangent?e.outTangent[i]:void 0}})),r.animations.push(o),t.targets.push(r)}(m);else{var g=t.name||"anim"+t.index,v=new e.Animation(g,l,1,h);if(v.setKeys(f),a.babylonAnimationTargets)for(var _=0,y=a.babylonAnimationTargets;_<y.length;_++){var x=y[_];x.animations.push(v.clone()),t.targets.push(x)}}}},p=r._GetProperty(this._gltf.accessors,s.input);if(!p)throw new Error(o+": Failed to find input accessor "+s.input);this._loadAccessorAsync("#/accessors/"+p.index,p,function(e){u=e,f()});var d=r._GetProperty(this._gltf.accessors,s.output);if(!d)throw new Error(o+": Failed to find output accessor "+s.output);this._loadAccessorAsync("#/accessors/"+d.index,d,function(e){c=e,f()})},r.prototype._loadBufferAsync=function(i,r,n){var o=this;if(this._addPendingData(r),r.loadedData)n(r.loadedData),this._removePendingData(r);else if(r.loadedObservable)r.loadedObservable.add(function(e){n(e.loadedData),o._removePendingData(e)});else{if(!r.uri)throw new Error(i+": Uri is missing");if(t.GLTFUtils.IsBase64(r.uri)){var s=t.GLTFUtils.DecodeBase64(r.uri);r.loadedData=new Uint8Array(s),n(r.loadedData),this._removePendingData(r)}else r.loadedObservable=new e.Observable,r.loadedObservable.add(function(e){n(e.loadedData),o._removePendingData(e)}),this._loadUri(i,r.uri,function(e){r.loadedData=e,r.loadedObservable.notifyObservers(r),r.loadedObservable=void 0})}},r.prototype._loadBufferViewAsync=function(e,t,i){var n=r._GetProperty(this._gltf.buffers,t.buffer);if(!n)throw new Error(e+": Failed to find buffer "+t.buffer);this._loadBufferAsync("#/buffers/"+n.index,n,function(r){var n;try{n=new Uint8Array(r.buffer,r.byteOffset+(t.byteOffset||0),t.byteLength)}catch(t){throw new Error(e+": "+t.message)}i(n)})},r.prototype._loadAccessorAsync=function(e,i,n){var o=this;if(i.sparse)throw new Error(e+": Sparse accessors are not currently supported");var s=r._GetProperty(this._gltf.bufferViews,i.bufferView);if(!s)throw new Error(e+": Failed to find buffer view "+i.bufferView);this._loadBufferViewAsync("#/bufferViews/"+s.index,s,function(a){var l=r._GetNumComponents(i.type);if(0===l)throw new Error(e+": Invalid type "+i.type);var h,u=i.byteOffset||0,c=s.byteStride;try{switch(i.componentType){case t.EComponentType.BYTE:h=o._buildArrayBuffer(Float32Array,a,u,i.count,l,c);break;case t.EComponentType.UNSIGNED_BYTE:h=o._buildArrayBuffer(Uint8Array,a,u,i.count,l,c);break;case t.EComponentType.SHORT:h=o._buildArrayBuffer(Int16Array,a,u,i.count,l,c);break;case t.EComponentType.UNSIGNED_SHORT:h=o._buildArrayBuffer(Uint16Array,a,u,i.count,l,c);break;case t.EComponentType.UNSIGNED_INT:h=o._buildArrayBuffer(Uint32Array,a,u,i.count,l,c);break;case t.EComponentType.FLOAT:h=o._buildArrayBuffer(Float32Array,a,u,i.count,l,c);break;default:throw new Error(e+": Invalid component type "+i.componentType)}}catch(t){throw new Error(e+": "+t)}n(h)})},r.prototype._buildArrayBuffer=function(e,t,i,r,n,o){i+=t.byteOffset;var s=r*n;if(null==o||o===n*e.BYTES_PER_ELEMENT)return new e(t.buffer,i,s);for(var a=o/e.BYTES_PER_ELEMENT,l=new e(t.buffer,i,a*r),h=new e(s),u=0,c=0;c<s;){for(var f=0;f<n;f++)h[c]=l[u+f],c++;u+=a}return h},r.prototype._addPendingData=function(e){this._renderReady||this._renderPendingCount++,this._addLoaderPendingData(e)},r.prototype._removePendingData=function(e){this._renderReady||0==--this._renderPendingCount&&(this._renderReady=!0,this._onRenderReady()),this._removeLoaderPendingData(e)},r.prototype._addLoaderPendingData=function(e){this._loaderPendingCount++;for(var t=0,i=this._loaderTrackers;t<i.length;t++)i[t]._addPendingData(e)},r.prototype._removeLoaderPendingData=function(e){for(var t=0,i=this._loaderTrackers;t<i.length;t++)i[t]._removePendingData(e);0==--this._loaderPendingCount&&this._onComplete()},r.prototype._whenAction=function(e,t){var r=this,n=new i(function(){r._loaderTrackers.splice(r._loaderTrackers.indexOf(n),1),t()});this._loaderTrackers.push(n),this._addLoaderPendingData(n),e(),this._removeLoaderPendingData(n)},r.prototype._getDefaultMaterial=function(){if(!this._defaultMaterial){var t="__gltf_default",i=this._babylonScene.getMaterialByName(t);i||(i=new e.PBRMaterial(t,this._babylonScene),i.sideOrientation=e.Material.CounterClockWiseSideOrientation,i.metallic=1,i.roughness=1),this._defaultMaterial=i}return this._defaultMaterial},r.prototype._loadMaterialMetallicRoughnessProperties=function(t,i){var n=i.babylonMaterial;n.metallic=1,n.roughness=1;var o=i.pbrMetallicRoughness;if(o){if(n.albedoColor=o.baseColorFactor?e.Color3.FromArray(o.baseColorFactor):new e.Color3(1,1,1),n.metallic=null==o.metallicFactor?1:o.metallicFactor,n.roughness=null==o.roughnessFactor?1:o.roughnessFactor,o.baseColorTexture){if(!(s=r._GetProperty(this._gltf.textures,o.baseColorTexture.index)))throw new Error(t+": Failed to find base color texture "+o.baseColorTexture.index);n.albedoTexture=this._loadTexture("#/textures/"+s.index,s,o.baseColorTexture.texCoord)}if(o.metallicRoughnessTexture){var s=r._GetProperty(this._gltf.textures,o.metallicRoughnessTexture.index);if(!s)throw new Error(t+": Failed to find metallic roughness texture "+o.metallicRoughnessTexture.index);n.metallicTexture=this._loadTexture("#/textures/"+s.index,s,o.metallicRoughnessTexture.texCoord),n.useMetallnessFromMetallicTextureBlue=!0,n.useRoughnessFromMetallicTextureGreen=!0,n.useRoughnessFromMetallicTextureAlpha=!1}this._loadMaterialAlphaProperties(t,i,o.baseColorFactor)}},r.prototype._loadMaterial=function(e,i,r){i.babylonMaterial?r(i.babylonMaterial,!1):t.GLTFLoaderExtension.LoadMaterial(this,e,i,r)||(this._createPbrMaterial(i),this._loadMaterialBaseProperties(e,i),this._loadMaterialMetallicRoughnessProperties(e,i),r(i.babylonMaterial,!0))},r.prototype._createPbrMaterial=function(t){var i=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);i.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=i},r.prototype._loadMaterialBaseProperties=function(t,i){var n=i.babylonMaterial;if(n.emissiveColor=i.emissiveFactor?e.Color3.FromArray(i.emissiveFactor):new e.Color3(0,0,0),i.doubleSided&&(n.backFaceCulling=!1,n.twoSidedLighting=!0),i.normalTexture){if(!(o=r._GetProperty(this._gltf.textures,i.normalTexture.index)))throw new Error(t+": Failed to find normal texture "+i.normalTexture.index);n.bumpTexture=this._loadTexture("#/textures/"+o.index,o,i.normalTexture.texCoord),n.invertNormalMapX=!this._babylonScene.useRightHandedSystem,n.invertNormalMapY=this._babylonScene.useRightHandedSystem,null!=i.normalTexture.scale&&(n.bumpTexture.level=i.normalTexture.scale)}if(i.occlusionTexture){if(!(o=r._GetProperty(this._gltf.textures,i.occlusionTexture.index)))throw new Error(t+": Failed to find occlusion texture "+i.occlusionTexture.index);n.ambientTexture=this._loadTexture("#/textures/"+o.index,o,i.occlusionTexture.texCoord),n.useAmbientInGrayScale=!0,null!=i.occlusionTexture.strength&&(n.ambientTextureStrength=i.occlusionTexture.strength)}if(i.emissiveTexture){var o=r._GetProperty(this._gltf.textures,i.emissiveTexture.index);if(!o)throw new Error(t+": Failed to find emissive texture "+i.emissiveTexture.index);n.emissiveTexture=this._loadTexture("#/textures/"+o.index,o,i.emissiveTexture.texCoord)}},r.prototype._loadMaterialAlphaProperties=function(t,i,r){var n=i.babylonMaterial;switch(i.alphaMode||"OPAQUE"){case"OPAQUE":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_OPAQUE;break;case"MASK":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHATEST,n.alphaCutOff=null==i.alphaCutoff?.5:i.alphaCutoff,r&&(0==r[3]?n.alphaCutOff=1:n.alphaCutOff/=r[3]),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0);break;case"BLEND":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHABLEND,r&&(n.alpha=r[3]),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0,n.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(t+": Invalid alpha mode "+i.alphaMode)}},r.prototype._loadTexture=function(i,n,o){var s=this,a=null==n.sampler?{}:r._GetProperty(this._gltf.samplers,n.sampler);if(!a)throw new Error(i+": Failed to find sampler "+n.sampler);var l=a.minFilter===t.ETextureMinFilter.NEAREST||a.minFilter===t.ETextureMinFilter.LINEAR,h=r._GetTextureSamplingMode(a.magFilter,a.minFilter);this._addPendingData(n);var u=new e.Texture(null,this._babylonScene,l,!1,h,function(){s._tryCatchOnError(function(){s._removePendingData(n)})},function(e){s._tryCatchOnError(function(){throw new Error(i+": "+e)})});if(n.url)u.updateURL(n.url);else if(n.dataReadyObservable)n.dataReadyObservable.add(function(e){u.updateURL(e.url)});else{n.dataReadyObservable=new e.Observable,n.dataReadyObservable.add(function(e){u.updateURL(e.url)});var c=r._GetProperty(this._gltf.images,n.source);if(!c)throw new Error(i+": Failed to find source "+n.source);this._loadImage("#/images/"+c.index,c,function(e){n.url=URL.createObjectURL(new Blob([e],{type:c.mimeType})),n.dataReadyObservable.notifyObservers(n),n.dataReadyObservable=void 0})}return u.coordinatesIndex=o||0,u.wrapU=r._GetTextureWrapMode(a.wrapS),u.wrapV=r._GetTextureWrapMode(a.wrapT),u.name=n.name||"texture"+n.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(u),u},r.prototype._loadImage=function(e,i,n){if(i.uri)t.GLTFUtils.IsBase64(i.uri)?n(new Uint8Array(t.GLTFUtils.DecodeBase64(i.uri))):this._loadUri(e,i.uri,n);else{var o=r._GetProperty(this._gltf.bufferViews,i.bufferView);if(!o)throw new Error(e+": Failed to find buffer view "+i.bufferView);this._loadBufferViewAsync("#/bufferViews/"+o.index,o,n)}},r.prototype._loadUri=function(i,r,n){var o=this;if(!t.GLTFUtils.ValidateUri(r))throw new Error(i+": Uri '"+r+"' is invalid");var s=e.Tools.LoadFile(this._rootUrl+r,function(e){o._tryCatchOnError(function(){n(new Uint8Array(e))})},function(e){o._tryCatchOnError(function(){o._onProgress(e)})},this._babylonScene.database,!0,function(e){o._tryCatchOnError(function(){throw new Error(i+": Failed to load '"+r+"'"+(e?": "+e.status+" "+e.statusText:""))})});s&&this._requests.push(s)},r.prototype._tryCatchOnError=function(t){if(!this._disposed)try{t()}catch(t){e.Tools.Error("glTF Loader: "+t.message),this._errorCallback&&this._errorCallback(t.message),this.dispose()}},r._AssignIndices=function(e){if(e)for(var t=0;t<e.length;t++)e[t].index=t},r._GetProperty=function(e,t){return e&&void 0!=t&&e[t]?e[t]:null},r._GetTextureWrapMode=function(i){switch(i=void 0==i?t.ETextureWrapMode.REPEAT:i){case t.ETextureWrapMode.CLAMP_TO_EDGE:return e.Texture.CLAMP_ADDRESSMODE;case t.ETextureWrapMode.MIRRORED_REPEAT:return e.Texture.MIRROR_ADDRESSMODE;case t.ETextureWrapMode.REPEAT:return e.Texture.WRAP_ADDRESSMODE;default:return e.Tools.Warn("Invalid texture wrap mode ("+i+")"),e.Texture.WRAP_ADDRESSMODE}},r._GetTextureSamplingMode=function(i,r){if(i=void 0==i?t.ETextureMagFilter.LINEAR:i,r=void 0==r?t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:r,i===t.ETextureMagFilter.LINEAR)switch(r){case t.ETextureMinFilter.NEAREST:return e.Texture.LINEAR_NEAREST;case t.ETextureMinFilter.LINEAR:return e.Texture.LINEAR_LINEAR;case t.ETextureMinFilter.NEAREST_MIPMAP_NEAREST:return e.Texture.LINEAR_NEAREST_MIPNEAREST;case t.ETextureMinFilter.LINEAR_MIPMAP_NEAREST:return e.Texture.LINEAR_LINEAR_MIPNEAREST;case t.ETextureMinFilter.NEAREST_MIPMAP_LINEAR:return e.Texture.LINEAR_NEAREST_MIPLINEAR;case t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:return e.Texture.LINEAR_LINEAR_MIPLINEAR;default:return e.Tools.Warn("Invalid texture minification filter ("+r+")"),e.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(i!==t.ETextureMagFilter.NEAREST&&e.Tools.Warn("Invalid texture magnification filter ("+i+")"),r){case t.ETextureMinFilter.NEAREST:return e.Texture.NEAREST_NEAREST;case t.ETextureMinFilter.LINEAR:return e.Texture.NEAREST_LINEAR;case t.ETextureMinFilter.NEAREST_MIPMAP_NEAREST:return e.Texture.NEAREST_NEAREST_MIPNEAREST;case t.ETextureMinFilter.LINEAR_MIPMAP_NEAREST:return e.Texture.NEAREST_LINEAR_MIPNEAREST;case t.ETextureMinFilter.NEAREST_MIPMAP_LINEAR:return e.Texture.NEAREST_NEAREST_MIPLINEAR;case t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:return e.Texture.NEAREST_LINEAR_MIPLINEAR;default:return e.Tools.Warn("Invalid texture minification filter ("+r+")"),e.Texture.NEAREST_NEAREST_MIPNEAREST}},r._GetNumComponents=function(e){switch(e){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16}return 0},r.Extensions={},r}();t.GLTFLoader=r,e.GLTFFileLoader.CreateGLTFLoaderV2=function(e){return new r(e)}}(e.GLTF2||(e.GLTF2={}))}(n||(n={}));!function(e){!function(e){var t=function(){function e(){}return e.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},e.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),i=t.length,r=new Uint8Array(new ArrayBuffer(i)),n=0;n<i;n++)r[n]=t.charCodeAt(n);return r.buffer},e.ValidateUri=function(e){return-1===e.indexOf("..")},e}();e.GLTFUtils=t}(e.GLTF2||(e.GLTF2={}))}(n||(n={}));!function(e){!function(e){var t=function(){function e(){this.enabled=!0}return e.prototype._traverseNode=function(e,t,i,r,n){return!1},e.prototype._loadNode=function(e,t,i){return!1},e.prototype._loadMaterial=function(e,t,i,r){return!1},e.prototype._loadExtension=function(e,t,i){var r=this;if(!t.extensions)return!1;var n=t.extensions[this.name];return!!n&&(t.extensions[this.name]=void 0,i(e+"extensions/"+this.name,n,function(){t.extensions[r.name]=n}),!0)},e.TraverseNode=function(e,t,i,r,n){return this._ApplyExtensions(function(o){return o._traverseNode(e,t,i,r,n)})},e.LoadNode=function(e,t,i){return this._ApplyExtensions(function(r){return r._loadNode(e,t,i)})},e.LoadMaterial=function(e,t,i,r){return this._ApplyExtensions(function(n){return n._loadMaterial(e,t,i,r)})},e._ApplyExtensions=function(t){var i=e._Extensions;if(!i)return!1;for(var r=0,n=i;r<n.length;r++){var o=n[r];if(o.enabled&&t(o))return!0}return!1},e._Extensions=[],e}();e.GLTFLoaderExtension=t}(e.GLTF2||(e.GLTF2={}))}(n||(n={}));!function(e){!function(t){!function(i){var r=function(i){function r(){return null!==i&&i.apply(this,arguments)||this}return o(r,i),Object.defineProperty(r.prototype,"name",{get:function(){return"MSFT_lod"},enumerable:!0,configurable:!0}),r.prototype._traverseNode=function(e,i,r,n,o){return this._loadExtension(i,r,function(i,s,a){for(var l=s.ids.length-1;l>=0;l--){var h=t.GLTFLoader._GetProperty(e._gltf.nodes,s.ids[l]);if(!h)throw new Error(i+": Failed to find node "+s.ids[l]);e._traverseNode(i,h,n,o)}e._traverseNode(i,r,n,o),a()})},r.prototype._loadNode=function(e,i,r){var n=this;return this._loadExtension(i,r,function(i,o,s){for(var a=[r],l=0,h=o.ids;l<h.length;l++){var u=h[l],c=t.GLTFLoader._GetProperty(e._gltf.nodes,u);if(!c)throw new Error(i+": Failed to find node "+u);a.push(c)}e._addLoaderPendingData(r),n._loadNodeLOD(e,i,a,a.length-1,function(){e._removeLoaderPendingData(r),s()})})},r.prototype._loadNodeLOD=function(e,t,i,n,o){var s=this;e._whenAction(function(){e._loadNode(t,i[n])},function(){n!==i.length-1&&i[n+1].babylonMesh.setEnabled(!1),0!==n?setTimeout(function(){e._tryCatchOnError(function(){s._loadNodeLOD(e,t,i,n-1,o)})},r.MinimalLODDelay):o()})},r.prototype._loadMaterial=function(e,i,r,n){var o=this;return this._loadExtension(i,r,function(i,s,a){for(var l=[r],h=0,u=s.ids;h<u.length;h++){var c=u[h],f=t.GLTFLoader._GetProperty(e._gltf.materials,c);if(!f)throw new Error(i+": Failed to find material "+c);l.push(f)}e._addLoaderPendingData(r),o._loadMaterialLOD(e,i,l,l.length-1,n,function(){e._removeLoaderPendingData(r),a()})})},r.prototype._loadMaterialLOD=function(t,i,n,o,s,a){var l=this;t._loadMaterial(i,n[o],function(h,u){s(h,u),0!==o?t._executeWhenRenderReady(function(){e.BaseTexture.WhenAllReady(h.getActiveTextures(),function(){setTimeout(function(){t._tryCatchOnError(function(){l._loadMaterialLOD(t,i,n,o-1,s,a)})},r.MinimalLODDelay)})}):a()})},r.MinimalLODDelay=250,r}(t.GLTFLoaderExtension);i.MSFTLOD=r,t.GLTFLoader.RegisterExtension(new r)}(t.Extensions||(t.Extensions={}))}(e.GLTF2||(e.GLTF2={}))}(n||(n={}));!function(e){!function(t){!function(i){var r=function(i){function r(){return null!==i&&i.apply(this,arguments)||this}return o(r,i),Object.defineProperty(r.prototype,"name",{get:function(){return"KHR_materials_pbrSpecularGlossiness"},enumerable:!0,configurable:!0}),r.prototype._loadMaterial=function(e,t,i,r){var n=this;return this._loadExtension(t,i,function(t,o,s){e._createPbrMaterial(i),e._loadMaterialBaseProperties(t,i),n._loadSpecularGlossinessProperties(e,t,i,o),r(i.babylonMaterial,!0)})},r.prototype._loadSpecularGlossinessProperties=function(i,r,n,o){var s=n.babylonMaterial;if(s.albedoColor=o.diffuseFactor?e.Color3.FromArray(o.diffuseFactor):new e.Color3(1,1,1),s.reflectivityColor=o.specularFactor?e.Color3.FromArray(o.specularFactor):new e.Color3(1,1,1),s.microSurface=null==o.glossinessFactor?1:o.glossinessFactor,o.diffuseTexture){if(!(a=t.GLTFLoader._GetProperty(i._gltf.textures,o.diffuseTexture.index)))throw new Error(r+": Failed to find diffuse texture "+o.diffuseTexture.index);s.albedoTexture=i._loadTexture("textures["+a.index+"]",a,o.diffuseTexture.texCoord)}if(o.specularGlossinessTexture){var a=t.GLTFLoader._GetProperty(i._gltf.textures,o.specularGlossinessTexture.index);if(!a)throw new Error(r+": Failed to find diffuse texture "+o.specularGlossinessTexture.index);s.reflectivityTexture=i._loadTexture("textures["+a.index+"]",a,o.specularGlossinessTexture.texCoord),s.reflectivityTexture.hasAlpha=!0,s.useMicroSurfaceFromReflectivityMapAlpha=!0}i._loadMaterialAlphaProperties(r,n,o.diffuseFactor)},r}(t.GLTFLoaderExtension);i.KHRMaterialsPbrSpecularGlossiness=r,t.GLTFLoader.RegisterExtension(new r)}(t.Extensions||(t.Extensions={}))}(e.GLTF2||(e.GLTF2={}))}(n||(n={})),function(t,i){var r=i();t&&t.BABYLON||(e.exports=r)}(this,function(){return n})}).call(t,i(1))},function(e,t,i){(function(t){var r=void 0!==t?t:"undefined"!=typeof window?window:this,n=r&&r.BABYLON||n||i(0),o=this&&this.__decorate||function(e,t,i,r){var n,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,r);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(s=(o<3?n(s):o>3?n(t,i,s):n(t,i))||s);return o>3&&s&&Object.defineProperty(t,i,s),s},s=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])};return function(t,i){function r(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}();!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.CLIPPLANE=!1,t.POINTSIZE=!1,t.FOG=!1,t.NORMAL=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(e,t){return i.call(this,e,t)||this}return s(r,i),r.prototype.needAlphaBlending=function(){return!0},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},Object.defineProperty(r.prototype,"activeLight",{get:function(){return this._activeLight},set:function(e){this._activeLight=e},enumerable:!0,configurable:!0}),r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;var a=s.getEngine();if(this._activeLight)for(var l=0,h=i._lightSources;l<h.length;l++){var u=h[l];if(u.shadowEnabled){if(this._activeLight===u)break;var c=i._lightSources.indexOf(this._activeLight);-1!==c&&(i._lightSources.splice(c,1),i._lightSources.splice(0,0,this._activeLight));break}}if(e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,a,o,!!n),e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,o),o._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,o,!1,1),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!1,!0),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var f=new e.EffectFallbacks;o.FOG&&f.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(o,f,1),o.NUM_BONE_INFLUENCERS>0&&f.addCPUSkinningFallback(0,i);var p=[e.VertexBuffer.PositionKind];o.NORMAL&&p.push(e.VertexBuffer.NormalKind),e.MaterialHelper.PrepareAttributesForBones(p,i,o,f),e.MaterialHelper.PrepareAttributesForInstances(p,o);var d=o.toString(),m=["world","view","viewProjection","vEyePosition","vLightsType","vFogInfos","vFogColor","pointSize","alpha","mBones","vClipPlane"],g=new Array,v=new Array;e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:m,uniformBuffersNames:v,samplers:g,defines:o,maxSimultaneousLights:1}),r.setEffect(s.getEngine().createEffect("shadowOnly",{attributes:p,uniformsNames:m,uniformBuffersNames:v,samplers:g,defines:d,fallbacks:f,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:1}},a),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;s&&(this._activeEffect=s,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._activeEffect),this._mustRebind(n,s)&&(e.MaterialHelper.BindClipPlane(this._activeEffect,n),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),this._activeEffect.setFloat("alpha",this.alpha),e.MaterialHelper.BindEyePosition(s,n)),n.lightsEnabled&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o,1),n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._afterBind(i,this._activeEffect))}},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.ShadowOnlyMaterial",t},r.prototype.getClassName=function(){return"ShadowOnlyMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},r}(e.PushMaterial);e.ShadowOnlyMaterial=i}(n||(n={})),n.Effect.ShadersStore.shadowOnlyVertexShader="precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\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<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\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\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",n.Effect.ShadersStore.shadowOnlyPixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\nuniform float alpha;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0..1]\n\nvec4 color=vec4(0.,0.,0.,(1.0-clamp(shadow,0.,1.))*alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.DIFFUSE=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.POINTSIZE=!1,t.FOG=!1,t.LIGHT0=!1,t.LIGHT1=!1,t.LIGHT2=!1,t.LIGHT3=!1,t.SPOTLIGHT0=!1,t.SPOTLIGHT1=!1,t.SPOTLIGHT2=!1,t.SPOTLIGHT3=!1,t.HEMILIGHT0=!1,t.HEMILIGHT1=!1,t.HEMILIGHT2=!1,t.HEMILIGHT3=!1,t.DIRLIGHT0=!1,t.DIRLIGHT1=!1,t.DIRLIGHT2=!1,t.DIRLIGHT3=!1,t.POINTLIGHT0=!1,t.POINTLIGHT1=!1,t.POINTLIGHT2=!1,t.POINTLIGHT3=!1,t.SHADOW0=!1,t.SHADOW1=!1,t.SHADOW2=!1,t.SHADOW3=!1,t.SHADOWS=!1,t.SHADOWESM0=!1,t.SHADOWESM1=!1,t.SHADOWESM2=!1,t.SHADOWESM3=!1,t.SHADOWPCF0=!1,t.SHADOWPCF1=!1,t.SHADOWPCF2=!1,t.SHADOWPCF3=!1,t.NORMAL=!1,t.UV1=!1,t.UV2=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r){var n=i.call(this,t,r)||this;return n._maxSimultaneousLights=4,n.topColor=new e.Color3(1,0,0),n.topColorAlpha=1,n.bottomColor=new e.Color3(0,0,1),n.bottomColorAlpha=1,n.offset=0,n.smoothness=1,n.disableLighting=!1,n._scaledDiffuse=new e.Color3,n}return s(r,i),r.prototype.needAlphaBlending=function(){return this.alpha<1||this.topColorAlpha<1||this.bottomColorAlpha<1},r.prototype.needAlphaTesting=function(){return!0},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;var a=s.getEngine();if(e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,a,o,!!n),e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,o),o._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,o,!1,this._maxSimultaneousLights),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!1,!0),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var l=new e.EffectFallbacks;o.FOG&&l.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(o,l),o.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,i);var h=[e.VertexBuffer.PositionKind];o.NORMAL&&h.push(e.VertexBuffer.NormalKind),o.UV1&&h.push(e.VertexBuffer.UVKind),o.UV2&&h.push(e.VertexBuffer.UV2Kind),o.VERTEXCOLOR&&h.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(h,i,o,l),e.MaterialHelper.PrepareAttributesForInstances(h,o);var u=o.toString(),c=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","diffuseMatrix","topColor","bottomColor","offset","smoothness"],f=["diffuseSampler"],p=new Array;e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:o,maxSimultaneousLights:4}),r.setEffect(s.getEngine().createEffect("gradient",{attributes:h,uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:u,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:4}},a),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;s&&(this._activeEffect=s,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,s),this._mustRebind(n,s)&&(e.MaterialHelper.BindClipPlane(s,n),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),e.MaterialHelper.BindEyePosition(s,n)),this._activeEffect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*i.visibility),n.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o),n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._activeEffect.setColor4("topColor",this.topColor,this.topColorAlpha),this._activeEffect.setColor4("bottomColor",this.bottomColor,this.bottomColorAlpha),this._activeEffect.setFloat("offset",this.offset),this._activeEffect.setFloat("smoothness",this.smoothness),this._afterBind(i,this._activeEffect))}},r.prototype.getAnimatables=function(){return[]},r.prototype.dispose=function(e){i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.GradientMaterial",t},r.prototype.getClassName=function(){return"GradientMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},o([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),o([e.serializeAsColor3()],r.prototype,"topColor",void 0),o([e.serialize()],r.prototype,"topColorAlpha",void 0),o([e.serializeAsColor3()],r.prototype,"bottomColor",void 0),o([e.serialize()],r.prototype,"bottomColorAlpha",void 0),o([e.serialize()],r.prototype,"offset",void 0),o([e.serialize()],r.prototype,"smoothness",void 0),o([e.serialize()],r.prototype,"disableLighting",void 0),r}(e.PushMaterial);e.GradientMaterial=i}(n||(n={})),n.Effect.ShadersStore.gradientVertexShader="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 DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\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<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\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\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\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",n.Effect.ShadersStore.gradientPixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 topColor;\nuniform vec4 bottomColor;\nuniform float offset;\nuniform float smoothness;\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<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\nfloat h=normalize(vPositionW).y+offset;\nfloat mysmoothness=clamp(smoothness,0.01,max(smoothness,10.));\nvec4 baseColor=mix(bottomColor,topColor,max(pow(max(h,0.0),mysmoothness),0.0));\n\nvec3 diffuseColor=baseColor.rgb;\n\nfloat alpha=baseColor.a;\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\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 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.DIFFUSE=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.POINTSIZE=!1,t.FOG=!1,t.LIGHT0=!1,t.LIGHT1=!1,t.LIGHT2=!1,t.LIGHT3=!1,t.SPOTLIGHT0=!1,t.SPOTLIGHT1=!1,t.SPOTLIGHT2=!1,t.SPOTLIGHT3=!1,t.HEMILIGHT0=!1,t.HEMILIGHT1=!1,t.HEMILIGHT2=!1,t.HEMILIGHT3=!1,t.DIRLIGHT0=!1,t.DIRLIGHT1=!1,t.DIRLIGHT2=!1,t.DIRLIGHT3=!1,t.POINTLIGHT0=!1,t.POINTLIGHT1=!1,t.POINTLIGHT2=!1,t.POINTLIGHT3=!1,t.SHADOW0=!1,t.SHADOW1=!1,t.SHADOW2=!1,t.SHADOW3=!1,t.SHADOWS=!1,t.SHADOWESM0=!1,t.SHADOWESM1=!1,t.SHADOWESM2=!1,t.SHADOWESM3=!1,t.SHADOWPCF0=!1,t.SHADOWPCF1=!1,t.SHADOWPCF2=!1,t.SHADOWPCF3=!1,t.NORMAL=!1,t.UV1=!1,t.UV2=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.diffuseColor=new e.Color3(1,1,1),n._disableLighting=!1,n._maxSimultaneousLights=4,n}return s(r,i),r.prototype.needAlphaBlending=function(){return this.alpha<1},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;var a=s.getEngine();if(o._areTexturesDirty&&(o._needUVs=!1,s.texturesEnabled&&this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled)){if(!this._diffuseTexture.isReady())return!1;o._needUVs=!0,o.DIFFUSE=!0}if(e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,o),o._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,o,!1,this._maxSimultaneousLights,this._disableLighting),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,a,o,!!n),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!0,!0),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var l=new e.EffectFallbacks;o.FOG&&l.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(o,l),o.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,i);var h=[e.VertexBuffer.PositionKind];o.NORMAL&&h.push(e.VertexBuffer.NormalKind),o.UV1&&h.push(e.VertexBuffer.UVKind),o.UV2&&h.push(e.VertexBuffer.UV2Kind),o.VERTEXCOLOR&&h.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(h,i,o,l),e.MaterialHelper.PrepareAttributesForInstances(h,o);var u=o.toString(),c=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","diffuseMatrix"],f=["diffuseSampler"],p=new Array;e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:o,maxSimultaneousLights:4}),r.setEffect(s.getEngine().createEffect("normal",{attributes:h,uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:u,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:4}},a),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;s&&(this._activeEffect=s,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._activeEffect),this._mustRebind(n,s)&&(this.diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._activeEffect.setTexture("diffuseSampler",this.diffuseTexture),this._activeEffect.setFloat2("vDiffuseInfos",this.diffuseTexture.coordinatesIndex,this.diffuseTexture.level),this._activeEffect.setMatrix("diffuseMatrix",this.diffuseTexture.getTextureMatrix())),e.MaterialHelper.BindClipPlane(this._activeEffect,n),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),e.MaterialHelper.BindEyePosition(s,n)),this._activeEffect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility),n.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o),n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._afterBind(i,this._activeEffect))}},r.prototype.getAnimatables=function(){var e=[];return this.diffuseTexture&&this.diffuseTexture.animations&&this.diffuseTexture.animations.length>0&&e.push(this.diffuseTexture),e},r.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._diffuseTexture&&e.push(this._diffuseTexture),e},r.prototype.hasTexture=function(e){return!!i.prototype.hasTexture.call(this,e)||this.diffuseTexture===e},r.prototype.dispose=function(e){this.diffuseTexture&&this.diffuseTexture.dispose(),i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.NormalMaterial",t},r.prototype.getClassName=function(){return"NormalMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},o([e.serializeAsTexture("diffuseTexture")],r.prototype,"_diffuseTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture",void 0),o([e.serializeAsColor3()],r.prototype,"diffuseColor",void 0),o([e.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),o([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),r}(e.PushMaterial);e.NormalMaterial=i}(n||(n={})),n.Effect.ShadersStore.normalVertexShader="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 DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\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<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\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\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\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",n.Effect.ShadersStore.normalPixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\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<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\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#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef NORMAL\nbaseColor=mix(baseColor,vec4(vNormalW,1.0),0.5);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\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 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.DIFFUSE=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.POINTSIZE=!1,t.FOG=!1,t.LIGHT0=!1,t.LIGHT1=!1,t.LIGHT2=!1,t.LIGHT3=!1,t.SPOTLIGHT0=!1,t.SPOTLIGHT1=!1,t.SPOTLIGHT2=!1,t.SPOTLIGHT3=!1,t.HEMILIGHT0=!1,t.HEMILIGHT1=!1,t.HEMILIGHT2=!1,t.HEMILIGHT3=!1,t.DIRLIGHT0=!1,t.DIRLIGHT1=!1,t.DIRLIGHT2=!1,t.DIRLIGHT3=!1,t.POINTLIGHT0=!1,t.POINTLIGHT1=!1,t.POINTLIGHT2=!1,t.POINTLIGHT3=!1,t.SHADOW0=!1,t.SHADOW1=!1,t.SHADOW2=!1,t.SHADOW3=!1,t.SHADOWS=!1,t.SHADOWESM0=!1,t.SHADOWESM1=!1,t.SHADOWESM2=!1,t.SHADOWESM3=!1,t.SHADOWPCF0=!1,t.SHADOWPCF1=!1,t.SHADOWPCF2=!1,t.SHADOWPCF3=!1,t.NORMAL=!1,t.UV1=!1,t.UV2=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.speed=1,n.movingSpeed=1,n.lowFrequencySpeed=1,n.fogDensity=.15,n._lastTime=0,n.diffuseColor=new e.Color3(1,1,1),n._disableLighting=!1,n._maxSimultaneousLights=4,n._scaledDiffuse=new e.Color3,n}return s(r,i),r.prototype.needAlphaBlending=function(){return this.alpha<1},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;var a=s.getEngine();if(o._areTexturesDirty&&(o._needUVs=!1,s.texturesEnabled&&this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled)){if(!this._diffuseTexture.isReady())return!1;o._needUVs=!0,o.DIFFUSE=!0}if(e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,o),o._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,o,!1,this._maxSimultaneousLights,this._disableLighting),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,a,o,!!n),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!0,!0),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var l=new e.EffectFallbacks;o.FOG&&l.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(o,l),o.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,i);var h=[e.VertexBuffer.PositionKind];o.NORMAL&&h.push(e.VertexBuffer.NormalKind),o.UV1&&h.push(e.VertexBuffer.UVKind),o.UV2&&h.push(e.VertexBuffer.UV2Kind),o.VERTEXCOLOR&&h.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(h,i,o,l),e.MaterialHelper.PrepareAttributesForInstances(h,o);var u=o.toString(),c=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","diffuseMatrix","time","speed","movingSpeed","fogColor","fogDensity","lowFrequencySpeed"],f=["diffuseSampler","noiseTexture"],p=new Array;e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:o,maxSimultaneousLights:this.maxSimultaneousLights}),r.setEffect(s.getEngine().createEffect("lava",{attributes:h,uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:u,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this.maxSimultaneousLights}},a),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;s&&(this._activeEffect=s,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._activeEffect),this._mustRebind(n,s)&&(this.diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._activeEffect.setTexture("diffuseSampler",this.diffuseTexture),this._activeEffect.setFloat2("vDiffuseInfos",this.diffuseTexture.coordinatesIndex,this.diffuseTexture.level),this._activeEffect.setMatrix("diffuseMatrix",this.diffuseTexture.getTextureMatrix())),this.noiseTexture&&this._activeEffect.setTexture("noiseTexture",this.noiseTexture),e.MaterialHelper.BindClipPlane(this._activeEffect,n),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),e.MaterialHelper.BindEyePosition(s,n)),this._activeEffect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*i.visibility),n.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o),n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._lastTime+=n.getEngine().getDeltaTime(),this._activeEffect.setFloat("time",this._lastTime*this.speed/1e3),this.fogColor||(this.fogColor=e.Color3.Black()),this._activeEffect.setColor3("fogColor",this.fogColor),this._activeEffect.setFloat("fogDensity",this.fogDensity),this._activeEffect.setFloat("lowFrequencySpeed",this.lowFrequencySpeed),this._activeEffect.setFloat("movingSpeed",this.movingSpeed),this._afterBind(i,this._activeEffect))}},r.prototype.getAnimatables=function(){var e=[];return this.diffuseTexture&&this.diffuseTexture.animations&&this.diffuseTexture.animations.length>0&&e.push(this.diffuseTexture),this.noiseTexture&&this.noiseTexture.animations&&this.noiseTexture.animations.length>0&&e.push(this.noiseTexture),e},r.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._diffuseTexture&&e.push(this._diffuseTexture),e},r.prototype.hasTexture=function(e){return!!i.prototype.hasTexture.call(this,e)||this.diffuseTexture===e},r.prototype.dispose=function(e){this.diffuseTexture&&this.diffuseTexture.dispose(),this.noiseTexture&&this.noiseTexture.dispose(),i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.LavaMaterial",t},r.prototype.getClassName=function(){return"LavaMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},o([e.serializeAsTexture("diffuseTexture")],r.prototype,"_diffuseTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture",void 0),o([e.serializeAsTexture()],r.prototype,"noiseTexture",void 0),o([e.serializeAsColor3()],r.prototype,"fogColor",void 0),o([e.serialize()],r.prototype,"speed",void 0),o([e.serialize()],r.prototype,"movingSpeed",void 0),o([e.serialize()],r.prototype,"lowFrequencySpeed",void 0),o([e.serialize()],r.prototype,"fogDensity",void 0),o([e.serializeAsColor3()],r.prototype,"diffuseColor",void 0),o([e.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),o([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),r}(e.PushMaterial);e.LavaMaterial=i}(n||(n={})),n.Effect.ShadersStore.lavaVertexShader="precision highp float;\n\nuniform float time;\nuniform float lowFrequencySpeed;\n\nvarying float noise;\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 DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\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<__decl__lightFragment>[0..maxSimultaneousLights]\n\n\n\nvec3 mod289(vec3 x)\n{\nreturn x-floor(x*(1.0/289.0))*289.0;\n}\nvec4 mod289(vec4 x)\n{\nreturn x-floor(x*(1.0/289.0))*289.0;\n}\nvec4 permute(vec4 x)\n{\nreturn mod289(((x*34.0)+1.0)*x);\n}\nvec4 taylorInvSqrt(vec4 r)\n{\nreturn 1.79284291400159-0.85373472095314*r;\n}\nvec3 fade(vec3 t) {\nreturn t*t*t*(t*(t*6.0-15.0)+10.0);\n}\n\nfloat pnoise(vec3 P,vec3 rep)\n{\nvec3 Pi0=mod(floor(P),rep); \nvec3 Pi1=mod(Pi0+vec3(1.0),rep); \nPi0=mod289(Pi0);\nPi1=mod289(Pi1);\nvec3 Pf0=fract(P); \nvec3 Pf1=Pf0-vec3(1.0); \nvec4 ix=vec4(Pi0.x,Pi1.x,Pi0.x,Pi1.x);\nvec4 iy=vec4(Pi0.yy,Pi1.yy);\nvec4 iz0=Pi0.zzzz;\nvec4 iz1=Pi1.zzzz;\nvec4 ixy=permute(permute(ix)+iy);\nvec4 ixy0=permute(ixy+iz0);\nvec4 ixy1=permute(ixy+iz1);\nvec4 gx0=ixy0*(1.0/7.0);\nvec4 gy0=fract(floor(gx0)*(1.0/7.0))-0.5;\ngx0=fract(gx0);\nvec4 gz0=vec4(0.5)-abs(gx0)-abs(gy0);\nvec4 sz0=step(gz0,vec4(0.0));\ngx0-=sz0*(step(0.0,gx0)-0.5);\ngy0-=sz0*(step(0.0,gy0)-0.5);\nvec4 gx1=ixy1*(1.0/7.0);\nvec4 gy1=fract(floor(gx1)*(1.0/7.0))-0.5;\ngx1=fract(gx1);\nvec4 gz1=vec4(0.5)-abs(gx1)-abs(gy1);\nvec4 sz1=step(gz1,vec4(0.0));\ngx1-=sz1*(step(0.0,gx1)-0.5);\ngy1-=sz1*(step(0.0,gy1)-0.5);\nvec3 g000=vec3(gx0.x,gy0.x,gz0.x);\nvec3 g100=vec3(gx0.y,gy0.y,gz0.y);\nvec3 g010=vec3(gx0.z,gy0.z,gz0.z);\nvec3 g110=vec3(gx0.w,gy0.w,gz0.w);\nvec3 g001=vec3(gx1.x,gy1.x,gz1.x);\nvec3 g101=vec3(gx1.y,gy1.y,gz1.y);\nvec3 g011=vec3(gx1.z,gy1.z,gz1.z);\nvec3 g111=vec3(gx1.w,gy1.w,gz1.w);\nvec4 norm0=taylorInvSqrt(vec4(dot(g000,g000),dot(g010,g010),dot(g100,g100),dot(g110,g110)));\ng000*=norm0.x;\ng010*=norm0.y;\ng100*=norm0.z;\ng110*=norm0.w;\nvec4 norm1=taylorInvSqrt(vec4(dot(g001,g001),dot(g011,g011),dot(g101,g101),dot(g111,g111)));\ng001*=norm1.x;\ng011*=norm1.y;\ng101*=norm1.z;\ng111*=norm1.w;\nfloat n000=dot(g000,Pf0);\nfloat n100=dot(g100,vec3(Pf1.x,Pf0.yz));\nfloat n010=dot(g010,vec3(Pf0.x,Pf1.y,Pf0.z));\nfloat n110=dot(g110,vec3(Pf1.xy,Pf0.z));\nfloat n001=dot(g001,vec3(Pf0.xy,Pf1.z));\nfloat n101=dot(g101,vec3(Pf1.x,Pf0.y,Pf1.z));\nfloat n011=dot(g011,vec3(Pf0.x,Pf1.yz));\nfloat n111=dot(g111,Pf1);\nvec3 fade_xyz=fade(Pf0);\nvec4 n_z=mix(vec4(n000,n100,n010,n110),vec4(n001,n101,n011,n111),fade_xyz.z);\nvec2 n_yz=mix(n_z.xy,n_z.zw,fade_xyz.y);\nfloat n_xyz=mix(n_yz.x,n_yz.y,fade_xyz.x);\nreturn 2.2*n_xyz;\n}\n\nfloat turbulence( vec3 p ) {\nfloat w=100.0;\nfloat t=-.5;\nfor (float f=1.0 ; f<=10.0 ; f++ ){\nfloat power=pow( 2.0,f );\nt+=abs( pnoise( vec3( power*p ),vec3( 10.0,10.0,10.0 ) )/power );\n}\nreturn t;\n}\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\n#ifdef NORMAL\n\nnoise=10.0*-.10*turbulence( .5*normal+time*1.15 );\n\nfloat b=lowFrequencySpeed*5.0*pnoise( 0.05*position +vec3(time*1.025),vec3( 100.0 ) );\n\nfloat displacement =-1.5*noise+b;\n\nvec3 newPosition=position+normal*displacement;\ngl_Position=viewProjection*finalWorld*vec4( newPosition,1.0 );\nvec4 worldPos=finalWorld*vec4(newPosition,1.0);\nvPositionW=vec3(worldPos);\nvNormalW=normalize(vec3(finalWorld*vec4(normal,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\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}",n.Effect.ShadersStore.lavaPixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n\nuniform float time;\nuniform float speed;\nuniform float movingSpeed;\nuniform vec3 fogColor;\nuniform sampler2D noiseTexture;\nuniform float fogDensity;\n\nvarying float noise;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nfloat random( vec3 scale,float seed ){\nreturn fract( sin( dot( gl_FragCoord.xyz+seed,scale ) )*43758.5453+seed ) ;\n}\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#ifdef DIFFUSE\n\nvec4 noiseTex=texture2D( noiseTexture,vDiffuseUV );\nvec2 T1=vDiffuseUV+vec2( 1.5,-1.5 )*time*0.02;\nvec2 T2=vDiffuseUV+vec2( -0.5,2.0 )*time*0.01*speed;\nT1.x+=noiseTex.x*2.0;\nT1.y+=noiseTex.y*2.0;\nT2.x-=noiseTex.y*0.2+time*0.001*movingSpeed;\nT2.y+=noiseTex.z*0.2+time*0.002*movingSpeed;\nfloat p=texture2D( noiseTexture,T1*3.0 ).a;\nvec4 lavaColor=texture2D( diffuseSampler,T2*4.0);\nvec4 temp=lavaColor*( vec4( p,p,p,p )*2. )+( lavaColor*lavaColor-0.1 );\nbaseColor=temp;\nfloat depth=gl_FragCoord.z*4.0;\nconst float LOG2=1.442695;\nfloat fogFactor=exp2(-fogDensity*fogDensity*depth*depth*LOG2 );\nfogFactor=1.0-clamp( fogFactor,0.0,1.0 );\nbaseColor=mix( baseColor,vec4( fogColor,baseColor.w ),fogFactor );\ndiffuseColor=baseColor.rgb;\n\n\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\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 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.DIFFUSE=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.POINTSIZE=!1,t.FOG=!1,t.NORMAL=!1,t.UV1=!1,t.UV2=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.diffuseColor=new e.Color3(1,1,1),n._disableLighting=!1,n._maxSimultaneousLights=4,n}return s(r,i),r.prototype.needAlphaBlending=function(){return this.alpha<1},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;var a=s.getEngine();if(o._areTexturesDirty&&(o._needUVs=!1,s.texturesEnabled&&this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled)){if(!this._diffuseTexture.isReady())return!1;o._needUVs=!0,o.DIFFUSE=!0}if(e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,o),o._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,o,!1,this._maxSimultaneousLights,this._disableLighting),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,a,o,!!n),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!0,!0),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var l=new e.EffectFallbacks;o.FOG&&l.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(o,l,this.maxSimultaneousLights),o.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,i);var h=[e.VertexBuffer.PositionKind];o.NORMAL&&h.push(e.VertexBuffer.NormalKind),o.UV1&&h.push(e.VertexBuffer.UVKind),o.UV2&&h.push(e.VertexBuffer.UV2Kind),o.VERTEXCOLOR&&h.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(h,i,o,l),e.MaterialHelper.PrepareAttributesForInstances(h,o);var u=o.toString(),c=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","diffuseMatrix"],f=["diffuseSampler"],p=new Array;e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:o,maxSimultaneousLights:this.maxSimultaneousLights}),r.setEffect(s.getEngine().createEffect("simple",{attributes:h,uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:u,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights-1}},a),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;s&&(this._activeEffect=s,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._activeEffect),this._mustRebind(n,s)&&(this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._activeEffect.setTexture("diffuseSampler",this._diffuseTexture),this._activeEffect.setFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),this._activeEffect.setMatrix("diffuseMatrix",this._diffuseTexture.getTextureMatrix())),e.MaterialHelper.BindClipPlane(this._activeEffect,n),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),e.MaterialHelper.BindEyePosition(s,n)),this._activeEffect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility),n.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o,this.maxSimultaneousLights),n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._afterBind(i,this._activeEffect))}},r.prototype.getAnimatables=function(){var e=[];return this._diffuseTexture&&this._diffuseTexture.animations&&this._diffuseTexture.animations.length>0&&e.push(this._diffuseTexture),e},r.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._diffuseTexture&&e.push(this._diffuseTexture),e},r.prototype.hasTexture=function(e){return!!i.prototype.hasTexture.call(this,e)||this.diffuseTexture===e},r.prototype.dispose=function(e){this._diffuseTexture&&this._diffuseTexture.dispose(),i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.SimpleMaterial",t},r.prototype.getClassName=function(){return"SimpleMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},o([e.serializeAsTexture("diffuseTexture")],r.prototype,"_diffuseTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture",void 0),o([e.serializeAsColor3("diffuse")],r.prototype,"diffuseColor",void 0),o([e.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),o([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),r}(e.PushMaterial);e.SimpleMaterial=i}(n||(n={})),n.Effect.ShadersStore.simpleVertexShader="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 DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\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<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\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\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\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",n.Effect.ShadersStore.simplePixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\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<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\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#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\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 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif \n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.BUMP=!1,t.REFLECTION=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.POINTSIZE=!1,t.FOG=!1,t.NORMAL=!1,t.UV1=!1,t.UV2=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.SPECULARTERM=!1,t.LOGARITHMICDEPTH=!1,t.FRESNELSEPARATE=!1,t.BUMPSUPERIMPOSE=!1,t.BUMPAFFECTSREFLECTION=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r,n){void 0===n&&(n=new e.Vector2(512,512));var o=i.call(this,t,r)||this;return o.renderTargetSize=n,o.diffuseColor=new e.Color3(1,1,1),o.specularColor=new e.Color3(0,0,0),o.specularPower=64,o._disableLighting=!1,o._maxSimultaneousLights=4,o.windForce=6,o.windDirection=new e.Vector2(0,1),o.waveHeight=.4,o.bumpHeight=.4,o._bumpSuperimpose=!1,o._fresnelSeparate=!1,o._bumpAffectsReflection=!1,o.waterColor=new e.Color3(.1,.1,.6),o.colorBlendFactor=.2,o.waterColor2=new e.Color3(.1,.1,.6),o.colorBlendFactor2=.2,o.waveLength=.1,o.waveSpeed=1,o._renderTargets=new e.SmartArray(16),o._mesh=null,o._reflectionTransform=e.Matrix.Zero(),o._lastTime=0,o._lastDeltaTime=0,o._createRenderTargets(r,n),o.getRenderTargetTextures=function(){return o._renderTargets.reset(),o._renderTargets.push(o._reflectionRTT),o._renderTargets.push(o._refractionRTT),o._renderTargets},o}return s(r,i),Object.defineProperty(r.prototype,"useLogarithmicDepth",{get:function(){return this._useLogarithmicDepth},set:function(e){this._useLogarithmicDepth=e&&this.getScene().getEngine().getCaps().fragmentDepthSupported,this._markAllSubMeshesAsMiscDirty()},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"refractionTexture",{get:function(){return this._refractionRTT},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"reflectionTexture",{get:function(){return this._reflectionRTT},enumerable:!0,configurable:!0}),r.prototype.addToRenderList=function(e){this._refractionRTT.renderList&&this._refractionRTT.renderList.push(e),this._reflectionRTT.renderList&&this._reflectionRTT.renderList.push(e)},r.prototype.enableRenderTargets=function(e){var t=e?1:0;this._refractionRTT.refreshRate=t,this._reflectionRTT.refreshRate=t},r.prototype.getRenderList=function(){return this._refractionRTT.renderList},Object.defineProperty(r.prototype,"renderTargetsEnabled",{get:function(){return!(0===this._refractionRTT.refreshRate)},enumerable:!0,configurable:!0}),r.prototype.needAlphaBlending=function(){return this.alpha<1},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;var a=s.getEngine();if(o._areTexturesDirty&&(o._needUVs=!1,s.texturesEnabled)){if(this.bumpTexture&&e.StandardMaterial.BumpTextureEnabled){if(!this.bumpTexture.isReady())return!1;o._needUVs=!0,o.BUMP=!0}e.StandardMaterial.ReflectionTextureEnabled&&(o.REFLECTION=!0)}if(e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,a,o,!!n),e.MaterialHelper.PrepareDefinesForMisc(i,s,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,o),o._areMiscDirty&&(this._fresnelSeparate&&(o.FRESNELSEPARATE=!0),this._bumpSuperimpose&&(o.BUMPSUPERIMPOSE=!0),this._bumpAffectsReflection&&(o.BUMPAFFECTSREFLECTION=!0)),o._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,o,!0,this._maxSimultaneousLights,this._disableLighting),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!0,!0),this._mesh=i,o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var l=new e.EffectFallbacks;o.FOG&&l.addFallback(1,"FOG"),o.LOGARITHMICDEPTH&&l.addFallback(0,"LOGARITHMICDEPTH"),e.MaterialHelper.HandleFallbacksForShadows(o,l,this.maxSimultaneousLights),o.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,i);var h=[e.VertexBuffer.PositionKind];o.NORMAL&&h.push(e.VertexBuffer.NormalKind),o.UV1&&h.push(e.VertexBuffer.UVKind),o.UV2&&h.push(e.VertexBuffer.UV2Kind),o.VERTEXCOLOR&&h.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(h,i,o,l),e.MaterialHelper.PrepareAttributesForInstances(h,o);var u=o.toString(),c=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vSpecularColor","vFogInfos","vFogColor","pointSize","vNormalInfos","mBones","vClipPlane","normalMatrix","logarithmicDepthConstant","worldReflectionViewProjection","windDirection","waveLength","time","windForce","cameraPosition","bumpHeight","waveHeight","waterColor","waterColor2","colorBlendFactor","colorBlendFactor2","waveSpeed"],f=["normalSampler","refractionSampler","reflectionSampler"],p=new Array;e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:o,maxSimultaneousLights:this.maxSimultaneousLights}),r.setEffect(s.getEngine().createEffect("water",{attributes:h,uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:u,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights}},a),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;if(s&&this._mesh){this._activeEffect=s,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._activeEffect),this._mustRebind(n,s)&&(this.bumpTexture&&e.StandardMaterial.BumpTextureEnabled&&(this._activeEffect.setTexture("normalSampler",this.bumpTexture),this._activeEffect.setFloat2("vNormalInfos",this.bumpTexture.coordinatesIndex,this.bumpTexture.level),this._activeEffect.setMatrix("normalMatrix",this.bumpTexture.getTextureMatrix())),e.MaterialHelper.BindClipPlane(this._activeEffect,n),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),e.MaterialHelper.BindEyePosition(s,n)),this._activeEffect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility),o.SPECULARTERM&&this._activeEffect.setColor4("vSpecularColor",this.specularColor,this.specularPower),n.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o,this.maxSimultaneousLights),n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),e.MaterialHelper.BindLogDepth(o,this._activeEffect,n),e.StandardMaterial.ReflectionTextureEnabled&&(this._activeEffect.setTexture("refractionSampler",this._refractionRTT),this._activeEffect.setTexture("reflectionSampler",this._reflectionRTT));var a=this._mesh.getWorldMatrix().multiply(this._reflectionTransform).multiply(n.getProjectionMatrix()),l=n.getEngine().getDeltaTime();l!==this._lastDeltaTime&&(this._lastDeltaTime=l,this._lastTime+=this._lastDeltaTime),this._activeEffect.setMatrix("worldReflectionViewProjection",a),this._activeEffect.setVector2("windDirection",this.windDirection),this._activeEffect.setFloat("waveLength",this.waveLength),this._activeEffect.setFloat("time",this._lastTime/1e5),this._activeEffect.setFloat("windForce",this.windForce),this._activeEffect.setFloat("waveHeight",this.waveHeight),this._activeEffect.setFloat("bumpHeight",this.bumpHeight),this._activeEffect.setColor4("waterColor",this.waterColor,1),this._activeEffect.setFloat("colorBlendFactor",this.colorBlendFactor),this._activeEffect.setColor4("waterColor2",this.waterColor2,1),this._activeEffect.setFloat("colorBlendFactor2",this.colorBlendFactor2),this._activeEffect.setFloat("waveSpeed",this.waveSpeed),this._afterBind(i,this._activeEffect)}}},r.prototype._createRenderTargets=function(t,i){var r=this;this._refractionRTT=new e.RenderTargetTexture(name+"_refraction",{width:i.x,height:i.y},t,!1,!0),this._refractionRTT.wrapU=e.Texture.MIRROR_ADDRESSMODE,this._refractionRTT.wrapV=e.Texture.MIRROR_ADDRESSMODE,this._refractionRTT.ignoreCameraViewport=!0,this._reflectionRTT=new e.RenderTargetTexture(name+"_reflection",{width:i.x,height:i.y},t,!1,!0),this._reflectionRTT.wrapU=e.Texture.MIRROR_ADDRESSMODE,this._reflectionRTT.wrapV=e.Texture.MIRROR_ADDRESSMODE,this._reflectionRTT.ignoreCameraViewport=!0;var n,o,s=null,a=e.Matrix.Zero();this._refractionRTT.onBeforeRender=function(){r._mesh&&(n=r._mesh.isVisible,r._mesh.isVisible=!1),s=t.clipPlane;var i=r._mesh?r._mesh.position.y:0;t.clipPlane=e.Plane.FromPositionAndNormal(new e.Vector3(0,i+.05,0),new e.Vector3(0,1,0))},this._refractionRTT.onAfterRender=function(){r._mesh&&(r._mesh.isVisible=n),t.clipPlane=s},this._reflectionRTT.onBeforeRender=function(){r._mesh&&(n=r._mesh.isVisible,r._mesh.isVisible=!1),s=t.clipPlane;var i=r._mesh?r._mesh.position.y:0;t.clipPlane=e.Plane.FromPositionAndNormal(new e.Vector3(0,i-.05,0),new e.Vector3(0,-1,0)),e.Matrix.ReflectionToRef(t.clipPlane,a),o=t.getViewMatrix(),a.multiplyToRef(o,r._reflectionTransform),t.setTransformMatrix(r._reflectionTransform,t.getProjectionMatrix()),t.getEngine().cullBackFaces=!1,t._mirroredCameraPosition=e.Vector3.TransformCoordinates(t.activeCamera.position,a)},this._reflectionRTT.onAfterRender=function(){r._mesh&&(r._mesh.isVisible=n),t.clipPlane=s,t.setTransformMatrix(o,t.getProjectionMatrix()),t.getEngine().cullBackFaces=!0,t._mirroredCameraPosition=null}},r.prototype.getAnimatables=function(){var e=[];return this.bumpTexture&&this.bumpTexture.animations&&this.bumpTexture.animations.length>0&&e.push(this.bumpTexture),this._reflectionRTT&&this._reflectionRTT.animations&&this._reflectionRTT.animations.length>0&&e.push(this._reflectionRTT),this._refractionRTT&&this._refractionRTT.animations&&this._refractionRTT.animations.length>0&&e.push(this._refractionRTT),e},r.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._bumpTexture&&e.push(this._bumpTexture),e},r.prototype.hasTexture=function(e){return!!i.prototype.hasTexture.call(this,e)||this._bumpTexture===e},r.prototype.dispose=function(e){this.bumpTexture&&this.bumpTexture.dispose();var t=this.getScene().customRenderTargets.indexOf(this._refractionRTT);-1!=t&&this.getScene().customRenderTargets.splice(t,1),t=-1,-1!=(t=this.getScene().customRenderTargets.indexOf(this._reflectionRTT))&&this.getScene().customRenderTargets.splice(t,1),this._reflectionRTT&&this._reflectionRTT.dispose(),this._refractionRTT&&this._refractionRTT.dispose(),i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.WaterMaterial",t.reflectionTexture.isRenderTarget=!0,t.refractionTexture.isRenderTarget=!0,t},r.prototype.getClassName=function(){return"WaterMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},r.CreateDefaultMesh=function(t,i){return e.Mesh.CreateGround(t,512,512,32,i,!1)},o([e.serializeAsTexture("bumpTexture")],r.prototype,"_bumpTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"bumpTexture",void 0),o([e.serializeAsColor3()],r.prototype,"diffuseColor",void 0),o([e.serializeAsColor3()],r.prototype,"specularColor",void 0),o([e.serialize()],r.prototype,"specularPower",void 0),o([e.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),o([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),o([e.serialize()],r.prototype,"windForce",void 0),o([e.serializeAsVector2()],r.prototype,"windDirection",void 0),o([e.serialize()],r.prototype,"waveHeight",void 0),o([e.serialize()],r.prototype,"bumpHeight",void 0),o([e.serialize("bumpSuperimpose")],r.prototype,"_bumpSuperimpose",void 0),o([e.expandToProperty("_markAllSubMeshesAsMiscDirty")],r.prototype,"bumpSuperimpose",void 0),o([e.serialize("fresnelSeparate")],r.prototype,"_fresnelSeparate",void 0),o([e.expandToProperty("_markAllSubMeshesAsMiscDirty")],r.prototype,"fresnelSeparate",void 0),o([e.serialize("bumpAffectsReflection")],r.prototype,"_bumpAffectsReflection",void 0),o([e.expandToProperty("_markAllSubMeshesAsMiscDirty")],r.prototype,"bumpAffectsReflection",void 0),o([e.serializeAsColor3()],r.prototype,"waterColor",void 0),o([e.serialize()],r.prototype,"colorBlendFactor",void 0),o([e.serializeAsColor3()],r.prototype,"waterColor2",void 0),o([e.serialize()],r.prototype,"colorBlendFactor2",void 0),o([e.serialize()],r.prototype,"waveLength",void 0),o([e.serialize()],r.prototype,"waveSpeed",void 0),o([e.serialize()],r.prototype,"useLogarithmicDepth",null),r}(e.PushMaterial);e.WaterMaterial=i}(n||(n={})),n.Effect.ShadersStore.waterVertexShader="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 BUMP\nvarying vec2 vNormalUV;\n#ifdef BUMPSUPERIMPOSE\nvarying vec2 vNormalUV2;\n#endif\nuniform mat4 normalMatrix;\nuniform vec2 vNormalInfos;\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<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<logDepthDeclaration>\n\nuniform mat4 worldReflectionViewProjection;\nuniform vec2 windDirection;\nuniform float waveLength;\nuniform float time;\nuniform float windForce;\nuniform float waveHeight;\nuniform float waveSpeed;\n\nvarying vec3 vPosition;\nvarying vec3 vRefractionMapTexCoord;\nvarying vec3 vReflectionMapTexCoord;\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,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 BUMP\nif (vNormalInfos.x == 0.)\n{\nvNormalUV=vec2(normalMatrix*vec4((uv*1.0)/waveLength+time*windForce*windDirection,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv*0.721)/waveLength+time*1.2*windForce*windDirection,1.0,0.0));\n#endif\n}\nelse\n{\nvNormalUV=vec2(normalMatrix*vec4((uv2*1.0)/waveLength+time*windForce*windDirection ,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv2*0.721)/waveLength+time*1.2*windForce*windDirection ,1.0,0.0));\n#endif\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\nvec3 p=position;\nfloat newY=(sin(((p.x/0.05)+time*waveSpeed))*waveHeight*windDirection.x*5.0)\n+(cos(((p.z/0.05)+time*waveSpeed))*waveHeight*windDirection.y*5.0);\np.y+=abs(newY);\ngl_Position=viewProjection*finalWorld*vec4(p,1.0);\n#ifdef REFLECTION\nworldPos=viewProjection*finalWorld*vec4(p,1.0);\n\nvPosition=position;\nvRefractionMapTexCoord.x=0.5*(worldPos.w+worldPos.x);\nvRefractionMapTexCoord.y=0.5*(worldPos.w+worldPos.y);\nvRefractionMapTexCoord.z=worldPos.w;\nworldPos=worldReflectionViewProjection*vec4(position,1.0);\nvReflectionMapTexCoord.x=0.5*(worldPos.w+worldPos.x);\nvReflectionMapTexCoord.y=0.5*(worldPos.w+worldPos.y);\nvReflectionMapTexCoord.z=worldPos.w;\n#endif\n#include<logDepthVertex>\n}\n",n.Effect.ShadersStore.waterPixelShader="#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\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<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef BUMP\nvarying vec2 vNormalUV;\nvarying vec2 vNormalUV2;\nuniform sampler2D normalSampler;\nuniform vec2 vNormalInfos;\n#endif\nuniform sampler2D refractionSampler;\nuniform sampler2D reflectionSampler;\n\nconst float LOG2=1.442695;\nuniform vec3 cameraPosition;\nuniform vec4 waterColor;\nuniform float colorBlendFactor;\nuniform vec4 waterColor2;\nuniform float colorBlendFactor2;\nuniform float bumpHeight;\nuniform float time;\n\nvarying vec3 vRefractionMapTexCoord;\nvarying vec3 vReflectionMapTexCoord;\nvarying vec3 vPosition;\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n\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#ifdef BUMP\n#ifdef BUMPSUPERIMPOSE\nbaseColor=0.6*texture2D(normalSampler,vNormalUV)+0.4*texture2D(normalSampler,vec2(vNormalUV2.x,vNormalUV2.y));\n#else\nbaseColor=texture2D(normalSampler,vNormalUV);\n#endif\nvec3 bumpColor=baseColor.rgb;\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\nbaseColor.rgb*=vNormalInfos.y;\n#else\nvec3 bumpColor=vec3(1.0);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec2 perturbation=bumpHeight*(baseColor.rg-0.5);\n#ifdef BUMPAFFECTSREFLECTION\nvec3 normalW=normalize(vNormalW+vec3(perturbation.x*8.0,0.0,perturbation.y*8.0));\nif (normalW.y<0.0) {\nnormalW.y=-normalW.y;\n}\n#else\nvec3 normalW=normalize(vNormalW);\n#endif\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\nvec2 perturbation=bumpHeight*(vec2(1.0,1.0)-0.5);\n#endif\n#ifdef FRESNELSEPARATE\n#ifdef REFLECTION\n\nvec3 eyeVector=normalize(vEyePosition-vPosition);\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation*0.5,0.0,1.0);\nvec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\nvec2 projectedReflectionTexCoords=clamp(vec2(\nvReflectionMapTexCoord.x/vReflectionMapTexCoord.z+perturbation.x*0.3,\nvReflectionMapTexCoord.y/vReflectionMapTexCoord.z+perturbation.y\n),0.0,1.0);\nvec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\nvec3 upVector=vec3(0.0,1.0,0.0);\nfloat fresnelTerm=clamp(abs(pow(dot(eyeVector,upVector),3.0)),0.05,0.65);\nfloat IfresnelTerm=1.0-fresnelTerm;\nrefractiveColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*refractiveColor;\nreflectiveColor=IfresnelTerm*colorBlendFactor2*waterColor+(1.0-colorBlendFactor2*IfresnelTerm)*reflectiveColor;\nvec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*IfresnelTerm;\nbaseColor=combinedColor;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#else \n#ifdef REFLECTION\n\nvec3 eyeVector=normalize(vEyePosition-vPosition);\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation,0.0,1.0);\nvec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\nvec2 projectedReflectionTexCoords=clamp(vReflectionMapTexCoord.xy/vReflectionMapTexCoord.z+perturbation,0.0,1.0);\nvec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\nvec3 upVector=vec3(0.0,1.0,0.0);\nfloat fresnelTerm=max(dot(eyeVector,upVector),0.0);\nvec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*(1.0-fresnelTerm);\nbaseColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*combinedColor;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#endif\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<logDepthFragment>\n#include<fogFragment>\ngl_FragColor=color;\n}\n";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.DIFFUSE=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.POINTSIZE=!1,t.FOG=!1,t.UV1=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.BonesPerMesh=0,t.NUM_BONE_INFLUENCERS=0,t.INSTANCES=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.diffuseColor=new e.Color3(1,1,1),n.speed=1,n._scaledDiffuse=new e.Color3,n._lastTime=0,n}return s(r,i),r.prototype.needAlphaBlending=function(){return!1},r.prototype.needAlphaTesting=function(){return!0},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;var a=s.getEngine();if(o._areTexturesDirty&&(o._needUVs=!1,this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled)){if(!this._diffuseTexture.isReady())return!1;o._needUVs=!0,o.DIFFUSE=!0}if(o._areMiscDirty&&(o.POINTSIZE=this.pointsCloud||s.forcePointsCloud,o.FOG=s.fogEnabled&&i.applyFog&&s.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,a,o,!!n),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!1,!0),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var l=new e.EffectFallbacks;o.FOG&&l.addFallback(1,"FOG"),o.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,i);var h=[e.VertexBuffer.PositionKind];o.UV1&&h.push(e.VertexBuffer.UVKind),o.VERTEXCOLOR&&h.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(h,i,o,l),e.MaterialHelper.PrepareAttributesForInstances(h,o);var u=o.toString();r.setEffect(s.getEngine().createEffect("fire",{attributes:h,uniformsNames:["world","view","viewProjection","vEyePosition","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","diffuseMatrix","time","speed"],uniformBuffersNames:[],samplers:["diffuseSampler","distortionSampler","opacitySampler"],defines:u,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:null,maxSimultaneousLights:4,transformFeedbackVaryings:null},a),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene();if(r._materialDefines){var o=r.effect;if(o){if(this._activeEffect=o,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._activeEffect),this._mustRebind(n,o)){if(this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._activeEffect.setTexture("diffuseSampler",this._diffuseTexture),this._activeEffect.setFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),this._activeEffect.setMatrix("diffuseMatrix",this._diffuseTexture.getTextureMatrix()),this._activeEffect.setTexture("distortionSampler",this._distortionTexture),this._activeEffect.setTexture("opacitySampler",this._opacityTexture)),n.clipPlane){var s=n.clipPlane;this._activeEffect.setFloat4("vClipPlane",s.normal.x,s.normal.y,s.normal.z,s.d)}this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),e.MaterialHelper.BindEyePosition(o,n)}this._activeEffect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*i.visibility),n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._lastTime+=n.getEngine().getDeltaTime(),this._activeEffect.setFloat("time",this._lastTime),this._activeEffect.setFloat("speed",this.speed),this._afterBind(i,this._activeEffect)}}},r.prototype.getAnimatables=function(){var e=[];return this._diffuseTexture&&this._diffuseTexture.animations&&this._diffuseTexture.animations.length>0&&e.push(this._diffuseTexture),this._distortionTexture&&this._distortionTexture.animations&&this._distortionTexture.animations.length>0&&e.push(this._distortionTexture),this._opacityTexture&&this._opacityTexture.animations&&this._opacityTexture.animations.length>0&&e.push(this._opacityTexture),e},r.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._diffuseTexture&&e.push(this._diffuseTexture),this._distortionTexture&&e.push(this._distortionTexture),this._opacityTexture&&e.push(this._opacityTexture),e},r.prototype.hasTexture=function(e){return!!i.prototype.hasTexture.call(this,e)||this._diffuseTexture===e||this._distortionTexture===e||this._opacityTexture===e},r.prototype.getClassName=function(){return"FireMaterial"},r.prototype.dispose=function(e){this._diffuseTexture&&this._diffuseTexture.dispose(),this._distortionTexture&&this._distortionTexture.dispose(),i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var e=i.prototype.serialize.call(this);return e.customType="BABYLON.FireMaterial",e.diffuseColor=this.diffuseColor.asArray(),e.speed=this.speed,this._diffuseTexture&&(e._diffuseTexture=this._diffuseTexture.serialize()),this._distortionTexture&&(e._distortionTexture=this._distortionTexture.serialize()),this._opacityTexture&&(e._opacityTexture=this._opacityTexture.serialize()),e},r.Parse=function(t,i,n){var o=new r(t.name,i);return o.diffuseColor=e.Color3.FromArray(t.diffuseColor),o.speed=t.speed,o.alpha=t.alpha,o.id=t.id,e.Tags.AddTagsTo(o,t.tags),o.backFaceCulling=t.backFaceCulling,o.wireframe=t.wireframe,t._diffuseTexture&&(o._diffuseTexture=e.Texture.Parse(t._diffuseTexture,i,n)),t._distortionTexture&&(o._distortionTexture=e.Texture.Parse(t._distortionTexture,i,n)),t._opacityTexture&&(o._opacityTexture=e.Texture.Parse(t._opacityTexture,i,n)),t.checkReadyOnlyOnce&&(o.checkReadyOnlyOnce=t.checkReadyOnlyOnce),o},o([e.serializeAsTexture("diffuseTexture")],r.prototype,"_diffuseTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture",void 0),o([e.serializeAsTexture("distortionTexture")],r.prototype,"_distortionTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"distortionTexture",void 0),o([e.serializeAsTexture("opacityTexture")],r.prototype,"_opacityTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"opacityTexture",void 0),o([e.serializeAsColor3("diffuse")],r.prototype,"diffuseColor",void 0),o([e.serialize()],r.prototype,"speed",void 0),r}(e.PushMaterial);e.FireMaterial=i}(n||(n={})),n.Effect.ShadersStore.fireVertexShader="precision highp float;\n\nattribute vec3 position;\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;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n\nuniform float time;\nuniform float speed;\n#ifdef DIFFUSE\nvarying vec2 vDistortionCoords1;\nvarying vec2 vDistortionCoords2;\nvarying vec2 vDistortionCoords3;\n#endif\nvoid main(void) {\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\n#ifdef DIFFUSE\nvDiffuseUV=uv;\nvDiffuseUV.y-=0.2;\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n#ifdef DIFFUSE\n\nvec3 layerSpeed=vec3(-0.2,-0.52,-0.1)*speed;\nvDistortionCoords1.x=uv.x;\nvDistortionCoords1.y=uv.y+layerSpeed.x*time/1000.0;\nvDistortionCoords2.x=uv.x;\nvDistortionCoords2.y=uv.y+layerSpeed.y*time/1000.0;\nvDistortionCoords3.x=uv.x;\nvDistortionCoords3.y=uv.y+layerSpeed.z*time/1000.0;\n#endif\n}\n",n.Effect.ShadersStore.firePixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\nuniform sampler2D distortionSampler;\nuniform sampler2D opacitySampler;\n#ifdef DIFFUSE\nvarying vec2 vDistortionCoords1;\nvarying vec2 vDistortionCoords2;\nvarying vec2 vDistortionCoords3;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvec4 bx2(vec4 x)\n{\nreturn vec4(2.0)*x-vec4(1.0);\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\n\nfloat alpha=1.0;\n#ifdef DIFFUSE\n\nconst float distortionAmount0=0.092;\nconst float distortionAmount1=0.092;\nconst float distortionAmount2=0.092;\nvec2 heightAttenuation=vec2(0.3,0.39);\nvec4 noise0=texture2D(distortionSampler,vDistortionCoords1);\nvec4 noise1=texture2D(distortionSampler,vDistortionCoords2);\nvec4 noise2=texture2D(distortionSampler,vDistortionCoords3);\nvec4 noiseSum=bx2(noise0)*distortionAmount0+bx2(noise1)*distortionAmount1+bx2(noise2)*distortionAmount2;\nvec4 perturbedBaseCoords=vec4(vDiffuseUV,0.0,1.0)+noiseSum*(vDiffuseUV.y*heightAttenuation.x+heightAttenuation.y);\nvec4 opacityColor=texture2D(opacitySampler,perturbedBaseCoords.xy);\n#ifdef ALPHATEST\nif (opacityColor.r<0.1)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor=texture2D(diffuseSampler,perturbedBaseCoords.xy)*2.0;\nbaseColor*=opacityColor;\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(1.0,1.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n\nvec4 color=vec4(baseColor.rgb,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.DIFFUSE=!1,t.HEIGHTMAP=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.POINTSIZE=!1,t.FOG=!1,t.NORMAL=!1,t.UV1=!1,t.UV2=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.HIGHLEVEL=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.diffuseColor=new e.Color3(1,1,1),n.furLength=1,n.furAngle=0,n.furColor=new e.Color3(.44,.21,.02),n.furOffset=0,n.furSpacing=12,n.furGravity=new e.Vector3(0,0,0),n.furSpeed=100,n.furDensity=20,n._disableLighting=!1,n._maxSimultaneousLights=4,n.highLevelFur=!0,n._furTime=0,n}return s(r,i),Object.defineProperty(r.prototype,"furTime",{get:function(){return this._furTime},set:function(e){this._furTime=e},enumerable:!0,configurable:!0}),r.prototype.needAlphaBlending=function(){return this.alpha<1},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.updateFur=function(){for(var e=1;e<this._meshes.length;e++){var t=this._meshes[e].material;t.furLength=this.furLength,t.furAngle=this.furAngle,t.furGravity=this.furGravity,t.furSpacing=this.furSpacing,t.furSpeed=this.furSpeed,t.furColor=this.furColor,t.diffuseTexture=this.diffuseTexture,t.furTexture=this.furTexture,t.highLevelFur=this.highLevelFur,t.furTime=this.furTime,t.furDensity=this.furDensity}},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;var a=s.getEngine();if(o._areTexturesDirty&&s.texturesEnabled){if(this.diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;o._needUVs=!0,o.DIFFUSE=!0}if(this.heightTexture&&a.getCaps().maxVertexTextureImageUnits){if(!this.heightTexture.isReady())return!1;o._needUVs=!0,o.HEIGHTMAP=!0}}if(this.highLevelFur!==o.HIGHLEVEL&&(o.HIGHLEVEL=!0,o.markAsUnprocessed()),e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,o),o._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,o,!1,this._maxSimultaneousLights,this._disableLighting),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,a,o,!!n),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!0,!0),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var l=new e.EffectFallbacks;o.FOG&&l.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(o,l,this.maxSimultaneousLights),o.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,i);var h=[e.VertexBuffer.PositionKind];o.NORMAL&&h.push(e.VertexBuffer.NormalKind),o.UV1&&h.push(e.VertexBuffer.UVKind),o.UV2&&h.push(e.VertexBuffer.UV2Kind),o.VERTEXCOLOR&&h.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(h,i,o,l),e.MaterialHelper.PrepareAttributesForInstances(h,o);var u=o.toString(),c=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","diffuseMatrix","furLength","furAngle","furColor","furOffset","furGravity","furTime","furSpacing","furDensity"],f=["diffuseSampler","heightTexture","furTexture"],p=new Array;e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:o,maxSimultaneousLights:this.maxSimultaneousLights}),r.setEffect(s.getEngine().createEffect("fur",{attributes:h,uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:u,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this.maxSimultaneousLights}},a),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;s&&(this._activeEffect=s,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._activeEffect),n.getCachedMaterial()!==this&&(this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._activeEffect.setTexture("diffuseSampler",this._diffuseTexture),this._activeEffect.setFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),this._activeEffect.setMatrix("diffuseMatrix",this._diffuseTexture.getTextureMatrix())),this._heightTexture&&this._activeEffect.setTexture("heightTexture",this._heightTexture),e.MaterialHelper.BindClipPlane(this._activeEffect,n),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),e.MaterialHelper.BindEyePosition(s,n)),this._activeEffect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility),n.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o,this.maxSimultaneousLights),n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._activeEffect.setFloat("furLength",this.furLength),this._activeEffect.setFloat("furAngle",this.furAngle),this._activeEffect.setColor4("furColor",this.furColor,1),this.highLevelFur&&(this._activeEffect.setVector3("furGravity",this.furGravity),this._activeEffect.setFloat("furOffset",this.furOffset),this._activeEffect.setFloat("furSpacing",this.furSpacing),this._activeEffect.setFloat("furDensity",this.furDensity),this._furTime+=this.getScene().getEngine().getDeltaTime()/this.furSpeed,this._activeEffect.setFloat("furTime",this._furTime),this._activeEffect.setTexture("furTexture",this.furTexture)),this._afterBind(i,this._activeEffect))}},r.prototype.getAnimatables=function(){var e=[];return this.diffuseTexture&&this.diffuseTexture.animations&&this.diffuseTexture.animations.length>0&&e.push(this.diffuseTexture),this.heightTexture&&this.heightTexture.animations&&this.heightTexture.animations.length>0&&e.push(this.heightTexture),e},r.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._diffuseTexture&&e.push(this._diffuseTexture),this._heightTexture&&e.push(this._heightTexture),e},r.prototype.hasTexture=function(e){return!!i.prototype.hasTexture.call(this,e)||this.diffuseTexture===e||this._heightTexture===e},r.prototype.dispose=function(e){if(this.diffuseTexture&&this.diffuseTexture.dispose(),this._meshes)for(var t=1;t<this._meshes.length;t++){var r=this._meshes[t].material;r&&r.dispose(e),this._meshes[t].dispose()}i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.FurMaterial",this._meshes&&(t.sourceMeshName=this._meshes[0].name,t.quality=this._meshes.length),t},r.prototype.getClassName=function(){return"FurMaterial"},r.Parse=function(t,i,n){var o=e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n);return t.sourceMeshName&&o.highLevelFur&&i.executeWhenReady(function(){var e=i.getMeshByName(t.sourceMeshName);if(e){var n=r.GenerateTexture("Fur Texture",i);o.furTexture=n,r.FurifyMesh(e,t.quality)}}),o},r.GenerateTexture=function(t,i){for(var r=new e.DynamicTexture("FurTexture "+t,256,i,!0),n=r.getContext(),o=0;o<2e4;++o)n.fillStyle="rgba(255, "+Math.floor(255*Math.random())+", "+Math.floor(255*Math.random())+", 1)",n.fillRect(Math.random()*r.getSize().width,Math.random()*r.getSize().height,2,2);return r.update(!1),r.wrapU=e.Texture.WRAP_ADDRESSMODE,r.wrapV=e.Texture.WRAP_ADDRESSMODE,r},r.FurifyMesh=function(t,i){var n,o=[t],s=t.material;if(!(s instanceof r))throw"The material of the source mesh must be a Fur Material";for(n=1;n<i;n++){var a=new e.FurMaterial(s.name+n,t.getScene());t.getScene().materials.pop(),e.Tags.EnableFor(a),e.Tags.AddTagsTo(a,"furShellMaterial"),a.furLength=s.furLength,a.furAngle=s.furAngle,a.furGravity=s.furGravity,a.furSpacing=s.furSpacing,a.furSpeed=s.furSpeed,a.furColor=s.furColor,a.diffuseTexture=s.diffuseTexture,a.furOffset=n/i,a.furTexture=s.furTexture,a.highLevelFur=s.highLevelFur,a.furTime=s.furTime,a.furDensity=s.furDensity;var l=t.clone(t.name+n);l.material=a,l.skeleton=t.skeleton,l.position=e.Vector3.Zero(),o.push(l)}for(n=1;n<o.length;n++)o[n].parent=t;return t.material._meshes=o,o},o([e.serializeAsTexture("diffuseTexture")],r.prototype,"_diffuseTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture",void 0),o([e.serializeAsTexture("heightTexture")],r.prototype,"_heightTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"heightTexture",void 0),o([e.serializeAsColor3()],r.prototype,"diffuseColor",void 0),o([e.serialize()],r.prototype,"furLength",void 0),o([e.serialize()],r.prototype,"furAngle",void 0),o([e.serializeAsColor3()],r.prototype,"furColor",void 0),o([e.serialize()],r.prototype,"furOffset",void 0),o([e.serialize()],r.prototype,"furSpacing",void 0),o([e.serializeAsVector3()],r.prototype,"furGravity",void 0),o([e.serialize()],r.prototype,"furSpeed",void 0),o([e.serialize()],r.prototype,"furDensity",void 0),o([e.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),o([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),o([e.serialize()],r.prototype,"highLevelFur",void 0),o([e.serialize()],r.prototype,"furTime",null),r}(e.PushMaterial);e.FurMaterial=i}(n||(n={})),n.Effect.ShadersStore.furVertexShader="precision highp 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 float furLength;\nuniform float furAngle;\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform vec3 furGravity;\nuniform float furTime;\nuniform float furSpacing;\nuniform float furDensity;\n#endif\n#ifdef HEIGHTMAP\nuniform sampler2D heightTexture;\n#endif\n#ifdef HIGHLEVEL\nvarying vec2 vFurUV;\n#endif\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 POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\nvarying float vfur_length;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\n\nfloat r=Rand(position);\n#ifdef HEIGHTMAP\n#if __VERSION__>100\nvfur_length=furLength*texture(heightTexture,uv).x;\n#else\nvfur_length=furLength*texture2D(heightTexture,uv).r;\n#endif\n#else \nvfur_length=(furLength*r);\n#endif\nvec3 tangent1=vec3(normal.y,-normal.x,0);\nvec3 tangent2=vec3(-normal.z,0,normal.x);\nr=Rand(tangent1*r);\nfloat J=(2.0+4.0*r);\nr=Rand(tangent2*r);\nfloat K=(2.0+2.0*r);\ntangent1=tangent1*J+tangent2*K;\ntangent1=normalize(tangent1);\nvec3 newPosition=position+normal*vfur_length*cos(furAngle)+tangent1*vfur_length*sin(furAngle);\n#ifdef HIGHLEVEL\n\nvec3 forceDirection=vec3(0.0,0.0,0.0);\nforceDirection.x=sin(furTime+position.x*0.05)*0.2;\nforceDirection.y=cos(furTime*0.7+position.y*0.04)*0.2;\nforceDirection.z=sin(furTime*0.7+position.z*0.04)*0.2;\nvec3 displacement=vec3(0.0,0.0,0.0);\ndisplacement=furGravity+forceDirection;\nfloat displacementFactor=pow(furOffset,3.0);\nvec3 aNormal=normal;\naNormal.xyz+=displacement*displacementFactor;\nnewPosition=vec3(newPosition.x,newPosition.y,newPosition.z)+(normalize(aNormal)*furOffset*furSpacing);\n#endif\n#ifdef NORMAL\n#ifdef HIGHLEVEL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0))*aNormal);\n#else\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n#endif\n\ngl_Position=viewProjection*finalWorld*vec4(newPosition,1.0);\nvec4 worldPos=finalWorld*vec4(newPosition,1.0);\nvPositionW=vec3(worldPos);\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#ifdef HIGHLEVEL\nvFurUV=vDiffuseUV*furDensity;\n#endif\n#else\n#ifdef HIGHLEVEL\nvFurUV=uv*furDensity;\n#endif\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",n.Effect.ShadersStore.furPixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 furColor;\nuniform float furLength;\nvarying vec3 vPositionW;\nvarying float vfur_length;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform sampler2D furTexture;\nvarying vec2 vFurUV;\n#endif\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<fogFragmentDeclaration>\n#include<clipPlaneFragmentDeclaration>\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=furColor;\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor*=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef HIGHLEVEL\n\nvec4 furTextureColor=texture2D(furTexture,vec2(vFurUV.x,vFurUV.y));\nif (furTextureColor.a<=0.0 || furTextureColor.g<furOffset) {\ndiscard;\n}\nfloat occlusion=mix(0.0,furTextureColor.b*1.2,furOffset);\nbaseColor=vec4(baseColor.xyz*occlusion,1.1-furOffset);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase.rgb*baseColor.rgb,0.0,1.0);\n\n#ifdef HIGHLEVEL\nvec4 color=vec4(finalDiffuse,alpha);\n#else\nfloat r=vfur_length/furLength*0.5;\nvec4 color=vec4(finalDiffuse*(0.5+r),alpha);\n#endif\n#include<fogFragment>\ngl_FragColor=color;\n}";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.DIFFUSE=!1,t.BUMP=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.POINTSIZE=!1,t.FOG=!1,t.SPECULARTERM=!1,t.NORMAL=!1,t.UV1=!1,t.UV2=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.diffuseColor=new e.Color3(1,1,1),n.specularColor=new e.Color3(0,0,0),n.specularPower=64,n._disableLighting=!1,n._maxSimultaneousLights=4,n}return s(r,i),r.prototype.needAlphaBlending=function(){return this.alpha<1},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;var a=s.getEngine();if(s.texturesEnabled){if(this.mixTexture&&e.StandardMaterial.DiffuseTextureEnabled){if(!this.mixTexture.isReady())return!1;o._needUVs=!0,o.DIFFUSE=!0}(this.bumpTexture1||this.bumpTexture2||this.bumpTexture3)&&e.StandardMaterial.BumpTextureEnabled&&(o._needUVs=!0,o._needNormals=!0,o.BUMP=!0)}if(e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,o),o._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,o,!1,this._maxSimultaneousLights,this._disableLighting),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,a,o,!!n),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!0,!0),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var l=new e.EffectFallbacks;o.FOG&&l.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(o,l,this.maxSimultaneousLights),o.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,i);var h=[e.VertexBuffer.PositionKind];o.NORMAL&&h.push(e.VertexBuffer.NormalKind),o.UV1&&h.push(e.VertexBuffer.UVKind),o.UV2&&h.push(e.VertexBuffer.UV2Kind),o.VERTEXCOLOR&&h.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(h,i,o,l),e.MaterialHelper.PrepareAttributesForInstances(h,o);var u=o.toString(),c=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vSpecularColor","vFogInfos","vFogColor","pointSize","vTextureInfos","mBones","vClipPlane","textureMatrix","diffuse1Infos","diffuse2Infos","diffuse3Infos"],f=["textureSampler","diffuse1Sampler","diffuse2Sampler","diffuse3Sampler","bump1Sampler","bump2Sampler","bump3Sampler"],p=new Array;e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:o,maxSimultaneousLights:this.maxSimultaneousLights}),r.setEffect(s.getEngine().createEffect("terrain",{attributes:h,uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:u,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this.maxSimultaneousLights}},a),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;s&&(this._activeEffect=s,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._activeEffect),this._mustRebind(n,s)&&(this.mixTexture&&(this._activeEffect.setTexture("textureSampler",this._mixTexture),this._activeEffect.setFloat2("vTextureInfos",this._mixTexture.coordinatesIndex,this._mixTexture.level),this._activeEffect.setMatrix("textureMatrix",this._mixTexture.getTextureMatrix()),e.StandardMaterial.DiffuseTextureEnabled&&(this._diffuseTexture1&&(this._activeEffect.setTexture("diffuse1Sampler",this._diffuseTexture1),this._activeEffect.setFloat2("diffuse1Infos",this._diffuseTexture1.uScale,this._diffuseTexture1.vScale)),this._diffuseTexture2&&(this._activeEffect.setTexture("diffuse2Sampler",this._diffuseTexture2),this._activeEffect.setFloat2("diffuse2Infos",this._diffuseTexture2.uScale,this._diffuseTexture2.vScale)),this._diffuseTexture3&&(this._activeEffect.setTexture("diffuse3Sampler",this._diffuseTexture3),this._activeEffect.setFloat2("diffuse3Infos",this._diffuseTexture3.uScale,this._diffuseTexture3.vScale))),e.StandardMaterial.BumpTextureEnabled&&n.getEngine().getCaps().standardDerivatives&&(this._bumpTexture1&&this._activeEffect.setTexture("bump1Sampler",this._bumpTexture1),this._bumpTexture2&&this._activeEffect.setTexture("bump2Sampler",this._bumpTexture2),this._bumpTexture3&&this._activeEffect.setTexture("bump3Sampler",this._bumpTexture3))),e.MaterialHelper.BindClipPlane(this._activeEffect,n),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),e.MaterialHelper.BindEyePosition(s,n)),this._activeEffect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility),o.SPECULARTERM&&this._activeEffect.setColor4("vSpecularColor",this.specularColor,this.specularPower),n.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o,this.maxSimultaneousLights),n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._afterBind(i,this._activeEffect))}},r.prototype.getAnimatables=function(){var e=[];return this.mixTexture&&this.mixTexture.animations&&this.mixTexture.animations.length>0&&e.push(this.mixTexture),e},r.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._mixTexture&&e.push(this._mixTexture),this._diffuseTexture1&&e.push(this._diffuseTexture1),this._diffuseTexture2&&e.push(this._diffuseTexture2),this._diffuseTexture3&&e.push(this._diffuseTexture3),this._bumpTexture1&&e.push(this._bumpTexture1),this._bumpTexture2&&e.push(this._bumpTexture2),this._bumpTexture3&&e.push(this._bumpTexture3),e},r.prototype.hasTexture=function(e){return!!i.prototype.hasTexture.call(this,e)||this._mixTexture===e||this._diffuseTexture1===e||this._diffuseTexture2===e||this._diffuseTexture3===e||this._bumpTexture1===e||this._bumpTexture2===e||this._bumpTexture3===e},r.prototype.dispose=function(e){this.mixTexture&&this.mixTexture.dispose(),i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.TerrainMaterial",t},r.prototype.getClassName=function(){return"TerrainMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},o([e.serializeAsTexture("mixTexture")],r.prototype,"_mixTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"mixTexture",void 0),o([e.serializeAsTexture("diffuseTexture1")],r.prototype,"_diffuseTexture1",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture1",void 0),o([e.serializeAsTexture("diffuseTexture2")],r.prototype,"_diffuseTexture2",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture2",void 0),o([e.serializeAsTexture("diffuseTexture3")],r.prototype,"_diffuseTexture3",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture3",void 0),o([e.serializeAsTexture("bumpTexture1")],r.prototype,"_bumpTexture1",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"bumpTexture1",void 0),o([e.serializeAsTexture("bumpTexture2")],r.prototype,"_bumpTexture2",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"bumpTexture2",void 0),o([e.serializeAsTexture("bumpTexture3")],r.prototype,"_bumpTexture3",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"bumpTexture3",void 0),o([e.serializeAsColor3()],r.prototype,"diffuseColor",void 0),o([e.serializeAsColor3()],r.prototype,"specularColor",void 0),o([e.serialize()],r.prototype,"specularPower",void 0),o([e.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),o([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),r}(e.PushMaterial);e.TerrainMaterial=i}(n||(n={})),n.Effect.ShadersStore.terrainVertexShader="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 DIFFUSE\nvarying vec2 vTextureUV;\nuniform mat4 textureMatrix;\nuniform vec2 vTextureInfos;\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<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\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\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vTextureInfos.x == 0.)\n{\nvTextureUV=vec2(textureMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvTextureUV=vec2(textureMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",n.Effect.ShadersStore.terrainPixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\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<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform sampler2D textureSampler;\nuniform vec2 vTextureInfos;\nuniform sampler2D diffuse1Sampler;\nuniform sampler2D diffuse2Sampler;\nuniform sampler2D diffuse3Sampler;\nuniform vec2 diffuse1Infos;\nuniform vec2 diffuse2Infos;\nuniform vec2 diffuse3Infos;\n#endif\n#ifdef BUMP\nuniform sampler2D bump1Sampler;\nuniform sampler2D bump2Sampler;\nuniform sampler2D bump3Sampler;\n#endif\n\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n\n#ifdef BUMP\n#extension GL_OES_standard_derivatives : enable\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,vec3 mixColor)\n{ \nvec3 bump1Color=texture2D(bump1Sampler,vTextureUV*diffuse1Infos).xyz;\nvec3 bump2Color=texture2D(bump2Sampler,vTextureUV*diffuse2Infos).xyz;\nvec3 bump3Color=texture2D(bump3Sampler,vTextureUV*diffuse3Infos).xyz;\nbump1Color.rgb*=mixColor.r;\nbump2Color.rgb=mix(bump1Color.rgb,bump2Color.rgb,mixColor.g);\nvec3 map=mix(bump2Color.rgb,bump3Color.rgb,mixColor.b);\nmap=map*255./127.-128./127.;\nmat3 TBN=cotangent_frame(vNormalW*vTextureInfos.y,-viewDir,vTextureUV);\nreturn normalize(TBN*map);\n}\n#endif\nvoid main(void) {\n\n#ifdef CLIPPLANE\nif (fClipDistance>0.0)\ndiscard;\n#endif\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\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\nbaseColor=texture2D(textureSampler,vTextureUV);\n#if defined(BUMP) && defined(DIFFUSE)\nnormalW=perturbNormal(viewDirectionW,baseColor.rgb);\n#endif\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vTextureInfos.y;\nvec4 diffuse1Color=texture2D(diffuse1Sampler,vTextureUV*diffuse1Infos);\nvec4 diffuse2Color=texture2D(diffuse2Sampler,vTextureUV*diffuse2Infos);\nvec4 diffuse3Color=texture2D(diffuse3Sampler,vTextureUV*diffuse3Infos);\ndiffuse1Color.rgb*=baseColor.r;\ndiffuse2Color.rgb=mix(diffuse1Color.rgb,diffuse2Color.rgb,baseColor.g);\nbaseColor.rgb=mix(diffuse2Color.rgb,diffuse3Color.rgb,baseColor.b);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor*baseColor.rgb,0.0,1.0);\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.DIFFUSEX=!1,t.DIFFUSEY=!1,t.DIFFUSEZ=!1,t.BUMPX=!1,t.BUMPY=!1,t.BUMPZ=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.POINTSIZE=!1,t.FOG=!1,t.SPECULARTERM=!1,t.NORMAL=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.tileSize=1,n.diffuseColor=new e.Color3(1,1,1),n.specularColor=new e.Color3(.2,.2,.2),n.specularPower=64,n._disableLighting=!1,n._maxSimultaneousLights=4,n}return s(r,i),r.prototype.needAlphaBlending=function(){return this.alpha<1},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;var a=s.getEngine();if(o._areTexturesDirty&&s.texturesEnabled){if(e.StandardMaterial.DiffuseTextureEnabled)for(var l=[this.diffuseTextureX,this.diffuseTextureY,this.diffuseTextureZ],h=["DIFFUSEX","DIFFUSEY","DIFFUSEZ"],u=0;u<l.length;u++)if(l[u]){if(!l[u].isReady())return!1;o[h[u]]=!0}if(e.StandardMaterial.BumpTextureEnabled)for(var l=[this.normalTextureX,this.normalTextureY,this.normalTextureZ],h=["BUMPX","BUMPY","BUMPZ"],u=0;u<l.length;u++)if(l[u]){if(!l[u].isReady())return!1;o[h[u]]=!0}}if(e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,o),o._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,o,!1,this._maxSimultaneousLights,this._disableLighting),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,a,o,!!n),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!0,!0),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var c=new e.EffectFallbacks;o.FOG&&c.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(o,c,this.maxSimultaneousLights),o.NUM_BONE_INFLUENCERS>0&&c.addCPUSkinningFallback(0,i);var f=[e.VertexBuffer.PositionKind];o.NORMAL&&f.push(e.VertexBuffer.NormalKind),o.VERTEXCOLOR&&f.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(f,i,o,c),e.MaterialHelper.PrepareAttributesForInstances(f,o);var p=o.toString(),d=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vSpecularColor","vFogInfos","vFogColor","pointSize","mBones","vClipPlane","tileSize"],m=["diffuseSamplerX","diffuseSamplerY","diffuseSamplerZ","normalSamplerX","normalSamplerY","normalSamplerZ"],g=new Array;e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:d,uniformBuffersNames:g,samplers:m,defines:o,maxSimultaneousLights:this.maxSimultaneousLights}),r.setEffect(s.getEngine().createEffect("triplanar",{attributes:f,uniformsNames:d,uniformBuffersNames:g,samplers:m,defines:p,fallbacks:c,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this.maxSimultaneousLights}},a),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;s&&(this._activeEffect=s,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._activeEffect),this._activeEffect.setFloat("tileSize",this.tileSize),n.getCachedMaterial()!==this&&(this.diffuseTextureX&&this._activeEffect.setTexture("diffuseSamplerX",this.diffuseTextureX),this.diffuseTextureY&&this._activeEffect.setTexture("diffuseSamplerY",this.diffuseTextureY),this.diffuseTextureZ&&this._activeEffect.setTexture("diffuseSamplerZ",this.diffuseTextureZ),this.normalTextureX&&this._activeEffect.setTexture("normalSamplerX",this.normalTextureX),this.normalTextureY&&this._activeEffect.setTexture("normalSamplerY",this.normalTextureY),this.normalTextureZ&&this._activeEffect.setTexture("normalSamplerZ",this.normalTextureZ),e.MaterialHelper.BindClipPlane(this._activeEffect,n),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),e.MaterialHelper.BindEyePosition(s,n)),this._activeEffect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility),o.SPECULARTERM&&this._activeEffect.setColor4("vSpecularColor",this.specularColor,this.specularPower),n.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o,this.maxSimultaneousLights),n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._afterBind(i,this._activeEffect))}},r.prototype.getAnimatables=function(){var e=[];return this.mixTexture&&this.mixTexture.animations&&this.mixTexture.animations.length>0&&e.push(this.mixTexture),e},r.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._diffuseTextureX&&e.push(this._diffuseTextureX),this._diffuseTextureY&&e.push(this._diffuseTextureY),this._diffuseTextureZ&&e.push(this._diffuseTextureZ),this._normalTextureX&&e.push(this._normalTextureX),this._normalTextureY&&e.push(this._normalTextureY),this._normalTextureZ&&e.push(this._normalTextureZ),e},r.prototype.hasTexture=function(e){return!!i.prototype.hasTexture.call(this,e)||this._diffuseTextureX===e||this._diffuseTextureY===e||this._diffuseTextureZ===e||this._normalTextureX===e||this._normalTextureY===e||this._normalTextureZ===e},r.prototype.dispose=function(e){this.mixTexture&&this.mixTexture.dispose(),i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.TriPlanarMaterial",t},r.prototype.getClassName=function(){return"TriPlanarMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},o([e.serializeAsTexture()],r.prototype,"mixTexture",void 0),o([e.serializeAsTexture("diffuseTextureX")],r.prototype,"_diffuseTextureX",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTextureX",void 0),o([e.serializeAsTexture("diffuseTexturY")],r.prototype,"_diffuseTextureY",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTextureY",void 0),o([e.serializeAsTexture("diffuseTextureZ")],r.prototype,"_diffuseTextureZ",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTextureZ",void 0),o([e.serializeAsTexture("normalTextureX")],r.prototype,"_normalTextureX",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"normalTextureX",void 0),o([e.serializeAsTexture("normalTextureY")],r.prototype,"_normalTextureY",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"normalTextureY",void 0),o([e.serializeAsTexture("normalTextureZ")],r.prototype,"_normalTextureZ",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"normalTextureZ",void 0),o([e.serialize()],r.prototype,"tileSize",void 0),o([e.serializeAsColor3()],r.prototype,"diffuseColor",void 0),o([e.serializeAsColor3()],r.prototype,"specularColor",void 0),o([e.serialize()],r.prototype,"specularPower",void 0),o([e.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),o([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),r}(e.PushMaterial);e.TriPlanarMaterial=i}(n||(n={})),n.Effect.ShadersStore.triplanarVertexShader="precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\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 DIFFUSEX\nvarying vec2 vTextureUVX;\n#endif\n#ifdef DIFFUSEY\nvarying vec2 vTextureUVY;\n#endif\n#ifdef DIFFUSEZ\nvarying vec2 vTextureUVZ;\n#endif\nuniform float tileSize;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying mat3 tangentSpace;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void)\n{\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 DIFFUSEX\nvTextureUVX=worldPos.zy/tileSize;\n#endif\n#ifdef DIFFUSEY\nvTextureUVY=worldPos.xz/tileSize;\n#endif\n#ifdef DIFFUSEZ\nvTextureUVZ=worldPos.xy/tileSize;\n#endif\n#ifdef NORMAL\n\nvec3 xtan=vec3(0,0,1);\nvec3 xbin=vec3(0,1,0);\nvec3 ytan=vec3(1,0,0);\nvec3 ybin=vec3(0,0,1);\nvec3 ztan=vec3(1,0,0);\nvec3 zbin=vec3(0,1,0);\nvec3 normalizedNormal=normalize(normal);\nnormalizedNormal*=normalizedNormal;\nvec3 worldBinormal=normalize(xbin*normalizedNormal.x+ybin*normalizedNormal.y+zbin*normalizedNormal.z);\nvec3 worldTangent=normalize(xtan*normalizedNormal.x+ytan*normalizedNormal.y+ztan*normalizedNormal.z);\nworldTangent=(world*vec4(worldTangent,1.0)).xyz;\nworldBinormal=(world*vec4(worldBinormal,1.0)).xyz;\nvec3 worldNormal=normalize(cross(worldTangent,worldBinormal));\ntangentSpace[0]=worldTangent;\ntangentSpace[1]=worldBinormal;\ntangentSpace[2]=worldNormal;\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",n.Effect.ShadersStore.triplanarPixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSEX\nvarying vec2 vTextureUVX;\nuniform sampler2D diffuseSamplerX;\n#ifdef BUMPX\nuniform sampler2D normalSamplerX;\n#endif\n#endif\n#ifdef DIFFUSEY\nvarying vec2 vTextureUVY;\nuniform sampler2D diffuseSamplerY;\n#ifdef BUMPY\nuniform sampler2D normalSamplerY;\n#endif\n#endif\n#ifdef DIFFUSEZ\nvarying vec2 vTextureUVZ;\nuniform sampler2D diffuseSamplerZ;\n#ifdef BUMPZ\nuniform sampler2D normalSamplerZ;\n#endif\n#endif\n#ifdef NORMAL\nvarying mat3 tangentSpace;\n#endif\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<fogFragmentDeclaration>\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(0.,0.,0.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=tangentSpace[2];\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\nvec4 baseNormal=vec4(0.0,0.0,0.0,1.0);\nnormalW*=normalW;\n#ifdef DIFFUSEX\nbaseColor+=texture2D(diffuseSamplerX,vTextureUVX)*normalW.x;\n#ifdef BUMPX\nbaseNormal+=texture2D(normalSamplerX,vTextureUVX)*normalW.x;\n#endif\n#endif\n#ifdef DIFFUSEY\nbaseColor+=texture2D(diffuseSamplerY,vTextureUVY)*normalW.y;\n#ifdef BUMPY\nbaseNormal+=texture2D(normalSamplerY,vTextureUVY)*normalW.y;\n#endif\n#endif\n#ifdef DIFFUSEZ\nbaseColor+=texture2D(diffuseSamplerZ,vTextureUVZ)*normalW.z;\n#ifdef BUMPZ\nbaseNormal+=texture2D(normalSamplerZ,vTextureUVZ)*normalW.z;\n#endif\n#endif\n#ifdef NORMAL\nnormalW=normalize((2.0*baseNormal.xyz-1.0)*tangentSpace);\n#endif\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.CLIPPLANE=!1,t.POINTSIZE=!1,t.FOG=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.luminance=1,n.turbidity=10,n.rayleigh=2,n.mieCoefficient=.005,n.mieDirectionalG=.8,n.distance=500,n.inclination=.49,n.azimuth=.25,n.sunPosition=new e.Vector3(0,100,0),n.useSunPosition=!1,n._cameraPosition=e.Vector3.Zero(),n}return s(r,i),r.prototype.needAlphaBlending=function(){return this.alpha<1},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;if(e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,o),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!0,!1),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var a=new e.EffectFallbacks;o.FOG&&a.addFallback(1,"FOG");var l=[e.VertexBuffer.PositionKind];o.VERTEXCOLOR&&l.push(e.VertexBuffer.ColorKind);var h=o.toString();r.setEffect(s.getEngine().createEffect("sky",l,["world","viewProjection","view","vFogInfos","vFogColor","pointSize","vClipPlane","luminance","turbidity","rayleigh","mieCoefficient","mieDirectionalG","sunPosition","cameraPosition"],[],h,a,this.onCompiled,this.onError),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene();if(r._materialDefines){var o=r.effect;if(o){if(this._activeEffect=o,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),this._mustRebind(n,o)){if(n.clipPlane){var s=n.clipPlane;this._activeEffect.setFloat4("vClipPlane",s.normal.x,s.normal.y,s.normal.z,s.d)}this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize)}n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect);var a=n.activeCamera;if(a){var l=a.getWorldMatrix();this._cameraPosition.x=l.m[12],this._cameraPosition.y=l.m[13],this._cameraPosition.z=l.m[14],this._activeEffect.setVector3("cameraPosition",this._cameraPosition)}if(this.luminance>0&&this._activeEffect.setFloat("luminance",this.luminance),this._activeEffect.setFloat("turbidity",this.turbidity),this._activeEffect.setFloat("rayleigh",this.rayleigh),this._activeEffect.setFloat("mieCoefficient",this.mieCoefficient),this._activeEffect.setFloat("mieDirectionalG",this.mieDirectionalG),!this.useSunPosition){var h=Math.PI*(this.inclination-.5),u=2*Math.PI*(this.azimuth-.5);this.sunPosition.x=this.distance*Math.cos(u),this.sunPosition.y=this.distance*Math.sin(u)*Math.sin(h),this.sunPosition.z=this.distance*Math.sin(u)*Math.cos(h)}this._activeEffect.setVector3("sunPosition",this.sunPosition),this._afterBind(i,this._activeEffect)}}},r.prototype.getAnimatables=function(){return[]},r.prototype.dispose=function(e){i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.SkyMaterial",t},r.prototype.getClassName=function(){return"SkyMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},o([e.serialize()],r.prototype,"luminance",void 0),o([e.serialize()],r.prototype,"turbidity",void 0),o([e.serialize()],r.prototype,"rayleigh",void 0),o([e.serialize()],r.prototype,"mieCoefficient",void 0),o([e.serialize()],r.prototype,"mieDirectionalG",void 0),o([e.serialize()],r.prototype,"distance",void 0),o([e.serialize()],r.prototype,"inclination",void 0),o([e.serialize()],r.prototype,"azimuth",void 0),o([e.serializeAsVector3()],r.prototype,"sunPosition",void 0),o([e.serialize()],r.prototype,"useSunPosition",void 0),r}(e.PushMaterial);e.SkyMaterial=i}(n||(n={})),n.Effect.ShadersStore.skyVertexShader="precision highp float;\n\nattribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\nvoid main(void) {\ngl_Position=viewProjection*world*vec4(position,1.0);\nvec4 worldPos=world*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",n.Effect.ShadersStore.skyPixelShader="precision highp float;\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\nuniform vec3 cameraPosition;\nuniform float luminance;\nuniform float turbidity;\nuniform float rayleigh;\nuniform float mieCoefficient;\nuniform float mieDirectionalG;\nuniform vec3 sunPosition;\n\n#include<fogFragmentDeclaration>\n\nconst float e=2.71828182845904523536028747135266249775724709369995957;\nconst float pi=3.141592653589793238462643383279502884197169;\nconst float n=1.0003;\nconst float N=2.545E25;\nconst float pn=0.035;\nconst vec3 lambda=vec3(680E-9,550E-9,450E-9);\nconst vec3 K=vec3(0.686,0.678,0.666);\nconst float v=4.0;\nconst float rayleighZenithLength=8.4E3;\nconst float mieZenithLength=1.25E3;\nconst vec3 up=vec3(0.0,1.0,0.0);\nconst float EE=1000.0;\nconst float sunAngularDiameterCos=0.999956676946448443553574619906976478926848692873900859324;\nconst float cutoffAngle=pi/1.95;\nconst float steepness=1.5;\nvec3 totalRayleigh(vec3 lambda)\n{\nreturn (8.0*pow(pi,3.0)*pow(pow(n,2.0)-1.0,2.0)*(6.0+3.0*pn))/(3.0*N*pow(lambda,vec3(4.0))*(6.0-7.0*pn));\n}\nvec3 simplifiedRayleigh()\n{\nreturn 0.0005/vec3(94,40,18);\n}\nfloat rayleighPhase(float cosTheta)\n{ \nreturn (3.0/(16.0*pi))*(1.0+pow(cosTheta,2.0));\n}\nvec3 totalMie(vec3 lambda,vec3 K,float T)\n{\nfloat c=(0.2*T )*10E-18;\nreturn 0.434*c*pi*pow((2.0*pi)/lambda,vec3(v-2.0))*K;\n}\nfloat hgPhase(float cosTheta,float g)\n{\nreturn (1.0/(4.0*pi))*((1.0-pow(g,2.0))/pow(1.0-2.0*g*cosTheta+pow(g,2.0),1.5));\n}\nfloat sunIntensity(float zenithAngleCos)\n{\nreturn EE*max(0.0,1.0-exp(-((cutoffAngle-acos(zenithAngleCos))/steepness)));\n}\nfloat A=0.15;\nfloat B=0.50;\nfloat C=0.10;\nfloat D=0.20;\nfloat EEE=0.02;\nfloat F=0.30;\nfloat W=1000.0;\nvec3 Uncharted2Tonemap(vec3 x)\n{\nreturn ((x*(A*x+C*B)+D*EEE)/(x*(A*x+B)+D*F))-EEE/F;\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\n\nfloat sunfade=1.0-clamp(1.0-exp((sunPosition.y/450000.0)),0.0,1.0);\nfloat rayleighCoefficient=rayleigh-(1.0*(1.0-sunfade));\nvec3 sunDirection=normalize(sunPosition);\nfloat sunE=sunIntensity(dot(sunDirection,up));\nvec3 betaR=simplifiedRayleigh()*rayleighCoefficient;\nvec3 betaM=totalMie(lambda,K,turbidity)*mieCoefficient;\nfloat zenithAngle=acos(max(0.0,dot(up,normalize(vPositionW-cameraPosition))));\nfloat sR=rayleighZenithLength/(cos(zenithAngle)+0.15*pow(93.885-((zenithAngle*180.0)/pi),-1.253));\nfloat sM=mieZenithLength/(cos(zenithAngle)+0.15*pow(93.885-((zenithAngle*180.0)/pi),-1.253));\nvec3 Fex=exp(-(betaR*sR+betaM*sM));\nfloat cosTheta=dot(normalize(vPositionW-cameraPosition),sunDirection);\nfloat rPhase=rayleighPhase(cosTheta*0.5+0.5);\nvec3 betaRTheta=betaR*rPhase;\nfloat mPhase=hgPhase(cosTheta,mieDirectionalG);\nvec3 betaMTheta=betaM*mPhase;\nvec3 Lin=pow(sunE*((betaRTheta+betaMTheta)/(betaR+betaM))*(1.0-Fex),vec3(1.5));\nLin*=mix(vec3(1.0),pow(sunE*((betaRTheta+betaMTheta)/(betaR+betaM))*Fex,vec3(1.0/2.0)),clamp(pow(1.0-dot(up,sunDirection),5.0),0.0,1.0));\nvec3 direction=normalize(vPositionW-cameraPosition);\nfloat theta=acos(direction.y);\nfloat phi=atan(direction.z,direction.x);\nvec2 uv=vec2(phi,theta)/vec2(2.0*pi,pi)+vec2(0.5,0.0);\nvec3 L0=vec3(0.1)*Fex;\nfloat sundisk=smoothstep(sunAngularDiameterCos,sunAngularDiameterCos+0.00002,cosTheta);\nL0+=(sunE*19000.0*Fex)*sundisk;\nvec3 whiteScale=1.0/Uncharted2Tonemap(vec3(W));\nvec3 texColor=(Lin+L0); \ntexColor*=0.04 ;\ntexColor+=vec3(0.0,0.001,0.0025)*0.3;\nfloat g_fMaxLuminance=1.0;\nfloat fLumScaled=0.1/luminance; \nfloat fLumCompressed=(fLumScaled*(1.0+(fLumScaled/(g_fMaxLuminance*g_fMaxLuminance))))/(1.0+fLumScaled); \nfloat ExposureBias=fLumCompressed;\nvec3 curr=Uncharted2Tonemap((log2(2.0/pow(luminance,4.0)))*texColor);\n\n\n\nvec3 retColor=curr*whiteScale;\n\n\nfloat alpha=1.0;\n#ifdef VERTEXCOLOR\nretColor.rgb*=vColor.rgb;\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n\nvec4 color=clamp(vec4(retColor.rgb,alpha),0.0,1.0);\n\n#include<fogFragment>\ngl_FragColor=color;\n}";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.TRANSPARENT=!1,t.FOG=!1,t.PREMULTIPLYALPHA=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.mainColor=e.Color3.Black(),n.lineColor=e.Color3.Teal(),n.gridRatio=1,n.gridOffset=e.Vector3.Zero(),n.majorUnitFrequency=10,n.minorUnitVisibility=.33,n.opacity=1,n.preMultiplyAlpha=!1,n._gridControl=new e.Vector4(n.gridRatio,n.majorUnitFrequency,n.minorUnitVisibility,n.opacity),n}return s(r,i),r.prototype.needAlphaBlending=function(){return this.opacity<1},r.prototype.needAlphaBlendingForMesh=function(e){return this.needAlphaBlending()},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;if(o.TRANSPARENT!==this.opacity<1&&(o.TRANSPARENT=!o.TRANSPARENT,o.markAsUnprocessed()),o.PREMULTIPLYALPHA!=this.preMultiplyAlpha&&(o.PREMULTIPLYALPHA=!o.PREMULTIPLYALPHA,o.markAsUnprocessed()),e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,!1,this.fogEnabled,o),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var a=[e.VertexBuffer.PositionKind,e.VertexBuffer.NormalKind],l=o.toString();r.setEffect(s.getEngine().createEffect("grid",a,["projection","worldView","mainColor","lineColor","gridControl","gridOffset","vFogInfos","vFogColor","world","view"],[],l,void 0,this.onCompiled,this.onError),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene();if(r._materialDefines){var o=r.effect;o&&(this._activeEffect=o,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("worldView",t.multiply(n.getViewMatrix())),this._activeEffect.setMatrix("view",n.getViewMatrix()),this._activeEffect.setMatrix("projection",n.getProjectionMatrix()),this._mustRebind(n,o)&&(this._activeEffect.setColor3("mainColor",this.mainColor),this._activeEffect.setColor3("lineColor",this.lineColor),this._activeEffect.setVector3("gridOffset",this.gridOffset),this._gridControl.x=this.gridRatio,this._gridControl.y=Math.round(this.majorUnitFrequency),this._gridControl.z=this.minorUnitVisibility,this._gridControl.w=this.opacity,this._activeEffect.setVector4("gridControl",this._gridControl)),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._afterBind(i,this._activeEffect))}},r.prototype.dispose=function(e){i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.GridMaterial",t},r.prototype.getClassName=function(){return"GridMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},o([e.serializeAsColor3()],r.prototype,"mainColor",void 0),o([e.serializeAsColor3()],r.prototype,"lineColor",void 0),o([e.serialize()],r.prototype,"gridRatio",void 0),o([e.serializeAsColor3()],r.prototype,"gridOffset",void 0),o([e.serialize()],r.prototype,"majorUnitFrequency",void 0),o([e.serialize()],r.prototype,"minorUnitVisibility",void 0),o([e.serialize()],r.prototype,"opacity",void 0),o([e.serialize()],r.prototype,"preMultiplyAlpha",void 0),r}(e.PushMaterial);e.GridMaterial=i}(n||(n={})),n.Effect.ShadersStore.gridVertexShader="precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\n\nuniform mat4 projection;\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 worldView;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include<fogVertexDeclaration>\nvoid main(void) {\n#ifdef FOG\nvec4 worldPos=world*vec4(position,1.0);\n#endif\n#include<fogVertex>\nvec4 cameraSpacePosition=worldView*vec4(position,1.0);\ngl_Position=projection*cameraSpacePosition;\n#ifdef TRANSPARENT\nvCameraSpacePosition=cameraSpacePosition;\n#endif\nvPosition=position;\nvNormal=normal;\n}",n.Effect.ShadersStore.gridPixelShader="#extension GL_OES_standard_derivatives : enable\n#define SQRT2 1.41421356\n#define PI 3.14159\nprecision highp float;\nuniform vec3 mainColor;\nuniform vec3 lineColor;\nuniform vec4 gridControl;\nuniform vec3 gridOffset;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include<fogFragmentDeclaration>\nfloat getVisibility(float position) {\n\nfloat majorGridFrequency=gridControl.y;\nif (floor(position+0.5) == floor(position/majorGridFrequency+0.5)*majorGridFrequency)\n{\nreturn 1.0;\n} \nreturn gridControl.z;\n}\nfloat getAnisotropicAttenuation(float differentialLength) {\nconst float maxNumberOfLines=10.0;\nreturn clamp(1.0/(differentialLength+1.0)-1.0/maxNumberOfLines,0.0,1.0);\n}\nfloat isPointOnLine(float position,float differentialLength) {\nfloat fractionPartOfPosition=position-floor(position+0.5); \nfractionPartOfPosition/=differentialLength; \nfractionPartOfPosition=clamp(fractionPartOfPosition,-1.,1.);\nfloat result=0.5+0.5*cos(fractionPartOfPosition*PI); \nreturn result; \n}\nfloat contributionOnAxis(float position) {\nfloat differentialLength=length(vec2(dFdx(position),dFdy(position)));\ndifferentialLength*=SQRT2; \n\nfloat result=isPointOnLine(position,differentialLength);\n\nfloat visibility=getVisibility(position);\nresult*=visibility;\n\nfloat anisotropicAttenuation=getAnisotropicAttenuation(differentialLength);\nresult*=anisotropicAttenuation;\nreturn result;\n}\nfloat normalImpactOnAxis(float x) {\nfloat normalImpact=clamp(1.0-3.0*abs(x*x*x),0.0,1.0);\nreturn normalImpact;\n}\nvoid main(void) {\n\nfloat gridRatio=gridControl.x;\nvec3 gridPos=(vPosition+gridOffset)/gridRatio;\n\nfloat x=contributionOnAxis(gridPos.x);\nfloat y=contributionOnAxis(gridPos.y);\nfloat z=contributionOnAxis(gridPos.z);\n\nvec3 normal=normalize(vNormal);\nx*=normalImpactOnAxis(normal.x);\ny*=normalImpactOnAxis(normal.y);\nz*=normalImpactOnAxis(normal.z);\n\nfloat grid=clamp(x+y+z,0.,1.);\n\nvec3 color=mix(mainColor,lineColor,grid);\n#ifdef FOG\n#include<fogFragment>\n#endif\n#ifdef TRANSPARENT\nfloat distanceToFragment=length(vCameraSpacePosition.xyz);\nfloat cameraPassThrough=clamp(distanceToFragment-0.25,0.0,1.0);\nfloat opacity=clamp(grid,0.08,cameraPassThrough*gridControl.w*grid);\ngl_FragColor=vec4(color.rgb,opacity);\n#ifdef PREMULTIPLYALPHA\ngl_FragColor.rgb*=opacity;\n#endif\n#else\n\ngl_FragColor=vec4(color.rgb,1.0);\n#endif\n}";!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.DIFFUSE=!1,t.AMBIENT=!1,t.OPACITY=!1,t.OPACITYRGB=!1,t.REFLECTION=!1,t.EMISSIVE=!1,t.SPECULAR=!1,t.BUMP=!1,t.PARALLAX=!1,t.PARALLAXOCCLUSION=!1,t.SPECULAROVERALPHA=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.ALPHAFROMDIFFUSE=!1,t.POINTSIZE=!1,t.FOG=!1,t.SPECULARTERM=!1,t.DIFFUSEFRESNEL=!1,t.OPACITYFRESNEL=!1,t.REFLECTIONFRESNEL=!1,t.REFRACTIONFRESNEL=!1,t.EMISSIVEFRESNEL=!1,t.FRESNEL=!1,t.NORMAL=!1,t.UV1=!1,t.UV2=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.GLOSSINESS=!1,t.ROUGHNESS=!1,t.EMISSIVEASILLUMINATION=!1,t.LINKEMISSIVEWITHDIFFUSE=!1,t.REFLECTIONFRESNELFROMSPECULAR=!1,t.LIGHTMAP=!1,t.USELIGHTMAPASSHADOWMAP=!1,t.REFLECTIONMAP_3D=!1,t.REFLECTIONMAP_SPHERICAL=!1,t.REFLECTIONMAP_PLANAR=!1,t.REFLECTIONMAP_CUBIC=!1,t.REFLECTIONMAP_PROJECTION=!1,t.REFLECTIONMAP_SKYBOX=!1,t.REFLECTIONMAP_EXPLICIT=!1,t.REFLECTIONMAP_EQUIRECTANGULAR=!1,t.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!1,t.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!1,t.INVERTCUBICMAP=!1,t.LOGARITHMICDEPTH=!1,t.REFRACTION=!1,t.REFRACTIONMAP_3D=!1,t.REFLECTIONOVERALPHA=!1,t.TWOSIDEDLIGHTING=!1,t.SHADOWFLOAT=!1,t.MORPHTARGETS=!1,t.MORPHTARGETS_NORMAL=!1,t.MORPHTARGETS_TANGENT=!1,t.NUM_MORPH_INFLUENCERS=0,t.IMAGEPROCESSING=!1,t.VIGNETTE=!1,t.VIGNETTEBLENDMODEMULTIPLY=!1,t.VIGNETTEBLENDMODEOPAQUE=!1,t.TONEMAPPING=!1,t.CONTRAST=!1,t.COLORCURVES=!1,t.COLORGRADING=!1,t.COLORGRADING3D=!1,t.SAMPLER3DGREENDEPTH=!1,t.SAMPLER3DBGRMAP=!1,t.IMAGEPROCESSINGPOSTPROCESS=!1,t.EXPOSURE=!1,t.rebuild(),t}return s(t,e),t.prototype.setReflectionMode=function(e){for(var t=0,i=["REFLECTIONMAP_CUBIC","REFLECTIONMAP_EXPLICIT","REFLECTIONMAP_PLANAR","REFLECTIONMAP_PROJECTION","REFLECTIONMAP_PROJECTION","REFLECTIONMAP_SKYBOX","REFLECTIONMAP_SPHERICAL","REFLECTIONMAP_EQUIRECTANGULAR","REFLECTIONMAP_EQUIRECTANGULAR_FIXED","REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED"];t<i.length;t++){var r=i[t];this[r]=r===e}},t}(e.MaterialDefines);e.StandardMaterialDefines_OldVer=t;var i=function(i){function r(t,n){var o=i.call(this,t,n)||this;return o.ambientColor=new e.Color3(0,0,0),o.diffuseColor=new e.Color3(1,1,1),o.specularColor=new e.Color3(1,1,1),o.emissiveColor=new e.Color3(0,0,0),o.specularPower=64,o._useAlphaFromDiffuseTexture=!1,o._useEmissiveAsIllumination=!1,o._linkEmissiveWithDiffuse=!1,o._useSpecularOverAlpha=!1,o._useReflectionOverAlpha=!1,o._disableLighting=!1,o._useParallax=!1,o._useParallaxOcclusion=!1,o.parallaxScaleBias=.05,o._roughness=0,o.indexOfRefraction=.98,o.invertRefractionY=!0,o._useLightmapAsShadowmap=!1,o._useReflectionFresnelFromSpecular=!1,o._useGlossinessFromSpecularMapAlpha=!1,o._maxSimultaneousLights=4,o._invertNormalMapX=!1,o._invertNormalMapY=!1,o._twoSidedLighting=!1,o._renderTargets=new e.SmartArray(16),o._worldViewProjectionMatrix=e.Matrix.Zero(),o._globalAmbientColor=new e.Color3(0,0,0),o._attachImageProcessingConfiguration(null),o.getRenderTargetTextures=function(){return o._renderTargets.reset(),r.ReflectionTextureEnabled&&o._reflectionTexture&&o._reflectionTexture.isRenderTarget&&o._renderTargets.push(o._reflectionTexture),r.RefractionTextureEnabled&&o._refractionTexture&&o._refractionTexture.isRenderTarget&&o._renderTargets.push(o._refractionTexture),o._renderTargets},o}return s(r,i),Object.defineProperty(r.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},set:function(e){this._attachImageProcessingConfiguration(e),this._markAllSubMeshesAsTexturesDirty()},enumerable:!0,configurable:!0}),r.prototype._attachImageProcessingConfiguration=function(e){var t=this;e!==this._imageProcessingConfiguration&&(this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),this._imageProcessingConfiguration=e||this.getScene().imageProcessingConfiguration,this._imageProcessingObserver=this._imageProcessingConfiguration.onUpdateParameters.add(function(e){t._markAllSubMeshesAsImageProcessingDirty()}))},Object.defineProperty(r.prototype,"cameraColorCurvesEnabled",{get:function(){return this.imageProcessingConfiguration.colorCurvesEnabled},set:function(e){this.imageProcessingConfiguration.colorCurvesEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"cameraColorGradingEnabled",{get:function(){return this.imageProcessingConfiguration.colorGradingEnabled},set:function(e){this.imageProcessingConfiguration.colorGradingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"cameraToneMappingEnabled",{get:function(){return this._imageProcessingConfiguration.toneMappingEnabled},set:function(e){this._imageProcessingConfiguration.toneMappingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"cameraExposure",{get:function(){return this._imageProcessingConfiguration.exposure},set:function(e){this._imageProcessingConfiguration.exposure=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"cameraContrast",{get:function(){return this._imageProcessingConfiguration.contrast},set:function(e){this._imageProcessingConfiguration.contrast=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"cameraColorGradingTexture",{get:function(){return this._imageProcessingConfiguration.colorGradingTexture},set:function(e){this._imageProcessingConfiguration.colorGradingTexture=e},enumerable:!0,configurable:!0}),r.prototype.getClassName=function(){return"StandardMaterial_OldVer"},Object.defineProperty(r.prototype,"useLogarithmicDepth",{get:function(){return this._useLogarithmicDepth},set:function(e){this._useLogarithmicDepth=e&&this.getScene().getEngine().getCaps().fragmentDepthSupported,this._markAllSubMeshesAsMiscDirty()},enumerable:!0,configurable:!0}),r.prototype.needAlphaBlending=function(){return this.alpha<1||null!=this._opacityTexture||this._shouldUseAlphaFromDiffuseTexture()||this._opacityFresnelParameters&&this._opacityFresnelParameters.isEnabled},r.prototype.needAlphaTesting=function(){return null!=this._diffuseTexture&&this._diffuseTexture.hasAlpha},r.prototype._shouldUseAlphaFromDiffuseTexture=function(){return null!=this._diffuseTexture&&this._diffuseTexture.hasAlpha&&this._useAlphaFromDiffuseTexture},r.prototype.getAlphaTestTexture=function(){return this._diffuseTexture},r.prototype.isReadyForSubMesh=function(i,n,o){if(this.isFrozen&&this._wasPreviouslyReady&&n.effect)return!0;n._materialDefines||(n._materialDefines=new t);var s=this.getScene(),a=n._materialDefines;if(!this.checkReadyOnEveryCall&&n.effect&&a._renderId===s.getRenderId())return!0;var l=s.getEngine();if(a._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,a,!0,this._maxSimultaneousLights,this._disableLighting),a._areTexturesDirty){if(a._needUVs=!1,s.texturesEnabled){if(this._diffuseTexture&&r.DiffuseTextureEnabled){if(!this._diffuseTexture.isReadyOrNotBlocking())return!1;a._needUVs=!0,a.DIFFUSE=!0}else a.DIFFUSE=!1;if(this._ambientTexture&&r.AmbientTextureEnabled){if(!this._ambientTexture.isReadyOrNotBlocking())return!1;a._needUVs=!0,a.AMBIENT=!0}else a.AMBIENT=!1;if(this._opacityTexture&&r.OpacityTextureEnabled){if(!this._opacityTexture.isReadyOrNotBlocking())return!1;a._needUVs=!0,a.OPACITY=!0,a.OPACITYRGB=this._opacityTexture.getAlphaFromRGB}else a.OPACITY=!1;if(this._reflectionTexture&&r.ReflectionTextureEnabled){if(!this._reflectionTexture.isReadyOrNotBlocking())return!1;switch(a._needNormals=!0,a.REFLECTION=!0,a.ROUGHNESS=this._roughness>0,a.REFLECTIONOVERALPHA=this._useReflectionOverAlpha,a.INVERTCUBICMAP=this._reflectionTexture.coordinatesMode===e.Texture.INVCUBIC_MODE,a.REFLECTIONMAP_3D=this._reflectionTexture.isCube,this._reflectionTexture.coordinatesMode){case e.Texture.CUBIC_MODE:case e.Texture.INVCUBIC_MODE:a.setReflectionMode("REFLECTIONMAP_CUBIC");break;case e.Texture.EXPLICIT_MODE:a.setReflectionMode("REFLECTIONMAP_EXPLICIT");break;case e.Texture.PLANAR_MODE:a.setReflectionMode("REFLECTIONMAP_PLANAR");break;case e.Texture.PROJECTION_MODE:a.setReflectionMode("REFLECTIONMAP_PROJECTION");break;case e.Texture.SKYBOX_MODE:a.setReflectionMode("REFLECTIONMAP_SKYBOX");break;case e.Texture.SPHERICAL_MODE:a.setReflectionMode("REFLECTIONMAP_SPHERICAL");break;case e.Texture.EQUIRECTANGULAR_MODE:a.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR");break;case e.Texture.FIXED_EQUIRECTANGULAR_MODE:a.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR_FIXED");break;case e.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:a.setReflectionMode("REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED")}}else a.REFLECTION=!1;if(this._emissiveTexture&&r.EmissiveTextureEnabled){if(!this._emissiveTexture.isReadyOrNotBlocking())return!1;a._needUVs=!0,a.EMISSIVE=!0}else a.EMISSIVE=!1;if(this._lightmapTexture&&r.LightmapTextureEnabled){if(!this._lightmapTexture.isReadyOrNotBlocking())return!1;a._needUVs=!0,a.LIGHTMAP=!0,a.USELIGHTMAPASSHADOWMAP=this._useLightmapAsShadowmap}else a.LIGHTMAP=!1;if(this._specularTexture&&r.SpecularTextureEnabled){if(!this._specularTexture.isReadyOrNotBlocking())return!1;a._needUVs=!0,a.SPECULAR=!0,a.GLOSSINESS=this._useGlossinessFromSpecularMapAlpha}else a.SPECULAR=!1;if(s.getEngine().getCaps().standardDerivatives&&this._bumpTexture&&r.BumpTextureEnabled){if(!this._bumpTexture.isReady())return!1;a._needUVs=!0,a.BUMP=!0,a.PARALLAX=this._useParallax,a.PARALLAXOCCLUSION=this._useParallaxOcclusion}else a.BUMP=!1;if(this._refractionTexture&&r.RefractionTextureEnabled){if(!this._refractionTexture.isReadyOrNotBlocking())return!1;a._needUVs=!0,a.REFRACTION=!0,a.REFRACTIONMAP_3D=this._refractionTexture.isCube}else a.REFRACTION=!1;a.TWOSIDEDLIGHTING=!this._backFaceCulling&&this._twoSidedLighting}else a.DIFFUSE=!1,a.AMBIENT=!1,a.OPACITY=!1,a.REFLECTION=!1,a.EMISSIVE=!1,a.LIGHTMAP=!1,a.BUMP=!1,a.REFRACTION=!1;a.ALPHAFROMDIFFUSE=this._shouldUseAlphaFromDiffuseTexture(),a.EMISSIVEASILLUMINATION=this._useEmissiveAsIllumination,a.LINKEMISSIVEWITHDIFFUSE=this._linkEmissiveWithDiffuse,a.SPECULAROVERALPHA=this._useSpecularOverAlpha}if(a._areImageProcessingDirty){if(!this._imageProcessingConfiguration.isReady())return!1;this._imageProcessingConfiguration.prepareDefines(a)}if(a._areFresnelDirty&&(r.FresnelEnabled?(this._diffuseFresnelParameters||this._opacityFresnelParameters||this._emissiveFresnelParameters||this._refractionFresnelParameters||this._reflectionFresnelParameters)&&(a.DIFFUSEFRESNEL=this._diffuseFresnelParameters&&this._diffuseFresnelParameters.isEnabled,a.OPACITYFRESNEL=this._opacityFresnelParameters&&this._opacityFresnelParameters.isEnabled,a.REFLECTIONFRESNEL=this._reflectionFresnelParameters&&this._reflectionFresnelParameters.isEnabled,a.REFLECTIONFRESNELFROMSPECULAR=this._useReflectionFresnelFromSpecular,a.REFRACTIONFRESNEL=this._refractionFresnelParameters&&this._refractionFresnelParameters.isEnabled,a.EMISSIVEFRESNEL=this._emissiveFresnelParameters&&this._emissiveFresnelParameters.isEnabled,a._needNormals=!0,a.FRESNEL=!0):a.FRESNEL=!1),e.MaterialHelper.PrepareDefinesForMisc(i,s,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,a),e.MaterialHelper.PrepareDefinesForAttributes(i,a,!0,!0,!0),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,l,a,!!o),a.isDirty){a.markAsProcessed(),s.resetCachedMaterial();var h=new e.EffectFallbacks;a.REFLECTION&&h.addFallback(0,"REFLECTION"),a.SPECULAR&&h.addFallback(0,"SPECULAR"),a.BUMP&&h.addFallback(0,"BUMP"),a.PARALLAX&&h.addFallback(1,"PARALLAX"),a.PARALLAXOCCLUSION&&h.addFallback(0,"PARALLAXOCCLUSION"),a.SPECULAROVERALPHA&&h.addFallback(0,"SPECULAROVERALPHA"),a.FOG&&h.addFallback(1,"FOG"),a.POINTSIZE&&h.addFallback(0,"POINTSIZE"),a.LOGARITHMICDEPTH&&h.addFallback(0,"LOGARITHMICDEPTH"),e.MaterialHelper.HandleFallbacksForShadows(a,h,this._maxSimultaneousLights),a.SPECULARTERM&&h.addFallback(0,"SPECULARTERM"),a.DIFFUSEFRESNEL&&h.addFallback(1,"DIFFUSEFRESNEL"),a.OPACITYFRESNEL&&h.addFallback(2,"OPACITYFRESNEL"),a.REFLECTIONFRESNEL&&h.addFallback(3,"REFLECTIONFRESNEL"),a.EMISSIVEFRESNEL&&h.addFallback(4,"EMISSIVEFRESNEL"),a.FRESNEL&&h.addFallback(4,"FRESNEL");var u=[e.VertexBuffer.PositionKind];a.NORMAL&&u.push(e.VertexBuffer.NormalKind),a.UV1&&u.push(e.VertexBuffer.UVKind),a.UV2&&u.push(e.VertexBuffer.UV2Kind),a.VERTEXCOLOR&&u.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(u,i,a,h),e.MaterialHelper.PrepareAttributesForInstances(u,a),e.MaterialHelper.PrepareAttributesForMorphTargets(u,i,a);var c="default",f=["world","view","viewProjection","vEyePosition","vLightsType","vAmbientColor","vDiffuseColor","vSpecularColor","vEmissiveColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","vAmbientInfos","vOpacityInfos","vReflectionInfos","vEmissiveInfos","vSpecularInfos","vBumpInfos","vLightmapInfos","vRefractionInfos","mBones","vClipPlane","diffuseMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","specularMatrix","bumpMatrix","lightmapMatrix","refractionMatrix","diffuseLeftColor","diffuseRightColor","opacityParts","reflectionLeftColor","reflectionRightColor","emissiveLeftColor","emissiveRightColor","refractionLeftColor","refractionRightColor","logarithmicDepthConstant","vTangentSpaceParams"],p=["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","lightmapSampler","refractionCubeSampler","refraction2DSampler"],d=["Material","Scene"];e.ImageProcessingConfiguration.PrepareUniforms(f,a),e.ImageProcessingConfiguration.PrepareSamplers(p,a),e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:f,uniformBuffersNames:d,samplers:p,defines:a,maxSimultaneousLights:this._maxSimultaneousLights}),this.customShaderNameResolve&&(c=this.customShaderNameResolve(c,f,d,p,a));var m=a.toString();n.setEffect(s.getEngine().createEffect(c,{attributes:u,uniformsNames:f,uniformBuffersNames:d,samplers:p,defines:m,fallbacks:h,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights,maxSimultaneousMorphTargets:a.NUM_MORPH_INFLUENCERS}},l),a),this.buildUniformLayout()}return!(!n.effect||!n.effect.isReady()||(a._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.buildUniformLayout=function(){this._uniformBuffer.addUniform("diffuseLeftColor",4),this._uniformBuffer.addUniform("diffuseRightColor",4),this._uniformBuffer.addUniform("opacityParts",4),this._uniformBuffer.addUniform("reflectionLeftColor",4),this._uniformBuffer.addUniform("reflectionRightColor",4),this._uniformBuffer.addUniform("refractionLeftColor",4),this._uniformBuffer.addUniform("refractionRightColor",4),this._uniformBuffer.addUniform("emissiveLeftColor",4),this._uniformBuffer.addUniform("emissiveRightColor",4),this._uniformBuffer.addUniform("vDiffuseInfos",2),this._uniformBuffer.addUniform("vAmbientInfos",2),this._uniformBuffer.addUniform("vOpacityInfos",2),this._uniformBuffer.addUniform("vReflectionInfos",2),this._uniformBuffer.addUniform("vEmissiveInfos",2),this._uniformBuffer.addUniform("vLightmapInfos",2),this._uniformBuffer.addUniform("vSpecularInfos",2),this._uniformBuffer.addUniform("vBumpInfos",3),this._uniformBuffer.addUniform("diffuseMatrix",16),this._uniformBuffer.addUniform("ambientMatrix",16),this._uniformBuffer.addUniform("opacityMatrix",16),this._uniformBuffer.addUniform("reflectionMatrix",16),this._uniformBuffer.addUniform("emissiveMatrix",16),this._uniformBuffer.addUniform("lightmapMatrix",16),this._uniformBuffer.addUniform("specularMatrix",16),this._uniformBuffer.addUniform("bumpMatrix",16),this._uniformBuffer.addUniform("vTangentSpaceParams",2),this._uniformBuffer.addUniform("refractionMatrix",16),this._uniformBuffer.addUniform("vRefractionInfos",4),this._uniformBuffer.addUniform("vSpecularColor",4),this._uniformBuffer.addUniform("vEmissiveColor",3),this._uniformBuffer.addUniform("vDiffuseColor",4),this._uniformBuffer.addUniform("pointSize",1),this._uniformBuffer.create()},r.prototype.unbind=function(){this._activeEffect&&(this._reflectionTexture&&this._reflectionTexture.isRenderTarget&&this._activeEffect.setTexture("reflection2DSampler",null),this._refractionTexture&&this._refractionTexture.isRenderTarget&&this._activeEffect.setTexture("refraction2DSampler",null)),i.prototype.unbind.call(this)},r.prototype.bindForSubMesh=function(t,i,n){var o=this.getScene(),s=n._materialDefines;if(s){var a=n.effect;if(a){if(this._activeEffect=a,this.bindOnlyWorldMatrix(t),e.MaterialHelper.BindBonesParameters(i,a),this._mustRebind(o,a,i.visibility)){if(this._uniformBuffer.bindToEffect(a,"Material"),this.bindViewProjection(a),!this._uniformBuffer.useUbo||!this.isFrozen||!this._uniformBuffer.isSync){if(r.FresnelEnabled&&s.FRESNEL&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("diffuseLeftColor",this.diffuseFresnelParameters.leftColor,this.diffuseFresnelParameters.power),this._uniformBuffer.updateColor4("diffuseRightColor",this.diffuseFresnelParameters.rightColor,this.diffuseFresnelParameters.bias)),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&this._uniformBuffer.updateColor4("opacityParts",new e.Color3(this.opacityFresnelParameters.leftColor.toLuminance(),this.opacityFresnelParameters.rightColor.toLuminance(),this.opacityFresnelParameters.bias),this.opacityFresnelParameters.power),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("reflectionLeftColor",this.reflectionFresnelParameters.leftColor,this.reflectionFresnelParameters.power),this._uniformBuffer.updateColor4("reflectionRightColor",this.reflectionFresnelParameters.rightColor,this.reflectionFresnelParameters.bias)),this.refractionFresnelParameters&&this.refractionFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("refractionLeftColor",this.refractionFresnelParameters.leftColor,this.refractionFresnelParameters.power),this._uniformBuffer.updateColor4("refractionRightColor",this.refractionFresnelParameters.rightColor,this.refractionFresnelParameters.bias)),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("emissiveLeftColor",this.emissiveFresnelParameters.leftColor,this.emissiveFresnelParameters.power),this._uniformBuffer.updateColor4("emissiveRightColor",this.emissiveFresnelParameters.rightColor,this.emissiveFresnelParameters.bias))),o.texturesEnabled&&(this._diffuseTexture&&r.DiffuseTextureEnabled&&(this._uniformBuffer.updateFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),this._uniformBuffer.updateMatrix("diffuseMatrix",this._diffuseTexture.getTextureMatrix())),this._ambientTexture&&r.AmbientTextureEnabled&&(this._uniformBuffer.updateFloat2("vAmbientInfos",this._ambientTexture.coordinatesIndex,this._ambientTexture.level),this._uniformBuffer.updateMatrix("ambientMatrix",this._ambientTexture.getTextureMatrix())),this._opacityTexture&&r.OpacityTextureEnabled&&(this._uniformBuffer.updateFloat2("vOpacityInfos",this._opacityTexture.coordinatesIndex,this._opacityTexture.level),this._uniformBuffer.updateMatrix("opacityMatrix",this._opacityTexture.getTextureMatrix())),this._reflectionTexture&&r.ReflectionTextureEnabled&&(this._uniformBuffer.updateFloat2("vReflectionInfos",this._reflectionTexture.level,this.roughness),this._uniformBuffer.updateMatrix("reflectionMatrix",this._reflectionTexture.getReflectionTextureMatrix())),this._emissiveTexture&&r.EmissiveTextureEnabled&&(this._uniformBuffer.updateFloat2("vEmissiveInfos",this._emissiveTexture.coordinatesIndex,this._emissiveTexture.level),this._uniformBuffer.updateMatrix("emissiveMatrix",this._emissiveTexture.getTextureMatrix())),this._lightmapTexture&&r.LightmapTextureEnabled&&(this._uniformBuffer.updateFloat2("vLightmapInfos",this._lightmapTexture.coordinatesIndex,this._lightmapTexture.level),this._uniformBuffer.updateMatrix("lightmapMatrix",this._lightmapTexture.getTextureMatrix())),this._specularTexture&&r.SpecularTextureEnabled&&(this._uniformBuffer.updateFloat2("vSpecularInfos",this._specularTexture.coordinatesIndex,this._specularTexture.level),this._uniformBuffer.updateMatrix("specularMatrix",this._specularTexture.getTextureMatrix())),this._bumpTexture&&o.getEngine().getCaps().standardDerivatives&&r.BumpTextureEnabled&&(this._uniformBuffer.updateFloat3("vBumpInfos",this._bumpTexture.coordinatesIndex,1/this._bumpTexture.level,this.parallaxScaleBias),this._uniformBuffer.updateMatrix("bumpMatrix",this._bumpTexture.getTextureMatrix()),o._mirroredCameraPosition?this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?1:-1,this._invertNormalMapY?1:-1):this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?-1:1,this._invertNormalMapY?-1:1)),this._refractionTexture&&r.RefractionTextureEnabled)){l=1;this._refractionTexture.isCube||(this._uniformBuffer.updateMatrix("refractionMatrix",this._refractionTexture.getReflectionTextureMatrix()),this._refractionTexture.depth&&(l=this._refractionTexture.depth)),this._uniformBuffer.updateFloat4("vRefractionInfos",this._refractionTexture.level,this.indexOfRefraction,l,this.invertRefractionY?-1:1)}this.pointsCloud&&this._uniformBuffer.updateFloat("pointSize",this.pointSize),s.SPECULARTERM&&this._uniformBuffer.updateColor4("vSpecularColor",this.specularColor,this.specularPower),this._uniformBuffer.updateColor3("vEmissiveColor",this.emissiveColor),this._uniformBuffer.updateColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility)}if(o.texturesEnabled&&(this._diffuseTexture&&r.DiffuseTextureEnabled&&a.setTexture("diffuseSampler",this._diffuseTexture),this._ambientTexture&&r.AmbientTextureEnabled&&a.setTexture("ambientSampler",this._ambientTexture),this._opacityTexture&&r.OpacityTextureEnabled&&a.setTexture("opacitySampler",this._opacityTexture),this._reflectionTexture&&r.ReflectionTextureEnabled&&(this._reflectionTexture.isCube?a.setTexture("reflectionCubeSampler",this._reflectionTexture):a.setTexture("reflection2DSampler",this._reflectionTexture)),this._emissiveTexture&&r.EmissiveTextureEnabled&&a.setTexture("emissiveSampler",this._emissiveTexture),this._lightmapTexture&&r.LightmapTextureEnabled&&a.setTexture("lightmapSampler",this._lightmapTexture),this._specularTexture&&r.SpecularTextureEnabled&&a.setTexture("specularSampler",this._specularTexture),this._bumpTexture&&o.getEngine().getCaps().standardDerivatives&&r.BumpTextureEnabled&&a.setTexture("bumpSampler",this._bumpTexture),this._refractionTexture&&r.RefractionTextureEnabled)){var l=1;this._refractionTexture.isCube?a.setTexture("refractionCubeSampler",this._refractionTexture):a.setTexture("refraction2DSampler",this._refractionTexture)}e.MaterialHelper.BindClipPlane(a,o),o.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor),e.MaterialHelper.BindEyePosition(a,o),a.setColor3("vAmbientColor",this._globalAmbientColor)}!this._mustRebind(o,a)&&this.isFrozen||(o.lightsEnabled&&!this._disableLighting&&e.MaterialHelper.BindLights(o,i,a,s,this._maxSimultaneousLights),(o.fogEnabled&&i.applyFog&&o.fogMode!==e.Scene.FOGMODE_NONE||this._reflectionTexture||this._refractionTexture)&&this.bindView(a),e.MaterialHelper.BindFogParameters(o,i,a),s.NUM_MORPH_INFLUENCERS&&e.MaterialHelper.BindMorphTargetParameters(i,a),e.MaterialHelper.BindLogDepth(s,a,o),this._imageProcessingConfiguration.bind(this._activeEffect)),this._uniformBuffer.update(),this._afterBind(i,this._activeEffect)}}},r.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},r.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._diffuseTexture&&e.push(this._diffuseTexture),this._ambientTexture&&e.push(this._ambientTexture),this._opacityTexture&&e.push(this._opacityTexture),this._reflectionTexture&&e.push(this._reflectionTexture),this._emissiveTexture&&e.push(this._emissiveTexture),this._specularTexture&&e.push(this._specularTexture),this._bumpTexture&&e.push(this._bumpTexture),this._lightmapTexture&&e.push(this._lightmapTexture),this._refractionTexture&&e.push(this._refractionTexture),e},r.prototype.dispose=function(e,t){t&&(this._diffuseTexture&&this._diffuseTexture.dispose(),this._ambientTexture&&this._ambientTexture.dispose(),this._opacityTexture&&this._opacityTexture.dispose(),this._reflectionTexture&&this._reflectionTexture.dispose(),this._emissiveTexture&&this._emissiveTexture.dispose(),this._specularTexture&&this._specularTexture.dispose(),this._bumpTexture&&this._bumpTexture.dispose(),this._lightmapTexture&&this._lightmapTexture.dispose(),this._refractionTexture&&this._refractionTexture.dispose()),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),i.prototype.dispose.call(this,e,t)},r.prototype.clone=function(t){var i=this,n=e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this);return n.name=t,n.id=t,n},r.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},Object.defineProperty(r,"DiffuseTextureEnabled",{get:function(){return r._DiffuseTextureEnabled},set:function(t){r._DiffuseTextureEnabled!==t&&(r._DiffuseTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"AmbientTextureEnabled",{get:function(){return r._AmbientTextureEnabled},set:function(t){r._AmbientTextureEnabled!==t&&(r._AmbientTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"OpacityTextureEnabled",{get:function(){return r._OpacityTextureEnabled},set:function(t){r._OpacityTextureEnabled!==t&&(r._OpacityTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ReflectionTextureEnabled",{get:function(){return r._ReflectionTextureEnabled},set:function(t){r._ReflectionTextureEnabled!==t&&(r._ReflectionTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"EmissiveTextureEnabled",{get:function(){return r._EmissiveTextureEnabled},set:function(t){r._EmissiveTextureEnabled!==t&&(r._EmissiveTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"SpecularTextureEnabled",{get:function(){return r._SpecularTextureEnabled},set:function(t){r._SpecularTextureEnabled!==t&&(r._SpecularTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BumpTextureEnabled",{get:function(){return r._BumpTextureEnabled},set:function(t){r._BumpTextureEnabled!==t&&(r._BumpTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"LightmapTextureEnabled",{get:function(){return r._LightmapTextureEnabled},set:function(t){r._LightmapTextureEnabled!==t&&(r._LightmapTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"RefractionTextureEnabled",{get:function(){return r._RefractionTextureEnabled},set:function(t){r._RefractionTextureEnabled!==t&&(r._RefractionTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ColorGradingTextureEnabled",{get:function(){return r._ColorGradingTextureEnabled},set:function(t){r._ColorGradingTextureEnabled!==t&&(r._ColorGradingTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"FresnelEnabled",{get:function(){return r._FresnelEnabled},set:function(t){r._FresnelEnabled!==t&&(r._FresnelEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.FresnelDirtyFlag))},enumerable:!0,configurable:!0}),r._DiffuseTextureEnabled=!0,r._AmbientTextureEnabled=!0,r._OpacityTextureEnabled=!0,r._ReflectionTextureEnabled=!0,r._EmissiveTextureEnabled=!0,r._SpecularTextureEnabled=!0,r._BumpTextureEnabled=!0,r._LightmapTextureEnabled=!0,r._RefractionTextureEnabled=!0,r._ColorGradingTextureEnabled=!0,r._FresnelEnabled=!0,o([e.serializeAsTexture("diffuseTexture")],r.prototype,"_diffuseTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture",void 0),o([e.serializeAsTexture("ambientTexture")],r.prototype,"_ambientTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"ambientTexture",void 0),o([e.serializeAsTexture("opacityTexture")],r.prototype,"_opacityTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"opacityTexture",void 0),o([e.serializeAsTexture("reflectionTexture")],r.prototype,"_reflectionTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"reflectionTexture",void 0),o([e.serializeAsTexture("emissiveTexture")],r.prototype,"_emissiveTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"emissiveTexture",void 0),o([e.serializeAsTexture("specularTexture")],r.prototype,"_specularTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"specularTexture",void 0),o([e.serializeAsTexture("bumpTexture")],r.prototype,"_bumpTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"bumpTexture",void 0),o([e.serializeAsTexture("lightmapTexture")],r.prototype,"_lightmapTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"lightmapTexture",void 0),o([e.serializeAsTexture("refractionTexture")],r.prototype,"_refractionTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"refractionTexture",void 0),o([e.serializeAsColor3("ambient")],r.prototype,"ambientColor",void 0),o([e.serializeAsColor3("diffuse")],r.prototype,"diffuseColor",void 0),o([e.serializeAsColor3("specular")],r.prototype,"specularColor",void 0),o([e.serializeAsColor3("emissive")],r.prototype,"emissiveColor",void 0),o([e.serialize()],r.prototype,"specularPower",void 0),o([e.serialize("useAlphaFromDiffuseTexture")],r.prototype,"_useAlphaFromDiffuseTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useAlphaFromDiffuseTexture",void 0),o([e.serialize("useEmissiveAsIllumination")],r.prototype,"_useEmissiveAsIllumination",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useEmissiveAsIllumination",void 0),o([e.serialize("linkEmissiveWithDiffuse")],r.prototype,"_linkEmissiveWithDiffuse",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"linkEmissiveWithDiffuse",void 0),o([e.serialize("useSpecularOverAlpha")],r.prototype,"_useSpecularOverAlpha",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useSpecularOverAlpha",void 0),o([e.serialize("useReflectionOverAlpha")],r.prototype,"_useReflectionOverAlpha",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useReflectionOverAlpha",void 0),o([e.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),o([e.serialize("useParallax")],r.prototype,"_useParallax",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useParallax",void 0),o([e.serialize("useParallaxOcclusion")],r.prototype,"_useParallaxOcclusion",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useParallaxOcclusion",void 0),o([e.serialize()],r.prototype,"parallaxScaleBias",void 0),o([e.serialize("roughness")],r.prototype,"_roughness",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"roughness",void 0),o([e.serialize()],r.prototype,"indexOfRefraction",void 0),o([e.serialize()],r.prototype,"invertRefractionY",void 0),o([e.serialize("useLightmapAsShadowmap")],r.prototype,"_useLightmapAsShadowmap",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useLightmapAsShadowmap",void 0),o([e.serializeAsFresnelParameters("diffuseFresnelParameters")],r.prototype,"_diffuseFresnelParameters",void 0),o([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"diffuseFresnelParameters",void 0),o([e.serializeAsFresnelParameters("opacityFresnelParameters")],r.prototype,"_opacityFresnelParameters",void 0),o([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"opacityFresnelParameters",void 0),o([e.serializeAsFresnelParameters("reflectionFresnelParameters")],r.prototype,"_reflectionFresnelParameters",void 0),o([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"reflectionFresnelParameters",void 0),o([e.serializeAsFresnelParameters("refractionFresnelParameters")],r.prototype,"_refractionFresnelParameters",void 0),o([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"refractionFresnelParameters",void 0),o([e.serializeAsFresnelParameters("emissiveFresnelParameters")],r.prototype,"_emissiveFresnelParameters",void 0),o([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"emissiveFresnelParameters",void 0),o([e.serialize("useReflectionFresnelFromSpecular")],r.prototype,"_useReflectionFresnelFromSpecular",void 0),o([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"useReflectionFresnelFromSpecular",void 0),o([e.serialize("useGlossinessFromSpecularMapAlpha")],r.prototype,"_useGlossinessFromSpecularMapAlpha",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useGlossinessFromSpecularMapAlpha",void 0),o([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),o([e.serialize("invertNormalMapX")],r.prototype,"_invertNormalMapX",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"invertNormalMapX",void 0),o([e.serialize("invertNormalMapY")],r.prototype,"_invertNormalMapY",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"invertNormalMapY",void 0),o([e.serialize("twoSidedLighting")],r.prototype,"_twoSidedLighting",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"twoSidedLighting",void 0),o([e.serialize()],r.prototype,"useLogarithmicDepth",null),r}(e.PushMaterial);e.StandardMaterial_OldVer=i;var r=function(){return function(){}}();e.CustomShaderStructure=r;var n=function(){return function(){}}();e.ShaderSpecialParts=n;var a=function(e){function t(){var t=e.call(this)||this;return t.VertexStore="",t.FragmentStore="#include<__decl__defaultFragment>\n#[Fragment_Begin]\n#extension GL_OES_standard_derivatives : enable\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;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW_helper;\nvarying vec3 localNormal;\nvarying vec3 localPosition;\nvec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nvarying vec2 vSpecularUV;\nuniform sampler2D specularSampler;\n#endif\n\n#include<fresnelFunction>\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#include<imageProcessingDeclaration>\n#include<imageProcessingFunctions>\n\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\n\n#[Fragment_Definitions]\n\nvoid main(void) {\n\nvNormalW = vNormalW_helper;\n#[Fragment_MainBegin]\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n#[Fragment_Custom_Diffuse]\n\nfloat alpha=vDiffuseColor.a;\n#[Fragment_Custom_Alpha]\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#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\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+uvOffset).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+uvOffset);\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#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\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+uvOffset);\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+uvOffset).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#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\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\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor;\n#else\ncolor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n#include<logDepthFragment>\n#include<fogFragment>\n\n// Apply image processing if relevant. As this applies in linear space, \n// We first move from gamma to linear.\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n\tcolor.rgb = toLinearSpace(color.rgb);\n#else\n\t#ifdef IMAGEPROCESSING\n\t\tcolor.rgb = toLinearSpace(color.rgb);\n\t\tcolor = applyImageProcessing(color);\n\t#endif\n#endif\n\n#[Fragment_Before_FragColor]\ngl_FragColor=color;\n}",t.VertexStore="#include<__decl__defaultVertex>\n\n#[Vertex_Begin]\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\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>\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nvarying vec2 vSpecularUV;\n#endif\n#ifdef BUMP\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 localPosition;\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW_helper;\nvarying vec3 localNormal;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\n\n#[Vertex_Definitions]\n\nvoid main(void) {\n \n #[Vertex_MainBegin]\n \nvec3 positionUpdated=position;\n#ifdef NORMAL \nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\n\nlocalPosition = positionUpdated;\n#[Vertex_Before_PositionUpdated]\n\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\n\n#[Vertex_Before_NormalUpdated]\n\nlocalNormal = normalUpdated;\nvNormalW_helper=normalize(vec3(finalWorld*vec4(normalUpdated,0.0)));\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,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<bumpVertex>\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include<pointCloudVertex>\n#include<logDepthVertex>\n}",t}return s(t,e),t}(r);e.ShaderForVer3_0=a;var l=function(){function e(){}return e.Ver3_0="3.0.0",e}();e.StandardShaderVersions=l;var h=function(t){function i(e,i){var r=t.call(this,e,i)||this;return r.CustomParts=new n,r.customShaderNameResolve=r.Builder,r.SelectVersion("3.0.0"),r}return s(i,t),i.prototype.AttachAfterBind=function(e,t){for(var i in this._newUniformInstances)"vec2"==(r=i.toString().split("-"))[0]?t.setVector2(r[1],this._newUniformInstances[i]):"vec3"==r[0]?t.setVector3(r[1],this._newUniformInstances[i]):"vec4"==r[0]?t.setVector4(r[1],this._newUniformInstances[i]):"mat4"==r[0]?t.setMatrix(r[1],this._newUniformInstances[i]):"float"==r[0]&&t.setFloat(r[1],this._newUniformInstances[i]);for(var i in this._newSamplerInstances){var r=i.toString().split("-");"sampler2D"==r[0]&&this._newSamplerInstances[i].isReady&&this._newSamplerInstances[i].isReady()&&t.setTexture(r[1],this._newSamplerInstances[i])}},i.prototype.ReviewUniform=function(e,t){if("uniform"==e)for(var i in this._newUniforms)-1==this._customUniform[i].indexOf("sampler")&&t.push(this._newUniforms[i]);if("sampler"==e)for(var i in this._newUniforms)-1!=this._customUniform[i].indexOf("sampler")&&t.push(this._newUniforms[i]);return t},i.prototype.Builder=function(t,r,n,o,s){var a=this;if(this._isCreatedShader)return this._createdShaderName;this._isCreatedShader=!1;var l="custom_"+ ++i.ShaderIndexer;this.ReviewUniform("uniform",r),this.ReviewUniform("sampler",o);var h=this._afterBind;return this._afterBind=function(e,t){if(t){a.AttachAfterBind(e,t);try{h(e,t)}catch(t){}}},e.Effect.ShadersStore[l+"VertexShader"]=this.ShaderVersion.VertexStore.replace("#[Vertex_Begin]",this.CustomParts.Vertex_Begin?this.CustomParts.Vertex_Begin:"").replace("#[Vertex_Definitions]",(this._customUniform?this._customUniform.join("\n"):"")+(this.CustomParts.Vertex_Definitions?this.CustomParts.Vertex_Definitions:"")).replace("#[Vertex_MainBegin]",this.CustomParts.Vertex_MainBegin?this.CustomParts.Vertex_MainBegin:"").replace("#[Vertex_Before_PositionUpdated]",this.CustomParts.Vertex_Before_PositionUpdated?this.CustomParts.Vertex_Before_PositionUpdated:"").replace("#[Vertex_Before_NormalUpdated]",this.CustomParts.Vertex_Before_NormalUpdated?this.CustomParts.Vertex_Before_NormalUpdated:""),e.Effect.ShadersStore[l+"PixelShader"]=this.ShaderVersion.FragmentStore.replace("#[Fragment_Begin]",this.CustomParts.Fragment_Begin?this.CustomParts.Fragment_Begin:"").replace("#[Fragment_MainBegin]",this.CustomParts.Fragment_MainBegin?this.CustomParts.Fragment_MainBegin:"").replace("#[Fragment_Definitions]",(this._customUniform?this._customUniform.join("\n"):"")+(this.CustomParts.Fragment_Definitions?this.CustomParts.Fragment_Definitions:"")).replace("#[Fragment_Custom_Diffuse]",this.CustomParts.Fragment_Custom_Diffuse?this.CustomParts.Fragment_Custom_Diffuse:"").replace("#[Fragment_Custom_Alpha]",this.CustomParts.Fragment_Custom_Alpha?this.CustomParts.Fragment_Custom_Alpha:"").replace("#[Fragment_Before_FragColor]",this.CustomParts.Fragment_Before_FragColor?this.CustomParts.Fragment_Before_FragColor:""),this._isCreatedShader=!0,this._createdShaderName=l,l},i.prototype.SelectVersion=function(e){switch(e){case"3.0.0":this.ShaderVersion=new a}},i.prototype.AddUniform=function(e,t,i){return this._customUniform||(this._customUniform=new Array,this._newUniforms=new Array,this._newSamplerInstances=new Array,this._newUniformInstances=new Array),i&&(t.indexOf("sampler"),this._newUniformInstances[t+"-"+e]=i),this._customUniform.push("uniform "+t+" "+e+";"),this._newUniforms.push(e),this},i.prototype.Fragment_Begin=function(e){return this.CustomParts.Fragment_Begin=e,this},i.prototype.Fragment_Definitions=function(e){return this.CustomParts.Fragment_Definitions=e,this},i.prototype.Fragment_MainBegin=function(e){return this.CustomParts.Fragment_MainBegin=e,this},i.prototype.Fragment_Custom_Diffuse=function(e){return this.CustomParts.Fragment_Custom_Diffuse=e.replace("result","diffuseColor"),this},i.prototype.Fragment_Custom_Alpha=function(e){return this.CustomParts.Fragment_Custom_Alpha=e.replace("result","alpha"),this},i.prototype.Fragment_Before_FragColor=function(e){return this.CustomParts.Fragment_Before_FragColor=e.replace("result","color"),this},i.prototype.Vertex_Begin=function(e){return this.CustomParts.Vertex_Begin=e,this},i.prototype.Vertex_Definitions=function(e){return this.CustomParts.Vertex_Definitions=e,this},i.prototype.Vertex_MainBegin=function(e){return this.CustomParts.Vertex_MainBegin=e,this},i.prototype.Vertex_Before_PositionUpdated=function(e){return this.CustomParts.Vertex_Before_PositionUpdated=e.replace("result","positionUpdated"),this},i.prototype.Vertex_Before_NormalUpdated=function(e){return this.CustomParts.Vertex_Before_NormalUpdated=e.replace("result","normalUpdated"),this},i.ShaderIndexer=1,i}(i);e.CustomMaterial=h}(n||(n={}));!function(e){var t=function(e){function t(){var t=e.call(this)||this;return t.DIFFUSE=!1,t.CLIPPLANE=!1,t.ALPHATEST=!1,t.POINTSIZE=!1,t.FOG=!1,t.NORMAL=!1,t.UV1=!1,t.UV2=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.NDOTL=!0,t.CUSTOMUSERLIGHTING=!0,t.CELLBASIC=!0,t.DEPTHPREPASS=!1,t.rebuild(),t}return s(t,e),t}(e.MaterialDefines),i=function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.diffuseColor=new e.Color3(1,1,1),n._computeHighLevel=!1,n._disableLighting=!1,n._maxSimultaneousLights=4,n}return s(r,i),r.prototype.needAlphaBlending=function(){return this.alpha<1},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;var a=s.getEngine();if(o._areTexturesDirty&&(o._needUVs=!1,s.texturesEnabled&&this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled)){if(!this._diffuseTexture.isReady())return!1;o._needUVs=!0,o.DIFFUSE=!0}if(o.CELLBASIC=!this.computeHighLevel,e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,o),o._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,o,!1,this._maxSimultaneousLights,this._disableLighting),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,a,o,!!n),e.MaterialHelper.PrepareDefinesForAttributes(i,o,!0,!0),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var l=new e.EffectFallbacks;o.FOG&&l.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(o,l,this.maxSimultaneousLights),o.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,i);var h=[e.VertexBuffer.PositionKind];o.NORMAL&&h.push(e.VertexBuffer.NormalKind),o.UV1&&h.push(e.VertexBuffer.UVKind),o.UV2&&h.push(e.VertexBuffer.UV2Kind),o.VERTEXCOLOR&&h.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(h,i,o,l),e.MaterialHelper.PrepareAttributesForInstances(h,o);var u=o.toString(),c=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","diffuseMatrix"],f=["diffuseSampler"],p=new Array;e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:o,maxSimultaneousLights:this.maxSimultaneousLights}),r.setEffect(s.getEngine().createEffect("cell",{attributes:h,uniformsNames:c,uniformBuffersNames:p,samplers:f,defines:u,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this.maxSimultaneousLights-1}},a),o)}return!(!r.effect||!r.effect.isReady()||(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,0))},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;s&&(this._activeEffect=s,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("viewProjection",n.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._activeEffect),this._mustRebind(n,s)&&(this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._activeEffect.setTexture("diffuseSampler",this._diffuseTexture),this._activeEffect.setFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),this._activeEffect.setMatrix("diffuseMatrix",this._diffuseTexture.getTextureMatrix())),e.MaterialHelper.BindClipPlane(this._activeEffect,n),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),e.MaterialHelper.BindEyePosition(s,n)),this._activeEffect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility),n.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o,this._maxSimultaneousLights),n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",n.getViewMatrix()),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._afterBind(i,this._activeEffect))}},r.prototype.getAnimatables=function(){var e=[];return this._diffuseTexture&&this._diffuseTexture.animations&&this._diffuseTexture.animations.length>0&&e.push(this._diffuseTexture),e},r.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._diffuseTexture&&e.push(this._diffuseTexture),e},r.prototype.hasTexture=function(e){return!!i.prototype.hasTexture.call(this,e)||this._diffuseTexture===e},r.prototype.dispose=function(e){this._diffuseTexture&&this._diffuseTexture.dispose(),i.prototype.dispose.call(this,e)},r.prototype.getClassName=function(){return"CellMaterial"},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.CellMaterial",t},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},o([e.serializeAsTexture("diffuseTexture")],r.prototype,"_diffuseTexture",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture",void 0),o([e.serializeAsColor3("diffuse")],r.prototype,"diffuseColor",void 0),o([e.serialize("computeHighLevel")],r.prototype,"_computeHighLevel",void 0),o([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"computeHighLevel",void 0),o([e.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),o([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),o([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),r}(e.PushMaterial);e.CellMaterial=i}(n||(n={})),n.Effect.ShadersStore.cellVertexShader="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 DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\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<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\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\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\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",n.Effect.ShadersStore.cellPixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\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<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n\nvec3 computeCustomDiffuseLighting(lightingInfo info,vec3 diffuseBase,float shadow)\n{\ndiffuseBase=info.diffuse*shadow;\n#ifdef CELLBASIC\nfloat level=1.0;\nif (info.ndl<0.5)\nlevel=0.5;\ndiffuseBase.rgb*vec3(level,level,level);\n#else\nfloat ToonThresholds[4];\nToonThresholds[0]=0.95;\nToonThresholds[1]=0.5;\nToonThresholds[2]=0.2;\nToonThresholds[3]=0.03;\nfloat ToonBrightnessLevels[5];\nToonBrightnessLevels[0]=1.0;\nToonBrightnessLevels[1]=0.8;\nToonBrightnessLevels[2]=0.6;\nToonBrightnessLevels[3]=0.35;\nToonBrightnessLevels[4]=0.2;\nif (info.ndl>ToonThresholds[0])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[0];\n}\nelse if (info.ndl>ToonThresholds[1])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[1];\n}\nelse if (info.ndl>ToonThresholds[2])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[2];\n}\nelse if (info.ndl>ToonThresholds[3])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[3];\n}\nelse\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[4];\n}\n#endif\nreturn max(diffuseBase,vec3(0.2));\n}\nvoid main(void)\n{\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#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nlightingInfo info;\nvec3 diffuseBase=vec3(0.,0.,0.);\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif \n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}",function(t,i){var r=i();t&&t.BABYLON||(e.exports=r)}(this,function(){return n})}).call(t,i(1))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(5),n=i(2);t.InitTags=function(e){void 0===e&&(e="babylon");for(var t=document.querySelectorAll(e),i=0;i<t.length;++i){var o=t.item(i),s=n.mapperManager.getMapper("dom").map(o);new r.DefaultViewer(o,s)}}},function(e,t,i){(function(t,r){/*!
  22. * @overview es6-promise - a tiny implementation of Promises/A+.
  23. * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
  24. * @license Licensed under MIT license
  25. * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
  26. * @version 4.1.1
  27. */
  28. !function(t,i){e.exports=i()}(0,function(){"use strict";function e(e){var t=typeof e;return null!==e&&("object"===t||"function"===t)}function n(e){return"function"==typeof e}function o(){return void 0!==V?function(){V(a)}:s()}function s(){var e=setTimeout;return function(){return e(a,1)}}function a(){for(var e=0;e<B;e+=2)(0,X[e])(X[e+1]),X[e]=void 0,X[e+1]=void 0;B=0}function l(e,t){var i=arguments,r=this,n=new this.constructor(u);void 0===n[K]&&R(n);var o=r._state;return o?function(){var e=i[o-1];z(function(){return S(o,n,e,r._result)})}():T(r,n,e,t),n}function h(e){var t=this;if(e&&"object"==typeof e&&e.constructor===t)return e;var i=new t(u);return _(i,e),i}function u(){}function c(){return new TypeError("You cannot resolve a promise with itself")}function f(){return new TypeError("A promises callback cannot return that same promise.")}function p(e){try{return e.then}catch(e){return J.error=e,J}}function d(e,t,i,r){try{e.call(t,i,r)}catch(e){return e}}function m(e,t,i){z(function(e){var r=!1,n=d(i,t,function(i){r||(r=!0,t!==i?_(e,i):x(e,i))},function(t){r||(r=!0,b(e,t))},"Settle: "+(e._label||" unknown promise"));!r&&n&&(r=!0,b(e,n))},e)}function g(e,t){t._state===Z?x(e,t._result):t._state===q?b(e,t._result):T(t,void 0,function(t){return _(e,t)},function(t){return b(e,t)})}function v(e,t,i){t.constructor===e.constructor&&i===l&&t.constructor.resolve===h?g(e,t):i===J?(b(e,J.error),J.error=null):void 0===i?x(e,t):n(i)?m(e,t,i):x(e,t)}function _(t,i){t===i?b(t,c()):e(i)?v(t,i,p(i)):x(t,i)}function y(e){e._onerror&&e._onerror(e._result),E(e)}function x(e,t){e._state===Q&&(e._result=t,e._state=Z,0!==e._subscribers.length&&z(E,e))}function b(e,t){e._state===Q&&(e._state=q,e._result=t,z(y,e))}function T(e,t,i,r){var n=e._subscribers,o=n.length;e._onerror=null,n[o]=t,n[o+Z]=i,n[o+q]=r,0===o&&e._state&&z(E,e)}function E(e){var t=e._subscribers,i=e._state;if(0!==t.length){for(var r=void 0,n=void 0,o=e._result,s=0;s<t.length;s+=3)r=t[s],n=t[s+i],r?S(i,r,n,o):n(o);e._subscribers.length=0}}function A(){this.error=null}function P(e,t){try{return e(t)}catch(e){return $.error=e,$}}function S(e,t,i,r){var o=n(i),s=void 0,a=void 0,l=void 0,h=void 0;if(o){if((s=P(i,r))===$?(h=!0,a=s.error,s.error=null):l=!0,t===s)return void b(t,f())}else s=r,l=!0;t._state!==Q||(o&&l?_(t,s):h?b(t,a):e===Z?x(t,s):e===q&&b(t,s))}function M(e,t){try{t(function(t){_(e,t)},function(t){b(e,t)})}catch(t){b(e,t)}}function C(){return ee++}function R(e){e[K]=ee++,e._state=void 0,e._result=void 0,e._subscribers=[]}function I(e,t){this._instanceConstructor=e,this.promise=new e(u),this.promise[K]||R(this.promise),N(t)?(this.length=t.length,this._remaining=t.length,this._result=new Array(this.length),0===this.length?x(this.promise,this._result):(this.length=this.length||0,this._enumerate(t),0===this._remaining&&x(this.promise,this._result))):b(this.promise,O())}function O(){return new Error("Array Methods must be provided an Array")}function D(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function w(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function L(e){this[K]=C(),this._result=this._state=void 0,this._subscribers=[],u!==e&&("function"!=typeof e&&D(),this instanceof L?M(this,e):w())}var F=void 0,N=F=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},B=0,V=void 0,U=void 0,z=function(e,t){X[B]=e,X[B+1]=t,2===(B+=2)&&(U?U(a):Y())},k="undefined"!=typeof window?window:void 0,G=k||{},H=G.MutationObserver||G.WebKitMutationObserver,W="undefined"==typeof self&&void 0!==t&&"[object process]"==={}.toString.call(t),j="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,X=new Array(1e3),Y=void 0;Y=W?function(){return t.nextTick(a)}:H?function(){var e=0,t=new H(a),i=document.createTextNode("");return t.observe(i,{characterData:!0}),function(){i.data=e=++e%2}}():j?function(){var e=new MessageChannel;return e.port1.onmessage=a,function(){return e.port2.postMessage(0)}}():void 0===k?function(){try{var e=i(34);return V=e.runOnLoop||e.runOnContext,o()}catch(e){return s()}}():s();var K=Math.random().toString(36).substring(16),Q=void 0,Z=1,q=2,J=new A,$=new A,ee=0;return I.prototype._enumerate=function(e){for(var t=0;this._state===Q&&t<e.length;t++)this._eachEntry(e[t],t)},I.prototype._eachEntry=function(e,t){var i=this._instanceConstructor,r=i.resolve;if(r===h){var n=p(e);if(n===l&&e._state!==Q)this._settledAt(e._state,t,e._result);else if("function"!=typeof n)this._remaining--,this._result[t]=e;else if(i===L){var o=new i(u);v(o,e,n),this._willSettleAt(o,t)}else this._willSettleAt(new i(function(t){return t(e)}),t)}else this._willSettleAt(r(e),t)},I.prototype._settledAt=function(e,t,i){var r=this.promise;r._state===Q&&(this._remaining--,e===q?b(r,i):this._result[t]=i),0===this._remaining&&x(r,this._result)},I.prototype._willSettleAt=function(e,t){var i=this;T(e,void 0,function(e){return i._settledAt(Z,t,e)},function(e){return i._settledAt(q,t,e)})},L.all=function(e){return new I(this,e).promise},L.race=function(e){var t=this;return new t(N(e)?function(i,r){for(var n=e.length,o=0;o<n;o++)t.resolve(e[o]).then(i,r)}:function(e,t){return t(new TypeError("You must pass an array to race."))})},L.resolve=h,L.reject=function(e){var t=new this(u);return b(t,e),t},L._setScheduler=function(e){U=e},L._setAsap=function(e){z=e},L._asap=z,L.prototype={constructor:L,then:l,catch:function(e){return this.then(null,e)}},L.polyfill=function(){var e=void 0;if(void 0!==r)e=r;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(e){throw new Error("polyfill failed because global object is unavailable in this environment")}var t=e.Promise;if(t){var i=null;try{i=Object.prototype.toString.call(t.resolve())}catch(e){}if("[object Promise]"===i&&!t.cast)return}e.Promise=L},L.Promise=L,L})}).call(t,i(33),i(1))},function(e,t){function i(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function n(e){if(u===setTimeout)return setTimeout(e,0);if((u===i||!u)&&setTimeout)return u=setTimeout,setTimeout(e,0);try{return u(e,0)}catch(t){try{return u.call(null,e,0)}catch(t){return u.call(this,e,0)}}}function o(e){if(c===clearTimeout)return clearTimeout(e);if((c===r||!c)&&clearTimeout)return c=clearTimeout,clearTimeout(e);try{return c(e)}catch(t){try{return c.call(null,e)}catch(t){return c.call(this,e)}}}function s(){m&&p&&(m=!1,p.length?d=p.concat(d):g=-1,d.length&&a())}function a(){if(!m){var e=n(s);m=!0;for(var t=d.length;t;){for(p=d,d=[];++g<t;)p&&p[g].run();g=-1,t=d.length}p=null,m=!1,o(e)}}function l(e,t){this.fun=e,this.array=t}function h(){}var u,c,f=e.exports={};!function(){try{u="function"==typeof setTimeout?setTimeout:i}catch(e){u=i}try{c="function"==typeof clearTimeout?clearTimeout:r}catch(e){c=r}}();var p,d=[],m=!1,g=-1;f.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var i=1;i<arguments.length;i++)t[i-1]=arguments[i];d.push(new l(e,t)),1!==d.length||m||n(a)},l.prototype.run=function(){this.fun.apply(null,this.array)},f.title="browser",f.browser=!0,f.env={},f.argv=[],f.version="",f.versions={},f.on=h,f.addListener=h,f.once=h,f.off=h,f.removeListener=h,f.removeAllListeners=h,f.emit=h,f.prependListener=h,f.prependOnceListener=h,f.listeners=function(e){return[]},f.binding=function(e){throw new Error("process.binding is not supported")},f.cwd=function(){return"/"},f.chdir=function(e){throw new Error("process.chdir is not supported")},f.umask=function(){return 0}},function(e,t){}])});