!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],h=e*r.m[3]+t*r.m[7]+i*r.m[11]+r.m[15];n.x=o/h,n.y=s/h,n.z=a/h},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,h=r*r,l=n*n,c=n*i-r*o;return c<-.4999999?(e.y=2*Math.atan2(n,o),e.x=Math.PI/2,e.z=0):c>.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-h+l+s),e.x=Math.asin(-2*(i*n-r*o)),e.y=Math.atan2(2*(i*r+n*o),a-h-l+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,h=this.y*this.z,l=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*(h+l),e.m[7]=0,e.m[8]=2*(s+a),e.m[9]=2*(h-l),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],h=r[5],l=r[9],c=r[2],u=r[6],p=r[10],f=n+h+p;f>0?(i=.5/Math.sqrt(f+1),t.w=.25/i,t.x=(u-l)*i,t.y=(s-c)*i,t.z=(a-o)*i):n>h&&n>p?(i=2*Math.sqrt(1+n-h-p),t.w=(u-l)/i,t.x=.25*i,t.y=(o+a)/i,t.z=(s+c)/i):h>p?(i=2*Math.sqrt(1+h-n-p),t.w=(s-c)/i,t.x=(o+a)/i,t.y=.25*i,t.z=(l+u)/i):(i=2*Math.sqrt(1+p-n-h),t.w=(a-o)/i,t.x=(s+c)/i,t.y=(l+u)/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),h=Math.cos(n),l=Math.sin(o),c=Math.cos(o),u=Math.sin(s),p=Math.cos(s);r.x=p*l*h+u*c*a,r.y=u*c*h-p*l*a,r.z=p*c*a-u*l*h,r.w=p*c*h+u*l*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,h=!1;if(a<0&&(h=!0,a=-a),a>.999999)o=1-s,n=h?-s:s;else{var l=Math.acos(a),c=1/Math.sin(l);o=Math.sin((1-s)*l)*c,n=h?-Math.sin(s*l)*c:Math.sin(s*l)*c}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,h=2*a-3*s+1,l=-2*a+3*s,c=a-2*s+o,u=a-s;return new t(e.x*h+r.x*l+i.x*c+n.x*u,e.y*h+r.y*l+i.y*c+n.y*u,e.z*h+r.z*l+i.z*c+n.z*u,e.w*h+r.w*l+i.w*c+n.w*u)},t}();e.Quaternion=a;var h=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],h=this.m[7],l=this.m[8],c=this.m[9],u=this.m[10],p=this.m[11],f=this.m[12],d=this.m[13],m=this.m[14],g=this.m[15],_=u*g-p*m,v=c*g-p*d,y=c*m-u*d,b=l*g-p*f,x=l*m-u*f,T=l*d-c*f,E=s*_-a*v+h*y,A=-(o*_-a*b+h*x),P=o*v-s*b+h*T,M=-(o*y-s*x+a*T),S=1/(t*E+i*A+r*P+n*M),C=a*g-h*m,R=s*g-h*d,I=s*m-a*d,O=o*g-h*f,w=o*m-a*f,D=o*d-s*f,L=a*p-h*u,F=s*p-h*c,N=s*u-a*c,B=o*p-h*l,V=o*u-a*l,U=o*c-s*l;return e.m[0]=E*S,e.m[4]=A*S,e.m[8]=P*S,e.m[12]=M*S,e.m[1]=-(i*_-r*v+n*y)*S,e.m[5]=(t*_-r*b+n*x)*S,e.m[9]=-(t*v-i*b+n*T)*S,e.m[13]=(t*y-i*x+r*T)*S,e.m[2]=(i*C-r*R+n*I)*S,e.m[6]=-(t*C-r*O+n*w)*S,e.m[10]=(t*R-i*O+n*D)*S,e.m[14]=-(t*I-i*w+r*D)*S,e.m[3]=-(i*L-r*F+n*N)*S,e.m[7]=(t*L-r*B+n*V)*S,e.m[11]=-(t*F-i*B+n*U)*S,e.m[15]=(t*N-i*V+r*U)*S,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],h=this.m[5],l=this.m[6],c=this.m[7],u=this.m[8],p=this.m[9],f=this.m[10],d=this.m[11],m=this.m[12],g=this.m[13],_=this.m[14],v=this.m[15],y=e.m[0],b=e.m[1],x=e.m[2],T=e.m[3],E=e.m[4],A=e.m[5],P=e.m[6],M=e.m[7],S=e.m[8],C=e.m[9],R=e.m[10],I=e.m[11],O=e.m[12],w=e.m[13],D=e.m[14],L=e.m[15];return t[i]=r*y+n*E+o*S+s*O,t[i+1]=r*b+n*A+o*C+s*w,t[i+2]=r*x+n*P+o*R+s*D,t[i+3]=r*T+n*M+o*I+s*L,t[i+4]=a*y+h*E+l*S+c*O,t[i+5]=a*b+h*A+l*C+c*w,t[i+6]=a*x+h*P+l*R+c*D,t[i+7]=a*T+h*M+l*I+c*L,t[i+8]=u*y+p*E+f*S+d*O,t[i+9]=u*b+p*A+f*C+d*w,t[i+10]=u*x+p*P+f*R+d*D,t[i+11]=u*T+p*M+f*I+d*L,t[i+12]=m*y+g*E+_*S+v*O,t[i+13]=m*b+g*A+_*C+v*w,t[i+14]=m*x+g*P+_*R+v*D,t[i+15]=m*T+g*M+_*I+v*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]),h=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]/h,i[9]/h,i[10]/h,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,h,l,c,u,p,f,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]=h,g.m[9]=l,g.m[10]=c,g.m[11]=u,g.m[12]=p,g.m[13]=f,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,h,l,c,u,p,f,d,m,g){var _=new t;return _.m[0]=e,_.m[1]=i,_.m[2]=r,_.m[3]=n,_.m[4]=o,_.m[5]=s,_.m[6]=a,_.m[7]=h,_.m[8]=l,_.m[9]=c,_.m[10]=u,_.m[11]=p,_.m[12]=f,_.m[13]=d,_.m[14]=m,_.m[15]=g,_},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,h=new n(0,0,0);e.decompose(o,s,h);var l=new n(0,0,0),c=new a,u=new n(0,0,0);i.decompose(l,c,u);var p=n.Lerp(o,l,r),f=a.Slerp(s,c,r),d=n.Lerp(h,u,r);return t.Compose(p,f,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),h=-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,h,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),h=-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,h,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=2/t,a=2/i,h=2/(n-r),l=-(n+r)/(n-r);e.Matrix.FromValuesToRef(s,0,0,0,0,a,0,0,0,0,h,0,0,0,l,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 h=2/(i-t),l=2/(n-r),c=2/(s-o),u=-(s+o)/(s-o),p=(t+i)/(t-i),f=(n+r)/(r-n);e.Matrix.FromValuesToRef(h,0,0,0,0,l,0,0,0,0,c,0,p,f,u,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=2*n/i,h=2*n/r,l=(o+n)/(o-n),c=-2*o*n/(o-n);return e.Matrix.FromValuesToRef(a,0,0,0,0,h,0,0,0,0,l,1,0,0,c,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,h=n,l=1/Math.tan(.5*t),c=s?l/i:l,u=s?l:l*i,p=(h+a)/(h-a),f=-2*h*a/(h-a);e.Matrix.FromValuesToRef(c,0,0,0,0,u,0,0,0,0,p,1,0,0,f,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,h=n,l=1/Math.tan(.5*t),c=s?l/i:l,u=s?l:l*i,p=-(h+a)/(h-a),f=-2*h*a/(h-a);e.Matrix.FromValuesToRef(c,0,0,0,0,u,0,0,0,0,p,-1,0,0,f,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),h=Math.tan(e.leftDegrees*Math.PI/180),l=Math.tan(e.rightDegrees*Math.PI/180),c=2/(h+l),u=2/(s+a);r.m[0]=c,r.m[1]=r.m[2]=r.m[3]=r.m[4]=0,r.m[5]=u,r.m[6]=r.m[7]=0,r.m[8]=(h-l)*c*.5,r.m[9]=-(s-a)*u*.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,h=e.height,l=e.x,c=e.y,u=t.FromValues(a/2,0,0,0,0,-h/2,0,0,0,0,s-o,0,l+a/2,h/2+c,o,1);return i.multiply(r).multiply(n).multiply(u)},t.GetAsMatrix2x2=function(e){return new Float32Array([e.m[0],e.m[1],e.m[4],e.m[5]])},t.GetAsMatrix3x3=function(e){return new Float32Array([e.m[0],e.m[1],e.m[2],e.m[4],e.m[5],e.m[6],e.m[8],e.m[9],e.m[10]])},t.Transpose=function(e){var 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,h=e.y*e.w,l=e.y*e.z,c=e.x*e.w;t.m[0]=1-2*(r+n),t.m[1]=2*(o+s),t.m[2]=2*(a-h),t.m[3]=0,t.m[4]=2*(o-s),t.m[5]=1-2*(n+i),t.m[6]=2*(l+c),t.m[7]=0,t.m[8]=2*(a+h),t.m[9]=2*(l-c),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=h;var l=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=h.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,h=i.y-e.y,l=i.z-e.z,c=o*l-s*h,u=s*a-n*l,p=n*h-o*a,f=Math.sqrt(c*c+u*u+p*p);return r=0!==f?1/f:0,this.normal.x=c*r,this.normal.y=u*r,this.normal.z=p*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=l;var c=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=c;var u=function(){function e(){}return e.GetPlanes=function(t){for(var i=[],r=0;r<6;r++)i.push(new l(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=u;!function(e){e[e.LOCAL=0]="LOCAL",e[e.WORLD=1]="WORLD",e[e.BONE=2]="BONE"}(e.Space||(e.Space={}));var p=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=p;var f=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,h=e,l=0;l<5;l++){var c=h*h;h-=(o*(c*h)+s*c+a*h-e)*(1/(3*o*c+2*s*h+a)),h=Math.min(1,Math.max(0,h))}return 3*Math.pow(1-h,2)*h*i+3*(1-h)*Math.pow(h,2)*n+Math.pow(h,3)},e}();e.BezierCurve=f;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 h=this.startAngle.degrees(),l=m.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),c=m.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();l-h>180&&(l-=360),l-h<-180&&(l+=360),c-l>180&&(c-=360),c-l<-180&&(c+=360),this.orientation=l-h<0?d.CW:d.CCW,this.angle=m.FromDegrees(this.orientation===d.CW?h-c:c-h)}}();e.Arc2=g;var _=function(){function e(e,t){this._points=new Array,this._length=0,this.closed=!1,this._points.push(new r(e,t))}return e.prototype.addLineTo=function(e,t){if(this.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),this.closed)return this;var s=this._points[this._points.length-1],a=new r(e,t),h=new r(i,n),l=new g(s,a,h),c=l.angle.radians()/o;l.orientation===d.CW&&(c*=-1);for(var u=l.startAngle.radians()+c,p=0;p1)return r.Zero();for(var t=e*this.length(),i=0,n=0;n=i&&t<=h){var l=a.normalize(),c=t-i;return new r(s.x+l.x*c,s.y+l.y*c)}i=h}return r.Zero()},e.StartingAt=function(t,i){return new e(t,i)},e}();e.Path2=_;var v=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=v;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},h=0;h<=o;h++)s.push(new n(a(h/o,t.x,i.x,r.x),a(h/o,t.y,i.y,r.y),a(h/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,h=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},l=0;l<=s;l++)a.push(new n(h(l/s,t.x,i.x,r.x,o.x),h(l/s,t.y,i.y,r.y,o.y),h(l/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,h=1/s,l=0;l<=s;l++)a.push(n.Hermite(t,i,r,o,l*h));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,h=0;h0?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();if(n[t])return n[t];n[t]={};for(var i=n[t],o=e,s=t;s;){var a=r[s];for(var h in a)i[h]=a[h];var l=void 0,c=!1;do{if(!(l=Object.getPrototypeOf(o)).getClassName){c=!0;break}if(l.getClassName()!==s)break;o=l}while(l);if(c)break;s=l.getClassName(),o=l}return i}function i(e,t){return function(i,n){var o=function(e){var t=e.getClassName();return r[t]||(r[t]={}),r[t]}(i);o[n]||(o[n]={type:e,sourceName:t})}}var r={},n={},o=function(i,r,n){var o=i();e.Tags&&e.Tags.AddTagsTo(o,r.tags);var s=t(o);for(var a in s){var h=s[a],l=r[a],c=h.type;if(void 0!==l&&null!==l)switch(c){case 0:case 6:o[a]=l;break;case 1:o[a]=n||l.isRenderTarget?l:l.clone();break;case 2:case 3:case 4:case 5:case 7:case 10:o[a]=n?l:l.clone()}}return o};e.expandToProperty=function(e,t){return void 0===t&&(t=null),function(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})}}(e,t)},e.serialize=function(e){return i(0,e)},e.serializeAsTexture=function(e){return i(1,e)},e.serializeAsColor3=function(e){return i(2,e)},e.serializeAsFresnelParameters=function(e){return i(3,e)},e.serializeAsVector2=function(e){return i(4,e)},e.serializeAsVector3=function(e){return i(5,e)},e.serializeAsMeshReference=function(e){return i(6,e)},e.serializeAsColorCurves=function(e){return i(7,e)},e.serializeAsColor4=function(e){return i(8,e)},e.serializeAsImageProcessingConfiguration=function(e){return i(9,e)},e.serializeAsQuaternion=function(e){return i(10,e)};var s=function(){function i(){}return i.Serialize=function(i,r){r||(r={}),e.Tags&&(r.tags=e.Tags.GetTags(i));var n=t(i);for(var o in n){var s=n[o],a=s.sourceName||o,h=s.type,l=i[o];if(void 0!==l&&null!==l)switch(h){case 0:r[a]=l;break;case 1:r[a]=l.serialize();break;case 2:r[a]=l.asArray();break;case 3:r[a]=l.serialize();break;case 4:case 5:r[a]=l.asArray();break;case 6:r[a]=l.id;break;case 7:r[a]=l.serialize();break;case 8:r[a]=l.asArray();break;case 9:r[a]=l.serialize()}}return r},i.Parse=function(i,r,n,o){void 0===o&&(o=null);var s=i();o||(o=""),e.Tags&&e.Tags.AddTagsTo(s,r.tags);var a=t(s);for(var h in a){var l=a[h],c=r[l.sourceName||h],u=l.type;if(void 0!==c&&null!==c){var p=s;switch(u){case 0:p[h]=c;break;case 1:n&&(p[h]=e.Texture.Parse(c,n,o));break;case 2:p[h]=e.Color3.FromArray(c);break;case 3:p[h]=e.FresnelParameters.Parse(c);break;case 4:p[h]=e.Vector2.FromArray(c);break;case 5:p[h]=e.Vector3.FromArray(c);break;case 6:n&&(p[h]=n.getLastMeshByID(c));break;case 7:p[h]=e.ColorCurves.Parse(c);break;case 8:p[h]=e.Color4.FromArray(c);break;case 9:p[h]=e.ImageProcessingConfiguration.Parse(c)}}}return s},i.Clone=function(e,t){return o(e,t,!1)},i.Instanciate=function(e,t){return o(e,t,!0)},i}();e.SerializationHelper=s}(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,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",l="",c=0,u=new Uint8Array(e);c>2,o=(3&t)<<4|(i=c>4,s=(15&i)<<2|(r=c>6,a=63&r,isNaN(i)?s=a=64:isNaN(r)&&(a=64),l+=h.charAt(n)+h.charAt(o)+h.charAt(s)+h.charAt(a);return"data:image/png;base64,"+l},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),h=r;h=(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),n&&n("Error while trying to load image: "+t,e)};var a=function(){s.src=t},h=function(){o&&o.loadImageFromDB(t,s)};if("data:"!==t.substr(0,5)&&o&&o.enableTexturesOffline&&e.Database.IsUASupportingBlobStorage)o.openAsync(h,a);else{if(-1!==t.indexOf("file:")){var l=decodeURIComponent(t.substring(5).toLowerCase());if(e.FilesInput.FilesToLoad[l]){try{var c;try{c=URL.createObjectURL(e.FilesInput.FilesToLoad[l],{oneTimeOnly:!0})}catch(t){c=URL.createObjectURL(e.FilesInput.FilesToLoad[l])}s.src=c}catch(e){s.src=""}return s}}a()}return s},r.LoadFile=function(t,i,n,o,s,a){t=r.CleanUrl(t);var h=null,l=function(){h=new XMLHttpRequest;var e=r.BaseUrl+t;h.open("GET",e,!0),s&&(h.responseType="arraybuffer"),n&&(h.onprogress=n),h.onreadystatechange=function(){var t=h;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)}},h.send(null)},c=function(){o&&o.loadFileFromDB(t,i,n,l,s)};if(-1!==(t=r.PreprocessUrl(t)).indexOf("file:")){var u=decodeURIComponent(t.substring(5).toLowerCase());if(e.FilesInput.FilesToLoad[u])return r.ReadFile(e.FilesInput.FilesToLoad[u],i,n,s),h}return o&&o.enableSceneOffline?o.openAsync(c,l):l(),h},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 h=0;hh&&(u=(p=h)*c);var f=Math.max(0,a-u)/2,d=Math.max(0,h-p)/2,m=e.getRenderingCanvas();l&&m&&l.drawImage(m,f,d,u,p),r.EncodeScreenshotCanvasData(o,s)},r.CreateScreenshotUsingRenderTarget=function(t,i,n,o,s,a,h,l){void 0===s&&(s="image/png"),void 0===a&&(a=1),void 0===h&&(h=!1);var c,u;if(n.precision)c=Math.round(t.getRenderWidth()*n.precision),u=Math.round(c/t.getAspectRatio(i)),n={width:c,height:u};else if(n.width&&n.height)c=n.width,u=n.height;else if(n.width&&!n.height)c=n.width,u=Math.round(c/t.getAspectRatio(i)),n={width:c,height:u};else if(n.height&&!n.width)u=n.height,n={width:c=Math.round(u*t.getAspectRatio(i)),height:u};else{if(isNaN(n))return void r.Error("Invalid 'size' parameter !");u=n,c=n}var p=i.getScene(),f=null;p.activeCamera!==i&&(f=p.activeCamera,p.activeCamera=i);var d=new e.RenderTargetTexture("screenShot",n,p,!1,!1,e.Engine.TEXTURETYPE_UNSIGNED_INT,!1,e.Texture.NEAREST_SAMPLINGMODE);d.renderList=null,d.samples=a,h&&d.addPostProcess(new e.FxaaPostProcess("antialiasing",1,p.activeCamera)),d.onAfterRenderObservable.add(function(){r.DumpFramebuffer(c,u,t,o,s,l)}),p.incrementRenderId(),p.resetCachedMaterial(),d.render(!0),d.dispose(),f&&(p.activeCamera=f),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;if(!t&&e.getClassName)i=e.getClassName();else{if(e instanceof Object){i=(t?e:Object.getPrototypeOf(e)).constructor.__bjsclassName__}i||(i=typeof e)}return 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(t,i,r,n,o,s){void 0===s&&(s=null);e.Tools.LoadFile(t,function(e){r[i]=e,r._internalCount++,6===r._internalCount&&o(r)},void 0,void 0,!0,function(e,t){s&&e&&s(e.status+" "+e.statusText,t)})},s=function(){return function(){}}(),a=function(){return function(){}}();e.InstancingAttributeInfo=a;var h=function(){return function(){}}();e.RenderTargetCreationOptions=h;var l=function(){return function(){}}();e.EngineCapabilities=l;var c=function(){function a(t,i,r,n){void 0===n&&(n=!1);var o=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=a.ALPHA_DISABLE,this._internalTexturesCache=new Array,this._boundTexturesCache={},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(o._vrDisplay&&o._vrDisplay.isPresenting){o._oldSize=new e.Size(o.getRenderWidth(),o.getRenderHeight()),o._oldHardwareScaleFactor=o.getHardwareScalingLevel();var t=o._vrDisplay.getEyeParameters("left");o.setHardwareScalingLevel(1),o.setSize(2*t.renderWidth,t.renderHeight)}else o.setHardwareScalingLevel(o._oldHardwareScaleFactor),o.setSize(o._oldSize.width,o._oldSize.height)};var h=null;if(a.Instances.push(this),t){if(r=r||{},t.getContext){if(h=t,this._renderingCanvas=h,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=h.getContext("webgl2",r)||h.getContext("experimental-webgl2",r),this._gl&&(this._webGLVersion=2)}catch(e){}if(!this._gl){if(!h)throw new Error("The provided canvas is null or undefined.");try{this._gl=h.getContext("webgl",r)||h.getContext("experimental-webgl",r)}catch(e){throw new Error("WebGL not supported")}}if(!this._gl)throw new Error("WebGL not supported");this._onCanvasFocus=function(){o.onCanvasFocusObservable.notifyObservers(o)},this._onCanvasBlur=function(){o.onCanvasBlurObservable.notifyObservers(o)},h.addEventListener("focus",this._onCanvasFocus),h.addEventListener("blur",this._onCanvasBlur),this._onBlur=function(){o.disablePerformanceMonitorInBackground&&o._performanceMonitor.disable(),o._windowIsBackground=!0},this._onFocus=function(){o.disablePerformanceMonitorInBackground&&o._performanceMonitor.enable(),o._windowIsBackground=!1},this._onCanvasPointerOut=function(){o.onCanvasPointerOutObservable.notifyObservers(o)},window.addEventListener("blur",this._onBlur),window.addEventListener("focus",this._onFocus),h.addEventListener("pointerout",this._onCanvasPointerOut),this._doNotHandleContextLost||(this._onContextLost=function(t){t.preventDefault(),o._contextWasLost=!0,e.Tools.Warn("WebGL context lost."),o.onContextLostObservable.notifyObservers(o)},this._onContextRestored=function(t){setTimeout(function(){o._initGLContext(),o._rebuildEffects(),o._rebuildInternalTextures(),o._rebuildBuffers(),o.wipeCaches(!0),e.Tools.Warn("WebGL context successfully restored."),o.onContextRestoredObservable.notifyObservers(o),o._contextWasLost=!1},0)},h.addEventListener("webglcontextlost",this._onContextLost,!1),h.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 l=r.limitDeviceRatio||window.devicePixelRatio||1;this._hardwareScalingLevel=n?1/Math.min(l,window.devicePixelRatio||1):1,this.resize(),this._isStencilEnable=!!r.stencil,this._initGLContext(),h&&(this._onFullscreenChange=function(){void 0!==document.fullscreen?o.isFullscreen=document.fullscreen:void 0!==document.mozFullScreen?o.isFullscreen=document.mozFullScreen:void 0!==document.webkitIsFullScreen?o.isFullscreen=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(o.isFullscreen=document.msIsFullScreen),o.isFullscreen&&o._pointerLockRequested&&h&&(h.requestPointerLock=h.requestPointerLock||h.msRequestPointerLock||h.mozRequestPointerLock||h.webkitRequestPointerLock,h.requestPointerLock&&h.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(){o.isPointerLock=document.mozPointerLockElement===h||document.webkitPointerLockElement===h||document.msPointerLockElement===h||document.pointerLockElement===h},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(){h&&h.requestPointerLock()},this._onVRDisplayPointerUnrestricted=function(){document.exitPointerLock()},window.addEventListener("vrdisplaypointerrestricted",this._onVRDisplayPointerRestricted,!1),window.addEventListener("vrdisplaypointerunrestricted",this._onVRDisplayPointerUnrestricted,!1)),r.audioEngine&&e.AudioEngine&&!a.audioEngine&&(a.audioEngine=new e.AudioEngine);for(var c=0;c1&&!this.disableUniformBuffers},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"needPOTTextures",{get:function(){return this._webGLVersion<2||this.forcePOTTextures},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"badOS",{get:function(){return this._badOS},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"badDesktopOS",{get:function(){return this._badDesktopOS},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"performanceMonitor",{get:function(){return this._performanceMonitor},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"texturesSupported",{get:function(){return this._texturesSupported},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"textureFormatInUse",{get:function(){return this._textureFormatInUse},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"currentViewport",{get:function(){return this._cachedViewport},enumerable:!0,configurable:!0}),Object.defineProperty(a.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(a.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(a.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}),a.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;else{null!=this._gl.getExtension("WEBGL_depth_texture")&&(this._caps.depthTextureExtension=!0)}if(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(a.prototype,"webGLVersion",{get:function(){return this._webGLVersion},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"isStencilEnable",{get:function(){return this._isStencilEnable},enumerable:!0,configurable:!0}),a.prototype._prepareWorkingCanvas=function(){if(!this._workingCanvas){this._workingCanvas=document.createElement("canvas");var e=this._workingCanvas.getContext("2d");e&&(this._workingContext=e)}},a.prototype.resetTextureCache=function(){for(var e in this._boundTexturesCache)this._boundTexturesCache[e]=null},a.prototype.isDeterministicLockStep=function(){return this._deterministicLockstep},a.prototype.getLockstepMaxSteps=function(){return this._lockstepMaxSteps},a.prototype.getGlInfo=function(){return{vendor:this._glVendor,renderer:this._glRenderer,version:this._glVersion}},a.prototype.getAspectRatio=function(e,t){void 0===t&&(t=!1);var i=e.viewport;return this.getRenderWidth(t)*i.width/(this.getRenderHeight(t)*i.height)},a.prototype.getRenderWidth=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget.width:this._gl.drawingBufferWidth},a.prototype.getRenderHeight=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget.height:this._gl.drawingBufferHeight},a.prototype.getRenderingCanvas=function(){return this._renderingCanvas},a.prototype.getRenderingCanvasClientRect=function(){return this._renderingCanvas?this._renderingCanvas.getBoundingClientRect():null},a.prototype.setHardwareScalingLevel=function(e){this._hardwareScalingLevel=e,this.resize()},a.prototype.getHardwareScalingLevel=function(){return this._hardwareScalingLevel},a.prototype.getLoadedTexturesCache=function(){return this._internalTexturesCache},a.prototype.getCaps=function(){return this._caps},Object.defineProperty(a.prototype,"drawCalls",{get:function(){return e.Tools.Warn("drawCalls is deprecated. Please use SceneInstrumentation class"),0},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"drawCallsPerfCounter",{get:function(){return e.Tools.Warn("drawCallsPerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),a.prototype.getDepthFunction=function(){return this._depthCullingState.depthFunc},a.prototype.setDepthFunction=function(e){this._depthCullingState.depthFunc=e},a.prototype.setDepthFunctionToGreater=function(){this._depthCullingState.depthFunc=this._gl.GREATER},a.prototype.setDepthFunctionToGreaterOrEqual=function(){this._depthCullingState.depthFunc=this._gl.GEQUAL},a.prototype.setDepthFunctionToLess=function(){this._depthCullingState.depthFunc=this._gl.LESS},a.prototype.setDepthFunctionToLessOrEqual=function(){this._depthCullingState.depthFunc=this._gl.LEQUAL},a.prototype.getStencilBuffer=function(){return this._stencilState.stencilTest},a.prototype.setStencilBuffer=function(e){this._stencilState.stencilTest=e},a.prototype.getStencilMask=function(){return this._stencilState.stencilMask},a.prototype.setStencilMask=function(e){this._stencilState.stencilMask=e},a.prototype.getStencilFunction=function(){return this._stencilState.stencilFunc},a.prototype.getStencilFunctionReference=function(){return this._stencilState.stencilFuncRef},a.prototype.getStencilFunctionMask=function(){return this._stencilState.stencilFuncMask},a.prototype.setStencilFunction=function(e){this._stencilState.stencilFunc=e},a.prototype.setStencilFunctionReference=function(e){this._stencilState.stencilFuncRef=e},a.prototype.setStencilFunctionMask=function(e){this._stencilState.stencilFuncMask=e},a.prototype.getStencilOperationFail=function(){return this._stencilState.stencilOpStencilFail},a.prototype.getStencilOperationDepthFail=function(){return this._stencilState.stencilOpDepthFail},a.prototype.getStencilOperationPass=function(){return this._stencilState.stencilOpStencilDepthPass},a.prototype.setStencilOperationFail=function(e){this._stencilState.stencilOpStencilFail=e},a.prototype.setStencilOperationDepthFail=function(e){this._stencilState.stencilOpDepthFail=e},a.prototype.setStencilOperationPass=function(e){this._stencilState.stencilOpStencilDepthPass=e},a.prototype.setDitheringState=function(e){e?this._gl.enable(this._gl.DITHER):this._gl.disable(this._gl.DITHER)},a.prototype.setRasterizerState=function(e){e?this._gl.disable(this._gl.RASTERIZER_DISCARD):this._gl.enable(this._gl.RASTERIZER_DISCARD)},a.prototype.stopRenderLoop=function(e){if(e){var t=this._activeRenderLoops.indexOf(e);t>=0&&this._activeRenderLoops.splice(t,1)}else this._activeRenderLoops=[]},a.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},a.prototype.runRenderLoop=function(t){-1===this._activeRenderLoops.indexOf(t)&&(this._activeRenderLoops.push(t),this._renderingQueueLaunched||(this._renderingQueueLaunched=!0,this._bindedRenderFunction=this._renderLoop.bind(this),this._frameHandler=e.Tools.QueueNewFrame(this._bindedRenderFunction)))},a.prototype.switchFullscreen=function(t){this.isFullscreen?e.Tools.ExitFullscreen():(this._pointerLockRequested=t,this._renderingCanvas&&e.Tools.RequestFullscreen(this._renderingCanvas))},a.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)},a.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)},a.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)},a.prototype.setDirectViewport=function(e,t,i,r){var n=this._cachedViewport;return this._cachedViewport=null,this._gl.viewport(e,t,i,r),n},a.prototype.beginFrame=function(){this.onBeginFrameObservable.notifyObservers(this),this._measureFps()},a.prototype.endFrame=function(){this._badOS&&this.flushFramebuffer(),this._vrDisplay&&this._vrDisplay.isPresenting&&this._vrDisplay.submitFrame(),this.onEndFrameObservable.notifyObservers(this)},a.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)}},a.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},a.prototype.bindArrayBuffer=function(e){this._vaoRecordInProgress||this._unbindVertexArrayObject(),this.bindBuffer(e,this._gl.ARRAY_BUFFER)},a.prototype.bindUniformBuffer=function(e){this._gl.bindBuffer(this._gl.UNIFORM_BUFFER,e)},a.prototype.bindUniformBufferBase=function(e,t){this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,t,e)},a.prototype.bindUniformBlock=function(e,t,i){var r=this._gl.getUniformBlockIndex(e,t);this._gl.uniformBlockBinding(e,r,i)},a.prototype.bindIndexBuffer=function(e){this._vaoRecordInProgress||this._unbindVertexArrayObject(),this.bindBuffer(e,this._gl.ELEMENT_ARRAY_BUFFER)},a.prototype.bindBuffer=function(e,t){(this._vaoRecordInProgress||this._currentBoundBuffer[t]!==e)&&(this._gl.bindBuffer(t,e),this._currentBoundBuffer[t]=e)},a.prototype.updateArrayBuffer=function(e){this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,e)},a.prototype.vertexAttribPointer=function(e,t,i,r,n,o,s){var a=this._currentBufferPointers[t],h=!1;a.active?(a.buffer!==e&&(a.buffer=e,h=!0),a.size!==i&&(a.size=i,h=!0),a.type!==r&&(a.type=r,h=!0),a.normalized!==n&&(a.normalized=n,h=!0),a.stride!==o&&(a.stride=o,h=!0),a.offset!==s&&(a.offset=s,h=!0)):(h=!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),(h||this._vaoRecordInProgress)&&(this.bindArrayBuffer(e),this._gl.vertexAttribPointer(t,i,r,n,o,s))},a.prototype._bindIndexBufferWithCache=function(e){null!=e&&this._cachedIndexBuffer!==e&&(this._cachedIndexBuffer=e,this.bindIndexBuffer(e),this._uintIndicesCurrentlySet=e.is32Bits)},a.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))))}}},a.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},a.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)},a.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(h),this._vertexAttribArraysEnabled[h]=!0,this.vertexAttribPointer(e,h,i[a],this._gl.FLOAT,!1,r,s)),s+=4*i[a]}}this._bindIndexBufferWithCache(t)},a.prototype._unbindVertexArrayObject=function(){this._cachedVertexArrayObject&&(this._cachedVertexArrayObject=null,this._gl.bindVertexArray(null))},a.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)},a.prototype.unbindInstanceAttributes=function(){for(var e,t=0,i=this._currentInstanceLocations.length;t1?"#version 300 es\n":"",a=t(n,e,"vertex",r,s),h=t(n,i,"fragment",r,s),l=this._createShaderProgram(a,h,n,o);return this.onAfterShaderCompilationObservable.notifyObservers(this),l},a.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}i.linkProgram(n),this.webGLVersion>1&&r&&this.bindTransformFeedback(null);if(!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},a.prototype.getUniforms=function(e,t){for(var i=new Array,r=0;r0?p.substring(_).toLowerCase():"",y=this.getCaps().s3tc&&".dds"===v,b=".tga"===v,x=!1;!this._textureFormatInUse||m||l||(p=p.substring(0,_)+this._textureFormatInUse,x=!0),n&&n._addPendingData(g),g.url=p,g.generateMipMaps=!i,g.samplingMode=o,g.invertY=r,this._doNotHandleContextLost||(g._buffer=h);var T=null;s&&!l&&(T=g.onLoadedObservable.add(s)),l||this._internalTexturesCache.push(g);var E=function(s,l){n&&n._removePendingData(g),T&&g.onLoadedObservable.remove(T),x?u.createTexture(t,i,r,n,o,null,a,h,g):e.Tools.UseFallbackTexture&&u.createTexture(e.Tools.fallbackTexture,i,r,n,o,null,a,h,g),a&&a(s||"Unknown error",l)},A=null;if(x||b||y)x?A=function(t){var s=new e.Internals.KhronosTextureContainer(t,1);u._prepareWebGLTexture(g,n,s.pixelWidth,s.pixelHeight,r,!1,!0,function(){return s.uploadLevels(u._gl,!i),!1},o)}:b?A=function(t){var s=new Uint8Array(t),a=e.Internals.TGATools.GetTGAHeader(s);u._prepareWebGLTexture(g,n,a.width,a.height,r,i,!1,function(){return e.Internals.TGATools.UploadContent(u._gl,s),!1},o)}:y&&(A=function(t){var s=e.Internals.DDSTools.GetDDSInfo(t),a=(s.isRGB||s.isLuminance||s.mipmapCount>1)&&!i&&s.width>>s.mipmapCount-1==1;u._prepareWebGLTexture(g,n,s.width,s.height,r,!a,s.isFourCC,function(){return e.Internals.DDSTools.UploadDDSLevels(u,u._gl,t,s,a,1),!1},o)}),h?A&&A(h):e.Tools.LoadFile(p,function(e){A&&A(e)},void 0,n?n.database:void 0,!0,function(e,t){E("Unable to load "+(e&&e.responseURL,t))});else{var P=function(t){d&&!u._doNotHandleContextLost&&(g._buffer=t),u._prepareWebGLTexture(g,n,t.width,t.height,r,i,!1,function(i,r,o){var s=u._gl,a=t.width===i&&t.height===r,h=c?u._getInternalFormat(c):".jpg"===v?s.RGB:s.RGBA;if(a)return s.texImage2D(s.TEXTURE_2D,0,h,h,s.UNSIGNED_BYTE,t),!1;var l=new e.InternalTexture(u,e.InternalTexture.DATASOURCE_TEMP);return u._bindTextureDirectly(s.TEXTURE_2D,l),s.texImage2D(s.TEXTURE_2D,0,h,h,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),u._rescaleTexture(l,g,n,h,function(){u._releaseTexture(l),u._bindTextureDirectly(s.TEXTURE_2D,g),o()}),!0},o)};!f||m?h instanceof HTMLImageElement?P(h):e.Tools.LoadImage(p,P,E,n?n.database:null):h instanceof Array||"string"==typeof h||h instanceof ArrayBuffer?e.Tools.LoadImage(h,P,E,n?n.database:null):P(h)}return g},a.prototype._rescaleTexture=function(t,i,r,n,o){var s=this,h=this.createRenderTargetTexture({width:i.width,height:i.height},{generateMipMaps:!1,type:a.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,a.TEXTURETYPE_UNSIGNED_INT)),this._rescalePostProcess.getEffect().executeWhenCompiled(function(){s._rescalePostProcess.onApply=function(e){e._bindTexture("textureSampler",t)};var e=r;e||(e=s.scenes[s.scenes.length-1]),e.postProcessManager.directRender([s._rescalePostProcess],h,!0),s._bindTextureDirectly(s._gl.TEXTURE_2D,i),s._gl.copyTexImage2D(s._gl.TEXTURE_2D,0,n,0,0,i.width,i.height,0),s.unBindFramebuffer(h),s._releaseTexture(h),o&&o()})},a.prototype._getInternalFormat=function(e){var t=this._gl.RGBA;switch(e){case a.TEXTUREFORMAT_ALPHA:t=this._gl.ALPHA;break;case a.TEXTUREFORMAT_LUMINANCE:t=this._gl.LUMINANCE;break;case a.TEXTUREFORMAT_LUMINANCE_ALPHA:t=this._gl.LUMINANCE_ALPHA;break;case a.TEXTUREFORMAT_RGB:t=this._gl.RGB;break;case a.TEXTUREFORMAT_RGBA:t=this._gl.RGBA}return t},a.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}},a.prototype.createRawTexture=function(t,i,n,o,s,a,h,l){void 0===l&&(l=null);var c=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RAW);c.baseWidth=i,c.baseHeight=n,c.width=i,c.height=n,c.format=o,c.generateMipMaps=s,c.samplingMode=h,c.invertY=a,c._compression=l,this._doNotHandleContextLost||(c._bufferView=t),this.updateRawTexture(c,t,o,a,l),this._bindTextureDirectly(this._gl.TEXTURE_2D,c);var u=r(h,s,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,u.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,u.min),s&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),this._internalTexturesCache.push(c),c},a.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},a.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},a.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}},a.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}}},a.prototype.createRenderTargetTexture=function(t,i){var n=new h;void 0!==i&&"object"==typeof i?(n.generateMipMaps=i.generateMipMaps,n.generateDepthBuffer=void 0===i.generateDepthBuffer||i.generateDepthBuffer,n.generateStencilBuffer=n.generateDepthBuffer&&i.generateStencilBuffer,n.type=void 0===i.type?a.TEXTURETYPE_UNSIGNED_INT:i.type,n.samplingMode=void 0===i.samplingMode?e.Texture.TRILINEAR_SAMPLINGMODE:i.samplingMode):(n.generateMipMaps=i,n.generateDepthBuffer=!0,n.generateStencilBuffer=!1,n.type=a.TEXTURETYPE_UNSIGNED_INT,n.samplingMode=e.Texture.TRILINEAR_SAMPLINGMODE),n.type!==a.TEXTURETYPE_FLOAT||this._caps.textureFloatLinearFiltering?n.type!==a.TEXTURETYPE_HALF_FLOAT||this._caps.textureHalfFloatLinearFiltering||(n.samplingMode=e.Texture.NEAREST_SAMPLINGMODE):n.samplingMode=e.Texture.NEAREST_SAMPLINGMODE;var o=this._gl,s=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RENDERTARGET);this._bindTextureDirectly(o.TEXTURE_2D,s);var l=t.width||t,c=t.height||t,u=r(n.samplingMode,!!n.generateMipMaps,o);n.type!==a.TEXTURETYPE_FLOAT||this._caps.textureFloat||(n.type=a.TEXTURETYPE_UNSIGNED_INT,e.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type")),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,u.mag),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,u.min),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.texImage2D(o.TEXTURE_2D,0,this._getRGBABufferInternalSizedFormat(n.type),l,c,0,o.RGBA,this._getWebGLTextureType(n.type),null);var p=o.createFramebuffer();return this.bindUnboundFramebuffer(p),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,s._webGLTexture,0),s._depthStencilBuffer=this._setupFramebufferDepthAttachments(!!n.generateStencilBuffer,n.generateDepthBuffer,l,c),n.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(o.TEXTURE_2D,null),o.bindRenderbuffer(o.RENDERBUFFER,null),this.bindUnboundFramebuffer(null),s._framebuffer=p,s.baseWidth=l,s.baseHeight=c,s.width=l,s.height=c,s.isReady=!0,s.samples=1,s.generateMipMaps=!!n.generateMipMaps,s.samplingMode=n.samplingMode,s.type=n.type,s._generateDepthBuffer=n.generateDepthBuffer,s._generateStencilBuffer=!!n.generateStencilBuffer,this.resetTextureCache(),this._internalTexturesCache.push(s),s},a.prototype.createMultipleRenderTarget=function(t,i){var n=!1,o=!0,s=!1,h=!1,l=1,c=a.TEXTURETYPE_UNSIGNED_INT,u=e.Texture.TRILINEAR_SAMPLINGMODE,p=[],f=[];void 0!==i&&(n=i.generateMipMaps,o=void 0===i.generateDepthBuffer||i.generateDepthBuffer,s=i.generateStencilBuffer,h=i.generateDepthTexture,l=i.textureCount||1,i.types&&(p=i.types),i.samplingModes&&(f=i.samplingModes));var d=this._gl,m=d.createFramebuffer();this.bindUnboundFramebuffer(m);for(var g=t.width||t,_=t.height||t,v=[],y=[],b=this._setupFramebufferDepthAttachments(s,o,g,_),x=0;x1?"COLOR_ATTACHMENT"+x:"COLOR_ATTACHMENT"+x+"_WEBGL"];v.push(P),y.push(M),d.activeTexture(d["TEXTURE"+x]),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,_,0,d.RGBA,this._getWebGLTextureType(E),null),d.framebufferTexture2D(d.DRAW_FRAMEBUFFER,M,d.TEXTURE_2D,P._webGLTexture,0),n&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(d.TEXTURE_2D,null),P._framebuffer=m,P._depthStencilBuffer=b,P.baseWidth=g,P.baseHeight=_,P.width=g,P.height=_,P.isReady=!0,P.samples=1,P.generateMipMaps=n,P.samplingMode=T,P.type=E,P._generateDepthBuffer=o,P._generateStencilBuffer=s,this._internalTexturesCache.push(P)}if(h&&this._caps.depthTextureExtension){var S=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_MULTIRENDERTARGET);d.activeTexture(d.TEXTURE0),d.bindTexture(d.TEXTURE_2D,S._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,_,0,d.DEPTH_COMPONENT,d.UNSIGNED_SHORT,null),d.framebufferTexture2D(d.FRAMEBUFFER,d.DEPTH_ATTACHMENT,d.TEXTURE_2D,S._webGLTexture,0),S._framebuffer=m,S.baseWidth=g,S.baseHeight=_,S.width=g,S.height=_,S.isReady=!0,S.samples=1,S.generateMipMaps=n,S.samplingMode=d.NEAREST,S._generateDepthBuffer=o,S._generateStencilBuffer=s,v.push(S),this._internalTexturesCache.push(S)}return d.drawBuffers(y),d.bindRenderbuffer(d.RENDERBUFFER,null),this.bindUnboundFramebuffer(null),this.resetTextureCache(),v},a.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},a.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},a.prototype._uploadDataToTexture=function(e,t,i,r,n,o,s,a){this._gl.texImage2D(e,t,i,r,n,0,o,s,a)},a.prototype._uploadCompressedDataToTexture=function(e,t,i,r,n,o){this._gl.compressedTexImage2D(e,t,i,r,n,0,o)},a.prototype.createRenderTargetCubeTexture=function(t,i){var n=this._gl,o=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RENDERTARGET),s=!0,a=!0,h=!1,l=e.Texture.TRILINEAR_SAMPLINGMODE;void 0!==i&&(s=void 0===i.generateMipMaps||i.generateMipMaps,h=!(!(a=void 0===i.generateDepthBuffer||i.generateDepthBuffer)||!i.generateStencilBuffer),void 0!==i.samplingMode&&(l=i.samplingMode)),o.isCube=!0,o.generateMipMaps=s,o.samples=1,o.samplingMode=l;var c=r(l,s,n);this._bindTextureDirectly(n.TEXTURE_CUBE_MAP,o);for(var u=0;u<6;u++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+u,0,n.RGBA,t,t,0,n.RGBA,n.UNSIGNED_BYTE,null);n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_MAG_FILTER,c.mag),n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_MIN_FILTER,c.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 p=n.createFramebuffer();return this.bindUnboundFramebuffer(p),o._depthStencilBuffer=this._setupFramebufferDepthAttachments(h,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=p,o.width=t,o.height=t,o.isReady=!0,this.resetTextureCache(),this._internalTexturesCache.push(o),o},a.prototype.createPrefilteredCubeTexture=function(t,i,r,n,o,s,a,h){var l=this;void 0===o&&(o=null),void 0===s&&(s=null),void 0===h&&(h=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,l._caps.textureLOD)o&&o(s);else{var a=l._gl,h=t.width;if(h){for(var c=[],u=0;u<3;u++){var p=1-u/2,f=n,d=e.Scalar.Log2(h)*r+n,m=f+(d-f)*p,g=Math.round(Math.min(Math.max(m,0),d)),_=new e.InternalTexture(l,e.InternalTexture.DATASOURCE_TEMP);if(_.isCube=!0,l._bindTextureDirectly(a.TEXTURE_CUBE_MAP,_),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MIN_FILTER,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 v=t.info,y=t.data;a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,v.isCompressed?1:0),e.Internals.DDSTools.UploadDDSLevels(l,l._gl,y,v,!0,6,g)}else e.Tools.Warn("DDS is the only prefiltered cube map supported so far.");l._bindTextureDirectly(a.TEXTURE_CUBE_MAP,null);var b=new e.BaseTexture(i);b.isCube=!0,b._texture=_,_.isReady=!0,c.push(b)}s._lodTextureHigh=c[2],s._lodTextureMid=c[1],s._lodTextureLow=c[0],o&&o(s)}}}else o&&o(null)},s,a,h)},a.prototype.createCubeTexture=function(t,i,r,s,a,h,l,c){var u=this;void 0===a&&(a=null),void 0===h&&(h=null),void 0===c&&(c=null);var p=this._gl,f=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_CUBE);f.isCube=!0,f.url=t,f.generateMipMaps=!s,this._doNotHandleContextLost||(f._extension=c,f._files=r);var d=!1,m=!1,g=t.lastIndexOf("."),_=c||(g>-1?t.substring(g).toLowerCase():"");this._textureFormatInUse?(_=this._textureFormatInUse,t=(g>-1?t.substring(0,g):t)+this._textureFormatInUse,d=!0):m=".dds"===_;var v=function(e,t){h&&e&&h(e.status+" "+e.statusText,t)};if(d)e.Tools.LoadFile(t,function(t){var i=new e.Internals.KhronosTextureContainer(t,6),r=i.numberOfMipmapLevels>1&&!s;u._bindTextureDirectly(p.TEXTURE_CUBE_MAP,f),p.pixelStorei(p.UNPACK_FLIP_Y_WEBGL,1),i.uploadLevels(u._gl,!s),u.setCubeMapTextureParams(p,r),f.width=i.pixelWidth,f.height=i.pixelHeight,f.isReady=!0},void 0,void 0,!0,v);else if(m)r&&6===r.length?function(e,t,i,r,n){void 0===n&&(n=null);var s=[];s._internalCount=0;for(var a=0;a<6;a++)o(r[a],a,s,0,i,n)}(0,0,function(t){for(var i,r=!1,n=0,o=0;o1)&&!s,u._bindTextureDirectly(p.TEXTURE_CUBE_MAP,f),p.pixelStorei(p.UNPACK_FLIP_Y_WEBGL,i.isCompressed?1:0),e.Internals.DDSTools.UploadDDSLevels(u,u._gl,h,i,r,6,-1,o),s||i.isFourCC||1!==i.mipmapCount||p.generateMipmap(p.TEXTURE_CUBE_MAP),f.width=i.width,f.height=i.height,f.type=i.textureType,n=i.width}u.setCubeMapTextureParams(p,r),f.isReady=!0,a&&a({isDDS:!0,width:n,info:i,imgs:t,texture:f})},r,h):e.Tools.LoadFile(t,function(t){var i=e.Internals.DDSTools.GetDDSInfo(t),r=(i.isRGB||i.isLuminance||i.mipmapCount>1)&&!s;u._bindTextureDirectly(p.TEXTURE_CUBE_MAP,f),p.pixelStorei(p.UNPACK_FLIP_Y_WEBGL,i.isCompressed?1:0),e.Internals.DDSTools.UploadDDSLevels(u,u._gl,t,i,r,6),s||i.isFourCC||1!==i.mipmapCount||p.generateMipmap(p.TEXTURE_CUBE_MAP),u.setCubeMapTextureParams(p,r),f.width=i.width,f.height=i.height,f.isReady=!0,f.type=i.textureType,a&&a({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");!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)}(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 n=[p.TEXTURE_CUBE_MAP_POSITIVE_X,p.TEXTURE_CUBE_MAP_POSITIVE_Y,p.TEXTURE_CUBE_MAP_POSITIVE_Z,p.TEXTURE_CUBE_MAP_NEGATIVE_X,p.TEXTURE_CUBE_MAP_NEGATIVE_Y,p.TEXTURE_CUBE_MAP_NEGATIVE_Z];u._bindTextureDirectly(p.TEXTURE_CUBE_MAP,f),p.pixelStorei(p.UNPACK_FLIP_Y_WEBGL,0);for(var o=l?u._getInternalFormat(l):u._gl.RGBA,h=0;h>y,x=0;x<6;x++){var T=v[y][x];_&&(T=f._convertRGBtoRGBATextureData(T,b,b,o)),d.texImage2D(x,y,g,b,b,0,u,c,T)}f._bindTextureDirectly(d.TEXTURE_CUBE_MAP,null)}else m.generateMipMaps=!s,f.updateRawCubeTexture(m,r,n,o,p);m.isReady=!0,f.resetTextureCache(),i._removePendingData(m),l&&l()}}(e)},void 0,i.database,!0,function(e,t){i._removePendingData(m),c&&e&&c(e.status+" "+e.statusText,t)}),m},a.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},a.prototype.createRawTexture3D=function(t,i,n,o,s,a,h,l,c){void 0===c&&(c=null);var u=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RAW3D);u.baseWidth=i,u.baseHeight=n,u.baseDepth=o,u.width=i,u.height=n,u.depth=o,u.format=s,u.generateMipMaps=a,u.samplingMode=l,u.is3D=!0,this._doNotHandleContextLost||(u._bufferView=t),this.updateRawTexture3D(u,t,s,h,c),this._bindTextureDirectly(this._gl.TEXTURE_3D,u);var p=r(l,a,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_MAG_FILTER,p.mag),this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_MIN_FILTER,p.min),a&&this._gl.generateMipmap(this._gl.TEXTURE_3D),this._bindTextureDirectly(this._gl.TEXTURE_3D,null),this._internalTexturesCache.push(u),u},a.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()}},a.prototype._prepareWebGLTexture=function(t,i,r,n,o,s,a,h,l){var c=this;void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE);var u=this.needPOTTextures?e.Tools.GetExponentOfTwo(r,this.getCaps().maxTextureSize):r,p=this.needPOTTextures?e.Tools.GetExponentOfTwo(n,this.getCaps().maxTextureSize):n,f=this._gl;if(f){if(!t._webGLTexture)return this.resetTextureCache(),void(i&&i._removePendingData(t));this._bindTextureDirectly(f.TEXTURE_2D,t),f.pixelStorei(f.UNPACK_FLIP_Y_WEBGL,void 0===o?1:o?1:0),t.baseWidth=r,t.baseHeight=n,t.width=u,t.height=p,t.isReady=!0,h(u,p,function(){c._prepareWebGLTextureContinuation(t,i,s,a,l)})||this._prepareWebGLTextureContinuation(t,i,s,a,l)}},a.prototype._convertRGBtoRGBATextureData=function(e,t,i,r){var n;n=r===a.TEXTURETYPE_FLOAT?new Float32Array(t*i*4):new Uint32Array(t*i*4);for(var o=0;o1&&this._bindTextureDirectly(this._gl.TEXTURE_3D,null)},a.prototype.setTexture=function(e,t,i){e<0||this._setTexture(e,i)&&this._gl.uniform1i(t,e)},a.prototype._setTexture=function(t,i){if(!i)return null!=this._boundTexturesCache[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===a.DELAYLOADSTATE_NOTLOADED)return i.delayLoad(),!1;var n;if(n=i.isReady()?i.getInternalTexture():i.isCube?this.emptyCubeTexture:i.is3D?this.emptyTexture3D:this.emptyTexture,r||this.activateTextureChannel(this._gl.TEXTURE0+t),this._boundTexturesCache[this._activeTextureChannel]===n)return!1;if(n&&n.is3D){if(this._bindTextureDirectly(this._gl.TEXTURE_3D,n),n&&n._cachedWrapU!==i.wrapU)switch(n._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(n&&n._cachedWrapV!==i.wrapV)switch(n._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(n&&n._cachedWrapR!==i.wrapR)switch(n._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(n&&n.isCube){if(this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,n),n._cachedCoordinatesMode!==i.coordinatesMode){n._cachedCoordinatesMode=i.coordinatesMode;var o=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,o),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_T,o)}this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP,i)}else{if(this._bindTextureDirectly(this._gl.TEXTURE_2D,n),n&&n._cachedWrapU!==i.wrapU)switch(n._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(n&&n._cachedWrapV!==i.wrapV)switch(n._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},a.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)},a.prototype.releaseEffects=function(){for(var e in this._compiledEffects)this._deleteProgram(this._compiledEffects[e]._program);this._compiledEffects={}},a.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();a.audioEngine&&a.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=a.Instances.indexOf(this);t>=0&&a.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()},a.prototype.displayLoadingUI=function(){if(e.Tools.IsWindowObjectExist()){var t=this.loadingScreen;t&&t.displayLoadingUI()}},a.prototype.hideLoadingUI=function(){if(e.Tools.IsWindowObjectExist()){var t=this.loadingScreen;t&&t.hideLoadingUI()}},Object.defineProperty(a.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(a.prototype,"loadingUIText",{set:function(e){this.loadingScreen.loadingUIText=e},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"loadingUIBackgroundColor",{set:function(e){this.loadingScreen.loadingUIBackgroundColor=e},enumerable:!0,configurable:!0}),a.prototype.attachContextLostEvent=function(e){this._renderingCanvas&&this._renderingCanvas.addEventListener("webglcontextlost",e,!1)},a.prototype.attachContextRestoredEvent=function(e){this._renderingCanvas&&this._renderingCanvas.addEventListener("webglcontextrestored",e,!1)},a.prototype.getVertexShaderSource=function(e){var t=this._gl.getAttachedShaders(e);return t?this._gl.getShaderSource(t[0]):null},a.prototype.getFragmentShaderSource=function(e){var t=this._gl.getAttachedShaders(e);return t?this._gl.getShaderSource(t[1]):null},a.prototype.getError=function(){return this._gl.getError()},a.prototype.getFps=function(){return this._fps},a.prototype.getDeltaTime=function(){return this._deltaTime},a.prototype._measureFps=function(){this._performanceMonitor.sampleFrame(),this._fps=this._performanceMonitor.averageFPS,this._deltaTime=this._performanceMonitor.instantaneousFrameTime||0},a.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},a.prototype._canRenderToFloatFramebuffer=function(){return this._webGLVersion>1?this._caps.colorBufferFloat:this._canRenderToFramebuffer(e.Engine.TEXTURETYPE_FLOAT)},a.prototype._canRenderToHalfFloatFramebuffer=function(){return this._webGLVersion>1?this._caps.colorBufferFloat:this._canRenderToFramebuffer(e.Engine.TEXTURETYPE_HALF_FLOAT)},a.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,h=new Uint8Array(4);t.readPixels(0,0,1,1,s,a,h),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},a.prototype._getWebGLTextureType=function(e){return e===a.TEXTURETYPE_FLOAT?this._gl.FLOAT:e===a.TEXTURETYPE_HALF_FLOAT?this._gl.HALF_FLOAT_OES:this._gl.UNSIGNED_BYTE},a.prototype._getRGBABufferInternalSizedFormat=function(e){return 1===this._webGLVersion?this._gl.RGBA:e===a.TEXTURETYPE_FLOAT?this._gl.RGBA32F:e===a.TEXTURETYPE_HALF_FLOAT?this._gl.RGBA16F:this._gl.RGBA},a.prototype.createQuery=function(){return this._gl.createQuery()},a.prototype.deleteQuery=function(e){return this._gl.deleteQuery(e),this},a.prototype.isQueryResultAvailable=function(e){return this._gl.getQueryParameter(e,this._gl.QUERY_RESULT_AVAILABLE)},a.prototype.getQueryResult=function(e){return this._gl.getQueryParameter(e,this._gl.QUERY_RESULT)},a.prototype.beginOcclusionQuery=function(e,t){var i=this.getGlAlgorithmType(e);return this._gl.beginQuery(i,t),this},a.prototype.endOcclusionQuery=function(e){var t=this.getGlAlgorithmType(e);return this._gl.endQuery(t),this},a.prototype._createTimeQuery=function(){var e=this._caps.timerQuery;return e.createQueryEXT?e.createQueryEXT():this.createQuery()},a.prototype._deleteTimeQuery=function(e){var t=this._caps.timerQuery;t.deleteQueryEXT?t.deleteQueryEXT(e):this.deleteQuery(e)},a.prototype._getTimeQueryResult=function(e){var t=this._caps.timerQuery;return t.getQueryObjectEXT?t.getQueryObjectEXT(e,t.QUERY_RESULT_EXT):this.getQueryResult(e)},a.prototype._getTimeQueryAvailability=function(e){var t=this._caps.timerQuery;return t.getQueryObjectEXT?t.getQueryObjectEXT(e,t.QUERY_RESULT_AVAILABLE_EXT):this.isQueryResultAvailable(e)},a.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},a.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},a.prototype.getGlAlgorithmType=function(t){return t===e.AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE?this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE:this._gl.ANY_SAMPLES_PASSED},a.prototype.createTransformFeedback=function(){return this._gl.createTransformFeedback()},a.prototype.deleteTransformFeedback=function(e){this._gl.deleteTransformFeedback(e)},a.prototype.bindTransformFeedback=function(e){this._gl.bindTransformFeedback(this._gl.TRANSFORM_FEEDBACK,e)},a.prototype.beginTransformFeedback=function(e){void 0===e&&(e=!0),this._gl.beginTransformFeedback(e?this._gl.POINTS:this._gl.TRIANGLES)},a.prototype.endTransformFeedback=function(){this._gl.endTransformFeedback()},a.prototype.setTranformFeedbackVaryings=function(e,t){this._gl.transformFeedbackVaryings(e,t,this._gl.INTERLEAVED_ATTRIBS)},a.prototype.bindTransformFeedbackBuffer=function(e){this._gl.bindBufferBase(this._gl.TRANSFORM_FEEDBACK_BUFFER,0,e)},a.isSupported=function(){try{var e=document.createElement("canvas");return null!=(e.getContext("webgl")||e.getContext("experimental-webgl"))&&!!window.WebGLRenderingContext}catch(e){return!1}},a.Instances=new Array,a._ALPHA_DISABLE=0,a._ALPHA_ADD=1,a._ALPHA_COMBINE=2,a._ALPHA_SUBTRACT=3,a._ALPHA_MULTIPLY=4,a._ALPHA_MAXIMIZED=5,a._ALPHA_ONEONE=6,a._ALPHA_PREMULTIPLIED=7,a._ALPHA_PREMULTIPLIED_PORTERDUFF=8,a._ALPHA_INTERPOLATE=9,a._ALPHA_SCREENMODE=10,a._DELAYLOADSTATE_NONE=0,a._DELAYLOADSTATE_LOADED=1,a._DELAYLOADSTATE_LOADING=2,a._DELAYLOADSTATE_NOTLOADED=4,a._TEXTUREFORMAT_ALPHA=0,a._TEXTUREFORMAT_LUMINANCE=1,a._TEXTUREFORMAT_LUMINANCE_ALPHA=2,a._TEXTUREFORMAT_RGB=4,a._TEXTUREFORMAT_RGBA=5,a._TEXTURETYPE_UNSIGNED_INT=0,a._TEXTURETYPE_FLOAT=1,a._TEXTURETYPE_HALF_FLOAT=2,a._NEVER=512,a._ALWAYS=519,a._LESS=513,a._EQUAL=514,a._LEQUAL=515,a._GREATER=516,a._GEQUAL=518,a._NOTEQUAL=517,a._KEEP=7680,a._REPLACE=7681,a._INCR=7682,a._DECR=7683,a._INVERT=5386,a._INCR_WRAP=34055,a._DECR_WRAP=34056,a._SCALEMODE_FLOOR=1,a._SCALEMODE_NEAREST=2,a._SCALEMODE_CEILING=3,a.CollisionsEpsilon=.001,a.CodeRepository="src/",a.ShadersRepository="src/Shaders/",a}();e.Engine=c}(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,i,r){var n=t(e,i),o=t(e,r);return function(e,t,i,r){return!(e>r||i>t)}(n.min,n.max,o.min,o.max)},r=function(){function t(t,i){this.minimum=t,this.maximum=i,this._isLocked=!1,this.boundingBox=new e.BoundingBox(t,i),this.boundingSphere=new e.BoundingSphere(t,i)}return Object.defineProperty(t.prototype,"isLocked",{get:function(){return this._isLocked},set:function(e){this._isLocked=e},enumerable:!0,configurable:!0}),t.prototype.update=function(e){this._isLocked||(this.boundingBox._update(e),this.boundingSphere._update(e))},t.prototype.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,r){if(!this.boundingSphere.centerWorld||!t.boundingSphere.centerWorld)return!1;if(!e.BoundingSphere.Intersects(this.boundingSphere,t.boundingSphere))return!1;if(!e.BoundingBox.Intersects(this.boundingBox,t.boundingBox))return!1;if(!r)return!0;var n=this.boundingBox,o=t.boundingBox;return!!i(n.directions[0],n,o)&&(!!i(n.directions[1],n,o)&&(!!i(n.directions[2],n,o)&&(!!i(o.directions[0],n,o)&&(!!i(o.directions[1],n,o)&&(!!i(o.directions[2],n,o)&&(!!i(e.Vector3.Cross(n.directions[0],o.directions[0]),n,o)&&(!!i(e.Vector3.Cross(n.directions[0],o.directions[1]),n,o)&&(!!i(e.Vector3.Cross(n.directions[0],o.directions[2]),n,o)&&(!!i(e.Vector3.Cross(n.directions[1],o.directions[0]),n,o)&&(!!i(e.Vector3.Cross(n.directions[1],o.directions[1]),n,o)&&(!!i(e.Vector3.Cross(n.directions[1],o.directions[2]),n,o)&&(!!i(e.Vector3.Cross(n.directions[2],o.directions[0]),n,o)&&(!!i(e.Vector3.Cross(n.directions[2],o.directions[1]),n,o)&&!!i(e.Vector3.Cross(n.directions[2],o.directions[2]),n,o))))))))))))))},t}();e.BoundingInfo=r}(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 h=-Math.atan2(s.z,s.x)-Math.PI/2,l=Math.sqrt(s.x*s.x+s.z*s.z),c=Math.atan2(s.y,l);return this.rotationQuaternion=this.rotationQuaternion||new e.Quaternion,e.Quaternion.RotationYawPitchRollToRef(h+i,c+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){if(null==t){var i=e.Tmp.Quaternion[0],r=e.Tmp.Vector3[0],n=e.Tmp.Vector3[1];this.parent&&this.parent.computeWorldMatrix&&this.parent.computeWorldMatrix(!0),this.computeWorldMatrix(!0),this.getWorldMatrix().decompose(n,i,r),this.rotationQuaternion?this.rotationQuaternion.copyFrom(i):i.toEulerAnglesToRef(this.rotation),this.scaling.x=n.x,this.scaling.y=n.y,this.scaling.z=n.z,this.position.x=r.x,this.position.y=r.y,this.position.z=r.z}else{var i=e.Tmp.Quaternion[0],r=e.Tmp.Vector3[0],n=e.Tmp.Vector3[1],o=e.Tmp.Matrix[0],s=e.Tmp.Matrix[1];this.computeWorldMatrix(!0),t.computeWorldMatrix(!0),t.getWorldMatrix().invertToRef(s),this.getWorldMatrix().multiplyToRef(s,o),o.decompose(n,i,r),this.rotationQuaternion?this.rotationQuaternion.copyFrom(i):i.toEulerAnglesToRef(this.rotation),this.position.x=r.x,this.position.y=r.y,this.position.z=r.z,this.scaling.x=n.x,this.scaling.y=n.y,this.scaling.z=n.z}return this.parent=t,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;if(this._cache.position.copyFrom(this.position),this._cache.scaling.copyFrom(this.scaling),this._cache.pivotMatrixUpdated=!1,this._cache.billboardMode=this.billboardMode,this._currentRenderId=this.getScene().getRenderId(),this._isDirty=!1,e.Matrix.ScalingToRef(this.scaling.x*this.scalingDeterminant,this.scaling.y*this.scalingDeterminant,this.scaling.z*this.scalingDeterminant,e.Tmp.Matrix[1]),this.rotationQuaternion){this.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,n){var o=this,s=e.SerializationHelper.Clone(function(){return new i(t,o.getScene())},this);if(s.name=t,s.id=t,r&&(s.parent=r),!n)for(var a=this.getDescendants(!0),h=0;he.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()),h=this._submeshesOctree.intersectsRay(a);o=h.length,n=h.data}else o=(n=this.subMeshes).length;for(var l=0;l1)||c.canIntersects(t)){var u=c.intersects(t,this._positions,this.getIndices(),i);if(u&&(i||!s||u.distance65535){o=!0;break}this._depthSortedIndices=o?new Uint32Array(i):new Uint16Array(i)}if(this._facetDepthSortFunction=function(e,t){return t.sqDistance-e.sqDistance},!this._facetDepthSortFrom){var a=this.getScene().activeCamera;this._facetDepthSortFrom=a?a.position:e.Vector3.Zero()}this._depthSortedFacets=[];for(u=0;ue.Epsilon?n.maximum.x-n.minimum.x:e.Epsilon,this._bbSize.y=n.maximum.y-n.minimum.y>e.Epsilon?n.maximum.y-n.minimum.y:e.Epsilon,this._bbSize.z=n.maximum.z-n.minimum.z>e.Epsilon?n.maximum.z-n.minimum.z:e.Epsilon;var l=this._bbSize.x>this._bbSize.y?this._bbSize.x:this._bbSize.y;if(l=l>this._bbSize.z?l:this._bbSize.z,this._subDiv.max=this._partitioningSubdivisions,this._subDiv.X=Math.floor(this._subDiv.max*this._bbSize.x/l),this._subDiv.Y=Math.floor(this._subDiv.max*this._bbSize.y/l),this._subDiv.Z=Math.floor(this._subDiv.max*this._bbSize.z/l),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=n,this._facetParameters.bbSize=this._bbSize,this._facetParameters.subDiv=this._subDiv,this._facetParameters.ratio=this.partitioningBBoxRatio,this._facetParameters.depthSort=this._facetDepthSort,this._facetDepthSort&&this._facetDepthSortEnabled&&(this.computeWorldMatrix(!0),this._worldMatrix.invertToRef(this._invertedMatrix),e.Vector3.TransformCoordinatesToRef(this._facetDepthSortFrom,this._invertedMatrix,this._facetDepthSortOrigin),this._facetParameters.distanceTo=this._facetDepthSortOrigin),this._facetParameters.depthSortedFacets=this._depthSortedFacets,e.VertexData.ComputeNormals(t,i,r,this._facetParameters),this._facetDepthSort&&this._facetDepthSortEnabled){this._depthSortedFacets.sort(this._facetDepthSortFunction);for(var c=this._depthSortedIndices.length/3|0,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(),h=e.Tmp.Matrix[5];a.invertToRef(h);var l=e.Tmp.Vector3[8];e.Vector3.TransformCoordinatesFromFloatsToRef(t,i,r,h,l);var c=this.getClosestFacetAtLocalCoordinates(l.x,l.y,l.z,n,o,s);return n&&e.Vector3.TransformCoordinatesFromFloatsToRef(n.x,n.y,n.z,a,n),c},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,h=0,l=0,c=0,u=0,p=0,f=0,d=0,m=this.getFacetLocalPositions(),g=this.getFacetLocalNormals(),_=this.getFacetsAtLocalCoordinates(e,t,i);if(!_)return null;for(var v,y,b,x=Number.MAX_VALUE,T=x,E=0;E<_.length;E++)y=g[v=_[E]],c=(e-(b=m[v]).x)*y.x+(t-b.y)*y.y+(i-b.z)*y.z,(!n||n&&o&&c>=0||n&&!o&&c<=0)&&(c=y.x*b.x+y.y*b.y+y.z*b.z,u=-(y.x*e+y.y*t+y.z*i-c)/(y.x*y.x+y.y*y.y+y.z*y.z),(T=(a=(p=e+y.x*u)-e)*a+(h=(f=t+y.y*u)-t)*h+(l=(d=i+y.z*u)-i)*l)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(){this._worldMatrix||(this._worldMatrix=e.Matrix.Identity());return 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 h=r.vrCameraMetrics||e.VRCameraMetrics.GetDefault();this._rigCameras[0]._cameraRigParams.vrMetrics=h,this._rigCameras[0].viewport=new e.Viewport(0,0,.5,1),this._rigCameras[0]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[0]._cameraRigParams.vrHMatrix=h.leftHMatrix,this._rigCameras[0]._cameraRigParams.vrPreViewMatrix=h.leftPreViewMatrix,this._rigCameras[0].getProjectionMatrix=this._rigCameras[0]._getVRProjectionMatrix,this._rigCameras[1]._cameraRigParams.vrMetrics=h,this._rigCameras[1].viewport=new e.Viewport(.5,0,.5,1),this._rigCameras[1]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[1]._cameraRigParams.vrHMatrix=h.rightHMatrix,this._rigCameras[1]._cameraRigParams.vrPreViewMatrix=h.rightPreViewMatrix,this._rigCameras[1].getProjectionMatrix=this._rigCameras[1]._getVRProjectionMatrix,h.compensateDistortion&&(this._rigCameras[0]._rigPostProcess=new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Left",this._rigCameras[0],!1,h),this._rigCameras[1]._rigPostProcess=new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Right",this._rigCameras[1],!0,h));break;case i.RIG_MODE_WEBVR:if(r.vrDisplay){var l=r.vrDisplay.getEyeParameters("left"),c=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",l),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",c),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 h=new t;s._currentPickResult=null;var l=null,c=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(!c&&e.ActionManager&&e.ActionManager.HasPickTriggers&&(l=s._initActionManager(l,h))&&(c=l.hasPickTriggers),c){var u=o.button;if(h.hasSwiped=Math.abs(s._startingPointerPosition.x-s._pointerX)>i.DragMovementThreshold||Math.abs(s._startingPointerPosition.y-s._pointerY)>i.DragMovementThreshold,!h.hasSwiped){var p=!i.ExclusiveDoubleClickMode;p||(p=!r.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP)&&!n.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP))&&!e.ActionManager.HasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)&&(l=s._initActionManager(l,h))&&(p=!l.hasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)),p?((new Date).getTime()-s._previousStartingPointerTime>i.DoubleClickDelay||u!==s._previousButtonPressed)&&(h.singleClick=!0,a(h,s._currentPickResult)):(s._previousDelayedSimpleClickTimeout=s._delayedSimpleClickTimeout,s._delayedSimpleClickTimeout=window.setTimeout(s._delayedSimpleClick.bind(s,u,h,a),i.DoubleClickDelay));var f=r.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP)||n.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP);!f&&e.ActionManager.HasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)&&(l=s._initActionManager(l,h))&&(f=l.hasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)),f&&(u===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 h=s.pickSprite(s._unTranslatedPointerX,s._unTranslatedPointerY,s._spritePredicate,!1,s.cameraToUseForPointers||void 0);h&&(h.hit&&h.pickedSprite&&h.pickedSprite.actionManager&&(h.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNewFromSprite(h.pickedSprite,s,t)),h.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 h=t.getAnimatables(),l=0;l0)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);if(r)return r;return 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);if(r)return r;return 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 h=this._engine.getStencilBuffer(),l=!1;if(this.renderTargetsEnabled&&this.highlightLayers&&this.highlightLayers.length>0){this._intermediateRendering=!0;for(g=0;g-1)){l=!0;var u=c._mainTexture;u._shouldRender()&&(this._renderId++,u.render(!1,!1),o=!0)}}this._intermediateRendering=!1,this._renderId++}o&&i.restoreDefaultFramebuffer(),this.OnAfterRenderTargetsRenderObservable.notifyObservers(this),this.postProcessManager._prepareFrame();var p,f;if(this.layers.length){for(i.setDepthBuffer(!1),p=0;p0);for(var d=0;d0)}if(this.layers.length){for(i.setDepthBuffer(!1),p=0;p-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(h,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))+this._timeAccumulator,r=1e3/60;this._physicsEngine&&(r=this._physicsEngine.getTimeStep()/1e3);var n=0,o=this._engine.getLockstepMaxSteps(),s=Math.floor(t/60);s=Math.min(s,o);do{this.onBeforeStepObservable.notifyObservers(this),this._animationRatio=.06*r,this._animate(),this.onAfterAnimationsObservable.notifyObservers(this),this._physicsEngine&&(this.onBeforePhysicsObservable.notifyObservers(this),this._physicsEngine._step(.06),this.onAfterPhysicsObservable.notifyObservers(this)),this.onAfterStepObservable.notifyObservers(this),this._currentStepId++,s>1&&n!=s-1&&this._evaluateActiveMeshes(),n++,t-=r}while(t>0&&n0),this._intermediateRendering=!0;for(var l=0;l0),this._intermediateRendering=!1,this._renderId++}if(this.customRenderTargets.length>0&&a.restoreDefaultFramebuffer(),this.OnAfterRenderTargetsRenderObservable.notifyObservers(this),this.activeCamera=h,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 _=0;_0&&this._engine.clear(null,!1,!0,!0),this._processSubCameras(this.activeCameras[_]);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=h,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=h,r))break}}return o||new e.PickingInfo},i.prototype.pick=function(t,i,r,n,o){var s=this;return this._tempPickingRay||(this._tempPickingRay=e.Ray.Zero()),this._internalPick(function(e){return s.createPickingRayToRef(t,i,e,s._tempPickingRay,o||null),s._tempPickingRay},r,n)},i.prototype.pickSprite=function(t,i,r,n,o){return this._tempPickingRay||(this._tempPickingRay=e.Ray.Zero()),this.createPickingRayInCameraSpaceToRef(t,i,this._tempPickingRay,o),this._internalPickSprites(this._tempPickingRay,r,n,o)},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=e.Ray.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=e.Ray.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=function(){if((r=e[s]).isReady())0==--i&&t();else{var o=function(){n.removeCallback(o),0==--i&&t()};(n=r.onLoadObservable).add(o)}},s=0;s0},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;tr)return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var n=0;n0){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(h.verticesStart+h.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,h=this._instancesBufferSize,l=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,h=a?this.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind):null,l=a?this.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind):null;if(!l||!h)return this;for(var c,u=t.getTransformMatrices(this),p=e.Vector3.Zero(),f=new e.Matrix,d=new e.Matrix,m=0,g=0;g0;c++)e.Matrix.FromFloat32ArrayToRefScaled(u,16*o[m+c],_,d),f.addToSelf(d);if(a)for(c=0;c<4&&(_=l[m+c])>0;c++)e.Matrix.FromFloat32ArrayToRefScaled(u,16*h[m+c],_,d),f.addToSelf(d);e.Vector3.TransformCoordinatesFromFloatsToRef(this._sourcePositions[g],this._sourcePositions[g+1],this._sourcePositions[g+2],f,p),p.toArray(r,g),e.Vector3.TransformNormalFromFloatsToRef(this._sourceNormals[g],this._sourceNormals[g+1],this._sourceNormals[g+2],f,p),p.toArray(n,g),f.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().boundingBox;i&&r?(i.MinimizeInPlace(o.minimumWorld),r.MaximizeInPlace(o.maximumWorld)):(i=o.minimumWorld,r=o.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 h=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 l,c=null,u=new Array,p=null;for(a=0;aa&&(a=c)}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._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 h="\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+h)):this.name.vertex?(e.Tools.Error("Vertex shader: "+this.name.vertex+a),e.Tools.Error("Fragment shader: "+this.name.fragment+h)):(e.Tools.Error("Vertex shader: "+this.name+a),e.Tools.Error("Fragment shader: "+this.name+h))},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 h=s[1];if(-1!==h.indexOf("__decl__")&&(h=h.replace(/__decl__/,""),this._engine.supportsUniformBuffers&&(h=(h=h.replace(/Vertex/,"Ubo")).replace(/Fragment/,"Ubo")),h+="Declaration"),!t.IncludesShadersStore[h]){var l=e.Engine.ShadersRepository+"ShadersInclude/"+h+".fx";return void e.Tools.LoadFile(l,function(e){t.IncludesShadersStore[h]=e,n._processIncludes(a,r)})}var c=t.IncludesShadersStore[h];if(s[2])for(var u=s[3].split(","),p=0;p1)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=h.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,h=!1,l=!1,c=!1,u=!1,p=!1;if(t.lightsEnabled&&!s)for(var f=0,d=i._lightSources;f0&&(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,h=s&&s.supportsTangents&&r.TANGENT,l=0;lo&&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 h=0,l=0,c=r._lightSources;l=0&&this._scene.materials.splice(i,1),i=0;ia?a:Math.floor(h);var l,c,u,p,f=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,d=i.uvs,m=i.colors,g=[],_=[],v=[],y=[],b=[],x=[],T=[],E=[],A=[],P=[];if(r.length<2){var M=[],S=[];for(u=0;u0&&(w=C[p].subtract(C[p-1]).length()+T[c],b[c].push(w),T[c]=w),p++;o&&(p--,g.push(C[0].x,C[0].y,C[0].z),w=C[p].subtract(C[0]).length()+T[c],b[c].push(w),T[c]=w),A[c]=R+O,P[c]=I,I+=R+O}var D,L,F=null,N=null;for(u=0;u1)?1:i.arc||1,h=i.slice&&i.slice<=0?1:i.slice||1,l=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,c=new e.Vector3(n/2,o/2,s/2),u=2+r,p=2*u,f=[],d=[],m=[],g=[],_=0;_<=u;_++){for(var v=_/u,y=v*Math.PI*h,b=0;b<=p;b++){var x=b/p,T=x*Math.PI*2*a,E=e.Matrix.RotationZ(-y),A=e.Matrix.RotationY(T),P=e.Vector3.TransformCoordinates(e.Vector3.Up(),E),M=e.Vector3.TransformCoordinates(P,A),S=M.multiply(c),C=M.divide(c).normalize();d.push(S.x,S.y,S.z),m.push(C.x,C.y,C.z),g.push(x,v)}if(_>0)for(var R=d.length/3,I=R-2*(p+1);I+p+21)?1:i.arc||1,p=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,f=i.faceUV||new Array(3),d=i.faceColors,m=2+(1+(1!==u&&c?2:0))*(l?h:1);for(r=0;r0&&(i.push(a-1),i.push(a)),a++}var p=new t;return p.indices=i,p.positions=r,o&&(p.colors=s),p},t.CreateDashedLines=function(i){var r=i.dashSize||3,n=i.gapSize||1,o=i.dashNb||200,s=i.points,a=new Array,h=new Array,l=e.Vector3.Zero(),c=0,u=0,p=0,f=0,d=0,m=0,g=0;for(g=0;g1)?1:i.arc||1,c=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE;r.push(0,0,0),s.push(.5,.5);for(var u=2*Math.PI*l,p=u/h,f=0;f=r.length)?0:i.type||0,u=i.size,p=i.sizeX||u||1,f=i.sizeY||u||1,d=i.sizeZ||u||1,m=i.custom||r[c],g=m.face.length,_=i.faceUV||new Array(g),v=i.faceColors,y=void 0===i.flat||i.flat,b=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,x=new Array,T=new Array,E=new Array,A=new Array,P=new Array,M=0,S=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,D=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 h=new Float32Array(i,a.positionsAttrDesc.offset,a.positionsAttrDesc.count);r.setVerticesData(e.VertexBuffer.PositionKind,h,!1)}if(a.normalsAttrDesc&&a.normalsAttrDesc.count>0){var l=new Float32Array(i,a.normalsAttrDesc.offset,a.normalsAttrDesc.count);r.setVerticesData(e.VertexBuffer.NormalKind,l,!1)}if(a.uvsAttrDesc&&a.uvsAttrDesc.count>0){var c=new Float32Array(i,a.uvsAttrDesc.offset,a.uvsAttrDesc.count);r.setVerticesData(e.VertexBuffer.UVKind,c,!1)}if(a.uvs2AttrDesc&&a.uvs2AttrDesc.count>0){var u=new Float32Array(i,a.uvs2AttrDesc.offset,a.uvs2AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV2Kind,u,!1)}if(a.uvs3AttrDesc&&a.uvs3AttrDesc.count>0){var p=new Float32Array(i,a.uvs3AttrDesc.offset,a.uvs3AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV3Kind,p,!1)}if(a.uvs4AttrDesc&&a.uvs4AttrDesc.count>0){var f=new Float32Array(i,a.uvs4AttrDesc.offset,a.uvs4AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV4Kind,f,!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 _=new Int32Array(i,a.matricesIndicesAttrDesc.offset,a.matricesIndicesAttrDesc.count);r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,_,!1)}if(a.matricesWeightsAttrDesc&&a.matricesWeightsAttrDesc.count>0){var v=new Float32Array(i,a.matricesWeightsAttrDesc.offset,a.matricesWeightsAttrDesc.count);r.setVerticesData(e.VertexBuffer.MatricesWeightsKind,v,!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 b=new Int32Array(i,a.subMeshesAttrDesc.offset,5*a.subMeshesAttrDesc.count);r.subMeshes=[];for(S=0;S>8),M.push((16711680&C)>>16),M.push(C>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,M,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 M=[],S=0;S>8),M.push((16711680&C)>>16),M.push(C>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,M,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,h=t.matricesWeightsExtra,l=t.numBoneInfluencer,c=a.length,u=0;ul-1)&&(f=l-1),p>.001){for(var g=1/p,d=0;d<4;d++)a[u+d]*=g;if(h)for(d=0;d<4;d++)h[u+d]*=g}else f>=4?(h[u+f-4]=1-p,s[u+f-4]=r):(a[u+f]=1-p,o[u+f]=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,h,l,c){void 0===c&&(c=e.Mesh.DEFAULTSIDE);var u=t.call(this,i,r,h,l)||this;return u.pathArray=n,u.closeArray=o,u.closePath=s,u.offset=a,u.side=c,u}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 h=i.call(this,t,r,o,s)||this;return h.size=n,h.side=a,h}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,h){void 0===a&&(a=null),void 0===h&&(h=e.Mesh.DEFAULTSIDE);var l=i.call(this,t,r,s,a)||this;return l.segments=n,l.diameter=o,l.side=h,l}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 h=function(t){function i(i,r,n,o,s,a,h){void 0===a&&(a=null),void 0===h&&(h=e.Mesh.DEFAULTSIDE);var l=t.call(this,i,r,s,a)||this;return l.radius=n,l.tessellation=o,l.side=h,l}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=h;var l=function(i){function r(t,r,n,o,s,a,h,l,c,u){void 0===h&&(h=1),void 0===c&&(c=null),void 0===u&&(u=e.Mesh.DEFAULTSIDE);var p=i.call(this,t,r,l,c)||this;return p.height=n,p.diameterTop=o,p.diameterBottom=s,p.tessellation=a,p.subdivisions=h,p.side=u,p}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=l;var c=function(i){function r(t,r,n,o,s,a,h,l){void 0===h&&(h=null),void 0===l&&(l=e.Mesh.DEFAULTSIDE);var c=i.call(this,t,r,a,h)||this;return c.diameter=n,c.thickness=o,c.tessellation=s,c.side=l,c}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=c;var u=function(i){function r(e,t,r,n,o,s,a){void 0===a&&(a=null);var h=i.call(this,e,t,s,a)||this;return h.width=r,h.height=n,h.subdivisions=o,h}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=u;var p=function(t){function i(e,i,r,n,o,s,a,h,l,c){void 0===c&&(c=null);var u=t.call(this,e,i,l,c)||this;return u.xmin=r,u.zmin=n,u.xmax=o,u.zmax=s,u.subdivisions=a,u.precision=h,u}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=p;var f=function(i){function r(t,r,n,o,s,a){void 0===s&&(s=null),void 0===a&&(a=e.Mesh.DEFAULTSIDE);var h=i.call(this,t,r,o,s)||this;return h.size=n,h.side=a,h}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=f;var d=function(i){function r(t,r,n,o,s,a,h,l,c,u,p){void 0===u&&(u=null),void 0===p&&(p=e.Mesh.DEFAULTSIDE);var f=i.call(this,t,r,c,u)||this;return f.radius=n,f.tube=o,f.radialSegments=s,f.tubularSegments=a,f.p=h,f.q=l,f.side=p,f}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;if(!i)return!1;return!(!(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._isEnabled=!0,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}),Object.defineProperty(t.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(e){this._isEnabled!==e&&(this._isEnabled=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||!this._isEnabled)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&&this._isEnabled);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 h=-2*this.vignetteWeight;t.setFloat4("vignetteSettings2",this.vignetteColor.r,this.vignetteColor.g,this.vignetteColor.b,h)}if(t.setFloat("exposureLinear",this.exposure),t.setFloat("contrast",this.contrast),this.colorGradingTexture){t.setTexture("txColorTransform",this.colorGradingTexture);var l=this.colorGradingTexture.getSize().height;t.setFloat4("colorTransformSettings",(l-1)/l,.5/l,l,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),r([e.serialize()],t.prototype,"_isEnabled",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){if("string"==typeof n){for(var o,s=null,a=null,h=n.split("\n"),l=0,c=0,u=0,p=0,f=0,d=0;d0&&(d+1)%4==0)s[d]=255;else{var b=a[d];s[d]=b/f*255}t.is3D?(t.updateSize(l,l,l),r.updateRawTexture3D(t,s,e.Engine.TEXTUREFORMAT_RGBA,!1)):(t.updateSize(l*l,l),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 h=Math.floor(o),l=o-h,c=a*(1-s),u=a*(1-s*l),p=a*(1-s*(1-l));switch(h){case 0:n.r=a,n.g=p,n.b=c;break;case 1:n.r=u,n.g=a,n.b=c;break;case 2:n.r=c,n.g=a,n.b=p;break;case 3:n.r=c,n.g=u,n.b=a;break;case 4:n.r=p,n.g=c,n.b=a;break;default:n.r=a,n.g=c,n.b=u}}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,h,a,n),a.isDirty){a.markAsProcessed(),s.resetCachedMaterial();var l=new e.EffectFallbacks;a.REFLECTION&&l.addFallback(0,"REFLECTION"),a.SPECULAR&&l.addFallback(0,"SPECULAR"),a.BUMP&&l.addFallback(0,"BUMP"),a.PARALLAX&&l.addFallback(1,"PARALLAX"),a.PARALLAXOCCLUSION&&l.addFallback(0,"PARALLAXOCCLUSION"),a.SPECULAROVERALPHA&&l.addFallback(0,"SPECULAROVERALPHA"),a.FOG&&l.addFallback(1,"FOG"),a.POINTSIZE&&l.addFallback(0,"POINTSIZE"),a.LOGARITHMICDEPTH&&l.addFallback(0,"LOGARITHMICDEPTH"),e.MaterialHelper.HandleFallbacksForShadows(a,l,this._maxSimultaneousLights),a.SPECULARTERM&&l.addFallback(0,"SPECULARTERM"),a.DIFFUSEFRESNEL&&l.addFallback(1,"DIFFUSEFRESNEL"),a.OPACITYFRESNEL&&l.addFallback(2,"OPACITYFRESNEL"),a.REFLECTIONFRESNEL&&l.addFallback(3,"REFLECTIONFRESNEL"),a.EMISSIVEFRESNEL&&l.addFallback(4,"EMISSIVEFRESNEL"),a.FRESNEL&&l.addFallback(4,"FRESNEL");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),a.VERTEXCOLOR&&c.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(c,i,a,l),e.MaterialHelper.PrepareAttributesForInstances(c,a),e.MaterialHelper.PrepareAttributesForMorphTargets(c,i,a);var u="default",p=["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"],f=["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","lightmapSampler","refractionCubeSampler","refraction2DSampler"],d=["Material","Scene"];e.ImageProcessingConfiguration.PrepareUniforms(p,a),e.ImageProcessingConfiguration.PrepareSamplers(f,a),e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:p,uniformBuffersNames:d,samplers:f,defines:a,maxSimultaneousLights:this._maxSimultaneousLights}),this.customShaderNameResolve&&(u=this.customShaderNameResolve(u,p,d,f,a));var m=a.toString();r.setEffect(s.getEngine().createEffect(u,{attributes:c,uniformsNames:p,uniformBuffersNames:d,samplers:f,defines:m,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights,maxSimultaneousMorphTargets:a.NUM_MORPH_INFLUENCERS}},h),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 h=this._mustRebind(n,a,i.visibility);if(e.MaterialHelper.BindBonesParameters(i,a),h){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)){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(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 l=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)}!h&&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.applyByPostProcess||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.RADIANCEOCCLUSION=!1,t.HORIZONOCCLUSION=!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._useHorizonOcclusion=!1,n._useRadianceOcclusion=!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 h=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 l=this._getReflectionTexture();if(l&&e.StandardMaterial.ReflectionTextureEnabled){if(!l.isReadyOrNotBlocking())return!1;switch(a.REFLECTION=!0,a.GAMMAREFLECTION=l.gammaSpace,a.REFLECTIONMAP_OPPOSITEZ=this.getScene().useRightHandedSystem?!l.invertZ:l.invertZ,a.LODINREFLECTIONALPHA=l.lodLevelInAlpha,l.coordinatesMode===e.Texture.INVCUBIC_MODE&&(a.INVERTCUBICMAP=!0),a.REFLECTIONMAP_3D=l.isCube,l.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}l.coordinatesMode!==e.Texture.SKYBOX_MODE&&l.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 c=this._getRefractionTexture();if(c&&e.StandardMaterial.RefractionTextureEnabled){if(!c.isReadyOrNotBlocking())return!1;a.REFRACTION=!0,a.REFRACTIONMAP_3D=c.isCube,a.GAMMAREFRACTION=c.gammaSpace,a.REFRACTIONMAP_OPPOSITEZ=l.invertZ,a.LODINREFRACTIONALPHA=l.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,a.RADIANCEOCCLUSION=this._useRadianceOcclusion,a.HORIZONOCCLUSION=this._useHorizonOcclusion,e.MaterialHelper.PrepareDefinesForMisc(i,s,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,a),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,h,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 u=new e.EffectFallbacks,p=0;a.USESPHERICALINVERTEX&&u.addFallback(p++,"USESPHERICALINVERTEX"),a.FOG&&u.addFallback(p,"FOG"),a.POINTSIZE&&u.addFallback(p,"POINTSIZE"),a.LOGARITHMICDEPTH&&u.addFallback(p,"LOGARITHMICDEPTH"),a.PARALLAX&&u.addFallback(p,"PARALLAX"),a.PARALLAXOCCLUSION&&u.addFallback(p++,"PARALLAXOCCLUSION"),a.ENVIRONMENTBRDF&&u.addFallback(p++,"ENVIRONMENTBRDF"),a.TANGENT&&u.addFallback(p++,"TANGENT"),a.BUMP&&u.addFallback(p++,"BUMP"),p=e.MaterialHelper.HandleFallbacksForShadows(a,u,this._maxSimultaneousLights,p++),a.SPECULARTERM&&u.addFallback(p++,"SPECULARTERM"),a.USESPHERICALFROMREFLECTIONMAP&&u.addFallback(p++,"USESPHERICALFROMREFLECTIONMAP"),a.LIGHTMAP&&u.addFallback(p++,"LIGHTMAP"),a.NORMAL&&u.addFallback(p++,"NORMAL"),a.AMBIENT&&u.addFallback(p++,"AMBIENT"),a.EMISSIVE&&u.addFallback(p++,"EMISSIVE"),a.VERTEXCOLOR&&u.addFallback(p++,"VERTEXCOLOR"),a.NUM_BONE_INFLUENCERS>0&&u.addCPUSkinningFallback(p++,i),a.MORPHTARGETS&&u.addFallback(p++,"MORPHTARGETS");var f=[e.VertexBuffer.PositionKind];a.NORMAL&&f.push(e.VertexBuffer.NormalKind),a.TANGENT&&f.push(e.VertexBuffer.TangentKind),a.UV1&&f.push(e.VertexBuffer.UVKind),a.UV2&&f.push(e.VertexBuffer.UV2Kind),a.VERTEXCOLOR&&f.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(f,i,a,u),e.MaterialHelper.PrepareAttributesForInstances(f,a),e.MaterialHelper.PrepareAttributesForMorphTargets(f,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 _=function(e){o.onCompiled&&o.onCompiled(e),o.bindSceneUniformBuffer(e,s.getSceneUniformBuffer())},v=a.toString();r.setEffect(s.getEngine().createEffect("pbr",{attributes:f,uniformsNames:d,uniformBuffersNames:g,samplers:m,defines:v,fallbacks:u,onCompiled:_,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights,maxSimultaneousMorphTargets:a.NUM_MORPH_INFLUENCERS}},h),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 h=null;if(a){this._uniformBuffer.bindToEffect(s,"Material"),this.bindViewProjection(s),h=this._getReflectionTexture();var l=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")),h&&e.StandardMaterial.ReflectionTextureEnabled){this._uniformBuffer.updateMatrix("reflectionMatrix",h.getReflectionTextureMatrix()),this._uniformBuffer.updateFloat2("vReflectionInfos",h.level,0);var c=h.sphericalPolynomial;o.USESPHERICALFROMREFLECTIONMAP&&c&&(this._activeEffect.setFloat3("vSphericalX",c.x.x,c.x.y,c.x.z),this._activeEffect.setFloat3("vSphericalY",c.y.x,c.y.y,c.y.z),this._activeEffect.setFloat3("vSphericalZ",c.z.x,c.z.y,c.z.z),this._activeEffect.setFloat3("vSphericalXX_ZZ",c.xx.x-c.zz.x,c.xx.y-c.zz.y,c.xx.z-c.zz.z),this._activeEffect.setFloat3("vSphericalYY_ZZ",c.yy.x-c.zz.x,c.yy.y-c.zz.y,c.yy.z-c.zz.z),this._activeEffect.setFloat3("vSphericalZZ",c.zz.x,c.zz.y,c.zz.z),this._activeEffect.setFloat3("vSphericalXY",c.xy.x,c.xy.y,c.xy.z),this._activeEffect.setFloat3("vSphericalYZ",c.yz.x,c.yz.y,c.yz.z),this._activeEffect.setFloat3("vSphericalZX",c.zx.x,c.zx.y,c.zx.z)),this._uniformBuffer.updateFloat3("vReflectionMicrosurfaceInfos",h.getSize().width,h.lodGenerationScale,h.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)),l&&e.StandardMaterial.RefractionTextureEnabled){this._uniformBuffer.updateMatrix("refractionMatrix",l.getReflectionTextureMatrix());var u=1;l.isCube||l.depth&&(u=l.depth),this._uniformBuffer.updateFloat4("vRefractionInfos",l.level,this._indexOfRefraction,u,this._invertRefractionY?-1:1),this._uniformBuffer.updateFloat3("vRefractionMicrosurfaceInfos",l.getSize().width,l.lodGenerationScale,l.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),h&&e.StandardMaterial.ReflectionTextureEnabled&&(o.LODBASEDMICROSFURACE?this._uniformBuffer.setTexture("reflectionSampler",h):(this._uniformBuffer.setTexture("reflectionSampler",h._lodTextureMid||h),this._uniformBuffer.setTexture("reflectionSamplerLow",h._lodTextureLow||h),this._uniformBuffer.setTexture("reflectionSamplerHigh",h._lodTextureHigh||h))),o.ENVIRONMENTBRDF&&this._uniformBuffer.setTexture("environmentBrdfSampler",this._environmentBRDFTexture),l&&e.StandardMaterial.RefractionTextureEnabled&&(o.LODBASEDMICROSFURACE?this._uniformBuffer.setTexture("refractionSampler",l):(this._uniformBuffer.setTexture("refractionSampler",l._lodTextureMid||l),this._uniformBuffer.setTexture("refractionSamplerLow",l._lodTextureLow||l),this._uniformBuffer.setTexture("refractionSamplerHigh",l._lodTextureHigh||l))),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 p=n._forcedViewPosition?n._forcedViewPosition:n._mirroredCameraPosition?n._mirroredCameraPosition:n.activeCamera.globalPosition,f=n.useRightHandedSystem===(null!=n._mirroredCameraPosition);s.setFloat4("vEyePosition",p.x,p.y,p.z,f?-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||h)&&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.useHorizonOcclusion=!1,n.useRadianceOcclusion=!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),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useHorizonOcclusion",void 0),r([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useRadianceOcclusion",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 h=a.srcElement||a.target;if(o.type===e.PointerEventTypes.POINTERDOWN&&h){try{h.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&&h){try{h.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 l=a.clientX-r.previousPosition.x,c=a.clientY-r.previousPosition.y;r.camera.getScene().useRightHandedSystem?r.camera.cameraRotation.y-=l/r.angularSensibility:r.camera.cameraRotation.y+=l/r.angularSensibility,r.camera.cameraRotation.x+=c/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){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===(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){if(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)}if(!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){if(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-h)*n.camera.radius*n.pinchDeltaPercentage:n.camera.inertialRadiusOffset+=(E-h)/(n.pinchPrecision*((n.angularSensibilityX+n.angularSensibilityY)/2)*b),u.isPaning=!1,u.isPinching=!0;else if(r&&r.pointerId===y.pointerId&&0!==n.panningSensibility&&n.multiTouchPanning){if(!u.isPaning)return u.isPaning=!0,u.isPinching=!1,u.x=y.x,void(u.y=y.y);n.camera.inertialPanningX+=-(y.x-u.x)/n.panningSensibility,n.camera.inertialPanningY+=(y.y-u.y)/n.panningSensibility}r&&r.pointerId===d.pointerId&&(u.x=y.x,u.y=y.y)}h=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,h=0,u.isPaning=!1,u.isPinching=!1,c=0,r=null,l=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 h=t.call(this,i,e.Vector3.Zero(),a)||this;return h.inertialAlphaOffset=0,h.inertialBetaOffset=0,h.inertialRadiusOffset=0,h.lowerAlphaLimit=null,h.upperAlphaLimit=null,h.lowerBetaLimit=.01,h.upperBetaLimit=Math.PI,h.lowerRadiusLimit=null,h.upperRadiusLimit=null,h.inertialPanningX=0,h.inertialPanningY=0,h.pinchToPanMaxDistance=20,h.panningDistanceLimit=null,h.panningOriginTarget=e.Vector3.Zero(),h.panningInertia=.9,h.zoomOnFactor=1,h.targetScreenOffset=e.Vector2.Zero(),h.allowUpsideDown=!0,h._viewMatrix=new e.Matrix,h.panningAxis=new e.Vector3(1,1,0),h.onMeshTargetChangedObservable=new e.Observable,h.checkCollisions=!1,h.collisionRadius=new e.Vector3(.5,.5,.5),h._previousPosition=e.Vector3.Zero(),h._collisionVelocity=e.Vector3.Zero(),h._newPosition=e.Vector3.Zero(),h._onCollisionPositionChange=function(t,i,r){void 0===r&&(r=null),h.getScene().workerCollisions&&h.checkCollisions&&i.multiplyInPlace(h._collider.radius),r?(h.setPosition(i),h.onCollide&&h.onCollide(r)):h._previousPosition.copyFrom(h.position);var n=Math.cos(h.alpha),o=Math.sin(h.alpha),s=Math.cos(h.beta),a=Math.sin(h.beta);0===a&&(a=1e-4);var l=h._getTargetPosition();l.addToRef(new e.Vector3(h.radius*n*a,h.radius*s,h.radius*o*a),h._newPosition),h.position.copyFrom(h._newPosition);var c=h.upVector;h.allowUpsideDown&&h.beta<0&&(c=(c=c.clone()).negate()),e.Matrix.LookAtLHToRef(h.position,l,c,h._viewMatrix),h._viewMatrix.m[12]+=h.targetScreenOffset.x,h._viewMatrix.m[13]+=h.targetScreenOffset.y,h._collisionTriggered=!1},h._target=e.Vector3.Zero(),s&&h.setTarget(s),h.alpha=r,h.beta=n,h.radius=o,h.getViewMatrix(),h.inputs=new e.ArcRotateCameraInputsManager(h),h.inputs.addKeyboard().addMouseWheel().addPointers(),h}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(){if(!this._collisionTriggered){if(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{r=t,n=t.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,u=this._orthoTop-this._orthoBottom;e.Matrix.OrthoOffCenterLHToRef(this._orthoLeft-c*this.shadowOrthoScale,this._orthoRight+c*this.shadowOrthoScale,this._orthoBottom-u*this.shadowOrthoScale,this._orthoTop+u*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,h,l){var c=void 0;if(!isNaN(parseFloat(s))&&isFinite(s)?c=i.ANIMATIONTYPE_FLOAT:s instanceof e.Quaternion?c=i.ANIMATIONTYPE_QUATERNION:s instanceof e.Vector3?c=i.ANIMATIONTYPE_VECTOR3:s instanceof e.Vector2?c=i.ANIMATIONTYPE_VECTOR2:s instanceof e.Color3?c=i.ANIMATIONTYPE_COLOR3:s instanceof e.Size&&(c=i.ANIMATIONTYPE_SIZE),void 0==c)return null;var u=new i(t,r,n,c,h),p=[{frame:0,value:s},{frame:o,value:a}];return u.setKeys(p),void 0!==l&&u.setEasingFunction(l),u},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,h,l,c){var u=i._PrepareAnimation(e,r,n,o,s,a,h,l);return u?t.getScene().beginDirectAnimation(t,[u],0,o,1===u.loopMode,1,c):null},i.CreateMergeAndStartAnimation=function(e,t,r,n,o,s,a,h,l,c){var u=i._PrepareAnimation(e,r,n,o,s,a,h,l);return u?(t.animations.push(u),t.getScene().beginAnimation(t,0,o,1===u.loopMode,1,c)):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 h=n*(s/1e3);o.setKeys([{frame:0,value:i[e].clone?i[e].clone():i[e]},{frame:h,value:t}]),i.animations||(i.animations=[]),i.animations.push(o);var l=r.beginAnimation(i,0,h,!1);return l.onAnimationEnd=a,l},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&&(h=c.values[1]),c.values.length>=2&&(l=c.values[2]);break;case i.ANIMATIONTYPE_QUATERNION:if(r=e.Quaternion.FromArray(c.values),c.values.length>=8){var u=e.Quaternion.FromArray(c.values.slice(4,8));u.equals(e.Quaternion.Zero())||(h=u)}if(c.values.length>=12){var p=e.Quaternion.FromArray(c.values.slice(8,12));p.equals(e.Quaternion.Zero())||(l=p)}break;case i.ANIMATIONTYPE_MATRIX:r=e.Matrix.FromArray(c.values);break;case i.ANIMATIONTYPE_COLOR3:r=e.Color3.FromArray(c.values);break;case i.ANIMATIONTYPE_VECTOR3:default:r=e.Vector3.FromArray(c.values)}var f={};f.frame=c.frame,f.value=r,void 0!=h&&(f.inTangent=h),void 0!=l&&(f.outTangent=l),a.push(f)}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 h=a;h=t){var c=s[h],u=this._getKeyValue(c.value),p=this._getKeyValue(l.value),f=void 0!==c.outTangent&&void 0!==l.inTangent,d=l.frame-c.frame,m=(t-c.frame)/d,g=this._animation.getEasingFunction();switch(null!=g&&(m=g.ease(m)),this._animation.dataType){case e.Animation.ANIMATIONTYPE_FLOAT:var _=f?this._animation.floatInterpolateFunctionWithTangents(u,c.outTangent*d,p,l.inTangent*d,m):this._animation.floatInterpolateFunction(u,p,m);switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return _;case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return n*i+_}break;case e.Animation.ANIMATIONTYPE_QUATERNION:var v=f?this._animation.quaternionInterpolateFunctionWithTangents(u,c.outTangent.scale(d),p,l.inTangent.scale(d),m):this._animation.quaternionInterpolateFunction(u,p,m);switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return v;case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return v.add(n.scale(i))}return v;case e.Animation.ANIMATIONTYPE_VECTOR3:var y=f?this._animation.vector3InterpolateFunctionWithTangents(u,c.outTangent.scale(d),p,l.inTangent.scale(d),m):this._animation.vector3InterpolateFunction(u,p,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 b=f?this._animation.vector2InterpolateFunctionWithTangents(u,c.outTangent.scale(d),p,l.inTangent.scale(d),m):this._animation.vector2InterpolateFunction(u,p,m);switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return b;case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return b.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(u,p,m);case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return this._animation.sizeInterpolateFunction(u,p,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(u,p,m);case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return this._animation.color3InterpolateFunction(u,p,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(u,p,m);case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return u}}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 h=!0,l=this._animation.getKeys();if(0!==l[0].frame){var c={frame:0,value:l[0].value};l.splice(0,0,c)}(il[l.length-1].frame)&&(i=l[0].frame),(rl[l.length-1].frame)&&(r=l[l.length-1].frame),i===r&&(i>l[0].frame?i--:ri&&f>p||i>r&&f>0,y=h?i+f%p:r,b=this._interpolate(y,v,this._animation.loopMode,u,d);this.setValue(b);for(var x=this._animation.getEvents(),T=0;T0&&y>=x[T].frame&&x[T].frame>=i||p<0&&y<=x[T].frame&&x[T].frame<=i){var E=x[T];E.isDone||(E.onlyOnce&&(x.splice(T,1),T--),E.isDone=!0,E.action())}else x[T].isDone&&!x[T].onlyOnce&&(x[T].isDone=!1);return h||(this._stopped=!0),h},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),h=Math.floor(a),l=h+1,c=(1-Math.pow(i,h))/(n*o),u=.5*(c+(1-Math.pow(i,l))/(n*o)),p=e-u,f=u-c;return-Math.pow(1/i,t-h)/(f*f)*(p-f)*(p+f)},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 h=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=h;var l=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=l;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},t}(t);e.QuadraticEase=c;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*e*e},t}(t);e.QuarticEase=u;var p=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=p;var f=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=f;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)){if(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?u.push(o):u.push(r),d){for(var m=new Array,g=0;g0){var u=c.properties[0].value,p=null===c.properties[0].targetType?u:n.getMeshByName(u);p._meshId&&(p.mesh=n.getMeshByID(p._meshId)),l={trigger:t[c.name],parameter:p}}else l=t[c.name];for(var f=0;f>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(),h=Number.MAX_VALUE,l=null,c=e.Vector3.Zero(),u=i.getViewMatrix(),p=0;pd&&(h=d,l=f,n))break}}}if(l){var m=new e.PickingInfo;return m.hit=!0,m.pickedSprite=l,m.distance=h,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;if(s<0)return!1;return 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 h=e.Vector3.Dot(this._edge2,this._qvec)*o;return h>this.length?null:new e.IntersectionInfo(s,a,h)},t.prototype.intersectsPlane=function(t){var i,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,h,l=this.origin.add(this.direction.multiplyByFloats(t.rayl,t.rayl,t.rayl)),c=r.subtract(i),u=l.subtract(this.origin),p=i.subtract(this.origin),f=e.Vector3.Dot(c,c),d=e.Vector3.Dot(c,u),m=e.Vector3.Dot(u,u),g=e.Vector3.Dot(c,p),_=e.Vector3.Dot(u,p),v=f*m-d*d,y=v,b=v;vy&&(s=y,h=_+d,b=m)),h<0?(h=0,-g<0?s=0:-g>f?s=y:(s=-g,y=f)):h>b&&(h=b,-g+d<0?s=0:-g+d>f?s=y:(s=-g+d,y=f)),o=Math.abs(s)0&&a<=this.length&&T.lengthSquared()h){var l=h;h=a,a=l}return a>0&&a0&&h=0))},i.prototype._canDoCollision=function(t,i,r,n){var o=e.Vector3.Distance(this.basePointWorld,t),s=Math.max(this.radius.x,this.radius.y,this.radius.z);return!(o>this.velocityWorldLength+s+i)&&!!function(e,t,i,r){return!(e.x>i.x+r||i.x-r>t.x||e.y>i.y+r||i.y-r>t.y||e.z>i.z+r||i.z-r>t.z)}(r,n,this.basePointWorld,this.velocityWorldLength+s)},i.prototype._testTriangle=function(i,r,n,o,s,a){var h,l=!1;r||(r=[]),r[i]||(r[i]=new e.Plane(0,0,0,0),r[i].copyFromPoints(n,o,s));var c=r[i];if(a||c.isFrontFacingTo(this.normalizedVelocity,0)){var u=c.signedDistanceTo(this.basePoint),p=e.Vector3.Dot(c.normal,this.velocity);if(0==p){if(Math.abs(u)>=1)return;l=!0,h=0}else{var f=(1-u)/p;if((h=(-1-u)/p)>f){var d=f;f=h,h=d}if(h>1||f<0)return;h<0&&(h=0),h>1&&(h=1)}this._collisionPoint.copyFromFloats(0,0,0);var m=!1,g=1;if(l||(this.basePoint.subtractToRef(c.normal,this._planeIntersectionPoint),this.velocity.scaleToRef(h,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,n,o,s,c.normal)&&(m=!0,g=h,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!m){var _=this.velocity.lengthSquared(),v=_;this.basePoint.subtractToRef(n,this._tempVector);var y=2*e.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,x=t(v,y,b,g);x.found&&(g=x.root,m=!0,this._collisionPoint.copyFrom(n)),this.basePoint.subtractToRef(o,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,(x=t(v,y,b,g)).found&&(g=x.root,m=!0,this._collisionPoint.copyFrom(o)),this.basePoint.subtractToRef(s,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,(x=t(v,y,b,g)).found&&(g=x.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(v=T*-_+E*E,y=T*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*E*A,b=T*(1-this._baseToVertex.lengthSquared())+A*A,(x=t(v,y,b,g)).found){var P=(E*x.root-A)/T;P>=0&&P<=1&&(g=x.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),v=T*-_+E*E,y=T*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*E*A,b=T*(1-this._baseToVertex.lengthSquared())+A*A,(x=t(v,y,b,g)).found&&(P=(E*x.root-A)/T)>=0&&P<=1&&(g=x.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),v=T*-_+E*E,y=T*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*E*A,b=T*(1-this._baseToVertex.lengthSquared())+A*A,(x=t(v,y,b,g)).found&&(P=(E*x.root-A)/T)>=0&&P<=1&&(g=x.root,m=!0,this._edge.scaleInPlace(P),s.addToRef(this._edge,this._collisionPoint))}if(m){var M=g*this.velocity.length();(!this.collisionFound||M4)){++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:var s=o.payload;if(!n._collisionsCallbackArray[s.collisionId])return;var a=n._collisionsCallbackArray[s.collisionId];if(a){var h=n._scene.getMeshByUniqueID(s.collidedMeshUniqueId);h&&a(s.collisionId,e.Vector3.FromArray(s.newPosition),h)}n._collisionsCallbackArray[s.collisionId]=null}else e.Tools.Warn("error returned from worker!")},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,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 h={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(h)}},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 h=s?s.collisionMask:r.collisionMask;r._initialize(t,i,a);for(var l=0;l=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){if(e===t)return e;return Math.random()*(t-e)+e},i=function(){function i(r,n,o,s,a,h){void 0===s&&(s=null),void 0===a&&(a=!1),void 0===h&&(h=.01);var l=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=h,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 c=this._vertexBuffer.createVertexBuffer(e.VertexBuffer.PositionKind,0,3),u=this._vertexBuffer.createVertexBuffer(e.VertexBuffer.ColorKind,3,4),p=this._vertexBuffer.createVertexBuffer("options",7,4);if(this._isAnimationSheetEnabled){var f=this._vertexBuffer.createVertexBuffer("cellIndex",11,1);this._vertexBuffers.cellIndex=f}this._vertexBuffers[e.VertexBuffer.PositionKind]=c,this._vertexBuffers[e.VertexBuffer.ColorKind]=u,this._vertexBuffers.options=p,this.startDirectionFunction=function(i,r,n,o){var s=t(l.direction1.x,l.direction2.x),a=t(l.direction1.y,l.direction2.y),h=t(l.direction1.z,l.direction2.z);e.Vector3.TransformNormalFromFloatsToRef(s*i,a*i,h*i,r,n)},this.startPositionFunction=function(i,r,n){var o=t(l.minEmitBox.x,l.maxEmitBox.x),s=t(l.minEmitBox.y,l.maxEmitBox.y),a=t(l.minEmitBox.z,l.maxEmitBox.z);e.Vector3.TransformCoordinatesFromFloatsToRef(o,s,a,i,r)},this.updateFunction=function(e){for(var t=0;t=i.lifeTime?(l.recycleParticle(i),t--):(i.colorStep.scaleToRef(l._scaledUpdateSpeed,l._scaledColorStep),i.color.addInPlace(l._scaledColorStep),i.color.a<0&&(i.color.a=0),i.angle+=i.angularSpeed*l._scaledUpdateSpeed,i.direction.scaleToRef(l._scaledUpdateSpeed,l._scaledDirection),i.position.addInPlace(l._scaledDirection),l.gravity.scaleToRef(l._scaledUpdateSpeed,l._scaledGravity),i.direction.addInPlace(l._scaledGravity),l._isAnimationSheetEnabled&&i.updateCellIndex(l._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 h=(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,h)}var l=new i(o,t.capacity,r,s);if(l.customShader=a,t.id&&(l.id=t.id),t.preventAutoStart&&(l.preventAutoStart=t.preventAutoStart),t.textureName&&(l.particleTexture=new e.Texture(n+t.textureName,r),l.particleTexture.name=t.textureName),t.emitterId?l.emitter=r.getLastMeshByID(t.emitterId):l.emitter=e.Vector3.FromArray(t.emitter),t.animations)for(var c=0;c-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,h){void 0===h&&(h=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,h&&(this._modelBoundingInfo=h,this._boundingInfo=new e.BoundingInfo(h.minimum,h.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._depthSort?this._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(),h=t.getVerticesData(e.VertexBuffer.UVKind),l=t.getVerticesData(e.VertexBuffer.ColorKind),c=t.getVerticesData(e.VertexBuffer.NormalKind),u=0,p=a.length/3;n?(n=n>p?p:n,r=Math.round(p/n),o=0):r=r>p?p:r;for(var f=[],d=[],m=[],g=[],_=e.Tmp.Vector3[0],v=r;up-(r=v+Math.floor((1+o)*Math.random()))&&(r=p-u),f.length=0,d.length=0,m.length=0,g.length=0;for(var y=0,b=3*u;b<3*(u+r);b++){d.push(y);var x=a[b];f.push(s[3*x],s[3*x+1],s[3*x+2]),h&&m.push(h[2*x],h[2*x+1]),l&&g.push(l[4*x],l[4*x+1],l[4*x+2],l[4*x+3]),y++}var T,E=this.nbParticles,A=this._posToShape(f),P=this._uvsToShapeUV(m);for(T=0;T65535&&(this._needs32Bits=!0)}if(this._pickable){var b=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 p=(s=this.particles[t]._pos)/3|0;h=4*p,c=2*p;for(var f=t;f<=i;f++){if(this._particle=this.particles[f],this._shape=this._particle._model._shape,this._shapeUV=this._particle._model._shapeUV,this.updateParticle(this._particle),this._depthSort&&this._depthSortParticles){var d=this.depthSortedParticles[f];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*(u=this._shape.length),h+=4*u,c+=2*u;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()),u=0;uthis._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[l]=this._shapeUV[2*u]*(this._particle.uvs.z-this._particle.uvs.x)+this._particle.uvs.x,this._uvs32[l+1]=this._shapeUV[2*u+1]*(this._particle.uvs.w-this._particle.uvs.y)+this._particle.uvs.y);else for(this._particle._stillInvisible=!0,u=0;uthis._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 l in this._textures)if(!this._textures[l].isReady())return!1;n.getAlphaTesting()&&o.push("#define ALPHATEST");var c=this._effect,u=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:u,fallbacks:a,onCompiled:this.onCompiled,onError:this.onError},n),!!this._effect.isReady()&&(c!==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._vectors2Arrays)this._effect.setArray2(r,this._vectors2Arrays[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=h[u].x),h[u].ye.Tmp.Vector3[1].y&&(e.Tmp.Vector3[1].y=h[u].y),h[u].ze.Tmp.Vector3[1].z&&(e.Tmp.Vector3[1].z=h[u].z),u++,r+=3;l._closePath&&(t[r]=h[0].x,t[r+1]=h[0].y,t[r+2]=h[0].z,r+=3)}}(u),l._boundingInfo=new e.BoundingInfo(e.Tmp.Vector3[0],e.Tmp.Vector3[1]),l._boundingInfo.update(l._worldMatrix),l.updateVerticesData(e.VertexBuffer.PositionKind,u,!1,!1),r.colors){for(var p=l.getVerticesData(e.VertexBuffer.ColorKind),f=0;f1?1:r.arc:1,a=void 0===r.closed||r.closed,h=r.shape,l=r.radius||1,c=r.tessellation||64,u=r.updatable,p=t.updateSideOrientation(r.sideOrientation),f=r.cap||e.Mesh.NO_CAP,d=2*Math.PI,m=new Array,g=r.invertUV||!1,_=0,v=0,y=d/c*s,b=new Array;for(_=0;_<=c;_++){b=[];for(f!=e.Mesh.CAP_START&&f!=e.Mesh.CAP_ALL||(b.push(new e.Vector3(0,h[0].y,0)),b.push(new e.Vector3(Math.cos(_*y)*h[0].x*l,h[0].y,Math.sin(_*y)*h[0].x*l))),v=0;v1)?1:r.arc||1;var d,m,g=function(t,i,r,n,o,s,a,h){for(var l,c,u,p,f=i.getTangents(),d=i.getNormals(),m=i.getDistances(),g=2*Math.PI/o*h,_=s||function(){return n},v=e.Tmp.Matrix[0],y=a===e.Mesh._NO_CAP||a===e.Mesh.CAP_END?0:2,b=0;b3?0:c,r.arc);var v=t.CreateRibbon(i,{pathArray:m,closePath:!0,closeArray:!1,updatable:p,sideOrientation:f,invertUV:u,frontUVs:r.frontUVs,backUVs:r.backUVs},n);return v.pathArray=m,v.path3D=d,v.tessellation=h,v.cap=c,v.arc=r.arc,v.radius=a,v},t.CreatePolyhedron=function(i,r,n){var o=new e.Mesh(i,n);r.sideOrientation=t.updateSideOrientation(r.sideOrientation),o._originalBuilderSideOrientation=r.sideOrientation;return 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(),h=r.normal||e.Vector3.Up(),l=r.size||e.Vector3.One(),c=r.angle||0;if(!h){var u=new e.Vector3(0,0,1),p=i.getScene().activeCamera,f=e.Vector3.TransformCoordinates(u,p.getWorldMatrix());h=p.globalPosition.subtract(f)}var d=-Math.atan2(h.z,h.x)-Math.PI/2,m=Math.sqrt(h.x*h.x+h.z*h.z),g=Math.atan2(h.y,m),_=e.Matrix.RotationYawPitchRoll(d,g,c).multiply(e.Matrix.Translation(a.x,a.y,a.z)),v=e.Matrix.Invert(_),y=i.getWorldMatrix().multiply(v),b=new e.VertexData;b.indices=[],b.positions=[],b.normals=[],b.uvs=[];for(var x=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(l,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,h=e.Vector3.Dot(t[s+1].position,i)-r>0,c=e.Vector3.Dot(t[s+2].position,i)-r>0,(a?1:0)+(h?1:0)+(c?1:0)){case 0:o.push(t[s]),o.push(t[s+1]),o.push(t[s+2]);break;case 1:if(a&&(u=t[s+1],p=t[s+2],f=n(t[s],u),d=n(t[s],p)),h){u=t[s],p=t[s+2],f=n(t[s+1],u),d=n(t[s+1],p),o.push(f),o.push(p.clone()),o.push(u.clone()),o.push(p.clone()),o.push(f.clone()),o.push(d);break}c&&(u=t[s],p=t[s+1],f=n(t[s+2],u),d=n(t[s+2],p)),u&&p&&f&&d&&(o.push(u.clone()),o.push(p.clone()),o.push(f),o.push(d),o.push(f.clone()),o.push(p.clone()));break;case 2:a||(p=n(u=t[s].clone(),t[s+1]),f=n(u,t[s+2]),o.push(u),o.push(p),o.push(f)),h||(p=n(u=t[s+1].clone(),t[s+2]),f=n(u,t[s]),o.push(u),o.push(p),o.push(f)),c||(p=n(u=t[s+2].clone(),t[s]),f=n(u,t[s+1]),o.push(u),o.push(p),o.push(f))}}return o},A=0;A3?0:u,p);var E=t.CreateRibbon(i,{pathArray:x,closeArray:l,closePath:c,updatable:d,sideOrientation:m,invertUV:_,frontUVs:v||void 0,backUVs:y||void 0},f);return E.pathArray=x,E.path3D=b,E.cap=u,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._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&&(l=!0,this._soundLoaded(i));break;case"String":h.push(i);case"Array":0===h.length&&(h=i);for(var c=0;c0&&(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){if(t.getBoundingInfo){var i=t.getBoundingInfo();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 h,l={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 c=function(){o._isReadyToPlay?(h._audioBuffer=o.getAudioBuffer(),h._isReadyToPlay=!0,h.autoplay&&h.play()):window.setTimeout(c,300)};h=new t(a,new ArrayBuffer(0),r,null,l),c()}else h=new t(a,s,r,function(){r._removePendingData(h)},l),r._addPendingData(h);if(i.position){var u=e.Vector3.FromArray(i.position);h.setPosition(u)}if(i.isDirectional&&(h.setDirectionalCone(i.coneInnerAngle||360,i.coneOuterAngle||360,i.coneOuterGain||0),i.localDirectionToMesh)){var p=e.Vector3.FromArray(i.localDirectionToMesh);h.setLocalDirectionToMesh(p)}if(i.connectedMeshId){var f=r.getMeshByID(i.connectedMeshId);f&&h.attachToMesh(f)}return h},t}();e.Sound=t}(s||(s={}));!function(e){var t=function(){function t(e,t){this.id=-1,this._isMainTrack=!1,this._isInitialized=!1,this._scene=e,this.soundCollection=new Array,this._options=t,this._isMainTrack||(this._scene.soundTracks.push(this),this.id=this._scene.soundTracks.length-1)}return t.prototype._initializeSoundTrackAudioGraph=function(){e.Engine.audioEngine.canUseWebAudio&&e.Engine.audioEngine.audioContext&&(this._outputAudioNode=e.Engine.audioEngine.audioContext.createGain(),this._outputAudioNode.connect(e.Engine.audioEngine.masterGain),this._options&&(this._options.volume&&(this._outputAudioNode.gain.value=this._options.volume),this._options.mainTrack&&(this._isMainTrack=this._options.mainTrack)),this._isInitialized=!0)},t.prototype.dispose=function(){if(e.Engine.audioEngine.canUseWebAudio){for(this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas();this.soundCollection.length;)this.soundCollection[0].dispose();this._outputAudioNode&&this._outputAudioNode.disconnect(),this._outputAudioNode=null}},t.prototype.AddSound=function(t){this._isInitialized||this._initializeSoundTrackAudioGraph(),e.Engine.audioEngine.canUseWebAudio&&this._outputAudioNode&&t.connectToSoundTrackAudioNode(this._outputAudioNode),t.soundTrackId&&(-1===t.soundTrackId?this._scene.mainSoundTrack.RemoveSound(t):this._scene.soundTracks[t.soundTrackId].RemoveSound(t)),this.soundCollection.push(t),t.soundTrackId=this.id},t.prototype.RemoveSound=function(e){var t=this.soundCollection.indexOf(e);-1!==t&&this.soundCollection.splice(t,1)},t.prototype.setVolume=function(t){e.Engine.audioEngine.canUseWebAudio&&this._outputAudioNode&&(this._outputAudioNode.gain.value=t)},t.prototype.switchPanningModelToHRTF=function(){if(e.Engine.audioEngine.canUseWebAudio)for(var t=0;t-1?i.substring(f).toLowerCase():"");if(!s&&(".dds"===d||n||(n=["_px.jpg","_py.jpg","_pz.jpg","_nx.jpg","_ny.jpg","_nz.jpg"]),s=[],n))for(var m=0;m0&&(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);o=this.getScene();if(o){var i=o.getEngine();if(void 0!==this.useCameraPostProcesses&&(e=this.useCameraPostProcesses),this._waitingRenderList){this.renderList=[];for(a=0;a=0&&this._renderingManager.dispatchParticles(v))}if(this.isCube)for(var b=0;b<6;b++)this.renderToTarget(b,l,c,e,t),o.incrementRenderId(),o.resetCachedMaterial();else this.renderToTarget(0,l,c,e,t);this.onAfterUnbindObservable.notifyObservers(this),o.activeCamera&&(this.activeCamera&&this.activeCamera!==o.activeCamera&&o.setTransformMatrix(o.activeCamera.getViewMatrix(),o.activeCamera.getProjectionMatrix(!0)),i.setViewport(o.activeCamera.viewport)),o.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 h=a.getEngine();this._texture&&(this._postProcessManager?this._postProcessManager._prepareFrame(this._texture,this._postProcesses):n&&a.postProcessManager._prepareFrame(this._texture)||this._texture&&h.bindFramebuffer(this._texture,this.isCube?t:void 0,void 0,void 0,this.ignoreCameraViewport),this.onBeforeRenderObservable.notifyObservers(t),this.onClearObservable.hasObservers()?this.onClearObservable.notifyObservers(h):h.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(),h),this.isCube&&5!==t?this.onAfterRenderObservable.notifyObservers(t):(this.isCube&&5===t&&h.generateMipMapsForCubemap(this._texture),h.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,h=!!(s=s||{}).generateMipMaps&&s.generateMipMaps,l=!!s.generateDepthTexture&&s.generateDepthTexture,c=void 0===s.doNotChangeAspectRatio||s.doNotChangeAspectRatio;if((a=t.call(this,i,r,o,h,c)||this)._engine=o.getEngine(),a.isSupported){for(var u=[],p=[],f=0;f1||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,h){void 0===s&&(s=e.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE),void 0===h&&(h=!0);var l=t.call(this,i,r,n,o,!0,s,!1,a,h)||this;return l.mirrorPlane=new e.Plane(0,1,0,1),l._transformMatrix=e.Matrix.Zero(),l._mirrorMatrix=e.Matrix.Zero(),l._adaptiveBlurKernel=0,l._blurKernelX=0,l._blurKernelY=0,l._blurRatio=1,l.ignoreCameraViewport=!0,l.onBeforeRenderObservable.add(function(){e.Matrix.ReflectionToRef(l.mirrorPlane,l._mirrorMatrix),l._savedViewMatrix=n.getViewMatrix(),l._mirrorMatrix.multiplyToRef(l._savedViewMatrix,l._transformMatrix),n.setTransformMatrix(l._transformMatrix,n.getProjectionMatrix()),n.clipPlane=l.mirrorPlane,n.getEngine().cullBackFaces=!1,n._mirroredCameraPosition=e.Vector3.TransformCoordinates(n.activeCamera.globalPosition,l._mirrorMatrix)}),l.onAfterRenderObservable.add(function(){n.setTransformMatrix(l._savedViewMatrix,n.getProjectionMatrix()),n.getEngine().cullBackFaces=!0,n._mirroredCameraPosition=null,delete n.clipPlane}),l}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 h=t.call(this,null,n,!o,void 0,s,void 0,void 0,void 0,void 0,a)||this;h.name=i,h._engine=h.getScene().getEngine(),h.wrapU=e.Texture.CLAMP_ADDRESSMODE,h.wrapV=e.Texture.CLAMP_ADDRESSMODE,h._generateMipMaps=o,r.getContext?(h._canvas=r,h._texture=h._engine.createDynamicTexture(r.width,r.height,o,s)):(h._canvas=document.createElement("canvas"),r.width?h._texture=h._engine.createDynamicTexture(r.width,r.height,o,s):h._texture=h._engine.createDynamicTexture(r,r,o,s));var l=h.getSize();return h._canvas.width=l.width,h._canvas.height=l.height,h._context=h._canvas.getContext("2d"),h}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 h=this.getSize();if(o&&(this._context.fillStyle=o,this._context.fillRect(0,0,h.width,h.height)),this._context.font=r,null===t||void 0===t){var l=this._context.measureText(e);t=(h.width-l.width)/2}if(null===i||void 0===i){var c=parseInt(r.replace(/\D/g,""));i=h.height/2+c/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 h=t.call(this,null,n,!o,s)||this;h._autoLaunch=!0;var l=null;return h.name=i,r instanceof HTMLVideoElement?h.video=r:(l=r,h.video=document.createElement("video"),h.video.autoplay=!1,h.video.loop=!0),h._engine=h.getScene().getEngine(),h._generateMipMaps=o,h._samplingMode=a,!h._engine.needPOTTextures||e.Tools.IsExponentOfTwo(h.video.videoWidth)&&e.Tools.IsExponentOfTwo(h.video.videoHeight)?(h.wrapU=e.Texture.WRAP_ADDRESSMODE,h.wrapV=e.Texture.WRAP_ADDRESSMODE):(h.wrapU=e.Texture.CLAMP_ADDRESSMODE,h.wrapV=e.Texture.CLAMP_ADDRESSMODE,h._generateMipMaps=!1),l?(h.video.addEventListener("canplay",function(){h._createTexture()}),l.forEach(function(e){var t=document.createElement("source");t.src=e,h.video.appendChild(t)})):h._createTexture(),h._lastUpdate=e.Tools.Now,h}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,h,l){void 0===a&&(a=!0),void 0===h&&(h=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE);var c=t.call(this,null,s,!a,h)||this;return c.format=o,c._engine=s.getEngine(),c._texture=s.getEngine().createRawTexture(i,r,n,o,a,h,l),c.wrapU=e.Texture.CLAMP_ADDRESSMODE,c.wrapV=e.Texture.CLAMP_ADDRESSMODE,c}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,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_LUMINANCE,o,s,a,h)},i.CreateLuminanceAlphaTexture=function(t,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA,o,s,a,h)},i.CreateAlphaTexture=function(t,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_ALPHA,o,s,a,h)},i.CreateRGBTexture=function(t,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_RGB,o,s,a,h)},i.CreateRGBATexture=function(t,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_RGBA,o,s,a,h)},i}(e.Texture);e.RawTexture=t}(s||(s={}));!function(e){var t=function(){function t(t,i,r,n,o,s,a,h,l,c,u,p,f,d){void 0===a&&(a=e.Texture.NEAREST_SAMPLINGMODE),void 0===c&&(c=null),void 0===u&&(u=e.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===p&&(p="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.animations=new Array,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)):h&&(this._engine=h,this._engine.postProcesses.push(this)),this._options=o,this.renderTargetSamplingMode=a||e.Texture.NEAREST_SAMPLINGMODE,this._reusable=l||!1,this._textureType=u,this._samplers=n||[],this._samplers.push("textureSampler"),this._fragmentUrl=i,this._vertexUrl=p,this._parameters=r||[],this._parameters.push("scale"),this._indexParameters=f,d||this.updateEffect(c)}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,h=(i?i.width:this._engine.getRenderWidth(!0))*this._options|0,l=(i?i.height:this._engine.getRenderHeight(!0))*this._options|0,c=this._options.width||h,u=this._options.height||l;if(!this._shareOutputWithPostProcess&&!this._forcedOutputTexture){if(this.adaptScaleToCurrentViewport){var p=s.currentViewport;p&&(c*=p.width,u*=p.height)}if((this.renderTargetSamplingMode===e.Texture.TRILINEAR_SAMPLINGMODE||this.alwaysForcePOT)&&(this._options.width||(c=s.needPOTTextures?e.Tools.GetExponentOfTwo(c,a,this.scaleMode):c),this._options.height||(u=s.needPOTTextures?e.Tools.GetExponentOfTwo(u,a,this.scaleMode):u)),this.width!==c||this.height!==u){if(this._textures.length>0){for(var f=0;f0)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,h){return void 0===n&&(n=null),void 0===h&&(h=e.Engine.TEXTURETYPE_UNSIGNED_INT),t.call(this,i,"pass",null,null,r,n,o,s,a,void 0,h)||this}return n(i,t),i}(e.PostProcess);e.PassPostProcess=t}(s||(s={}));a=this&&this.__assign||Object.assign||function(e){for(var t,i=1,r=arguments.length;i=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=s.length)return void(e&&e(i));setTimeout(p,16)}};p()}else e&&e(this)}else e&&e(this)}else e&&e(this)},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 h=r.join("\n");return this._cachedDefines!==h&&(this._cachedDefines=h,this._effect=this._scene.getEngine().createEffect("shadowMap",n,["world","mBones","viewProjection","diffuseMatrix","lightPosition","depthValues","biasAndScale"],["diffuseSampler"],h)),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!==f.skeletons&&null!==f.skeletons){if(!1===v.indexOf(b.skeletonId)>-1)for(var I=0,O=f.skeletons.length;I0){for(var se=0;se0){for(var he=0;he0&&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){if(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 h=0;ho.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),h=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,h,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 h=a.objectStore(o).get(t);h.onsuccess=function(e){s=e.target.result},h.onerror=function(i){e.Tools.Error("Error loading file "+t+" from DB."),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,h=new XMLHttpRequest;h.open("GET",t,!0),n&&(h.responseType="arraybuffer"),r&&(h.onprogress=r),h.addEventListener("load",function(){if(200===h.status||e.Tools.ValidateXHRData(h,n?6:1))if(a=n?h.response:h.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 l;l="scenes"===s?{sceneUrl:t,data:a,version:o.manifestVersionFound}:{textureUrl:t,data:a};try{var c=r.objectStore(s).put(l);c.onsuccess=function(e){},c.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),h.addEventListener("error",function(t){e.Tools.Error("error on XHR request."),i()},!1),h.send()}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},t.IsUASupportingBlobStorage=!0,t.IDBStorageEnabled=!0,t.parseURL=function(e){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._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){i||s.preventDefault();if(-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)},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,h){void 0===s&&(s=null),void 0===a&&(a=!0),void 0===h&&(h=!1);var l=t.call(this,null,o,!a)||this;l.isCube=h,l.isEnabled=!0,l._currentRefreshId=-1,l._refreshRate=1,l._vertexBuffers={},l._uniforms=new Array,l._samplers=new Array,l._textures={},l._floats={},l._floatsArrays={},l._colors3={},l._colors4={},l._vectors2={},l._vectors3={},l._matrices={},l._fallbackTextureUsed=!1,o._proceduralTextures.push(l),l._engine=o.getEngine(),l.name=i,l.isRenderTarget=!0,l._size=r,l._generateMipMaps=a,l.setFragment(n),l._fallbackTexture=s,h?(l._texture=l._engine.createRenderTargetCubeTexture(r,{generateMipMaps:a}),l.setFloat("face",0)):l._texture=l._engine.createRenderTargetTexture(r,a);var c=[];return c.push(1,1),c.push(-1,1),c.push(-1,-1),c.push(1,-1),l._vertexBuffers[e.VertexBuffer.PositionKind]=new e.VertexBuffer(l._engine,c,e.VertexBuffer.PositionKind,!1,!1,2),l._createIndexBuffer(),l}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(){if(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 h=50*t._computeLocalCameraSpeed();this._vector3.copyFromFloats(i.x*h,0,-i.y*h),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||u<-this.maxCameraSpeed)&&(u=u<1?-this.maxCameraSpeed:this.maxCameraSpeed),(p>this.maxCameraSpeed||p<-this.maxCameraSpeed)&&(p=p<1?-this.maxCameraSpeed:this.maxCameraSpeed),(f>this.maxCameraSpeed||f<-this.maxCameraSpeed)&&(f=f<1?-this.maxCameraSpeed:this.maxCameraSpeed),this.position=new e.Vector3(this.position.x+u,this.position.y+p,this.position.z+f),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 h=t.call(this,i,e.Vector3.Zero(),a)||this;return h.alpha=r,h.beta=n,h.radius=o,h.target=s,h._cartesianCoordinates=e.Vector3.Zero(),h.follow(),h}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)if(this._renderPipelines.hasOwnProperty(e)){this._renderPipelines[e]._rebuild()}},e.prototype.dispose=function(){for(var e in this._renderPipelines)if(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._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,h=n.combineRatio||n;return s._originalColorPostProcess=new e.PassPostProcess("SSAOOriginalSceneColor",h,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1),s._createSSAOPostProcess(a),s._createBlurPostProcess(a),s._createSSAOCombinePostProcess(h),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),h="#define LUMINANCE_DOWN_SAMPLE\n";0===a&&(h+="#define FINAL_DOWN_SAMPLER");var l=new e.PostProcess("HDRLuminanceDownSample"+a,"standard",["dsOffsets","halfDestPixelSize"],[],{width:o,height:o},null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,h,r);this.luminanceDownSamplePostProcesses.push(l)}var c=this.luminancePostProcess;this.luminanceDownSamplePostProcesses.forEach(function(i,r){var o=new Array(18);i.onApply=function(e){if(c){for(var t=0,s=-1;s<2;s++)for(var a=-1;a<2;a++)o[t]=s/c.width,o[t+1]=a/c.height,t+=2;e.setArray2("dsOffsets",o),e.setFloat("halfDestPixelSize",.5/c.width),c=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 h=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),l=s.multiply(h).multiply(o);t.setMatrix("lensStarMatrix",l),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(),h=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,h.x=r.motionBlurPostProcess.width,h.y=r.motionBlurPostProcess.height,e.setVector2("screenSize",h),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(){if(this._scene.getEngine().getCaps().drawBuffersExtension){return this._scene.enableGeometryBufferRenderer().getGBuffer().textures[0]}return 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 h=o.getCaps().instancedArrays&&null!==a.visibleInstances[i._id];if(t.isReady(i,h)){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 l=s.getAlphaTestTexture();l&&(t._effect.setTexture("diffuseSampler",l),t._effect.setMatrix("diffuseMatrix",l.getTextureMatrix()))}r.useBones&&r.computeBonesUsingShaders&&r.skeleton&&t._effect.setMatrices("mBones",r.skeleton.getTransformMatrices(r)),r._processRendering(i,t._effect,e.Material.TriangleFillMode,a,h,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 h=s.getCaps().instancedArrays&&null!==a.visibleInstances[t._id];if(r.isReady(t,h)){var l=r._volumetricLightScatteringPass;if(i===r.mesh&&(l=t.effect?t.effect:n.getEffect()),s.enableEffect(l),i._bind(t,l,e.Material.TriangleFillMode),i===r.mesh)n.bind(i.getWorldMatrix(),i);else{if(r._volumetricLightScatteringPass.setMatrix("viewProjection",o.getTransformMatrix()),n&&n.needAlphaTesting()){var c=n.getAlphaTestTexture();r._volumetricLightScatteringPass.setTexture("diffuseSampler",c),c&&r._volumetricLightScatteringPass.setMatrix("diffuseMatrix",c.getTextureMatrix())}i.useBones&&i.computeBonesUsingShaders&&i.skeleton&&r._volumetricLightScatteringPass.setMatrices("mBones",i.skeleton.getTransformMatrices(i))}i._processRendering(t,r._volumetricLightScatteringPass,e.Material.TriangleFillMode,a,h,function(e,t){return l.setMatrix("world",t)})}}}}},h=new e.Color4(0,0,0,1);this._volumetricLightScatteringRTT.onBeforeRenderObservable.add(function(){s=t.clearColor,t.clearColor=h}),this._volumetricLightScatteringRTT.onAfterRenderObservable.add(function(){t.clearColor=s}),this._volumetricLightScatteringRTT.customRenderFunction=function(i,r,n,o){var s,h=t.getEngine();if(o.length){for(h.setColorWrite(!1),s=0;st._alphaIndex?1:e._alphaIndext._distanceToCamera?-1:0}),h.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,h){void 0===n&&(n=null),void 0===o&&(o=null),void 0===s&&(s=null),void 0===a&&(a=null),void 0===h&&(h=null);var l=t.call(this,i,r.getScene())||this;return l.name=i,l.children=new Array,l.animations=new Array,l._index=null,l._worldTransform=new e.Matrix,l._absoluteTransform=new e.Matrix,l._invertedAbsoluteTransform=new e.Matrix,l._scaleMatrix=e.Matrix.Identity(),l._scaleVector=e.Vector3.One(),l._negateScaleChildren=e.Vector3.One(),l._scalingDeterminant=1,l._skeleton=r,l._localMatrix=o||e.Matrix.Identity(),l._restPose=s||l._localMatrix.clone(),l._baseMatrix=a||l._localMatrix.clone(),l._index=h,r.bones.push(l),l.setParent(n,!1),l._updateDifferenceMatrix(),l}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=c&&a.frame<=u&&(n?(l=a.value.clone(),g?(h=l.getTranslation(),l.setTranslation(h.scaleInPlace(_))):v&&o?(h=l.getTranslation(),l.setTranslation(h.multiplyInPlace(o))):l=a.value):l=a.value,y.push({frame:a.frame+r,value:l}));return this.animations[0].createRange(i,c+r,u+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],h=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,h),o.m[12]+=h.x,o.m[13]+=h.y,o.m[14]+=h.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],h=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,h),o.m[12]=h.x,o.m[13]=h.y,o.m[14]=h.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 h=i._tmpMats[1];h.copyFrom(a),h.invert();var l=i._tmpMats[2];e.Matrix.FromValuesToRef(t,0,0,0,0,r,0,0,0,0,n,0,0,0,0,1,l),this._scaleMatrix.multiplyToRef(l,this._scaleMatrix),this._scaleVector.x*=t,this._scaleVector.y*=r,this._scaleVector.z*=n,s.multiplyToRef(h,s),s.multiplyToRef(l,s),s.multiplyToRef(a,s);var c=this.getParent();c?s.multiplyToRef(c.getAbsoluteTransform(),this.getAbsoluteTransform()):this.getAbsoluteTransform().copyFrom(s);var u=this.children.length;l.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),h=this._bone2.getAbsolutePosition(t),l=this._bone1.getAbsolutePosition(t);this._bone1Length=e.Vector3.Distance(a,h),this._bone2Length=e.Vector3.Distance(h,l)}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],h=t._tmpVecs[1],l=t._tmpVecs[2],c=t._tmpVecs[3],u=t._tmpVecs[4],p=t._tmpQuat;i.getAbsolutePositionToRef(this.mesh,a),n.subtractToRef(a,u),0==u.x&&0==u.y&&0==u.z?u.y=1:u.normalize(),r.subtractToRef(a,c),c.normalize(),e.Vector3.CrossToRef(c,u,h),h.normalize(),e.Vector3.CrossToRef(c,h,l),l.normalize(),e.Matrix.FromXYZAxesToRef(l,c,h,o);var f=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-f*f)/(2*d*m),_=(m*m+f*f-d*d)/(2*m*f);g>1&&(g=1),_>1&&(_=1),g<-1&&(g=-1),_<-1&&(_=-1);var v=Math.acos(g),y=Math.acos(_),b=-v-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 x=t._tmpVecs[5];x.copyFrom(this._bendAxis),x.x*=-1,e.Matrix.RotationAxisToRef(x,-y,s),s.multiplyToRef(o,o)}this.poleAngle&&(e.Matrix.RotationAxisToRef(c,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,p),e.Quaternion.SlerpToRef(this._bone1Quat,p,this.slerpAmount,this._bone1Quat),b=this._bone2Ang*(1-this.slerpAmount)+b*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,b,e.Space.LOCAL),this._bone2Ang=b}},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,h=i.getParent(),l=t._tmpVecs[1];l.copyFrom(this.upAxis),this.upAxisSpace==e.Space.BONE&&h?(this._transformYawPitch&&e.Vector3.TransformCoordinatesToRef(l,this._transformYawPitchInv,l),h.getDirectionToRef(l,this.mesh,l)):this.upAxisSpace==e.Space.LOCAL&&(a.getDirectionToRef(l,l),1==a.scaling.x&&1==a.scaling.y&&1==a.scaling.z||l.normalize());var c=!1,u=!1;if(this._maxYaw==Math.PI&&this._minYaw==-Math.PI||(c=!0),this._maxPitch==Math.PI&&this._minPitch==-Math.PI||(u=!0),c||u){var p=t._tmpMats[2],f=t._tmpMats[3];if(this.upAxisSpace==e.Space.BONE&&1==l.y&&h)h.getRotationMatrixToRef(e.Space.WORLD,this.mesh,p);else if(this.upAxisSpace!=e.Space.LOCAL||1!=l.y||h){(m=t._tmpVecs[2]).copyFrom(this._fowardAxis),this._transformYawPitch&&e.Vector3.TransformCoordinatesToRef(m,this._transformYawPitchInv,m),h?h.getDirectionToRef(m,this.mesh,m):a.getDirectionToRef(m,m);var d=e.Vector3.Cross(l,m);d.normalize();var m=e.Vector3.Cross(d,l);e.Matrix.FromXYZAxesToRef(d,l,m,p)}else p.copyFrom(a.getWorldMatrix());p.invertToRef(f);var g=null;if(u){y=t._tmpVecs[3];n.subtractToRef(r,y),e.Vector3.TransformCoordinatesToRef(y,f,y),g=Math.sqrt(y.x*y.x+y.z*y.z);var _=Math.atan2(y.y,g),v=_;_>this._maxPitch?(y.y=this._maxPitchTan*g,v=this._maxPitch):_this._maxYaw||bMath.PI?this._isAngleBetween(b,this._maxYaw,this._midYawConstraint)?(y.z=this._maxYawCos*g,y.x=this._maxYawSin*g,x=this._maxYaw):this._isAngleBetween(b,this._midYawConstraint,this._minYaw)&&(y.z=this._minYawCos*g,y.x=this._minYawSin*g,x=this._minYaw):b>this._maxYaw?(y.z=this._maxYawCos*g,y.x=this._maxYawSin*g,x=this._maxYaw):bMath.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,f,T);var A=Math.atan2(T.x,T.z);if(this._getAngleBetween(A,b)>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 h=s.rest?e.Matrix.FromArray(s.rest):null,l=new e.Bone(s.name,n,a,e.Matrix.FromArray(s.matrix),h);s.length&&(l.length=s.length),s.animation&&l.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 h=Math.round(s*i);h<0?h=0:h>=i&&(h=i-1);var l=Math.round(a*r);l<0?l=0:l>=r&&(l=r-1);var c=r-l-1;return{r:t[c*i*3+3*h+0],g:t[c*i*3+3*h+1],b:t[c*i*3+3*h+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,h=t.width,l=t.dataPosition,c=0,u=0,p=0,f=new ArrayBuffer(4*h),d=new Uint8Array(f),m=new ArrayBuffer(t.width*t.height*4*3),g=new Float32Array(m);a>0;){if(i=e[l++],r=e[l++],n=e[l++],o=e[l++],2!=i||2!=r||128&n)throw"HDR Bad header format, not RLE";if((n<<8|o)!=h)throw"HDR Bad header format, wrong scan line width";for(c=0,p=0;p<4;p++)for(u=(p+1)*h;c128){if(0==(s=i-128)||s>u-c)throw"HDR Bad Format, bad scanline data (run)";for(;s-- >0;)d[c++]=r}else{if(0==(s=i)||s>u-c)throw"HDR Bad Format, bad scanline data (non-run)";if(d[c++]=r,--s>0)for(var _=0;_>s,2),h=0;h<6;h++){var l=r.subarray(o,o+a);n[s].push(l),o+=a}}return n}:null,s=function(n){var s=t.getScene();if(!s)return null;var a=new Int32Array(n);r=new Float32Array(n);var h=a[0];if(t._size=a[1],!t._texture)return null;t._texture.updateSize(t._size,t._size);var l=new e.SphericalPolynomial;l.x.copyFromFloats(r[2],r[3],r[4]),l.y.copyFromFloats(r[5],r[6],r[7]),l.z.copyFromFloats(r[8],r[9],r[10]),l.xx.copyFromFloats(r[11],r[12],r[13]),l.yy.copyFromFloats(r[14],r[15],r[16]),l.zz.copyFromFloats(r[17],r[18],r[19]),l.xy.copyFromFloats(r[20],r[21],r[22]),l.yz.copyFromFloats(r[23],r[24],r[25]),l.zx.copyFromFloats(r[26],r[27],r[28]),t.sphericalPolynomial=l,i=a[29];for(var c=30,u=[],p=3*Math.pow(t._size,2),f=0;f<6;f++)u.push(r.subarray(c,c+p)),c+=p;for(var d=[],m=null,g=0;g<6;g++){var _=null;if(1===h){_=u[[0,2,4,1,3,5][g]]}if(!o&&_){if(!s.getEngine().getCaps().textureFloat){var v=new ArrayBuffer(p);m=new Uint8Array(v)}for(var y=0;y255){var A=255/E;b*=A,x*=A,T*=A}m[3*y+0]=b,m[3*y+1]=x,m[3*y+2]=T}}m?d.push(m):d.push(_)}return d};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,s,o,this._onLoad,this._onError))},i.prototype.loadHDRTexture=function(){var t=this,r=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=[],h=null,l=0;l<6;l++){if(!n.getEngine().getCaps().textureFloat){var c=new ArrayBuffer(t._size*t._size*3);h=new Uint8Array(c)}var u=o[i._facesMapping[l]];if(t._useInGammaSpace||h)for(var p=0;p255){var _=255/g;f*=_,d*=_,m*=_}h[3*p+0]=f,h[3*p+1]=d,h[3*p+2]=m}h?a.push(h):a.push(u)}return a},n=this.getScene();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,r,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===d(e,t,i,r)>0)for(o=t;o=t;o-=r)s=p(o,e[o],e[o+1],s);return s&&h(s,s.next)&&(f(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||!h(r,r.next)&&0!==a(r.prev,r,r.next))r=r.next;else{if(f(r),(r=t=r.prev)===r.next)return;i=!0}}while(i||r!==t);return t}function r(e,t,n,p,d,m,g){if(e){!g&&m&&function(e,t,i,r){var n=e;do{null===n.z&&(n.z=o(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,function(e){var t,i,r,n,o,s,a,h,l=1;do{for(i=e,e=null,o=null,s=0;i;){for(s++,r=i,a=0,t=0;t0||h>0&&r;)0===a?(n=r,r=r.nextZ,h--):0!==h&&r?i.z<=r.z?(n=i,i=i.nextZ,a--):(n=r,r=r.nextZ,h--):(n=i,i=i.nextZ,a--),o?o.nextZ=n:e=n,n.prevZ=o,o=n;i=r}o.nextZ=null,l*=2}while(s>1)}(n)}(e,p,d,m);for(var _,v,y=e;e.prev!==e.next;)if(_=e.prev,v=e.next,m?function(e,t,i,r){var n=e.prev,h=e,l=e.next;if(a(n,h,l)>=0)return!1;var c=n.xh.x?n.x>l.x?n.x:l.x:h.x>l.x?h.x:l.x,f=n.y>h.y?n.y>l.y?n.y:l.y:h.y>l.y?h.y:l.y,d=o(c,u,t,i,r),m=o(p,f,t,i,r),g=e.nextZ;for(;g&&g.z<=m;){if(g!==e.prev&&g!==e.next&&s(n.x,n.y,h.x,h.y,l.x,l.y,g.x,g.y)&&a(g.prev,g,g.next)>=0)return!1;g=g.nextZ}g=e.prevZ;for(;g&&g.z>=d;){if(g!==e.prev&&g!==e.next&&s(n.x,n.y,h.x,h.y,l.x,l.y,g.x,g.y)&&a(g.prev,g,g.next)>=0)return!1;g=g.prevZ}return!0}(e,p,d,m):function(e){var t=e.prev,i=e,r=e.next;if(a(t,i,r)>=0)return!1;var n=e.next.next;for(;n!==e.prev;){if(s(t.x,t.y,i.x,i.y,r.x,r.y,n.x,n.y)&&a(n.prev,n,n.next)>=0)return!1;n=n.next}return!0}(e))t.push(_.i/n),t.push(e.i/n),t.push(v.i/n),f(e),e=v.next,y=v.next;else if((e=v)===y){g?1===g?r(e=function(e,t,i){var r=e;do{var n=r.prev,o=r.next.next;!h(n,o)&&l(n,r,r.next,o)&&c(n,o)&&c(o,n)&&(t.push(n.i/i),t.push(r.i/i),t.push(o.i/i),f(r),f(r.next),r=e=o),r=r.next}while(r!==e);return r}(e,t,n),t,n,p,d,m,2):2===g&&function(e,t,n,o,s,a){var h=e;do{for(var p=h.next.next;p!==h.prev;){if(h.i!==p.i&&function(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(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&&l(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&c(e,t)&&c(t,e)&&function(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}(e,t)}(h,p)){var f=u(h,p);return h=i(h,h.next),f=i(f,f.next),r(h,t,n,o,s,a,void 0),void r(f,t,n,o,s,a,void 0)}p=p.next}h=h.next}while(h!==e)}(e,t,n,p,d,m):r(i(e,void 0),t,n,p,d,m,1);break}}}function n(e,t){return e.x-t.x}function o(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 s(e,t,i,r,n,o,s,a){return(n-s)*(t-a)-(e-s)*(o-a)>=0&&(e-s)*(r-a)-(i-s)*(t-a)>=0&&(i-s)*(o-a)-(n-s)*(r-a)>=0}function a(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function h(e,t){return e.x===t.x&&e.y===t.y}function l(e,t,i,r){return!!(h(e,t)&&h(i,r)||h(e,r)&&h(i,t))||a(e,t,i)>0!=a(e,t,r)>0&&a(i,r,e)>0!=a(i,r,t)>0}function c(e,t){return a(e.prev,e,e.next)<0?a(e,t,e.next)>=0&&a(e,e.prev,t)>=0:a(e,t,e.prev)<0||a(e,e.next,t)<0}function u(e,t){var i=new m(e.i,e.x,e.y),r=new m(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 m(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 f(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 d(e,t,i,r){for(var n=0,o=t,s=i-r;o=r.next.y){var h=r.x+(o-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(h<=n&&h>a){if(a=h,h===n){if(o===r.y)return r;if(o===r.next.y)return r.next}i=r.x=r.x&&r.x>=p&&s(oi.x)&&c(r,e)&&(i=r,d=l),r=r.next;return i}(e,t)){var r=u(t,e);i(r,r.next)}}(m[h],o),o=i(o,o.next);return o}(e,o,p,a)),e.length>80*a){v=d=e[0],y=m=e[1];for(var x=a;xd&&(d=g),_>m&&(m=_);b=Math.max(d-v,m-y)}return r(p,f,a,v,y,b,0),f};var m=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(d(e,0,o,i));if(n)for(var a=0,h=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,h=0;h0){var f=a.length/3;this._points.elements.forEach(function(e){s.push(0,-1,0),a.push(e.x,-i,e.y),h.push(1-(e.x-l.min.x)/l.width,1-(e.y-l.min.y)/l.height)});for(var d=c.length,p=0;ps.elements.length-1?s.elements[0]:s.elements[u+1],t.push(f.x,0,f.y),t.push(f.x,-a,f.y),t.push(p.x,0,p.y),t.push(p.x,-a,p.y);var d=new e.Vector3(f.x,0,f.y),m=new e.Vector3(p.x,0,p.y).subtract(d),g=new e.Vector3(0,1,0),_=e.Vector3.Cross(m,g);_=_.normalize(),r.push(c/o.width,0),r.push(c/o.width,1),c+=m.length(),r.push(c/o.width,0),r.push(c/o.width,1),h?(i.push(_.x,_.y,_.z),i.push(_.x,_.y,_.z),i.push(_.x,_.y,_.z),i.push(_.x,_.y,_.z),n.push(l),n.push(l+2),n.push(l+1),n.push(l+1),n.push(l+2),n.push(l+3)):(i.push(-_.x,-_.y,-_.z),i.push(-_.x,-_.y,-_.z),i.push(-_.x,-_.y,-_.z),i.push(-_.x,-_.y,-_.z),n.push(l),n.push(l+1),n.push(l+2),n.push(l+1),n.push(l+3),n.push(l+2)),l+=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 h,l,c=0,u=[];for(h=0;ht.EPSILON?1:0;c|=p,u.push(p)}switch(c){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 f=[],d=[];for(h=0;h=3&&(x=new n(f,i.shared)).plane&&s.push(x),d.length>=3&&(x=new n(d,i.shared)).plane&&a.push(x)}},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,h=i.y+i.height/2,l=a-this._positionX,c=h-this._positionY;t.enableEffect(this._effect),t.setState(!1),t.setDepthBuffer(!1),t.bindBuffers(this._vertexBuffers,this._indexBuffer,this._effect);for(var u=0;u-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],h=this.object;if(h.rotationQuaternion)if(s){var l=t._tmpQuat;h.rotationQuaternion.multiplyToRef(s,l),i.setRotationQuaternion(l,e.Space.WORLD,r)}else i.setRotationQuaternion(h.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(h.getAbsolutePosition()),i.setAbsolutePosition(a,r)):(r.setAbsolutePosition(h.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 h=this.object;if(h.rotationQuaternion)if(s){var l=t._tmpQuat;i.getRotationQuaternionToRef(e.Space.WORLD,r,l),l.multiplyToRef(s,h.rotationQuaternion)}else i.getRotationQuaternionToRef(e.Space.WORLD,r,h.rotationQuaternion);var c=t._tmpVecs[0],u=t._tmpVecs[1];a||((a=t._tmpVecs[2]).x=0,a.y=1,a.z=0),i.getDirectionToRef(a,r,u),i.getAbsolutePositionToRef(r,c),void 0!==o&&null!==o||!n||(o=n.length()),void 0!==o&&null!==o&&(c.x+=u.x*o,c.y+=u.y*o,c.z+=u.z*o),h.setAbsolutePosition(c)},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.getImpostors=function(){return this._impostors},t.prototype.getImpostorForPhysicsObject=function(e){for(var t=0;tn)return null;var p=s===t.Constant?o:o*(1-u/n);return{force:h.multiplyByFloats(p,p,p),contactPoint:c}},i.prototype.dispose=function(e){var t=this;void 0===e&&(e=!0),e?this._sphere.dispose():setTimeout(function(){t._dataFetched||t._sphere.dispose()},0)},i.prototype._prepareSphere=function(){this._sphere||(this._sphere=e.MeshBuilder.CreateSphere("radialExplosionEventSphere",this._sphereOptions,this._scene),this._sphere.isVisible=!1)},i.prototype._intersectsWithSphere=function(t,i,r){var n=t.object;return this._prepareSphere(),this._sphere.position=i,this._sphere.scaling=new e.Vector3(2*r,2*r,2*r),this._sphere._updateBoundingInfo(),this._sphere.computeWorldMatrix(!0),this._sphere.intersectsMesh(n,!0)},i}();e.PhysicsRadialExplosionEvent=n;var o=function(){function e(e,i,r,n,o,s){void 0===s&&(s=t.Constant),this._dataFetched=!1,this._physicsHelper=e,this._scene=i,this._origin=r,this._radius=n,this._strength=o,this._falloff=s,this._tickCallback=this._tick.bind(this)}return e.prototype.getData=function(){return this._dataFetched=!0,{sphere:this._sphere}},e.prototype.enable=function(){this._tickCallback.call(this),this._scene.registerBeforeRender(this._tickCallback)},e.prototype.disable=function(){this._scene.unregisterBeforeRender(this._tickCallback)},e.prototype.dispose=function(e){var t=this;void 0===e&&(e=!0),e?this._sphere.dispose():setTimeout(function(){t._dataFetched||t._sphere.dispose()},0)},e.prototype._tick=function(){if(this._sphere)this._physicsHelper.applyRadialExplosionForce(this._origin,this._radius,-1*this._strength,this._falloff);else{var e=this._physicsHelper.applyRadialExplosionForce(this._origin,this._radius,-1*this._strength,this._falloff);e&&(this._sphere=e.getData().sphere.clone("radialExplosionEventSphereClone"))}},e}();e.PhysicsGravitationalFieldEvent=o;var s=function(){function t(t,r,n,o,s,a,h){this._originTop=e.Vector3.Zero(),this._originDirection=e.Vector3.Zero(),this._cylinderPosition=e.Vector3.Zero(),this._dataFetched=!1,this._physicsEngine=t,this._scene=r,this._origin=n,this._radius=o,this._strength=s,this._height=a,this._updraftMode=h,this._origin.addToRef(new e.Vector3(0,this._height/2,0),this._cylinderPosition),this._origin.addToRef(new e.Vector3(0,this._height,0),this._originTop),this._updraftMode===i.Perpendicular&&(this._originDirection=this._origin.subtract(this._originTop).normalize()),this._tickCallback=this._tick.bind(this)}return t.prototype.getData=function(){return this._dataFetched=!0,{cylinder:this._cylinder}},t.prototype.enable=function(){this._tickCallback.call(this),this._scene.registerBeforeRender(this._tickCallback)},t.prototype.disable=function(){this._scene.unregisterBeforeRender(this._tickCallback)},t.prototype.dispose=function(e){var t=this;void 0===e&&(e=!0),e?this._cylinder.dispose():setTimeout(function(){t._dataFetched||t._cylinder.dispose()},0)},t.prototype.getImpostorForceAndContactPoint=function(e){if(0===e.mass)return null;if(!this._intersectsWithCylinder(e))return null;var t=e.getObjectCenter();if(this._updraftMode===i.Perpendicular)r=this._originDirection;else var r=t.subtract(this._originTop);var n=-1*this._strength;return{force:r.multiplyByFloats(n,n,n),contactPoint:t}},t.prototype._tick=function(){var e=this;this._physicsEngine.getImpostors().forEach(function(t){var i=e.getImpostorForceAndContactPoint(t);i&&t.applyForce(i.force,i.contactPoint)})},t.prototype._prepareCylinder=function(){this._cylinder||(this._cylinder=e.MeshBuilder.CreateCylinder("updraftEventCylinder",{height:this._height,diameter:2*this._radius},this._scene),this._cylinder.isVisible=!1)},t.prototype._intersectsWithCylinder=function(e){var t=e.object;return this._prepareCylinder(),this._cylinder.position=this._cylinderPosition,this._cylinder.intersectsMesh(t,!0)},t}();e.PhysicsUpdraftEvent=s}(s||(s={}));!function(e){var t=function(){function t(t,r){void 0===t&&(t=!0),void 0===r&&(r=10),this._useDeltaForWorldStep=t,this.name="CannonJSPlugin",this._physicsMaterials=new Array,this._fixedTimeStep=1/60,this.BJSCANNON="undefined"!=typeof CANNON?CANNON:i(15),this._minus90X=new e.Quaternion(-.7071067811865475,0,0,.7071067811865475),this._plus90X=new e.Quaternion(.7071067811865475,0,0,.7071067811865475),this._tmpPosition=e.Vector3.Zero(),this._tmpDeltaPosition=e.Vector3.Zero(),this._tmpUnityRotation=new e.Quaternion,this.isSupported()?(this.world=new this.BJSCANNON.World,this.world.broadphase=new this.BJSCANNON.NaiveBroadphase,this.world.solver.iterations=r):e.Tools.Error("CannonJS is not available. Please make sure you included the js file.")}return t.prototype.setGravity=function(e){this.world.gravity.copy(e)},t.prototype.setTimeStep=function(e){this._fixedTimeStep=e},t.prototype.getTimeStep=function(){return this._fixedTimeStep},t.prototype.executeStep=function(e,t){this.world.step(this._fixedTimeStep,this._useDeltaForWorldStep?e:0,3)},t.prototype.applyImpulse=function(e,t,i){var r=new this.BJSCANNON.Vec3(i.x,i.y,i.z),n=new this.BJSCANNON.Vec3(t.x,t.y,t.z);e.physicsBody.applyImpulse(n,r)},t.prototype.applyForce=function(e,t,i){var r=new this.BJSCANNON.Vec3(i.x,i.y,i.z),n=new this.BJSCANNON.Vec3(t.x,t.y,t.z);e.physicsBody.applyForce(n,r)},t.prototype.generatePhysicsBody=function(e){if(e.parent)e.physicsBody&&(this.removePhysicsBody(e),e.forceUpdate());else{if(e.isBodyInitRequired()){var t=this._createShape(e),i=e.physicsBody;i&&this.removePhysicsBody(e);var r=this._addMaterial("mat-"+e.uniqueId,e.getParam("friction"),e.getParam("restitution")),n={mass:e.getParam("mass"),material:r},o=e.getParam("nativeOptions");for(var s in o)o.hasOwnProperty(s)&&(n[s]=o[s]);e.physicsBody=new this.BJSCANNON.Body(n),e.physicsBody.addEventListener("collide",e.onCollide),this.world.addEventListener("preStep",e.beforeStep),this.world.addEventListener("postStep",e.afterStep),e.physicsBody.addShape(t),this.world.add(e.physicsBody),i&&["force","torque","velocity","angularVelocity"].forEach(function(t){e.physicsBody[t].copy(i[t])}),this._processChildMeshes(e)}this._updatePhysicsBodyTransformation(e)}},t.prototype._processChildMeshes=function(t){var i=this,r=t.object.getChildMeshes?t.object.getChildMeshes(!0):[],n=t.object.rotationQuaternion;if(r.length){var o=function(r,s){if(n&&s.rotationQuaternion){var a=s.getPhysicsImpostor();if(a){if(a.parent!==t){var h=s.getAbsolutePosition().subtract(t.object.getAbsolutePosition()),l=s.rotationQuaternion.multiply(e.Quaternion.Inverse(n));a.physicsBody&&(i.removePhysicsBody(a),a.physicsBody=null),a.parent=t,a.resetUpdateFlags(),t.physicsBody.addShape(i._createShape(a),new i.BJSCANNON.Vec3(h.x,h.y,h.z),new i.BJSCANNON.Quaternion(l.x,l.y,l.z,l.w)),t.physicsBody.mass+=a.getParam("mass")}}n.multiplyInPlace(s.rotationQuaternion),s.getChildMeshes(!0).filter(function(e){return!!e.physicsImpostor}).forEach(o.bind(i,s.getAbsolutePosition()))}};r.filter(function(e){return!!e.physicsImpostor}).forEach(o.bind(this,t.object.getAbsolutePosition()))}},t.prototype.removePhysicsBody=function(e){e.physicsBody.removeEventListener("collide",e.onCollide),this.world.removeEventListener("preStep",e.beforeStep),this.world.removeEventListener("postStep",e.afterStep),this.world.remove(e.physicsBody)},t.prototype.generateJoint=function(t){var i=t.mainImpostor.physicsBody,r=t.connectedImpostor.physicsBody;if(i&&r){var n,o=t.joint.jointData,s={pivotA:o.mainPivot?(new this.BJSCANNON.Vec3).copy(o.mainPivot):null,pivotB:o.connectedPivot?(new this.BJSCANNON.Vec3).copy(o.connectedPivot):null,axisA:o.mainAxis?(new this.BJSCANNON.Vec3).copy(o.mainAxis):null,axisB:o.connectedAxis?(new this.BJSCANNON.Vec3).copy(o.connectedAxis):null,maxForce:o.nativeParams.maxForce,collideConnected:!!o.collision};switch(t.joint.type){case e.PhysicsJoint.HingeJoint:case e.PhysicsJoint.Hinge2Joint:n=new this.BJSCANNON.HingeConstraint(i,r,s);break;case e.PhysicsJoint.DistanceJoint:n=new this.BJSCANNON.DistanceConstraint(i,r,o.maxDistance||2);break;case e.PhysicsJoint.SpringJoint:var a=o;n=new this.BJSCANNON.Spring(i,r,{restLength:a.length,stiffness:a.stiffness,damping:a.damping,localAnchorA:s.pivotA,localAnchorB:s.pivotB});break;case e.PhysicsJoint.LockJoint:n=new this.BJSCANNON.LockConstraint(i,r,s);break;case e.PhysicsJoint.PointToPointJoint:case e.PhysicsJoint.BallAndSocketJoint:default:n=new this.BJSCANNON.PointToPointConstraint(i,s.pivotA,r,s.pivotA,s.maxForce)}n.collideConnected=!!o.collision,t.joint.physicsJoint=n,t.joint.type!==e.PhysicsJoint.SpringJoint?this.world.addConstraint(n):t.mainImpostor.registerAfterPhysicsStep(function(){n.applyForce()})}},t.prototype.removeJoint=function(e){this.world.removeConstraint(e.joint.physicsJoint)},t.prototype._addMaterial=function(e,t,i){var r,n;for(r=0;rr.length)e.Tools.Error("Unable to load TGA file - Not enough data");else{n+=o.id_length;var s=!1,a=!1,h=!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:break;case t._TYPE_RLE_GREY:s=!0;case t._TYPE_GREY:h=!0}var l,c,u=o.pixel_size>>3,p=o.width*o.height*u;if(a&&(c=r.subarray(n,n+=o.colormap_length*(o.colormap_size>>3))),s){l=new Uint8Array(p);for(var f,d,m,g=0,_=new Uint8Array(u);n>t._ORIGIN_SHIFT){default:case t._ORIGIN_UL:v=0,b=1,E=o.width,y=0,x=1,T=o.height;break;case t._ORIGIN_BL:v=0,b=1,E=o.width,y=o.height-1,x=-1,T=-1;break;case t._ORIGIN_UR:v=o.width-1,b=-1,E=-1,y=0,x=1,T=o.height;break;case t._ORIGIN_BR:v=o.width-1,b=-1,E=-1,y=o.height-1,x=-1,T=-1}var A=t["_getImageData"+(h?"Grey":"")+o.pixel_size+"bits"](o,c,l,y,x,T,v,b,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,h){var l,c,u,p=i,f=t,d=e.width,m=e.height,g=0,_=new Uint8Array(d*m*4);for(u=r;u!==o;u+=n)for(c=s;c!==h;c+=a,g++)l=p[g],_[4*(c+d*u)+3]=255,_[4*(c+d*u)+2]=f[3*l+0],_[4*(c+d*u)+1]=f[3*l+1],_[4*(c+d*u)+0]=f[3*l+2];return _},t._getImageData16bits=function(e,t,i,r,n,o,s,a,h){var l,c,u,p=i,f=e.width,d=e.height,m=0,g=new Uint8Array(f*d*4);for(u=r;u!==o;u+=n)for(c=s;c!==h;c+=a,m+=2)l=p[m+0]+(p[m+1]<<8),g[4*(c+f*u)+0]=(31744&l)>>7,g[4*(c+f*u)+1]=(992&l)>>2,g[4*(c+f*u)+2]=(31&l)>>3,g[4*(c+f*u)+3]=32768&l?0:255;return g},t._getImageData24bits=function(e,t,i,r,n,o,s,a,h){var l,c,u=i,p=e.width,f=e.height,d=0,m=new Uint8Array(p*f*4);for(c=r;c!==o;c+=n)for(l=s;l!==h;l+=a,d+=3)m[4*(l+p*c)+3]=255,m[4*(l+p*c)+2]=u[d+0],m[4*(l+p*c)+1]=u[d+1],m[4*(l+p*c)+0]=u[d+2];return m},t._getImageData32bits=function(e,t,i,r,n,o,s,a,h){var l,c,u=i,p=e.width,f=e.height,d=0,m=new Uint8Array(p*f*4);for(c=r;c!==o;c+=n)for(l=s;l!==h;l+=a,d+=4)m[4*(l+p*c)+2]=u[d+0],m[4*(l+p*c)+1]=u[d+1],m[4*(l+p*c)+0]=u[d+2],m[4*(l+p*c)+3]=u[d+3];return m},t._getImageDataGrey8bits=function(e,t,i,r,n,o,s,a,h){var l,c,u,p=i,f=e.width,d=e.height,m=0,g=new Uint8Array(f*d*4);for(u=r;u!==o;u+=n)for(c=s;c!==h;c+=a,m++)l=p[m],g[4*(c+f*u)+0]=l,g[4*(c+f*u)+1]=l,g[4*(c+f*u)+2]=l,g[4*(c+f*u)+3]=255;return g},t._getImageDataGrey16bits=function(e,t,i,r,n,o,s,a,h){var l,c,u=i,p=e.width,f=e.height,d=0,m=new Uint8Array(p*f*4);for(c=r;c!==o;c+=n)for(l=s;l!==h;l+=a,d+=2)m[4*(l+p*c)+0]=u[d+0],m[4*(l+p*c)+1]=u[d+0],m[4*(l+p*c)+2]=u[d+0],m[4*(l+p*c)+3]=u[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)}var r=i("DXT1"),n=i("DXT3"),o=i("DXT5"),s=i("DX10"),a=function(){function t(){}return t.GetDDSInfo=function(t){var i=new Int32Array(t,0,31),a=new Int32Array(t,0,35),h=1;131072&i[2]&&(h=Math.max(1,i[7]));var l=i[21],c=l===s?a[32]:0,u=e.Engine.TEXTURETYPE_UNSIGNED_INT;switch(l){case 113:u=e.Engine.TEXTURETYPE_HALF_FLOAT;break;case 116:u=e.Engine.TEXTURETYPE_FLOAT;break;case s:if(10===c){u=e.Engine.TEXTURETYPE_HALF_FLOAT;break}}return{width:i[4],height:i[3],mipmapCount:h,isFourCC:4==(4&i[20]),isRGB:64==(64&i[20]),isLuminance:131072==(131072&i[20]),isCube:512==(512&i[28]),isCompressed:l===r||l===n||l===o,dxgiFormat:c,textureType:u}},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),h=new Uint16Array(o,r),l=0,c=0;c>8&255,e>>16&255,e>>24&255)}(d))}C&&(P=i._getWebGLTextureType(l.textureType),A=i._getRGBABufferInternalSizedFormat(l.textureType)),y=1,131072&T[2]&&!1!==c&&(y=Math.max(1,T[7]));for(var I=0;I>8&65280|e>>24&255},t.prototype.uploadLevels=function(e,i){switch(this.loadType){case t.COMPRESSED_2D:this._upload2DCompressedLevels(e,i)}},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],h=a.getParent();if(h){var l=this._debugLines[n];l||(l=[e.Vector3.Zero(),e.Vector3.Zero()],this._debugLines[n]=l),a.getAbsolutePositionToRef(this.mesh,l[0]),h.getAbsolutePositionToRef(this.mesh,l[1]),l[0].subtractInPlace(o),l[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 h=0;hthis.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,h._isEnabled=!0)},h._isEnabled=!1,h}();e.SIMDHelper=h}(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 h=t.call(this,i,"stereoscopicInterlace",["stepSize"],["camASampler"],1,r[1],o,s,a,n?"#define IS_STEREOSCOPIC_HORIZ 1":void 0)||this;return h._passedProcess=r[0]._rigPostProcess,h._stepSize=new e.Vector2(1/h.width,1/h.height),h.onSizeChangedObservable.add(function(){h._stepSize=new e.Vector2(1/h.width,1/h.height)}),h.onApplyObservable.add(function(e){e.setTextureFromPostProcess("camASampler",h._passedProcess),e.setFloat2("stepSize",h._stepSize.x,h._stepSize.y)}),h}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._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.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;o-i._padSensibilityDown&&(i._teleportationAllowed&&i._teleportCamera(),i._teleportationRequestInitiated=!1):e.y<-i._padSensibilityUp&&(i._teleportationRequestInitiated=!0))}),t.rightStick&&t.onrightstickchanged(function(e){i._rotationLeftAsked?e.x>-i._padSensibilityDown&&(i._rotationLeftAsked=!1):e.x<-i._padSensibilityUp&&(i._rotationLeftAsked=!0,i._rotationAllowed&&i._rotateCamera(!1)),i._rotationRightAsked?e.xi._padSensibilityUp&&(i._rotationRightAsked=!0,i._rotationAllowed&&i._rotateCamera(!0))})},t.prototype._enableTeleportationOnController=function(t){var i=this,r=t.mesh;if(r){for(var n=r.getChildMeshes(),o=0;o-i._padSensibilityDown&&(i._teleportationAllowed&&(i._teleportationAllowed=!1,i._teleportCamera()),i._teleportationRequestInitiated=!1):e.y<-i._padSensibilityUp&&("left"===t.hand&&i._leftLaserPointer?(i._leftLaserPointer.isVisible=!0,i._rightLaserPointer&&(i._rightLaserPointer.isVisible=!1)):i._rightLaserPointer&&(i._rightLaserPointer.isVisible=!0,i._leftLaserPointer&&(i._leftLaserPointer.isVisible=!1)),i._teleportationRequestInitiated=!0),i._rotationLeftAsked?e.x>-i._padSensibilityDown&&(i._rotationLeftAsked=!1):e.x<-i._padSensibilityUp&&(i._rotationLeftAsked=!0,i._rotationAllowed&&i._rotateCamera(!1)),i._rotationRightAsked?e.xi._padSensibilityUp&&(i._rotationRightAsked=!0,i._rotationAllowed&&i._rotateCamera(!0))}),t.onTriggerStateChangedObservable.add(function(e){i._pointerDownOnMeshAsked?e.valuei._padSensibilityUp&&(i._pointerDownOnMeshAsked=!0,i._currentMeshSelected&&i._currentHit&&i._scene.simulatePointerDown(i._currentHit))})}},t.prototype._createGazeTracker=function(){this._gazeTracker=e.Mesh.CreateTorus("gazeTracker",.0035,.0025,20,this._scene,!1),this._gazeTracker.bakeCurrentTransformIntoVertices(),this._gazeTracker.isPickable=!1;var t=new e.StandardMaterial("targetMat",this._scene);t.specularColor=e.Color3.Black(),t.emissiveColor=new e.Color3(.7,.7,.7),t.backFaceCulling=!1,this._gazeTracker.material=t},t.prototype._createTeleportationCircles=function(){this._teleportationCircle=e.Mesh.CreateGround("teleportationCircle",2,2,2,this._scene),this._teleportationCircle.isPickable=!1;var t=new e.DynamicTexture("DynamicTexture",512,this._scene,!0);t.hasAlpha=!0;var i=t.getContext();i.beginPath(),i.arc(256,256,200,0,2*Math.PI,!1),i.fillStyle=this._teleportationFillColor,i.fill(),i.lineWidth=10,i.strokeStyle=this._teleportationBorderColor,i.stroke(),i.closePath(),t.update();var r=new e.StandardMaterial("TextPlaneMaterial",this._scene);r.diffuseTexture=t,this._teleportationCircle.material=r;var n=e.Mesh.CreateTorus("torusTeleportation",.75,.1,25,this._scene,!1);n.isPickable=!1,n.parent=this._teleportationCircle;var o=new e.Animation("animationInnerCircle","position.y",30,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CYCLE),s=[];s.push({frame:0,value:0}),s.push({frame:30,value:.4}),s.push({frame:60,value:0}),o.setKeys(s);var a=new e.SineEase;a.setEasingMode(e.EasingFunction.EASINGMODE_EASEINOUT),o.setEasingFunction(a),n.animations=[],n.animations.push(o),this._scene.beginAnimation(n,0,60,!0),this._hideTeleportationCircle()},t.prototype._displayTeleportationCircle=function(){this._teleportationCircle.isVisible=!0,this._teleportationCircle.getChildren()[0].isVisible=!0},t.prototype._hideTeleportationCircle=function(){this._teleportationCircle.isVisible=!1,this._teleportationCircle.getChildren()[0].isVisible=!1},t.prototype._rotateCamera=function(t){var i=this;t?this._rotationAngle++:this._rotationAngle--,this.currentVRCamera.animations=[];var r=e.Quaternion.FromRotationMatrix(e.Matrix.RotationY(Math.PI/4*this._rotationAngle)),n=new e.Animation("animationRotation","rotationQuaternion",90,e.Animation.ANIMATIONTYPE_QUATERNION,e.Animation.ANIMATIONLOOPMODE_CONSTANT),o=[];o.push({frame:0,value:this.currentVRCamera.rotationQuaternion}),o.push({frame:6,value:r}),n.setKeys(o);var s=new e.CircleEase;s.setEasingMode(e.EasingFunction.EASINGMODE_EASEINOUT),n.setEasingFunction(s),this.currentVRCamera.animations.push(n),this._postProcessMove.animations=[];var a=new e.Animation("animationPP","vignetteWeight",90,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CONSTANT),h=[];h.push({frame:0,value:0}),h.push({frame:3,value:4}),h.push({frame:6,value:0}),a.setKeys(h),a.setEasingFunction(s),this._postProcessMove.animations.push(a);var l=new e.Animation("animationPP2","vignetteStretch",90,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CONSTANT),c=[];c.push({frame:0,value:0}),c.push({frame:3,value:10}),c.push({frame:6,value:0}),l.setKeys(c),l.setEasingFunction(s),this._postProcessMove.animations.push(l),this._postProcessMove.imageProcessingConfiguration.vignetteWeight=0,this._postProcessMove.imageProcessingConfiguration.vignetteStretch=0,this._postProcessMove.imageProcessingConfiguration.vignetteEnabled=!0,this._scene.beginAnimation(this._postProcessMove,0,6,!1,1,function(){i._postProcessMove.imageProcessingConfiguration.vignetteEnabled=!1}),this._scene.beginAnimation(this.currentVRCamera,0,6,!1,1)},t.prototype._moveTeleportationSelectorTo=function(t){if(t.pickedPoint){this._teleportationAllowed=!0,this._teleportationRequestInitiated?this._displayTeleportationCircle():this._hideTeleportationCircle(),this._haloCenter.copyFrom(t.pickedPoint),this._teleportationCircle.position.copyFrom(t.pickedPoint);var i=t.getNormal();if(i){var r=e.Vector3.Cross(e.Axis.Y,i),n=e.Vector3.Cross(i,r);e.Vector3.RotationFromAxisToRef(n,i,r,this._teleportationCircle.rotation)}this._teleportationCircle.position.y+=.1}},t.prototype._teleportCamera=function(){var t=this;this.currentVRCamera.animations=[];var i=new e.Animation("animationCameraTeleportationX","position.x",90,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CONSTANT),r=[];r.push({frame:0,value:this.currentVRCamera.position.x}),r.push({frame:11,value:this._haloCenter.x});var n=new e.CircleEase;n.setEasingMode(e.EasingFunction.EASINGMODE_EASEINOUT),i.setKeys(r),i.setEasingFunction(n),this.currentVRCamera.animations.push(i);var o=new e.Animation("animationCameraTeleportationY","position.y",90,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CONSTANT),s=[];s.push({frame:0,value:this.currentVRCamera.position.y}),s.push({frame:11,value:this._haloCenter.y+1.7}),o.setKeys(s),o.setEasingFunction(n),this.currentVRCamera.animations.push(o);var a=new e.Animation("animationCameraTeleportationZ","position.z",90,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CONSTANT),h=[];h.push({frame:0,value:this.currentVRCamera.position.z}),h.push({frame:11,value:this._haloCenter.z}),a.setKeys(h),a.setEasingFunction(n),this.currentVRCamera.animations.push(a),this._postProcessMove.animations=[];var l=new e.Animation("animationPP","vignetteWeight",90,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CONSTANT),c=[];c.push({frame:0,value:0}),c.push({frame:5,value:8}),c.push({frame:11,value:0}),l.setKeys(c),this._postProcessMove.animations.push(l);var u=new e.Animation("animationPP2","vignetteStretch",90,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CONSTANT),p=[];p.push({frame:0,value:0}),p.push({frame:5,value:10}),p.push({frame:11,value:0}),u.setKeys(p),this._postProcessMove.animations.push(u),this._postProcessMove.imageProcessingConfiguration.vignetteWeight=8,this._postProcessMove.imageProcessingConfiguration.vignetteStretch=10,this._postProcessMove.imageProcessingConfiguration.vignetteEnabled=!0,this._scene.beginAnimation(this._postProcessMove,0,11,!1,1,function(){t._postProcessMove.imageProcessingConfiguration.vignetteEnabled=!1}),this._scene.beginAnimation(this.currentVRCamera,0,11,!1,1)},t.prototype._castRayAndSelectObject=function(){var t;t=!this.currentVRCamera.rightController&&!this.currentVRCamera.leftController||this._leftLaserPointer&&!this._leftLaserPointer.isVisible&&!this._rightLaserPointer||this._rightLaserPointer&&!this._rightLaserPointer.isVisible&&!this._leftLaserPointer||this._rightLaserPointer&&this._leftLaserPointer&&!this._rightLaserPointer.isVisible&&!this._leftLaserPointer.isVisible?this.currentVRCamera.getForwardRay():this._leftLaserPointer&&this._leftLaserPointer.isVisible?this.currentVRCamera.leftController.getForwardRay():this.currentVRCamera.rightController.getForwardRay();var i=this._scene.pickWithRay(t,this._meshSelectionPredicate);if(i&&i.pickedPoint){var r=1;this._isActionableMesh&&(r=3),this._gazeTracker.scaling.x=i.distance*r,this._gazeTracker.scaling.y=i.distance*r,this._gazeTracker.scaling.z=i.distance*r;var n=i.getNormal();if(n){var o=e.Vector3.Cross(e.Axis.Y,n),s=e.Vector3.Cross(n,o);e.Vector3.RotationFromAxisToRef(s,n,o,this._gazeTracker.rotation)}this._gazeTracker.position.copyFrom(i.pickedPoint),this._gazeTracker.position.x<0?this._gazeTracker.position.x+=.002:this._gazeTracker.position.x-=.002,this._gazeTracker.position.y<0?this._gazeTracker.position.y+=.002:this._gazeTracker.position.y-=.002,this._gazeTracker.position.z<0?this._gazeTracker.position.z+=.002:this._gazeTracker.position.z-=.002,this._rightLaserPointer&&this._rightLaserPointer.isVisible&&(this._rightLaserPointer.scaling.y=i.distance,this._rightLaserPointer.position.z=-i.distance/2),this._leftLaserPointer&&this._leftLaserPointer.isVisible&&(this._leftLaserPointer.scaling.y=i.distance,this._leftLaserPointer.position.z=-i.distance/2)}if(i&&i.pickedMesh){if(this._currentHit=i,-1!==i.pickedMesh.name.indexOf(this._floorMeshName)&&i.pickedPoint)return void this._moveTeleportationSelectorTo(i);this._hideTeleportationCircle(),this._teleportationAllowed=!1,i.pickedMesh!==this._currentMeshSelected&&(this.meshSelectionPredicate(i.pickedMesh)?(this._currentMeshSelected=i.pickedMesh,i.pickedMesh.isPickable&&i.pickedMesh.actionManager?(this.changeGazeColor(new e.Color3(0,0,1)),this.changeLaserColor(new e.Color3(.2,.2,1)),this._isActionableMesh=!0):(this.changeGazeColor(new e.Color3(.7,.7,.7)),this.changeLaserColor(new e.Color3(.7,.7,.7)),this._isActionableMesh=!1),this.onNewMeshSelected.notifyObservers(this._currentMeshSelected)):(this._currentMeshSelected=null,this.changeGazeColor(new e.Color3(.7,.7,.7)),this.changeLaserColor(new e.Color3(.7,.7,.7))))}else this._currentHit=null,this._currentMeshSelected=null,this._teleportationAllowed=!1,this._hideTeleportationCircle(),this.changeGazeColor(new e.Color3(.7,.7,.7)),this.changeLaserColor(new e.Color3(.7,.7,.7))},t.prototype.changeLaserColor=function(e){this._leftLaserPointer&&this._leftLaserPointer.material&&(this._leftLaserPointer.material.emissiveColor=e),this._rightLaserPointer&&this._rightLaserPointer.material&&(this._rightLaserPointer.material.emissiveColor=e)},t.prototype.changeGazeColor=function(e){this._gazeTracker.material&&(this._gazeTracker.material.emissiveColor=e)},t.prototype.dispose=function(){this.isInVRMode()&&this.exitVR(),this._deviceOrientationCamera.dispose(),this._passProcessMove&&this._passProcessMove.dispose(),this._postProcessMove&&this._postProcessMove.dispose(),this._webVRCamera&&this._webVRCamera.dispose(),this._vrDeviceOrientationCamera&&this._vrDeviceOrientationCamera.dispose(),this._useCustomVRButton||document.body.removeChild(this._btnVR),document.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("vrdisplaypresentchange",this._onVrDisplayPresentChange)},t.prototype.getClassName=function(){return"VRExperienceHelper"},t}();e.VRExperienceHelper=t}(s||(s={}));!function(e){var t;!function(e){e[e.X=0]="X",e[e.Y=1]="Y",e[e.Z=2]="Z"}(t=e.JoystickAxis||(e.JoystickAxis={}));var i=function(){function i(r){var n=this;if(this._leftJoystick=!!r,i._globalJoystickIndex++,this._axisTargetedByLeftAndRight=t.X,this._axisTargetedByUpAndDown=t.Y,this.reverseLeftRight=!1,this.reverseUpDown=!1,this._touches=new e.StringDictionary,this.deltaPosition=e.Vector3.Zero(),this._joystickSensibility=25,this._inversedSensibility=1/(this._joystickSensibility/1e3),this._onResize=function(e){i.vjCanvasWidth=window.innerWidth,i.vjCanvasHeight=window.innerHeight,i.vjCanvas&&(i.vjCanvas.width=i.vjCanvasWidth,i.vjCanvas.height=i.vjCanvasHeight),i.halfWidth=i.vjCanvasWidth/2},!i.vjCanvas){window.addEventListener("resize",this._onResize,!1),i.vjCanvas=document.createElement("canvas"),i.vjCanvasWidth=window.innerWidth,i.vjCanvasHeight=window.innerHeight,i.vjCanvas.width=window.innerWidth,i.vjCanvas.height=window.innerHeight,i.vjCanvas.style.width="100%",i.vjCanvas.style.height="100%",i.vjCanvas.style.position="absolute",i.vjCanvas.style.backgroundColor="transparent",i.vjCanvas.style.top="0px",i.vjCanvas.style.left="0px",i.vjCanvas.style.zIndex="5",i.vjCanvas.style.msTouchAction="none",i.vjCanvas.setAttribute("touch-action","none");var o=i.vjCanvas.getContext("2d");if(!o)throw new Error("Unable to create canvas for virtual joystick");(i.vjCanvasContext=o).strokeStyle="#ffffff",i.vjCanvasContext.lineWidth=2,document.body.appendChild(i.vjCanvas)}i.halfWidth=i.vjCanvas.width/2,this.pressed=!1,this._joystickColor="cyan",this._joystickPointerID=-1,this._joystickPointerPos=new e.Vector2(0,0),this._joystickPreviousPointerPos=new e.Vector2(0,0),this._joystickPointerStartPos=new e.Vector2(0,0),this._deltaJoystickVector=new e.Vector2(0,0),this._onPointerDownHandlerRef=function(e){n._onPointerDown(e)},this._onPointerMoveHandlerRef=function(e){n._onPointerMove(e)},this._onPointerUpHandlerRef=function(e){n._onPointerUp(e)},i.vjCanvas.addEventListener("pointerdown",this._onPointerDownHandlerRef,!1),i.vjCanvas.addEventListener("pointermove",this._onPointerMoveHandlerRef,!1),i.vjCanvas.addEventListener("pointerup",this._onPointerUpHandlerRef,!1),i.vjCanvas.addEventListener("pointerout",this._onPointerUpHandlerRef,!1),i.vjCanvas.addEventListener("contextmenu",function(e){e.preventDefault()},!1),requestAnimationFrame(function(){n._drawVirtualJoystick()})}return i.prototype.setJoystickSensibility=function(e){this._joystickSensibility=e,this._inversedSensibility=1/(this._joystickSensibility/1e3)},i.prototype._onPointerDown=function(e){e.preventDefault(),(!0===this._leftJoystick?e.clientXi.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);e.AsyncLoop.Run(t.settings.length,function(e){!function(e,i){r.simplify(e,function(r){t.mesh.addLODLevel(e.distance,r),r.isVisible=!0,i()})}(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 h(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,h){return this.data[e]*this.data[n]*this.data[h]+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[h]},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 h=function(){function t(t){this._mesh=t,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;e.AsyncLoop.Run(this.decimationIterations,function(t){a-s<=o?t.breakLoop():function(t,i){setTimeout(function(){t%5==0&&n.updateMesh(0===t);for(var r=0;rh||r.deleted||r.isDirty))for(var o=0;o<3;++o)if(r.error[o]>0,function(t){if(a){var i=t+l.verticesStart,n=e.Vector3.FromArray(a,3*i),h=function(e){if(r)for(var t=0;t0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.UVKind,h),l.length>0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.ColorKind,l);var b=this._mesh.subMeshes[t];t>0&&(this._reconstructedMesh.subMeshes=[],_.forEach(function(t){e.SubMesh.AddToMesh(t.materialIndex,t.verticesStart,t.verticesCount,t.indexStart,t.indexCount,t.getMesh())}),e.SubMesh.AddToMesh(b.materialIndex,g,f,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(p,f).normalize();if(n[a]=!1,e.Vector3.Dot(d,h.normal)<.2)return!0}else n[a]=!0,s.push(h)}}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 h=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=h;var l=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=l;var c=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,h=0;h4&&(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){var s;if(void 0===i)s=!0;else{s=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 u=o.join("\n");return this._cachedDefines!==u&&(this._cachedDefines=u,this._glowMapGenerationEffect=this._scene.getEngine().createEffect("glowMapGeneration",s,["world","mBones","viewProjection","diffuseMatrix","color","emissiveMatrix"],["diffuseSampler","emissiveSampler"],u)),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(),h=i.getStencilOperationDepthFail(),l=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(l),i.setStencilBuffer(r),i.setStencilOperationPass(s),i.setStencilOperationFail(a),i.setStencilOperationDepthFail(h),i._stencilState.reset(),this.onAfterComposeObservable.notifyObservers(this);var c=this._mainTexture.getSize();this.setMainTextureSize(),c.width===this._mainTextureDesiredSize.width&&c.height===this._mainTextureDesiredSize.height||(this.onSizeChangedObservable.notifyObservers(this),this.disposeTextureAndPostProcesses(),this.createTextureAndPostProcesses())}},i.prototype.addExcludedMesh=function(e){if(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 h=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=h;var l=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=l;var c=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=c;var u=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 h=t.call(this,e)||this;return h.name=e,h.url=i,h.size=r,h.noMipmap=n,h.generateHarmonics=o,h.useInGammaSpace=s,h.usePMREMGenerator=a,h}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=u;var p=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 h(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 l(t,i,r,n,o);return this.tasks.push(s),s},t.prototype.addCubeTextureTask=function(e,t,i,r,n){var o=new c(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 u(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;el.upperRadiusLimit?l.upperRadiusLimit:h),h):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,h,l,c){void 0===o&&(o=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===s&&(s=null),void 0===a&&(a=null),void 0===h&&(h=null);var u=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_URL),p=String(t);return u.url=p,u.generateMipMaps=!i,u.samplingMode=o,u.invertY=r,u.baseWidth=this._options.textureSize,u.baseHeight=this._options.textureSize,u.width=this._options.textureSize,u.height=this._options.textureSize,c&&(u.format=c),u.isReady=!0,s&&s(),u},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._boundTexturesCache[this._activeTextureChannel]!==t&&(this._boundTexturesCache[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 h=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 l=this._reflectionTexture;if(l&&e.StandardMaterial.ReflectionTextureEnabled){if(!l.isReadyOrNotBlocking())return!1;switch(a.REFLECTION=!0,a.GAMMAREFLECTION=l.gammaSpace,a.REFLECTIONBLUR=this._reflectionBlur>0,a.REFLECTIONMAP_OPPOSITEZ=this.getScene().useRightHandedSystem?!l.invertZ:l.invertZ,a.LODINREFLECTIONALPHA=l.lodLevelInAlpha,l.coordinatesMode===e.Texture.INVCUBIC_MODE&&(a.INVERTCUBICMAP=!0),a.REFLECTIONMAP_3D=l.isCube,l.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,h,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 c=new e.EffectFallbacks;a.FOG&&c.addFallback(0,"FOG"),a.POINTSIZE&&c.addFallback(1,"POINTSIZE"),e.MaterialHelper.HandleFallbacksForShadows(a,c,this._maxSimultaneousLights),a.NUM_BONE_INFLUENCERS>0&&c.addCPUSkinningFallback(0,i);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),e.MaterialHelper.PrepareAttributesForBones(u,i,a,c),e.MaterialHelper.PrepareAttributesForInstances(u,a);var p=["world","view","viewProjection","vEyePosition","vLightsType","vFogInfos","vFogColor","pointSize","vClipPlane","mBones","vPrimaryColor","vSecondaryColor","vTertiaryColor","vReflectionInfos","reflectionMatrix","vReflectionMicrosurfaceInfos","shadowLevel","alpha","vBackgroundCenter","vReflectionControl","vDiffuseInfos","diffuseMatrix"],f=["diffuseSampler","reflectionSampler","reflectionSamplerLow","reflectionSamplerHigh"],d=["Material","Scene"];e.ImageProcessingConfiguration.PrepareUniforms(p,a),e.ImageProcessingConfiguration.PrepareSamplers(f,a),e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:p,uniformBuffersNames:d,samplers:f,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:u,uniformsNames:p,uniformBuffersNames:d,samplers:f,defines:g,fallbacks:c,onCompiled:m,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights}},h),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 h=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")),h&&e.StandardMaterial.ReflectionTextureEnabled&&(this._uniformBuffer.updateMatrix("reflectionMatrix",h.getReflectionTextureMatrix()),this._uniformBuffer.updateFloat2("vReflectionInfos",h.level,this._reflectionBlur),this._uniformBuffer.updateFloat3("vReflectionMicrosurfaceInfos",h.getSize().width,h.lodGenerationScale,h.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),h&&e.StandardMaterial.ReflectionTextureEnabled&&(o.REFLECTIONBLUR&&o.TEXTURELODSUPPORT?this._uniformBuffer.setTexture("reflectionSampler",h):o.REFLECTIONBLUR?(this._uniformBuffer.setTexture("reflectionSampler",h._lodTextureMid||h),this._uniformBuffer.setTexture("reflectionSamplerLow",h._lodTextureLow||h),this._uniformBuffer.setTexture("reflectionSamplerHigh",h._lodTextureHigh||h)):this._uniformBuffer.setTexture("reflectionSampler",h),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){var i=this;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.onDisposeObservable.add(function(){i._ground=null})),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 RADIANCEOCCLUSION\n#ifdef AMBIENTINGRAYSCALE\nfloat ambientMonochrome=ambientOcclusionColor.r;\n#else\nfloat ambientMonochrome=getLuminance(ambientOcclusionColor);\n#endif\nfloat seo=environmentRadianceOcclusion(ambientMonochrome,NdotVUnclamped);\nspecularEnvironmentReflectance*=seo;\n#endif\n#ifdef HORIZONOCCLUSION\n#ifdef BUMP\n#ifdef REFLECTIONMAP_3D\nfloat eho=environmentHorizonOcclusion(reflectionCoords,normalW);\nspecularEnvironmentReflectance*=eho;\n#endif\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\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\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();if(!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=function(i){var r=e.attributes.item(i),o=r.nodeName.split(".");o.reduce(function(e,t,i){var s=n.kebabToCamel(t);if(i===o.length-1){var a=r.nodeValue;if("true"===a)a=!0;else if("false"===a)a=!1;else{var h=parseFloat(a);isNaN(h)||(a=h)}e[s]=a}else e[s]=e[s]||{};return e[s]},t)},r=0;r0)&&(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 h=document.getElementById("close-button");return h&&h.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":if(t){(document.exitFullscreen||document.webkitExitFullscreen||document.msExitFullscreen||document.mozCancelFullScreen).call(document)}else{(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)}if(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(e){if(void 0===e&&(e=[]),this.configuration.skybox){var t=void 0;if(this.configuration.skybox.cubeTexture&&(t="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)),t){this.extendClassWithConfig(t,this.configuration.skybox.cubeTexture);var i=this.configuration.skybox.scale||this.scene.activeCamera&&(this.scene.activeCamera.maxZ-this.scene.activeCamera.minZ)/2||1,r=this.scene.createDefaultSkybox(t,this.configuration.skybox.pbr,i,this.configuration.skybox.blur);this.configuration.skybox.material&&this.configuration.skybox.material.imageProcessingConfiguration&&r&&(r.material.imageProcessingConfiguration=new o.ImageProcessingConfiguration),this.extendClassWithConfig(r,this.configuration.skybox),r&&e.push(r)}}if(this.configuration.ground){var n="boolean"==typeof this.configuration.ground?{}:this.configuration.ground,s=n.size||this.configuration.skybox&&this.configuration.skybox.scale||3e3,a=o.Mesh.CreatePlane("BackgroundPlane",s,this.scene),h=new o.BackgroundMaterial("groundmat",this.scene);if(a.rotation.x=Math.PI/2,a.receiveShadows=n.receiveShadows||!1,h.alpha=.9,h.alphaMode=o.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF,h.shadowLevel=.5,h.primaryLevel=1,h.primaryColor=new o.Color3(.2,.2,.3).toLinearSpace().scale(3),h.secondaryLevel=0,h.tertiaryLevel=0,h.useRGBColor=!1,h.enableNoise=!0,n.material&&this.extendClassWithConfig(a,a.material),a.material=h,!0===this.configuration.ground||n.shadowOnly){a.receiveShadows=!0;(c=new o.Texture("https://assets.babylonjs.com/environments/backgroundGround.png",this.scene)).gammaSpace=!1,c.hasAlpha=!0,h.diffuseTexture=c}else if(n.mirror){var l=new o.MirrorTexture("mirror",512,this.scene);l.mirrorPlane=new o.Plane(0,-1,0,0),l.renderList=l.renderList||[],e.length&&e.forEach(function(e){e&&l.renderList&&l.renderList.push(e)}),h.reflectionTexture=l}else if(n.material&&n.material.diffuseTexture){var c=new o.Texture(n.material.diffuseTexture,this.scene);h.diffuseTexture=c}!0===this.configuration.ground&&(a.receiveShadows=!0,a.material&&(a.material.alpha=.4)),this.extendClassWithConfig(a,n)}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 "},function(e,t){e.exports=" "},function(e,t){e.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAStUlEQVR42uyaA7TrShiFn23btm3btm3btm3btm372LWd9+318nSRNk2mtz3trLXX5PbmZOafPT9nxmq1VmuKFggEZs1ms0uVSqUj8vn8Q/SP5nK5lRpMjFYLh8NTZTKZhSBxi2KxeDlEPgh+BQVrhKbfwDNgZf45QZ2J0mrxeHxGtHJRCDoUQm+FpLd4joKc5aKJaDbDNzxuZT3yyLg1FqPVWPip0un0PBCxMUScD+6wtTJr+dz49hdsmh14nMiAKK0WiUSmgbjFC4XCYSz2VeB9/p2wyaxJK9EY93set+dxwhYr1QU9U7B4s4CNIfMM+pvAzyBm1VFjPl+D3cDELdacyVy4kMsdLBMrX0kf4beM1QCt9Ff7hY14nGRpWiIHBgYmU+BDwLMRi3EMJN4KpJUBa5g05OlHthORc4amIJXgZ30EPtXWyiHITFtN0JBziDz6DB6nHtYEI+i04BZQtJqwIfcAOBXM0hCEdXR0TM1k5ydV2Iv+CLTyeXbqgWeeeeY4DmnMOGjxTrw/aDVpkxtirW7Bos09xkns6+ublAlNA3Gr4S+3JCe4ksk9YOeWsdH4nkcTicTMZfLVuXjvrQYmKS54/EZaRReqaQvzz7FrZUYXBocz8BV2tWcQpEDR5eR7mPjGTmP98ssvEyra5N1CnZNZBL+Dp9mUF7A2a0W7u6dlE8/E82Ve0zVlCHz3HhFtnGAmfJWPC5Nm4pfSO6YLWIdVee/bOiFTiz1A/zL9xSpJqjLmpGHJZHJW9sDlvB/yul7gHlze4sY0Wr7UQLrwierA5fJf7eISrcaE9jHuh/TXsLk3j0aj81dbepRbUkXND40Gz7Hx1/SdaIRcz9BCxjDHh/A4nlMAxvjbKa0wZGaDKmeCO5nLAQoQOzs7fa86pVKpOfj2lSDsdc60N5Reat380uD5DfuyZ5KBwGzOc0jNiWCvet1QfONH+ushcz/M6AoqIUojapgWzgauBTEfiP6QzS+ix/E0qW6CB9MFCL7/G5Pd1DGd+uyz8SHmKB0eVPC9KAvwA3iK56Py6fTasVhseoMnVuMrs6h0seWelFnI9PqgIG+DTT2dSSsFsgw3+1z1ZpUsyyzOMrz7+QgH77+CB9gAp/HTWqFQaEqZMMOp4hKMd7hN1DcgxfMzLiLfsZFlMf7mScngA9Gfqp7w3XffuSe6WCi8Y9WufUYwsUKZY0EVVA5FoB3wR3MZNquTg3mxMNvSXw0+Bn1OrgBcid+ds9IxkHc51ljWJuNDAPsb67I/j5O5EfKaGkeyaSZ5hEktdEhxZrGs3GqMfxKL9aYCPJCtYqET4BIep6zQzI9N1L20rIA02geiO5HhYKunZ5JKdtgpNThSCzGpt+2z3YN0N8rkOaoW1K7Iicy9Gfs2HeuBrM+ytWuh3WiULvQxn2d90uh2OmUIkzpp8MZ+ayj4lcFvl6ZiznRxbRKTEe0j3JdizPkYb3fGvUim1n1FzptG4XP3rjQQ03tgWeW/oFBlPv8s8h6tG6GO1tBOKYoeKkFt4HmdhbI7V+F7Rk9P2traJlKRoZTP6x7WOeAl5tFZJyXOt3Xm/eabb47nwkWuCl4YHQf8nheh4BkgQpfWGrjxwdOAlEsNvR/sh6ldsJbXShlrXDbSyfV8tmznse/SL+ZCrnGUSvJ3X/6toUAaeowIVbXNa1rQ78IcfaCc1s+bkWj+ijKvCvjoj6Sf0Mm/5jOZbXinrc4PLdJQfbdSKzeuxkjFTSdJbs43qw2QtFNtX7mrTmr+c1+5OMIYz5VLRfj/2XnvlQa4ypMBCi6nMW7hwmFdI553VDXpB1wQHKyEYL0DZrHvLJ8LXnbjK2WmdCb9iMOF88+cK2D1d8MD96Kqm5+ZAlgHKBZ5Q8rHml3i6VRJGlfJDUI7Oo/4UAG7tdx4mPhlHSpy9Ub0oA4/qvGryrsVlOmuG/37IDniiZy4HOkPC9nsTm4miXlcrZIJ4X82gaA/2zvneNmdHoz/bNu2bdu2bdu2bdu2bdu2fbz3zfe9+eOizelMs93uns7n08uz0+48nUzwJPnFyQO2QAZi/IXNwgGTdXlTgFrfMnH4P9mRS6m18GgWFio/7xFVWiJAS59aHu5Tj7MMBQyxbIktFo1d0kS86mmMtZsmNGYOlknB6wkCTA8mWS5EtPz888+cxXc6vfkPmAqYcsAMxbFUmvZX77wzlhF82SqU4Pf++++PmjeqhBg4OS1QYCldAs4NTgvzrTzDWuxY435wwPYtMweMNXdk3NjzYd8GTHRWyhyE1xboxUzaS47JLieHwhmcvb0oYIvJz35Z0nP4o14YNxcEznenGVXKCTAi5VYCC3CnrXOS//dKJiP4j7entxCk/Bzet1rJAL463D9h42K9LSdmnUhE3yuWSNFA/f6WQsROh9HoyAHbRz1glptzh/JkKdqAqFfrjZD5RFrtZ+3glcNlvX1mCIA3GvYegQ54TM85Ltg9YsNNZu0KAXmz8uzgrtMss0/W7z8v64YdvKQHwElaL1xiK4dJFv2RvPYrURe513dynfYtgXD/8Kj7YFM5BoG6xEs2kyXvx8k6IYFzWcRxEjIKt0/5eezgqSzxqYVRahFsymc06jKHIaJLCLC94zr//XcBXno3F3I/IbOxYHkMalnk2SzfMp4t68yBSmP5lTVH6HUB9VxscXljxzGwLDXA7DjJJZ7F6znVmTRsb1/+qTwA828Z+FjbWvYrGQcDShICFPLw10C9wSHDbrchbBqArR3HZtk2cL779aOmAnJ/1gnZjSbAtv16ouWDVc7WHvIzM1iaeCsDjIYduIOvyPLl9wh4wF0Tio1NEVCt5lZxYY5arzpZcovV5Zq8rAALlfZdi9pDFC3whdktyw7ekLWPnZBzNDDm+xxi12FXjkbylizKkfLnxwZgTy5R4h18fy9YvB8yn4j0DTMFkUkBzaLN4hjxyJTAr2x5ogwxPp0sws4Q/nCypzxzmQG+1yHjxNCJjBik/PDFGWT+fV6pMMpEWNPSsDUBey2lv3xoBhHKDzAb5AS7XEaQRdPz66+/Tpp5dzwnpK/u7p7HI0QMouWDyDf6scQXpn+Nj5fCmZSl38G7eWV94meIKB3YDwf9s4HsSgC+JeYLy+e+I7nK1iZbB2Ap/radEQGbP3Dt3o4uwZvmK64JFQd6pxcgmgg+Qh8BmO87vaFg7Ro41zl5CppN2dNT+96w43wA1vn6EMDTegX6SYTLaVeS61r7KQu7Um52pifAHW1tJ7cawCiIkn4ygbGDbwqcb+nsaBrnAmJ0EHblwoaLzQNg5tu6BQH+2DERoSbYLBiUfZDmK2Yi3j7/BTRF9Ip9CWAUTfn/DwLm+o30o6BkNHKG0/KP2jq6t+Kl0cmXcwT4b1HaxuoLAFPawTEODCtmhKD0TBK7RI0/PM3b1dnZvSM7OSFNggdcIfaLy73nbH2AbaqOUpjbA+Z6MCoZTQt0pXqXNCfojATTas5IdgZn+mJ9ZAefYYRLlwt8We4MhBfwOm8bIBd4rbSzuo00CUvEOAAiZZKWazWAKfriFc4kyz9XicP+jS+6Vg34rCvAYoot0GoAW1Qd6EeBO3iXGJNop0GZGAT4iwPY4Iq1AMBSI3Mhr0C/YDVvzA6eNYngJl4tRLI5cF/KGfO9IyBjtRLAOIgsogME/ZD5BJNpggHmQykP959c0+WqGGAHrTdtOYDDqTofhSTJx1CaACiVmaEPMJU3wPo2Ht/qAFvsR0zQkNojYFGXGpY8BEEIb4ApJ9jqAFtUHanDOXkIN7ynq+uaaIDxtvTyJn6QlqcrovYOLwcA+a5yr7+bGWCtoUU9MbrQLO4U6AeDs/Ls4LMy3OBjkrttdmY+gHGZQnZvNoAV1E9kjc6jQFyGemI4OZYOtIHXjQZYPnxQxrfoLbp9ebQKAGBb5JcZYC3P39PzBlWFtIDZUHVusbBEIQRxrVc1Ql8EWIn8b9IEC8J+niq6pO6EBGfylGTCVFoy8IvejPqfI4aL0X53MwDM4mrVm508a1ozp3e9svBsQ/umt5LhB98oCuD29rfKCrD65R+mRieZE57Vc2uSXgvHO6CuGEfjO5izeQCGm/tv6EJop7SZPQPhnZ0d9xcNcK3/+EELr64FqJ5FVXEmAaoIeM3E8DO37OGgvVJ63hFgRP5ZRQGsvQavFY12JepcOye+TUoNbfn9BUDNGZE6x+OBHi+eymJrl94Aaz3mD4hty6Kt4pkQp1ki0xLxYS0B1ZU473DoH9mqAJMNoHlYmDPh/ly7itDMslP3o/J8LlDt9N1V/FvftQDA+NFlvnm1iq3LoPEmJSQE1MPpy1iTUTyvOmLwlmTl+cr4yuGhO+67777R/AH2HzgxKFkhgB4TkAzn1joQgmJhre+0edW4ohG+m/fhP/3008kSCAg7lwFgCIk07+LokuvdRhRW0w42l7n1GeLNzLLznn766THFszKjgPyTt+gRE2XDRgGMKEf8yqIeX8RONepmP6/tDsb27g72cpaHkMJdU+nPL8Bb5gkw/1YkwLhdaXujlerfb9BORbt/n3omBmsj/yDCgRcnABjs1o1565oJYJwPKn5P1CZa3Q3s+X8Jz2Jo975Dazz2hACjBn1XmQHWvhLzyoIeS3y7iJ1q+LZvo8oBzTfrCqZBJTkzBBit93F22QBWX/lSBN8bulO1kRat6SS3aLzi0LSTwV8KAYa+wFqQNPMQhWr9pNL2eQCmtyANl2lxC1GtwU2z3tR48cwR+tDwHX//PXNAnDmcbSkPl9iSXTTotQ0x+EwA8W6HQed4/fXXJ470iZ+tjSl/LkT82r0GLxSrZIGYeDFVeeXIO1S1+Hvr3cp8Wbk6E2K5OxsPODH+3lgfqzg/EKse3VuKtldvr0mTENI7I9Z5XMS3xp07jIp2/ucxiWehzm91EX4bDnBxncod7dXdJHth7BgRLEfJalQBxFsVsj7u7VxpsBF4Y0Q8u//vpgXYtldPoK1cjM0NKY+MQ/oRZwgTLlOUZj0KpkXom6U1JNuaHWC1Vy+CXBdjr2rA/2BAlaun0CBDgEiZEgUiVHRQQcDol7tXWQFWe/VW+eMaFKAJPdrQRQTUrRDjkY2hvyq8NT5Bcs0+vCThv4c0amKekqTZtv377/Up93m3gabNk/Qb/O6778aNad9L02iZ4344bjnTXj50BS9gRx4u5XHvShFFU6SxHeQztw36JVLm4R6PNMBePepvsTtjzlWZY0FKAnva3dQQbQjAGN7yhu+SIloBcYyUlnej0kUzC5kMznRR9iolo2JEIbxo+iLXy0OGS3WIRo201Ayp1PIeIKa0vQO48eXBv2kQwCza/+3V7nh7dXL57E4yhw/nymZ5LjZE2YZU67lHF/LWNBebiMFZ8TYVBbDaq8/J7xvHdOZGwULRkjnuqHdzavQbuQ987JU0F7iBwwBGz7VT08jaND7my9QLYOxVje0eGGOv0otJRPeisCkwkQoIRKADHGk/a4kAZtRkiEZ5jGEbbk32QIoWfUZsa3WaZckf5yD4EXGuTq89nb50az5t94G6VV6khQs3h7zSUMnAs6q7S87xRoiiBH/2UYF+YMjra8ifR40IjeLc30vmeAlxXoAn7AV6L9r9K0oOcELVnhUD51k5w1mForNtjB8YjV4WeWOZ4yG52gryhF0K30uPraYciNZT076gXFPnSWfVanxvYK/WpElHxMs3IpXlWOgi4sQ8L1IBp4laFc0/iO/WZKR84c9EJE8WCrDaqxfI2z976FlFzhWfG4B7VSvIvj5ZpNaMTbpbbda/fLknDDv09Sz2p9JsbqPYKRptRCLd1Dhj5Pe3CgL1P7ke1V5UfL/WHXiy5HrFWAyAG763EGXwfYVmhANDbd6Ogsokfaahw6k0h7hvDNEQ58KZYcQ5r7HFbbBz/wbO+YJZkavri9o3hyzAyobZwULtmyPgMR9lhWx71d0Z8Q7FauTlnVB3azWIGxux4G4KoWYNcGiX0n1ELr7CZwssRXgpzAp1vVYjodv39cYCdspILRaGjUsf/gHJaAWdrW+QG0Rv/QrFbPHSBywngFzzDeiEkB2zovybktEch90C9wcI/zQjSelhUQ3DJTkpdrCxwD+IJroCvCdPXnMAg2PLfDU6qoF/eX6TZVl8Lclzax0dsyrVqBpO4pqAQHcDecz3EvxQwkI16kGkp9m0v2ljxoU/UGfElBUCxYCMK/HKejMj5LpRriWVx1yNIgfmhyz+83U4WzFvDsAZUa1yYwfcLAh4P3kwI+S6RMybBcrHjKg8XQshTiOZESR+bS+prONUK1niITtvezTcAGYEid2zasSpGUY1ekSztpgRcpHpsK5co1er1YRDu6DelsCMOL5d6DmVo78FBgRzcRy+pgTzFeiqVq1Ki43KZo0b/wP23paVqC/D3gAAAABJRU5ErkJggg=="},function(e,t){e.exports=" "},function(e,t){e.exports="
{{closeText}}
"},function(e,t){e.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAQAAAD9CzEMAAAAt0lEQVR42u2WAQbDQBBFQ9IbRtDcrrqK3LBbXrEH6OuHEPMBjPd2xHyZKtdNpcLMg11Pr7y4/YdvwIdd4jtw4BU0Rjrbz9mNzkjzgpU3wNhCvH5M3i1fKzzeK3K8V+R4r8jxTpHjlULhc0WOd8fU6e4I8y3y13tFjHel4GswwAvFSR/ZN6Zv2gjvmzbGhwqPzxUenys83is8Pld4vFac/9sy8/SVNrbgYJl8WGhsvkpoA1+pVK6ZLyLNXm2txsT5AAAAAElFTkSuQmCC"},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="undefined"==typeof Promise?i(32).Promise:Promise,t.disableInit=!1,document.addEventListener("DOMContentLoaded",function(e){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,h){if(!i[a]){if(!t[a]){if(!h&&("function"==typeof r&&r))return r(a,!0);if(s)return s(a,!0);throw new Error("Cannot find module '"+a+"'")}var l=i[a]={exports:{}};t[a][0].call(l.exports,function(e){var i=t[a][1][e];return o(i||e)},l,l.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 h=1;hs.x&&(s.x=l.x),l.xs.y&&(s.y=l.y),l.ys.z&&(s.z=l.z),l.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 h=this.lowerBound,l=this.upperBound;e.copy(h),t.set(l.x,h.y,h.z),i.set(l.x,l.y,h.z),r.set(h.x,l.y,l.z),n.set(l.x,h.y,h.z),o.set(h.x,l.y,h.z),s.set(h.x,h.y,l.z),a.copy(l)};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],h=i[4],l=i[5],c=i[6],u=i[7];this.getCorners(r,n,o,a,h,l,c,u);for(var p=0;8!==p;p++){var f=i[p];e.pointToLocal(f,f)}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],h=i[4],l=i[5],c=i[6],u=i[7];this.getCorners(r,n,o,a,h,l,c,u);for(var p=0;8!==p;p++){var f=i[p];e.pointToWorld(f,f)}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 h=new o;new o,new s,new o;r.prototype.doBoundingSphereBroadphase=function(e,t,i,r){var n=h;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 h=0;h=c&&(a=c-1),h<0?h=0:h>=u&&(h=u-1),l<0?l=0:l>=p&&(l=p-1),g<0?g=0:g>=c&&(g=c-1),_<0?_=0:_>=u&&(_=u-1),v<0?v=0:v>=p&&(v=p-1),h*=d,l*=m,g*=f,_*=d,v*=m;for(var P=a*=f;P<=g;P+=f)for(var M=h;M<=_;M+=d)for(var S=l;S<=v;S+=m){var C=P+M+S;w[C][D[C]++]=s}}for(var n=e.numObjects(),o=e.bodies,h=this.aabbMax,l=this.aabbMin,c=this.nx,u=this.ny,p=this.nz,f=u*p,d=p,m=1,g=h.x,_=h.y,v=h.z,y=l.x,b=l.y,x=l.z,T=c/(g-y),E=u/(_-b),A=p/(v-x),P=(g-y)/c,M=(_-b)/u,S=(v-x)/p,C=.5*Math.sqrt(P*P+M*M+S*S),R=s.types,I=R.SPHERE,O=R.PLANE,w=(R.BOX,R.COMPOUND,R.CONVEXPOLYHEDRON,this.bins),D=this.binLengths,L=this.bins.length,F=0;F!==L;F++)D[F]=0;for(var N=Math.ceil,l=Math.min,h=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,k=ie.position.z,z=B.radius;r(V-z,U-z,k-z,V+z,U+z,k+z,ie);break;case O:B.worldNormalNeedsUpdate&&B.computeWorldNormal(ie.quaternion);var G=B.worldNormal,W=y+.5*P-ie.position.x,H=b+.5*M-ie.position.y,j=x+.5*S-ie.position.z,X=a;X.set(W,H,j);for(var Y=0,K=0;Y!==c;Y++,K+=f,X.y=H,X.x+=P)for(var Q=0,Z=0;Q!==u;Q++,Z+=d,X.z=j,X.y+=M)for(var q=0,J=0;q!==p;q++,J+=m,X.z+=S)if(X.dot(G)1)for(var te=w[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,h=a.length;for(r=0;r!==h;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 o,this.to=t?t.clone():new o,this._direction=new o,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,L),i.vsub(t,f),e.vsub(t,d);var n,o,s=L.dot(L),a=L.dot(f),h=L.dot(d),l=f.dot(f),c=f.dot(d);return(n=l*h-a*c)>=0&&(o=s*c-a*h)>=0&&n+oe.boundingSphereRadius)){var n=this[e.type];n&&n.call(this,e,t,i,r)}};new o,new o;var _=new o,v=new o,y=new o,b=new o;new o,new h;r.prototype.intersectBox=function(e,t,i,r){return this.intersectConvex(e.convexPolyhedronRepresentation,t,i,r)},r.prototype[l.types.BOX]=r.prototype.intersectBox,r.prototype.intersectPlane=function(e,t,i,r){var n=this.from,s=this.to,a=this._direction,h=new o(0,0,1);t.vmult(h,h);var l=new o;n.vsub(i,l);var c=l.dot(h);s.vsub(i,l);if(!(c*l.dot(h)>0||n.distanceTo(s)p)&&(p=l[0]),(null===u||l[1]f)&&(f=l[1])),null!==c){var m=[];e.getRectMinMax(c,u,p,f,m);for(var g=c;g<=p;g++)for(var _=u;_<=f;_++){if(this.result._shouldStop)return;if(e.getConvexTrianglePillar(g,_,!1),a.pointToWorldFrame(i,t,e.pillarOffset,s),this.intersectConvex(e.pillarConvex,t,s,n,x),this.result._shouldStop)return;e.getConvexTrianglePillar(g,_,!0),a.pointToWorldFrame(i,t,e.pillarOffset,s),this.intersectConvex(e.pillarConvex,t,s,n,x)}}},r.prototype[l.types.HEIGHTFIELD]=r.prototype.intersectHeightfield;var T=new o,E=new o;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),h=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)),l=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),c=Math.pow(h,2)-4*a*l,u=T,p=E;if(!(c<0))if(0===c)n.lerp(o,c,u),u.vsub(i,p),p.normalize(),this.reportIntersection(p,u,e,r,-1);else{var f=(-h-Math.sqrt(c))/(2*a),d=(-h+Math.sqrt(c))/(2*a);if(f>=0&&f<=1&&(n.lerp(o,f,u),u.vsub(i,p),p.normalize(),this.reportIntersection(p,u,e,r,-1)),this.result._shouldStop)return;d>=0&&d<=1&&(n.lerp(o,d,u),u.vsub(i,p),p.normalize(),this.reportIntersection(p,u,e,r,-1))}},r.prototype[l.types.SPHERE]=r.prototype.intersectSphere;var A=new o,P=(new o,new o,new o);r.prototype.intersectConvex=function(e,t,i,r,o){for(var s=A,a=P,h=o&&o.faceList||null,l=e.faces,c=e.vertices,u=e.faceNormals,p=this._direction,f=this.from,d=this.to,m=f.distanceTo(d),g=h?h.length:l.length,x=this.result,T=0;!x._shouldStop&&Tm||this.reportIntersection(s,_,e,r,E)}}}}},r.prototype[l.types.CONVEXPOLYHEDRON]=r.prototype.intersectConvex;var M=new o,S=new o,C=new o,R=new o,I=new o,O=new o,w=(new c,[]),D=new a;r.prototype.intersectTrimesh=function(e,t,i,r,o){var s=M,h=w,l=D,c=P,u=S,p=C,f=R,d=O,m=I,g=(o&&o.faceList,e.indices),x=(e.vertices,e.faceNormals,this.from),T=this.to,E=this._direction;l.position.copy(i),l.quaternion.copy(t),a.vectorToLocalFrame(i,t,E,u),a.pointToLocalFrame(i,t,x,p),a.pointToLocalFrame(i,t,T,f);var A=p.distanceSquared(f);e.tree.rayQuery(this,l,h);for(var L=0,F=h.length;!this.result._shouldStop&&L!==F;L++){var N=h[L];e.getNormal(N,s),e.getVertex(g[3*N],v),v.vsub(p,c);var B=u.dot(s),V=s.dot(c)/B;if(!(V<0)){u.scale(V,_),_.vadd(p,_),e.getVertex(g[3*N+1],y),e.getVertex(g[3*N+2],b);var U=_.distanceSquared(p);!n(_,y,v,b)&&!n(_,v,y,b)||U>A||(a.vectorToWorldFrame(t,s,m),a.pointToWorldFrame(i,t,_,d),this.reportIntersection(m,d,e,r,N))}}h.length=0},r.prototype[l.types.TRIMESH]=r.prototype.intersectTrimesh,r.prototype.reportIntersection=function(e,t,i,n,o){var s=this.from,a=this.to,h=s.distanceTo(t),l=this.result;if(!(this.skipBackfaces&&e.dot(this._direction)>0))switch(l.hitFaceIndex=void 0!==o?o:-1,this.mode){case r.ALL:this.hasHit=!0,l.set(s,a,e,t,i,n,h),l.hasHit=!0,this.callback(l);break;case r.CLOSEST:(h=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,h=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),n=0;n!==a;n++){var l=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,h),r=Math.PI/2,n=0),l<-.499&&(i=-2*Math.atan2(o,h),r=-Math.PI/2,n=0),isNaN(i)){var c=o*o,u=s*s,p=a*a;i=Math.atan2(2*s*h-2*o*a,1-2*u-2*p),r=Math.asin(2*l),n=Math.atan2(2*o*h-2*s*a,1-2*c-2*p)}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),h=Math.sin(t/2),l=Math.sin(i/2);return"XYZ"===r?(this.x=a*o*s+n*h*l,this.y=n*h*s-a*o*l,this.z=n*o*l+a*h*s,this.w=n*o*s-a*h*l):"YXZ"===r?(this.x=a*o*s+n*h*l,this.y=n*h*s-a*o*l,this.z=n*o*l-a*h*s,this.w=n*o*s+a*h*l):"ZXY"===r?(this.x=a*o*s-n*h*l,this.y=n*h*s+a*o*l,this.z=n*o*l+a*h*s,this.w=n*o*s-a*h*l):"ZYX"===r?(this.x=a*o*s-n*h*l,this.y=n*h*s+a*o*l,this.z=n*o*l-a*h*s,this.w=n*o*s+a*h*l):"YZX"===r?(this.x=a*o*s+n*h*l,this.y=n*h*s+a*o*l,this.z=n*o*l-a*h*s,this.w=n*o*s-a*h*l):"XZY"===r&&(this.x=a*o*s-n*h*l,this.y=n*h*s-a*o*l,this.z=n*o*l+a*h*s,this.w=n*o*s+a*h*l),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){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){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){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){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,h=this.z;return t=t||new r,t.x=a*o-h*n,t.y=h*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 h,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"),h=(e("../material/Material"),e("../collision/AABB")),l=e("../shapes/Box");(r.prototype=new n).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){t=t||new o;return e.vsub(this.position,t),this.quaternion.conjugate().vmult(t,t),t},r.prototype.vectorToLocalFrame=function(e,t){t=t||new o;return this.quaternion.conjugate().vmult(e,t),t},r.prototype.pointToWorldFrame=function(e,t){t=t||new o;return this.quaternion.vmult(e,t),t.vadd(this.position,t),t},r.prototype.vectorToWorldFrame=function(e,t){t=t||new o;return this.quaternion.vmult(e,t),t};var c=new o,u=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 p=new h;r.prototype.computeAABB=function(){for(var e=this.shapes,t=this.shapeOffsets,i=this.shapeOrientations,r=e.length,n=c,o=u,s=this.quaternion,a=this.aabb,h=p,l=0;l!==r;l++){var f=e[l];i[l].mult(s,o),o.vmult(t[l],n),n.vadd(this.position,n),f.calculateWorldAABB(n,o,h.lowerBound,h.upperBound),0===l?a.copy(h):a.extend(h)}this.aabbNeedsUpdate=!1};var f=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=f,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 _=new o,v=new o;r.prototype.applyLocalForce=function(e,t){if(this.type===r.DYNAMIC){var i=_,n=v;this.vectorToWorldFrame(e,i),this.pointToWorldFrame(t,n),this.applyForce(i,n)}};var y=new o,b=new o,x=new o;r.prototype.applyImpulse=function(e,t){if(this.type===r.DYNAMIC){var i=y;t.vsub(this.position,i);var n=b;n.copy(e),n.mult(this.invMass,n),this.velocity.vadd(n,this.velocity);var o=x;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),l.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){var r=x,n=T,o=E,s=A;return t.vsub(e.position,r),r.cross(i,n),e.invInertiaWorld.vmult(n,s),s.cross(r,o),e.invMass+i.dot(o)}e("./Body");var o=e("../math/Vec3"),s=e("../math/Quaternion"),a=(e("../collision/RaycastResult"),e("../collision/Ray")),h=e("../objects/WheelInfo");t.exports=r;new o,new o,new o;var l=new o,c=new o,u=new o;new a;r.prototype.addWheel=function(e){var t=new h(e=e||{}),i=this.wheelInfos.length;return this.wheelInfos.push(t),i},r.prototype.setSteeringValue=function(e,t){this.wheelInfos[t].steering=e};new o;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;nf.maxSuspensionForce&&(l=f.maxSuspensionForce),f.raycastResult.hitNormalWorld.scale(l*e,a),f.raycastResult.hitPointWorld.vsub(r.position,h),r.applyImpulse(a,f.raycastResult.hitPointWorld)}this.updateFriction(e);var c=new o,u=new o,p=new o;for(n=0;n0?1:-1)*f.customSlidingRotationalSpeed*e),Math.abs(f.brake)>Math.abs(f.engineForce)&&(f.deltaRotation=0),f.rotation+=f.deltaRotation,f.deltaRotation*=.99}},r.prototype.updateSuspension=function(e){for(var t=this.chassisBody.mass,i=this.wheelInfos,r=i.length,n=0;nm&&(e.suspensionLength=m,e.raycastResult.reset());var g=e.raycastResult.hitNormalWorld.dot(e.directionWorld),_=new o;r.getVelocityAtWorldPoint(e.raycastResult.hitPointWorld,_);var v=e.raycastResult.hitNormalWorld.dot(_);if(g>=-.1)e.suspensionRelativeVelocity=0,e.clippedInvContactDotSuspension=10;else{var y=-1/g;e.suspensionRelativeVelocity=v*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=l,i=c,r=u,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,a=new s;a.setFromAxisAngle(t,o);var h=new s;h.setFromAxisAngle(i,n.rotation);var p=n.worldTransform.quaternion;this.chassisBody.quaternion.mult(a,p),p.mult(h,p),p.normalize();var f=n.worldTransform.position;f.copy(n.directionWorld),f.scale(n.suspensionLength,f),f.vadd(n.chassisConnectionPointWorld,f)};var d=[new o(1,0,0),new o(0,1,0),new o(0,0,1)];r.prototype.getWheelTransformWorld=function(e){return this.wheelInfos[e].worldTransform};var m=new o,g=[],_=[];r.prototype.updateFriction=function(e){for(var t=m,i=this.wheelInfos,r=i.length,s=this.chassisBody,a=_,h=g,l=0;l1.1)return 0;var s=P,a=M,h=S;return e.getVelocityAtWorldPoint(t,s),i.getVelocityAtWorldPoint(r,a),s.vsub(a,h),-.2*n.dot(h)*(1/(e.invMass+i.invMass))}(s,w.raycastResult.hitPointWorld,f,w.raycastResult.hitPointWorld,c),w.sideImpulse*=1}}this.sliding=!1;for(l=0;lA){this.sliding=!0,w.sliding=!0;var O=E/Math.sqrt(I);w.skidInfo*=O}}}if(this.sliding)for(l=0;lthis.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 h=this.particles[a];h.position.vsub(e.position,s),r!==h.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),l>r.y&&(r.y=l),c>r.z&&(r.z=c),af&&(f=m,p=d)}for(var g=[],_=i.faces[p],v=_.length,y=0;y=0&&this.clipFaceAgainstHull(s,e,t,g,a,h,l)};var u=new o,p=new o,f=new o,d=new o,m=new o,g=new o;r.prototype.findSeparatingAxis=function(e,t,i,r,n,o,s,a){var h=u,l=p,c=f,_=d,v=m,y=g,b=Number.MAX_VALUE,x=this;if(x.uniqueAxes)for(E=0;E!==x.uniqueAxes.length;E++){i.vmult(x.uniqueAxes[E],h);if(!1===(M=x.testSepAxis(h,e,t,i,r,n)))return!1;M0&&o.negate(o),!0};var _=[],v=[];r.prototype.testSepAxis=function(e,t,i,n,o,s){r.project(this,e,i,n,_),r.project(t,e,o,s,v);var a=_[0],h=_[1],l=v[0],c=v[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 h=t;h<=r;h++){var l=o[a][h];l>s&&(s=l)}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,h=this.elementSize,l=r.faces;r.vertices.length=6;for(c=0;c<6;c++)r.vertices[c]||(r.vertices[c]=new s);l.length=5;for(var c=0;c<5;c++)l[c]||(l[c]=[]);var u=r.vertices,p=(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)*h,(t+.75)*h,p),u[0].set(.25*h,.25*h,a[e+1][t+1]-p),u[1].set(-.75*h,.25*h,a[e][t+1]-p),u[2].set(.25*h,-.75*h,a[e+1][t]-p),u[3].set(.25*h,.25*h,-p-1),u[4].set(-.75*h,.25*h,-p-1),u[5].set(.25*h,-.75*h,-p-1),l[0][0]=0,l[0][1]=1,l[0][2]=2,l[1][0]=5,l[1][1]=4,l[1][2]=3,l[2][0]=2,l[2][1]=5,l[2][2]=3,l[2][3]=0,l[3][0]=3,l[3][1]=4,l[3][2]=1,l[3][3]=0,l[4][0]=1,l[4][1]=4,l[4][2]=5,l[4][3]=2):(n.set((e+.25)*h,(t+.25)*h,p),u[0].set(-.25*h,-.25*h,a[e][t]-p),u[1].set(.75*h,-.25*h,a[e+1][t]-p),u[2].set(-.25*h,.75*h,a[e][t+1]-p),u[3].set(-.25*h,-.25*h,-p-1),u[4].set(.75*h,-.25*h,-p-1),u[5].set(-.25*h,.75*h,-p-1),l[0][0]=0,l[0][1]=1,l[0][2]=2,l[1][0]=5,l[1][1]=4,l[1][2]=3,l[2][0]=0,l[2][1]=2,l[2][2]=5,l[2][3]=3,l[3][0]=1,l[3][1]=0,l[3][2]=3,l[3][3]=4,l[4][0]=4,l[4][1]=5,l[4][2]=2,l[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 b=new s,x=new a;r.prototype.calculateWorldAABB=function(e,t,i,r){var n=b,o=x;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=[],h=0;h<=i;h++)for(d=0;d<=n;d++){var l=d/n*o,c=h/i*Math.PI*2,u=(e+t*Math.cos(c))*Math.cos(l),p=(e+t*Math.cos(c))*Math.sin(l),f=t*Math.sin(c);s.push(u,p,f)}for(h=1;h<=i;h++)for(var d=1;d<=n;d++){var m=(n+1)*h+d-1,g=(n+1)*(h-1)+d-1,_=(n+1)*(h-1)+d,v=(n+1)*h+d;a.push(m,g,v),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,h,l,c=0,u=this.iterations,p=this.tolerance*this.tolerance,f=this.equations,d=f.length,m=t.bodies,g=m.length,_=e;if(0!==d)for(P=0;P!==g;P++)m[P].updateSolveMassProperties();var v=s,y=a,b=o;v.length=d,y.length=d,b.length=d;for(P=0;P!==d;P++){A=f[P];b[P]=0,y[P]=A.computeB(_),v[P]=1/A.computeC()}if(0!==d){for(P=0;P!==g;P++){var x=(M=m[P]).vlambda,T=M.wlambda;x.set(0,0,0),T&&T.set(0,0,0)}for(c=0;c!==u;c++){h=0;for(var E=0;E!==d;E++){var A=f[E];i=y[E],r=v[E],(l=b[E])+(n=r*(i-A.computeGWlambda()-A.eps*l))A.maxForce&&(n=A.maxForce-l),b[E]+=n,h+=n>0?n:-n,A.addToWlambda(n)}if(h*h=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 u,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=z;e[(o+1)%n].vsub(s,a);var h=G;a.cross(t,h);var l=W;i.vsub(s,l);var c=h.dot(l);if(!(null===r||c>0&&!0===r||c<=0&&!1===r))return!1;null===r&&(r=c>0)}return!0}t.exports=r;var o=e("../collision/AABB"),s=e("../shapes/Shape"),a=e("../collision/Ray"),h=e("../math/Vec3"),l=e("../math/Transform"),c=(e("../shapes/ConvexPolyhedron"),e("../math/Quaternion")),u=(e("../solver/Solver"),e("../utils/Vec3Pool")),p=e("../equations/ContactEquation"),f=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 p(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 h=i.material||e.material,l=r.material||t.material;return h&&l&&h.restitution>=0&&l.restitution>=0&&(s.restitution=h.restitution*l.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,h=a.friction,l=n.material||i.material,c=o.material||r.material;if(l&&c&&l.friction>=0&&c.friction>=0&&(h=l.friction*c.friction),h>0){var u=h*s.gravity.length(),p=i.invMass+r.invMass;p>0&&(p=1/p);var d=this.frictionEquationPool,m=d.length?d.pop():new f(i,r,u*p),g=d.length?d.pop():new f(i,r,u*p);return m.bi=g.bi=i,m.bj=g.bj=r,m.minForce=g.minForce=-u*p,m.maxForce=g.maxForce=u*p,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 h,m=new h,g=new h;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 _=new h,v=new h,y=new c,b=new c;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,h=b,l=_,c=v,u=0,p=e.length;u!==p;u++){var f=e[u],d=t[u],m=null;f.material&&d.material&&(m=i.getContactMaterial(f.material,d.material)||null);for(var g=0;gx.boundingSphereRadius+E.boundingSphereRadius)){var A=null;x.material&&E.material&&(A=i.getContactMaterial(x.material,E.material)||null),this.currentContactMaterial=A||m||i.defaultContactMaterial;var P=this[x.type|E.type];P&&(x.type0&&k<0){d.vsub(c,m),f.copy(p),f.normalize(),z=m.dot(f),f.scale(z,m),m.vadd(c,m);if((Y=m.distanceTo(d))0){var P=X,M=Y;P.copy(l[(b+1)%3]),M.copy(l[(b+2)%3]);var S=P.norm(),C=M.norm();P.normalize(),M.normalize();var R=H.dot(P),I=H.dot(M);if(R-S&&I-C){V=Math.abs(A-E-c);(null===y||V0){for(var C=[],R=0,I=x.length;R!==I;R++){var O=l.get();s.vmult(p[x[R]],O),r.vadd(O,O),C.push(O)}if(n(C,T,i)){v=!0;W=this.createContactEquation(a,h,e,t);T.mult(-f,W.ri),T.negate(W.ni);var w=l.get();T.mult(-M,w);var D=l.get();T.mult(-f,D),i.vsub(r,W.rj),W.rj.vadd(D,W.rj),W.rj.vadd(w,W.rj),W.rj.vadd(r,W.rj),W.rj.vsub(h.position,W.rj),W.ri.vadd(i,W.ri),W.ri.vsub(a.position,W.ri),l.release(w),l.release(D),this.result.push(W),this.createFrictionEquationsFromContact(W,this.frictionResult);for(var R=0,L=C.length;R!==L;R++)l.release(C[R]);return}for(R=0;R!==x.length;R++){var F=l.get(),N=l.get();s.vmult(p[x[(R+1)%x.length]],F),s.vmult(p[x[(R+2)%x.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=l.get(),k=l.get();i.vsub(F,k);var z=k.dot(V);V.mult(z,U),U.vadd(F,U);var G=l.get();if(U.vsub(i,G),z>0&&z*ze.boundingSphereRadius+t.boundingSphereRadius)&&e.findSeparatingAxis(t,i,n,r,o,p,c,u)){var f=[],d=de;e.clipAgainstHull(i,n,t,r,o,p,-100,100,f);for(var m=0,g=0;g!==f.length;g++){var _=this.createContactEquation(s,a,e,t,h,l),v=_.ri,y=_.rj;p.negate(_.ni),f[g].normal.negate(d),d.mult(f[g].depth,d),f[g].point.vadd(d,v),y.copy(f[g].point),v.vsub(i,v),y.vsub(r,y),v.vadd(i,v),v.vsub(s.position,v),y.vadd(r,y),y.vsub(a.position,y),this.result.push(_),m++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(_,this.frictionResult)}this.enableFrictionReduction&&m&&this.createFrictionFromAverage(m)}};var me=new h,ge=new h,_e=new h;r.prototype[s.types.PLANE|s.types.PARTICLE]=r.prototype.planeParticle=function(e,t,i,r,n,o,s,a){var h=me;h.set(0,0,1),s.quaternion.vmult(h,h);var l=ge;r.vsub(s.position,l);if(h.dot(l)<=0){var c=this.createContactEquation(a,s,t,e);c.ni.copy(h),c.ni.negate(c.ni),c.ri.set(0,0,0);var u=_e;h.mult(h.dot(r),u),r.vsub(u,u),c.rj.copy(u),this.result.push(c),this.createFrictionEquationsFromContact(c,this.frictionResult)}};var ve=new h;r.prototype[s.types.PARTICLE|s.types.SPHERE]=r.prototype.sphereParticle=function(e,t,i,r,n,o,s,a){var h=ve;h.set(0,0,1),r.vsub(i,h);if(h.norm2()<=e.radius*e.radius){var l=this.createContactEquation(a,s,t,e);h.normalize(),l.rj.copy(h),l.rj.mult(e.radius,l.rj),l.ni.copy(h),l.ni.negate(l.ni),l.ri.set(0,0,0),this.result.push(l),this.createFrictionEquationsFromContact(l,this.frictionResult)}};var ye=new c,be=new h,xe=(new h,new h),Te=new h,Ee=new h;r.prototype[s.types.PARTICLE|s.types.CONVEXPOLYHEDRON]=r.prototype.convexParticle=function(e,t,i,r,n,o,s,a){var h=-1,l=xe,c=Ee,u=null,p=be;if(p.copy(r),p.vsub(i,p),n.conjugate(ye),ye.vmult(p,p),e.pointIsInside(p)){e.worldVerticesNeedsUpdate&&e.computeWorldVertices(i,n),e.worldFaceNormalsNeedsUpdate&&e.computeWorldFaceNormals(n);for(var f=0,d=e.faces.length;f!==d;f++){var m=[e.worldVertices[e.faces[f][0]]],g=e.worldFaceNormals[f];r.vsub(m[0],Te);var _=-g.dot(Te);(null===u||Math.abs(_)h.length||_>h[0].length)){m<0&&(m=0),g<0&&(g=0),_<0&&(_=0),v<0&&(v=0),m>=h.length&&(m=h.length-1),g>=h.length&&(g=h.length-1),v>=h[0].length&&(v=h[0].length-1),_>=h[0].length&&(_=h[0].length-1);var y=[];t.getRectMinMax(m,_,g,v,y);var b=y[0],x=y[1];if(!(d.z-u>x||d.z+uh.length||_>h[0].length)){d<0&&(d=0),m<0&&(m=0),g<0&&(g=0),_<0&&(_=0),d>=h.length&&(d=h.length-1),m>=h.length&&(m=h.length-1),_>=h[0].length&&(_=h[0].length-1),g>=h[0].length&&(g=h[0].length-1);var v=[];t.getRectMinMax(d,g,m,_,v);var y=v[0],b=v[1];if(!(f.z-c>b||f.z+c2)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(){l.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 v,this.bodies=[],this.solver=new a,this.constraints=[],this.narrowphase=new h(this),this.collisionMatrix=new c,this.collisionMatrixPrevious=new c,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new d,this.defaultMaterial=new u("default"),this.defaultContactMaterial=new p(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"),h=(e("../utils/Vec3Pool"),e("../equations/ContactEquation"),e("../equations/FrictionEquation"),e("./Narrowphase")),l=e("../utils/EventTarget"),c=e("../collision/ArrayCollisionMatrix"),u=e("../material/Material"),p=e("../material/ContactMaterial"),f=e("../objects/Body"),d=e("../utils/TupleDictionary"),m=e("../collision/RaycastResult"),g=e("../collision/AABB"),_=e("../collision/Ray"),v=e("../collision/NaiveBroadphase");r.prototype=new l;new g;var y=new _;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 f&&(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=_.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=_.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=_.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 b=Date.now();performance.timing&&performance.timing.navigationStart&&(b=performance.timing.navigationStart),performance.now=function(){return Date.now()-b}}var x=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=x,h=this.bodies,l=0;l!==h.length;l++){var c=h[l];c.type!==f.STATIC&&c.sleepState!==f.SLEEPING?(c.position.vsub(c.previousPosition,a),a.scale(s,a),c.position.vadd(a,c.interpolatedPosition)):(c.interpolatedPosition.copy(c.position),c.interpolatedQuaternion.copy(c.quaternion))}}};var T={type:"postStep"},E={type:"preStep"},A={type:"collide",body:null,contact:null},P=[],M=[],S=[],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=S,o=C,s=this.numObjects(),a=this.bodies,h=this.solver,l=this.gravity,c=this.doProfiling,u=this.profile,p=f.DYNAMIC,d=this.constraints,m=M,g=(l.norm(),l.x),_=l.y,v=l.z,y=0;for(c&&(t=performance.now()),y=0;y!==s;y++){if((V=a[y]).type&p){var b=V.force,x=V.mass;b.x+=x*g,b.y+=x*_,b.z+=x*v}}for(var y=0,w=this.subsystems.length;y!==w;y++)this.subsystems[y].update();c&&(t=performance.now()),r.length=0,o.length=0,this.broadphase.collisionPairs(this,r,o),c&&(u.broadphase=performance.now()-t);k=d.length;for(y=0;y!==k;y++){if(!(z=d[y]).collideConnected)for(G=r.length-1;G>=0;G-=1)(z.bodyA===r[G]&&z.bodyB===o[G]||z.bodyB===r[G]&&z.bodyA===o[G])&&(r.splice(G,1),o.splice(G,1))}this.collisionMatrixTick(),c&&(t=performance.now());var D=P,L=i.length;for(y=0;y!==L;y++)D.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,D,this.frictionEquations,m),c&&(u.narrowphase=performance.now()-t),c&&(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&&(z.restitution=V.material.restitution*U.material.restitution)),h.addEquation(z),V.allowSleep&&V.type===f.DYNAMIC&&V.sleepState===f.SLEEPING&&U.sleepState===f.AWAKE&&U.type!==f.STATIC){U.velocity.norm2()+U.angularVelocity.norm2()>=2*Math.pow(U.sleepSpeedLimit,2)&&(V._wakeUpAfterNarrowphase=!0)}if(U.allowSleep&&U.type===f.DYNAMIC&&U.sleepState===f.SLEEPING&&V.sleepState===f.AWAKE&&V.type!==f.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=z,V.dispatchEvent(A),A.body=V,U.dispatchEvent(A))}for(c&&(u.makeContactConstraints=performance.now()-t,t=performance.now()),y=0;y!==s;y++){(V=a[y])._wakeUpAfterNarrowphase&&(V.wakeUp(),V._wakeUpAfterNarrowphase=!1)}var k=d.length;for(y=0;y!==k;y++){var z=d[y];z.update();for(var G=0,W=z.equations.length;G!==W;G++){var H=z.equations[G];h.addEquation(H)}}h.solve(e,this),c&&(u.solve=performance.now()-t),h.removeAllEquations();var j=Math.pow;for(y=0;y!==s;y++){if((V=a[y]).type&p){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)}c&&(t=performance.now());var Z=R,q=I,J=this.stepnumber,$=f.DYNAMIC|f.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!==f.SLEEPING){var se=re.velocity,ae=re.angularVelocity,he=re.position,le=re.quaternion,ce=re.invMass,ue=re.invInertiaWorld;se.x+=ne.x*ce*e,se.y+=ne.y*ce*e,se.z+=ne.z*ce*e,re.angularVelocity&&(ue.vmult(oe,O),O.mult(e,O),O.vadd(ae,ae)),he.x+=se.x*e,he.y+=se.y*e,he.z+=se.z*e,re.angularVelocity&&(Z.set(ae.x,ae.y,ae.z,0),Z.mult(le,q),le.x+=ie*q.x,le.y+=ie*q.y,le.z+=ie*q.z,le.w+=ie*q.w,ee&&(te?le.normalizeFast():le.normalize())),re.aabb&&(re.aabbNeedsUpdate=!0),re.updateInertiaWorld&&re.updateInertiaWorld()}}for(this.clearForces(),this.broadphase.dirty=!0,c&&(u.integrate=performance.now()-t),this.time+=e,this.stepnumber+=1,this.dispatchEvent(T),y=0;y!==s;y++){var pe=(V=a[y]).postStep;pe&&pe.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,h=this.broadPhase.numPairs;h--;){var l,c,u=s[h];u.shape1.id.5?y.sleep():y.updatePosition(this.timeStep)):(y.sleepTime=0,y.updatePosition(this.timeStep)),this.numIslands++;else{var b=0,x=0,T=1;this.islandStack[0]=y,y.addedToIsland=!0;do{if(o=this.islandStack[--T],this.islandStack[T]=null,o.sleeping=!1,this.islandRigidBodies[b++]=o,!o.isStatic){for(var E=o.contactLink;null!==E;E=E.next){var A=E.contact;if(!(_=A.constraint).addedToIsland&&A.touching){this.islandConstraints[x++]=_,_.addedToIsland=!0;var P;(P=E.body).addedToIsland||(this.islandStack[T++]=P,P.addedToIsland=!0)}}for(var M=o.jointLink;null!==M;M=M.next)(_=M.joint).addedToIsland||(this.islandConstraints[x++]=_,_.addedToIsland=!0,!(P=M.body).addedToIsland&&P.isDynamic&&(this.islandStack[T++]=P,P.addedToIsland=!0))}}while(0!=T);for(var S=(new a.Vec3).addTime(this.gravity,this.timeStep),C=b;C--;)(o=this.islandRigidBodies[C]).isDynamic&&o.linearVelocity.addEqual(S);if(this.enableRandomizer)for(C=x;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=x;C--;)this.islandConstraints[C].preSolve(this.timeStep,v);for(var I=this.numIterations;I--;)for(C=x;C--;)this.islandConstraints[C].solve();for(C=x;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 h=this.massInfo.mass,l=s.relativePosition.x,c=s.relativePosition.y,u=s.relativePosition.z;o.addScale(s.relativePosition,h),this.mass+=h,this.rotateInertia(s.relativeRotation,this.massInfo.inertia,n),this.localInertia.addEqual(n),r[0]+=h*(c*c+u*u),r[4]+=h*(l*l+u*u),r[8]+=h*(l*l+c*c);var p=h*l*c,f=h*c*u,d=h*u*l;r[1]-=p,r[3]-=p,r[2]-=f,r[6]-=f,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);l=o.x,c=o.y,u=o.z,r[0]-=this.mass*(c*c+u*u),r[4]-=this.mass*(l*l+u*u),r[8]-=this.mass*(l*l+c*c),p=this.mass*l*c,f=this.mass*c*u,d=this.mass*u*l,r[1]+=p,r[3]+=p,r[2]+=f,r[6]+=f,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],h=r[1],l=r[4],c=r[7],u=r[2],p=r[5],f=r[8],d=n[0],m=n[3],g=n[6],_=n[1],v=n[4],y=n[7],b=n[2],x=n[5],T=n[8],E=o*d+h*m+u*g,A=o*_+h*v+u*y,P=o*b+h*x+u*T,M=s*d+l*m+p*g,S=s*_+l*v+p*y,C=s*b+l*x+p*T,R=a*d+c*m+f*g,I=a*_+c*v+f*y,O=a*b+c*x+f*T,w=i.elements;w[0]=E*o+A*h+P*u,w[1]=E*s+A*l+P*p,w[2]=E*a+A*c+P*f,w[3]=M*o+S*h+C*u,w[4]=M*s+S*l+C*p,w[5]=M*a+S*c+C*f,w[6]=R*o+I*h+O*u,w[7]=R*s+I*l+O*p,w[8]=R*a+I*c+O*f},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,h=i*o,l=r*s,c=t*o,u=i*s,p=t*s,f=e*n,d=e*o,m=e*s,g=this.rotation.elements;g[0]=1-h-l,g[1]=c-m,g[2]=p+d,g[3]=c+m,g[4]=1-a-l,g[5]=u-f,g[6]=p-d,g[7]=u+f,g[8]=1-a-h,this.rotateInertia(this.rotation,this.inverseLocalInertia,this.inverseInertia);for(var _=this.shapes;null!=_;_=_.next)_.position.mul(this.position,_.relativePosition,this.rotation),_.rotation.mul(this.rotation,_.relativeRotation),_.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,h,l,c,u,p,f,d,m,g){this.elements=new s(16);var _=this.elements;_[0]=void 0!==e?e:1,_[4]=t||0,_[8]=i||0,_[12]=r||0,_[1]=n||0,_[5]=void 0!==o?o:1,_[9]=a||0,_[13]=h||0,_[2]=l||0,_[6]=c||0,_[10]=void 0!==u?u:1,_[14]=p||0,_[3]=f||0,_[7]=d||0,_[11]=m||0,_[15]=void 0!==g?g:1},a.Mat44.prototype={constructor:a.Mat44,set:function(e,t,i,r,n,o,s,a,h,l,c,u,p,f,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]=h,g[6]=l,g[10]=c,g[14]=u,g[3]=p,g[7]=f,g[11]=d,g[15]=m,this}},a.Mat33=function(e,t,i,r,n,o,a,h,l){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,h||0,void 0!==l?l:1)},a.Mat33.prototype={constructor:a.Mat33,set:function(e,t,i,r,n,o,s,a,h){var l=this.elements;return l[0]=e,l[1]=t,l[2]=i,l[3]=r,l[4]=n,l[5]=o,l[6]=s,l[7]=a,l[8]=h,this},init:function(e,t,i,r,n,o,s,a,h){var l=this.elements;return l[0]=e,l[1]=t,l[2]=i,l[3]=r,l[4]=n,l[5]=o,l[6]=s,l[7]=a,l[8]=h,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],h=r[1],l=r[4],c=r[7],u=r[2],p=r[5],f=r[8],d=n[0],m=n[3],g=n[6],_=n[1],v=n[4],y=n[7],b=n[2],x=n[5],T=n[8];return i[0]=o*d+h*m+u*g,i[1]=o*_+h*v+u*y,i[2]=o*b+h*x+u*T,i[3]=s*d+l*m+p*g,i[4]=s*_+l*v+p*y,i[5]=s*b+l*x+p*T,i[6]=a*d+c*m+f*g,i[7]=a*_+c*v+f*y,i[8]=a*b+c*x+f*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,h=a.sin(t),l=a.cos(t),c=1-l,u=i*i*c+l,p=i*r*c-n*h,f=i*n*c+r*h,d=r*i*c+n*h,m=r*r*c+l,g=r*n*c-i*h,_=n*i*c-r*h,v=n*r*c+i*h,y=n*n*c+l,b=e.elements,x=b[0],T=b[3],E=b[6],A=b[1],P=b[4],M=b[7],S=b[2],C=b[5],R=b[8],I=this.elements;return s?(I[0]=u*x+p*T+f*E,I[1]=u*A+p*P+f*M,I[2]=u*S+p*C+f*R,I[3]=d*x+m*T+g*E,I[4]=d*A+m*P+g*M,I[5]=d*S+m*C+g*R,I[6]=_*x+v*T+y*E,I[7]=_*A+v*P+y*M,I[8]=_*S+v*C+y*R):(I[0]=x*u+A*d+S*_,I[1]=x*p+A*m+S*v,I[2]=x*f+A*g+S*y,I[3]=T*u+P*d+C*_,I[4]=T*p+P*m+C*v,I[5]=T*f+P*g+C*y,I[6]=E*u+M*d+R*_,I[7]=E*p+M*m+R*v,I[8]=E*f+M*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,h=e.x*r,l=e.y*n,c=e.x*n,u=e.s*i,p=e.s*r,f=e.s*n;return t[0]=1-s-a,t[1]=h-f,t[2]=c+p,t[3]=h+f,t[4]=1-o-a,t[5]=l-u,t[6]=c-p,t[7]=l+u,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],h=i[7],l=i[2],c=i[5],u=i[8],p=a*u-h*c,f=h*l-s*u,d=s*c-a*l,m=r*p+n*f+o*d;return 0!=m&&(m=1/m),t[0]=m*p,t[1]=m*f,t[2]=m*d,t[3]=m*(c*o-n*u),t[4]=m*(r*u-l*o),t[5]=m*(l*n-r*c),t[6]=m*(n*h-a*o),t[7]=m*(s*o-r*h),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]),h=e[8],l=new a.Vec3;new a.Quat;return l.y=a.asin(function(e){return a.min(a.max(e,-1),1)}(r)),a.abs(r)<.99999?(l.x=a.atan2(-o,h),l.z=a.atan2(-i,t)):(l.x=a.atan2(s,n),l.z=0),l},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,h=this.y,l=this.z,c=(i*o+r*l-n*h)*(t*=.5),u=(-i*l+r*o+n*s)*t,p=(i*h-r*s+n*o)*t;o+=(-i*s-r*h-n*l)*t,s+=c,h+=u,l+=p;var f=1/a.sqrt(o*o+s*s+h*h+l*l);return this.s=o*f,this.x=s*f,this.y=h*f,this.z=l*f,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,h=t.z,l=t.s;return this.x=i*l+o*s+r*h-n*a,this.y=r*l+o*a+n*s-i*h,this.z=n*l+o*h+i*a-r*s,this.s=o*l-i*s-r*a-n*h,this},arc:function(e,t){var i=e.x,r=e.y,n=e.z,o=t.x,s=t.y,h=t.z,l=i*o+r*s+n*h;if(-1==l)return o=r*i-n*n,s=-n*r-i*i,h=i*n+r*r,l=1/a.sqrt(o*o+s*s+h*h),this.s=0,this.x=o*l,this.y=s*l,this.z=h*l,this;var c=r*h-n*s,u=n*o-i*h,p=i*s-r*o;return this.s=a.sqrt(.5*(1+l)),l=.5/this.s,this.x=c*l,this.y=u*l,this.z=p*l,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],h=i[4],l=i[5],c=i[6],u=i[7],p=i[8],f=r+h+p;return f>0?(t=.5/a.sqrt(f+1),this.w=.25/t,this.x=(u-l)*t,this.y=(o-c)*t,this.z=(s-n)*t):r>h&&r>p?(t=2*a.sqrt(1+r-h-p),this.w=(u-l)/t,this.x=.25*t,this.y=(n+s)/t,this.z=(o+c)/t):h>p?(t=2*a.sqrt(1+h-r-p),this.w=(o-c)/t,this.x=(n+s)/t,this.y=.25*t,this.z=(l+u)/t):(t=2*a.sqrt(1+p-r-h),this.w=(s-n)/t,this.x=(o+c)/t,this.y=(l+u)/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,h=a*t+o*r-s*i,l=a*i+s*t-n*r,c=a*r+n*i-o*t,u=-n*t-o*i-s*r;return this.x=h*a+u*-n+l*-s-c*-o,this.y=l*a+u*-o+c*-n-h*-s,this.z=c*a+u*-s+h*-o-l*-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],h=r[3],l=r[4],c=r[5],u=r[6],p=r[7],f=r[8];return"XYZ"===(t=t||this._order)?(this._y=a.asin(i(s,-1,1)),a.abs(s)<.99999?(this._x=a.atan2(-c,f),this._z=a.atan2(-o,n)):(this._x=a.atan2(p,l),this._z=0)):"YXZ"===t?(this._x=a.asin(-i(c,-1,1)),a.abs(c)<.99999?(this._y=a.atan2(s,f),this._z=a.atan2(h,l)):(this._y=a.atan2(-u,n),this._z=0)):"ZXY"===t?(this._x=a.asin(i(p,-1,1)),a.abs(p)<.99999?(this._y=a.atan2(-u,f),this._z=a.atan2(-o,l)):(this._y=0,this._z=a.atan2(h,n))):"ZYX"===t?(this._y=a.asin(-i(u,-1,1)),a.abs(u)<.99999?(this._x=a.atan2(p,f),this._z=a.atan2(h,n)):(this._x=0,this._z=a.atan2(-o,l))):"YZX"===t?(this._z=a.asin(i(h,-1,1)),a.abs(h)<.99999?(this._x=a.atan2(-c,l),this._y=a.atan2(-u,n)):(this._x=0,this._y=a.atan2(s,f))):"XZY"===t?(this._z=a.asin(-i(o,-1,1)),a.abs(o)<.99999?(this._x=a.atan2(p,l),this._y=a.atan2(s,n)):(this._x=a.atan2(-c,f),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,h=e.s*e.s;return"XYZ"===(t=t||this._order)?(this._x=a.atan2(2*(e.x*e.s-e.y*e.z),h-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),h+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),h-n-o+s),this._z=a.atan2(2*(e.x*e.y+e.z*e.s),h-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),h-n-o+s),this._z=a.atan2(2*(e.z*e.s-e.x*e.y),h-n+o-s)):"ZYX"===t?(this._x=a.atan2(2*(e.x*e.s+e.z*e.y),h-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),h+n-o-s)):"YZX"===t?(this._x=a.atan2(2*(e.x*e.s-e.z*e.y),h-n+o-s),this._y=a.atan2(2*(e.y*e.s-e.x*e.z),h+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),h-n+o-s),this._y=a.atan2(2*(e.x*e.z+e.y*e.s),h+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),h=a.cos(.5*e),l=a.sin(.5*e),c=r*o,u=n*s,p=c*h-u*l,f=c*l+u*h,d=n*o*h+r*s*l,m=r*s*h-n*o*l,g=2*a.acos(p),_=f*f+d*d+m*m;return _<.001?(f=1,d=m=0):(f/=_=a.sqrt(_),d/=_,m/=_),[g,f,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),h=a.cos(e),l=a.sin(e),c=new a.Mat33,u=c.elements;return u[0]=r*o,u[1]=n*l-r*s*h,u[2]=r*s*l+n*h,u[3]=s,u[4]=o*h,u[5]=-o*l,u[6]=-n*o,u[7]=n*s*h+r*l,u[8]=-n*s*l+r*h,c},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 h=this.localAxis2X*i[0]+this.localAxis2Y*i[1]+this.localAxis2Z*i[2],l=this.localAxis2X*i[3]+this.localAxis2Y*i[4]+this.localAxis2Z*i[5],c=this.localAxis2X*i[6]+this.localAxis2Y*i[7]+this.localAxis2Z*i[8],u=n*this.body2.inverseMass+h*this.body1.inverseMass,p=o*this.body2.inverseMass+l*this.body1.inverseMass,f=s*this.body2.inverseMass+c*this.body1.inverseMass;(r=a.sqrt(u*u+p*p+f*f))>0&&(r=1/r);var d=(p*=r)*(u*=r)-(f*=r)*f,m=-f*p-u*u,g=u*f+p*p,_=p*(g*=r=1/a.sqrt(d*d+m*m+g*g))-f*(m*=r),v=f*(d*=r)-u*g,y=u*m-p*d;this.nor.init(u,p,f),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],h=this.localAxis1X*i[3]+this.localAxis1Y*i[4]+this.localAxis1Z*i[5],l=this.localAxis1X*i[6]+this.localAxis1Y*i[7]+this.localAxis1Z*i[8],c=this.localAngAxis1X*i[0]+this.localAngAxis1Y*i[1]+this.localAngAxis1Z*i[2],u=this.localAngAxis1X*i[3]+this.localAngAxis1Y*i[4]+this.localAngAxis1Z*i[5],p=this.localAngAxis1X*i[6]+this.localAngAxis1Y*i[7]+this.localAngAxis1Z*i[8];i=this.body2.rotation.elements;var f=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],_=this.localAngAxis2X*i[3]+this.localAngAxis2Y*i[4]+this.localAngAxis2Z*i[5],v=this.localAngAxis2X*i[6]+this.localAngAxis2Y*i[7]+this.localAngAxis2Z*i[8],y=s*this.body2.inverseMass+f*this.body1.inverseMass,b=h*this.body2.inverseMass+d*this.body1.inverseMass,x=l*this.body2.inverseMass+m*this.body1.inverseMass;(r=a.sqrt(y*y+b*b+x*x))>0&&(r=1/r);var T=(b*=r)*(y*=r)-(x*=r)*x,E=-x*b-y*y,A=y*x+b*b,P=b*(A*=r=1/a.sqrt(T*T+E*E+A*A))-x*(E*=r),M=x*(T*=r)-y*A,S=y*E-b*T;this.nor.init(y,b,x),this.tan.init(T,E,A),this.bin.init(P,M,S),this.rotationalLimitMotor.angle=y*(u*v-p*_)+b*(p*g-c*v)+x*(c*_-u*g)<0?-this.acosClamp(c*g+u*_+p*v):this.acosClamp(c*g+u*_+p*v),r=h*m-l*d,n=l*f-s*m,o=s*d-h*f,this.r3.limitMotor2.angle=T*r+E*n+A*o,this.r3.limitMotor3.angle=P*r+M*n+S*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],h=this.localAngAxis1X*i[0]+this.localAngAxis1Y*i[1]+this.localAngAxis1Z*i[2],l=this.localAngAxis1X*i[3]+this.localAngAxis1Y*i[4]+this.localAngAxis1Z*i[5],c=this.localAngAxis1X*i[6]+this.localAngAxis1Y*i[7]+this.localAngAxis1Z*i[8];i=this.body2.rotation.elements;var u=this.localAxis2X*i[0]+this.localAxis2Y*i[1]+this.localAxis2Z*i[2],p=this.localAxis2X*i[3]+this.localAxis2Y*i[4]+this.localAxis2Z*i[5],f=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*u+o*p+s*f,this.rotationalLimitMotor1.angle=n*(l*f-c*p)+o*(c*u-h*f)+s*(h*p-l*u)<0?-this.acosClamp(h*u+l*p+c*f):this.acosClamp(h*u+l*p+c*f),this.rotationalLimitMotor2.angle=u*(m*s-g*o)+p*(g*n-d*s)+f*(d*o-m*n)<0?this.acosClamp(d*n+m*o+g*s):-this.acosClamp(d*n+m*o+g*s);var _=p*s-f*o,v=f*n-u*s,y=u*o-p*n;(r=a.sqrt(_*_+v*v+y*y))>0&&(r=1/r);var b=(v*=r)*f-(y*=r)*p,x=y*u-(_*=r)*f,T=_*p-v*u;(r=a.sqrt(b*b+x*x+T*T))>0&&(r=1/r),b*=r,x*=r,T*=r;var E=o*y-s*v,A=s*_-n*y,P=n*v-o*_;(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(b,x,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 h=a.sqrt(this.velx*this.velx+this.vely*this.vely+this.velz*this.velz);h>.005?(h=(.005-h)/h*t*.05,this.velx*=h,this.vely*=h,this.velz*=h):(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,h=o>0,l=s>0,c=this.lowerLimit1<=this.upperLimit1,u=this.lowerLimit2<=this.upperLimit2,p=this.lowerLimit3<=this.upperLimit3,f=this.limitMotor1.angle;c?(this.lowerLimit1==this.upperLimit1?(0!=this.limitState1&&(this.limitState1=0,this.limitImpulse1=0),this.limitVelocity1=this.lowerLimit1-f):fthis.upperLimit1?(1!=this.limitState1&&(this.limitState1=1,this.limitImpulse1=0),this.limitVelocity1=this.upperLimit1-f):(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;u?(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),h||(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(p?(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),l||(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||h)?this.maxMotorImpulse2=this.maxMotorForce2*e:(this.motorImpulse2=0,this.maxMotorImpulse2=0),this.enableMotor3&&(0!=this.limitState3||l)?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,_=g*g*e,v=t/(_+2*this.limitMotor1.dampingRatio*g);this.cfm1=this.kv00*v,this.limitVelocity1*=_*v}else this.cfm1=0,this.limitVelocity1*=.05*t;h&&2!=this.limitState2?(v=t/((_=(g=6.2831853*o)*g*e)+2*this.limitMotor2.dampingRatio*g),this.cfm2=this.kv11*v,this.limitVelocity2*=_*v):(this.cfm2=0,this.limitVelocity2*=.05*t),l&&2!=this.limitState3?(v=t/((_=(g=6.2831853*s)*g*e)+2*this.limitMotor3.dampingRatio*g),this.cfm3=this.kv22*v,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 b=this.limitImpulse1+this.motorImpulse1,x=this.limitImpulse2+this.motorImpulse2,T=this.limitImpulse3+this.motorImpulse3;this.a1.x+=b*this.a1x1+x*this.a1x2+T*this.a1x3,this.a1.y+=b*this.a1y1+x*this.a1y2+T*this.a1y3,this.a1.z+=b*this.a1z1+x*this.a1z2+T*this.a1z3,this.a2.x-=b*this.a2x1+x*this.a2x2+T*this.a2x3,this.a2.y-=b*this.a2y1+x*this.a2y2+T*this.a2y3,this.a2.z-=b*this.a2z1+x*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,h=r*this.d20+n*this.d21+o*this.d22;this.limitImpulse1+=s,this.limitImpulse2+=a,this.limitImpulse3+=h,this.a1.x+=s*this.a1x1+a*this.a1x2+h*this.a1x3,this.a1.y+=s*this.a1y1+a*this.a1y2+h*this.a1y3,this.a1.z+=s*this.a1z1+a*this.a1z2+h*this.a1z3,this.a2.x-=s*this.a2x1+a*this.a2x2+h*this.a2x3,this.a2.y-=s*this.a2y1+a*this.a2y2+h*this.a2y3,this.a2.z-=s*this.a2z1+a*this.a2z2+h*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,h=this.motorImpulse3,l=0,c=0,u=0;this.enableMotor1&&(l=(r-this.motorSpeed1)*this.dv00,this.motorImpulse1+=l,this.motorImpulse1>this.maxMotorImpulse1?this.motorImpulse1=this.maxMotorImpulse1:this.motorImpulse1<-this.maxMotorImpulse1&&(this.motorImpulse1=-this.maxMotorImpulse1),l=this.motorImpulse1-s),this.enableMotor2&&(c=(n-this.motorSpeed2)*this.dv11,this.motorImpulse2+=c,this.motorImpulse2>this.maxMotorImpulse2?this.motorImpulse2=this.maxMotorImpulse2:this.motorImpulse2<-this.maxMotorImpulse2&&(this.motorImpulse2=-this.maxMotorImpulse2),c=this.motorImpulse2-a),this.enableMotor3&&(u=(o-this.motorSpeed3)*this.dv22,this.motorImpulse3+=u,this.motorImpulse3>this.maxMotorImpulse3?this.motorImpulse3=this.maxMotorImpulse3:this.motorImpulse3<-this.maxMotorImpulse3&&(this.motorImpulse3=-this.maxMotorImpulse3),u=this.motorImpulse3-h),r+=l*this.kv00+c*this.k01+u*this.k02,n+=l*this.k10+c*this.kv11+u*this.k12,o+=l*this.k20+c*this.k21+u*this.kv22,r-=this.limitVelocity1+this.limitImpulse1*this.cfm1,n-=this.limitVelocity2+this.limitImpulse2*this.cfm2,o-=this.limitVelocity3+this.limitImpulse3*this.cfm3;var p=this.limitImpulse1,f=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,_=r*this.d20+n*this.d21+o*this.d22;this.limitImpulse1+=m,this.limitImpulse2+=g,this.limitImpulse3+=_;var v=0;(2==this.limitState1||this.limitImpulse1*this.limitState1<0)&&(n+=(m=-p)*this.k10,o+=m*this.k20,v|=1),(2==this.limitState2||this.limitImpulse2*this.limitState2<0)&&(r+=(g=-f)*this.k01,o+=g*this.k21,v|=2),(2==this.limitState3||this.limitImpulse3*this.limitState3<0)&&(r+=(_=-d)*this.k02,n+=_*this.k12,v|=4);var y;switch(v){case 1:y=1/(this.k11*this.k22-this.k12*this.k21),g=(this.k22*n+-this.k12*o)*y,_=(-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,_=(-this.k20*r+this.k00*o)*y;break;case 3:_=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+p,this.limitImpulse2=g+f,this.limitImpulse3=_+d;var b=l+m,x=c+g,T=u+_;this.a1.x+=b*this.a1x1+x*this.a1x2+T*this.a1x3,this.a1.y+=b*this.a1y1+x*this.a1y2+T*this.a1y3,this.a1.z+=b*this.a1z1+x*this.a1z2+T*this.a1z3,this.a2.x-=b*this.a2x1+x*this.a2x2+T*this.a2x3,this.a2.y-=b*this.a2y1+x*this.a2y2+T*this.a2y3,this.a2.z-=b*this.a2z1+x*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 h=6.2831853*n,l=h*h*e,c=t/(l+2*this.limitMotor.dampingRatio*h);this.cfm=this.motorDenom*c,this.limitVelocity*=l*c}else this.cfm=0,this.limitVelocity*=.05*t;this.invDenom=1/(this.motorDenom+this.cfm),this.limitImpulse*=.95,this.motorImpulse*=.95;var u=this.limitImpulse+this.motorImpulse;this.a1.x+=u*this.a1x,this.a1.y+=u*this.a1y,this.a1.z+=u*this.a1z,this.a2.x-=u*this.a2x,this.a2.y-=u*this.a2y,this.a2.z-=u*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,h=n*this.ax2+o*this.ay2+s*this.az2,l=n*this.ax3+o*this.ay3+s*this.az3,c=this.limitMotor1.frequency,u=this.limitMotor2.frequency,p=this.limitMotor3.frequency,f=c>0,d=u>0,m=p>0,g=this.lowerLimit1<=this.upperLimit1,_=this.lowerLimit2<=this.upperLimit2,v=this.lowerLimit3<=this.upperLimit3;(f&&a>20||a<-20)&&(f=!1),(d&&h>20||h<-20)&&(d=!1),(m&&l>20||l<-20)&&(m=!1),g?(this.lowerLimit1==this.upperLimit1?(0!=this.limitState1&&(this.limitState1=0,this.limitImpulse1=0),this.limitVelocity1=this.lowerLimit1-a,f||(a=this.lowerLimit1)):athis.upperLimit1?(1!=this.limitState1&&(this.limitState1=1,this.limitImpulse1=0),this.limitVelocity1=this.upperLimit1-a,f||(a=this.upperLimit1)):(this.limitState1=2,this.limitImpulse1=0,this.limitVelocity1=0),f||(this.limitVelocity1>.005?this.limitVelocity1-=.005:this.limitVelocity1<-.005?this.limitVelocity1+=.005:this.limitVelocity1=0)):(this.limitState1=2,this.limitImpulse1=0),_?(this.lowerLimit2==this.upperLimit2?(0!=this.limitState2&&(this.limitState2=0,this.limitImpulse2=0),this.limitVelocity2=this.lowerLimit2-h,d||(h=this.lowerLimit2)):hthis.upperLimit2?(1!=this.limitState2&&(this.limitState2=1,this.limitImpulse2=0),this.limitVelocity2=this.upperLimit2-h,d||(h=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),v?(this.lowerLimit3==this.upperLimit3?(0!=this.limitState3&&(this.limitState3=0,this.limitImpulse3=0),this.limitVelocity3=this.lowerLimit3-l,m||(l=this.lowerLimit3)):lthis.upperLimit3?(1!=this.limitState3&&(this.limitState3=1,this.limitImpulse3=0),this.limitVelocity3=this.upperLimit3-l,m||(l=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||f)?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+h*this.ax2+l*this.ax2,b=a*this.ay1+h*this.ay2+l*this.ay2,x=a*this.az1+h*this.az2+l*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+b*T,this.r1z=this.r1.z+x*T,this.r2x=this.r2.x-y*E,this.r2y=this.r2.y-b*E,this.r2z=this.r2.z-x*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,f&&2!=this.limitState1){var P=6.2831853*c,M=P*P*e,S=t/(M+2*this.limitMotor1.dampingRatio*P);this.cfm1=this.kv00*S,this.limitVelocity1*=M*S}else this.cfm1=0,this.limitVelocity1*=.05*t;d&&2!=this.limitState2?(S=t/((M=(P=6.2831853*u)*P*e)+2*this.limitMotor2.dampingRatio*P),this.cfm2=this.kv11*S,this.limitVelocity2*=M*S):(this.cfm2=0,this.limitVelocity2*=.05*t),m&&2!=this.limitState3?(S=t/((M=(P=6.2831853*p)*P*e)+2*this.limitMotor3.dampingRatio*P),this.cfm3=this.kv22*S,this.limitVelocity3*=M*S):(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,h=this.motorImpulse3,l=0,c=0,u=0;this.enableMotor1&&(l=(r-this.motorSpeed1)*this.dv00,this.motorImpulse1+=l,this.motorImpulse1>this.maxMotorImpulse1?this.motorImpulse1=this.maxMotorImpulse1:this.motorImpulse1<-this.maxMotorImpulse1&&(this.motorImpulse1=-this.maxMotorImpulse1),l=this.motorImpulse1-s),this.enableMotor2&&(c=(n-this.motorSpeed2)*this.dv11,this.motorImpulse2+=c,this.motorImpulse2>this.maxMotorImpulse2?this.motorImpulse2=this.maxMotorImpulse2:this.motorImpulse2<-this.maxMotorImpulse2&&(this.motorImpulse2=-this.maxMotorImpulse2),c=this.motorImpulse2-a),this.enableMotor3&&(u=(o-this.motorSpeed3)*this.dv22,this.motorImpulse3+=u,this.motorImpulse3>this.maxMotorImpulse3?this.motorImpulse3=this.maxMotorImpulse3:this.motorImpulse3<-this.maxMotorImpulse3&&(this.motorImpulse3=-this.maxMotorImpulse3),u=this.motorImpulse3-h),r+=l*this.kv00+c*this.k01+u*this.k02,n+=l*this.k10+c*this.kv11+u*this.k12,o+=l*this.k20+c*this.k21+u*this.kv22,r-=this.limitVelocity1+this.limitImpulse1*this.cfm1,n-=this.limitVelocity2+this.limitImpulse2*this.cfm2,o-=this.limitVelocity3+this.limitImpulse3*this.cfm3;var p=this.limitImpulse1,f=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,_=r*this.d20+n*this.d21+o*this.d22;this.limitImpulse1+=m,this.limitImpulse2+=g,this.limitImpulse3+=_;var v=0;(2==this.limitState1||this.limitImpulse1*this.limitState1<0)&&(n+=(m=-p)*this.k10,o+=m*this.k20,v|=1),(2==this.limitState2||this.limitImpulse2*this.limitState2<0)&&(r+=(g=-f)*this.k01,o+=g*this.k21,v|=2),(2==this.limitState3||this.limitImpulse3*this.limitState3<0)&&(r+=(_=-d)*this.k02,n+=_*this.k12,v|=4);var y;switch(v){case 1:y=1/(this.k11*this.k22-this.k12*this.k21),g=(this.k22*n+-this.k12*o)*y,_=(-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,_=(-this.k20*r+this.k00*o)*y;break;case 3:_=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=p+m,this.limitImpulse2=f+g,this.limitImpulse3=d+_;var b=l+m,x=c+g,T=u+_;this.l1.x+=b*this.l1x1+x*this.l1x2+T*this.l1x3,this.l1.y+=b*this.l1y1+x*this.l1y2+T*this.l1y3,this.l1.z+=b*this.l1z1+x*this.l1z2+T*this.l1z3,this.a1.x+=b*this.a1x1+x*this.a1x2+T*this.a1x3,this.a1.y+=b*this.a1y1+x*this.a1y2+T*this.a1y3,this.a1.z+=b*this.a1z1+x*this.a1z2+T*this.a1z3,this.l2.x-=b*this.l2x1+x*this.l2x2+T*this.l2x3,this.l2.y-=b*this.l2y1+x*this.l2y2+T*this.l2y3,this.l2.z-=b*this.l2z1+x*this.l2z2+T*this.l2z3,this.a2.x-=b*this.a2x1+x*this.a2x2+T*this.a2x3,this.a2.y-=b*this.a2y1+x*this.a2y2+T*this.a2y3,this.a2.z-=b*this.a2z1+x*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,h=this.limitMotor.frequency,l=h>0,c=this.lowerLimit<=this.upperLimit;(l&&a>20||a<-20)&&(l=!1),c?(this.lowerLimit==this.upperLimit?(0!=this.limitState&&(this.limitState=0,this.limitImpulse=0),this.limitVelocity=this.lowerLimit-a,l||(a=this.lowerLimit)):athis.upperLimit?(1!=this.limitState&&(this.limitState=1,this.limitImpulse=0),this.limitVelocity=this.upperLimit-a,l||(a=this.upperLimit)):(this.limitState=2,this.limitImpulse=0,this.limitVelocity=0),l||(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||l)?this.maxMotorImpulse=this.maxMotorForce*e:(this.motorImpulse=0,this.maxMotorImpulse=0);var u=a*this.ax,p=a*this.ay,f=a*this.az,d=this.m1/(this.m1+this.m2),m=1-d;if(this.r1x=this.r1.x+u*d,this.r1y=this.r1.y+p*d,this.r1z=this.r1.z+f*d,this.r2x=this.r2.x-u*m,this.r2y=this.r2.y-p*m,this.r2z=this.r2.z-f*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,l&&2!=this.limitState){var g=6.2831853*h,_=g*g*e,v=t/(_+2*this.limitMotor.dampingRatio*g);this.cfm=this.motorDenom*v,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,h=r.localPoint2.x,l=r.localPoint2.y,c=r.localPoint2.z,u=-1,p=4e-4,f=e;f--;){var d=(i=this.buffer[f]).lp1X-o,m=i.lp1Y-s,g=i.lp1Z-a,_=d*d+m*m+g*g,v=(d=i.lp2X-h)*d+(m=i.lp2Y-l)*m+(g=i.lp2Z-c)*g;_.04?B=1/a.sqrt(B):(L=C*S-R*R,F=-R*C-S*S,N=S*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)-S*N,k=S*F-C*L;p.norX=S,p.norY=C,p.norZ=R,p.tanX=L,p.tanY=F,p.tanZ=N,p.binX=V,p.binY=U,p.binZ=k,p.norU1X=S*this.m1,p.norU1Y=C*this.m1,p.norU1Z=R*this.m1,p.norU2X=S*this.m2,p.norU2Y=C*this.m2,p.norU2Z=R*this.m2,p.tanU1X=L*this.m1,p.tanU1Y=F*this.m1,p.tanU1Z=N*this.m1,p.tanU2X=L*this.m2,p.tanU2Y=F*this.m2,p.tanU2Z=N*this.m2,p.binU1X=V*this.m1,p.binU1Y=U*this.m1,p.binU1Z=k*this.m1,p.binU2X=V*this.m2,p.binU2Y=U*this.m2,p.binU2Z=k*this.m2;var z=T*R-E*C,G=E*S-x*R,W=x*C-T*S,H=P*R-M*C,j=M*S-A*R,X=A*C-P*S,Y=T*N-E*F,K=E*L-x*N,Q=x*F-T*L,Z=P*N-M*F,q=M*L-A*N,J=A*F-P*L,$=T*k-E*U,ee=E*V-x*k,te=x*U-T*V,ie=P*k-M*U,re=M*V-A*k,ne=A*U-P*V,oe=z*i[0]+G*i[1]+W*i[2],se=z*i[3]+G*i[4]+W*i[5],ae=z*i[6]+G*i[7]+W*i[8],he=H*r[0]+j*r[1]+X*r[2],le=H*r[3]+j*r[4]+X*r[5],ce=H*r[6]+j*r[7]+X*r[8],ue=Y*i[0]+K*i[1]+Q*i[2],pe=Y*i[3]+K*i[4]+Q*i[5],fe=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],_e=$*i[0]+ee*i[1]+te*i[2],ve=$*i[3]+ee*i[4]+te*i[5],ye=$*i[6]+ee*i[7]+te*i[8],be=ie*r[0]+re*r[1]+ne*r[2],xe=ie*r[3]+re*r[4]+ne*r[5],Te=ie*r[6]+re*r[7]+ne*r[8];p.norT1X=z,p.norT1Y=G,p.norT1Z=W,p.tanT1X=Y,p.tanT1Y=K,p.tanT1Z=Q,p.binT1X=$,p.binT1Y=ee,p.binT1Z=te,p.norT2X=H,p.norT2Y=j,p.norT2Z=X,p.tanT2X=Z,p.tanT2Y=q,p.tanT2Z=J,p.binT2X=ie,p.binT2Y=re,p.binT2Z=ne,p.norTU1X=oe,p.norTU1Y=se,p.norTU1Z=ae,p.tanTU1X=ue,p.tanTU1Y=pe,p.tanTU1Z=fe,p.binTU1X=_e,p.binTU1Y=ve,p.binTU1Z=ye,p.norTU2X=he,p.norTU2Y=le,p.norTU2Z=ce,p.tanTU2X=de,p.tanTU2Y=me,p.tanTU2Z=ge,p.binTU2X=be,p.binTU2Y=xe,p.binTU2Z=Te,d=z*i[0]+G*i[1]+W*i[2],_=(m=z*i[3]+G*i[4]+W*i[5])*E-(g=z*i[6]+G*i[7]+W*i[8])*T,v=g*x-d*E,y=d*T-m*x,d=H*r[0]+j*r[1]+X*r[2];var Ee=1/(u+S*(_+=(m=H*r[3]+j*r[4]+X*r[5])*M-(g=H*r[6]+j*r[7]+X*r[8])*P)+C*(v+=g*A-d*M)+R*(y+=d*P-m*A));d=Y*i[0]+K*i[1]+Q*i[2],_=(m=Y*i[3]+K*i[4]+Q*i[5])*E-(g=Y*i[6]+K*i[7]+Q*i[8])*T,v=g*x-d*E,y=d*T-m*x,d=Z*r[0]+q*r[1]+J*r[2];var Ae=1/(u+L*(_+=(m=Z*r[3]+q*r[4]+J*r[5])*M-(g=Z*r[6]+q*r[7]+J*r[8])*P)+F*(v+=g*A-d*M)+N*(y+=d*P-m*A));d=$*i[0]+ee*i[1]+te*i[2],_=(m=$*i[3]+ee*i[4]+te*i[5])*E-(g=$*i[6]+ee*i[7]+te*i[8])*T,v=g*x-d*E,y=d*T-m*x,d=ie*r[0]+re*r[1]+ne*r[2];var Pe=1/(u+V*(_+=(m=ie*r[3]+re*r[4]+ne*r[5])*M-(g=ie*r[6]+re*r[7]+ne*r[8])*P)+U*(v+=g*A-d*M)+k*(y+=d*P-m*A));if(p.norDen=Ee,p.tanDen=Ae,p.binDen=Pe,b.warmStarted){var Me=b.normalImpulse;this.lv1.x+=p.norU1X*Me,this.lv1.y+=p.norU1Y*Me,this.lv1.z+=p.norU1Z*Me,this.av1.x+=oe*Me,this.av1.y+=se*Me,this.av1.z+=ae*Me,this.lv2.x-=p.norU2X*Me,this.lv2.y-=p.norU2Y*Me,this.lv2.z-=p.norU2Z*Me,this.av2.x-=he*Me,this.av2.y-=le*Me,this.av2.z-=ce*Me,p.norImp=Me,p.tanImp=0,p.binImp=0,D=0}else p.norImp=0,p.tanImp=0,p.binImp=0;D>-1&&(D=0);var Se=this.restitution*-D,Ce=-(b.penetration+.005)*t*.05;SeT*T&&(b*=M=T/a.sqrt(M),x*=M),m=b-d,_=x-g,e+=f.tanU1X*m+f.binU1X*_,t+=f.tanU1Y*m+f.binU1Y*_,i+=f.tanU1Z*m+f.binU1Z*_,s+=f.tanTU1X*m+f.binTU1X*_,h+=f.tanTU1Y*m+f.binTU1Y*_,l+=f.tanTU1Z*m+f.binTU1Z*_,r-=f.tanU2X*m+f.binU2X*_,n-=f.tanU2Y*m+f.binU2Y*_,o-=f.tanU2Z*m+f.binU2Z*_,c-=f.tanTU2X*m+f.binTU2X*_,u-=f.tanTU2Y*m+f.binTU2Y*_,p-=f.tanTU2Z*m+f.binTU2Z*_,v=(r-e)*f.norX+(n-t)*f.norY+(o-i)*f.norZ+c*f.norT2X+u*f.norT2Y+p*f.norT2Z-s*f.norT1X-h*f.norT1Y-l*f.norT1Z,d=y,m=(v-f.norTar)*f.norDen,(y+=m)>0&&(y=0),m=y-d,e+=f.norU1X*m,t+=f.norU1Y*m,i+=f.norU1Z*m,s+=f.norTU1X*m,h+=f.norTU1Y*m,l+=f.norTU1Z*m,r-=f.norU2X*m,n-=f.norU2Y*m,o-=f.norU2Z*m,c-=f.norTU2X*m,u-=f.norTU2Y*m,p-=f.norTU2Z*m,f.norImp=y,f.tanImp=b,f.binImp=x,f.last)break;f=f.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=h,this.av1.z=l,this.av2.x=c,this.av2.y=u,this.av2.z=p},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 h=this.points[this.numPoints++];h.position.x=e,h.position.y=t,h.position.z=i;var l=this.body1.rotation,c=e-this.body1.position.x,u=t-this.body1.position.y,p=i-this.body1.position.z,f=l.elements;h.localPoint1.x=c*f[0]+u*f[3]+p*f[6],h.localPoint1.y=c*f[1]+u*f[4]+p*f[7],h.localPoint1.z=c*f[2]+u*f[5]+p*f[8],l=this.body2.rotation,c=e-this.body2.position.x,u=t-this.body2.position.y,p=i-this.body2.position.z,h.localPoint2.x=c*f[0]+u*f[3]+p*f[6],h.localPoint2.y=c*f[1]+u*f[4]+p*f[7],h.localPoint2.z=c*f[2]+u*f[5]+p*f[8],h.normalImpulse=0,a?(h.normal.x=-r,h.normal.y=-n,h.normal.z=-o):(h.normal.x=r,h.normal.y=n,h.normal.z=o),h.penetration=s,h.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],h=t[14],l=t[15],c=t[16],u=t[17],p=this.position.x,f=this.position.y,d=this.position.z,m=this.elements;m[0]=p+i+o+l,m[1]=f+r+s+c,m[2]=d+n+h+u,m[3]=p+i+o-l,m[4]=f+r+s-c,m[5]=d+n+h-u,m[6]=p+i-o+l,m[7]=f+r-s+c,m[8]=d+n-h+u,m[9]=p+i-o-l,m[10]=f+r-s-c,m[11]=d+n-h-u,m[12]=p-i+o+l,m[13]=f-r+s+c,m[14]=d-n+h+u,m[15]=p-i+o-l,m[16]=f-r+s-c,m[17]=d-n+h-u,m[18]=p-i-o+l,m[19]=f-r-s+c,m[20]=d-n-h+u,m[21]=p-i-o-l,m[22]=f-r-s-c,m[23]=d-n-h-u;var g=t[9]<0?-t[9]:t[9],_=t[10]<0?-t[10]:t[10],v=t[11]<0?-t[11]:t[11];g=t[12]<0?g-t[12]:g+t[12],_=t[13]<0?_-t[13]:_+t[13],v=t[14]<0?v-t[14]:v+t[14],g=t[15]<0?g-t[15]:g+t[15],_=t[16]<0?_-t[16]:_+t[16],v=t[17]<0?v-t[17]:v+t[17];var y=a.AABB_PROX;this.aabb.set(this.position.x-g-y,this.position.x+g+y,this.position.y-_-y,this.position.y+_+y,this.position.z-v-y,this.position.z+v+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,h,l,c,u,p=this.rotation.elements;n=p[1]*p[1],o=p[4]*p[4],s=p[7]*p[7],this.normalDirection.set(p[1],p[4],p[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,h=this.halfDirection.x<0?-this.halfDirection.x:this.halfDirection.x,l=this.halfDirection.y<0?-this.halfDirection.y:this.halfDirection.y,c=this.halfDirection.z<0?-this.halfDirection.z:this.halfDirection.z,h=t<0?h-t:h+t,l=i<0?l-i:l+i,c=r<0?c-r:c+r,u=a.AABB_PROX,this.aabb.set(this.position.x-h-u,this.position.x+h+u,this.position.y-l-u,this.position.y+l+u,this.position.z-c-u,this.position.z+c+u),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=le*Se+ce*Ce+ue*Re,k=le*Ie+ce*Oe+ue*we,z=le*De+ce*Le+ue*Fe,U<0&&(U=-U),k<0&&(k=-k),z<0&&(z=-z),V=U*se+k*ae+z*he,!((x=N-B-V)>0||(N=pe*ee+fe*te+de*ie,(s=N>0)||(N=-N),B=ne,U=pe*Se+fe*Ce+de*Re,k=pe*Ie+fe*Oe+de*we,z=pe*De+fe*Le+de*Fe,U<0&&(U=-U),k<0&&(k=-k),z<0&&(z=-z),V=U*se+k*ae+z*he,(T=N-B-V)>0||(N=me*ee+ge*te+_e*ie,(h=N>0)||(N=-N),B=oe,U=me*Se+ge*Ce+_e*Re,k=me*Ie+ge*Oe+_e*we,z=me*De+ge*Le+_e*Fe,U<0&&(U=-U),k<0&&(k=-k),z<0&&(z=-z),V=U*se+k*ae+z*he,(E=N-B-V)>0||(N=Se*ee+Ce*te+Re*ie,(l=N>0)||(N=-N),U=Se*le+Ce*ce+Re*ue,k=Se*pe+Ce*fe+Re*de,z=Se*me+Ce*ge+Re*_e,U<0&&(U=-U),k<0&&(k=-k),z<0&&(z=-z),B=U*re+k*ne+z*oe,V=se,(A=1*(N-B-V))>0||(N=Ie*ee+Oe*te+we*ie,(c=N>0)||(N=-N),U=Ie*le+Oe*ce+we*ue,k=Ie*pe+Oe*fe+we*de,z=Ie*me+Oe*ge+we*_e,U<0&&(U=-U),k<0&&(k=-k),z<0&&(z=-z),B=U*re+k*ne+z*oe,V=ae,(P=1*(N-B-V))>0||(N=De*ee+Le*te+Fe*ie,(u=N>0)||(N=-N),U=De*le+Le*ce+Fe*ue,k=De*pe+Le*fe+Fe*de,z=De*me+Le*ge+Fe*_e,U<0&&(U=-U),k<0&&(k=-k),z<0&&(z=-z),B=U*re+k*ne+z*oe,V=he,(M=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,(p=N>0)||(N=-N),U=je*pe+Xe*fe+Ye*de,k=je*me+Xe*ge+Ye*_e,U<0&&(U=-U),k<0&&(k=-k),B=U*ne+k*oe,U=je*Ie+Xe*Oe+Ye*we,k=je*De+Xe*Le+Ye*Fe,U<0&&(U=-U),k<0&&(k=-k),V=U*ae+k*he,(S=N-B-V)>0)return}else p=!1,S=0,vt=!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,(f=N>0)||(N=-N),U=Ke*pe+Qe*fe+Ze*de,k=Ke*me+Qe*ge+Ze*_e,U<0&&(U=-U),k<0&&(k=-k),B=U*ne+k*oe,U=Ke*Se+Qe*Ce+Ze*Re,k=Ke*De+Qe*Le+Ze*Fe,U<0&&(U=-U),k<0&&(k=-k),V=U*se+k*he,(C=N-B-V)>0)return}else f=!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*pe+Je*fe+$e*de,k=qe*me+Je*ge+$e*_e,U<0&&(U=-U),k<0&&(k=-k),B=U*ne+k*oe,U=qe*Se+Je*Ce+$e*Re,k=qe*Ie+Je*Oe+$e*we,U<0&&(U=-U),k<0&&(k=-k),V=U*se+k*ae,(R=N-B-V)>0)return}else d=!1,R=0,bt=!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*le+tt*ce+it*ue,k=et*me+tt*ge+it*_e,U<0&&(U=-U),k<0&&(k=-k),B=U*re+k*oe,U=et*Ie+tt*Oe+it*we,k=et*De+tt*Le+it*Fe,U<0&&(U=-U),k<0&&(k=-k),V=U*ae+k*he,(I=N-B-V)>0)return}else m=!1,I=0,xt=!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*le+nt*ce+ot*ue,k=rt*me+nt*ge+ot*_e,U<0&&(U=-U),k<0&&(k=-k),B=U*re+k*oe,U=rt*Se+nt*Ce+ot*Re,k=rt*De+nt*Le+ot*Fe,U<0&&(U=-U),k<0&&(k=-k),V=U*se+k*he,(O=N-B-V)>0)return}else g=!1,O=0,Tt=!0;if((N=st*st+at*at+ht*ht)>1e-5){if(N=1/a.sqrt(N),st*=N,at*=N,ht*=N,N=st*ee+at*te+ht*ie,(_=N>0)||(N=-N),U=st*le+at*ce+ht*ue,k=st*me+at*ge+ht*_e,U<0&&(U=-U),k<0&&(k=-k),B=U*re+k*oe,U=st*Se+at*Ce+ht*Re,k=st*Ie+at*Oe+ht*we,U<0&&(U=-U),k<0&&(k=-k),V=U*se+k*ae,(w=N-B-V)>0)return}else _=!1,w=0,Et=!0;if((N=lt*lt+ct*ct+ut*ut)>1e-5){if(N=1/a.sqrt(N),lt*=N,ct*=N,ut*=N,N=lt*ee+ct*te+ut*ie,(v=N>0)||(N=-N),U=lt*le+ct*ce+ut*ue,k=lt*pe+ct*fe+ut*de,U<0&&(U=-U),k<0&&(k=-k),B=U*re+k*ne,U=lt*Ie+ct*Oe+ut*we,k=lt*De+ct*Le+ut*Fe,U<0&&(U=-U),k<0&&(k=-k),V=U*ae+k*he,(D=N-B-V)>0)return}else v=!1,D=0,At=!0;if((N=pt*pt+ft*ft+dt*dt)>1e-5){if(N=1/a.sqrt(N),pt*=N,ft*=N,dt*=N,N=pt*ee+ft*te+dt*ie,(y=N>0)||(N=-N),U=pt*le+ft*ce+dt*ue,k=pt*pe+ft*fe+dt*de,U<0&&(U=-U),k<0&&(k=-k),B=U*re+k*ne,U=pt*Se+ft*Ce+dt*Re,k=pt*De+ft*Le+dt*Fe,U<0&&(U=-U),k<0&&(k=-k),V=U*se+k*he,(L=N-B-V)>0)return}else y=!1,L=0,Pt=!0;if((N=mt*mt+gt*gt+_t*_t)>1e-5){if(N=1/a.sqrt(N),mt*=N,gt*=N,_t*=N,N=mt*ee+gt*te+_t*ie,(b=N>0)||(N=-N),U=mt*le+gt*ce+_t*ue,k=mt*pe+gt*fe+_t*de,U<0&&(U=-U),k<0&&(k=-k),B=U*re+k*ne,U=mt*Se+gt*Ce+_t*Re,k=mt*Ie+gt*Oe+_t*we,U<0&&(U=-U),k<0&&(k=-k),V=U*se+k*ae,(F=N-B-V)>0)return}else b=!1,F=0,Mt=!0;var St=x,Ct=x,Rt=0,It=o;T>Ct&&(St=T,Ct=T,Rt=1,It=s),E>Ct&&(St=E,Ct=E,Rt=2,It=h),A>Ct&&(St=A,Ct=A,Rt=3,It=l),P>Ct&&(St=P,Ct=P,Rt=4,It=c),M>Ct&&(St=M,Ct=M,Rt=5,It=u),S-.01>Ct&&!vt&&(St=S,Ct=S-.01,Rt=6,It=p),C-.01>Ct&&!yt&&(St=C,Ct=C-.01,Rt=7,It=f),R-.01>Ct&&!bt&&(St=R,Ct=R-.01,Rt=8,It=d),I-.01>Ct&&!xt&&(St=I,Ct=I-.01,Rt=9,It=m),O-.01>Ct&&!Tt&&(St=O,Ct=O-.01,Rt=10,It=g),w-.01>Ct&&!Et&&(St=w,Ct=w-.01,Rt=11,It=_),D-.01>Ct&&!At&&(St=D,Ct=D-.01,Rt=12,It=v),L-.01>Ct&&!Pt&&(St=L,Ct=L-.01,Rt=13,It=y),F-.01>Ct&&!Mt&&(St=F,Rt=14,It=b);var Ot=0,wt=0,Dt=0,Lt=0,Ft=0,Nt=0,Bt=0,Vt=0,Ut=0,kt=0,zt=0,Gt=0,Wt=0,Ht=0,jt=0,Xt=0,Yt=0,Kt=0,Qt=!1;0==Rt?(It?(kt=K+ve,zt=Q+ye,Gt=Z+be,Ot=le,wt=ce,Dt=ue):(kt=K-ve,zt=Q-ye,Gt=Z-be,Ot=-le,wt=-ce,Dt=-ue),Wt=xe,Ht=Te,jt=Ee,Lt=-pe,Ft=-fe,Nt=-de,Xt=Ae,Yt=Pe,Kt=Me,Bt=-me,Vt=-ge,Ut=-_e):1==Rt?(It?(kt=K+xe,zt=Q+Te,Gt=Z+Ee,Ot=pe,wt=fe,Dt=de):(kt=K-xe,zt=Q-Te,Gt=Z-Ee,Ot=-pe,wt=-fe,Dt=-de),Wt=ve,Ht=ye,jt=be,Lt=-le,Ft=-ce,Nt=-ue,Xt=Ae,Yt=Pe,Kt=Me,Bt=-me,Vt=-ge,Ut=-_e):2==Rt?(It?(kt=K+Ae,zt=Q+Pe,Gt=Z+Me,Ot=me,wt=ge,Dt=_e):(kt=K-Ae,zt=Q-Pe,Gt=Z-Me,Ot=-me,wt=-ge,Dt=-_e),Wt=ve,Ht=ye,jt=be,Lt=-le,Ft=-ce,Nt=-ue,Xt=xe,Yt=Te,Kt=Ee,Bt=-pe,Vt=-fe,Ut=-de):3==Rt?(Qt=!0,It?(kt=q-Ne,zt=J-Be,Gt=$-Ve,Ot=-Se,wt=-Ce,Dt=-Re):(kt=q+Ne,zt=J+Be,Gt=$+Ve,Ot=Se,wt=Ce,Dt=Re),Wt=Ue,Ht=ke,jt=ze,Lt=-Ie,Ft=-Oe,Nt=-we,Xt=Ge,Yt=We,Kt=He,Bt=-De,Vt=-Le,Ut=-Fe):4==Rt?(Qt=!0,It?(kt=q-Ue,zt=J-ke,Gt=$-ze,Ot=-Ie,wt=-Oe,Dt=-we):(kt=q+Ue,zt=J+ke,Gt=$+ze,Ot=Ie,wt=Oe,Dt=we),Wt=Ne,Ht=Be,jt=Ve,Lt=-Se,Ft=-Ce,Nt=-Re,Xt=Ge,Yt=We,Kt=He,Bt=-De,Vt=-Le,Ut=-Fe):5==Rt?(Qt=!0,It?(kt=q-Ge,zt=J-We,Gt=$-He,Ot=-De,wt=-Le,Dt=-Fe):(kt=q+Ge,zt=J+We,Gt=$+He,Ot=De,wt=Le,Dt=Fe),Wt=Ne,Ht=Be,jt=Ve,Lt=-Se,Ft=-Ce,Nt=-Re,Xt=Ue,Yt=ke,Kt=ze,Bt=-Ie,Vt=-Oe,Ut=-we):6==Rt?(Ot=je,wt=Xe,Dt=Ye,Lt=le,Ft=ce,Nt=ue,Bt=Se,Vt=Ce,Ut=Re):7==Rt?(Ot=Ke,wt=Qe,Dt=Ze,Lt=le,Ft=ce,Nt=ue,Bt=Ie,Vt=Oe,Ut=we):8==Rt?(Ot=qe,wt=Je,Dt=$e,Lt=le,Ft=ce,Nt=ue,Bt=De,Vt=Le,Ut=Fe):9==Rt?(Ot=et,wt=tt,Dt=it,Lt=pe,Ft=fe,Nt=de,Bt=Se,Vt=Ce,Ut=Re):10==Rt?(Ot=rt,wt=nt,Dt=ot,Lt=pe,Ft=fe,Nt=de,Bt=Ie,Vt=Oe,Ut=we):11==Rt?(Ot=st,wt=at,Dt=ht,Lt=pe,Ft=fe,Nt=de,Bt=De,Vt=Le,Ut=Fe):12==Rt?(Ot=lt,wt=ct,Dt=ut,Lt=me,Ft=ge,Nt=_e,Bt=Se,Vt=Ce,Ut=Re):13==Rt?(Ot=pt,wt=ft,Dt=dt,Lt=me,Ft=ge,Nt=_e,Bt=Ie,Vt=Oe,Ut=we):14==Rt&&(Ot=mt,wt=gt,Dt=_t,Lt=me,Ft=ge,Nt=_e,Bt=De,Vt=Le,Ut=Fe);if(Rt>5){It||(Ot=-Ot,wt=-wt,Dt=-Dt);var Zt,qt,Jt,$t,ei,ti,ii,ri,ni,oi,si;qt=Ot*(ti=G[0])+wt*(ii=G[1])+Dt*(ri=G[2]),(Zt=Ot*(Jt=G[3])+wt*($t=G[4])+Dt*(ei=G[5]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[6])+wt*($t=G[7])+Dt*(ei=G[8]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[9])+wt*($t=G[10])+Dt*(ei=G[11]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[12])+wt*($t=G[13])+Dt*(ei=G[14]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[15])+wt*($t=G[16])+Dt*(ei=G[17]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[18])+wt*($t=G[19])+Dt*(ei=G[20]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),(Zt=Ot*(Jt=G[21])+wt*($t=G[22])+Dt*(ei=G[23]))>qt&&(qt=Zt,ti=Jt,ii=$t,ri=ei),qt=Ot*(ni=W[0])+wt*(oi=W[1])+Dt*(si=W[2]),(Zt=Ot*(Jt=W[3])+wt*($t=W[4])+Dt*(ei=W[5]))0?k>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-k),this.clipVertices2[Pi]=Mi+(Ri-Mi)*ai,this.clipVertices2[Pi+1]=Si+(Ii-Si)*ai,this.clipVertices2[Pi+2]=Ci+(Oi-Ci)*ai):k>0&&(Pi=3*Ai,Ai++,ai=U/(U-k),this.clipVertices2[Pi]=Mi+(Ri-Mi)*ai,this.clipVertices2[Pi+1]=Si+(Ii-Si)*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),Mi=Ri,Si=Ii,Ci=Oi,U=k;if(0!=(Ei=Ai)){for(Ai=0,Pi=3*(Ei-1),U=((Mi=this.clipVertices2[Pi])-kt-Xt)*Bt+((Si=this.clipVertices2[Pi+1])-zt-Yt)*Vt+((Ci=this.clipVertices2[Pi+2])-Gt-Kt)*Ut,wi=0;wi0?k>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-k),this.clipVertices1[Pi]=Mi+(Ri-Mi)*ai,this.clipVertices1[Pi+1]=Si+(Ii-Si)*ai,this.clipVertices1[Pi+2]=Ci+(Oi-Ci)*ai):k>0&&(Pi=3*Ai,Ai++,ai=U/(U-k),this.clipVertices1[Pi]=Mi+(Ri-Mi)*ai,this.clipVertices1[Pi+1]=Si+(Ii-Si)*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),Mi=Ri,Si=Ii,Ci=Oi,U=k;if(0!=(Ei=Ai)){for(Ai=0,Pi=3*(Ei-1),U=((Mi=this.clipVertices1[Pi])-kt+Wt)*-Lt+((Si=this.clipVertices1[Pi+1])-zt+Ht)*-Ft+((Ci=this.clipVertices1[Pi+2])-Gt+jt)*-Nt,wi=0;wi0?k>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-k),this.clipVertices2[Pi]=Mi+(Ri-Mi)*ai,this.clipVertices2[Pi+1]=Si+(Ii-Si)*ai,this.clipVertices2[Pi+2]=Ci+(Oi-Ci)*ai):k>0&&(Pi=3*Ai,Ai++,ai=U/(U-k),this.clipVertices2[Pi]=Mi+(Ri-Mi)*ai,this.clipVertices2[Pi+1]=Si+(Ii-Si)*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),Mi=Ri,Si=Ii,Ci=Oi,U=k;if(0!=(Ei=Ai)){for(Ai=0,Pi=3*(Ei-1),U=((Mi=this.clipVertices2[Pi])-kt+Xt)*-Bt+((Si=this.clipVertices2[Pi+1])-zt+Yt)*-Vt+((Ci=this.clipVertices2[Pi+2])-Gt+Kt)*-Ut,wi=0;wi0?k>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-k),this.clipVertices1[Pi]=Mi+(Ri-Mi)*ai,this.clipVertices1[Pi+1]=Si+(Ii-Si)*ai,this.clipVertices1[Pi+2]=Ci+(Oi-Ci)*ai):k>0&&(Pi=3*Ai,Ai++,ai=U/(U-k),this.clipVertices1[Pi]=Mi+(Ri-Mi)*ai,this.clipVertices1[Pi+1]=Si+(Ii-Si)*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),Mi=Ri,Si=Ii,Ci=Oi,U=k;if(Ei=Ai,Qt){var Di=r;r=n,n=Di}if(0!=Ei){var Li=r!=e;if(Ei>4){Lt=hi-(Mi=.25*(hi+ui+di+_i)),Ft=li-(Si=.25*(li+pi+mi+vi)),Nt=ci-(Ci=.25*(ci+fi+gi+yi)),Bt=ui-Mi,Vt=pi-Si,Ut=fi-Ci;var Fi=0,Ni=0,Bi=0,Vi=0,Ui=-this.INF;for(bi=this.INF,wi=0;wiUi&&(Ui=xi,Bi=wi);for(this.used[Fi]=!0,this.used[Bi]=!0,Ui=-this.INF,bi=this.INF,wi=0;wiUi&&(Ui=xi,Vi=wi));Pi=3*Fi,(xi=((Mi=this.clipVertices1[Pi])-kt)*Ot+((Si=this.clipVertices1[Pi+1])-zt)*wt+((Ci=this.clipVertices1[Pi+2])-Gt)*Dt)<0&&i.addPoint(Mi,Si,Ci,Ot,wt,Dt,xi,Li),Pi=3*Ni,(xi=((Mi=this.clipVertices1[Pi])-kt)*Ot+((Si=this.clipVertices1[Pi+1])-zt)*wt+((Ci=this.clipVertices1[Pi+2])-Gt)*Dt)<0&&i.addPoint(Mi,Si,Ci,Ot,wt,Dt,xi,Li),Pi=3*Bi,(xi=((Mi=this.clipVertices1[Pi])-kt)*Ot+((Si=this.clipVertices1[Pi+1])-zt)*wt+((Ci=this.clipVertices1[Pi+2])-Gt)*Dt)<0&&i.addPoint(Mi,Si,Ci,Ot,wt,Dt,xi,Li),Pi=3*Vi,(xi=((Mi=this.clipVertices1[Pi])-kt)*Ot+((Si=this.clipVertices1[Pi+1])-zt)*wt+((Ci=this.clipVertices1[Pi+2])-Gt)*Dt)<0&&i.addPoint(Mi,Si,Ci,Ot,wt,Dt,xi,Li)}else for(wi=0;wix?S=x:S<-x?S=-x: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=S<0?x+S:x-S,P=C<0?T+C:T-C,M=R<0?E+R:E-R,A0&&l0&&u0&&(o=V,s=U,h=k,V=Y,U=K,k=Q,Y=o,K=s,Q=h,o=w,s=D,h=L,w=z,D=G,L=W,z=o,G=s,W=h,o=F,s=N,h=B,F=H,N=j,B=X,H=o,j=s,X=h,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-k*ne)*M+(k*re-V*oe)*S+(V*ne-U*re)*C<0)Y=re,K=ne,Q=oe,z=q,G=J,W=$,H=ee,j=te,X=ie,R=(s=U-S)*(u=oe-C)-(h=k-C)*(c=ne-S),I=h*(l=re-M)-(o=V-M)*u,O=o*c-s*l;else if((ne*Q-oe*K)*M+(oe*Y-re*Q)*S+(re*K-ne*Y)*C<0)V=re,U=ne,k=oe,w=q,D=J,L=$,F=ee,N=te,B=ie,R=(s=ne-S)*(u=Q-C)-(h=oe-C)*(c=K-S),I=h*(l=Y-M)-(o=re-M)*u,O=o*c-s*l;else for(var se=!1;;){if(o=Y-V,s=K-U,h=Q-k,l=re-V,c=ne-U,u=oe-k,R=s*u-h*c,I=h*l-o*u,O=o*c-s*l,p=1/a.sqrt(R*R+I*I+O*O),R*=p,I*=p,O*=p,R*V+I*U+O*k>=0&&!se){var ae=(U*Q-k*K)*re+(k*Y-V*Q)*ne+(V*K-U*Y)*oe,he=(ne*Q-oe*K)*M+(oe*Y-re*Q)*S+(re*K-ne*Y)*C,le=(S*k-C*U)*re+(C*V-M*k)*ne+(M*U-S*V)*oe,ce=(K*k-Q*U)*M+(Q*V-Y*k)*S+(Y*U-K*V)*C,ue=ae+he+le+ce;ue<=0&&(ae=0,ue=(he=(K*oe-Q*ne)*R+(Q*re-Y*oe)*I+(Y*ne-K*re)*O)+(le=(ne*Q-oe*K)*R+(oe*Y-re*Q)*I+(re*K-ne*Y)*O)+(ce=(U*Q-k*K)*R+(k*Y-V*Q)*I+(V*K-U*Y)*O));var pe=1/ue;f=(b*ae+w*he+z*le+q*ce)*pe,d=(x*ae+D*he+G*le+J*ce)*pe,m=(T*ae+L*he+W*le+$*ce)*pe,g=(E*ae+F*he+H*le+ee*ce)*pe,_=(A*ae+N*he+j*le+te*ce)*pe,v=(P*ae+B*he+X*le+ie*ce)*pe,se=!0}this.supportPointB(e,-R,-I,-O,y);var fe=y.x,de=y.y,me=y.z;this.supportPointC(t,R,I,O,y);var ge=y.x,_e=y.y,ve=y.z,ye=ge-fe,be=_e-de,xe=ve-me,Te=-(ye*R+be*I+xe*O);if((ye-re)*R+(be-ne)*I+(xe-oe)*O<=.01||Te>=0)return!!se&&(i.init(-R,-I,-O),r.init(.5*(f+g),.5*(d+_),.5*(m+v)),n.x=Te,!0);(be*k-xe*U)*M+(xe*V-ye*k)*S+(ye*U-be*V)*C<0?(be*Q-xe*K)*M+(xe*Y-ye*Q)*S+(ye*K-be*Y)*C<0?(V=ye,U=be,k=xe,w=fe,D=de,L=me,F=ge,N=_e,B=ve):(re=ye,ne=be,oe=xe,q=fe,J=de,$=me,ee=ge,te=_e,ie=ve):(be*oe-xe*ne)*M+(xe*re-ye*oe)*S+(ye*ne-be*re)*C<0?(Y=ye,K=be,Q=xe,z=fe,G=de,W=me,H=ge,j=_e,X=ve):(V=ye,U=be,k=xe,w=fe,D=de,L=me,F=ge,N=_e,B=ve)}}},a.BoxCylinderCollisionDetector.prototype.supportPointB=function(e,t,i,r,n){var o,s,a,h=e.rotation.elements,l=h[0]*t+h[3]*i+h[6]*r,c=h[1]*t+h[4]*i+h[7]*r,u=h[2]*t+h[5]*i+h[8]*r,p=e.halfWidth,f=e.halfHeight,d=e.halfDepth;o=l<0?-p:p,s=c<0?-f:f,a=u<0?-d:d,l=h[0]*o+h[1]*s+h[2]*a+e.position.x,c=h[3]*o+h[4]*s+h[5]*a+e.position.y,u=h[6]*o+h[7]*s+h[8]*a+e.position.z,n.init(l,c,u)},a.BoxCylinderCollisionDetector.prototype.supportPointC=function(e,t,i,r,n){var o,s,h,l=e.rotation.elements,c=l[0]*t+l[3]*i+l[6]*r,u=l[1]*t+l[4]*i+l[7]*r,p=l[2]*t+l[5]*i+l[8]*r,f=c,d=p,m=f*f+d*d,g=e.radius,_=e.halfHeight;0==m?u<0?(o=g,s=-_,h=0):(o=g,s=_,h=0):(m=e.radius/a.sqrt(m),u<0?(o=f*m,s=-_,h=d*m):(o=f*m,s=_,h=d*m)),c=l[0]*o+l[1]*s+l[2]*h+e.position.x,u=l[3]*o+l[4]*s+l[5]*h+e.position.y,p=l[6]*o+l[7]*s+l[8]*h+e.position.z,n.init(c,u,p)},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,h=new a.Vec3;if(this.getSep(r,n,o,s,h)){var l=r.position.x,c=r.position.y,u=r.position.z,p=n.position.x,f=n.position.y,d=n.position.z,m=r.halfWidth,g=r.halfHeight,_=r.halfDepth,v=n.halfHeight,y=n.radius,b=r.dimentions,x=b[0],T=b[1],E=b[2],A=b[3],P=b[4],M=b[5],S=b[6],C=b[7],R=b[8],I=b[9],O=b[10],w=b[11],D=b[12],L=b[13],F=b[14],N=b[15],B=b[16],V=b[17],U=n.normalDirection.x,k=n.normalDirection.y,z=n.normalDirection.z,G=n.halfDirection.x,W=n.halfDirection.y,H=n.halfDirection.z,j=o.x,X=o.y,Y=o.z,K=j*x+X*T+Y*E,Q=j*A+X*P+Y*M,Z=j*S+X*C+Y*R,q=j*U+X*k+Y*z,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,he,le,ce,ue,pe,fe,de,me,ge,_e,ve,ye,be,xe,Te,Ee,Ae,Pe,Me,Se,Ce,Re,Ie,Oe,we,De,Le,Fe,Ne,Be,Ve,Ue,ke,ze,Ge,We,He,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,h.x,this.flip);else if(4==ie){te?(se=p-G,ae=f-W,he=d-H,j=-U,X=-k,Y=-z):(se=p+G,ae=f+W,he=d+H,j=U,X=k,Y=z);var it,rt,nt,ot,st,at,ht,lt,ct,ut,pt,ft;ie=0,(je=x*j+T*X+E*Y)<(Te=1)&&(Te=je,ie=0),-je=.999999?(Ae=-X,Pe=Y,Me=j):(Ae=j,Pe=X,Me=Y),Ee=Ae*U+Pe*k+Me*z,Ce=Ee*U-Ae,Re=Ee*k-Pe,Ie=Ee*z-Me,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,Me=he+Ie,Te<-.96||Te>.96)le=U*U*1.5-.5,ce=U*k*1.5-.866025403*z,ue=U*z*1.5+.866025403*k,pe=k*U*1.5+.866025403*z,fe=k*k*1.5-.5,de=k*z*1.5-.866025403*U,me=z*U*1.5-.866025403*k,ge=z*k*1.5+.866025403*U,_e=z*z*1.5-.5,He=qe*(Ae=(ve=Ae)-(xe=j*(ve-re)+X*((ye=Pe)-ne)+Y*((be=Me)-oe))*j-re)+Je*(Pe=ye-xe*X-ne)+$e*(Me=be-xe*Y-oe),(ke=Ke*Ae+Qe*Pe+Ze*Me)<-et?ke=-et:ke>et&&(ke=et),He<-tt?He=-tt:He>tt&&(He=tt),ve=re+(Ae=ke*Ke+He*qe),ye=ne+(Pe=ke*Qe+He*Je),be=oe+(Me=ke*Ze+He*$e),i.addPoint(ve,ye,be,j,X,Y,xe,this.flip),ye=Ce*pe+Re*fe+Ie*de,be=Ce*me+Re*ge+Ie*_e,(xe=j*((ve=(Ce=ve=Ce*le+Re*ce+Ie*ue)+se)-re)+X*((ye=(Re=ye)+ae)-ne)+Y*((be=(Ie=be)+he)-oe))<=0&&(He=qe*(Ae=ve-xe*j-re)+Je*(Pe=ye-xe*X-ne)+$e*(Me=be-xe*Y-oe),(ke=Ke*Ae+Qe*Pe+Ze*Me)<-et?ke=-et:ke>et&&(ke=et),He<-tt?He=-tt:He>tt&&(He=tt),ve=re+(Ae=ke*Ke+He*qe),ye=ne+(Pe=ke*Qe+He*Je),be=oe+(Me=ke*Ze+He*$e),i.addPoint(ve,ye,be,j,X,Y,xe,this.flip)),ye=Ce*pe+Re*fe+Ie*de,be=Ce*me+Re*ge+Ie*_e,(xe=j*((ve=(Ce=ve=Ce*le+Re*ce+Ie*ue)+se)-re)+X*((ye=(Re=ye)+ae)-ne)+Y*((be=(Ie=be)+he)-oe))<=0&&(He=qe*(Ae=ve-xe*j-re)+Je*(Pe=ye-xe*X-ne)+$e*(Me=be-xe*Y-oe),(ke=Ke*Ae+Qe*Pe+Ze*Me)<-et?ke=-et:ke>et&&(ke=et),He<-tt?He=-tt:He>tt&&(He=tt),ve=re+(Ae=ke*Ke+He*qe),ye=ne+(Pe=ke*Qe+He*Je),be=oe+(Me=ke*Ze+He*$e),i.addPoint(ve,ye,be,j,X,Y,xe,this.flip));else{if(Be=Ae,Ve=Pe,Ue=Me,ke=j*(Be-re)+X*(Ve-ne)+Y*(Ue-oe),Be-=ke*j,Ve-=ke*X,Ue-=ke*Y,Te>0?(ze=Ae+2*G,Ge=Pe+2*W,We=Me+2*H):(ze=Ae-2*G,Ge=Pe-2*W,We=Me-2*H),He=j*(ze-re)+X*(Ge-ne)+Y*(We-oe),ze-=He*j,Ge-=He*X,We-=He*Y,Oe=Be-re,we=Ve-ne,De=Ue-oe,Le=ze-re,Fe=Ge-ne,Ne=We-oe,Ae=ze-Be,Pe=Ge-Ve,Me=We-Ue,Se=He-ke,K=Oe*Ke+we*Qe+De*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+(we=(Ve+=Pe*Ye)-ne)*Qe+(De=(Ue+=Me*Ye)-oe)*Ze,Ae=ze-Be,Pe=Ge-Ve,Me=We-Ue,Se=He-(ke+=Se*Ye)}else Xe>0&&(Q=(Le=(ze=Be+Ae*(Ye=je/(je-Xe)))-re)*Ke+(Fe=(Ge=Ve+Pe*Ye)-ne)*Qe+(Ne=(We=Ue+Me*Ye)-oe)*Ze,Ae=ze-Be,Pe=Ge-Ve,Me=We-Ue,Se=(He=ke+Se*Ye)-ke);if(je=K+et,Xe=Q+et,je<0){if(Xe<0)return;Oe=(Be+=Ae*(Ye=je/(je-Xe)))-re,we=(Ve+=Pe*Ye)-ne,De=(Ue+=Me*Ye)-oe,Ae=ze-Be,Pe=Ge-Ve,Me=We-Ue,Se=He-(ke+=Se*Ye)}else Xe<0&&(Le=(ze=Be+Ae*(Ye=je/(je-Xe)))-re,Fe=(Ge=Ve+Pe*Ye)-ne,Ne=(We=Ue+Me*Ye)-oe,Ae=ze-Be,Pe=Ge-Ve,Me=We-Ue,Se=(He=ke+Se*Ye)-ke);if(K=Oe*qe+we*Je+De*$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+(we=(Ve+=Pe*Ye)-ne)*Je+(De=(Ue+=Me*Ye)-oe)*$e,Ae=ze-Be,Pe=Ge-Ve,Me=We-Ue,Se=He-(ke+=Se*Ye)}else Xe>0&&(Q=(Le=(ze=Be+Ae*(Ye=je/(je-Xe)))-re)*qe+(Fe=(Ge=Ve+Pe*Ye)-ne)*Je+(Ne=(We=Ue+Me*Ye)-oe)*$e,Ae=ze-Be,Pe=Ge-Ve,Me=We-Ue,Se=(He=ke+Se*Ye)-ke);if(je=K+tt,Xe=Q+tt,je<0){if(Xe<0)return;Be+=Ae*(Ye=je/(je-Xe)),Ve+=Pe*Ye,Ue+=Me*Ye,ke+=Se*Ye}else Xe<0&&(ze=Be+Ae*(Ye=je/(je-Xe)),Ge=Ve+Pe*Ye,We=Ue+Me*Ye,He=ke+Se*Ye);ke<0&&i.addPoint(Be,Ve,Ue,j,X,Y,ke,this.flip),He<0&&i.addPoint(ze,Ge,We,j,X,Y,He,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,h,l,c,u,p,f,d,m,g,_,v,y=new a.Vec3,b=e.position.x,x=e.position.y,T=e.position.z,E=t.position.x,A=t.position.y,P=t.position.z,M=E-b,S=A-x,C=P-T;M*M+S*S+C*C==0&&(S=.001);var R=-M,I=-S,O=-C;this.supportPoint(e,-R,-I,-O,y);var w=y.x,D=y.y,L=y.z;this.supportPoint(t,R,I,O,y);var F=y.x,N=y.y,B=y.z,V=F-w,U=N-D,k=B-L;if(V*R+U*I+k*O<=0)return!1;if(R=U*C-k*S,I=k*M-V*C,O=V*S-U*M,R*R+I*I+O*O==0)return i.init(V-M,U-S,k-C),i.normalize(i),r.init(.5*(w+F),.5*(D+N),.5*(L+B)),!0;this.supportPoint(e,-R,-I,-O,y);var z=y.x,G=y.y,W=y.z;this.supportPoint(t,R,I,O,y);var H=y.x,j=y.y,X=y.z,Y=H-z,K=j-G,Q=X-W;if(Y*R+K*I+Q*O<=0)return!1;(R=(s=U-S)*(u=Q-C)-(h=k-C)*(c=K-S))*M+(I=h*(l=Y-M)-(o=V-M)*u)*S+(O=o*c-s*l)*C>0&&(o=V,s=U,h=k,V=Y,U=K,k=Q,Y=o,K=s,Q=h,o=w,s=D,h=L,w=z,D=G,L=W,z=o,G=s,W=h,o=F,s=N,h=B,F=H,N=j,B=X,H=o,j=s,X=h,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-k*ne)*M+(k*re-V*oe)*S+(V*ne-U*re)*C<0)Y=re,K=ne,Q=oe,z=q,G=J,W=$,H=ee,j=te,X=ie,R=(s=U-S)*(u=oe-C)-(h=k-C)*(c=ne-S),I=h*(l=re-M)-(o=V-M)*u,O=o*c-s*l;else if((ne*Q-oe*K)*M+(oe*Y-re*Q)*S+(re*K-ne*Y)*C<0)V=re,U=ne,k=oe,w=q,D=J,L=$,F=ee,N=te,B=ie,R=(s=ne-S)*(u=Q-C)-(h=oe-C)*(c=K-S),I=h*(l=Y-M)-(o=re-M)*u,O=o*c-s*l;else for(var se=!1;;){if(o=Y-V,s=K-U,h=Q-k,l=re-V,c=ne-U,u=oe-k,R=s*u-h*c,I=h*l-o*u,O=o*c-s*l,p=1/a.sqrt(R*R+I*I+O*O),R*=p,I*=p,O*=p,R*V+I*U+O*k>=0&&!se){var ae=(U*Q-k*K)*re+(k*Y-V*Q)*ne+(V*K-U*Y)*oe,he=(ne*Q-oe*K)*M+(oe*Y-re*Q)*S+(re*K-ne*Y)*C,le=(S*k-C*U)*re+(C*V-M*k)*ne+(M*U-S*V)*oe,ce=(K*k-Q*U)*M+(Q*V-Y*k)*S+(Y*U-K*V)*C,ue=ae+he+le+ce;ue<=0&&(ae=0,ue=(he=(K*oe-Q*ne)*R+(Q*re-Y*oe)*I+(Y*ne-K*re)*O)+(le=(ne*Q-oe*K)*R+(oe*Y-re*Q)*I+(re*K-ne*Y)*O)+(ce=(U*Q-k*K)*R+(k*Y-V*Q)*I+(V*K-U*Y)*O));var pe=1/ue;f=(b*ae+w*he+z*le+q*ce)*pe,d=(x*ae+D*he+G*le+J*ce)*pe,m=(T*ae+L*he+W*le+$*ce)*pe,g=(E*ae+F*he+H*le+ee*ce)*pe,_=(A*ae+N*he+j*le+te*ce)*pe,v=(P*ae+B*he+X*le+ie*ce)*pe,se=!0}this.supportPoint(e,-R,-I,-O,y);var fe=y.x,de=y.y,me=y.z;this.supportPoint(t,R,I,O,y);var ge=y.x,_e=y.y,ve=y.z,ye=ge-fe,be=_e-de,xe=ve-me,Te=-(ye*R+be*I+xe*O);if((ye-re)*R+(be-ne)*I+(xe-oe)*O<=.01||Te>=0)return!!se&&(i.init(-R,-I,-O),r.init(.5*(f+g),.5*(d+_),.5*(m+v)),n.x=Te,!0);(be*k-xe*U)*M+(xe*V-ye*k)*S+(ye*U-be*V)*C<0?(be*Q-xe*K)*M+(xe*Y-ye*Q)*S+(ye*K-be*Y)*C<0?(V=ye,U=be,k=xe,w=fe,D=de,L=me,F=ge,N=_e,B=ve):(re=ye,ne=be,oe=xe,q=fe,J=de,$=me,ee=ge,te=_e,ie=ve):(be*oe-xe*ne)*M+(xe*re-ye*oe)*S+(ye*ne-be*re)*C<0?(Y=ye,K=be,Q=xe,z=fe,G=de,W=me,H=ge,j=_e,X=ve):(V=ye,U=be,k=xe,w=fe,D=de,L=me,F=ge,N=_e,B=ve)}}},a.CylinderCylinderCollisionDetector.prototype.supportPoint=function(e,t,i,r,n){var o,s,h,l=e.rotation.elements,c=l[0]*t+l[3]*i+l[6]*r,u=l[1]*t+l[4]*i+l[7]*r,p=l[2]*t+l[5]*i+l[8]*r,f=c,d=p,m=f*f+d*d,g=e.radius,_=e.halfHeight;0==m?u<0?(o=g,s=-_,h=0):(o=g,s=_,h=0):(m=e.radius/a.sqrt(m),u<0?(o=f*m,s=-_,h=d*m):(o=f*m,s=_,h=d*m)),c=l[0]*o+l[1]*s+l[2]*h+e.position.x,u=l[3]*o+l[4]*s+l[5]*h+e.position.y,p=l[6]*o+l[7]*s+l[8]*h+e.position.z,n.init(c,u,p)},a.CylinderCylinderCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n;e.id0,ce=he>0;le||(ae=-ae),ce||(he=-he);var ue=0;(ae>.999||he>.999)&&(ue=ae>he?1:2);var pe,fe,de,me,ge,_e,ve,ye,be,xe,Te,Ee,Ae,Pe,Me,Se,Ce,Re,Ie,Oe,we=se.x;switch(pe=ne.x,fe=ne.y,de=ne.z,ue){case 0:i.addPoint(oe.x,oe.y,oe.z,pe,fe,de,we,!1);break;case 1:if(le?(s=R+Q,h=I+Z,l=O+q,pe=W,fe=H,de=j):(s=R-Q,h=I-Z,l=O-q,pe=-W,fe=-H,de=-j),A=pe*X+fe*Y+de*K,o=A<0?N:-N,c=w+o*X,u=D+o*Y,p=L+o*K,he>=.999999?(f=-fe,d=de,m=pe):(f=pe,d=fe,m=de),o=f*X+d*Y+m*K,te=o*X-f,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,f=c+te,d=u+ie,m=p+re,A<-.96||A>.96)me=X*X*1.5-.5,ge=X*Y*1.5-.866025403*K,_e=X*K*1.5+.866025403*Y,ve=Y*X*1.5+.866025403*K,ye=Y*Y*1.5-.5,be=Y*K*1.5-.866025403*X,xe=K*X*1.5-.866025403*Y,Te=K*Y*1.5+.866025403*X,Ee=K*K*1.5-.5,(o=(f=(Ae=f)-(Se=pe*(Ae-s)+fe*((Pe=d)-h)+de*((Me=m)-l))*pe-s)*f+(d=Pe-Se*fe-h)*d+(m=Me-Se*de-l)*m)>z*z&&(f*=o=z/a.sqrt(o),d*=o,m*=o),Ae=s+f,Pe=h+d,Me=l+m,i.addPoint(Ae,Pe,Me,pe,fe,de,Se,!1),Pe=te*ve+ie*ye+re*be,Me=te*xe+ie*Te+re*Ee,(Se=pe*((Ae=(te=Ae=te*me+ie*ge+re*_e)+c)-s)+fe*((Pe=(ie=Pe)+u)-h)+de*((Me=(re=Me)+p)-l))<=0&&((o=(f=Ae-Se*pe-s)*f+(d=Pe-Se*fe-h)*d+(m=Me-Se*de-l)*m)>z*z&&(f*=o=z/a.sqrt(o),d*=o,m*=o),Ae=s+f,Pe=h+d,Me=l+m,i.addPoint(Ae,Pe,Me,pe,fe,de,Se,!1)),Pe=te*ve+ie*ye+re*be,Me=te*xe+ie*Te+re*Ee,(Se=pe*((Ae=(te=Ae=te*me+ie*ge+re*_e)+c)-s)+fe*((Pe=(ie=Pe)+u)-h)+de*((Me=(re=Me)+p)-l))<=0&&((o=(f=Ae-Se*pe-s)*f+(d=Pe-Se*fe-h)*d+(m=Me-Se*de-l)*m)>z*z&&(f*=o=z/a.sqrt(o),d*=o,m*=o),Ae=s+f,Pe=h+d,Me=l+m,i.addPoint(Ae,Pe,Me,pe,fe,de,Se,!1));else{if(g=f,_=d,v=m,T=pe*(g-s)+fe*(_-h)+de*(v-l),g-=T*pe,_-=T*fe,v-=T*de,A>0?(y=f+X*N*2,b=d+Y*N*2,x=m+K*N*2):(y=f-X*N*2,b=d-Y*N*2,x=m-K*N*2),E=pe*(y-s)+fe*(b-h)+de*(x-l),y-=E*pe,b-=E*fe,x-=E*de,te=s-g,ie=h-_,re=l-v,f=y-g,d=b-_,m=x-v,Ce=te*te+ie*ie+re*re,Re=te*f+ie*d+re*m,Ie=f*f+d*d+m*m,(Oe=Re*Re-Ie*(Ce-z*z))<0)break;(M=(Re-(Oe=a.sqrt(Oe)))/Ie)<(P=(Re+Oe)/Ie)&&(o=P,P=M,M=o),M>1&&(M=1),P<0&&(P=0),f=g+(y-g)*P,d=_+(b-_)*P,m=v+(x-v)*P,y=g+(y-g)*M,b=_+(b-_)*M,x=v+(x-v)*M,g=f,_=d,v=m,o=T+(E-T)*P,E=T+(E-T)*M,(T=o)<0&&i.addPoint(g,_,v,pe,fe,de,Se,!1),E<0&&i.addPoint(y,b,x,pe,fe,de,Se,!1)}break;case 2:if(ce?(c=w-J,u=D-$,p=L-ee,pe=-X,fe=-Y,de=-K):(c=w+J,u=D+$,p=L+ee,pe=X,fe=Y,de=K),A=pe*W+fe*H+de*j,o=A<0?F:-F,s=R+o*W,h=I+o*H,l=O+o*j,ae>=.999999?(f=-fe,d=de,m=pe):(f=pe,d=fe,m=de),o=f*W+d*H+m*j,te=o*W-f,ie=o*H-d,re=o*j-m,0==(o=a.sqrt(te*te+ie*ie+re*re)))break;if(o=z/o,te*=o,ie*=o,re*=o,f=s+te,d=h+ie,m=l+re,A<-.96||A>.96)me=W*W*1.5-.5,ge=W*H*1.5-.866025403*j,_e=W*j*1.5+.866025403*H,ve=H*W*1.5+.866025403*j,ye=H*H*1.5-.5,be=H*j*1.5-.866025403*W,xe=j*W*1.5-.866025403*H,Te=j*H*1.5+.866025403*W,Ee=j*j*1.5-.5,(o=(f=(Ae=f)-(Se=pe*(Ae-c)+fe*((Pe=d)-u)+de*((Me=m)-p))*pe-c)*f+(d=Pe-Se*fe-u)*d+(m=Me-Se*de-p)*m)>G*G&&(f*=o=G/a.sqrt(o),d*=o,m*=o),Ae=c+f,Pe=u+d,Me=p+m,i.addPoint(Ae,Pe,Me,-pe,-fe,-de,Se,!1),Pe=te*ve+ie*ye+re*be,Me=te*xe+ie*Te+re*Ee,(Se=pe*((Ae=(te=Ae=te*me+ie*ge+re*_e)+s)-c)+fe*((Pe=(ie=Pe)+h)-u)+de*((Me=(re=Me)+l)-p))<=0&&((o=(f=Ae-Se*pe-c)*f+(d=Pe-Se*fe-u)*d+(m=Me-Se*de-p)*m)>G*G&&(f*=o=G/a.sqrt(o),d*=o,m*=o),Ae=c+f,Pe=u+d,Me=p+m,i.addPoint(Ae,Pe,Me,-pe,-fe,-de,Se,!1)),Pe=te*ve+ie*ye+re*be,Me=te*xe+ie*Te+re*Ee,(Se=pe*((Ae=(te=Ae=te*me+ie*ge+re*_e)+s)-c)+fe*((Pe=(ie=Pe)+h)-u)+de*((Me=(re=Me)+l)-p))<=0&&((o=(f=Ae-Se*pe-c)*f+(d=Pe-Se*fe-u)*d+(m=Me-Se*de-p)*m)>G*G&&(f*=o=G/a.sqrt(o),d*=o,m*=o),Ae=c+f,Pe=u+d,Me=p+m,i.addPoint(Ae,Pe,Me,-pe,-fe,-de,Se,!1));else{if(g=f,_=d,v=m,T=pe*(g-c)+fe*(_-u)+de*(v-p),g-=T*pe,_-=T*fe,v-=T*de,A>0?(y=f+W*F*2,b=d+H*F*2,x=m+j*F*2):(y=f-W*F*2,b=d-H*F*2,x=m-j*F*2),E=pe*(y-c)+fe*(b-u)+de*(x-p),y-=E*pe,b-=E*fe,x-=E*de,te=c-g,ie=u-_,re=p-v,f=y-g,d=b-_,m=x-v,Ce=te*te+ie*ie+re*re,Re=te*f+ie*d+re*m,Ie=f*f+d*d+m*m,(Oe=Re*Re-Ie*(Ce-G*G))<0)break;(M=(Re-(Oe=a.sqrt(Oe)))/Ie)<(P=(Re+Oe)/Ie)&&(o=P,P=M,M=o),M>1&&(M=1),P<0&&(P=0),f=g+(y-g)*P,d=_+(b-_)*P,m=v+(x-v)*P,y=g+(y-g)*M,b=_+(b-_)*M,x=v+(x-v)*M,g=f,_=d,v=m,o=T+(E-T)*P,E=T+(E-T)*M,(T=o)<0&&i.addPoint(g,_,v,-pe,-fe,-de,T,!1),E<0&&i.addPoint(y,b,x,-pe,-fe,-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,h=o.y,l=o.z,c=n.position,u=c.x,p=c.y,f=c.z,d=n.normalDirection.x,m=n.normalDirection.y,g=n.normalDirection.z,_=r.radius,v=n.radius,y=_+v,b=n.halfHeight,x=s-u,T=h-p,E=l-f,A=x*d+T*m+E*g;if(!(A<-b-_||A>b+_)){var P=u+A*d,M=p+A*m,S=f+A*g,C=s-P,R=h-M,I=l-S,O=C*C+R*R+I*I;if(!(O>y*y)){O>v*v&&(C*=O=v/a.sqrt(O),R*=O,I*=O),A<-b?A=-b:A>b&&(A=b);var w;(O=(x=(P=u+A*d+C)-s)*x+(T=(M=p+A*m+R)-h)*T+(E=(S=f+A*g+I)-l)*E)>0&&O<_*_&&(x*=w=1/(O=a.sqrt(O)),T*=w,E*=w,i.addPoint(s+x*_,h+T*_,l+E*_,x,T,E,O-_,this.flip))}}},a.TetraTetraCollisionDetector=function(){a.CollisionDetector.call(this)},a.TetraTetraCollisionDetector.prototype=Object.create(a.CollisionDetector.prototype),a.TetraTetraCollisionDetector.prototype.constructor=a.TetraTetraCollisionDetector,a.TetraTetraCollisionDetector.prototype.detectCollision=function(e,t,i){var r,s,a,h,l,c,u=e.faces,p=e.verts,f=(t.faces,t.verts),d=0,m=u;for(r=0;r<4;r++)for(a=p[r],s=0;s<4;s++)h=f[m[r].a],l=f[m[r].b],c=f[m[r].c],n(o(a.x,a.y),o(h.x,h.y),o(l.x,l.y),o(c.x,c.y))&&n(o(a.x,a.z),o(h.x,h.z),o(l.x,l.z),o(c.x,c.z))&&n(o(a.z,a.y),o(h.z,h.y),o(l.z,l.y),o(c.z,c.y))&&d++,4===d&&i.addPoint(a)},a.AABB=function(e,t,i,r,n,o){this.elements=new s(6);var a=this.elements;a[0]=e||0,a[1]=i||0,a[2]=n||0,a[3]=t||0,a[4]=r||0,a[5]=o||0},a.AABB.prototype={constructor:a.AABB,set:function(e,t,i,r,n,o){var s=this.elements;return s[0]=e,s[3]=t,s[1]=i,s[4]=r,s[2]=n,s[5]=o,this},intersectTest:function(e){var t=this.elements,i=e.elements;return t[0]>i[3]||t[1]>i[4]||t[2]>i[5]||t[3]i[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;nh){var c=n;do{if(r[c]=l,0==--c)break;l=r[c-1]}while(l.value>h);if(r[c]=s,(e+=n-c)>t){i=!0;break}}}if(i){e=2;var u=this.stack;for(u[0]=0,u[1]=this.numElements-1;e>0;){var p=u[--e],f=u[--e],d=p-f;if(d>16){var m=f+a.floor(.5*d);for(s=r[m],r[m]=r[p],r[p]=s,h=s.value,n=f-1,c=p;;){var g,_;do{g=r[++n]}while(g.value=c)break;r[n]=_,r[c]=g}r[p]=r[n],r[n]=s,n-f>p-n?(u[e++]=f,u[e++]=n-1,u[e++]=n+1,u[e++]=p):(u[e++]=n+1,u[e++]=p,u[e++]=f,u[e++]=n-1)}else for(n=f+1;n<=p;n++)if(s=r[n],h=s.value,(l=r[n-1]).value>h){c=n;do{if(r[c]=l,0==--c)break;l=r[c-1]}while(l.value>h);r[c]=s}}}},calculateTestCount:function(){for(var e=1,t=0,i=1,r=this.numElements;iv.max1.value||mv.max2.value||_v.max1.value||mv.max2.value||_0?this.freeNodes[--this.numFreeNodes]:new a.DBVTNode).parent=g,m.child1=e,m.child2=n,m.aabb.combine(e.aabb,n.aabb),m.height=n.height+1,n.parent=m,e.parent=m,n==this.root?this.root=m:g.child1==n?g.child1=m:g.child2=m;do{m=this.balance(m),this.fix(m),m=m.parent}while(null!=m)}else this.root=e},getBalance:function(e){return null!=e.proxy?0:e.child1.height-e.child2.height},deleteLeaf:function(e){if(e!=this.root){var t,i=e.parent;if(t=i.child1==e?i.child2:i.child1,i==this.root)return this.root=t,void(t.parent=null);var r=i.parent;t.parent=r,r.child1==i?r.child1=t:r.child2=t,this.numFreeNodes<16384&&(this.freeNodes[this.numFreeNodes++]=i);do{r=this.balance(r),this.fix(r),r=r.parent}while(null!=r)}else this.root=null},balance:function(e){var t=e.height;if(t<2)return e;var i,r=e.parent,n=e.child1,o=e.child2,s=n.height,a=o.height,h=s-a;if(h>1){var l=n.child1,c=n.child2,u=l.height,p=c.height;return u>p?(n.child2=e,e.parent=n,e.child1=c,c.parent=e,e.aabb.combine(c.aabb,o.aabb),i=p-a,e.height=p-(i&i>>31)+1,n.aabb.combine(l.aabb,e.aabb),i=u-t,n.height=u-(i&i>>31)+1):(n.child1=e,e.parent=n,e.child1=l,l.parent=e,e.aabb.combine(l.aabb,o.aabb),i=u-a,e.height=u-(i&i>>31)+1,n.aabb.combine(e.aabb,c.aabb),i=t-p,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(h<-1){var f=o.child1,d=o.child2,m=f.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(f.aabb,e.aabb),i=m-t,o.height=m-(i&i>>31)+1):(o.child1=e,e.parent=o,e.child2=f,f.parent=e,e.aabb.combine(n.aabb,f.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,h=2;for(this.stack[0]=e,this.stack[1]=t;h>0;)if(n=this.stack[--h],o=this.stack[--h],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[h++]=n.child1,this.stack[h++]=o,this.stack[h++]=n.child2,this.stack[h++]=o):(this.stack[h++]=n,this.stack[h++]=o.child1,this.stack[h++]=n,this.stack[h++]=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,h;"jointDistance"===t[0]?(s=e.min||0,h=e.max||10,s*=a.INV_SCALE,h*=a.INV_SCALE):(s=e.min||57.29578,h=e.max||0,s*=a.degtorad,h*=a.degtorad);var l=e.limit||null,c=e.spring||null,u=e.motor||null,p=new a.JointConfig;p.allowCollision=e.collision||!1,p.localAxis1.init(i[0],i[1],i[2]),p.localAxis2.init(r[0],r[1],r[2]),p.localAnchorPoint1.init(n[0],n[1],n[2]),p.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)),p.body1=e.body1,p.body2=e.body2;var f;switch(t[0]){case"jointDistance":f=new a.DistanceJoint(p,s,h),null!==c&&f.limitMotor.setSpring(c[0],c[1]),null!==u&&f.limitMotor.setSpring(u[0],u[1]);break;case"jointHinge":f=new a.HingeJoint(p,s,h),null!==c&&f.limitMotor.setSpring(c[0],c[1]),null!==u&&f.limitMotor.setSpring(u[0],u[1]);break;case"jointPrisme":f=new a.PrismaticJoint(p,s,h);break;case"jointSlide":f=new a.SliderJoint(p,s,h);break;case"jointBall":f=new a.BallAndSocketJoint(p);break;case"jointWheel":f=new a.WheelJoint(p),null!==l&&f.rotationalLimitMotor1.setLimit(l[0],l[1]),null!==c&&f.rotationalLimitMotor1.setSpring(c[0],c[1]),null!==u&&f.rotationalLimitMotor1.setSpring(u[0],u[1])}return f.name=e.name||"",this.addJoint(f),f}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 _=e.size||[1,1,1];_=_.map(function(e){return e*a.INV_SCALE});var v=e.rot||[0,0,0];v=v.map(function(e){return e*a.degtorad});for(var y=[],b=0;b0&&(M[b].relativePosition=new a.Vec3(g[E],g[E+1],g[E+2]),y[A+0]&&(M[b].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 h=this;h.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 l(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 h=i(18);h.registerHelper("eachInMap",function(e,t){var i="";return Object.keys(e).map(function(r){var n=e[r];"object"==typeof n?(n.id=n.id||r,i+=t.fn(n)):i+=t.fn({id:r,value:n})}),i});var l=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=h.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 c="[object Object]";r.prototype={constructor:r,logger:l.default,log:l.default.log,registerHelper:function(e,t){if(o.toString.call(e)===c){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)===c)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)===c){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 u=l.default.log;t.log=u,t.createFrame=o.createFrame,t.logger=l.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 h=function(e){return"function"==typeof e};h(/x/)&&(t.isFunction=h=function(e){return"function"==typeof e&&"[object Function]"===a.call(e)}),t.isFunction=h;var l=Array.isArray||function(e){return!(!e||"object"!=typeof e)&&"[object Array]"===a.call(e)};t.isArray=l},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 h=Error.prototype.constructor.call(this,e),l=0;l0?(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){l&&(l.key=t,l.index=i,l.first=0===i,l.last=!!o,c&&(l.contextPath=c+t)),h+=r(e[t],{data:l,blockParams:n.blockParams([e[t],t],[c+t,null])})}if(!t)throw new o.default("Must pass iterator to #each");var r=t.fn,s=t.inverse,a=0,h="",l=void 0,c=void 0;if(t.data&&t.ids&&(c=n.appendContextPath(t.data.contextPath,t.ids[0])+"."),n.isFunction(e)&&(e=e.call(this)),t.data&&(l=n.createFrame(t.data)),e&&"object"==typeof e)if(n.isArray(e))for(var u=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]+"'");E=this.lexer.showPosition?"Parse error on line "+(h+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+x.join(", ")+", got '"+(this.terminals_[f]||f)+"'":"Parse error on line "+(h+1)+": Unexpected "+(1==f?"end of input":"'"+(this.terminals_[f]||f)+"'"),this.parseError(E,{text:this.lexer.match,token:this.terminals_[f]||f,line:this.lexer.yylineno,loc:u,expected:x})}}if(g[0]instanceof Array&&g.length>1)throw new Error("Parse Error: multiple actions possible at state: "+m+", token: "+f);switch(g[0]){case 1:r.push(f),n.push(this.lexer.yytext),o.push(this.lexer.yylloc),r.push(g[1]),f=null,d?(f=d,d=null):(l=this.lexer.yyleng,a=this.lexer.yytext,h=this.lexer.yylineno,u=this.lexer.yylloc,c>0&&c--);break;case 2:if(y=this.productions_[g[1]][1],T.$=n[n.length-y],T._$={first_line:o[o.length-(y||1)].first_line,last_line:o[o.length-1].last_line,first_column:o[o.length-(y||1)].first_column,last_column:o[o.length-1].last_column},p&&(T._$.range=[o[o.length-(y||1)].range[0],o[o.length-1].range[1]]),void 0!==(_=this.performAction.call(T,a,l,h,this.yy,g[1],n,o)))return _;y&&(r=r.slice(0,-1*y*2),n=n.slice(0,-1*y),o=o.slice(0,-1*y)),r.push(this.productions_[g[1]][0]),n.push(T.$),o.push(T._$),b=s[r[r.length-2]][r[r.length-1]],r.push(b);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];this.yytext+=e,this.yyleng++,this.offset++,this.match+=e,this.matched+=e;return 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 h=i(1).default;t.__esModule=!0;var l=h(i(39));(r.prototype=new l.default).Program=function(e){var t=!this.options.ignoreStandalone,i=!this.isRootSeen;this.isRootSeen=!0;for(var r=e.body,h=0,l=r.length;h0)throw new o.default("Invalid path: "+r,{loc:i});".."===l&&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 h=/\*/.test(e.open);t.blockParams=e.blockParams;var l=void 0,c=void 0;if(i){if(h)throw new o.default("Unexpected inverse block on decorator",i);i.chain&&(i.program.body[0].closeStrip=n.strip),c=i.strip,l=i.program}return s&&(s=l,l=t,t=s),{type:h?"DecoratorBlock":"BlockStatement",path:e.path,params:e.params,hash:e.hash,program:t,inverse:l,openStrip:e.strip,inverseStrip:c,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(h.isArray(e)&&h.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,l.default.helpers.simpleId(n))}},PathExpression:function(e){this.addDepth(e.depth),this.opcode("getContext",e.depth);var t=e.parts[0],i=l.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(){}var o=i(1).default;t.__esModule=!0;var s=i(4),a=o(i(6)),h=i(5),l=o(i(43));n.prototype={nameLookup:function(e,t){return n.isValidJavaScriptVariableName(t)?[e,".",t]:[e,"[",JSON.stringify(t),"]"]},depthedLookup:function(e){return[this.aliasable("container.lookup"),'(depths, "',e,'")']},compilerInfo:function(){var e=s.COMPILER_REVISION;return[e,s.REVISION_CHANGES[e]]},appendToBuffer:function(e,t,i){return h.isArray(e)||(e=[e]),e=this.source.wrap(e,t),this.environment.isSimple?["return ",e,";"]:i?["buffer += ",e,";"]:(e.appendToBuffer=!0,e)},initializeBuffer:function(){return this.quotedString("")},compile:function(e,t,i,r){this.environment=e,this.options=t,this.stringParams=this.options.stringParams,this.trackIds=this.options.trackIds,this.precompile=!r,this.name=this.environment.name,this.isChild=!!i,this.context=i||{decorators:[],programs:[],environments:[]},this.preamble(),this.stackSlot=0,this.stackVars=[],this.aliases={},this.registers={list:[]},this.hashes=[],this.compileStack=[],this.inlineStack=[],this.blockParams=[],this.compileChildren(e,t),this.useDepths=this.useDepths||e.useDepths||e.useDecorators||this.options.compat,this.useBlockParams=this.useBlockParams||e.useBlockParams;var n=e.opcodes,o=void 0,s=void 0,h=void 0,l=void 0;for(h=0,l=n.length;h0&&(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 o=this;if(this.options.strict||this.options.assumeObjects)this.push(function(e,t,i,r){var n=t.popStack(),o=0,s=i.length;for(e&&s--;othis.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;tnav-bar{position:absolute;height:160px;width:100%;bottom:0;background-color:rgba(0,0,0,.3);color:#fff;transition:1s;align-items:flex-start;justify-content:space-around;display:flex;flex-direction:column}@media screen and (min-width:768px){nav-bar{align-items:center;flex-direction:row;justify-content:space-between;height:80px}}div.flex-container{display:flex;width:100%}div.thumbnail{position:relative;overflow:hidden;display:block;width:40px;height:40px;background-size:cover;background-position:center;border-radius:20px;margin:0 10px}div.title-container{flex-direction:column;display:flex;justify-content:space-between}span.model-title{font-size:125%}span.model-subtitle{font-size:90%}div.button-container{align-items:center;justify-content:flex-end}div.button{cursor:pointer;height:30px;margin:0 10px}div.button img{height:100%} {{#if disableOnFullscreen}} {{/if}}
{{#if title}}{{title}}{{/if}} {{#if subtitle}}{{subtitle}} {{/if}}
{{#eachInMap buttons}}
{{#if text}} {{text}}> {{/if}} {{#if image}} {{altText}} {{/if}}
{{/eachInMap}}
'},function(e,t){e.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQAAAAB/ecQqAAAAAnRSTlMAAHaTzTgAAAAeSURBVHgBY6ASsP/A/wcXZQNGhCkyAfE24HUndQAAXlkXcQ24P7gAAAAASUVORK5CYII="},function(e,t){e.exports="HELP"},function(e,t){e.exports="SHARE"},function(e,t,i){!function(t,i){e.exports=i()}(0,function(){"use strict";function e(e){var t=Object.prototype.toString.call(e);return"[object RegExp]"===t||"[object Date]"===t||function(e){return e.$$typeof===o}(e)}function t(e,t){return(!t||!1!==t.clone)&&n(e)?r(function(e){return Array.isArray(e)?[]:{}}(e),e,t):e}function i(e,i,r){return e.concat(i).map(function(e){return t(e,r)})}function r(e,o,s){var a=Array.isArray(o);if(a===Array.isArray(e)){if(a){return((s||{arrayMerge:i}).arrayMerge||i)(e,o,s)}return function(e,i,o){var s={};return n(e)&&Object.keys(e).forEach(function(i){s[i]=t(e[i],o)}),Object.keys(i).forEach(function(a){n(i[a])&&e[a]?s[a]=r(e[a],i[a],o):s[a]=t(i[a],o)}),s}(e,o,s)}return t(o,s)}var n=function(t){return function(e){return!!e&&"object"==typeof e}(t)&&!e(t)},o="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;r.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce(function(e,i){return r(e,i,t)},{})};return r})},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 h;if(this.isBinary(r)){f=new e.Mesh("stlmesh",i);return this.parseBinary(f,r),o&&o.push(f),!0}for(var l=new Uint8Array(r),c="",u=0;u127)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),h=new Uint32Array(3*n),l=0,c=0;c=0?c.substring(0,u):c;p=p.toLowerCase();var f=u>=0?c.substring(u+1).trim():"";"newmtl"===p?(h&&this.materials.push(h),h=new e.StandardMaterial(f,i)):"kd"===p&&h?(o=f.split(a,3).map(parseFloat),h.diffuseColor=e.Color3.FromArray(o)):"ka"===p&&h?(o=f.split(a,3).map(parseFloat),h.ambientColor=e.Color3.FromArray(o)):"ks"===p&&h?(o=f.split(a,3).map(parseFloat),h.specularColor=e.Color3.FromArray(o)):"ke"===p&&h?(o=f.split(a,3).map(parseFloat),h.emissiveColor=e.Color3.FromArray(o)):"ns"===p&&h?h.specularPower=parseFloat(f):"d"===p&&h?h.alpha=parseFloat(f):"map_ka"===p&&h?h.ambientTexture=t._getTexture(n,f,i):"map_kd"===p&&h?h.diffuseTexture=t._getTexture(n,f,i):"map_ks"===p&&h?h.specularTexture=t._getTexture(n,f,i):"map_ns"===p||("map_bump"===p&&h?h.bumpTexture=t._getTexture(n,f,i):"map_d"===p&&h&&(h.opacityTexture=t._getTexture(n,f,i)))}}h&&this.materials.push(h)},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,h=[],l=[],c=[],u=[],p=[],f=[],d=[],m=[],g=[],_=0,v=!1,y=[],b=[],x=[],T=[],E="",A="",P=new t,M=1,S=!0,C=function(e,t,r,n,o,s){var a;-1==(a=i.OPTIMIZE_WITH_UV?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}(g,[e,r,t]):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]}(g,[e,r]))?(p.push(f.length),f.push(n),d.push(o),m.push(s),g[e].normals.push(r),g[e].idx.push(_++),i.OPTIMIZE_WITH_UV&&g[e].uv.push(t)):p.push(a)},R=function(){for(var e=0;e0&&(a=u[u.length-1],R(),p.reverse(),a.indices=p.slice(),a.positions=y.slice(),a.normals=b.slice(),a.uvs=x.slice(),p=[],y=[],b=[],x=[])},w=o.split("\n"),D=0;D-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=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: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=1313821514,r=5130562,n=t.readUint32();if(n!==t.getLength())throw new Error("Length in header does not match actual data length: "+n+" != "+t.getLength());var o=t.readUint32();if(t.readUint32()!==i)throw new Error("First chunk format is not JSON");for(var s=JSON.parse(e._decodeBufferToText(t.readUint8Array(o))),a=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"],h=function(e,t,i){for(var r in e){var n=e[r];i[t][r]=n}},l=function(e){if(e)for(var t=0;t0&&(g=f(s,o))&&-1===a.indexOf(g)&&a.push(g),new e.Bone(h.jointName||"",n,g,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=_(t,i,i.meshes,r,i.babylonNode)).skeleton=t.scene.getLastSkeletonByID(i.skin),null===a.skeleton&&s.babylonSkeleton&&(a.skeleton=g(t,s,0,s.babylonSkeleton,i.skin),s.babylonSkeleton||(s.babylonSkeleton=a.skeleton)),o=a}}else if(i.meshes){var a=_(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 h=t.cameras[i.camera];if(h)if("orthographic"===h.type){var l=new e.FreeCamera(i.camera,e.Vector3.Zero(),t.scene);l.name=i.name||"",l.mode=e.Camera.ORTHOGRAPHIC_CAMERA,l.attachControl(t.scene.getEngine().getRenderingCanvas()),o=l}else if("perspective"===h.type){var c=h[h.type],u=new e.FreeCamera(i.camera,e.Vector3.Zero(),t.scene);u.name=i.name||"",u.attachControl(t.scene.getEngine().getRenderingCanvas()),c.aspectRatio||(c.aspectRatio=t.scene.getEngine().getRenderWidth()/t.scene.getEngine().getRenderHeight()),c.znear&&c.zfar&&(u.maxZ=c.zfar,u.minZ=c.znear),o=u}}}else{var p=t.lights[i.light];if(p)if("ambient"===p.type){var f=p[p.type],d=new e.HemisphericLight(i.light,e.Vector3.Zero(),t.scene);d.name=i.name||"",f.color&&(d.diffuse=e.Color3.FromArray(f.color)),o=d}else if("directional"===p.type){var m=p[p.type],y=new e.DirectionalLight(i.light,e.Vector3.Zero(),t.scene);y.name=i.name||"",m.color&&(y.diffuse=e.Color3.FromArray(m.color)),o=y}else if("point"===p.type){var b=p[p.type],x=new e.PointLight(i.light,e.Vector3.Zero(),t.scene);x.name=i.name||"",b.color&&(x.diffuse=e.Color3.FromArray(b.color)),o=x}else if("spot"===p.type){var T=p[p.type],E=new e.SpotLight(i.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);E.name=i.name||"",T.color&&(E.diffuse=e.Color3.FromArray(T.color)),T.fallOfAngle&&(E.angle=T.fallOfAngle),T.fallOffExponent&&(E.exponent=T.fallOffExponent),o=E}}if(!i.jointName){if(i.babylonNode)return i.babylonNode;if(null===o){var A=new e.Mesh(i.name||"",t.scene);i.babylonNode=A,o=A}}if(null!==o){if(i.matrix&&o instanceof e.Mesh)!function(t,i,r){if(i.matrix){var n=new e.Vector3(0,0,0),o=new e.Quaternion,s=new e.Vector3(0,0,0);e.Matrix.FromArray(i.matrix).decompose(s,o,n),v(t,n,o,s)}else i.translation&&i.rotation&&i.scale&&v(t,e.Vector3.FromArray(i.translation),e.Quaternion.FromArray(i.rotation),e.Vector3.FromArray(i.scale));t.computeWorldMatrix(!0)}(o,i);else{var P=i.translation||[0,0,0],M=i.rotation||[0,0,0,1],S=i.scale||[1,1,1];v(o,e.Vector3.FromArray(P),e.Quaternion.FromArray(M),e.Vector3.FromArray(S))}o.updateCache(!0),i.babylonNode=o}return o},b=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=y(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;h--){var l=t.GLTFLoader._GetProperty(e._gltf.nodes,s.ids[h]);if(!l)throw new Error(i+": Failed to find node "+s.ids[h]);e._traverseNode(i,l,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],h=0,l=o.ids;h=Math.abs(r["client"+o]-this.firstXY[o])}return this.firstXY=null,t}},findTouch:function(e,t){for(var i,r=0,n=e.length;r=t.length){var i=[];N.forEach(function(e,r){if(1!==r&&!this.findTouch(t,r-2)){var n=e.out;i.push(n)}},this),i.forEach(this.cancelOut,this)}},touchstart:function(e){this.vacuumTouches(e),this.setPrimaryTouch(e.changedTouches[0]),this.dedupSynthMouse(e),this.scrolling||(this.clickCount++,this.processTouches(e,this.overDown))},overDown:function(e){N.set(e.pointerId,{target:e.target,out:e,outTarget:e.target}),g.enterOver(e),g.down(e)},touchmove:function(e){this.scrolling||(this.shouldScroll(e)?(this.scrolling=!0,this.touchcancel(e)):(e.preventDefault(),this.processTouches(e,this.moveOverOut)))},moveOverOut:function(e){var t=e,i=N.get(t.pointerId);if(i){var r=i.out,n=i.outTarget;g.move(t),r&&n!==t.target&&(r.relatedTarget=t.target,t.relatedTarget=n,r.target=n,t.target?(g.leaveOut(r),g.enterOver(t)):(t.target=n,t.relatedTarget=null,this.cancelOut(t))),i.out=t,i.outTarget=t.target}},touchend:function(e){this.dedupSynthMouse(e),this.processTouches(e,this.upOut)},upOut:function(e){this.scrolling||(g.up(e),g.leaveOut(e)),this.cleanUpPointer(e)},touchcancel:function(e){this.processTouches(e,this.cancelOut)},cancelOut:function(e){g.cancel(e),g.leaveOut(e),this.cleanUpPointer(e)},cleanUpPointer:function(e){N.delete(e.pointerId),this.removePrimaryPointer(e)},dedupSynthMouse:function(e){var t=w.lastTouches,i=e.changedTouches[0];if(this.isPrimaryTouch(i)){var r={x:i.clientX,y:i.clientY};t.push(r);var n=function(e,t){var i=e.indexOf(t);i>-1&&e.splice(i,1)}.bind(null,t,r);setTimeout(n,2500)}}};O=new i(B.elementAdded,B.elementRemoved,B.elementChanged,B);var V,U,k,z=g.pointermap,G=window.MSPointerEvent&&"number"==typeof window.MSPointerEvent.MSPOINTER_TYPE_MOUSE,W={events:["MSPointerDown","MSPointerMove","MSPointerUp","MSPointerOut","MSPointerOver","MSPointerCancel","MSGotPointerCapture","MSLostPointerCapture"],register:function(e){g.listen(e,this.events)},unregister:function(e){g.unlisten(e,this.events)},POINTER_TYPES:["","unavailable","touch","pen","mouse"],prepareEvent:function(e){var t=e;return G&&(t=g.cloneEvent(e),t.pointerType=this.POINTER_TYPES[e.pointerType]),t},cleanup:function(e){z.delete(e)},MSPointerDown:function(e){z.set(e.pointerId,e);var t=this.prepareEvent(e);g.down(t)},MSPointerMove:function(e){var t=this.prepareEvent(e);g.move(t)},MSPointerUp:function(e){var t=this.prepareEvent(e);g.up(t),this.cleanup(e.pointerId)},MSPointerOut:function(e){var t=this.prepareEvent(e);g.leaveOut(t)},MSPointerOver:function(e){var t=this.prepareEvent(e);g.enterOver(t)},MSPointerCancel:function(e){var t=this.prepareEvent(e);g.cancel(t),this.cleanup(e.pointerId)},MSLostPointerCapture:function(e){var t=g.makeEvent("lostpointercapture",e);g.dispatchEvent(t)},MSGotPointerCapture:function(e){var t=g.makeEvent("gotpointercapture",e);g.dispatchEvent(t)}};window.navigator.msPointerEnabled?(V=function(e){s(e),a(this),h(e)&&(g.setCapture(e,this,!0),this.msSetPointerCapture(e))},U=function(e){s(e),g.releaseCapture(e,!0),this.msReleasePointerCapture(e)}):(V=function(e){s(e),a(this),h(e)&&g.setCapture(e,this)},U=function(e){s(e),g.releaseCapture(e)}),k=function(e){return!!g.captureInfo[e]},function(){if(M){A.forEach(function(e){String(e)===e?(P+=n(e)+o(e)+"\n",S&&(P+=r(e)+o(e)+"\n")):(P+=e.selectors.map(n)+o(e.rule)+"\n",S&&(P+=e.selectors.map(r)+o(e.rule)+"\n"))});var e=document.createElement("style");e.textContent=P,document.head.appendChild(e)}}(),function(){if(!window.PointerEvent){if(window.PointerEvent=e,window.navigator.msPointerEnabled){var t=window.navigator.msMaxTouchPoints;Object.defineProperty(window.navigator,"maxTouchPoints",{value:t,enumerable:!0}),g.registerSource("ms",W)}else Object.defineProperty(window.navigator,"maxTouchPoints",{value:0,enumerable:!0}),g.registerSource("mouse",w),void 0!==window.ontouchstart&&g.registerSource("touch",B);g.register(document)}}(),window.Element&&!Element.prototype.setPointerCapture&&Object.defineProperties(Element.prototype,{setPointerCapture:{value:V},releasePointerCapture:{value:U},hasPointerCapture:{value:k}});return{dispatcher:g,Installer:i,PointerEvent:e,PointerMap:u,targetFinding:_}})},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