!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;rr.x?r.x:n)r.y?r.y:o,o=oi.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.xthis.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)r.y?r.y:o)r.z?r.z:s,s=sthis.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;f1)return r.Zero();for(var t=e*this.length(),i=0,n=0;n=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;rt+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;l0?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-r180&&(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;e0},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;tthis.data.length&&(this.data.length*=2)},e.prototype.forEach=function(e){for(var t=0;tthis.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t=this.length?-1:t},e.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>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>2,o=(3&t)<<4|(i=u>4,s=(15&i)<<2|(r=u>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?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.xi.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;ll&&(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("
"+t+"

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

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

")},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=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=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;u1&&!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();e1||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;i0){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;i65535){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=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=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;t1?"#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;r0?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;b1?"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>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;s1&&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=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;tthis.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.xt.x-this.minimumWorld.x)&&(!(this.maximumWorld.y-t.yt.y-this.minimumWorld.y)&&!(this.maximumWorld.z-t.zt.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.xt.x)&&(!(this.maximumWorld.yt.y)&&!(this.maximumWorld.zt.z))},t.Intersects=function(e,t){return!(e.maximumWorld.xt.maximumWorld.x)&&(!(e.maximumWorld.yt.maximumWorld.y)&&!(e.maximumWorld.zt.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;t1&&!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;h1)||u.canIntersects(t)){var c=u.intersects(t,this._positions,this.getIndices(),i);if(c&&(i||!s||c.distancee.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;uthis._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=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)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;i0&&-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;e0&&(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;s0&&this._postProcesses[0].markTextureDirty();for(var t=0,i=this._rigCameras.length;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;ei._alphaIndex?1:e._alphaIndext._distanceToCamera?-1:0},t.frontToBackSortCompare=function(e,t){return e._distanceToCamerat._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;ii.LongPressDelay&&Math.abs(n._startingPointerPosition.x-n._pointerX)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._previousStartingPointerTime0&&(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)0)return!1;var t;for(t=0;t0},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;h0)return;this._animationTimeLast=t}var i=(t-this._animationTimeLast)*this.animationTimeScale;this._animationTime+=i,this._animationTimeLast=t;for(var r=0;r0?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-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=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=0;t--)if(this.skeletons[t].id===e)return this.skeletons[t];return null},i.prototype.getSkeletonById=function(e){for(var t=0;t0&&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;a0&&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;s0),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-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;f0);for(var d=0;d0)}if(this.layers.length){for(i.setDepthBuffer(!1),f=0;f-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._currentInternalStep1&&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;l0),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;u0)}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;f0)for(var g=0;g0&&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;v0?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-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=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;n0)for(var s=0;s=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=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;o0},enumerable:!0,configurable:!0}),r.prototype._sortLODLevels=function(){this._LODLevels.sort(function(e,t){return e.distancet.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;tn)return this.onLODLevelSelection&&this.onLODLevelSelection(n,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var o=0;o0){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=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=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-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-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;s4,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;g0;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;a65536)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;aa&&(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]||(ethis._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,ethis._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;r0&&(n.computeBonesUsingShaders=!1)}}else{var o=this._defines[this._currentRank];if(o)for(r=0;r-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;f1)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;a0,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;p0&&(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;ho&&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=0&&this._scene.materials.splice(i,1),i=0;ia?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;c0&&(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;c1)?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+21)?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;r0&&(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;g1)?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=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;In.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;o0&&(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;t0){for(o=0;o0){for(o=0;o0){for(var o=0;o0){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>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>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-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;ch-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=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;d0&&(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"];t0,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=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)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;tn.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)Math.PI&&(this.beta=this.beta-2*Math.PI):this.betathis.upperBetaLimit&&(this.beta=this.upperBetaLimit),this.lowerAlphaLimit&&this.alphathis.upperAlphaLimit&&(this.alpha=this.upperAlphaLimit),this.lowerRadiusLimit&&this.radiusthis.upperRadiusLimit&&(this.radius=this.upperRadiusLimit)},i.prototype.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;sthis._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=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=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-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=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;at[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)}(ih[h.length-1].frame)&&(i=h[0].frame),(rh[h.length-1].frame)&&(r=h[h.length-1].frame),i===r&&(i>h[0].frame?i--:ri&&p>f||i>r&&p>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;T0&&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-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=.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]-1&&this._scene._actionManagers.splice(e,1)},t.prototype.getScene=function(){return this._scene},t.prototype.hasSpecificTriggers=function(e){for(var t=0;t-1)return!0}return!1},t.prototype.hasSpecificTrigger=function(e){for(var t=0;t=t._OnPickTrigger&&i.trigger<=t._OnPointerOutTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasPickTriggers",{get:function(){for(var e=0;e=t._OnPickTrigger&&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;r0;if(2===i.type?f.push(o):f.push(r),m){for(var g=new Array,v=0;v0){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>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;fd&&(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;athis._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;et.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.yt.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.zt.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;rt.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=_;_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)0&&a<=this.length&&T.lengthSquared()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&&a0&&l=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||S4)){++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=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=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;i0,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-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-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-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;cf-(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;T65535&&(this._needs32Bits=!0)}if(this._pickable){var x=n.length/3;for(m=0;m=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;cthis._maximum.x&&(this._maximum.x=this._positions32[o]),this._positions32[o+1]this._maximum.y&&(this._maximum.y=this._positions32[o+1]),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;cthis._maxX||ithis._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,tthis._maxX||ithis._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 t4&&(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;ne.Tmp.Vector3[1].x&&(e.Tmp.Vector3[1].x=l[c].x),l[c].ye.Tmp.Vector3[1].y&&(e.Tmp.Vector3[1].y=l[c].y),l[c].ze.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;d1?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;_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;x3?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;s0,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;A3?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 t0&&(h=!0,this._soundLoaded(i));break;case"String":l.push(i);case"Array":0===l.length&&(l=i);for(var u=0;u0&&(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;t0&&(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=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=0&&e.customRenderTargets.splice(i,1);for(var r=0,n=e.cameras;r=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;p1||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=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;p0)for(var e=0;e0&&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)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-1&&void 0!==p.skeletons&&null!==p.skeletons&&!1===_.indexOf(x.skeletonId)>-1)for(var I=0,O=p.skeletons.length;I0){for(var se=0;se0){for(var le=0;le0&&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;o0){for(var i=new Array,r=[],n=e.dataTransfer?e.dataTransfer.items:null,o=0;o0&&(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;lo.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=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=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.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=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;ethis.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;n4&&(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;i0?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=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._hdrCurrentLuminancen-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;e4&&(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;s0&&-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;st._alphaIndex?1:e._alphaIndext._distanceToCamera?-1:0}),l.setAlphaMode(e.Engine.ALPHA_COMBINE),s=0;s0)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=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;m0&&(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):vthis._maxYaw||xMath.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):xMath.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)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,tt&&ei&&e-1&&this._meshesWithPoseMatrix.splice(t,1)},t.prototype._computeTransformMatrices=function(e,t){this.onBeforeComputeObservable.notifyObservers(this);for(var i=0;i0&&(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-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;o0&&(e=this._meshesWithPoseMatrix[0].getPoseMatrix()),e},t.prototype.sortBones=function(){for(var e=new Array,t=new Array(this.bones.length),i=0;iMath.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;n32767)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;u128){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,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;y255){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;f255){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=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.xo.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=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.x&&r.x>=u&&g(oi.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;t0||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=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;o80*n){d=u=e[0],m=c=e[1];for(var v=n;vu&&(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;a0&&(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.xi.x&&(i.x=e.x),e.yi.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;l0){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;fs.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;lt.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=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;e0&&(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._positionXt.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._positionXi.x+i.width-this.borderLimit?this._positionX-i.x-i.width+this.borderLimit:0)>(n=this._positionYi.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-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;tr.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>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>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=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;t0?(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=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;t0){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;lthis.capacity&&this._depth>>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=2)){for(var n=!1,o=0;oi.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;rl||r.deleted||r.isDirty))for(var o=0;o<3;++o)if(r.error[o]>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;i0&&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.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;or.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=i.targetFrameRate)n&&n();else{for(var s=!0,a=!0,l=0;l4&&(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])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;eh.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;it&&(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\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\n#include\n\n#include\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\n#include\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include[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\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL \nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include\n#include\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\n#include\n#include\n#include[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include\n#include\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\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\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\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\n#endif\n#include\n#include\n#include\n#include\n#include\n#include\nvoid main(void) {\n#include\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\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\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[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\n#include\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\n#include\n\n#include\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\n#endif\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include\n#include\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include[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\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include\n#include\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\n\n#include\n\n#include\n\n#include[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n\n#include\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\n#endif\n#ifdef ENVIRONMENTBRDF\nuniform sampler2D environmentBrdfSampler;\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n#include\n#include\n#include\n\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n\n#include\nvoid main(void) {\n#include\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\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\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[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\n#include(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\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\nvoid main(void) {\nvec4 color=texture2D(diffuseSampler,vUV);\nif (alphaTest) \n{\nif (color.a<0.95)\ndiscard;\n}\ncolor*=vColor;\n#include\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\n\nuniform mat4 viewProjection;\nuniform mat4 world;\n\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\nvoid main(void) {\nmat4 finalWorld=world;\n#include\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\n\n#include\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\n#include\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\n\n#include\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\n#include\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; imaxZ) {\ngl_FragColor=vec4(1.0,1.0,1.0,1.0);\nreturn;\n}\nfor (int i=0; i1.0 || offset.y>1.0) {\ncontinue;\n}\n\nfloat sampleDepth=abs(texture2D(textureSampler,offset.xy).r);\n\nfloat rangeCheck=abs(depth-sampleDepth)=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; i0.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 (luminanceshadowPixelDepth)\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=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=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\n#include\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\n#include\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[3]\n#else\n#include[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\n#include\n#include\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[0..varyingCount]\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nsampleCenter=(position*madd+madd);\n#include[0..varyingCount]\ngl_Position=vec4(position,0.0,1.0);\n}",kernelBlurPixelShader:"\nuniform sampler2D textureSampler;\nuniform vec2 delta;\n\nvarying vec2 sampleCenter;\n#include[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[0..varyingCount]\n#include[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\n\n#include\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\n#include\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\n\nuniform float offset;\n#include\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\nvoid main(void)\n{\nvec3 offsetPosition=position+normal*offset;\n#include\n#include\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\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\nvoid main(void) {\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\n#include\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\n\n#include\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\n#include\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\n#include\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\n\n#include\n\n#include[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\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n\n#ifndef SHADOWONLY\n#define SHADOWONLY;\n#endif\n#include\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include\n#include\n#include\n\n#include\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\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[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\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))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))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; icurrRayHeight)\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;i0)&&(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\r\n\r\n"},function(e,t){e.exports='\r\n\r\n'},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='\r\n\r\n\r\n\r\n\r\n'},function(e,t){e.exports='\r\n\r\n
\r\n {{closeText}}\r\n
\r\n\r\n\r\n'},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 (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;ls.x&&(s.x=h.x),h.xs.y&&(s.y=h.y),h.ys.z&&(s.z=h.z),h.zt&&(this.lowerBound.x=t);i=e.upperBound.x;this.upperBound.xt&&(this.lowerBound.y=t);i=e.upperBound.y;this.upperBound.yt&&(this.lowerBound.z=t);var i=e.upperBound.z;this.upperBound.z=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()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=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)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;re){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+oe.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)f)&&(f=h[0]),(null===c||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&&Tm||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=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=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=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;om?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.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&&in?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))),n1.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;np.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;n0?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;np&&(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;uT){this.sliding=!0,M.sliding=!0;var S=b/Math.sqrt(P);M.skidInfo*=S}}}if(this.sliding)for(u=0;uthis.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()=-.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;or.x&&(r.x=a),h>r.y&&(r.y=h),u>r.z&&(r.z=u),ap&&(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;A0&&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(at&&(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;si.x&&(i.x=n.x),n.yi.y&&(i.y=n.y),n.zi.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.maxForce&&(n=A.maxForce-h),x[E]+=n,l+=n>0?n:-n,A.addToWlambda(n)}if(l*l=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;gb.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.type0&&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))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&&I-C){V=Math.abs(A-E-u);(null===y||V0){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*ke.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)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+cl.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+u2)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=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+"
"}};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.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.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.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+"
",this.broadPhase+"

","FPS: "+this.fps+" fps

","rigidbody "+this.parent.numRigidBodies+"
","contact   "+this.parent.numContacts+"
","ct-point  "+this.parent.numContactPoints+"
","paircheck "+this.parent.broadPhase.numPairChecks+"
","island    "+this.parent.numIslands+"

","Time in milliseconde

","broad-phase  "+a.fix(this.broadPhaseTime)+"
","narrow-phase "+a.fix(this.narrowPhaseTime)+"
","solving      "+a.fix(this.solvingTime)+"
","total        "+a.fix(this.totalTime)+"
","updating     "+this.updatingTime()+"
"].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 ei?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):pthis.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):dthis.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):mthis.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):athis.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)):athis.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)):lthis.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)):hthis.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)):athis.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.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;MeT*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.id0)||(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]))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;Di0?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;Di0?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;Di0?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;DiUi&&(Ui=bi,Bi=Di);for(this.used[Fi]=!0,this.used[Bi]=!0,Ui=-this.INF,xi=this.INF,Di=0;DiUi&&(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;Dib?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,A0&&h0&&c0&&(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=.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.id0,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&&Oi[3]||t[1]>i[4]||t[2]>i[5]||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[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-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=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>t!=0;)t++;t=t*this.numElements>>2,e=0;for(var i=!1,r=this.elements,n=1,o=this.numElements;nl){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=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_.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(),p0?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-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;x0&&(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= 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":">",'"':""","'":"'","`":"`","=":"="},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;h0?(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=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;o2&&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;st[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;l0)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;i1)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=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--;o0&&(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;ithis.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\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\r\n\r\n{{#if disableOnFullscreen}}\r\n\r\n{{/if}}\r\n\r\n
\r\n \x3c!-- holding the description --\x3e\r\n
\r\n \x3c!-- holding the thumbnail \r\n {{title}}--\x3e\r\n
\r\n
\r\n\r\n {{#if title}}{{title}}{{/if}}\r\n {{#if subtitle}}{{subtitle}} {{/if}}\r\n
\r\n
\r\n
\r\n \x3c!-- holding the buttons --\x3e\r\n {{#each buttons}}\r\n
\r\n {{#if text}}\r\n {{text}}> {{/if}} {{#if image}}\r\n {{altText}} {{/if}}\r\n
\r\n {{/each}}\r\n
'},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;c127)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=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;e0&&(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-1;)o.push(i),r=i+1;if(-1==i&&0==o.length)P.materials[t].dispose();else for(var a=0;a0)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.major?1:e.majort.minor?1:e.minor=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;t0&&(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;P0&&-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;ss.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=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=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;l0&&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\n\n#include\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\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include\n#include\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\n\n#include\n#include[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\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include\n\n#include\nvoid main(void) {\n#include\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[0..1]\n\nvec4 color=vec4(0.,0.,0.,(1.0-clamp(shadow,0.,1.))*alpha);\n#include\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\n\n#include\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\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include\n#include \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\n\n#include\n#include[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\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include\n#include\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include\n\n#include\nvoid main(void) {\n#include\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\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[0]\n#include[1]\n#include[2]\n#include[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\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\n\n#include\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\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include\n#include\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\n\n#include\n#include[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\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include\n#include\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include\n\n#include\nvoid main(void) {\n#include\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\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[0]\n#include[1]\n#include[2]\n#include[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\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\n\n#include\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\n#include\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\n#include\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\n\n#include\n#include[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\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include\n#include\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include\n\n#include\nfloat random( vec3 scale,float seed ){\nreturn fract( sin( dot( gl_FragCoord.xyz+seed,scale ) )*43758.5453+seed ) ;\n}\nvoid main(void) {\n#include\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\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[0]\n#include[1]\n#include[2]\n#include[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\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\n\n#include\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\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include\n#include\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\n\n#include\n#include[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\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include\n\n#include\nvoid main(void) {\n#include\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\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[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\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\n\n#include\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\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\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\n#include\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\n\n#include\n\n#include[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\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\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\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\n#include\n\n#include\nvoid main(void) {\n\n#include\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[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[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\n#include\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\n\n#include\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\n#include\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\n#include\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\n\n#include\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\n\n#include\nvec4 bx2(vec4 x)\n{\nreturn vec4(2.0)*x-vec4(1.0);\n}\nvoid main(void) {\n\n#include\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\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\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;e0&&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\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\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\n#include\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\n#include\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\n\n#include\n\n#include[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\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\n#include\n#include\n#include\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\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\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[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\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\n\n#include\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\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include\n#include\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\n\n#include[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\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\n#include\n#include\n\n#include\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\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[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\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;u0&&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\n\n#include\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\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void)\n{\n#include\n#include\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\n\n#include\n\n#include[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\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\n#include\n#include\n#include\nvoid main(void) {\n\n#include\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\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[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\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\n#include\nvoid main(void) {\ngl_Position=viewProjection*world*vec4(position,1.0);\nvec4 worldPos=world*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n\n#include\n\n#include\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\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\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\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\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\nvoid main(void) {\n#ifdef FOG\nvec4 worldPos=world*vec4(position,1.0);\n#endif\n#include\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\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\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"];t0,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\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\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\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\n#endif\n#include\n#include\n\n#include\n#include\n#include\n#include\n\n#[Fragment_Definitions]\n\nvoid main(void) {\n\nvNormalW = vNormalW_helper;\n#[Fragment_MainBegin]\n\n#include\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\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[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\n#include\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\n\n#include\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\n#include\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include[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\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[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include\n#include\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\n#include\n#include\n#include[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include\n#include\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\n\n#include\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\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include\n#include\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\n\n#include\n#include[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\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include\n\n#include\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\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\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[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\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;i1)for(var i=1;i